Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403]

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