Fix A tag regex searching in book. MDL-15842 ; merged from 19_STABLE
[moodle.git] / print.php
CommitLineData
dab784a3 1<?PHP // $Id: print.php,v 1.2 2007/05/20 06:00:26 skodak Exp $
02039379
PS
2
3require_once('../../config.php');
4require_once('lib.php');
5
6$id = required_param('id', PARAM_INT); // Course Module ID
7$chapterid = optional_param('chapterid', 0, PARAM_INT); // Chapter ID
8
9// =========================================================================
10// security checks START - teachers and students view
11// =========================================================================
dab784a3 12if (!$cm = get_coursemodule_from_id('book', $id)) {
02039379
PS
13 error('Course Module ID was incorrect');
14}
15
16if (!$course = get_record('course', 'id', $cm->course)) {
17 error('Course is misconfigured');
18}
19
dab784a3 20require_course_login($course, true, $cm);
02039379
PS
21
22if (!$book = get_record('book', 'id', $cm->instance)) {
23 error('Course module is incorrect');
24}
25
26if ($book->disableprinting) {
27 error('Printing is disabled');
28}
29
30//check all variables
31if ($chapterid) {
32 //single chapter printing
33 if (!$chapter = get_record('book_chapters', 'id', $chapterid)) {
34 error('Incorrect chapter ID');
35 }
36 if ($chapter->bookid != $book->id) {//chapter id not in this book!!!!
37 error('Chapter not in this book!');
38 }
39 if ($chapter->hidden) {
40 error('Only visible chapters can be printed');
41 }
42} else {
43 //complete book
44 $chapter = false;
45}
46unset($id);
47unset($chapterid);
48// =========================================================================
49// security checks END
50// =========================================================================
51
52$strbooks = get_string('modulenameplural', 'book');
53$strbook = get_string('modulename', 'book');
dab784a3 54$strtop = get_string('top', 'book');
02039379
PS
55
56@header('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
57@header('Pragma: no-cache');
58@header('Expires: ');
59@header('Accept-Ranges: none');
dab784a3 60@header('Content-type: text/html; charset=utf-8');
02039379 61
dab784a3 62$formatoptions = new object();
02039379
PS
63$formatoptions->noclean = true;
64
65if ($chapter) {
66 add_to_log($course->id, 'book', 'print', 'print.php?id='.$cm->id.'&chapterid='.$chapter->id, $book->id, $cm->id);
67
68 $chapters = get_records('book_chapters', 'bookid', $book->id, 'pagenum, title');
69
70 $print = 0;
71 $edit = 0;
72 require('toc.php');
73
74 /// page header
75 ?>
76 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
77 <html>
78 <head>
dab784a3
PS
79 <title><?PHP echo format_string($book->name) ?></title>
80 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
81 <meta name="description" content="<?PHP echo s(format_string($book->name)) ?>" />
02039379
PS
82 <link rel="stylesheet" type="text/css" href="book_print.css" />
83 </head>
84 <body>
85 <a name="top"></a>
86 <div class="chapter">
87 <?PHP
88
89 if (!$book->customtitles) {
90 if ($currsubtitle == '&nbsp;') {
91 echo '<p class="book_chapter_title">'.$currtitle.'<p>';
92 } else {
93 echo '<p class="book_chapter_title">'.$currtitle.'<br />'.$currsubtitle.'</p>';
94 }
95 }
96 echo format_text($chapter->content, FORMAT_HTML, $formatoptions, $course->id);
97 echo '</div>';
98 echo '</body> </html>';
99
100} else {
101 add_to_log($course->id, 'book', 'print', 'print.php?id='.$cm->id, $book->id, $cm->id);
102 $site = get_record('course','id',1);
103 $chapters = get_records('book_chapters', 'bookid', $book->id, 'pagenum');
104
105 /// page header
106 ?>
107 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
108 <html>
109 <head>
dab784a3 110 <title><?PHP echo format_string(name) ?></title>
02039379 111 <meta http-equiv="Content-Type" content="text/html; charset=<?PHP echo $encoding ?>" />
dab784a3 112 <meta name="description" content="<?PHP echo s(format_string($book->name)) ?>" />
02039379
PS
113 <link rel="stylesheet" type="text/css" href="book_print.css" />
114 </head>
115 <body>
116 <a name="top"></a>
dab784a3
PS
117 <p class="book_title"><?PHP echo format_string($book->name) ?></p>
118 <p class="book_summary"><?PHP echo format_string($book->summary) ?></p>
02039379
PS
119 <div class="book_info"><table>
120 <tr>
121 <td><?PHP echo get_string('site') ?>:</td>
dab784a3 122 <td><a href="<?PHP echo $CFG->wwwroot ?>"><?PHP echo format_string($site->fullname) ?></a></td>
02039379
PS
123 </tr><tr>
124 <td><?PHP echo get_string('course') ?>:</td>
dab784a3 125 <td><?PHP echo format_string($course->fullname) ?></td>
02039379
PS
126 </tr><tr>
127 <td><?PHP echo get_string('modulename', 'book') ?>:</td>
dab784a3 128 <td><?PHP echo format_string($book->name) ?></td>
02039379
PS
129 </tr><tr>
130 <td><?PHP echo get_string('printedby', 'book') ?>:</td>
dab784a3 131 <td><?PHP echo format_string(fullname($USER, true)) ?></td>
02039379
PS
132 </tr><tr>
133 <td><?PHP echo get_string('printdate','book') ?>:</td>
134 <td><?PHP echo userdate(time()) ?></td>
135 </tr>
136 </table></div>
137
138 <?PHP
139 $print = 1;
140 require('toc.php');
141 echo $toc;
142 // chapters
143 $link1 = $CFG->wwwroot.'/mod/book/view.php?id='.$course->id.'&chapterid=';
144 $link2 = $CFG->wwwroot.'/mod/book/view.php?id='.$course->id;
145 foreach ($chapters as $ch) {
146 if (!$ch->hidden) {
147 echo '<div class="book_chapter"><a name="ch'.$ch->id.'"></a>';
148 if (!$book->customtitles) {
149 echo '<p class="book_chapter_title">'.$titles[$ch->id].'</p>';
150 }
151 $content = str_replace($link1, '#ch', $ch->content);
152 $content = str_replace($link2, '#top', $content);
153 echo format_text($content, FORMAT_HTML, $formatoptions, $course->id);
154 echo '</div>';
155 //echo '<a href="#toc">'.$strtop.'</a>';
156
157 }
158 }
159 echo '</body> </html>';
160}
161
162?>