Fixed the primary key problem in the mysql.
[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
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.
dcb1bd3c 51 echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"0\" width=\"100%\">";
f9903ed0 52
24f2b65a 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>";
24f2b65a 75 echo "<td colspan=\"3\" valign=\"top\" bgcolor=\"$THEME->cellcontent\" class=\"weeklyoutlineclip\" width=\"100%\">";
76 echo "<p><font size=\"2\">";
7977cffd 77 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"mod.php?cancelcopy=true\">$strcancel</a>)";
78 echo "</font></p>";
79 echo "</td>";
80 echo "</tr>";
24f2b65a 81 echo "<tr><td colspan=\"3\"><img src=\"../pix/spacer.gif\" width=\"1\" height=\"1\"></td></tr>";
7977cffd 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>";
24f2b65a 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
179c9a50 94 $summaryformatoptions->noclean = true;
95 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
5f850588 96
9a223597 97 if (isediting($course->id)) {
5f850588 98 echo " <a title=\"$streditsummary\" ".
24f2b65a 99 " href=\"editsection.php?id=$thissection->id\"><img height=\"11\" width=\"11\" src=\"$CFG->pixpath/t/edit.gif\" ".
26686b7a 100 " border=\"0\" alt=\"$streditsummary\" /></a><br />";
9a223597 101 }
5f850588 102
26686b7a 103 echo '<br clear="all" />';
0f3fe4b6 104
1ea7c627 105 print_section($course, $thissection, $mods, $modnamesused);
9a223597 106
107 if (isediting($course->id)) {
e0161bff 108 print_section_add_menus($course, $section, $modnames);
9a223597 109 }
110
b86fc0e2 111 echo "</td>";
24f2b65a 112 echo "<td nowrap bgcolor=\"$THEME->cellheading\" class=\"weeklyoutlineside\" valign=\"top\" align=\"center\" width=\"10\">";
1ea7c627 113 echo "&nbsp;</td></tr>";
24f2b65a 114 echo "<tr><td colspan=\"3\"><img src=\"../pix/spacer.gif\" width=\"1\" height=\"1\"></td></tr>";
9a223597 115 }
116
117
118/// Now all the weekly sections
f9903ed0 119 $timenow = time();
120 $weekdate = $course->startdate; // this should be 0:00 Monday of that week
674416ea 121 $weekdate += 7200; // Add two hours to avoid possible DST problems
1ea7c627 122 $section = 1;
584ec10e 123 $sectionmenu = array();
f9903ed0 124 $weekofseconds = 604800;
b5fe4c93 125 $course->enddate = $course->startdate + ($weekofseconds * $course->numsections);
f9903ed0 126
dcde9f02 127 $strftimedateshort = " ".get_string("strftimedateshort");
128
e3f0a6a7 129 while ($weekdate < $course->enddate) {
f9903ed0 130
131 $nextweekdate = $weekdate + ($weekofseconds);
1ea7c627 132 $weekday = userdate($weekdate, $strftimedateshort);
133 $endweekday = userdate($weekdate+518400, $strftimedateshort);
600149be 134
1ea7c627 135 if (!empty($displaysection) and $displaysection != $section) { // Check this week is visible
584ec10e 136 $sectionmenu["week=$section"] = s("$strweek $section | $weekday - $endweekday");
1ea7c627 137 $section++;
b86fc0e2 138 $weekdate = $nextweekdate;
139 continue;
600149be 140 }
141
1ea7c627 142 if (!empty($sections[$section])) {
143 $thissection = $sections[$section];
f9903ed0 144
1ea7c627 145 } else {
146 unset($thissection);
147 $thissection->course = $course->id; // Create a new week structure
148 $thissection->section = $section;
149 $thissection->summary = "";
150 $thissection->visible = 1;
151 if (!$thissection->id = insert_record("course_sections", $thissection)) {
152 notify("Error inserting new week!");
153 }
154 }
f9903ed0 155
db7da819 156 $showsection = (isteacher($course->id) or $thissection->visible or !$course->hiddensections);
f9903ed0 157
db7da819 158 if ($showsection) {
f9903ed0 159
db7da819 160 $currentweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate));
f9903ed0 161
db7da819 162 if (!$thissection->visible) {
163 $colorsides = "bgcolor=\"$THEME->hidden\" class=\"weeklyoutlinesidehidden\"";
164 $colormain = "bgcolor=\"$THEME->cellcontent\" class=\"weeklyoutlinecontenthidden\"";
165 } else if ($currentweek) {
166 $colorsides = "bgcolor=\"$THEME->cellheading2\" class=\"weeklyoutlinesidehighlight\"";
167 $colormain = "bgcolor=\"$THEME->cellcontent\" class=\"weeklyoutlinecontenthighlight\"";
168 } else {
169 $colorsides = "bgcolor=\"$THEME->cellheading\" class=\"weeklyoutlineside\"";
170 $colormain = "bgcolor=\"$THEME->cellcontent\" class=\"weeklyoutlinecontent\"";
1ea7c627 171 }
172
db7da819 173 echo "<tr>";
24f2b65a 174 echo "<td nowrap $colorsides valign=\"top\" width=\"20\">";
175 echo "<p align=\"center\"><font size=\"3\"><a name=\"$section\">$section</a></font></p>";
1ea7c627 176 echo "</td>";
db7da819 177
24f2b65a 178 echo "<td valign=\"top\" $colormain width=\"100%\">";
db7da819 179
180 if (!isteacher($course->id) and !$thissection->visible) { // Hidden for students
181 echo "<p class=\"weeklydatetext\">$weekday - $endweekday ";
182 echo "(".get_string("notavailable").")";
183 echo "</p>";
184 echo "</td>";
185
1ea7c627 186 } else {
db7da819 187
188 echo "<p class=\"weeklydatetext\">$weekday - $endweekday</p>";
189
179c9a50 190 $summaryformatoptions->noclean = true;
191 echo format_text($thissection->summary, FORMAT_HTML, $summaryformatoptions);
db7da819 192
193 if (isediting($course->id)) {
194 echo " <a title=\"$streditsummary\" href=\"editsection.php?id=$thissection->id\">".
26686b7a 195 "<img src=\"$CFG->pixpath/t/edit.gif\" height=\"11\" width=\"11\" border=\"0\" /></a><br />";
db7da819 196 }
197
26686b7a 198 echo '<br clear="all" />';
db7da819 199
200 print_section($course, $thissection, $mods, $modnamesused);
201
202 if (isediting($course->id)) {
e0161bff 203 print_section_add_menus($course, $section, $modnames);
db7da819 204 }
205
206 echo "</td>";
1ea7c627 207 }
24f2b65a 208 echo "<td nowrap $colorsides valign=\"top\" align=\"center\" width=\"10\">";
209 echo "<font size=\"1\">";
12905134 210
db7da819 211 if ($displaysection == $section) {
212 echo "<a href=\"view.php?id=$course->id&week=all\" title=\"$strshowallweeks\">".
26686b7a 213 "<img src=\"$CFG->pixpath/i/all.gif\" height=\"25\" width=\"16\" border=\"0\" /></a><br />";
db7da819 214 } else {
215 $strshowonlyweek = get_string("showonlyweek", "", $section);
216 echo "<a href=\"view.php?id=$course->id&week=$section\" title=\"$strshowonlyweek\">".
26686b7a 217 "<img src=\"$CFG->pixpath/i/one.gif\" height=\"16\" width=\"16\" border=\"0\" /></a><br />";
12905134 218 }
db7da819 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\">".
26686b7a 223 "<img src=\"$CFG->pixpath/i/hide.gif\" vspace=\"3\" height=\"16\" width=\"16\" border=\"0\" /></a><br />";
db7da819 224 } else {
225 echo "<a href=\"view.php?id=$course->id&show=$section\" title=\"$strweekshow\">".
26686b7a 226 "<img src=\"$CFG->pixpath/i/show.gif\" vspace=\"3\" height=\"16\" width=\"16\" border=\"0\" /></a><br />";
db7da819 227 }
228
229 if ($section > 1) { // Add a arrow to move section up
230 echo "<a href=\"view.php?id=$course->id&section=$section&move=-1\" title=\"$strmoveup\">".
26686b7a 231 "<img src=\"$CFG->pixpath/t/up.gif\" vspace=\"3\" height=\"11\" width=\"11\" border=\"0\" /></a><br />";
db7da819 232 }
233
234 if ($section < $course->numsections) { // Add a arrow to move section down
235 echo "<a href=\"view.php?id=$course->id&section=$section&move=1\" title=\"$strmovedown\">".
26686b7a 236 "<img src=\"$CFG->pixpath/t/down.gif\" vspace=\"3\" height=\"11\" width=\"11\" border=\"0\" /></a><br />";
db7da819 237 }
238
12905134 239 }
db7da819 240
241 echo "</td>";
242 echo "</tr>";
24f2b65a 243 echo "<tr><td colspan=\"3\"><img src=\"../pix/spacer.gif\" width=\"1\" height=\"1\"></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
262 if(block_have_active($rightblocks) || $editing) {
263 echo '<td style="vertical-align: top; width: '.$preferred_width_right.'px;">';
9743a982 264 print_course_blocks($course, $rightblocks, BLOCK_RIGHT);
0f3fe4b6 265 if ($editing && !empty($missingblocks)) {
6236ed99 266 block_print_blocks_admin($course, $missingblocks);
13beeacb 267 }
7541bc3e 268 print_spacer(1, 120, true);
0f3fe4b6 269 echo '</td>';
13beeacb 270 }
19a55d67 271
0f3fe4b6 272 echo "</tr>\n";
273 echo "</table>\n";
f9903ed0 274?>