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