course-format-topic MDL-24680 Fixed XHTML bug that was destroying page layout.
[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
4cac68ab
PS
28defined('MOODLE_INTERNAL') || die();
29
8bdc9cac 30require_once($CFG->libdir.'/filelib.php');
689456eb 31
8bdc9cac 32$topic = optional_param('topic', -1, PARAM_INT);
0f3fe4b6 33
8bdc9cac
SH
34if ($topic != -1) {
35 $displaysection = course_set_display($course->id, $topic);
36} else {
37 if (isset($USER->display[$course->id])) {
38 $displaysection = $USER->display[$course->id];
b86fc0e2 39 } else {
8bdc9cac 40 $displaysection = course_set_display($course->id, 0);
0b35af18 41 }
8bdc9cac 42}
0b35af18 43
8bdc9cac 44$context = get_context_instance(CONTEXT_COURSE, $course->id);
3924b988 45
8bdc9cac
SH
46if (($marker >=0) && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
47 $course->marker = $marker;
f685e830 48 $DB->set_field("course", "marker", $marker, array("id"=>$course->id));
8bdc9cac
SH
49}
50
51$streditsummary = get_string('editsummary');
52$stradd = get_string('add');
53$stractivities = get_string('activities');
54$strshowalltopics = get_string('showalltopics');
55$strtopic = get_string('topic');
56$strgroups = get_string('groups');
57$strgroupmy = get_string('groupmy');
58$editing = $PAGE->user_is_editing();
59
60if ($editing) {
61 $strtopichide = get_string('hidetopicfromothers');
62 $strtopicshow = get_string('showtopicfromothers');
63 $strmarkthistopic = get_string('markthistopic');
64 $strmarkedthistopic = get_string('markedthistopic');
65 $strmoveup = get_string('moveup');
66 $strmovedown = get_string('movedown');
67}
68
69// Print the Your progress icon if the track completion is enabled
70$completioninfo = new completion_info($course);
71$completioninfo->print_help_icon();
72
73echo $OUTPUT->heading(get_string('topicoutline'), 2, 'headingblock header outline');
74
75// Note, an ordered list would confuse - "1" could be the clipboard or summary.
76echo "<ul class='topics'>\n";
0b35af18 77
8bdc9cac
SH
78/// If currently moving a file then show the current clipboard
79if (ismoving($course->id)) {
80 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
81 $strcancel= get_string('cancel');
82 echo '<li class="clipboard">';
83 echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
84 echo "</li>\n";
85}
d897cae4 86
8bdc9cac 87/// Print Section 0 with general activities
e3568fde 88
8bdc9cac
SH
89$section = 0;
90$thissection = $sections[$section];
4cac68ab 91unset($sections[0]);
8bdc9cac
SH
92
93if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
94
95 // Note, no need for a 'left side' cell or DIV.
96 // Note, 'right side' is BEFORE content.
7e184672 97 echo '<li id="section-0" class="section main clearfix" >';
8bdc9cac
SH
98 echo '<div class="left side">&nbsp;</div>';
99 echo '<div class="right side" >&nbsp;</div>';
100 echo '<div class="content">';
b7676071
SH
101 if (!is_null($thissection->name)) {
102 echo $OUTPUT->heading($thissection->name, 3, 'sectionname');
103 }
8bdc9cac
SH
104 echo '<div class="summary">';
105
106 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
64f93798 107 $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $thissection->id);
fbaea88f 108 $summaryformatoptions = new stdClass();
8bdc9cac 109 $summaryformatoptions->noclean = true;
e34a326f 110 echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
8bdc9cac
SH
111
112 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $coursecontext)) {
113 echo '<a title="'.$streditsummary.'" '.
b5d0cafc 114 ' href="editsection.php?id='.$thissection->id.'"><img src="'.$OUTPUT->pix_url('t/edit') . '" '.
8bdc9cac
SH
115 ' class="icon edit" alt="'.$streditsummary.'" /></a>';
116 }
117 echo '</div>';
2c0411e2 118
8bdc9cac 119 print_section($course, $thissection, $mods, $modnamesused);
9a223597 120
8bdc9cac
SH
121 if ($PAGE->user_is_editing()) {
122 print_section_add_menus($course, $section, $modnames);
7977cffd 123 }
124
8bdc9cac
SH
125 echo '</div>';
126 echo "</li>\n";
127}
9a223597 128
9a223597 129
8bdc9cac
SH
130/// Now all the normal modules by topic
131/// Everything below uses "section" terminology - each "section" is a topic.
9f7f1a74 132
8bdc9cac
SH
133$timenow = time();
134$section = 1;
135$sectionmenu = array();
0f3fe4b6 136
8bdc9cac 137while ($section <= $course->numsections) {
0f3fe4b6 138
8bdc9cac
SH
139 if (!empty($sections[$section])) {
140 $thissection = $sections[$section];
9a223597 141
8bdc9cac 142 } else {
7e184672 143 $thissection = new stdClass;
8bdc9cac
SH
144 $thissection->course = $course->id; // Create a new section structure
145 $thissection->section = $section;
1459becf 146 $thissection->name = null;
8bdc9cac 147 $thissection->summary = '';
f9f952e8 148 $thissection->summaryformat = FORMAT_HTML;
8bdc9cac
SH
149 $thissection->visible = 1;
150 $thissection->id = $DB->insert_record('course_sections', $thissection);
151 }
9a223597 152
8bdc9cac 153 $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
9a223597 154
8bdc9cac
SH
155 if (!empty($displaysection) and $displaysection != $section) { // Check this topic is visible
156 if ($showsection) {
47e75d04 157 $sectionmenu[$section] = get_section_name($course, $thissection);
8bdc9cac
SH
158 }
159 $section++;
160 continue;
161 }
9a223597 162
8bdc9cac 163 if ($showsection) {
0b35af18 164
8bdc9cac 165 $currenttopic = ($course->marker == $section);
7d99d695 166
8bdc9cac
SH
167 $currenttext = '';
168 if (!$thissection->visible) {
169 $sectionstyle = ' hidden';
170 } else if ($currenttopic) {
171 $sectionstyle = ' current';
172 $currenttext = get_accesshide(get_string('currenttopic','access'));
7d99d695 173 } else {
8bdc9cac 174 $sectionstyle = '';
7d99d695 175 }
176
7e184672 177 echo '<li id="section-'.$section.'" class="section main clearfix'.$sectionstyle.'" >'; //'<div class="left side">&nbsp;</div>';
8bdc9cac
SH
178
179 echo '<div class="left side">'.$currenttext.$section.'</div>';
180 // Note, 'right side' is BEFORE content.
181 echo '<div class="right side">';
182
4454447d 183 if ($displaysection == $section) { // Show the zoom boxes
8bdc9cac 184 echo '<a href="view.php?id='.$course->id.'&amp;topic=0#section-'.$section.'" title="'.$strshowalltopics.'">'.
b5d0cafc 185 '<img src="'.$OUTPUT->pix_url('i/all') . '" class="icon" alt="'.$strshowalltopics.'" /></a><br />';
8bdc9cac
SH
186 } else {
187 $strshowonlytopic = get_string("showonlytopic", "", $section);
188 echo '<a href="view.php?id='.$course->id.'&amp;topic='.$section.'" title="'.$strshowonlytopic.'">'.
b5d0cafc 189 '<img src="'.$OUTPUT->pix_url('i/one') . '" class="icon" alt="'.$strshowonlytopic.'" /></a><br />';
8dc93b94 190 }
191
8bdc9cac 192 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
db7da819 193
8bdc9cac 194 if ($course->marker == $section) { // Show the "light globe" on/off
b5d0cafc 195 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 196 } else {
b5d0cafc 197 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 198 }
db7da819 199
8bdc9cac
SH
200 if ($thissection->visible) { // Show the hide/show eye
201 echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strtopichide.'">'.
b5d0cafc 202 '<img src="'.$OUTPUT->pix_url('i/hide') . '" class="icon hide" alt="'.$strtopichide.'" /></a><br />';
db7da819 203 } else {
8bdc9cac 204 echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strtopicshow.'">'.
b5d0cafc 205 '<img src="'.$OUTPUT->pix_url('i/show') . '" class="icon hide" alt="'.$strtopicshow.'" /></a><br />';
8bdc9cac
SH
206 }
207 if ($section > 1) { // Add a arrow to move section up
208 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 209 '<img src="'.$OUTPUT->pix_url('t/up') . '" class="icon up" alt="'.$strmoveup.'" /></a><br />';
db7da819 210 }
0b35af18 211
8bdc9cac
SH
212 if ($section < $course->numsections) { // Add a arrow to move section down
213 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 214 '<img src="'.$OUTPUT->pix_url('t/down') . '" class="icon down" alt="'.$strmovedown.'" /></a><br />';
8bdc9cac
SH
215 }
216 }
217 echo '</div>';
0b35af18 218
8bdc9cac
SH
219 echo '<div class="content">';
220 if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) { // Hidden for students
45390cf7 221 echo get_string('notavailable');
8bdc9cac 222 } else {
b7676071
SH
223 if (!is_null($thissection->name)) {
224 echo $OUTPUT->heading($thissection->name, 3, 'sectionname');
225 }
8bdc9cac 226 echo '<div class="summary">';
8bdc9cac 227 if ($thissection->summary) {
6597e6b7 228 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
64f93798 229 $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course', 'section', $thissection->id);
fbaea88f 230 $summaryformatoptions = new stdClass();
6597e6b7 231 $summaryformatoptions->noclean = true;
e34a326f 232 echo format_text($summarytext, $thissection->summaryformat, $summaryformatoptions);
ff828023 233 } else {
8bdc9cac 234 echo '&nbsp;';
12905134 235 }
236
830dd6e9 237 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
8bdc9cac 238 echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
b5d0cafc 239 '<img src="'.$OUTPUT->pix_url('t/edit') . '" class="icon edit" alt="'.$streditsummary.'" /></a><br /><br />';
9f7f1a74 240 }
241 echo '</div>';
242
8bdc9cac
SH
243 print_section($course, $thissection, $mods, $modnamesused);
244 echo '<br />';
245 if ($PAGE->user_is_editing()) {
246 print_section_add_menus($course, $section, $modnames);
7d99d695 247 }
0b35af18 248 }
ff828023 249
c46f27a3 250 echo '</div>';
8bdc9cac 251 echo "</li>\n";
1d019652 252 }
8bdc9cac 253
4cac68ab 254 unset($sections[$section]);
8bdc9cac
SH
255 $section++;
256}
4cac68ab
PS
257
258if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
259 // print stealth sections if present
260 $modinfo = get_fast_modinfo($course);
261 foreach ($sections as $section=>$thissection) {
262 if (empty($modinfo->sections[$section])) {
263 continue;
264 }
265
46b2346b 266 echo '<li id="section-'.$section.'" class="section main clearfix orphaned hidden">'; //'<div class="left side">&nbsp;</div>';
4cac68ab
PS
267
268 echo '<div class="left side">';
4cac68ab
PS
269 echo '</div>';
270 // Note, 'right side' is BEFORE content.
271 echo '<div class="right side">';
4cac68ab
PS
272 echo '</div>';
273 echo '<div class="content">';
46b2346b 274 echo $OUTPUT->heading(get_string('orphanedactivities'), 3, 'sectionname');
4cac68ab 275 print_section($course, $thissection, $mods, $modnamesused);
4cac68ab
PS
276 echo '</div>';
277 echo "</li>\n";
278 }
279}
280
281
8bdc9cac
SH
282echo "</ul>\n";
283
284if (!empty($sectionmenu)) {
6fe3775a
PS
285 $select = new single_select(new moodle_url('/course/view.php', array('id'=>$course->id)), 'topic', $sectionmenu);
286 $select->label = get_string('jumpto');
287 $select->class = 'jumpmenu';
288 $select->formid = 'sectionmenu';
289 echo $OUTPUT->render($select);
8bdc9cac 290}