testing wrong thing
[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
765814de 5 include_once("$CFG->dirroot/mod/forum/lib.php");
f9903ed0 6
94361e02 7 if (! $sections = get_all_sections($course->id)) {
b5fe4c93 8 $section->course = $course->id; // Create a default section.
9 $section->section = 0;
10 $section->id = insert_record("course_sections", $section);
94361e02 11 if (! $sections = get_all_sections($course->id) ) {
b5fe4c93 12 error("Error finding or creating section structures for this course");
f9903ed0 13 }
14 }
f9903ed0 15
72e62a9e 16 if (isset($week)) {
17 if ($week == "all") {
b5fe4c93 18 unset($USER->section);
600149be 19 } else {
72e62a9e 20 $USER->section = $week;
600149be 21 }
8223d271 22 save_session("USER");
600149be 23 }
24
9a223597 25 if ($course->newsitems) {
26 $news = forum_get_course_forum($course->id, "news");
27 }
d897cae4 28
29 $streditsummary = get_string("editsummary");
30 $stradd = get_string("add");
31 $stractivities = get_string("activities");
9a223597 32
600149be 33
9a223597 34/// Layout the whole page as three big columns.
600149be 35 echo "<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 WIDTH=100%>";
f9903ed0 36
9a223597 37/// The left column ...
13c7e271 38
9a223597 39 echo "<TR VALIGN=top><TD VALIGN=top WIDTH=180>";
13c7e271 40
9a223597 41/// Links to people
59a7100c 42 $moddata[]="<A TITLE=\"".get_string("listofallpeople")."\" HREF=\"../user/index.php?id=$course->id\">".get_string("participants")."</A>";
2c0411e2 43 $modicon[]="<IMG SRC=\"../user/users.gif\" HEIGHT=16 WIDTH=16 ALT=\"\">";
2415d953 44 $editmyprofile = "<A TITLE=\"$USER->firstname $USER->lastname\" HREF=\"../user/view.php?id=$USER->id&course=$course->id\">".get_string("editmyprofile")."</A>";
2c0411e2 45 if ($USER->description) {
46 $moddata[]= $editmyprofile;
47 } else {
9a223597 48 $moddata[]= $editmyprofile." <BLINK>*</BLINK>";
2c0411e2 49 }
50 $modicon[]="<IMG SRC=\"../user/user.gif\" HEIGHT=16 WIDTH=16 ALT=\"\">";
5e367a2d 51 print_side_block(get_string("people"), "", $moddata, $modicon);
13c7e271 52
f9903ed0 53
9a223597 54/// Then all the links to activities by type
f9903ed0 55 $moddata = array();
56 $modicon = array();
90845098 57 if ($modnamesused) {
58 foreach ($modnamesused as $modname => $modfullname) {
59 $moddata[] = "<A HREF=\"../mod/$modname/index.php?id=$course->id\">".$modnamesplural[$modname]."</A>";
2c0411e2 60 $modicon[] = "<IMG SRC=\"../mod/$modname/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"\">";
f9903ed0 61 }
62 }
5e367a2d 63 print_side_block($stractivities, "", $moddata, $modicon);
f9903ed0 64
9a223597 65/// Print a form to search forums
5e367a2d 66 $searchform = forum_print_search_form($course, "", true);
67 $searchform = "<DIV ALIGN=\"CENTER\">$searchform</DIV>";
68 print_side_block(get_string("search","forum"), $searchform);
9a223597 69
13c7e271 70
9a223597 71/// Admin links and controls
0d97d1e3 72 if (isteacher($course->id)) {
b4d7002e 73 print_course_admin_links($course);
f9903ed0 74 }
f9903ed0 75
9a223597 76
77/// Start main column
f51ab26b 78 echo "</TD><TD WIDTH=\"*\">";
5e367a2d 79 print_heading_block(get_string("weeklyoutline"));
9a223597 80
81 echo "<TABLE BORDER=0 CELLPADDING=8 CELLSPACING=0 WIDTH=100%>";
82
83
84/// Print Week 0 with general activities
85
86 $week = 0;
87 $thisweek = $sections[$week];
88
89 if ($thisweek->summary or $thisweek->sequence or isediting($course->id)) {
90 echo "<TR>";
91 echo "<TD NOWRAP BGCOLOR=\"$THEME->cellheading\" VALIGN=top WIDTH=20>&nbsp;</TD>";
92 echo "<TD VALIGN=top BGCOLOR=\"$THEME->cellcontent\" WIDTH=\"100%\">";
93
94 if (isediting($course->id)) {
95 $thisweek->summary .= "&nbsp;<A TITLE=\"$streditsummary\" ".
96 "HREF=\"editsection.php?id=$thisweek->id\"><IMG SRC=\"../pix/t/edit.gif\" ".
97 "BORDER=0 ALT=\"$streditsummary\"></A></P>";
98 }
99
100 echo text_to_html($thisweek->summary);
101
d897cae4 102 print_section($course, $thisweek, $mods, $modnamesused);
9a223597 103
104 if (isediting($course->id)) {
105 echo "<DIV ALIGN=right>";
106 popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$week&add=",
d897cae4 107 $modnames, "section$week", "", "$stradd...", "mods", $stractivities);
9a223597 108 echo "</DIV>";
109 }
110
111 echo "</TD>";
112 echo "<TD NOWRAP BGCOLOR=\"$THEME->cellheading\" VALIGN=top ALIGN=CENTER WIDTH=10>";
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
118
119/// Now all the weekly sections
f9903ed0 120 $timenow = time();
121 $weekdate = $course->startdate; // this should be 0:00 Monday of that week
122 $week = 1;
123 $weekofseconds = 604800;
b5fe4c93 124 $course->enddate = $course->startdate + ($weekofseconds * $course->numsections);
f9903ed0 125
e3f0a6a7 126 while ($weekdate < $course->enddate) {
f9903ed0 127
128 $nextweekdate = $weekdate + ($weekofseconds);
600149be 129
72e62a9e 130 if (isset($USER->section)) { // Just display a single week
131 if ($USER->section != $week) {
600149be 132 $week++;
133 $weekdate = $nextweekdate;
134 continue;
135 }
136 }
137
f9903ed0 138 $thisweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate));
139
bea7a51e 140 $weekday = userdate($weekdate, " %d %B");
141 $endweekday = userdate($weekdate+518400, " %d %B");
f9903ed0 142
143 if ($thisweek) {
144 $highlightcolor = $THEME->cellheading2;
145 } else {
146 $highlightcolor = $THEME->cellheading;
147 }
148
600149be 149 echo "<TR>";
d3e2c35a 150 echo "<TD NOWRAP BGCOLOR=\"$highlightcolor\" VALIGN=top WIDTH=20>";
f9903ed0 151 echo "<P ALIGN=CENTER><FONT SIZE=3><B>$week</B></FONT></P>";
152 echo "</TD>";
153
d3e2c35a 154 echo "<TD VALIGN=top BGCOLOR=\"$THEME->cellcontent\" WIDTH=\"100%\">";
f9903ed0 155 echo "<P><FONT SIZE=3 COLOR=\"$THEME->cellheading2\">$weekday - $endweekday</FONT></P>";
156
b5fe4c93 157 if (! $thisweek = $sections[$week]) {
f9903ed0 158 $thisweek->course = $course->id; // Create a new week structure
ad14a10e 159 $thisweek->section = $week;
f9903ed0 160 $thisweek->summary = "";
ad14a10e 161 if (!$thisweek->id = insert_record("course_sections", $thisweek)) {
162 notify("Error inserting new week!");
163 }
f9903ed0 164 }
165
2c309dc2 166 if (isediting($course->id)) {
2c0411e2 167 $thisweek->summary .= "&nbsp;<A TITLE=\"$streditsummary\" HREF=\"editsection.php?id=$thisweek->id\"><IMG SRC=\"../pix/t/edit.gif\" BORDER=0 ALT=\"$streditsummary\"></A></P>";
f9903ed0 168 }
169
170 echo text_to_html($thisweek->summary);
171
d897cae4 172 print_section($course, $thisweek, $mods, $modnamesused);
f9903ed0 173
2c309dc2 174 if (isediting($course->id)) {
f9903ed0 175 echo "<DIV ALIGN=right>";
b5fe4c93 176 popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$week&add=",
d897cae4 177 $modnames, "section$week", "", "$stradd...", "mods", $stractivities);
f9903ed0 178 echo "</DIV>";
179 }
180
181 echo "</TD>";
d3e2c35a 182 echo "<TD NOWRAP BGCOLOR=\"$highlightcolor\" VALIGN=top ALIGN=CENTER WIDTH=10>";
600149be 183 echo "<FONT SIZE=1>";
72e62a9e 184 if (isset($USER->section)) {
2c0411e2 185 $strshowallweeks = get_string("showallweeks");
186 echo "<A HREF=\"view.php?id=$course->id&week=all\" TITLE=\"$strshowallweeks\"><IMG SRC=../pix/i/all.gif BORDER=0></A></FONT>";
600149be 187 } else {
2c0411e2 188 $strshowonlyweek = get_string("showonlyweek", "", $week);
189 echo "<A HREF=\"view.php?id=$course->id&week=$week\" TITLE=\"$strshowonlyweek\"><IMG SRC=../pix/i/one.gif BORDER=0></A></FONT>";
600149be 190 }
191 echo "</TD>";
f9903ed0 192 echo "</TR>";
600149be 193 echo "<TR><TD COLSPAN=3><IMG SRC=\"../pix/spacer.gif\" WIDTH=1 HEIGHT=1></TD></TR>";
f9903ed0 194
195 $week++;
196 $weekdate = $nextweekdate;
197 }
198 echo "</TABLE>";
f9903ed0 199
13beeacb 200 if ($news or $course->showrecent) {
201 echo "</TD><TD WIDTH=210>";
202
203 // Print all the news items.
204
205 if ($news) {
5e367a2d 206 print_heading_block(get_string("latestnews"));
6e07f680 207 print_simple_box_start("CENTER", "100%", $THEME->cellcontent, 3, 0);
13beeacb 208 echo "<FONT SIZE=1>";
209 forum_print_latest_discussions($news->id, $course->newsitems, "minimal", "DESC", false);
210 echo "</FONT>";
211 print_simple_box_end();
469e5eb1 212 echo "<BR \>";
13beeacb 213 }
214
215 // Print all the recent activity
216 if ($course->showrecent) {
5e367a2d 217 print_heading_block(get_string("recentactivity"));
6e07f680 218 print_simple_box_start("CENTER", "100%", $THEME->cellcontent, 3, 0);
13beeacb 219 print_recent_activity($course);
220 print_simple_box_end();
221 }
600149be 222
469e5eb1 223 echo "<BR \><IMG SRC=\"../pix/spacer.gif\" WIDTH=210 HEIGHT=1>";
13beeacb 224 }
19a55d67 225
f51ab26b 226 echo "</TD></TR></TABLE>\n";
f9903ed0 227
228?>