Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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 printing
19
 *
20
 * @package    booktool_print
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(__DIR__.'/../../../../config.php');
1441 ariadna 26
require_once(__DIR__.'/lib.php');
27
require_once(__DIR__.'/../../locallib.php');
1 efrain 28
 
29
$id        = required_param('id', PARAM_INT);           // Course Module ID
30
$chapterid = optional_param('chapterid', 0, PARAM_INT); // Chapter ID
31
 
32
// =========================================================================
33
// security checks START - teachers and students view
34
// =========================================================================
35
 
36
$cm = get_coursemodule_from_id('book', $id, 0, false, MUST_EXIST);
37
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
38
$book = $DB->get_record('book', array('id' => $cm->instance), '*', MUST_EXIST);
39
 
40
require_course_login($course, true, $cm);
41
 
42
$context = context_module::instance($cm->id);
43
require_capability('mod/book:read', $context);
44
require_capability('booktool/print:print', $context);
45
 
46
// Check all variables.
47
if ($chapterid) {
48
    // Single chapter printing - only visible!
49
    $chapter = $DB->get_record('book_chapters', array('id' => $chapterid, 'bookid' => $book->id), '*',
50
            MUST_EXIST);
51
} else {
52
    // Complete book.
53
    $chapter = false;
54
}
55
 
56
$PAGE->set_url('/mod/book/print.php', array('id' => $id, 'chapterid' => $chapterid));
57
 
58
$PAGE->activityheader->disable();
59
$PAGE->set_pagelayout("embedded");
60
 
61
unset($id);
62
unset($chapterid);
63
 
64
// Security checks END.
65
 
66
// read chapters
67
$chapters = book_preload_chapters($book);
68
 
69
$strbooks = get_string('modulenameplural', 'mod_book');
70
$strbook  = get_string('modulename', 'mod_book');
71
$strtop   = get_string('top', 'mod_book');
72
 
73
// Page header.
74
$strtitle = format_string($book->name, true, array('context' => $context));
75
$PAGE->set_title($strtitle);
76
$PAGE->set_heading($strtitle);
77
$PAGE->requires->css('/mod/book/tool/print/print.css');
78
 
79
$renderer = $PAGE->get_renderer('booktool_print');
80
 
81
// Begin page output.
82
echo $OUTPUT->header();
83
 
84
if ($chapter) {
85
    if ($chapter->hidden) {
86
        require_capability('mod/book:viewhiddenchapters', $context);
87
    }
88
    \booktool_print\event\chapter_printed::create_from_chapter($book, $context, $chapter)->trigger();
89
    $page = new booktool_print\output\print_book_chapter_page($book, $cm, $chapter);
90
} else {
91
    \booktool_print\event\book_printed::create_from_book($book, $context)->trigger();
92
    $page = new booktool_print\output\print_book_page($book, $cm);
93
}
94
 
95
echo $renderer->render($page);
96
 
97
// Finish page output.
98
echo $OUTPUT->footer();