Latest version for Moodle 1.2 from wim
[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
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");
584ec10e 26 $strweek = get_string("week");
f374fb10 27 $strgroups = get_string("groups");
28 $strgroupmy = get_string("groupmy");
1ea7c627 29 if (isediting($course->id)) {
30 $strstudents = moodle_strtolower($course->students);
31 $strweekhide = get_string("weekhide", "", $strstudents);
32 $strweekshow = get_string("weekshow", "", $strstudents);
d7b97e43 33 $strmoveup = get_string("moveup");
34 $strmovedown = get_string("movedown");
1ea7c627 35 }
9a223597 36
600149be 37
9a223597 38/// Layout the whole page as three big columns.
dc0dc7d5 39 echo "<table border=0 cellpadding=3 cellspacing=0 width=100%>";
f9903ed0 40
9a223597 41/// The left column ...
13c7e271 42
dc0dc7d5 43 echo "<tr valign=top><td valign=top width=180>";
13c7e271 44
9a223597 45/// Links to people
dc0dc7d5 46 $moddata[]="<a title=\"".get_string("listofallpeople")."\" href=\"../user/index.php?id=$course->id\">".get_string("participants")."</a>";
c9f6251e 47 $modicon[]="<img src=\"$CFG->pixpath/i/users.gif\" height=16 width=16 alt=\"\">";
f374fb10 48
49 if ($course->groupmode or !$course->groupmodeforce) {
3d575e6f 50 if ($course->groupmode == VISIBLEGROUPS or isteacheredit($course->id)) {
f374fb10 51 $moddata[]="<a title=\"$strgroups\" href=\"groups.php?id=$course->id\">$strgroups</a>";
15e06a24 52 $modicon[]="<img src=\"$CFG->pixpath/i/group.gif\" height=16 width=16 alt=\"\">";
3d575e6f 53 } else if ($course->groupmode == SEPARATEGROUPS and $course->groupmodeforce) {
54 // Show nothing
f374fb10 55 } else if ($currentgroup = get_current_group($course->id)) {
56 $moddata[]="<a title=\"$strgroupmy\" href=\"group.php?id=$course->id\">$strgroupmy</a>";
15e06a24 57 $modicon[]="<img src=\"$CFG->pixpath/i/group.gif\" height=16 width=16 alt=\"\">";
f374fb10 58 }
f374fb10 59 }
60
5fde0ca6 61 $fullname = fullname($USER, true);
62 $editmyprofile = "<a title=\"$fullname\" href=\"../user/edit.php?id=$USER->id&course=$course->id\">".get_string("editmyprofile")."</a>";
2c0411e2 63 if ($USER->description) {
64 $moddata[]= $editmyprofile;
65 } else {
dc0dc7d5 66 $moddata[]= $editmyprofile." <blink>*</blink>";
2c0411e2 67 }
c9f6251e 68 $modicon[]="<img src=\"$CFG->pixpath/i/user.gif\" height=16 width=16 alt=\"\">";
5e367a2d 69 print_side_block(get_string("people"), "", $moddata, $modicon);
13c7e271 70
f9903ed0 71
9a223597 72/// Then all the links to activities by type
f9903ed0 73 $moddata = array();
74 $modicon = array();
90845098 75 if ($modnamesused) {
76 foreach ($modnamesused as $modname => $modfullname) {
c9f6251e 77 if ($modname != "label") {
78 $moddata[] = "<a href=\"../mod/$modname/index.php?id=$course->id\">".$modnamesplural[$modname]."</a>";
79 $modicon[] = "<img src=\"$CFG->modpixpath/$modname/icon.gif\" height=16 width=16 alt=\"\">";
80 }
f9903ed0 81 }
82 }
5e367a2d 83 print_side_block($stractivities, "", $moddata, $modicon);
f9903ed0 84
9a223597 85/// Print a form to search forums
5e367a2d 86 $searchform = forum_print_search_form($course, "", true);
b86fc0e2 87 $searchform = "<div align=\"center\">$searchform</div>";
5e367a2d 88 print_side_block(get_string("search","forum"), $searchform);
9a223597 89
13c7e271 90
9a223597 91/// Admin links and controls
13469b82 92 print_course_admin_links($course);
f9903ed0 93
f3120024 94/// My courses
95 print_courses_sideblock(0, "180");
9a223597 96
97/// Start main column
b86fc0e2 98 echo "</td><td width=\"*\">";
7541bc3e 99 print_heading_block(get_string("weeklyoutline"), "100%", "outlineheadingblock");
e5454458 100 print_spacer(8, 1, true);
9a223597 101
7541bc3e 102 echo "<table class=\"weeklyoutline\" border=\"0\" cellpadding=\"8\" cellspacing=\"0\" width=\"100%\">";
9a223597 103
7977cffd 104/// If currently moving a file then show the current clipboard
105 if (ismoving($course->id)) {
adcedde7 106 $stractivityclipboard = strip_tags(get_string("activityclipboard", "", addslashes($USER->activitycopyname)));
7977cffd 107 $strcancel= get_string("cancel");
108 echo "<tr>";
109 echo "<td colspan=3 valign=top bgcolor=\"$THEME->cellcontent\" class=\"weeklyoutlineclip\" width=\"100%\">";
110 echo "<p><font size=2>";
111 echo "$stractivityclipboard&nbsp;&nbsp;(<a href=\"mod.php?cancelcopy=true\">$strcancel</a>)";
112 echo "</font></p>";
113 echo "</td>";
114 echo "</tr>";
115 echo "<tr><td colspan=3><img src=\"../pix/spacer.gif\" width=1 height=1></td></tr>";
116 }
117
1ea7c627 118/// Print Section 0 with general activities
9a223597 119
1ea7c627 120 $section = 0;
121 $thissection = $sections[$section];
9a223597 122
1ea7c627 123 if ($thissection->summary or $thissection->sequence or isediting($course->id)) {
dc0dc7d5 124 echo "<tr>";
125 echo "<td nowrap bgcolor=\"$THEME->cellheading\" class=\"weeklyoutlineside\" valign=top width=20>&nbsp;</td>";
126 echo "<td valign=top bgcolor=\"$THEME->cellcontent\" class=\"weeklyoutlinecontent\" width=\"100%\">";
9a223597 127
128 if (isediting($course->id)) {
399266ce 129 $thissection->summary .= " <a title=\"$streditsummary\" ".
c9f6251e 130 "href=\"editsection.php?id=$thissection->id\"><img height=11 width=11 src=\"$CFG->pixpath/t/edit.gif\" ".
dc0dc7d5 131 "border=0 alt=\"$streditsummary\"></a></p>";
9a223597 132 }
133
445b2301 134 echo format_text($thissection->summary);
9a223597 135
1ea7c627 136 print_section($course, $thissection, $mods, $modnamesused);
9a223597 137
138 if (isediting($course->id)) {
dc0dc7d5 139 echo "<div align=right>";
1ea7c627 140 popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
141 $modnames, "section$section", "", "$stradd...", "mods", $stractivities);
dc0dc7d5 142 echo "</div>";
9a223597 143 }
144
b86fc0e2 145 echo "</td>";
146 echo "<td nowrap bgcolor=\"$THEME->cellheading\" class=\"weeklyoutlineside\" valign=top align=center width=10>";
1ea7c627 147 echo "&nbsp;</td></tr>";
b86fc0e2 148 echo "<tr><td colspan=3><img src=\"../pix/spacer.gif\" width=1 height=1></td></tr>";
9a223597 149 }
150
151
152/// Now all the weekly sections
f9903ed0 153 $timenow = time();
154 $weekdate = $course->startdate; // this should be 0:00 Monday of that week
674416ea 155 $weekdate += 7200; // Add two hours to avoid possible DST problems
1ea7c627 156 $section = 1;
584ec10e 157 $sectionmenu = array();
f9903ed0 158 $weekofseconds = 604800;
b5fe4c93 159 $course->enddate = $course->startdate + ($weekofseconds * $course->numsections);
f9903ed0 160
dcde9f02 161 $strftimedateshort = " ".get_string("strftimedateshort");
162
e3f0a6a7 163 while ($weekdate < $course->enddate) {
f9903ed0 164
165 $nextweekdate = $weekdate + ($weekofseconds);
1ea7c627 166 $weekday = userdate($weekdate, $strftimedateshort);
167 $endweekday = userdate($weekdate+518400, $strftimedateshort);
600149be 168
1ea7c627 169 if (!empty($displaysection) and $displaysection != $section) { // Check this week is visible
584ec10e 170 $sectionmenu["week=$section"] = s("$strweek $section | $weekday - $endweekday");
1ea7c627 171 $section++;
b86fc0e2 172 $weekdate = $nextweekdate;
173 continue;
600149be 174 }
175
1ea7c627 176 if (!empty($sections[$section])) {
177 $thissection = $sections[$section];
f9903ed0 178
1ea7c627 179 } else {
180 unset($thissection);
181 $thissection->course = $course->id; // Create a new week structure
182 $thissection->section = $section;
183 $thissection->summary = "";
184 $thissection->visible = 1;
185 if (!$thissection->id = insert_record("course_sections", $thissection)) {
186 notify("Error inserting new week!");
187 }
188 }
f9903ed0 189
1ea7c627 190 $currentweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate));
191
192 if (!$thissection->visible) {
193 $colorsides = "bgcolor=\"$THEME->hidden\" class=\"weeklyoutlinesidehidden\"";
194 $colormain = "bgcolor=\"$THEME->cellcontent\" class=\"weeklyoutlinecontenthidden\"";
195 } else if ($currentweek) {
bfca4cff 196 $colorsides = "bgcolor=\"$THEME->cellheading2\" class=\"weeklyoutlinesidehighlight\"";
197 $colormain = "bgcolor=\"$THEME->cellcontent\" class=\"weeklyoutlinecontenthighlight\"";
f9903ed0 198 } else {
bfca4cff 199 $colorsides = "bgcolor=\"$THEME->cellheading\" class=\"weeklyoutlineside\"";
200 $colormain = "bgcolor=\"$THEME->cellcontent\" class=\"weeklyoutlinecontent\"";
f9903ed0 201 }
202
dc0dc7d5 203 echo "<tr>";
204 echo "<td nowrap $colorsides valign=top width=20>";
1ea7c627 205 echo "<p align=center><font size=3><b>$section</b></font></p>";
dc0dc7d5 206 echo "</td>";
f9903ed0 207
1ea7c627 208 echo "<td valign=top $colormain width=\"100%\">";
209
210 if (!isteacher($course->id) and !$thissection->visible) { // Hidden for students
211 echo "<p class=\"weeklydatetext\">$weekday - $endweekday ";
212 echo "(".get_string("notavailable").")";
213 echo "</p>";
214 echo "</td>";
f9903ed0 215
f8430195 216 } else {
f9903ed0 217
1ea7c627 218 echo "<p class=\"weeklydatetext\">$weekday - $endweekday</p>";
f9903ed0 219
1ea7c627 220 if (isediting($course->id)) {
399266ce 221 $thissection->summary .= " <a title=\"$streditsummary\" href=\"editsection.php?id=$thissection->id\">".
c9f6251e 222 "<img src=\"$CFG->pixpath/t/edit.gif\" height=11 width=11 border=0></a></p>";
1ea7c627 223 }
f9903ed0 224
445b2301 225 echo format_text($thissection->summary);
f9903ed0 226
1ea7c627 227 print_section($course, $thissection, $mods, $modnamesused);
f9903ed0 228
1ea7c627 229 if (isediting($course->id)) {
230 echo "<div align=right>";
231 popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&add=",
232 $modnames, "section$section", "", "$stradd...");
233 echo "</div>";
234 }
235
236 echo "</td>";
237 }
dc0dc7d5 238 echo "<td nowrap $colorsides valign=top align=center width=10>";
239 echo "<font size=1>";
1ea7c627 240
241 if ($displaysection == $section) {
242 echo "<a href=\"view.php?id=$course->id&week=all\" title=\"$strshowallweeks\">".
c9f6251e 243 "<img src=\"$CFG->pixpath/i/all.gif\" height=25 width=16 border=0></a><br />";
600149be 244 } else {
1ea7c627 245 $strshowonlyweek = get_string("showonlyweek", "", $section);
246 echo "<a href=\"view.php?id=$course->id&week=$section\" title=\"$strshowonlyweek\">".
c9f6251e 247 "<img src=\"$CFG->pixpath/i/one.gif\" height=16 width=16 border=0></a><br />";
600149be 248 }
1ea7c627 249
250 if (isediting($course->id)) {
251 if ($thissection->visible) { // Show the hide/show eye
252 echo "<a href=\"view.php?id=$course->id&hide=$section\" title=\"$strweekhide\">".
c9f6251e 253 "<img src=\"$CFG->pixpath/i/hide.gif\" vspace=3 height=16 width=16 border=0></a><br />";
1ea7c627 254 } else {
255 echo "<a href=\"view.php?id=$course->id&show=$section\" title=\"$strweekshow\">".
c9f6251e 256 "<img src=\"$CFG->pixpath/i/show.gif\" vspace=3 height=16 width=16 border=0></a><br />";
1ea7c627 257 }
12905134 258
259 if ($section > 1) { // Add a arrow to move section up
d7b97e43 260 echo "<a href=\"view.php?id=$course->id&section=$section&move=-1\" title=\"$strmoveup\">".
c9f6251e 261 "<img src=\"$CFG->pixpath/t/up.gif\" vspace=3 height=11 width=11 border=0></a><br />";
12905134 262 }
263
264 if ($section < $course->numsections) { // Add a arrow to move section down
d7b97e43 265 echo "<a href=\"view.php?id=$course->id&section=$section&move=1\" title=\"$strmovedown\">".
c9f6251e 266 "<img src=\"$CFG->pixpath/t/down.gif\" vspace=3 height=11 width=11 border=0></a><br />";
12905134 267 }
268
1ea7c627 269 }
270
dc0dc7d5 271 echo "</td>";
272 echo "</tr>";
273 echo "<tr><td colspan=3><img src=\"../pix/spacer.gif\" width=1 height=1></td></tr>";
f9903ed0 274
1ea7c627 275 $section++;
f9903ed0 276 $weekdate = $nextweekdate;
277 }
dc0dc7d5 278 echo "</table>";
584ec10e 279
280 if (!empty($sectionmenu)) {
281 echo "<center>";
282 echo popup_form("$CFG->wwwroot/course/view.php?id=$course->id&", $sectionmenu,
283 "sectionmenu", "", get_string("jumpto"), "", "", true);
284 echo "</center>";
285 }
f9903ed0 286
ce78926d 287 if (!empty($news) or !empty($course->showrecent)) {
dc0dc7d5 288 echo "</td><td width=210>";
13beeacb 289
290 // Print all the news items.
291
ce78926d 292 if (!empty($news)) {
7541bc3e 293 print_side_block_start(get_string("latestnews"), 210, "sideblocklatestnews");
dc0dc7d5 294 echo "<font size=\"-2\">";
32dcc874 295 forum_print_latest_discussions($news->id, $course->newsitems, "minimal", "", false);
dc0dc7d5 296 echo "</font>";
7541bc3e 297 print_side_block_end();
13beeacb 298 }
299
300 // Print all the recent activity
ce78926d 301 if (!empty($course->showrecent)) {
7541bc3e 302 print_side_block_start(get_string("recentactivity"), 210, "sideblockrecentactivity");
13beeacb 303 print_recent_activity($course);
7541bc3e 304 print_side_block_end();
13beeacb 305 }
600149be 306
7541bc3e 307 print_spacer(1, 120, true);
13beeacb 308 }
19a55d67 309
dc0dc7d5 310 echo "</td></tr></table>\n";
f9903ed0 311
312?>