MDL-12149 Added code to check for selected group as well, so that privileged users...
[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"
f9903ed0 4
3febabd8 5 require_once($CFG->libdir.'/ajax/ajaxlib.php');
f145c248 6
7 if (!empty($THEME->customcorners)) {
8 require_once($CFG->dirroot.'/lib/custom_corners_lib.php');
9 }
f9903ed0 10
0cdae0dc 11 $week = optional_param('week', -1, PARAM_INT);
12
c15816ce 13 // Bounds for block widths
14 // more flexible for theme designers taken from theme config.php
15 $lmin = (empty($THEME->block_l_min_width)) ? 100 : $THEME->block_l_min_width;
16 $lmax = (empty($THEME->block_l_max_width)) ? 210 : $THEME->block_l_max_width;
17 $rmin = (empty($THEME->block_r_min_width)) ? 100 : $THEME->block_r_min_width;
18 $rmax = (empty($THEME->block_r_max_width)) ? 210 : $THEME->block_r_max_width;
19
20 define('BLOCK_L_MIN_WIDTH', $lmin);
21 define('BLOCK_L_MAX_WIDTH', $lmax);
22 define('BLOCK_R_MIN_WIDTH', $rmin);
23 define('BLOCK_R_MAX_WIDTH', $rmax);
24
870e3cad 25 $preferred_width_left = bounded_number(BLOCK_L_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]),
26 BLOCK_L_MAX_WIDTH);
27 $preferred_width_right = bounded_number(BLOCK_R_MIN_WIDTH, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]),
28 BLOCK_R_MAX_WIDTH);
f9903ed0 29
0cdae0dc 30 if ($week != -1) {
b86fc0e2 31 $displaysection = course_set_display($course->id, $week);
32 } else {
33 if (isset($USER->display[$course->id])) {
34 $displaysection = $USER->display[$course->id];
600149be 35 } else {
b86fc0e2 36 $displaysection = course_set_display($course->id, 0);
600149be 37 }
38 }
39
a3f24f7c 40 $streditsummary = get_string('editsummary');
41 $stradd = get_string('add');
42 $stractivities = get_string('activities');
43 $strshowallweeks = get_string('showallweeks');
44 $strweek = get_string('week');
45 $strgroups = get_string('groups');
46 $strgroupmy = get_string('groupmy');
47 $editing = $PAGE->user_is_editing();
48
0f3fe4b6 49 if ($editing) {
1ea7c627 50 $strstudents = moodle_strtolower($course->students);
6cba878d 51 $strweekhide = get_string('weekhide', '', $strstudents);
52 $strweekshow = get_string('weekshow', '', $strstudents);
53 $strmoveup = get_string('moveup');
54 $strmovedown = get_string('movedown');
1ea7c627 55 }
9a223597 56
3924b988 57 $context = get_context_instance(CONTEXT_COURSE, $course->id);
9a223597 58/// Layout the whole page as three big columns.
3b456f6a 59 echo '<table id="layout-table" cellspacing="0" summary="'.get_string('layouttable').'"><tr>';
dd9098cc 60 $lt = (empty($THEME->layouttable)) ? array('left', 'middle', 'right') : $THEME->layouttable;
61 foreach ($lt as $column) {
62 switch ($column) {
63 case 'left':
64
0f3fe4b6 65/// The left column ...
f374fb10 66
dffd4bb9 67 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
bd792a75 68 echo '<td style="width:'.$preferred_width_left.'px" id="left-column">';
dd9098cc 69
f145c248 70 if (!empty($THEME->customcorners)) print_custom_corners_start();
66492322 71 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
f145c248 72 if (!empty($THEME->customcorners)) print_custom_corners_end();
dd9098cc 73
0f3fe4b6 74 echo '</td>';
2c0411e2 75 }
dd9098cc 76 break;
77 case 'middle':
9a223597 78/// Start main column
dd9098cc 79 echo '<td id="middle-column">';
80
f145c248 81 if (!empty($THEME->customcorners)) print_custom_corners_start();
dd9098cc 82
5c355019 83 echo skip_main_destination();
446390fb 84
85 print_heading_block(get_string('weeklyoutline'), 'outline');
9a223597 86
3b456f6a 87 echo '<table class="weeks" width="100%" summary="'.get_string('layouttable').'">';
9a223597 88
7977cffd 89/// If currently moving a file then show the current clipboard
90 if (ismoving($course->id)) {
6cba878d 91 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', addslashes($USER->activitycopyname)));
92 $strcancel= get_string('cancel');
93 echo '<tr class="clipboard">';
94 echo '<td colspan="3">';
95 echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.$USER->sesskey.'">'.$strcancel.'</a>)';
96 echo '</td>';
97 echo '</tr>';
c63bf72a 98 }
7977cffd 99
1ea7c627 100/// Print Section 0 with general activities
9a223597 101
1ea7c627 102 $section = 0;
103 $thissection = $sections[$section];
9a223597 104
1ea7c627 105 if ($thissection->summary or $thissection->sequence or isediting($course->id)) {
c1ac64b5 106 echo '<tr id="section-0" class="section main">';
6cba878d 107 echo '<td class="left side">&nbsp;</td>';
108 echo '<td class="content">';
40901069 109
110 echo '<div class="summary">';
179c9a50 111 $summaryformatoptions->noclean = true;
112 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
5f850588 113
61e75e95 114 if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
6cba878d 115 echo '<a title="'.$streditsummary.'" '.
116 ' href="editsection.php?id='.$thissection->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" '.
1f48fec7 117 'class="iconsmall edit" alt="'.$streditsummary.'" /></a><br /><br />';
9a223597 118 }
40901069 119 echo '</div>';
120
1ea7c627 121 print_section($course, $thissection, $mods, $modnamesused);
9a223597 122
123 if (isediting($course->id)) {
e0161bff 124 print_section_add_menus($course, $section, $modnames);
9a223597 125 }
126
6cba878d 127 echo '</td>';
128 echo '<td class="right side">&nbsp;</td>';
129 echo '</tr>';
c1ac64b5 130 echo '<tr class="section separator"><td colspan="3" class="spacer"></td></tr>';
6cba878d 131
9a223597 132 }
133
134
6cba878d 135/// Now all the normal modules by week
136/// Everything below uses "section" terminology - each "section" is a week.
137
f9903ed0 138 $timenow = time();
139 $weekdate = $course->startdate; // this should be 0:00 Monday of that week
674416ea 140 $weekdate += 7200; // Add two hours to avoid possible DST problems
1ea7c627 141 $section = 1;
584ec10e 142 $sectionmenu = array();
f9903ed0 143 $weekofseconds = 604800;
b5fe4c93 144 $course->enddate = $course->startdate + ($weekofseconds * $course->numsections);
f9903ed0 145
6cba878d 146 $strftimedateshort = ' '.get_string('strftimedateshort');
dcde9f02 147
e3f0a6a7 148 while ($weekdate < $course->enddate) {
f9903ed0 149
150 $nextweekdate = $weekdate + ($weekofseconds);
1ea7c627 151 $weekday = userdate($weekdate, $strftimedateshort);
152 $endweekday = userdate($weekdate+518400, $strftimedateshort);
600149be 153
1ea7c627 154 if (!empty($sections[$section])) {
155 $thissection = $sections[$section];
f9903ed0 156
1ea7c627 157 } else {
158 unset($thissection);
159 $thissection->course = $course->id; // Create a new week structure
160 $thissection->section = $section;
6cba878d 161 $thissection->summary = '';
1ea7c627 162 $thissection->visible = 1;
6cba878d 163 if (!$thissection->id = insert_record('course_sections', $thissection)) {
164 notify('Error inserting new week!');
1ea7c627 165 }
166 }
f9903ed0 167
3924b988 168 $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
f9903ed0 169
8dc93b94 170 if (!empty($displaysection) and $displaysection != $section) { // Check this week is visible
171 if ($showsection) {
6cba878d 172 $sectionmenu['week='.$section] = s("$strweek $section | $weekday - $endweekday");
8dc93b94 173 }
174 $section++;
175 $weekdate = $nextweekdate;
176 continue;
177 }
178
db7da819 179 if ($showsection) {
f9903ed0 180
db7da819 181 $currentweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate));
f9903ed0 182
e9b9c1d8 183 $currenttext = '';
db7da819 184 if (!$thissection->visible) {
6cba878d 185 $sectionstyle = ' hidden';
db7da819 186 } else if ($currentweek) {
6cba878d 187 $sectionstyle = ' current';
e9b9c1d8 188 $currenttext = get_accesshide(get_string('currentweek','access'));
db7da819 189 } else {
6cba878d 190 $sectionstyle = '';
1ea7c627 191 }
192
c1ac64b5 193 echo '<tr id="section-'.$section.'" class="section main'.$sectionstyle.'">';
e9b9c1d8 194 echo '<td class="left side">&nbsp;'.$currenttext.'</td>';
dc140b6c 195
9837bd1d 196 $weekperiod = $weekday.' - '.$endweekday;
88c5092a 197
6cba878d 198 echo '<td class="content">';
3924b988 199 if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) { // Hidden for students
3ecc49d4 200 echo '<div class="weekdates">'.$weekperiod.' ('.get_string('notavailable').')</div>';
dc140b6c 201
1ea7c627 202 } else {
3ecc49d4 203 echo '<div class="weekdates">'.$weekperiod.'</div>';
dc140b6c 204
40901069 205 echo '<div class="summary">';
179c9a50 206 $summaryformatoptions->noclean = true;
207 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
dc140b6c 208
61e75e95 209 if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
6cba878d 210 echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
1f48fec7 211 '<img src="'.$CFG->pixpath.'/t/edit.gif" class="iconsmall edit" alt="'.$streditsummary.'" /></a><br /><br />';
db7da819 212 }
40901069 213 echo '</div>';
dc140b6c 214
db7da819 215 print_section($course, $thissection, $mods, $modnamesused);
dc140b6c 216
db7da819 217 if (isediting($course->id)) {
e0161bff 218 print_section_add_menus($course, $section, $modnames);
db7da819 219 }
1ea7c627 220 }
6cba878d 221 echo '</td>';
222
223 echo '<td class="right side">';
12905134 224
db7da819 225 if ($displaysection == $section) {
0cdae0dc 226 echo '<a href="view.php?id='.$course->id.'&amp;week=0#section-'.$section.'" title="'.$strshowallweeks.'">'.
d57be0a8 227 '<img src="'.$CFG->pixpath.'/i/all.gif" class="icon wkall" alt="'.$strshowallweeks.'" /></a><br />';
db7da819 228 } else {
229 $strshowonlyweek = get_string("showonlyweek", "", $section);
6cba878d 230 echo '<a href="view.php?id='.$course->id.'&amp;week='.$section.'" title="'.$strshowonlyweek.'">'.
ce148ff5 231 '<img src="'.$CFG->pixpath.'/i/one.gif" class="icon wkone" alt="'.$strshowonlyweek.'" /></a><br />';
12905134 232 }
dc140b6c 233
217a8ee9 234 if (isediting($course->id) && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
db7da819 235 if ($thissection->visible) { // Show the hide/show eye
4baeb9b0 236 echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strweekhide.'">'.
14efad93 237 '<img src="'.$CFG->pixpath.'/i/hide.gif" class="icon hide" alt="'.$strweekhide.'" /></a><br />';
db7da819 238 } else {
58de1815 239 echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.$USER->sesskey.'#section-'.$section.'" title="'.$strweekshow.'">'.
14efad93 240 '<img src="'.$CFG->pixpath.'/i/show.gif" class="icon hide" alt="'.$strweekshow.'" /></a><br />';
db7da819 241 }
db7da819 242 if ($section > 1) { // Add a arrow to move section up
1bc6fc82 243 echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=-1&amp;sesskey='.$USER->sesskey.'#section-'.($section-1).'" title="'.$strmoveup.'">'.
1f48fec7 244 '<img src="'.$CFG->pixpath.'/t/up.gif" class="iconsmall up" alt="'.$strmoveup.'" /></a><br />';
db7da819 245 }
dc140b6c 246
db7da819 247 if ($section < $course->numsections) { // Add a arrow to move section down
1bc6fc82 248 echo '<a href="view.php?id='.$course->id.'&amp;random='.rand(1,10000).'&amp;section='.$section.'&amp;move=1&amp;sesskey='.$USER->sesskey.'#section-'.($section+1).'" title="'.$strmovedown.'">'.
1f48fec7 249 '<img src="'.$CFG->pixpath.'/t/down.gif" class="iconsmall down" alt="'.$strmovedown.'" /></a><br />';
db7da819 250 }
12905134 251 }
dc140b6c 252
6cba878d 253 echo '</td></tr>';
c1ac64b5 254 echo '<tr class="section separator"><td colspan="3" class="spacer"></td></tr>';
1ea7c627 255 }
256
1ea7c627 257 $section++;
f9903ed0 258 $weekdate = $nextweekdate;
259 }
6cba878d 260 echo '</table>';
584ec10e 261
262 if (!empty($sectionmenu)) {
6cba878d 263 echo '<div align="center" class="jumpmenu">';
99499e69 264 echo popup_form($CFG->wwwroot.'/course/view.php?id='.$course->id.'&amp;', $sectionmenu,
6cba878d 265 'sectionmenu', '', get_string('jumpto'), '', '', true);
266 echo '</div>';
584ec10e 267 }
0f3fe4b6 268
f145c248 269 if (!empty($THEME->customcorners)) print_custom_corners_end();
dd9098cc 270
6cba878d 271 echo '</td>';
0f3fe4b6 272
dd9098cc 273 break;
274 case 'right':
0f3fe4b6 275 // The right column
dffd4bb9 276 if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing) {
bd792a75 277 echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
dd9098cc 278
f145c248 279 if (!empty($THEME->customcorners)) print_custom_corners_start();
66492322 280 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
f145c248 281 if (!empty($THEME->customcorners)) print_custom_corners_end();
dd9098cc 282
9b4b78fd 283 echo '</td>';
13beeacb 284 }
19a55d67 285
dd9098cc 286 break;
287 }
288 }
6cba878d 289 echo '</tr></table>';
290
2ef9d19a 291?>