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