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