fixed log action inserts
[moodle.git] / view.php
CommitLineData
02039379
PS
1<?PHP // $Id: view.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$edit = optional_param('edit', -1, PARAM_BOOL); // Edit mode
9
10// =========================================================================
11// security checks START - teachers edit; students view
12// =========================================================================
13if ($CFG->forcelogin) {
14 require_login();
15}
16
17if (!$cm = get_record('course_modules', 'id', $id)) {
18 error('Course Module ID is incorrect');
19}
20
21if (!$course = get_record('course', 'id', $cm->course)) {
22 error('Course is misconfigured');
23}
24
25if ($course->category) {
26 require_login($course->id);
27}
28
29if (!$book = get_record('book', 'id', $cm->instance)) {
30 error('Course module is incorrect');
31}
32
33$isteacher = isteacheredit($course->id);
34if ($isteacher) {
35 if($edit != -1) {
36 $USER->editing = $edit;
37 } else {
38 if (isset($USER->editing)) {
39 $edit = $USER->editing;
40 } else {
41 $edit = 0;
42 }
43 }
44} else {
45 $edit = 0;
46}
47
48if (!$cm->visible and !$isteacher) {
49 notice(get_string('activityiscurrentlyhidden'));
50}
51
52/// read chapters
53$select = $isteacher ? "bookid = $book->id" : "bookid = $book->id AND hidden = 0";
54$chapters = get_records_select('book_chapters', $select, 'pagenum', 'id, pagenum, subchapter, title, hidden');
55
56if (!$chapters) {
57 if ($isteacher) {
58 redirect('edit.php?id='.$cm->id); //no chapters - add new one
59 die;
60 } else {
61 error('Error reading book chapters.');
62 }
63}
64/// check chapterid and read chapter data
65if ($chapterid == '0') { // go to first chapter if no given
66 foreach($chapters as $ch) {
67 if ($isteacher) {
68 $chapterid = $ch->id;
69 break;
70 }
71 if (!$ch->hidden) {
72 $chapterid = $ch->id;
73 break;
74 }
75 }
76}
77
78
79if (!$chapter = get_record('book_chapters', 'id', $chapterid)) {
80 error('Error reading book chapters.');
81}
82
83//check all variables
84unset($id);
85unset($chapterid);
86
87/// chapter is hidden for students
88if (!$isteacher and $chapter->hidden) {
89 error('Error reading book chapters.');
90}
91
92/// chapter not part of this book!
93if ($chapter->bookid != $book->id) {
94 error('Chapter not part of this book!');
95}
96// =========================================================================
97// security checks END
98// =========================================================================
99
100add_to_log($course->id, 'book', 'view', 'view.php?id='.$cm->id.'&chapterid='.$chapter->id, $book->id, $cm->id);
101
102
103///read standard strings
104$strbooks = get_string('modulenameplural', 'book');
105$strbook = get_string('modulename', 'book');
106$strTOC = get_string('TOC', 'book');
107
108/// prepare header
109if ($course->category) {
110 $navigation = '<a href="../../course/view.php?id='.$course->id.'">'.$course->shortname.'</a> ->';
111} else {
112 $navigation = '';
113}
114
115$buttons = $isteacher ? '<table cellspacing="0" cellpadding="0"><tr><td>'.update_module_button($cm->id, $course->id, $strbook).'</td>'.
116 '<td>&nbsp;</td><td>'.book_edit_button($cm->id, $course->id, $chapter->id).'</td></tr></table>'
117 : '&nbsp;';
118
119print_header( "$course->shortname: $book->name ($chapter->title)",
120 $course->fullname,
121 "$navigation <a href=\"index.php?id=$course->id\">$strbooks</a> -> $book->name",
122 '',
123 '<style type="text/css">@import url('.$CFG->wwwroot.'/mod/book/book_theme.css);</style>',
124 true,
125 $buttons,
126 navmenu($course, $cm)
127 );
128
129
130/// prepare chapter navigation icons
131$previd = null;
132$nextid = null;
133$found = 0;
134foreach ($chapters as $ch) {
135 if ($found) {
136 $nextid= $ch->id;
137 break;
138 }
139 if ($ch->id == $chapter->id) {
140 $found = 1;
141 }
142 if (!$found) {
143 $previd = $ch->id;
144 }
145}
146if ($ch == current($chapters)) {
147 $nextid = $ch->id;
148}
149$chnavigation = '';
150if ($previd) {
151 $chnavigation .= '<a title="'.get_string('navprev', 'book').'" href="view.php?id='.$cm->id.'&chapterid='.$previd.'"><img src="pix/nav_prev.gif" height="24" width="24" border="0"></img></a>';
152} else {
153 $chnavigation .= '<img src="pix/nav_prev_dis.gif" height="24" width="24" border="0"></img>';
154}
155$chnavigation .= '&nbsp;&nbsp;<img src="pix/nav_sep.gif" height="24" width="2" border="0"></img>&nbsp;&nbsp;';
156if ($nextid) {
157 $chnavigation .= '<a title="'.get_string('navnext', 'book').'" href="view.php?id='.$cm->id.'&chapterid='.$nextid.'"><img src="pix/nav_next.gif" height="24" width="24" border="0"></img></a>';
158} else {
159 $sec = '';
160 if ($section = get_record('course_sections', 'id', $cm->section)) {
161 $sec = $section->section;
162 }
163 $chnavigation .= '<a title="'.get_string('navexit', 'book').'" href="../../course/view.php?id='.$course->id.'#section-'.$sec.'"><img src="pix/nav_exit.gif" height="24" width="24" border="0"></img></a>';
164}
165
166/// prepare print icons
167if ($book->disableprinting) {
168 $printbook = '';
169 $printchapter = '';
170} else {
171 $printbook = '<a title="'.get_string('printbook', 'book').'" href="print.php?id='.$cm->id.'" target="_blank"><img src="pix/print_book.gif" height="24" width="24" border="0"></img></a>';
172 $printchapter = '<a title="'.get_string('printchapter', 'book').'" href="print.php?id='.$cm->id.'&chapterid='.$chapter->id.'" target="_blank"><img src="pix/print_chapter.gif" height="24" width="24" border="0"></img></a>';
173}
174
175// prepare $toc and $currtitle, $currsubtitle
176require('toc.php');
177
178if ($edit) {
179 $tocwidth = $CFG->book_tocwidth + 80;
180} else {
181 $tocwidth = $CFG->book_tocwidth;
182}
183
184$doimport = ($isteacher and $edit) ? '<font size="-1"> (<a href="import.php?id='.$cm->id.'">'.get_string('doimport', 'book').'</a>)</font>' : '';
185
186
187// =====================================================
188// Book display HTML code
189// =====================================================
190
191?>
192<table border="0" cellspacing="0" width="100%" valign="top" cellpadding="2">
193
194<!-- subchapter title and upper navigation row //-->
195<tr>
196 <td width="<?php echo $tocwidth ?>" valign="bottom">
197 <?php print_string('toc', 'book'); echo $doimport; ?>
198 </td>
199 <td valign="top">
200 <table border="0" cellspacing="0" width="100%" valign="top" cellpadding="0">
201 <tr>
202 <td nowrap align="left"><?php echo $printbook.'&nbsp'.$printchapter ?></td>
203 <td nowrap align="right"><?php echo $chnavigation ?></td>
204 </tr>
205 </table>
206 </td>
207</tr>
208
209<!-- toc and chapter row //-->
210<tr>
211 <td width="<?php echo $tocwidth ?>" valign="top" align="left">
212 <?php
213 print_simple_box_start('middle', '100%');
214 echo $toc;
215 print_simple_box_end();
216 if ($isteacher and $edit) {
217 echo '<font size="1"><br />';
218 helpbutton('faq', get_string('faq','book'), 'book', true, true);
219 echo '</font>';
220 }
221 ?>
222 </td>
223 <td valign="top" align="right">
224 <?php
225 print_simple_box_start('middle', '100%');
226 $content = '';
227 if (!$book->customtitles) {
228 if ($currsubtitle == '&nbsp;') {
229 $content .= '<p class="book_chapter_title">'.$currtitle.'<p>';
230 } else {
231 $content .= '<p class="book_chapter_title">'.$currtitle.'<br />'.$currsubtitle.'</p>';
232 }
233 }
234 $content .= $chapter->content;
235
236 $nocleanoption = new object();
237 $nocleanoption->noclean = true;
238 echo '<div class="book_content">';
239 echo format_text($content, FORMAT_HTML, $nocleanoption, $course->id);
240 echo '</div>';
241 print_simple_box_end();
242 /// lower navigation
243 echo '<p>'.$chnavigation.'<p>';
244 ?>
245 </td>
246</tr>
247</table>
248
249<?php
250print_footer($course);
251
252?>