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