Missed a spot there
[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
b0e3a925 5 require_once("$CFG->dirroot/mod/forum/lib.php");
f9903ed0 6
0f3fe4b6 7 // Bounds for block widths
8 define('BLOCK_L_MIN_WIDTH', 100);
9 define('BLOCK_L_MAX_WIDTH', 210);
10 define('BLOCK_R_MIN_WIDTH', 100);
11 define('BLOCK_R_MAX_WIDTH', 210);
12
9b4b78fd 13 optional_variable($preferred_width_left, blocks_preferred_width($pageblocks[BLOCK_POS_LEFT]));
14 optional_variable($preferred_width_right, blocks_preferred_width($pageblocks[BLOCK_POS_RIGHT]));
0f3fe4b6 15 $preferred_width_left = min($preferred_width_left, BLOCK_L_MAX_WIDTH);
16 $preferred_width_left = max($preferred_width_left, BLOCK_L_MIN_WIDTH);
17 $preferred_width_right = min($preferred_width_right, BLOCK_R_MAX_WIDTH);
18 $preferred_width_right = max($preferred_width_right, BLOCK_R_MIN_WIDTH);
f9903ed0 19
72e62a9e 20 if (isset($week)) {
b86fc0e2 21 $displaysection = course_set_display($course->id, $week);
22 } else {
23 if (isset($USER->display[$course->id])) {
24 $displaysection = $USER->display[$course->id];
600149be 25 } else {
b86fc0e2 26 $displaysection = course_set_display($course->id, 0);
600149be 27 }
28 }
29
9a223597 30 if ($course->newsitems) {
31 $news = forum_get_course_forum($course->id, "news");
32 }
0f3fe4b6 33
a3f24f7c 34 $streditsummary = get_string('editsummary');
35 $stradd = get_string('add');
36 $stractivities = get_string('activities');
37 $strshowallweeks = get_string('showallweeks');
38 $strweek = get_string('week');
39 $strgroups = get_string('groups');
40 $strgroupmy = get_string('groupmy');
41 $editing = $PAGE->user_is_editing();
42
0f3fe4b6 43 if ($editing) {
1ea7c627 44 $strstudents = moodle_strtolower($course->students);
45 $strweekhide = get_string("weekhide", "", $strstudents);
46 $strweekshow = get_string("weekshow", "", $strstudents);
d7b97e43 47 $strmoveup = get_string("moveup");
48 $strmovedown = get_string("movedown");
1ea7c627 49 }
9a223597 50
600149be 51
9a223597 52/// Layout the whole page as three big columns.
e96ba29d 53 echo '<table id="layout-table"><tr>';
13c7e271 54
0f3fe4b6 55/// The left column ...
f374fb10 56
9b4b78fd 57 if(blocks_have_content($pageblocks[BLOCK_POS_LEFT]) || $editing) {
e96ba29d 58 echo '<td style="width: '.$preferred_width_left.'px;" id="left-column">';
f032aa7a 59 blocks_print_group($PAGE, $pageblocks[BLOCK_POS_LEFT]);
0f3fe4b6 60 echo '</td>';
2c0411e2 61 }
9a223597 62
63/// Start main column
e96ba29d 64 echo '<td id="middle-column">';
446390fb 65
66 print_heading_block(get_string('weeklyoutline'), 'outline');
e5454458 67 print_spacer(8, 1, true);
9a223597 68
7541bc3e 69 echo "<table class=\"weeklyoutline\" border=\"0\" cellpadding=\"8\" cellspacing=\"0\" width=\"100%\">";
9a223597 70
7977cffd 71/// If currently moving a file then show the current clipboard
72 if (ismoving($course->id)) {
adcedde7 73 $stractivityclipboard = strip_tags(get_string("activityclipboard", "", addslashes($USER->activitycopyname)));
7977cffd 74 $strcancel= get_string("cancel");
75 echo "<tr>";
554cec9f 76 echo "<td colspan=\"3\" valign=\"top\" class=\"weeklyoutlineclip\" width=\"100%\">";
0e2851b9 77 echo "<div><font size=\"2\">";
8b92f5bb 78 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"mod.php?cancelcopy=true&amp;sesskey=$USER->sesskey\">$strcancel</a>)";
0e2851b9 79 echo "</font></div>";
7977cffd 80 echo "</td>";
81 echo "</tr>";
839f2456 82 echo "<tr><td colspan=\"3\"><img src=\"../pix/spacer.gif\" width=\"1\" height=\"1\" alt=\"\" /></td></tr>";
7977cffd 83 }
84
1ea7c627 85/// Print Section 0 with general activities
9a223597 86
1ea7c627 87 $section = 0;
88 $thissection = $sections[$section];
9a223597 89
1ea7c627 90 if ($thissection->summary or $thissection->sequence or isediting($course->id)) {
dc0dc7d5 91 echo "<tr>";
554cec9f 92 echo "<td nowrap=\"nowrap\" class=\"weeklyoutlineside\" valign=\"top\" width=\"20\">&nbsp;</td>";
93 echo "<td valign=\"top\" class=\"weeklyoutlinecontent\" width=\"100%\">";
9a223597 94
179c9a50 95 $summaryformatoptions->noclean = true;
96 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
5f850588 97
9a223597 98 if (isediting($course->id)) {
5f850588 99 echo " <a title=\"$streditsummary\" ".
24f2b65a 100 " href=\"editsection.php?id=$thissection->id\"><img height=\"11\" width=\"11\" src=\"$CFG->pixpath/t/edit.gif\" ".
dfc12289 101 " border=\"0\" alt=\"$streditsummary\" /></a><br /><br />";
9a223597 102 }
5f850588 103
1ea7c627 104 print_section($course, $thissection, $mods, $modnamesused);
9a223597 105
106 if (isediting($course->id)) {
e0161bff 107 print_section_add_menus($course, $section, $modnames);
9a223597 108 }
109
b86fc0e2 110 echo "</td>";
554cec9f 111 echo "<td nowrap=\"nowrap\" class=\"weeklyoutlineside\" valign=\"top\" align=\"center\" width=\"10\">";
1ea7c627 112 echo "&nbsp;</td></tr>";
839f2456 113 echo "<tr><td colspan=\"3\"><img src=\"../pix/spacer.gif\" width=\"1\" height=\"1\" alt=\"\" /></td></tr>";
9a223597 114 }
115
116
117/// Now all the weekly sections
f9903ed0 118 $timenow = time();
119 $weekdate = $course->startdate; // this should be 0:00 Monday of that week
674416ea 120 $weekdate += 7200; // Add two hours to avoid possible DST problems
1ea7c627 121 $section = 1;
584ec10e 122 $sectionmenu = array();
f9903ed0 123 $weekofseconds = 604800;
b5fe4c93 124 $course->enddate = $course->startdate + ($weekofseconds * $course->numsections);
f9903ed0 125
dcde9f02 126 $strftimedateshort = " ".get_string("strftimedateshort");
127
e3f0a6a7 128 while ($weekdate < $course->enddate) {
f9903ed0 129
130 $nextweekdate = $weekdate + ($weekofseconds);
1ea7c627 131 $weekday = userdate($weekdate, $strftimedateshort);
132 $endweekday = userdate($weekdate+518400, $strftimedateshort);
600149be 133
1ea7c627 134 if (!empty($sections[$section])) {
135 $thissection = $sections[$section];
f9903ed0 136
1ea7c627 137 } else {
138 unset($thissection);
139 $thissection->course = $course->id; // Create a new week structure
140 $thissection->section = $section;
141 $thissection->summary = "";
142 $thissection->visible = 1;
143 if (!$thissection->id = insert_record("course_sections", $thissection)) {
144 notify("Error inserting new week!");
145 }
146 }
f9903ed0 147
db7da819 148 $showsection = (isteacher($course->id) or $thissection->visible or !$course->hiddensections);
f9903ed0 149
8dc93b94 150 if (!empty($displaysection) and $displaysection != $section) { // Check this week is visible
151 if ($showsection) {
152 $sectionmenu["week=$section"] = s("$strweek $section | $weekday - $endweekday");
153 }
154 $section++;
155 $weekdate = $nextweekdate;
156 continue;
157 }
158
db7da819 159 if ($showsection) {
f9903ed0 160
db7da819 161 $currentweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate));
f9903ed0 162
db7da819 163 if (!$thissection->visible) {
554cec9f 164 $colorsides = "class=\"weeklyoutlinesidehidden\"";
165 $colormain = "class=\"weeklyoutlinecontenthidden\"";
db7da819 166 } else if ($currentweek) {
554cec9f 167 $colorsides = "class=\"weeklyoutlinesidehighlight\"";
168 $colormain = "class=\"weeklyoutlinecontenthighlight\"";
db7da819 169 } else {
554cec9f 170 $colorsides = "class=\"weeklyoutlineside\"";
171 $colormain = "class=\"weeklyoutlinecontent\"";
1ea7c627 172 }
173
db7da819 174 echo "<tr>";
44ff1b87 175 echo "<td nowrap=\"nowrap\" $colorsides valign=\"top\" width=\"20\">";
0e2851b9 176 echo "<div align=\"center\"><font size=\"3\"><a name=\"$section\">$section</a></font></div>";
1ea7c627 177 echo "</td>";
dc140b6c 178
24f2b65a 179 echo "<td valign=\"top\" $colormain width=\"100%\">";
dc140b6c 180
db7da819 181 if (!isteacher($course->id) and !$thissection->visible) { // Hidden for students
0e2851b9 182 echo "<div class=\"weeklydatetext\">$weekday - $endweekday ";
db7da819 183 echo "(".get_string("notavailable").")";
0e2851b9 184 echo "</div>";
db7da819 185 echo "</td>";
dc140b6c 186
1ea7c627 187 } else {
dc140b6c 188
0e2851b9 189 echo "<div class=\"weeklydatetext\">$weekday - $endweekday</div>";
dc140b6c 190
179c9a50 191 $summaryformatoptions->noclean = true;
192 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
dc140b6c 193
db7da819 194 if (isediting($course->id)) {
195 echo " <a title=\"$streditsummary\" href=\"editsection.php?id=$thissection->id\">".
dfc12289 196 "<img src=\"$CFG->pixpath/t/edit.gif\" height=\"11\" width=\"11\" border=\"0\" /></a><br /><br />";
db7da819 197 }
dc140b6c 198
db7da819 199 print_section($course, $thissection, $mods, $modnamesused);
dc140b6c 200
db7da819 201 if (isediting($course->id)) {
e0161bff 202 print_section_add_menus($course, $section, $modnames);
db7da819 203 }
dc140b6c 204
db7da819 205 echo "</td>";
1ea7c627 206 }
44ff1b87 207 echo "<td nowrap=\"nowrap\" $colorsides valign=\"top\" align=\"center\" width=\"10\">";
24f2b65a 208 echo "<font size=\"1\">";
12905134 209
db7da819 210 if ($displaysection == $section) {
839f2456 211 echo "<a href=\"view.php?id=$course->id&amp;week=all\" title=\"$strshowallweeks\">".
212 "<img src=\"$CFG->pixpath/i/all.gif\" height=\"25\" width=\"16\" border=\"0\" alt=\"\" /></a><br />";
db7da819 213 } else {
214 $strshowonlyweek = get_string("showonlyweek", "", $section);
839f2456 215 echo "<a href=\"view.php?id=$course->id&amp;week=$section\" title=\"$strshowonlyweek\">".
216 "<img src=\"$CFG->pixpath/i/one.gif\" height=\"16\" width=\"16\" border=\"0\" alt=\"\" /></a><br />";
12905134 217 }
dc140b6c 218
db7da819 219 if (isediting($course->id)) {
220 if ($thissection->visible) { // Show the hide/show eye
5b224948 221 echo "<a href=\"view.php?id=$course->id&amp;hide=$section&amp;sesskey=$USER->sesskey\" title=\"$strweekhide\">".
839f2456 222 "<img src=\"$CFG->pixpath/i/hide.gif\" vspace=\"3\" height=\"16\" width=\"16\" border=\"0\" alt=\"\" /></a><br />";
db7da819 223 } else {
5b224948 224 echo "<a href=\"view.php?id=$course->id&amp;show=$section&amp;sesskey=$USER->sesskey\" title=\"$strweekshow\">".
839f2456 225 "<img src=\"$CFG->pixpath/i/show.gif\" vspace=\"3\" height=\"16\" width=\"16\" border=\"0\" alt=\"\" /></a><br />";
db7da819 226 }
dc140b6c 227
db7da819 228 if ($section > 1) { // Add a arrow to move section up
5b224948 229 echo "<a href=\"view.php?id=$course->id&amp;section=$section&amp;move=-1&amp;sesskey=$USER->sesskey\" title=\"$strmoveup\">".
839f2456 230 "<img src=\"$CFG->pixpath/t/up.gif\" vspace=\"3\" height=\"11\" width=\"11\" border=\"0\" alt=\"\" /></a><br />";
db7da819 231 }
dc140b6c 232
db7da819 233 if ($section < $course->numsections) { // Add a arrow to move section down
5b224948 234 echo "<a href=\"view.php?id=$course->id&amp;section=$section&amp;move=1&amp;sesskey=$USER->sesskey\" title=\"$strmovedown\">".
839f2456 235 "<img src=\"$CFG->pixpath/t/down.gif\" vspace=\"3\" height=\"11\" width=\"11\" border=\"0\" alt=\"\" /></a><br />";
db7da819 236 }
dc140b6c 237
12905134 238 }
dc140b6c 239
44ff1b87 240 echo "</font>";
db7da819 241 echo "</td>";
242 echo "</tr>";
839f2456 243 echo "<tr><td colspan=\"3\"><img src=\"../pix/spacer.gif\" width=\"1\" height=\"1\" alt=\"\"></td></tr>";
1ea7c627 244 }
245
1ea7c627 246 $section++;
f9903ed0 247 $weekdate = $nextweekdate;
248 }
dc0dc7d5 249 echo "</table>";
584ec10e 250
251 if (!empty($sectionmenu)) {
252 echo "<center>";
0f3fe4b6 253 echo popup_form("$CFG->wwwroot/course/view.php?id=$course->id&", $sectionmenu,
584ec10e 254 "sectionmenu", "", get_string("jumpto"), "", "", true);
255 echo "</center>";
256 }
0f3fe4b6 257
258
259 echo "</td>";
260
261 // The right column
9b4b78fd 262 if(blocks_have_content($pageblocks[BLOCK_POS_RIGHT]) || $editing) {
e96ba29d 263 echo '<td style="width: '.$preferred_width_right.'px;" id="right-column">';
f032aa7a 264 blocks_print_group($PAGE, $pageblocks[BLOCK_POS_RIGHT]);
c1d8705f 265 if ($editing) {
266 blocks_print_adminblock($PAGE, $pageblocks);
13beeacb 267 }
9b4b78fd 268 echo '</td>';
13beeacb 269 }
19a55d67 270
0f3fe4b6 271 echo "</tr>\n";
272 echo "</table>\n";
f9903ed0 273?>