MDL-64506 theme: Update BSB references and upgrade texts
[moodle.git] / mod / book / tool / print / index.php
CommitLineData
8d623d14 1<?php
b15ef0b0 2// This file is part of Moodle - http://moodle.org/
2c1e98e6
PS
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 printing
19 *
3542c4f4
EL
20 * @package booktool_print
21 * @copyright 2004-2011 Petr Skoda {@link http://skodak.org}
2c1e98e6
PS
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
02039379 24
1fcf0ca8
RS
25require(__DIR__.'/../../../../config.php');
26require_once(__DIR__.'/locallib.php');
02039379
PS
27
28$id = required_param('id', PARAM_INT); // Course Module ID
29$chapterid = optional_param('chapterid', 0, PARAM_INT); // Chapter ID
30
31// =========================================================================
32// security checks START - teachers and students view
33// =========================================================================
02039379 34
2c1e98e6 35$cm = get_coursemodule_from_id('book', $id, 0, false, MUST_EXIST);
8cf64176
MG
36$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
37$book = $DB->get_record('book', array('id' => $cm->instance), '*', MUST_EXIST);
02039379 38
dab784a3 39require_course_login($course, true, $cm);
c6d2eda2 40
1fc9e895 41$context = context_module::instance($cm->id);
c6d2eda2 42require_capability('mod/book:read', $context);
7927cab1 43require_capability('booktool/print:print', $context);
c6d2eda2 44
3542c4f4 45// Check all variables.
02039379 46if ($chapterid) {
3542c4f4 47 // Single chapter printing - only visible!
8cf64176
MG
48 $chapter = $DB->get_record('book_chapters', array('id' => $chapterid, 'bookid' => $book->id), '*',
49 MUST_EXIST);
02039379 50} else {
3542c4f4 51 // Complete book.
02039379
PS
52 $chapter = false;
53}
56e7577e 54
8cf64176 55$PAGE->set_url('/mod/book/print.php', array('id' => $id, 'chapterid' => $chapterid));
56e7577e 56
15b3c4e0
JC
57$PAGE->set_pagelayout("embedded");
58
02039379
PS
59unset($id);
60unset($chapterid);
02039379 61
3542c4f4
EL
62// Security checks END.
63
64// read chapters
ee952cbb
PS
65$chapters = book_preload_chapters($book);
66
1cc316b7
PS
67$strbooks = get_string('modulenameplural', 'mod_book');
68$strbook = get_string('modulename', 'mod_book');
69$strtop = get_string('top', 'mod_book');
02039379 70
15b3c4e0 71// Page header.
8cf64176 72$strtitle = format_string($book->name, true, array('context' => $context));
15b3c4e0
JC
73$PAGE->set_title($strtitle);
74$PAGE->set_heading($strtitle);
d8389cd6 75$PAGE->requires->css('/mod/book/tool/print/print.css');
15b3c4e0 76
8cf64176
MG
77$renderer = $PAGE->get_renderer('booktool_print');
78
15b3c4e0
JC
79// Begin page output.
80echo $OUTPUT->header();
02039379 81
02039379 82if ($chapter) {
ee952cbb
PS
83 if ($chapter->hidden) {
84 require_capability('mod/book:viewhiddenchapters', $context);
85 }
ef2a9ece 86 \booktool_print\event\chapter_printed::create_from_chapter($book, $context, $chapter)->trigger();
8cf64176 87 $page = new booktool_print\output\print_book_chapter_page($book, $cm, $chapter);
02039379 88} else {
ef2a9ece 89 \booktool_print\event\book_printed::create_from_book($book, $context)->trigger();
8cf64176 90 $page = new booktool_print\output\print_book_page($book, $cm);
02039379
PS
91}
92
8cf64176
MG
93echo $renderer->render($page);
94
15b3c4e0
JC
95// Finish page output.
96echo $OUTPUT->footer();