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