navigation MDL-20651 Added config setting to hide course categories on the navigation
[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.
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.
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 *
16 * Target: 3-column graphical view using relative widths for pixel screen sizes
17 * 800x600, 1024x768... on IE6, Firefox. Below 800 columns will shift downwards.
18 *
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
25 * @package
26 */
27//TODO (nfreear): Accessibility: evaluation, lang/en_utf8/moodle.php: $string['formattopicscss']
0b35af18 28
8bdc9cac
SH
29require_once($CFG->libdir.'/ajax/ajaxlib.php');
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;
48 if (! $DB->set_field("course", "marker", $marker, array("id"=>$course->id))) {
49 print_error("cannotmarktopic");
0b35af18 50 }
8bdc9cac
SH
51}
52
53$streditsummary = get_string('editsummary');
54$stradd = get_string('add');
55$stractivities = get_string('activities');
56$strshowalltopics = get_string('showalltopics');
57$strtopic = get_string('topic');
58$strgroups = get_string('groups');
59$strgroupmy = get_string('groupmy');
60$editing = $PAGE->user_is_editing();
61
62if ($editing) {
63 $strtopichide = get_string('hidetopicfromothers');
64 $strtopicshow = get_string('showtopicfromothers');
65 $strmarkthistopic = get_string('markthistopic');
66 $strmarkedthistopic = get_string('markedthistopic');
67 $strmoveup = get_string('moveup');
68 $strmovedown = get_string('movedown');
69}
70
71// Print the Your progress icon if the track completion is enabled
72$completioninfo = new completion_info($course);
73$completioninfo->print_help_icon();
74
75echo $OUTPUT->heading(get_string('topicoutline'), 2, 'headingblock header outline');
76
77// Note, an ordered list would confuse - "1" could be the clipboard or summary.
78echo "<ul class='topics'>\n";
0b35af18 79
8bdc9cac
SH
80/// If currently moving a file then show the current clipboard
81if (ismoving($course->id)) {
82 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
83 $strcancel= get_string('cancel');
84 echo '<li class="clipboard">';
85 echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
86 echo "</li>\n";
87}
d897cae4 88
8bdc9cac 89/// Print Section 0 with general activities
e3568fde 90
8bdc9cac
SH
91$section = 0;
92$thissection = $sections[$section];
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.
98 echo '<li id="section-0" class="section main" >';
99 echo '<div class="left side">&nbsp;</div>';
100 echo '<div class="right side" >&nbsp;</div>';
101 echo '<div class="content">';
102 echo '<div class="summary">';
103
104 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
105 $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course_section', $thissection->id);
106 $summaryformatoptions = new object();
107 $summaryformatoptions->noclean = true;
108 echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);
109
110 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $coursecontext)) {
111 echo '<a title="'.$streditsummary.'" '.
112 ' href="editsection.php?id='.$thissection->id.'"><img src="'.$OUTPUT->old_icon_url('t/edit') . '" '.
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
SH
140 } else {
141 unset($thissection);
142 $thissection->course = $course->id; // Create a new section structure
143 $thissection->section = $section;
144 $thissection->summary = '';
145 $thissection->visible = 1;
146 $thissection->id = $DB->insert_record('course_sections', $thissection);
147 }
9a223597 148
8bdc9cac 149 $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
9a223597 150
8bdc9cac
SH
151 if (!empty($displaysection) and $displaysection != $section) { // Check this topic is visible
152 if ($showsection) {
153 $strsummary = strip_tags(format_string($thissection->summary,true));
154 if (strlen($strsummary) < 57) {
155 $strsummary = ' - '.$strsummary;
156 } else {
157 $strsummary = ' - '.substr($strsummary, 0, 60).'...';
158 }
159 $sectionmenu[$section] = s($section.$strsummary);
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
8bdc9cac
SH
179 echo '<li id="section-'.$section.'" class="section main'.$sectionstyle.'" >'; //'<div class="left side">&nbsp;</div>';
180
181 echo '<div class="left side">'.$currenttext.$section.'</div>';
182 // Note, 'right side' is BEFORE content.
183 echo '<div class="right side">';
184
185 if ($displaysection == $section) { // Show the zoom boxes
186 echo '<a href="view.php?id='.$course->id.'&amp;topic=0#section-'.$section.'" title="'.$strshowalltopics.'">'.
187 '<img src="'.$OUTPUT->old_icon_url('i/all') . '" class="icon" alt="'.$strshowalltopics.'" /></a><br />';
188 } else {
189 $strshowonlytopic = get_string("showonlytopic", "", $section);
190 echo '<a href="view.php?id='.$course->id.'&amp;topic='.$section.'" title="'.$strshowonlytopic.'">'.
191 '<img src="'.$OUTPUT->old_icon_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
SH
196 if ($course->marker == $section) { // Show the "light globe" on/off
197 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 />';
198 } else {
199 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 />';
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.'">'.
204 '<img src="'.$OUTPUT->old_icon_url('i/hide') . '" class="icon hide" alt="'.$strtopichide.'" /></a><br />';
db7da819 205 } else {
8bdc9cac
SH
206 echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strtopicshow.'">'.
207 '<img src="'.$OUTPUT->old_icon_url('i/show') . '" class="icon hide" alt="'.$strtopicshow.'" /></a><br />';
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.'">'.
211 '<img src="'.$OUTPUT->old_icon_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.'">'.
216 '<img src="'.$OUTPUT->old_icon_url('t/down') . '" class="icon down" alt="'.$strmovedown.'" /></a><br />';
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
223 echo get_string('notavailable').'</div>';
224 } else {
225 echo '<div class="summary">';
226 $summaryformatoptions->noclean = true;
227 if ($thissection->summary) {
228 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
ff828023 229 } else {
8bdc9cac 230 echo '&nbsp;';
12905134 231 }
232
830dd6e9 233 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
8bdc9cac
SH
234 echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
235 '<img src="'.$OUTPUT->old_icon_url('t/edit') . '" class="icon edit" alt="'.$streditsummary.'" /></a><br /><br />';
9f7f1a74 236 }
237 echo '</div>';
238
8bdc9cac
SH
239 print_section($course, $thissection, $mods, $modnamesused);
240 echo '<br />';
241 if ($PAGE->user_is_editing()) {
242 print_section_add_menus($course, $section, $modnames);
7d99d695 243 }
0b35af18 244 }
ff828023 245
c46f27a3 246 echo '</div>';
8bdc9cac 247 echo "</li>\n";
1d019652 248 }
8bdc9cac
SH
249
250 $section++;
251}
252echo "</ul>\n";
253
254if (!empty($sectionmenu)) {
255 echo '<div class="jumpmenu">';
256 $popupurl = $CFG->wwwroot.'/course/view.php?id='.$course->id;
257 $select = html_select::make_popup_form($popupurl, 'topic', $sectionmenu, 'sectionmenu');
258 $select->set_label(get_string('jumpto'));
259 echo $OUTPUT->select($select);
260 echo '</div>';
261}