Added a "topics" format. it's very similar to the "Weeks" format,
[moodle.git] / course / topics.php
CommitLineData
0b35af18 1<?PHP // $Id$
2 // Display the whole course as "topics" made of of modules
3 // In fact, this is very similar to the "weeks" format, in that
4 // each "topic" is actually a week. The main difference is that
5 // the dates aren't printed - it's just an aesthetic thing for
6 // courses that aren't so rigidly defined by time.
7 // Included from "view.php"
8
9 include("../mod/discuss/lib.php");
10
11 if (! $rawweeks = get_records("course_weeks", "course", $course->id) ) {
12 $week->course = $course->id; // Create a default week.
13 $week->week = 0;
14 $week->id = insert_record("course_weeks", $week);
15 if (! $rawweeks = get_records("course_weeks", "course", $course->id) ) {
16 error("Error finding or creating week structures for this course");
17 }
18 }
19
20 foreach($rawweeks as $cw) { //Index the weeks
21 $weeks[$cw->week] = $cw;
22 }
23
24 if (isset($topic)) {
25 if ($topic == "all") {
26 unset($USER->topic);
27 } else {
28 $USER->topic = $topic;
29 }
30 }
31
32 if (isteacher($course->id) and isset($marker)) {
33 $course->marker = $marker;
34 if (! set_field("course", "marker", $marker, "id", $course->id)) {
35 error("Could not mark that topic for this course");
36 }
37 }
38
39
40 // Layout the whole page as three big columns.
41 echo "<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 WIDTH=100%>";
42 echo "<TR VALIGN=top><TD VALIGN=top WIDTH=180>";
43
44 // Layout the left column
45
46
47 // Links to people
48
49 print_simple_box("People", $align="CENTER", $width="100%", $color="$THEME->cellheading");
50 $moddata[]="<A HREF=\"../user/index.php?id=$course->id\">List of all people</A>";
51 $modicon[]="<IMG SRC=\"../user/users.gif\" HEIGHT=16 WIDTH=16 ALT=\"List of everyone\">";
52 $moddata[]="<A HREF=\"../user/view.php?id=$USER->id&course=$course->id\">Edit my profile</A>";
53 $modicon[]="<IMG SRC=\"../user/user.gif\" HEIGHT=16 WIDTH=16 ALT=\"Me\">";
54 print_side_block("", $moddata, "", $modicon);
55
56
57 // Then all the links to module types
58
59 $moddata = array();
60 $modicon = array();
61 if ($modtype) {
62 foreach ($modtype as $modname => $modfullname) {
63 $moddata[] = "<A HREF=\"../mod/$modname/index.php?id=$course->id\">".$modfullname."s</A>";
64 $modicon[] = "<IMG SRC=\"../mod/$modname/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"$modfullname\">";
65 }
66 }
67 print_simple_box("Activities", $align="CENTER", $width="100%", $color="$THEME->cellheading");
68 print_side_block("", $moddata, "", $modicon);
69
70 // Print a form to search discussions
71 print_simple_box("Search Discussions", $align="CENTER", $width="100%", $color="$THEME->cellheading");
72 echo "<DIV ALIGN=CENTER>";
73 print_discussion_search_form($course);
74 echo "</DIV>";
75
76 // Admin links and controls
77
78 if (isteacher($course->id)) {
79 $adminicon[]="<IMG SRC=\"../pix/i/edit.gif\" HEIGHT=16 WIDTH=16 ALT=\"Edit\">";
80 if ($USER->editing) {
81 $admindata[]="<A HREF=\"view.php?id=$course->id&edit=off\">Turn editing off</A>";
82 } else {
83 $admindata[]="<A HREF=\"view.php?id=$course->id&edit=on\">Turn editing on</A>";
84 }
85
86 $admindata[]="<A HREF=\"edit.php?id=$course->id\">Course settings...</A>";
87 $adminicon[]="<IMG SRC=\"../pix/i/settings.gif\" HEIGHT=16 WIDTH=16 ALT=\"Course\">";
88 $admindata[]="<A HREF=\"log.php?id=$course->id\">Logs...</A>";
89 $adminicon[]="<IMG SRC=\"../pix/i/log.gif\" HEIGHT=16 WIDTH=16 ALT=\"Log\">";
90 $admindata[]="<A HREF=\"../files/index.php?id=$course->id\">Files...</A>";
91 $adminicon[]="<IMG SRC=\"../files/pix/files.gif\" HEIGHT=16 WIDTH=16 ALT=\"Files\">";
92
93 print_simple_box("Administration", $align="CENTER", $width="100%", $color="$THEME->cellheading");
94 print_side_block("", $admindata, "", $adminicon);
95 }
96
97
98 // Start main column
99 echo "</TD><TD WIDTH=\"*\">";
100
101 print_simple_box("Topic Outline", $align="CENTER", $width="100%", $color="$THEME->cellheading");
102
103 // Everything below uses "week" terminology - each "week" is a topic.
104
105 // Now all the weekly modules
106 $timenow = time();
107 $weekdate = $course->startdate; // this should be 0:00 Monday of that week
108 $week = 1;
109 $weekofseconds = 604800;
110
111 echo "<TABLE BORDER=0 CELLPADDING=8 CELLSPACING=0 WIDTH=100%>";
112 while ($weekdate < $course->enddate) {
113
114 $nextweekdate = $weekdate + ($weekofseconds);
115
116 if (isset($USER->topic)) { // Just display a single topic
117 if ($USER->topic != $week) {
118 $week++;
119 $weekdate = $nextweekdate;
120 continue;
121 }
122 }
123
124 $currenttopic = ($course->marker == $week);
125
126 if ($currenttopic) {
127 $highlightcolor = $THEME->cellheading2;
128 } else {
129 $highlightcolor = $THEME->cellheading;
130 }
131
132 echo "<TR>";
133 echo "<TD NOWRAP BGCOLOR=\"$highlightcolor\" VALIGN=top WIDTH=20>";
134 echo "<P ALIGN=CENTER><FONT SIZE=3><B>$week</B></FONT></P>";
135 echo "</TD>";
136
137 echo "<TD VALIGN=top BGCOLOR=\"$THEME->cellcontent\" WIDTH=\"100%\">";
138
139 if (! $thisweek = $weeks[$week]) {
140 $thisweek->course = $course->id; // Create a new week structure
141 $thisweek->week = $week;
142 $thisweek->summary = "";
143 $thisweek->id = insert_record("course_weeks", $thisweek);
144 }
145
146 if ($USER->editing) {
147 $thisweek->summary .= "&nbsp;<A HREF=editweek.php?id=$thisweek->id><IMG SRC=\"../pix/t/edit.gif\" BORDER=0 ALT=\"Edit summary\"></A></P>";
148 }
149
150 echo text_to_html($thisweek->summary);
151
152 echo "<P>";
153 if ($thisweek->sequence) {
154
155 $thisweekmods = explode(",", $thisweek->sequence);
156
157 foreach ($thisweekmods as $modnumber) {
158 $mod = $mods[$modnumber];
159 $instancename = get_field("$mod->modname", "name", "id", "$mod->instance");
160 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>";
161 if ($USER->editing) {
162 echo make_editing_buttons($mod->id);
163 }
164 echo "<BR>\n";
165 }
166 }
167 echo "</UL></P>\n";
168
169 if ($USER->editing) {
170 echo "<DIV ALIGN=right>";
171 popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&week=$week&add=",
172 $modtypes, "week$week", "", "Add...");
173 echo "</DIV>";
174 }
175
176 echo "</TD>";
177 echo "<TD NOWRAP BGCOLOR=\"$highlightcolor\" VALIGN=top ALIGN=CENTER WIDTH=10>";
178 echo "<FONT SIZE=1>";
179 if (isset($USER->topic)) {
180 echo "<A HREF=\"view.php?id=$course->id&topic=all\" TITLE=\"Show all topics\"><IMG SRC=../pix/i/allweeks.gif BORDER=0></A><BR><BR>";
181 } else {
182 echo "<A HREF=\"view.php?id=$course->id&topic=$week\" TITLE=\"Show only topic $week\"><IMG SRC=../pix/i/oneweek.gif BORDER=0></A><BR><BR>";
183 }
184 if ($USER->editing and $course->marker != $week) {
185 echo "<A HREF=\"view.php?id=$course->id&marker=$week\" TITLE=\"Mark this topic as the current topic\"><IMG SRC=../pix/i/marker.gif BORDER=0></A><BR><BR>";
186 }
187 echo "</TD>";
188 echo "</TR>";
189 echo "<TR><TD COLSPAN=3><IMG SRC=\"../pix/spacer.gif\" WIDTH=1 HEIGHT=1></TD></TR>";
190
191 $week++;
192 $weekdate = $nextweekdate;
193 }
194 echo "</TABLE>";
195
196
197 echo "</TD><TD WIDTH=180>";
198
199 // Print all the news items.
200
201 if ($news = get_course_news_forum($course->id)) {
202 print_simple_box("Latest News", $align="CENTER", $width="100%", $color="$THEME->cellheading");
203 print_simple_box_start("CENTER", "100%", "#FFFFFF", 3, 0);
204 echo "<FONT SIZE=1>";
205 forum_latest_topics($news->id, 5, "minimal", "DESC", false);
206 echo "</FONT>";
207 print_simple_box_end();
208 }
209 echo "<BR>";
210
211 // Print all the recent activity
212 print_simple_box("Recent Activity", $align="CENTER", $width="100%", $color="$THEME->cellheading");
213 print_simple_box_start("CENTER", "100%", "#FFFFFF", 3, 0);
214 print_recent_activity($course);
215 print_simple_box_end();
216
217 echo "</TD></TR></TABLE>\n";
218
219?>