[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/book/tool/print/ -> index.php (source)

   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(dirname(__FILE__).'/../../../../config.php');
  26  require_once(dirname(__FILE__).'/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), '*', MUST_EXIST);
  49  } else {
  50      // Complete book.
  51      $chapter = false;
  52  }
  53  
  54  $PAGE->set_url('/mod/book/print.php', array('id'=>$id, 'chapterid'=>$chapterid));
  55  
  56  unset($id);
  57  unset($chapterid);
  58  
  59  // Security checks END.
  60  
  61  // read chapters
  62  $chapters = book_preload_chapters($book);
  63  
  64  $strbooks = get_string('modulenameplural', 'mod_book');
  65  $strbook  = get_string('modulename', 'mod_book');
  66  $strtop   = get_string('top', 'mod_book');
  67  
  68  @header('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
  69  @header('Pragma: no-cache');
  70  @header('Expires: ');
  71  @header('Accept-Ranges: none');
  72  @header('Content-type: text/html; charset=utf-8');
  73  
  74  if ($chapter) {
  75  
  76      if ($chapter->hidden) {
  77          require_capability('mod/book:viewhiddenchapters', $context);
  78      }
  79      \booktool_print\event\chapter_printed::create_from_chapter($book, $context, $chapter)->trigger();
  80  
  81      // page header
  82      ?>
  83      <!DOCTYPE HTML>
  84      <html>
  85      <head>
  86        <title><?php echo format_string($book->name, true, array('context'=>$context)) ?></title>
  87        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  88        <meta name="description" content="<?php echo s(format_string($book->name, true, array('context'=>$context))) ?>" />
  89        <link rel="stylesheet" type="text/css" href="print.css" />
  90      </head>
  91      <body>
  92      <?php
  93      // Print dialog link.
  94      $printtext = get_string('printchapter', 'booktool_print');
  95      $printicon = $OUTPUT->pix_icon('chapter', $printtext, 'booktool_print', array('class' => 'book_print_icon'));
  96      $printlinkatt = array('onclick' => 'window.print();return false;', 'class' => 'book_no_print');
  97      echo html_writer::link('#', $printicon.$printtext, $printlinkatt);
  98      ?>
  99      <a name="top"></a>
 100      <?php
 101      echo $OUTPUT->heading(format_string($book->name, true, array('context'=>$context)), 1);
 102      ?>
 103      <div class="chapter">
 104      <?php
 105  
 106  
 107      if (!$book->customtitles) {
 108          if (!$chapter->subchapter) {
 109              $currtitle = book_get_chapter_title($chapter->id, $chapters, $book, $context);
 110              echo $OUTPUT->heading($currtitle);
 111          } else {
 112              $currtitle = book_get_chapter_title($chapters[$chapter->id]->parent, $chapters, $book, $context);
 113              $currsubtitle = book_get_chapter_title($chapter->id, $chapters, $book, $context);
 114              echo $OUTPUT->heading($currtitle);
 115              echo $OUTPUT->heading($currsubtitle, 3);
 116          }
 117      }
 118  
 119      $chaptertext = file_rewrite_pluginfile_urls($chapter->content, 'pluginfile.php', $context->id, 'mod_book', 'chapter', $chapter->id);
 120      echo format_text($chaptertext, $chapter->contentformat, array('noclean'=>true, 'context'=>$context));
 121      echo '</div>';
 122      echo '</body> </html>';
 123  
 124  } else {
 125      \booktool_print\event\book_printed::create_from_book($book, $context)->trigger();
 126  
 127      $allchapters = $DB->get_records('book_chapters', array('bookid'=>$book->id), 'pagenum');
 128      $book->intro = file_rewrite_pluginfile_urls($book->intro, 'pluginfile.php', $context->id, 'mod_book', 'intro', null);
 129  
 130      // page header
 131      ?>
 132      <!DOCTYPE HTML>
 133      <html>
 134      <head>
 135        <title><?php echo format_string($book->name, true, array('context'=>$context)) ?></title>
 136        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 137        <meta name="description" content="<?php echo s(format_string($book->name, true, array('noclean'=>true, 'context'=>$context))) ?>" />
 138        <link rel="stylesheet" type="text/css" href="print.css" />
 139      </head>
 140      <body>
 141      <?php
 142      // Print dialog link.
 143      $printtext = get_string('printbook', 'booktool_print');
 144      $printicon = $OUTPUT->pix_icon('book', $printtext, 'booktool_print', array('class' => 'book_print_icon'));
 145      $printlinkatt = array('onclick' => 'window.print();return false;', 'class' => 'book_no_print');
 146      echo html_writer::link('#', $printicon.$printtext, $printlinkatt);
 147      ?>
 148      <a name="top"></a>
 149      <?php
 150      echo $OUTPUT->heading(format_string($book->name, true, array('context'=>$context)), 1);
 151      ?>
 152      <p class="book_summary"><?php echo format_text($book->intro, $book->introformat, array('noclean'=>true, 'context'=>$context)) ?></p>
 153      <div class="book_info"><table>
 154      <tr>
 155      <td><?php echo get_string('site') ?>:</td>
 156      <td><a href="<?php echo $CFG->wwwroot ?>"><?php echo format_string($SITE->fullname, true, array('context'=>$context)) ?></a></td>
 157      </tr><tr>
 158      <td><?php echo get_string('course') ?>:</td>
 159      <td><?php echo format_string($course->fullname, true, array('context'=>$context)) ?></td>
 160      </tr><tr>
 161      <td><?php echo get_string('modulename', 'mod_book') ?>:</td>
 162      <td><?php echo format_string($book->name, true, array('context'=>$context)) ?></td>
 163      </tr><tr>
 164      <td><?php echo get_string('printedby', 'booktool_print') ?>:</td>
 165      <td><?php echo fullname($USER, true) ?></td>
 166      </tr><tr>
 167      <td><?php echo get_string('printdate', 'booktool_print') ?>:</td>
 168      <td><?php echo userdate(time()) ?></td>
 169      </tr>
 170      </table></div>
 171  
 172      <?php
 173      list($toc, $titles) = booktool_print_get_toc($chapters, $book, $cm);
 174      echo $toc;
 175      // chapters
 176      $link1 = $CFG->wwwroot.'/mod/book/view.php?id='.$course->id.'&chapterid=';
 177      $link2 = $CFG->wwwroot.'/mod/book/view.php?id='.$course->id;
 178      foreach ($chapters as $ch) {
 179          $chapter = $allchapters[$ch->id];
 180          if ($chapter->hidden) {
 181              continue;
 182          }
 183          echo '<div class="book_chapter"><a name="ch'.$ch->id.'"></a>';
 184          if (!$book->customtitles) {
 185              if (!$chapter->subchapter) {
 186                  echo $OUTPUT->heading($titles[$ch->id]);
 187              } else {
 188                  echo $OUTPUT->heading($titles[$ch->id], 3);
 189              }
 190          }
 191          $content = str_replace($link1, '#ch', $chapter->content);
 192          $content = str_replace($link2, '#top', $content);
 193          $content = file_rewrite_pluginfile_urls($content, 'pluginfile.php', $context->id, 'mod_book', 'chapter', $ch->id);
 194          echo format_text($content, $chapter->contentformat, array('noclean'=>true, 'context'=>$context));
 195          echo '</div>';
 196          // echo '<a href="#toc">'.$strtop.'</a>';
 197      }
 198      echo '</body> </html>';
 199  }
 200  


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1