MDL-12296:
[moodle.git] / course / format / topics / format.php
CommitLineData
dcb1bd3c 1<?php // $Id$
0b35af18 2 // Display the whole course as "topics" made of of modules
3 // In fact, this is very similar to the "weeks" format, in that
4 // each "topic" is actually a week. The main difference is that
0f3fe4b6 5 // the dates aren't printed - it's just an aesthetic thing for
0b35af18 6 // courses that aren't so rigidly defined by time.
7 // Included from "view.php"
a0bfbeaa 8
0b35af18 9
a0bfbeaa 10 require_once($CFG->libdir.'/ajax/ajaxlib.php');
f145c248 11
12 if (!empty($THEME->customcorners)) {
13 require_once($CFG->dirroot.'/lib/custom_corners_lib.php');
14 }
a0bfbeaa 15
0cdae0dc 16 $topic = optional_param('topic', -1, PARAM_INT);
17
0f3fe4b6 18 // Bounds for block widths
689456eb 19 // more flexible for theme designers taken from theme config.php
20 $lmin = (empty($THEME->block_l_min_width)) ? 100 : $THEME->block_l_min_width;
21 $lmax = (empty($THEME->block_l_max_width)) ? 210 : $THEME->block_l_max_width;
22 $rmin = (empty($THEME->block_r_min_width)) ? 100 : $THEME->block_r_min_width;
23 $rmax = (empty($THEME->block_r_max_width)) ? 210 : $THEME->block_r_max_width;
24
25 define('BLOCK_L_MIN_WIDTH', $lmin);
26 define('BLOCK_L_MAX_WIDTH', $lmax);
27 define('BLOCK_R_MIN_WIDTH', $rmin);
28 define('BLOCK_R_MAX_WIDTH', $rmax);
0f3fe4b6 29
870e3cad 30 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
31 BLOCK_L_MAX_WIDTH);
32 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
33 BLOCK_R_MAX_WIDTH);
0f3fe4b6 34
0cdae0dc 35 if ($topic != -1) {
b86fc0e2 36 $displaysection = course_set_display($course->id, $topic);
37 } else {
38 if (isset($USER->display[$course->id])) { // for admins, mostly
39 $displaysection = $USER->display[$course->id];
0b35af18 40 } else {
b86fc0e2 41 $displaysection = course_set_display($course->id, 0);
0b35af18 42 }
43 }
44
3924b988 45 $context = get_context_instance(CONTEXT_COURSE, $course->id);
46
47 if (($marker >=0) && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
0b35af18 48 $course->marker = $marker;
49 if (! set_field("course", "marker", $marker, "id", $course->id)) {
50 error("Could not mark that topic for this course");
51 }
52 }
53
a3f24f7c 54 $streditsummary = get_string('editsummary');
55 $stradd = get_string('add');
56 $stractivities = get_string('activities');
57 $strshowalltopics = get_string('showalltopics');
58 $strtopic = get_string('topic');
59 $strgroups = get_string('groups');
60 $strgroupmy = get_string('groupmy');
61 $editing = $PAGE->user_is_editing();
62
0f3fe4b6 63 if ($editing) {
1ea7c627 64 $strstudents = moodle_strtolower($course->students);
c46f27a3 65 $strtopichide = get_string('topichide', '', $strstudents);
66 $strtopicshow = get_string('topicshow', '', $strstudents);
67 $strmarkthistopic = get_string('markthistopic');
68 $strmarkedthistopic = get_string('markedthistopic');
69 $strmoveup = get_string('moveup');
70 $strmovedown = get_string('movedown');
dfec7b01 71 }
d897cae4 72
0b35af18 73
9a223597 74/// Layout the whole page as three big columns.
3b456f6a 75 echo '<table id="layout-table" cellspacing="0" summary="'.get_string('layouttable').'"><tr>';
7ff56f2d 76
0f3fe4b6 77/// The left column ...
d55c9a1f 78 $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
79 foreach ($lt as $column) {
80 switch ($column) {
81 case 'left':
f374fb10 82
dffd4bb9 83 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
bd792a75 84 echo '<td style="width:'.$preferred_width_left.'px" id="left-column">';
f145c248 85 if (!empty($THEME->customcorners)) print_custom_corners_start();
262cb5e0 86 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
f145c248 87 if (!empty($THEME->customcorners)) print_custom_corners_end();
0f3fe4b6 88 echo '</td>';
0b35af18 89 }
f3120024 90
d55c9a1f 91 break;
92 case 'middle':
9a223597 93/// Start main column
262cb5e0 94 echo '<td id="middle-column">';
f145c248 95 if (!empty($THEME->customcorners)) print_custom_corners_start();
5c355019 96 echo skip_main_destination();
0b35af18 97
446390fb 98 print_heading_block(get_string('topicoutline'), 'outline');
2c0411e2 99
3b456f6a 100 echo '<table class="topics" width="100%" summary="'.get_string('layouttable').'">';
9a223597 101
7977cffd 102/// If currently moving a file then show the current clipboard
103 if (ismoving($course->id)) {
c46f27a3 104 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname)));
105 $strcancel= get_string('cancel');
06959cfc 106 echo '<tr class="clipboard">';
107 echo '<td colspan="3">';
c46f27a3 108 echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.$USER->sesskey.'">'.$strcancel.'</a>)';
109 echo '</td>';
110 echo '</tr>';
7977cffd 111 }
112
0f3fe4b6 113/// Print Section 0
9a223597 114
1ea7c627 115 $section = 0;
116 $thissection = $sections[$section];
9a223597 117
1ea7c627 118 if ($thissection->summary or $thissection->sequence or isediting($course->id)) {
c1ac64b5 119 echo '<tr id="section-0" class="section main">';
06959cfc 120 echo '<td class="left side">&nbsp;</td>';
121 echo '<td class="content">';
40901069 122
123 echo '<div class="summary">';
179c9a50 124 $summaryformatoptions->noclean = true;
125 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
5f850588 126
61e75e95 127 if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
554cec9f 128 echo '<a title="'.$streditsummary.'" '.
129 ' href="editsection.php?id='.$thissection->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" '.
abcaf2cf 130 ' alt="'.$streditsummary.'" /></a><br /><br />';
9a223597 131 }
40901069 132 echo '</div>';
0f3fe4b6 133
1ea7c627 134 print_section($course, $thissection, $mods, $modnamesused);
0f3fe4b6 135
9a223597 136 if (isediting($course->id)) {
e0161bff 137 print_section_add_menus($course, $section, $modnames);
9a223597 138 }
0f3fe4b6 139
554cec9f 140 echo '</td>';
06959cfc 141 echo '<td class="right side">&nbsp;</td>';
c46f27a3 142 echo '</tr>';
c1ac64b5 143 echo '<tr class="section separator"><td colspan="3" class="spacer"></td></tr>';
9a223597 144 }
145
146
147/// Now all the normal modules by topic
148/// Everything below uses "section" terminology - each "section" is a topic.
149
150 $timenow = time();
151 $section = 1;
1d019652 152 $sectionmenu = array();
9a223597 153
b5fe4c93 154 while ($section <= $course->numsections) {
0b35af18 155
7d99d695 156 if (!empty($sections[$section])) {
157 $thissection = $sections[$section];
158
159 } else {
160 unset($thissection);
161 $thissection->course = $course->id; // Create a new section structure
162 $thissection->section = $section;
c46f27a3 163 $thissection->summary = '';
7d99d695 164 $thissection->visible = 1;
c46f27a3 165 if (!$thissection->id = insert_record('course_sections', $thissection)) {
166 notify('Error inserting new topic!');
7d99d695 167 }
168 }
169
3924b988 170 $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
0b35af18 171
8dc93b94 172 if (!empty($displaysection) and $displaysection != $section) {
173 if ($showsection) {
a35ae3ef 174 $strsummary = strip_tags(format_string($thissection->summary,true));
8dc93b94 175 if (strlen($strsummary) < 57) {
176 $strsummary = ' - '.$strsummary;
177 } else {
178 $strsummary = ' - '.substr($strsummary, 0, 60).'...';
179 }
180 $sectionmenu['topic='.$section] = s($section.$strsummary);
181 }
182 $section++;
183 continue;
184 }
185
db7da819 186 if ($showsection) {
187
188 $currenttopic = ($course->marker == $section);
189
e9b9c1d8 190 $currenttext = '';
db7da819 191 if (!$thissection->visible) {
06959cfc 192 $sectionstyle = ' hidden';
db7da819 193 } else if ($currenttopic) {
06959cfc 194 $sectionstyle = ' current';
e9b9c1d8 195 $currenttext = get_accesshide(get_string('currenttopic','access'));
db7da819 196 } else {
06959cfc 197 $sectionstyle = '';
db7da819 198 }
0b35af18 199
c1ac64b5 200 echo '<tr id="section-'.$section.'" class="section main'.$sectionstyle.'">';
e9b9c1d8 201 echo '<td class="left side">'.$currenttext.$section.'</td>';
5f850588 202
549f7213 203 echo '<td class="content">';
3924b988 204 if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) { // Hidden for students
c46f27a3 205 echo get_string('notavailable');
eccc37c0 206 } else {
40901069 207 echo '<div class="summary">';
179c9a50 208 $summaryformatoptions->noclean = true;
209 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
0f3fe4b6 210
61e75e95 211 if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
c4bff2fb 212 echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
abcaf2cf 213 '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$streditsummary.'" /></a><br /><br />';
eccc37c0 214 }
40901069 215 echo '</div>';
0f3fe4b6 216
eccc37c0 217 print_section($course, $thissection, $mods, $modnamesused);
7d99d695 218
eccc37c0 219 if (isediting($course->id)) {
e0161bff 220 print_section_add_menus($course, $section, $modnames);
eccc37c0 221 }
7d99d695 222 }
549f7213 223 echo '</td>';
0b35af18 224
549f7213 225 echo '<td class="right side">';
eccc37c0 226 if ($displaysection == $section) { // Show the zoom boxes
0cdae0dc 227 echo '<a href="view.php?id='.$course->id.'&amp;topic=0#section-'.$section.'" title="'.$strshowalltopics.'">'.
abcaf2cf 228 '<img src="'.$CFG->pixpath.'/i/all.gif" alt="'.$strshowalltopics.'" /></a><br />';
ff828023 229 } else {
c46f27a3 230 $strshowonlytopic = get_string('showonlytopic', '', $section);
231 echo '<a href="view.php?id='.$course->id.'&amp;topic='.$section.'" title="'.$strshowonlytopic.'">'.
abcaf2cf 232 '<img src="'.$CFG->pixpath.'/i/one.gif" alt="'.$strshowonlytopic.'" /></a><br />';
12905134 233 }
234
217a8ee9 235 if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
eccc37c0 236 if ($course->marker == $section) { // Show the "light globe" on/off
4baeb9b0 237 echo '<a href="view.php?id='.$course->id.'&amp;marker=0&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strmarkedthistopic.'">'.
abcaf2cf 238 '<img src="'.$CFG->pixpath.'/i/marked.gif" alt="'.$strmarkedthistopic.'" /></a><br />';
eccc37c0 239 } else {
4baeb9b0 240 echo '<a href="view.php?id='.$course->id.'&amp;marker='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strmarkthistopic.'">'.
abcaf2cf 241 '<img src="'.$CFG->pixpath.'/i/marker.gif" alt="'.$strmarkthistopic.'" /></a><br />';
eccc37c0 242 }
243
244 if ($thissection->visible) { // Show the hide/show eye
4baeb9b0 245 echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strtopichide.'">'.
abcaf2cf 246 '<img src="'.$CFG->pixpath.'/i/hide.gif" alt="'.$strtopichide.'" /></a><br />';
eccc37c0 247 } else {
58de1815 248 echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strtopicshow.'">'.
abcaf2cf 249 '<img src="'.$CFG->pixpath.'/i/show.gif" alt="'.$strtopicshow.'" /></a><br />';
eccc37c0 250 }
251
252 if ($section > 1) { // Add a arrow to move section up
1bc6fc82 253 echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=-1&amp;sesskey='.$USER->sesskey.'#section-'.($section-1).'" title="'.$strmoveup.'">'.
abcaf2cf 254 '<img src="'.$CFG->pixpath.'/t/up.gif" alt="'.$strmoveup.'" /></a><br />';
eccc37c0 255 }
256
257 if ($section < $course->numsections) { // Add a arrow to move section down
1bc6fc82 258 echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=1&amp;sesskey='.$USER->sesskey.'#section-'.($section+1).'" title="'.$strmovedown.'">'.
abcaf2cf 259 '<img src="'.$CFG->pixpath.'/t/down.gif" alt="'.$strmovedown.'" /></a><br />';
eccc37c0 260 }
12905134 261
7d99d695 262 }
0b35af18 263
c46f27a3 264 echo '</td></tr>';
c1ac64b5 265 echo '<tr class="section separator"><td colspan="3" class="spacer"></td></tr>';
0b35af18 266 }
ff828023 267
b5fe4c93 268 $section++;
0b35af18 269 }
c46f27a3 270 echo '</table>';
1d019652 271
272 if (!empty($sectionmenu)) {
06959cfc 273 echo '<div align="center" class="jumpmenu">';
0c012545 274 echo popup_form($CFG->wwwroot.'/course/view.php?id='.$course->id.'&amp;', $sectionmenu,
c46f27a3 275 'sectionmenu', '', get_string('jumpto'), '', '', true);
276 echo '</div>';
1d019652 277 }
0b35af18 278
f145c248 279 if (!empty($THEME->customcorners)) print_custom_corners_end();
c46f27a3 280 echo '</td>';
13beeacb 281
d55c9a1f 282 break;
283 case 'right':
0f3fe4b6 284 // The right column
dffd4bb9 285 if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing) {
bd792a75 286 echo '<td style="width:'.$preferred_width_right.'px" id="right-column">';
f145c248 287 if (!empty($THEME->customcorners)) print_custom_corners_start();
66492322 288 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
f145c248 289 if (!empty($THEME->customcorners)) print_custom_corners_end();
0f3fe4b6 290 echo '</td>';
0b35af18 291 }
0b35af18 292
d55c9a1f 293 break;
294 }
295 }
c46f27a3 296 echo '</tr></table>';
a0bfbeaa 297
2ef9d19a 298?>