MDL-28151 resource: prevent cropping of large images
[moodle.git] / mod / book / show.php
blob7af7de22dba9a2eacf8554238e77c7cf1e4bc481
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.
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/>.
17 /**
18 * Show/hide book chapter
20 * @package mod_book
21 * @copyright 2004-2010 Petr Skoda {@link http://skodak.org}
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require(dirname(__FILE__).'/../../config.php');
26 require_once(dirname(__FILE__).'/locallib.php');
28 $id = required_param('id', PARAM_INT); // Course Module ID
29 $chapterid = required_param('chapterid', PARAM_INT); // Chapter ID
31 $cm = get_coursemodule_from_id('book', $id, 0, false, MUST_EXIST);
32 $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
33 $book = $DB->get_record('book', array('id'=>$cm->instance), '*', MUST_EXIST);
35 require_login($course, false, $cm);
36 require_sesskey();
38 $context = context_module::instance($cm->id);
39 require_capability('mod/book:edit', $context);
41 $PAGE->set_url('/mod/book/show.php', array('id'=>$id, 'chapterid'=>$chapterid));
43 $chapter = $DB->get_record('book_chapters', array('id'=>$chapterid, 'bookid'=>$book->id), '*', MUST_EXIST);
45 // Switch hidden state.
46 $chapter->hidden = $chapter->hidden ? 0 : 1;
48 // Update record.
49 $DB->update_record('book_chapters', $chapter);
51 // Change visibility of subchapters too.
52 if (!$chapter->subchapter) {
53 $chapters = $DB->get_records('book_chapters', array('bookid'=>$book->id), 'pagenum', 'id, subchapter, hidden');
54 $found = 0;
55 foreach ($chapters as $ch) {
56 if ($ch->id == $chapter->id) {
57 $found = 1;
58 } else if ($found and $ch->subchapter) {
59 $ch->hidden = $chapter->hidden;
60 $DB->update_record('book_chapters', $ch);
61 } else if ($found) {
62 break;
67 add_to_log($course->id, 'course', 'update mod', '../mod/book/view.php?id='.$cm->id, 'book '.$book->id);
68 add_to_log($course->id, 'book', 'update', 'view.php?id='.$cm->id, $book->id, $cm->id);
70 book_preload_chapters($book); // fix structure
71 $DB->set_field('book', 'revision', $book->revision+1, array('id'=>$book->id));
73 redirect('view.php?id='.$cm->id.'&chapterid='.$chapter->id);