fixed log action inserts
[moodle.git] / toc.php
CommitLineData
02039379
PS
1<?PHP // $Id: toc.php,v 1.1 2006/03/12 18:39:59 skodak Exp $
2
3defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
4
5/// included from mod/book/view.php and print.php
6///
7/// uses:
8/// $chapters - all book chapters
9/// $chapter - may be false
10/// $cm - course module
11/// $book - book
12/// $edit - force editing view
13
14
15/// fills:
16/// $toc
17/// $title (not for print)
18
19$currtitle = ''; //active chapter title (plain text)
20$currsubtitle = ''; //active subchapter if any
21$prevtitle = '&nbsp;';
22$toc = ''; //representation of toc (HTML)
23
24$nch = 0; //chapter number
25$ns = 0; //subchapter number
26$title = '';
27$first = 1;
28
29if (!isset($print)) {
30 $print = 0;
31}
32
33switch ($book->numbering) {
34 case NUM_NONE:
35 $toc .= '<div class="book_toc_none">';
36 break;
37 case NUM_NUMBERS:
38 $toc .= '<div class="book_toc_numbered">';
39 break;
40 case NUM_BULLETS:
41 $toc .= '<div class="book_toc_bullets">';
42 break;
43 case NUM_INDENTED:
44 $toc .= '<div class="book_toc_indented">';
45 break;
46}
47
48
49if ($print) { ///TOC for printing
50 $toc .= '<a name="toc"></a>';
51 if ($book->customtitles) {
52 $toc .= '<h1>'.get_string('toc', 'book').'</h1>';
53 } else {
54 $toc .= '<p class="book_chapter_title">'.get_string('toc', 'book').'</p>';
55 }
56 $titles = array();
57 $toc .= '<ul>';
58 foreach($chapters as $ch) {
59 $title = trim(strip_tags($ch->title));
60 if (!$ch->hidden) {
61 if (!$ch->subchapter) {
62 $nch++;
63 $ns = 0;
64 $toc .= ($first) ? '<li>' : '</ul></li><li>';
65 if ($book->numbering === NUM_NUMBERS) {
66 $title = "$nch $title";
67 }
68 } else {
69 $ns++;
70 $toc .= ($first) ? '<li><ul><li>' : '<li>';
71 if ($book->numbering === NUM_NUMBERS) {
72 $title = "$nch.$ns $title";
73 }
74 }
75 $titles[$ch->id] = $title;
76 $toc .= '<a title="'.htmlspecialchars($title).'" href="#ch'.$ch->id.'">'.$title.'</a>';
77 $toc .= (!$ch->subchapter) ? '<ul>' : '</li>';
78 $first = 0;
79 }
80 }
81 $toc .= '</ul></li></ul>';
82} else if ($edit) { ///teacher's TOC
83 $toc .= '<font size="-1"><ul>';
84 $i = 0;
85 foreach($chapters as $ch) {
86 $i++;
87 $title = trim(strip_tags($ch->title));
88 if (!$ch->subchapter) {
89 $toc .= ($first) ? '<li>' : '</ul></li><li>';
90 if (!$ch->hidden) {
91 $nch++;
92 $ns = 0;
93 if ($book->numbering === NUM_NUMBERS) {
94 $title = "$nch $title";
95 }
96 } else {
97 if ($book->numbering === NUM_NUMBERS) {
98 $title = "x $title";
99 }
100 $title = '<span class="dimmed_text">'.$title.'</span>';
101 }
102 $prevtitle = $title;
103 } else {
104 $toc .= ($first) ? '<li><ul><li>' : '<li>';
105 if (!$ch->hidden) {
106 $ns++;
107 if ($book->numbering === NUM_NUMBERS) {
108 $title = "$nch.$ns $title";
109 }
110 } else {
111 if ($book->numbering === NUM_NUMBERS) {
112 $title = "x.x $title";
113 }
114 $title = '<span class="dimmed_text">'.$title.'</span>';
115 }
116 }
117
118 if ($ch->id === $chapter->id) {
119 $toc .= '<strong>'.$title.'</strong>';
120 if ($ch->subchapter) {
121 $currtitle = $prevtitle;
122 $currsubtitle = $title;
123 } else {
124 $currtitle = $title;
125 $currsubtitle = '&nbsp;';
126 }
127 } else {
128 $toc .= '<a title="'.htmlspecialchars($title).'" href="view.php?id='.$cm->id.'&chapterid='.$ch->id.'">'.$title.'</a>';
129 }
130 $toc .= '&nbsp;&nbsp;';
131 if ($i != 1) {
132 $toc .= ' <a title="'.get_string('up').'" href="move.php?id='.$cm->id.'&chapterid='.$ch->id.'&up=1&sesskey='.$USER->sesskey.'"><img src="'.$CFG->pixpath.'/t/up.gif" height="11" width="11" border="0" /></a>';
133 }
134 if ($i != count($chapters)) {
135 $toc .= ' <a title="'.get_string('down').'" href="move.php?id='.$cm->id.'&chapterid='.$ch->id.'&up=0&sesskey='.$USER->sesskey.'"><img src="'.$CFG->pixpath.'/t/down.gif" height="11" width="11" border="0" /></a>';
136 }
137 $toc .= ' <a title="'.get_string('edit').'" href="edit.php?id='.$cm->id.'&chapterid='.$ch->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" height="11" width="11" border="0" /></a>';
138 $toc .= ' <a title="'.get_string('delete').'" href="delete.php?id='.$cm->id.'&chapterid='.$ch->id.'&sesskey='.$USER->sesskey.'"><img src="'.$CFG->pixpath.'/t/delete.gif" height="11" width="11" border="0" /></a>';
139 if ($ch->hidden) {
140 $toc .= ' <a title="'.get_string('show').'" href="show.php?id='.$cm->id.'&chapterid='.$ch->id.'&sesskey='.$USER->sesskey.'"><img src="'.$CFG->pixpath.'/t/show.gif" height="11" width="11" border="0" /></a>';
141 } else {
142 $toc .= ' <a title="'.get_string('hide').'" href="show.php?id='.$cm->id.'&chapterid='.$ch->id.'&sesskey='.$USER->sesskey.'"><img src="'.$CFG->pixpath.'/t/hide.gif" height="11" width="11" border="0" /></a>';
143 }
144 $toc .= ' <a title="'.get_string('addafter', 'book').'" href="edit.php?id='.$cm->id.'&pagenum='.$ch->pagenum.'&subchapter='.$ch->subchapter.'"><img src="pix/add.gif" height="11" width="11" border="0" /></a>';
145
146 $toc .= (!$ch->subchapter) ? '<ul>' : '</li>';
147 $first = 0;
148 }
149 $toc .= '</ul></li></ul></font>';
150} else { //normal students view
151 $toc .= '<font size="-1"><ul>';
152 foreach($chapters as $ch) {
153 $title = trim(strip_tags($ch->title));
154 if (!$ch->hidden) {
155 if (!$ch->subchapter) {
156 $nch++;
157 $ns = 0;
158 $toc .= ($first) ? '<li>' : '</ul></li><li>';
159 if ($book->numbering === NUM_NUMBERS) {
160 $title = "$nch $title";
161 }
162 $prevtitle = $title;
163 } else {
164 $ns++;
165 $toc .= ($first) ? '<li><ul><li>' : '<li>';
166 if ($book->numbering === NUM_NUMBERS) {
167 $title = "$nch.$ns $title";
168 }
169 }
170 if ($ch->id === $chapter->id) {
171 $toc .= '<strong>'.$title.'</strong>';
172 if ($ch->subchapter) {
173 $currtitle = $prevtitle;
174 $currsubtitle = $title;
175 } else {
176 $currtitle = $title;
177 $currsubtitle = '&nbsp;';
178 }
179 } else {
180 $toc .= '<a title="'.htmlspecialchars($title).'" href="view.php?id='.$cm->id.'&chapterid='.$ch->id.'">'.$title.'</a>';
181 }
182 $toc .= (!$ch->subchapter) ? '<ul>' : '</li>';
183 $first = 0;
184 }
185 }
186 $toc .= '</ul></li></ul></font>';
187}
188
189$toc .= '</div>';
190
191$toc = str_replace('<ul></ul>', '', $toc); //cleanup of invalid structures
192
193?>