MDL-24650 fixing sloppy regression, sorry; credit for goes to Daniele Cordella
[moodle.git] / course / format / topics / format.php
CommitLineData
8bdc9cac
SH
1<?php
2
3// Display the whole course as "topics" made of of modules
4// Included from "view.php"
9f7f1a74 5/**
6 * Evaluation topics format for course display - NO layout tables, for accessibility, etc.
aa6c1ced
PS
7 *
8 * A duplicate course format to enable the Moodle development team to evaluate
9 * CSS for the multi-column layout in place of layout tables.
9f7f1a74 10 * Less risk for the Moodle 1.6 beta release.
11 * 1. Straight copy of topics/format.php
12 * 2. Replace <table> and <td> with DIVs; inline styles.
13 * 3. Reorder columns so that in linear view content is first then blocks;
14 * styles to maintain original graphical (side by side) view.
15 *
aa6c1ced 16 * Target: 3-column graphical view using relative widths for pixel screen sizes
9f7f1a74 17 * 800x600, 1024x768... on IE6, Firefox. Below 800 columns will shift downwards.
aa6c1ced 18 *
9f7f1a74 19 * http://www.maxdesign.com.au/presentation/em/ Ideal length for content.
20 * http://www.svendtofte.com/code/max_width_in_ie/ Max width in IE.
21 *
22 * @copyright &copy; 2006 The Open University
23 * @author N.D.Freear@open.ac.uk, and others.
24 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
aa6c1ced 25 * @package
9f7f1a74 26 */
0b35af18 27
8bdc9cac 28require_once($CFG->libdir.'/filelib.php');
689456eb 29
8bdc9cac 30$topic = optional_param('topic', -1, PARAM_INT);
0f3fe4b6 31
8bdc9cac
SH
32if ($topic != -1) {
33 $displaysection = course_set_display($course->id, $topic);
34} else {
35 if (isset($USER->display[$course->id])) {
36 $displaysection = $USER->display[$course->id];
b86fc0e2 37 } else {
8bdc9cac 38 $displaysection = course_set_display($course->id, 0);
0b35af18 39 }
8bdc9cac 40}
0b35af18 41
8bdc9cac 42$context = get_context_instance(CONTEXT_COURSE, $course->id);
3924b988 43
8bdc9cac
SH
44if (($marker >=0) && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
45 $course->marker = $marker;
f685e830 46 $DB->set_field("course", "marker", $marker, array("id"=>$course->id));
8bdc9cac
SH
47}
48
49$streditsummary = get_string('editsummary');
50$stradd = get_string('add');
51$stractivities = get_string('activities');
52$strshowalltopics = get_string('showalltopics');
53$strtopic = get_string('topic');
54$strgroups = get_string('groups');
55$strgroupmy = get_string('groupmy');
56$editing = $PAGE->user_is_editing();
57
58if ($editing) {
59 $strtopichide = get_string('hidetopicfromothers');
60 $strtopicshow = get_string('showtopicfromothers');
61 $strmarkthistopic = get_string('markthistopic');
62 $strmarkedthistopic = get_string('markedthistopic');
63 $strmoveup = get_string('moveup');
64 $strmovedown = get_string('movedown');
65}
66
67// Print the Your progress icon if the track completion is enabled
68$completioninfo = new completion_info($course);
69$completioninfo->print_help_icon();
70
71echo $OUTPUT->heading(get_string('topicoutline'), 2, 'headingblock header outline');
72
6b0034a6 73echo "<span id='maincontent'></span>";
8bdc9cac
SH
74// Note, an ordered list would confuse - "1" could be the clipboard or summary.
75echo "<ul class='topics'>\n";
0b35af18 76
8bdc9cac
SH
77/// If currently moving a file then show the current clipboard
78if (ismoving($course->id)) {
79 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
80 $strcancel= get_string('cancel');
81 echo '<li class="clipboard">';
82 echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
83 echo "</li>\n";
84}
d897cae4 85
8bdc9cac 86/// Print Section 0 with general activities
e3568fde 87
8bdc9cac
SH
88$section = 0;
89$thissection = $sections[$section];
90
91if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
92
93 // Note, no need for a 'left side' cell or DIV.
94 // Note, 'right side' is BEFORE content.
7e184672 95 echo '<li id="section-0" class="section main clearfix" >';
8bdc9cac
SH
96 echo '<div class="left side">&nbsp;</div>';
97 echo '<div class="right side" >&nbsp;</div>';
98 echo '<div class="content">';
b7676071
SH
99 if (!is_null($thissection->name)) {
100 echo $OUTPUT->heading($thissection->name, 3, 'sectionname');
101 }
8bdc9cac
SH
102 echo '<div class="summary">';
103
104 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
64f93798 105 $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $thissection->id);
fbaea88f 106 $summaryformatoptions = new stdClass();
8bdc9cac 107 $summaryformatoptions->noclean = true;
e34a326f 108 echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
8bdc9cac
SH
109
110 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $coursecontext)) {
111 echo '<a title="'.$streditsummary.'" '.
b5d0cafc 112 ' href="editsection.php?id='.$thissection->id.'"><img src="'.$OUTPUT->pix_url('t/edit') . '" '.
8bdc9cac
SH
113 ' class="icon edit" alt="'.$streditsummary.'" /></a>';
114 }
115 echo '</div>';
2c0411e2 116
8bdc9cac 117 print_section($course, $thissection, $mods, $modnamesused);
9a223597 118
8bdc9cac
SH
119 if ($PAGE->user_is_editing()) {
120 print_section_add_menus($course, $section, $modnames);
7977cffd 121 }
122
8bdc9cac
SH
123 echo '</div>';
124 echo "</li>\n";
125}
9a223597 126
9a223597 127
8bdc9cac
SH
128/// Now all the normal modules by topic
129/// Everything below uses "section" terminology - each "section" is a topic.
9f7f1a74 130
8bdc9cac
SH
131$timenow = time();
132$section = 1;
133$sectionmenu = array();
0f3fe4b6 134
8bdc9cac 135while ($section <= $course->numsections) {
0f3fe4b6 136
8bdc9cac
SH
137 if (!empty($sections[$section])) {
138 $thissection = $sections[$section];
9a223597 139
8bdc9cac 140 } else {
7e184672 141 $thissection = new stdClass;
8bdc9cac
SH
142 $thissection->course = $course->id; // Create a new section structure
143 $thissection->section = $section;
1459becf 144 $thissection->name = null;
8bdc9cac 145 $thissection->summary = '';
f9f952e8 146 $thissection->summaryformat = FORMAT_HTML;
8bdc9cac
SH
147 $thissection->visible = 1;
148 $thissection->id = $DB->insert_record('course_sections', $thissection);
149 }
9a223597 150
8bdc9cac 151 $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
9a223597 152
8bdc9cac
SH
153 if (!empty($displaysection) and $displaysection != $section) { // Check this topic is visible
154 if ($showsection) {
47e75d04 155 $sectionmenu[$section] = get_section_name($course, $thissection);
8bdc9cac
SH
156 }
157 $section++;
158 continue;
159 }
9a223597 160
8bdc9cac 161 if ($showsection) {
0b35af18 162
8bdc9cac 163 $currenttopic = ($course->marker == $section);
7d99d695 164
8bdc9cac
SH
165 $currenttext = '';
166 if (!$thissection->visible) {
167 $sectionstyle = ' hidden';
168 } else if ($currenttopic) {
169 $sectionstyle = ' current';
170 $currenttext = get_accesshide(get_string('currenttopic','access'));
7d99d695 171 } else {
8bdc9cac 172 $sectionstyle = '';
7d99d695 173 }
174
7e184672 175 echo '<li id="section-'.$section.'" class="section main clearfix'.$sectionstyle.'" >'; //'<div class="left side">&nbsp;</div>';
8bdc9cac
SH
176
177 echo '<div class="left side">'.$currenttext.$section.'</div>';
178 // Note, 'right side' is BEFORE content.
179 echo '<div class="right side">';
180
4454447d 181 if ($displaysection == $section) { // Show the zoom boxes
8bdc9cac 182 echo '<a href="view.php?id='.$course->id.'&amp;topic=0#section-'.$section.'" title="'.$strshowalltopics.'">'.
b5d0cafc 183 '<img src="'.$OUTPUT->pix_url('i/all') . '" class="icon" alt="'.$strshowalltopics.'" /></a><br />';
8bdc9cac
SH
184 } else {
185 $strshowonlytopic = get_string("showonlytopic", "", $section);
186 echo '<a href="view.php?id='.$course->id.'&amp;topic='.$section.'" title="'.$strshowonlytopic.'">'.
b5d0cafc 187 '<img src="'.$OUTPUT->pix_url('i/one') . '" class="icon" alt="'.$strshowonlytopic.'" /></a><br />';
8dc93b94 188 }
189
8bdc9cac 190 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
db7da819 191
8bdc9cac 192 if ($course->marker == $section) { // Show the "light globe" on/off
b5d0cafc 193 echo '<a href="view.php?id='.$course->id.'&amp;marker=0&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strmarkedthistopic.'">'.'<img src="'.$OUTPUT->pix_url('i/marked') . '" alt="'.$strmarkedthistopic.'" /></a><br />';
8bdc9cac 194 } else {
b5d0cafc 195 echo '<a href="view.php?id='.$course->id.'&amp;marker='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strmarkthistopic.'">'.'<img src="'.$OUTPUT->pix_url('i/marker') . '" alt="'.$strmarkthistopic.'" /></a><br />';
8bdc9cac 196 }
db7da819 197
8bdc9cac
SH
198 if ($thissection->visible) { // Show the hide/show eye
199 echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strtopichide.'">'.
b5d0cafc 200 '<img src="'.$OUTPUT->pix_url('i/hide') . '" class="icon hide" alt="'.$strtopichide.'" /></a><br />';
db7da819 201 } else {
8bdc9cac 202 echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strtopicshow.'">'.
b5d0cafc 203 '<img src="'.$OUTPUT->pix_url('i/show') . '" class="icon hide" alt="'.$strtopicshow.'" /></a><br />';
8bdc9cac
SH
204 }
205 if ($section > 1) { // Add a arrow to move section up
206 echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=-1&amp;sesskey='.sesskey().'#section-'.($section-1).'" title="'.$strmoveup.'">'.
b5d0cafc 207 '<img src="'.$OUTPUT->pix_url('t/up') . '" class="icon up" alt="'.$strmoveup.'" /></a><br />';
db7da819 208 }
0b35af18 209
8bdc9cac
SH
210 if ($section < $course->numsections) { // Add a arrow to move section down
211 echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=1&amp;sesskey='.sesskey().'#section-'.($section+1).'" title="'.$strmovedown.'">'.
b5d0cafc 212 '<img src="'.$OUTPUT->pix_url('t/down') . '" class="icon down" alt="'.$strmovedown.'" /></a><br />';
8bdc9cac
SH
213 }
214 }
215 echo '</div>';
0b35af18 216
8bdc9cac
SH
217 echo '<div class="content">';
218 if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) { // Hidden for students
219 echo get_string('notavailable').'</div>';
220 } else {
b7676071
SH
221 if (!is_null($thissection->name)) {
222 echo $OUTPUT->heading($thissection->name, 3, 'sectionname');
223 }
8bdc9cac 224 echo '<div class="summary">';
8bdc9cac 225 if ($thissection->summary) {
6597e6b7 226 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
64f93798 227 $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $thissection->id);
fbaea88f 228 $summaryformatoptions = new stdClass();
6597e6b7 229 $summaryformatoptions->noclean = true;
e34a326f 230 echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
ff828023 231 } else {
8bdc9cac 232 echo '&nbsp;';
12905134 233 }
234
830dd6e9 235 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
8bdc9cac 236 echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
b5d0cafc 237 '<img src="'.$OUTPUT->pix_url('t/edit') . '" class="icon edit" alt="'.$streditsummary.'" /></a><br /><br />';
9f7f1a74 238 }
239 echo '</div>';
240
8bdc9cac
SH
241 print_section($course, $thissection, $mods, $modnamesused);
242 echo '<br />';
243 if ($PAGE->user_is_editing()) {
244 print_section_add_menus($course, $section, $modnames);
7d99d695 245 }
0b35af18 246 }
ff828023 247
c46f27a3 248 echo '</div>';
8bdc9cac 249 echo "</li>\n";
1d019652 250 }
8bdc9cac
SH
251
252 $section++;
253}
254echo "</ul>\n";
255
256if (!empty($sectionmenu)) {
6fe3775a
PS
257 $select = new single_select(new moodle_url('/course/view.php', array('id'=>$course->id)), 'topic', $sectionmenu);
258 $select->label = get_string('jumpto');
259 $select->class = 'jumpmenu';
260 $select->formid = 'sectionmenu';
261 echo $OUTPUT->render($select);
8bdc9cac 262}