moodle_page: MDL-12212 reimplement user_is_editing, deprecate isediting
[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);
ab9ad21d 60/* Internet Explorer min-width fix. (See theme/standard/styles_layout.css: min-width for Firefox.)
61 Window width: 800px, Firefox 763px, IE 752px. (Window width: 640px, Firefox 602px, IE 588px.)
62*/
63?>
64
65<!--[if IE]>
66 <style type="text/css">
67 .weeks-format { width: expression(document.body.clientWidth < 800 ? "752px" : "auto"); }
68 </style>
69<![endif]-->
70<?php
71/// Layout the whole page as three big columns (was, id="layout-table")
72 echo '<div class="weeks-format">';
73
0f3fe4b6 74/// The left column ...
f374fb10 75
dffd4bb9 76 if (blocks_have_content($pageblocks, BLOCK_POS_LEFT) || $editing) {
9f7f1a74 77 print_container_start();
ab9ad21d 78 echo '<div id="left-column">';
66492322 79 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_LEFT);
ab9ad21d 80 echo '</div>';
9f7f1a74 81 print_container_end();
2c0411e2 82 }
ab9ad21d 83
84/// The right column, BEFORE the middle-column.
85 if (blocks_have_content($pageblocks, BLOCK_POS_RIGHT) || $editing) {
9f7f1a74 86 print_container_start();
ab9ad21d 87 echo '<div id="right-column">';
88 blocks_print_group($PAGE, $pageblocks, BLOCK_POS_RIGHT);
89 echo '</div>';
9f7f1a74 90 print_container_end();
ab9ad21d 91 }
92
9a223597 93/// Start main column
ab9ad21d 94 echo '<div id="middle-column">';
9f7f1a74 95 print_container_start();
446390fb 96
ab9ad21d 97 echo skip_main_destination();
98
446390fb 99 print_heading_block(get_string('weeklyoutline'), 'outline');
9a223597 100
ab9ad21d 101 // Note, an ordered list would confuse - "1" could be the clipboard or summary.
102 echo "<ul class='weeks'>\n";
9a223597 103
7977cffd 104/// If currently moving a file then show the current clipboard
105 if (ismoving($course->id)) {
294ce987 106 $stractivityclipboard = strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
6cba878d 107 $strcancel= get_string('cancel');
ab9ad21d 108 echo '<li class="clipboard">';
d4a1fcaf 109 echo $stractivityclipboard.'&nbsp;&nbsp;(<a href="mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
ab9ad21d 110 echo "</li>\n";
c63bf72a 111 }
7977cffd 112
1ea7c627 113/// Print Section 0 with general activities
9a223597 114
1ea7c627 115 $section = 0;
116 $thissection = $sections[$section];
9a223597 117
830dd6e9 118 if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
ab9ad21d 119
120 // Note, 'right side' is BEFORE content.
121 echo '<li id="section-0" class="section main" >';
122 echo '<div class="left side">&nbsp;</div>';
123 echo '<div class="right side" >&nbsp;</div>';
124 echo '<div class="content">';
40901069 125
126 echo '<div class="summary">';
644d506a 127
128 $coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
edc0c493 129 $summarytext = file_rewrite_pluginfile_urls($thissection->summary, 'pluginfile.php', $coursecontext->id, 'course_section', $thissection->id);
644d506a 130 $summaryformatoptions = new object();
179c9a50 131 $summaryformatoptions->noclean = true;
644d506a 132 echo format_text($summarytext, FORMAT_HTML, $summaryformatoptions);
5f850588 133
830dd6e9 134 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
ab9ad21d 135 echo '<p><a title="'.$streditsummary.'" '.
6cba878d 136 ' href="editsection.php?id='.$thissection->id.'"><img src="'.$CFG->pixpath.'/t/edit.gif" '.
ab9ad21d 137 ' class="icon edit" alt="'.$streditsummary.'" /></a></p>';
9a223597 138 }
40901069 139 echo '</div>';
140
1ea7c627 141 print_section($course, $thissection, $mods, $modnamesused);
9a223597 142
830dd6e9 143 if ($PAGE->user_is_editing()) {
e0161bff 144 print_section_add_menus($course, $section, $modnames);
9a223597 145 }
146
ab9ad21d 147 echo '</div>';
148 echo "</li>\n";
9a223597 149 }
150
151
6cba878d 152/// Now all the normal modules by week
153/// Everything below uses "section" terminology - each "section" is a week.
154
f9903ed0 155 $timenow = time();
156 $weekdate = $course->startdate; // this should be 0:00 Monday of that week
01e1f34e 157 $weekdate += 7200; // Add two hours to avoid possible DST problems
1ea7c627 158 $section = 1;
584ec10e 159 $sectionmenu = array();
01e1f34e 160 $weekofseconds = 604800;
b5fe4c93 161 $course->enddate = $course->startdate + ($weekofseconds * $course->numsections);
f9903ed0 162
6cba878d 163 $strftimedateshort = ' '.get_string('strftimedateshort');
dcde9f02 164
e3f0a6a7 165 while ($weekdate < $course->enddate) {
f9903ed0 166
167 $nextweekdate = $weekdate + ($weekofseconds);
1ea7c627 168 $weekday = userdate($weekdate, $strftimedateshort);
01e1f34e 169 $endweekday = userdate($weekdate+518400, $strftimedateshort);
600149be 170
1ea7c627 171 if (!empty($sections[$section])) {
172 $thissection = $sections[$section];
f9903ed0 173
1ea7c627 174 } else {
175 unset($thissection);
176 $thissection->course = $course->id; // Create a new week structure
177 $thissection->section = $section;
6cba878d 178 $thissection->summary = '';
1ea7c627 179 $thissection->visible = 1;
f400841b 180 if (!$thissection->id = $DB->insert_record('course_sections', $thissection)) {
6cba878d 181 notify('Error inserting new week!');
1ea7c627 182 }
183 }
f9903ed0 184
3924b988 185 $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
f9903ed0 186
8dc93b94 187 if (!empty($displaysection) and $displaysection != $section) { // Check this week is visible
188 if ($showsection) {
6cba878d 189 $sectionmenu['week='.$section] = s("$strweek $section | $weekday - $endweekday");
8dc93b94 190 }
191 $section++;
192 $weekdate = $nextweekdate;
193 continue;
194 }
195
db7da819 196 if ($showsection) {
f9903ed0 197
db7da819 198 $currentweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate));
f9903ed0 199
e9b9c1d8 200 $currenttext = '';
db7da819 201 if (!$thissection->visible) {
6cba878d 202 $sectionstyle = ' hidden';
db7da819 203 } else if ($currentweek) {
6cba878d 204 $sectionstyle = ' current';
e9b9c1d8 205 $currenttext = get_accesshide(get_string('currentweek','access'));
db7da819 206 } else {
6cba878d 207 $sectionstyle = '';
1ea7c627 208 }
209
ab9ad21d 210 echo '<li id="section-'.$section.'" class="section main'.$sectionstyle.'" >';
dc140b6c 211
ab9ad21d 212 echo '<div class="left side">&nbsp;'.$currenttext.'</div>';
12905134 213
ab9ad21d 214 // Note, 'right side' is BEFORE content.
215 echo '<div class="right side">';
216
db7da819 217 if ($displaysection == $section) {
0cdae0dc 218 echo '<a href="view.php?id='.$course->id.'&amp;week=0#section-'.$section.'" title="'.$strshowallweeks.'">'.
d57be0a8 219 '<img src="'.$CFG->pixpath.'/i/all.gif" class="icon wkall" alt="'.$strshowallweeks.'" /></a><br />';
db7da819 220 } else {
221 $strshowonlyweek = get_string("showonlyweek", "", $section);
6cba878d 222 echo '<a href="view.php?id='.$course->id.'&amp;week='.$section.'" title="'.$strshowonlyweek.'">'.
ce148ff5 223 '<img src="'.$CFG->pixpath.'/i/one.gif" class="icon wkone" alt="'.$strshowonlyweek.'" /></a><br />';
12905134 224 }
dc140b6c 225
830dd6e9 226 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
db7da819 227 if ($thissection->visible) { // Show the hide/show eye
d4a1fcaf 228 echo '<a href="view.php?id='.$course->id.'&amp;hide='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strweekhide.'">'.
14efad93 229 '<img src="'.$CFG->pixpath.'/i/hide.gif" class="icon hide" alt="'.$strweekhide.'" /></a><br />';
db7da819 230 } else {
d4a1fcaf 231 echo '<a href="view.php?id='.$course->id.'&amp;show='.$section.'&amp;sesskey='.sesskey().'#section-'.$section.'" title="'.$strweekshow.'">'.
14efad93 232 '<img src="'.$CFG->pixpath.'/i/show.gif" class="icon hide" alt="'.$strweekshow.'" /></a><br />';
db7da819 233 }
db7da819 234 if ($section > 1) { // Add a arrow to move section up
d4a1fcaf 235 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.'">'.
ab9ad21d 236 '<img src="'.$CFG->pixpath.'/t/up.gif" class="icon up" alt="'.$strmoveup.'" /></a><br />';
db7da819 237 }
dc140b6c 238
db7da819 239 if ($section < $course->numsections) { // Add a arrow to move section down
d4a1fcaf 240 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.'">'.
ab9ad21d 241 '<img src="'.$CFG->pixpath.'/t/down.gif" class="icon down" alt="'.$strmovedown.'" /></a><br />';
242 }
243 }
244 echo '</div>';
245
0154653b 246 $weekperiod = $weekday.' - '.$endweekday;
247
ab9ad21d 248 echo '<div class="content">';
249 if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) { // Hidden for students
0154653b 250 print_heading($currenttext.$weekperiod.' ('.get_string('notavailable').')', null, 3, 'weekdates');
ab9ad21d 251
252 } else {
0154653b 253 print_heading($currenttext.$weekperiod, null, 3, 'weekdates');
ab9ad21d 254
255 echo '<div class="summary">';
256 $summaryformatoptions->noclean = true;
257 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
258
830dd6e9 259 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $course->id))) {
ab9ad21d 260 echo ' <a title="'.$streditsummary.'" href="editsection.php?id='.$thissection->id.'">'.
261 '<img src="'.$CFG->pixpath.'/t/edit.gif" class="icon edit" alt="'.$streditsummary.'" /></a><br /><br />';
262 }
263 echo '</div>';
264
265 print_section($course, $thissection, $mods, $modnamesused);
266
830dd6e9 267 if ($PAGE->user_is_editing()) {
ab9ad21d 268 print_section_add_menus($course, $section, $modnames);
db7da819 269 }
12905134 270 }
dc140b6c 271
ab9ad21d 272 echo '</div>';
273 echo "</li>\n";
1ea7c627 274 }
275
1ea7c627 276 $section++;
f9903ed0 277 $weekdate = $nextweekdate;
278 }
ab9ad21d 279 echo "</ul>\n";
584ec10e 280
281 if (!empty($sectionmenu)) {
85db96c5 282 echo '<div class="jumpmenu">';
99499e69 283 echo popup_form($CFG->wwwroot.'/course/view.php?id='.$course->id.'&amp;', $sectionmenu,
6cba878d 284 'sectionmenu', '', get_string('jumpto'), '', '', true);
285 echo '</div>';
584ec10e 286 }
0f3fe4b6 287
9f7f1a74 288 print_container_end();
2119c151 289 echo '</div>';
dd9098cc 290
ab9ad21d 291 echo '</div>';
292 echo '<div class="clearer"></div>';
6cba878d 293
2ef9d19a 294?>