course)) { error('Course is misconfigured'); } if (!$book = get_record('book', 'id', $cm->instance)) { 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 = get_records_select('book_chapters', $select, '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 = get_record('book_chapters', 'id', $chapterid)) { error('Error reading book chapters.'); } //check all variables unset($id); unset($chapterid); /// chapter is hidden for students if (!$allowedit && $chapter->hidden) { error('Error reading book chapters.'); } /// chapter not part of this book! if ($chapter->bookid != $book->id) { 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'); $strTOC = get_string('TOC', '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).'
' : ' '; /// prepare chapter navigation icons $previd = null; $nextid = null; $found = 0; foreach ($chapters as $ch) { if ($found) { $nextid= $ch->id; break; } if ($ch->id == $chapter->id) { $found = 1; } if (!$found) { $previd = $ch->id; } } if ($ch == current($chapters)) { $nextid = $ch->id; } $chnavigation = ''; echo "previd=$previd nextid=$nextid
"; if ($previd) { $chnavigation .= ''.get_string('navprev', 'book').''; } else { $chnavigation .= ''; } if ($nextid) { $chnavigation .= ''.get_string('navnext', 'book').''; } else { $sec = ''; if ($section = get_record('course_sections', 'id', $cm->section)) { $sec = $section->section; } $chnavigation .= ''.get_string('navexit', 'book').''; } echo "chnavigation=$chnavigation
"; /// prepare print icons if ($book->disableprinting) { $printbook = ''; $printchapter = ''; } else { $printbook = ''.get_string('printbook', 'book').''; $printchapter = ''.get_string('printchapter', 'book').''; } // ===================================================== // Book display HTML code // ===================================================== echo "OK"; ?>

'; helpbutton('faq', get_string('faq','book'), 'book', true, true); echo ''; } ?>
customtitles) { if ($currsubtitle == ' ') { $content .= '

'.$currtitle.'

'; } else { $content .= '

'.$currtitle.'
'.$currsubtitle.'

'; } } $content .= $chapter->content; $nocleanoption = new object(); $nocleanoption->noclean = true; echo '
'; echo format_text($content, FORMAT_HTML, $nocleanoption, $course->id); echo '
'; print_box_end(); /// lower navigation echo '

'.$chnavigation.'

'; ?>