. require_once('../../config.php'); require_once('lib.php'); $id = required_param('id', PARAM_INT); // Course Module ID. $chapterid = optional_param('chapterid', 0, PARAM_INT); // Chapter ID. $edit = optional_param('edit', -1, PARAM_BOOL); // Edit mode. /* ========================================================================= * security checks START - teachers edit; students view * ========================================================================= */ if (!$cm = get_coursemodule_from_id('book', $id)) { print_error('Course Module ID was incorrect'); } if (!$course = $DB->get_record('course', array( 'id' => $cm->course))) { print_error('Course is misconfigured'); } if (!$book = $DB->get_record('book', array( 'id' => $cm->instance))) { print_error('Course module is incorrect'); } require_course_login($course, true, $cm); $context = get_context_instance(CONTEXT_MODULE, $cm->id); // Read chapters. $select = $allowedit ? "bookid = $book->id" : "bookid = $book->id AND hidden = 0"; $chapters = $DB->get_records_select('book_chapters', $select, null, 'pagenum', 'id, pagenum, subchapter, title, hidden'); // Check chapterid and read chapter data. if ($chapterid == '0') { // Go to first chapter if no given. foreach ($chapters as $ch) { if ($allowedit) { $chapterid = $ch->id; break; } if (!$ch->hidden) { $chapterid = $ch->id; break; } } } if (!$chapter = $DB->get_record('book_chapters', array('id' => $chapterid))) { print_error('Error reading book chapters.'); } // Check all variables. unset($id); unset($chapterid); // Chapter is hidden for students. if (!$allowedit && $chapter->hidden) { print_error('Error reading book chapters.'); } // Chapter not part of this book! if ($chapter->bookid != $book->id) { print_error('Chapter not part of this book!'); } /* ========================================================================= * security checks END * ========================================================================= */ add_to_log($course->id, 'book', 'view', 'view.php?id='.$cm->id.'&chapterid='.$chapter->id, $book->id, $cm->id); // Read standard strings. $strbooks = get_string('modulenameplural', 'book'); $strbook = get_string('modulename', 'book'); // Prepare header. if ($course->category) { $navigation = ''.$course->shortname.' ->'; } else { $navigation = ''; } $buttons = $allowedit ? '
'. update_module_button($cm->id, $course->id, $strbook).' | '. ''.book_edit_button($cm->id, $course->id, $chapter->id).' |
|
||
box_start('generalbox');
echo $toc;
echo $OUTPUT->box_end();
if ($allowedit && $edit) {
echo ' '; helpbutton('faq', get_string('faq', 'book'), 'book', true, true); echo ''; } ?> |
box_start('generalbox');
$content = '';
if (!$book->customtitles) {
if ($currsubtitle == ' ') {
$content .= ' '.$currtitle.' '; } else { $content .= ''.$currtitle.' ';
echo format_text($content, FORMAT_HTML, $nocleanoption, $course->id);
echo ' ';
echo $OUTPUT->box_end();
// Lower navigation.
echo ''.$chnavigation.' '; ?> |