More debug...
[moodle.git] / course / weeks.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
f9903ed0 7
72e62a9e 8 if (isset($week)) {
b86fc0e2 9 $displaysection = course_set_display($course->id, $week);
10 } else {
11 if (isset($USER->display[$course->id])) {
12 $displaysection = $USER->display[$course->id];
600149be 13 } else {
b86fc0e2 14 $displaysection = course_set_display($course->id, 0);
600149be 15 }
16 }
17
9a223597 18 if ($course->newsitems) {
19 $news = forum_get_course_forum($course->id, "news");
20 }
d897cae4 21
1ea7c627 22 $streditsummary = get_string("editsummary");
23 $stradd = get_string("add");
24 $stractivities = get_string("activities");
25 $strshowallweeks = get_string("showallweeks");
26 if (isediting($course->id)) {
27 $strstudents = moodle_strtolower($course->students);
28 $strweekhide = get_string("weekhide", "", $strstudents);
29 $strweekshow = get_string("weekshow", "", $strstudents);
30 }
9a223597 31
600149be 32
9a223597 33/// Layout the whole page as three big columns.
dc0dc7d5 34 echo "<table border=0 cellpadding=3 cellspacing=0 width=100%>";
f9903ed0 35
9a223597 36/// The left column ...
13c7e271 37
dc0dc7d5 38 echo "<tr valign=top><td valign=top width=180>";
13c7e271 39
9a223597 40/// Links to people
dc0dc7d5 41 $moddata[]="<a title=\"".get_string("listofallpeople")."\" href=\"../user/index.php?id=$course->id\">".get_string("participants")."</a>";
42 $modicon[]="<img src=\"$pixpath/i/users.gif\" height=16 width=16 alt=\"\">";
43 $editmyprofile = "<a title=\"$USER->firstname $USER->lastname\" href=\"../user/edit.php?id=$USER->id&course=$course->id\">".get_string("editmyprofile")."</a>";
2c0411e2 44 if ($USER->description) {
45 $moddata[]= $editmyprofile;
46 } else {
dc0dc7d5 47 $moddata[]= $editmyprofile." <blink>*</blink>";
2c0411e2 48 }
dc0dc7d5 49 $modicon[]="<img src=\"$pixpath/i/user.gif\" height=16 width=16 alt=\"\">";
5e367a2d 50 print_side_block(get_string("people"), "", $moddata, $modicon);
13c7e271 51
f9903ed0 52
9a223597 53/// Then all the links to activities by type
f9903ed0 54 $moddata = array();
55 $modicon = array();
90845098 56 if ($modnamesused) {
57 foreach ($modnamesused as $modname => $modfullname) {
dc0dc7d5 58 $moddata[] = "<a href=\"../mod/$modname/index.php?id=$course->id\">".$modnamesplural[$modname]."</a>";
59 $modicon[] = "<img src=\"$modpixpath/$modname/icon.gif\" height=16 width=16 alt=\"\">";
f9903ed0 60 }
61 }
5e367a2d 62 print_side_block($stractivities, "", $moddata, $modicon);
f9903ed0 63
9a223597 64/// Print a form to search forums
5e367a2d 65 $searchform = forum_print_search_form($course, "", true);
b86fc0e2 66 $searchform = "<div align=\"center\">$searchform</div>";
5e367a2d 67 print_side_block(get_string("search","forum"), $searchform);
9a223597 68
13c7e271 69
9a223597 70/// Admin links and controls
13469b82 71 print_course_admin_links($course);
f9903ed0 72
9a223597 73
74/// Start main column
b86fc0e2 75 echo "</td><td width=\"*\">";
7541bc3e 76 print_heading_block(get_string("weeklyoutline"), "100%", "outlineheadingblock");
e5454458 77 print_spacer(8, 1, true);
9a223597 78
7541bc3e 79 echo "<table class=\"weeklyoutline\" border=\"0\" cellpadding=\"8\" cellspacing=\"0\" width=\"100%\">";
9a223597 80
1ea7c627 81/// Print Section 0 with general activities
9a223597 82
1ea7c627 83 $section = 0;
84 $thissection = $sections[$section];
9a223597 85
1ea7c627 86 if ($thissection->summary or $thissection->sequence or isediting($course->id)) {
dc0dc7d5 87 echo "<tr>";
88 echo "<td nowrap bgcolor=\"$THEME->cellheading\" class=\"weeklyoutlineside\" valign=top width=20>&nbsp;</td>";
89 echo "<td valign=top bgcolor=\"$THEME->cellcontent\" class=\"weeklyoutlinecontent\" width=\"100%\">";
9a223597 90
91 if (isediting($course->id)) {
399266ce 92 $thissection->summary .= " <a title=\"$streditsummary\" ".
1ea7c627 93 "href=\"editsection.php?id=$thissection->id\"><img height=11 width=11 src=\"$pixpath/t/edit.gif\" ".
dc0dc7d5 94 "border=0 alt=\"$streditsummary\"></a></p>";
9a223597 95 }
96
1ea7c627 97 echo text_to_html($thissection->summary);
9a223597 98
1ea7c627 99 print_section($course, $thissection, $mods, $modnamesused);
9a223597 100
101 if (isediting($course->id)) {
dc0dc7d5 102 echo "<div align=right>";
1ea7c627 103 popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
104 $modnames, "section$section", "", "$stradd...", "mods", $stractivities);
dc0dc7d5 105 echo "</div>";
9a223597 106 }
107
b86fc0e2 108 echo "</td>";
109 echo "<td nowrap bgcolor=\"$THEME->cellheading\" class=\"weeklyoutlineside\" valign=top align=center width=10>";
1ea7c627 110 echo "&nbsp;</td></tr>";
b86fc0e2 111 echo "<tr><td colspan=3><img src=\"../pix/spacer.gif\" width=1 height=1></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
1ea7c627 118 $section = 1;
f9903ed0 119 $weekofseconds = 604800;
b5fe4c93 120 $course->enddate = $course->startdate + ($weekofseconds * $course->numsections);
f9903ed0 121
dcde9f02 122 $strftimedateshort = " ".get_string("strftimedateshort");
123
e3f0a6a7 124 while ($weekdate < $course->enddate) {
f9903ed0 125
126 $nextweekdate = $weekdate + ($weekofseconds);
1ea7c627 127 $weekday = userdate($weekdate, $strftimedateshort);
128 $endweekday = userdate($weekdate+518400, $strftimedateshort);
600149be 129
1ea7c627 130 if (!empty($displaysection) and $displaysection != $section) { // Check this week is visible
131 $section++;
b86fc0e2 132 $weekdate = $nextweekdate;
133 continue;
600149be 134 }
135
1ea7c627 136 if (!empty($sections[$section])) {
137 $thissection = $sections[$section];
f9903ed0 138
1ea7c627 139 } else {
140 unset($thissection);
141 $thissection->course = $course->id; // Create a new week structure
142 $thissection->section = $section;
143 $thissection->summary = "";
144 $thissection->visible = 1;
145 if (!$thissection->id = insert_record("course_sections", $thissection)) {
146 notify("Error inserting new week!");
147 }
148 }
f9903ed0 149
1ea7c627 150 $currentweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate));
151
152 if (!$thissection->visible) {
153 $colorsides = "bgcolor=\"$THEME->hidden\" class=\"weeklyoutlinesidehidden\"";
154 $colormain = "bgcolor=\"$THEME->cellcontent\" class=\"weeklyoutlinecontenthidden\"";
155 } else if ($currentweek) {
bfca4cff 156 $colorsides = "bgcolor=\"$THEME->cellheading2\" class=\"weeklyoutlinesidehighlight\"";
157 $colormain = "bgcolor=\"$THEME->cellcontent\" class=\"weeklyoutlinecontenthighlight\"";
f9903ed0 158 } else {
bfca4cff 159 $colorsides = "bgcolor=\"$THEME->cellheading\" class=\"weeklyoutlineside\"";
160 $colormain = "bgcolor=\"$THEME->cellcontent\" class=\"weeklyoutlinecontent\"";
f9903ed0 161 }
162
dc0dc7d5 163 echo "<tr>";
164 echo "<td nowrap $colorsides valign=top width=20>";
1ea7c627 165 echo "<p align=center><font size=3><b>$section</b></font></p>";
dc0dc7d5 166 echo "</td>";
f9903ed0 167
1ea7c627 168 echo "<td valign=top $colormain width=\"100%\">";
169
170 if (!isteacher($course->id) and !$thissection->visible) { // Hidden for students
171 echo "<p class=\"weeklydatetext\">$weekday - $endweekday ";
172 echo "(".get_string("notavailable").")";
173 echo "</p>";
174 echo "</td>";
f9903ed0 175
f8430195 176 } else {
f9903ed0 177
1ea7c627 178 echo "<p class=\"weeklydatetext\">$weekday - $endweekday</p>";
f9903ed0 179
1ea7c627 180 if (isediting($course->id)) {
399266ce 181 $thissection->summary .= " <a title=\"$streditsummary\" href=\"editsection.php?id=$thissection->id\">".
1ea7c627 182 "<img src=\"$pixpath/t/edit.gif\" height=11 width=11 border=0></a></p>";
183 }
f9903ed0 184
1ea7c627 185 echo text_to_html($thissection->summary);
f9903ed0 186
1ea7c627 187 print_section($course, $thissection, $mods, $modnamesused);
f9903ed0 188
1ea7c627 189 if (isediting($course->id)) {
190 echo "<div align=right>";
191 popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
192 $modnames, "section$section", "", "$stradd...");
193 echo "</div>";
194 }
195
196 echo "</td>";
197 }
dc0dc7d5 198 echo "<td nowrap $colorsides valign=top align=center width=10>";
199 echo "<font size=1>";
1ea7c627 200
201 if ($displaysection == $section) {
202 echo "<a href=\"view.php?id=$course->id&week=all\" title=\"$strshowallweeks\">".
203 "<img src=\"$pixpath/i/all.gif\" height=25 width=16 border=0></a><br />";
600149be 204 } else {
1ea7c627 205 $strshowonlyweek = get_string("showonlyweek", "", $section);
206 echo "<a href=\"view.php?id=$course->id&week=$section\" title=\"$strshowonlyweek\">".
207 "<img src=\"$pixpath/i/one.gif\" height=16 width=16 border=0></a><br />";
600149be 208 }
1ea7c627 209
210 if (isediting($course->id)) {
211 if ($thissection->visible) { // Show the hide/show eye
212 echo "<a href=\"view.php?id=$course->id&hide=$section\" title=\"$strweekhide\">".
213 "<img src=\"$pixpath/i/hide.gif\" vspace=3 height=16 width=16 border=0></a><br />";
214 } else {
215 echo "<a href=\"view.php?id=$course->id&show=$section\" title=\"$strweekshow\">".
216 "<img src=\"$pixpath/i/show.gif\" vspace=3 height=16 width=16 border=0></a><br />";
217 }
218 }
219
dc0dc7d5 220 echo "</td>";
221 echo "</tr>";
222 echo "<tr><td colspan=3><img src=\"../pix/spacer.gif\" width=1 height=1></td></tr>";
f9903ed0 223
1ea7c627 224 $section++;
f9903ed0 225 $weekdate = $nextweekdate;
226 }
dc0dc7d5 227 echo "</table>";
f9903ed0 228
ce78926d 229 if (!empty($news) or !empty($course->showrecent)) {
dc0dc7d5 230 echo "</td><td width=210>";
13beeacb 231
232 // Print all the news items.
233
ce78926d 234 if (!empty($news)) {
7541bc3e 235 print_side_block_start(get_string("latestnews"), 210, "sideblocklatestnews");
dc0dc7d5 236 echo "<font size=\"-2\">";
32dcc874 237 forum_print_latest_discussions($news->id, $course->newsitems, "minimal", "", false);
dc0dc7d5 238 echo "</font>";
7541bc3e 239 print_side_block_end();
13beeacb 240 }
241
242 // Print all the recent activity
ce78926d 243 if (!empty($course->showrecent)) {
7541bc3e 244 print_side_block_start(get_string("recentactivity"), 210, "sideblockrecentactivity");
13beeacb 245 print_recent_activity($course);
7541bc3e 246 print_side_block_end();
13beeacb 247 }
600149be 248
7541bc3e 249 print_spacer(1, 120, true);
13beeacb 250 }
19a55d67 251
dc0dc7d5 252 echo "</td></tr></table>\n";
f9903ed0 253
254?>