Initial revision
[moodle.git] / course / weeks.php
CommitLineData
f9903ed0 1<?PHP // $Id$
2
3// Display the whole course as "weeks" made of of modules
4// Included from "view.php"
5
6 if (! $rawweeks = get_records("course_weeks", "course", $course->id) ) {
7 $week->course = $course->id; // Create a default week.
8 $week->week = 0;
9 $week->id = insert_record("course_weeks", $week);
10 if (! $rawweeks = get_records("course_weeks", "course", $course->id) ) {
11 error("Error finding or creating week structures for this course");
12 }
13 }
14
15 foreach($rawweeks as $cw) { //Index the weeks
16 $weeks[$cw->week] = $cw;
17 }
18
19 // Layout the whole page as two big columns.
20 echo "<TABLE BORDER=0 CELLPADDING=4>";
21 echo "<TR VALIGN=top><TD VALIGN=top WIDTH=200>";
22 echo "<IMG SRC=\"../pix/spacer.gif\" WIDTH=180 HEIGHT=1><BR>";
23
24 // Layout the left column
25
26 print_side_block("<A HREF=\"new.php?id=$course->id\">What's New!</A>",
27 "", "<FONT SIZE=1>...since your last login</FONT>");
28
29 // Then, print all the news items.
30
31 include("../mod/discuss/lib.php");
32 if ($news = get_course_news_forum($course->id)) {
33 print_simple_box_start("CENTER", "100%", "#FFFFFF", 5);
34 echo "<P><B><FONT SIZE=2>Latest News</FONT></B><BR>";
35 echo "<FONT SIZE=1>";
36 forum_latest_topics($news->id, 5, "minimal", "DESC", false);
37 echo "</FONT>";
38 print_simple_box_end();
39 }
40
41 // Now, print all the course links on the side
42
43 // Then all the links to module types
44
45 $moddata = array();
46 $modicon = array();
47
48 if ($modtype) {
49 foreach ($modtype as $modname => $modfullname) {
50 $moddata[] = "<A HREF=\"../mod/$modname/index.php?id=$course->id\">".$modfullname."s</A>";
51 $modicon[] = "<IMG SRC=\"../mod/$modname/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"$modfullname\">";
52 }
53 }
54
55 $moddata[]="<A HREF=\"../user/index.php?id=$course->id\">Participants</A>";
56 $modicon[]="<IMG SRC=\"../user/users.gif\" HEIGHT=16 WIDTH=16 ALT=\"Participants\">";
57
58 print_side_block("Activities", $moddata, "", $modicon);
59
60 // Admin links and controls
61
62 $admindata[]="<A HREF=\"../user/view.php?id=$USER->id&course=$course->id\">My details</A>";
63 $adminicon[]="<IMG SRC=\"../user/user.gif\" HEIGHT=16 WIDTH=16 ALT=\"About me\">";
64
65 if ($USER->teacher[$course->id]) {
66 $admindata[]="<A HREF=\"edit.php?id=$course->id\">Course settings</A>";
67 $adminicon[]="<IMG SRC=\"../pix/i/settings.gif\" HEIGHT=16 WIDTH=16 ALT=\"Course\">";
68 $admindata[]="<A HREF=\"log.php?id=$course->id\">Logs</A>";
69 $adminicon[]="<IMG SRC=\"../pix/i/log.gif\" HEIGHT=16 WIDTH=16 ALT=\"Log\">";
70 $admindata[]="<A HREF=\"email.php?id=$course->id\">Send mail</A>";
71 $adminicon[]="<IMG SRC=\"../pix/i/email.gif\" HEIGHT=16 WIDTH=16 ALT=\"Email\">";
72 $admindata[]="<A HREF=\"../files/index.php?id=$course->id\">Files</A>";
73 $adminicon[]="<IMG SRC=\"../files/pix/files.gif\" HEIGHT=16 WIDTH=16 ALT=\"Files\">";
74 }
75 print_side_block("Administration", $admindata, "", $adminicon);
76
77
78 // Start main column
79 echo "</TD><TD WIDTH=100%>";
80
81 // Now all the weekly modules
82
83
84 $timenow = time();
85 $weekdate = $course->startdate; // this should be 0:00 Monday of that week
86 $week = 1;
87 $weekofseconds = 604800;
88
89 echo "<P><IMG SRC=\"../pix/spacer.gif\" WIDTH=100% HEIGHT=3><BR>";
90 echo "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>";
91 echo "<TR><TD>";
92 echo "<B><FONT SIZE=2>Weekly Outline</FONT></B>\n";
93
94 // Global switches
95 echo "</TD><TD NOWRAP ALIGN=RIGHT><P><FONT SIZE=1>";
96 if ($USER->teacher[$course->id]) {
97 if ($USER->editing) {
98 echo "<A HREF=\"view.php?id=$course->id&edit=off\">Turn editing off</A>";
99 } else {
100 echo "<A HREF=\"view.php?id=$course->id&edit=on\">Turn editing on</A>";
101 }
102 }
103 if ($USER->help) {
104 echo "&nbsp;&nbsp;&nbsp;<A HREF=\"view.php?id=$course->id&help=off\">Turn help off</A>";
105 } else {
106 echo "&nbsp;&nbsp;&nbsp;<A HREF=\"view.php?id=$course->id&help=on\">Turn help on</A>";
107 }
108 echo "</FONT></P></TD></TR></TABLE>";
109
110 echo "<TABLE BORDER=0 CELLPADDING=8 CELLSPACING=0 WIDTH=100%>";
111 while ($weekdate < $course->enddate) {
112 echo "<TR>";
113
114 $nextweekdate = $weekdate + ($weekofseconds);
115 $thisweek = (($weekdate <= $timenow) && ($timenow < $nextweekdate));
116
117 $weekday = date("j F", $weekdate);
118 $endweekday = date("j F", $weekdate+(6*24*3600));
119
120 if ($thisweek) {
121 $highlightcolor = $THEME->cellheading2;
122 } else {
123 $highlightcolor = $THEME->cellheading;
124 }
125
126 echo "<TD NOWRAP BGCOLOR=\"$highlightcolor\" VALIGN=top>";
127 echo "<P ALIGN=CENTER><FONT SIZE=3><B>$week</B></FONT></P>";
128 echo "</TD>";
129
130 echo "<TD VALIGN=top BGCOLOR=\"$THEME->cellcontent\">";
131 echo "<P><FONT SIZE=3 COLOR=\"$THEME->cellheading2\">$weekday - $endweekday</FONT></P>";
132
133 if (! $thisweek = $weeks[$week]) {
134 $thisweek->course = $course->id; // Create a new week structure
135 $thisweek->week = $week;
136 $thisweek->summary = "";
137 $thisweek->id = insert_record("course_weeks", $thisweek);
138 }
139
140 if ($USER->editing) {
141 $thisweek->summary .= "&nbsp;<A HREF=editweek.php?id=$thisweek->id><IMG SRC=\"../pix/t/edit.gif\" BORDER=0 ALT=\"Edit summary\"></A></P>";
142 }
143
144 echo text_to_html($thisweek->summary);
145
146 echo "<P>";
147 if ($thisweek->sequence) {
148
149 $thisweekmods = explode(",", $thisweek->sequence);
150
151 foreach ($thisweekmods as $modnumber) {
152 $mod = $mods[$modnumber];
153 $instancename = get_field("$mod->modname", "name", "id", "$mod->instance");
154 echo "<IMG SRC=\"../mod/$mod->modname/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\"> <A HREF=\"../mod/$mod->modname/view.php?id=$mod->id\">$instancename</A>";
155 if ($USER->editing) {
156 echo make_editing_buttons($mod->id);
157 }
158 echo "<BR>\n";
159 }
160 }
161 echo "</UL></P>\n";
162
163 if ($USER->editing) {
164 echo "<DIV ALIGN=right>";
165 popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&week=$week&add=",
166 $modtypes, "week$week", "", "Add...");
167 echo "</DIV>";
168 }
169
170 echo "</TD>";
171 echo "<TD NOWRAP BGCOLOR=\"$highlightcolor\" VALIGN=top>&nbsp;</TD>";
172 echo "</TR>";
173 echo "<TR><TD COLSPAN=3><IMG SRC=../pix/spacer.gif WIDTH=1 HEIGHT=1></TD></TR>";
174
175 $week++;
176 $weekdate = $nextweekdate;
177 }
178 echo "</TABLE>";
179 echo "</TABLE>";
180
181
182 echo "</TD></TR></TABLE>";
183
184?>