[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Book view page 19 * 20 * @package mod_book 21 * @copyright 2004-2011 Petr Skoda {@link http://skodak.org} 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 require(dirname(__FILE__).'/../../config.php'); 26 require_once(dirname(__FILE__).'/locallib.php'); 27 require_once($CFG->libdir.'/completionlib.php'); 28 29 $id = optional_param('id', 0, PARAM_INT); // Course Module ID 30 $bid = optional_param('b', 0, PARAM_INT); // Book id 31 $chapterid = optional_param('chapterid', 0, PARAM_INT); // Chapter ID 32 $edit = optional_param('edit', -1, PARAM_BOOL); // Edit mode 33 34 // ========================================================================= 35 // security checks START - teachers edit; students view 36 // ========================================================================= 37 if ($id) { 38 $cm = get_coursemodule_from_id('book', $id, 0, false, MUST_EXIST); 39 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST); 40 $book = $DB->get_record('book', array('id'=>$cm->instance), '*', MUST_EXIST); 41 } else { 42 $book = $DB->get_record('book', array('id'=>$bid), '*', MUST_EXIST); 43 $cm = get_coursemodule_from_instance('book', $book->id, 0, false, MUST_EXIST); 44 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST); 45 $id = $cm->id; 46 } 47 48 require_course_login($course, true, $cm); 49 50 $context = context_module::instance($cm->id); 51 require_capability('mod/book:read', $context); 52 53 $allowedit = has_capability('mod/book:edit', $context); 54 $viewhidden = has_capability('mod/book:viewhiddenchapters', $context); 55 56 if ($allowedit) { 57 if ($edit != -1 and confirm_sesskey()) { 58 $USER->editing = $edit; 59 } else { 60 if (isset($USER->editing)) { 61 $edit = $USER->editing; 62 } else { 63 $edit = 0; 64 } 65 } 66 } else { 67 $edit = 0; 68 } 69 70 // read chapters 71 $chapters = book_preload_chapters($book); 72 73 if ($allowedit and !$chapters) { 74 redirect('edit.php?cmid='.$cm->id); // No chapters - add new one. 75 } 76 // Check chapterid and read chapter data 77 if ($chapterid == '0') { // Go to first chapter if no given. 78 \mod_book\event\course_module_viewed::create_from_book($book, $context)->trigger(); 79 80 foreach ($chapters as $ch) { 81 if ($edit) { 82 $chapterid = $ch->id; 83 break; 84 } 85 if (!$ch->hidden) { 86 $chapterid = $ch->id; 87 break; 88 } 89 } 90 } 91 92 $courseurl = new moodle_url('/course/view.php', array('id' => $course->id)); 93 94 // No content in the book. 95 if (!$chapterid) { 96 $PAGE->set_url('/mod/book/view.php', array('id' => $id)); 97 notice(get_string('nocontent', 'mod_book'), $courseurl->out(false)); 98 } 99 // Chapter doesnt exist or it is hidden for students 100 if ((!$chapter = $DB->get_record('book_chapters', array('id' => $chapterid, 'bookid' => $book->id))) or ($chapter->hidden and !$viewhidden)) { 101 print_error('errorchapter', 'mod_book', $courseurl); 102 } 103 104 $PAGE->set_url('/mod/book/view.php', array('id'=>$id, 'chapterid'=>$chapterid)); 105 106 107 // Unset all page parameters. 108 unset($id); 109 unset($bid); 110 unset($chapterid); 111 112 // Security checks END. 113 114 \mod_book\event\chapter_viewed::create_from_chapter($book, $context, $chapter)->trigger(); 115 116 // Read standard strings. 117 $strbooks = get_string('modulenameplural', 'mod_book'); 118 $strbook = get_string('modulename', 'mod_book'); 119 $strtoc = get_string('toc', 'mod_book'); 120 121 // prepare header 122 $pagetitle = $book->name . ": " . $chapter->title; 123 $PAGE->set_title($pagetitle); 124 $PAGE->set_heading($course->fullname); 125 126 book_add_fake_block($chapters, $chapter, $book, $cm, $edit); 127 128 // prepare chapter navigation icons 129 $previd = null; 130 $nextid = null; 131 $last = null; 132 foreach ($chapters as $ch) { 133 if (!$edit and $ch->hidden) { 134 continue; 135 } 136 if ($last == $chapter->id) { 137 $nextid = $ch->id; 138 break; 139 } 140 if ($ch->id != $chapter->id) { 141 $previd = $ch->id; 142 } 143 $last = $ch->id; 144 } 145 146 $navprevicon = right_to_left() ? 'nav_next' : 'nav_prev'; 147 $navnexticon = right_to_left() ? 'nav_prev' : 'nav_next'; 148 $navprevdisicon = right_to_left() ? 'nav_next_dis' : 'nav_prev_dis'; 149 150 $chnavigation = ''; 151 if ($previd) { 152 $chnavigation .= '<a title="'.get_string('navprev', 'book').'" href="view.php?id='.$cm->id. 153 '&chapterid='.$previd.'"><img src="'.$OUTPUT->pix_url($navprevicon, 'mod_book').'" class="icon" alt="'.get_string('navprev', 'book').'"/></a>'; 154 } else { 155 $chnavigation .= '<img src="'.$OUTPUT->pix_url($navprevdisicon, 'mod_book').'" class="icon" alt="" />'; 156 } 157 if ($nextid) { 158 $chnavigation .= '<a title="'.get_string('navnext', 'book').'" href="view.php?id='.$cm->id. 159 '&chapterid='.$nextid.'"><img src="'.$OUTPUT->pix_url($navnexticon, 'mod_book').'" class="icon" alt="'.get_string('navnext', 'book').'" /></a>'; 160 } else { 161 $sec = $DB->get_field('course_sections', 'section', array('id' => $cm->section)); 162 $returnurl = course_get_url($course, $sec); 163 $chnavigation .= '<a title="'.get_string('navexit', 'book').'" href="'.$returnurl.'"><img src="'.$OUTPUT->pix_url('nav_exit', 'mod_book'). 164 '" class="icon" alt="'.get_string('navexit', 'book').'" /></a>'; 165 166 // we are cheating a bit here, viewing the last page means user has viewed the whole book 167 $completion = new completion_info($course); 168 $completion->set_module_viewed($cm); 169 } 170 171 // ===================================================== 172 // Book display HTML code 173 // ===================================================== 174 175 echo $OUTPUT->header(); 176 echo $OUTPUT->heading($book->name); 177 178 // upper nav 179 echo '<div class="navtop">'.$chnavigation.'</div>'; 180 181 // chapter itself 182 $hidden = $chapter->hidden ? ' dimmed_text' : null; 183 echo $OUTPUT->box_start('generalbox book_content' . $hidden); 184 185 if (!$book->customtitles) { 186 if (!$chapter->subchapter) { 187 $currtitle = book_get_chapter_title($chapter->id, $chapters, $book, $context); 188 echo $OUTPUT->heading($currtitle, 3); 189 } else { 190 $currtitle = book_get_chapter_title($chapters[$chapter->id]->parent, $chapters, $book, $context); 191 $currsubtitle = book_get_chapter_title($chapter->id, $chapters, $book, $context); 192 echo $OUTPUT->heading($currtitle, 3); 193 echo $OUTPUT->heading($currsubtitle, 4); 194 } 195 } 196 $chaptertext = file_rewrite_pluginfile_urls($chapter->content, 'pluginfile.php', $context->id, 'mod_book', 'chapter', $chapter->id); 197 echo format_text($chaptertext, $chapter->contentformat, array('noclean'=>true, 'overflowdiv'=>true, 'context'=>$context)); 198 199 echo $OUTPUT->box_end(); 200 201 // lower navigation 202 echo '<div class="navbottom">'.$chnavigation.'</div>'; 203 204 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |