navigation MDL-20651 Added config setting to hide course categories on the navigation
[moodle.git] / course / format / weeks / format.php
CommitLineData
24f2b65a 1<?php // $Id$
600149be 2 // Display the whole course as "weeks" made of of modules
3 // Included from "view.php"
ab9ad21d 4/**
5 * Evaluation weekly 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 weeks/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['formatweekscss']
f9903ed0 27
3febabd8 28 require_once($CFG->libdir.'/ajax/ajaxlib.php');
644d506a 29 require_once($CFG->libdir.'/filelib.php');
ab9ad21d 30
0cdae0dc 31 $week = optional_param('week', -1, PARAM_INT);
32
0cdae0dc 33 if ($week != -1) {
b86fc0e2 34 $displaysection = course_set_display($course->id, $week);
35 } else {
36 if (isset($USER->display[$course->id])) {
37 $displaysection = $USER->display[$course->id];
600149be 38 } else {
b86fc0e2 39 $displaysection = course_set_display($course->id, 0);
600149be 40 }
41 }
42
a3f24f7c 43 $streditsummary = get_string('editsummary');
44 $stradd = get_string('add');
45 $stractivities = get_string('activities');
46 $strshowallweeks = get_string('showallweeks');
47 $strweek = get_string('week');
48 $strgroups = get_string('groups');
49 $strgroupmy = get_string('groupmy');
50 $editing = $PAGE->user_is_editing();
51
0f3fe4b6 52 if ($editing) {
9101efd3 53 $strweekhide = get_string('hideweekfromothers');
54 $strweekshow = get_string('showweekfromothers');
6cba878d 55 $strmoveup = get_string('moveup');
56 $strmovedown = get_string('movedown');
1ea7c627 57 }
9a223597 58
3924b988 59 $context = get_context_instance(CONTEXT_COURSE, $course->id);
e3568fde 60
61 //Print the Your progress icon if the track completion is enabled
62 $completioninfo = new completion_info($course);
63 $completioninfo->print_help_icon();
64
27ca34af 65 echo $OUTPUT->heading(get_string('weeklyoutline'), 2, 'headingblock header outline');
9a223597 66
ab9ad21d 67 // Note, an ordered list would confuse - "1" could be the clipboard or summary.
68 echo "<ul class='weeks'>\n";
9a223597 69
7977cffd 70/// If currently moving a file then show the current clipboard
71 if (ismoving($course->id)) {
294ce987 72 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
6cba878d 73 $strcancel= get_string('cancel');
ab9ad21d 74 echo '<li class="clipboard">';
d4a1fcaf 75 echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
ab9ad21d 76 echo "</li>\n";
c63bf72a 77 }
7977cffd 78
1ea7c627 79/// Print Section 0 with general activities
9a223597 80
1ea7c627 81 $section = 0;
82 $thissection = $sections[$section];
9a223597 83
830dd6e9 84 if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
ab9ad21d 85
86 // Note, 'right side' is BEFORE content.
87 echo '<li id="section-0" class="section main" >';
d4a03c00 88 echo '<div class="left side">&nbsp;</div>';
ab9ad21d 89 echo '<div class="right side" >&nbsp;</div>';
90 echo '<div class="content">';
40901069 91
92 echo '<div class="summary">';
644d506a 93
94 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
edc0c493 95 $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course_section', $thissection->id);
644d506a 96 $summaryformatoptions = new object();
179c9a50 97 $summaryformatoptions->noclean = true;
644d506a 98 echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);
5f850588 99
830dd6e9 100 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
ab9ad21d 101 echo '<p><a title="'.$streditsummary.'" '.
6b608f8f 102 ' href="editsection.php?id='.$thissection->id.'"><img src="'.$OUTPUT->old_icon_url('t/edit') . '" '.
ab9ad21d 103 ' class="icon edit" alt="'.$streditsummary.'" /></a></p>';
9a223597 104 }
40901069 105 echo '</div>';
106
1ea7c627 107 print_section($course, $thissection, $mods, $modnamesused);
9a223597 108
830dd6e9 109 if ($PAGE->user_is_editing()) {
e0161bff 110 print_section_add_menus($course, $section, $modnames);
9a223597 111 }
112
ab9ad21d 113 echo '</div>';
114 echo "</li>\n";
9a223597 115 }
116
117
6cba878d 118/// Now all the normal modules by week
119/// Everything below uses "section" terminology - each "section" is a week.
120
f9903ed0 121 $timenow = time();
122 $weekdate = $course->startdate; // this should be 0:00 Monday of that week
01e1f34e 123 $weekdate += 7200; // Add two hours to avoid possible DST problems
1ea7c627 124 $section = 1;
584ec10e 125 $sectionmenu = array();
01e1f34e 126 $weekofseconds = 604800;
b5fe4c93 127 $course->enddate = $course->startdate + ($weekofseconds * $course->numsections);
f9903ed0 128
6cba878d 129 $strftimedateshort = ' '.get_string('strftimedateshort');
dcde9f02 130
e3f0a6a7 131 while ($weekdate < $course->enddate) {
f9903ed0 132
133 $nextweekdate = $weekdate + ($weekofseconds);
1ea7c627 134 $weekday = userdate($weekdate, $strftimedateshort);
01e1f34e 135 $endweekday = userdate($weekdate+518400, $strftimedateshort);
600149be 136
1ea7c627 137 if (!empty($sections[$section])) {
138 $thissection = $sections[$section];
f9903ed0 139
1ea7c627 140 } else {
141 unset($thissection);
142 $thissection->course = $course->id; // Create a new week structure
143 $thissection->section = $section;
6cba878d 144 $thissection->summary = '';
1ea7c627 145 $thissection->visible = 1;
a8f3a651 146 $thissection->id = $DB->insert_record('course_sections', $thissection);
1ea7c627 147 }
f9903ed0 148
3924b988 149 $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
f9903ed0 150
8dc93b94 151 if (!empty($displaysection) and $displaysection != $section) { // Check this week is visible
152 if ($showsection) {
82fcab32 153 $sectionmenu[$section] = s("$strweek $section | $weekday - $endweekday");
8dc93b94 154 }
155 $section++;
156 $weekdate = $nextweekdate;
157 continue;
158 }
159
db7da819 160 if ($showsection) {
f9903ed0 161
db7da819 162 $currentweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate));
f9903ed0 163
e9b9c1d8 164 $currenttext = '';
db7da819 165 if (!$thissection->visible) {
6cba878d 166 $sectionstyle = ' hidden';
db7da819 167 } else if ($currentweek) {
6cba878d 168 $sectionstyle = ' current';
e9b9c1d8 169 $currenttext = get_accesshide(get_string('currentweek','access'));
db7da819 170 } else {
6cba878d 171 $sectionstyle = '';
1ea7c627 172 }
173
ab9ad21d 174 echo '<li id="section-'.$section.'" class="section main'.$sectionstyle.'" >';
dc140b6c 175
ab9ad21d 176 echo '<div class="left side">&nbsp;'.$currenttext.'</div>';
12905134 177
ab9ad21d 178 // Note, 'right side' is BEFORE content.
179 echo '<div class="right side">';
180
db7da819 181 if ($displaysection == $section) {
0cdae0dc 182 echo '<a href="view.php?id='.$course->id.'&amp;week=0#section-'.$section.'" title="'.$strshowallweeks.'">'.
6b608f8f 183 '<img src="'.$OUTPUT->old_icon_url('i/all') . '" class="icon wkall" alt="'.$strshowallweeks.'" /></a><br />';
db7da819 184 } else {
185 $strshowonlyweek = get_string("showonlyweek", "", $section);
6cba878d 186 echo '<a href="view.php?id='.$course->id.'&amp;week='.$section.'" title="'.$strshowonlyweek.'">'.
6b608f8f 187 '<img src="'.$OUTPUT->old_icon_url('i/one') . '" class="icon wkone" alt="'.$strshowonlyweek.'" /></a><br />';
12905134 188 }
dc140b6c 189
830dd6e9 190 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
db7da819 191 if ($thissection->visible) { // Show the hide/show eye
d4a1fcaf 192 echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strweekhide.'">'.
6b608f8f 193 '<img src="'.$OUTPUT->old_icon_url('i/hide') . '" class="icon hide" alt="'.$strweekhide.'" /></a><br />';
db7da819 194 } else {
d4a1fcaf 195 echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strweekshow.'">'.
6b608f8f 196 '<img src="'.$OUTPUT->old_icon_url('i/show') . '" class="icon hide" alt="'.$strweekshow.'" /></a><br />';
db7da819 197 }
db7da819 198 if ($section > 1) { // Add a arrow to move section up
d4a1fcaf 199 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 200 '<img src="'.$OUTPUT->old_icon_url('t/up') . '" class="icon up" alt="'.$strmoveup.'" /></a><br />';
db7da819 201 }
dc140b6c 202
db7da819 203 if ($section < $course->numsections) { // Add a arrow to move section down
d4a1fcaf 204 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 205 '<img src="'.$OUTPUT->old_icon_url('t/down') . '" class="icon down" alt="'.$strmovedown.'" /></a><br />';
ab9ad21d 206 }
207 }
208 echo '</div>';
209
0154653b 210 $weekperiod = $weekday.' - '.$endweekday;
211
ab9ad21d 212 echo '<div class="content">';
213 if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) { // Hidden for students
7c5286cd 214 echo $OUTPUT->heading($currenttext.$weekperiod.' ('.get_string('notavailable').')', 3, 'weekdates');
ab9ad21d 215
216 } else {
7c5286cd 217 echo $OUTPUT->heading($currenttext.$weekperiod, 3, 'weekdates');
ab9ad21d 218
219 echo '<div class="summary">';
220 $summaryformatoptions->noclean = true;
221 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
222
830dd6e9 223 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
ab9ad21d 224 echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
6b608f8f 225 '<img src="'.$OUTPUT->old_icon_url('t/edit') . '" class="icon edit" alt="'.$streditsummary.'" /></a><br /><br />';
ab9ad21d 226 }
227 echo '</div>';
228
229 print_section($course, $thissection, $mods, $modnamesused);
230
830dd6e9 231 if ($PAGE->user_is_editing()) {
ab9ad21d 232 print_section_add_menus($course, $section, $modnames);
db7da819 233 }
12905134 234 }
dc140b6c 235
ab9ad21d 236 echo '</div>';
237 echo "</li>\n";
1ea7c627 238 }
239
1ea7c627 240 $section++;
f9903ed0 241 $weekdate = $nextweekdate;
242 }
ab9ad21d 243 echo "</ul>\n";
584ec10e 244
245 if (!empty($sectionmenu)) {
85db96c5 246 echo '<div class="jumpmenu">';
82fcab32 247 $popupurl = $CFG->wwwroot.'/course/view.php?id='.$course->id;
7b1f2c82 248 $select = html_select::make_popup_form($popupurl, 'week', $sectionmenu, 'sectionmenu');
64e12bb7 249 $select->set_label(get_string('jumpto'));
250 echo $OUTPUT->select($select);
6cba878d 251 echo '</div>';
584ec10e 252 }