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