f9903ed0 |
1 | <? // $Id$ |
97c270e9 |
2 | // Library of useful functions |
f9903ed0 |
3 | |
f9903ed0 |
4 | |
3d891989 |
5 | if (defined('COURSE_MAX_LOG_DISPLAY')) { // Being included again - should never happen!! |
9ae687af |
6 | return; |
7 | } |
8 | |
3d891989 |
9 | define('COURSE_MAX_LOG_DISPLAY', 150); // days |
d9d1c35d |
10 | |
3d891989 |
11 | define('COURSE_MAX_LOGS_PER_PAGE', 1000); // records |
1c0200e0 |
12 | |
3d891989 |
13 | define('COURSE_LIVELOG_REFRESH', 60); // Seconds |
87ffed0d |
14 | |
10a95b43 |
15 | define('COURSE_MAX_RECENT_PERIOD', 604800); // A week, in seconds |
ef58b822 |
16 | |
f9903ed0 |
17 | |
9ae687af |
18 | |
f9903ed0 |
19 | function print_log_selector_form($course, $selecteduser=0, $selecteddate="today") { |
20 | |
9481285b |
21 | global $USER, $CFG; |
22 | |
f9903ed0 |
23 | // Get all the possible users |
24 | $users = array(); |
720a43ce |
25 | |
26 | if ($course->category) { |
30d6173e |
27 | if ($courseusers = get_course_users($course->id, "u.lastaccess DESC")) { |
28 | foreach ($courseusers as $courseuser) { |
29 | $users[$courseuser->id] = "$courseuser->firstname $courseuser->lastname"; |
30 | } |
f9903ed0 |
31 | } |
9fa49e22 |
32 | if ($guest = get_guest()) { |
30d6173e |
33 | $users[$guest->id] = "$guest->firstname $guest->lastname"; |
122cffc9 |
34 | } |
f9903ed0 |
35 | } |
720a43ce |
36 | |
37 | if (isadmin()) { |
9fa49e22 |
38 | if ($ccc = get_records("course", "", "", "fullname")) { |
720a43ce |
39 | foreach ($ccc as $cc) { |
cfa5d3f2 |
40 | if ($cc->category) { |
41 | $courses["$cc->id"] = "$cc->fullname"; |
42 | } else { |
43 | $courses["$cc->id"] = " $cc->fullname (Site)"; |
44 | } |
720a43ce |
45 | } |
f9903ed0 |
46 | } |
cfa5d3f2 |
47 | asort($courses); |
f9903ed0 |
48 | } |
49 | |
dcde9f02 |
50 | |
51 | $strftimedate = get_string("strftimedate"); |
52 | $strftimedaydate = get_string("strftimedaydate"); |
53 | |
f9903ed0 |
54 | asort($users); |
55 | |
56 | // Get all the possible dates |
9481285b |
57 | // Note that we are keeping track of real (GMT) time and user time |
58 | // User time is only used in displays - all calcs and passing is GMT |
59 | |
60 | $timenow = time(); // GMT |
61 | |
62 | // What day is it now for the user, and when is midnight that day (in GMT). |
9604ccb1 |
63 | $timemidnight = $today = usergetmidnight($timenow); |
9481285b |
64 | |
65 | // Put today up the top of the list |
dcde9f02 |
66 | $dates = array("$timemidnight" => get_string("today").", ".userdate($timenow, $strftimedate) ); |
9481285b |
67 | |
68 | if (! $course->startdate) { |
69 | $course->startdate = $course->timecreated; |
70 | } |
f9903ed0 |
71 | |
9481285b |
72 | $numdates = 1; |
73 | while ($timemidnight > $course->startdate and $numdates < 365) { |
f9903ed0 |
74 | $timemidnight = $timemidnight - 86400; |
9481285b |
75 | $timenow = $timenow - 86400; |
dcde9f02 |
76 | $dates["$timemidnight"] = userdate($timenow, $strftimedaydate); |
9481285b |
77 | $numdates++; |
f9903ed0 |
78 | } |
79 | |
80 | if ($selecteddate == "today") { |
81 | $selecteddate = $today; |
82 | } |
83 | |
84 | echo "<CENTER>"; |
85 | echo "<FORM ACTION=log.php METHOD=get>"; |
720a43ce |
86 | if (isadmin()) { |
849bc02a |
87 | choose_from_menu ($courses, "id", $course->id, ""); |
720a43ce |
88 | } else { |
89 | echo "<INPUT TYPE=hidden NAME=id VALUE=\"$course->id\">"; |
90 | } |
91 | if ($course->category) { |
97c270e9 |
92 | choose_from_menu ($users, "user", $selecteduser, get_string("allparticipants") ); |
720a43ce |
93 | } |
97c270e9 |
94 | choose_from_menu ($dates, "date", $selecteddate, get_string("alldays")); |
95 | echo "<INPUT TYPE=submit VALUE=\"".get_string("showtheselogs")."\">"; |
f9903ed0 |
96 | echo "</FORM>"; |
97 | echo "</CENTER>"; |
98 | } |
99 | |
600149be |
100 | function make_log_url($module, $url) { |
101 | switch ($module) { |
102 | case "course": |
103 | case "user": |
104 | case "file": |
105 | case "login": |
106 | case "lib": |
107 | case "admin": |
108 | return "/$module/$url"; |
109 | break; |
110 | default: |
111 | return "/mod/$module/$url"; |
112 | break; |
113 | } |
114 | } |
115 | |
116 | |
f9903ed0 |
117 | function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") { |
9481285b |
118 | // It is assumed that $date is the GMT time of midnight for that day, |
119 | // and so the next 86400 seconds worth of logs are printed. |
f9903ed0 |
120 | |
3d891989 |
121 | global $CFG; |
47f1da80 |
122 | |
720a43ce |
123 | if ($course->category) { |
ebc3bd2b |
124 | $selector = "WHERE l.course='$course->id' AND l.userid = u.id"; |
a2ab3b05 |
125 | |
720a43ce |
126 | } else { |
ebc3bd2b |
127 | $selector = "WHERE l.userid = u.id"; // Show all courses |
9fa49e22 |
128 | if ($ccc = get_courses(-1)) { |
720a43ce |
129 | foreach ($ccc as $cc) { |
130 | $courses[$cc->id] = "$cc->shortname"; |
131 | } |
132 | } |
133 | } |
f9903ed0 |
134 | |
135 | if ($user) { |
ebc3bd2b |
136 | $selector .= " AND l.userid = '$user'"; |
f9903ed0 |
137 | } |
138 | |
139 | if ($date) { |
140 | $enddate = $date + 86400; |
141 | $selector .= " AND l.time > '$date' AND l.time < '$enddate'"; |
142 | } |
143 | |
f9d5fd3b |
144 | $order = $order." LIMIT ".COURSE_MAX_LOGS_PER_PAGE; // To keep it manageable |
145 | |
6aeec7f8 |
146 | if (!$logs = get_logs($selector, $order)) { |
f9903ed0 |
147 | notify("No logs found!"); |
148 | print_footer($course); |
149 | exit; |
150 | } |
151 | |
152 | $count=0; |
153 | $tt = getdate(time()); |
154 | $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]); |
f9d5fd3b |
155 | if (($totalcountlogs = count($logs)) == COURSE_MAX_LOGS_PER_PAGE) { |
156 | $totalcountlogs = "$totalcountlogs (+)"; |
1c0200e0 |
157 | } |
158 | |
dcde9f02 |
159 | $strftimedatetime = get_string("strftimedatetime"); |
160 | |
f9d5fd3b |
161 | echo "<p align=center>"; |
1c0200e0 |
162 | print_string("displayingrecords", "", $totalcountlogs); |
f9d5fd3b |
163 | echo "</p>"; |
1c0200e0 |
164 | |
f9d5fd3b |
165 | echo "<table border=0 align=center cellpadding=3 cellspacing=3>"; |
f9903ed0 |
166 | foreach ($logs as $log) { |
600149be |
167 | |
9fa49e22 |
168 | if ($ld = get_record("log_display", "module", "$log->module", "action", "$log->action")) { |
565f7a95 |
169 | $log->info = get_field($ld->mtable, $ld->field, "id", $log->info); |
600149be |
170 | } |
171 | |
f9d5fd3b |
172 | echo "<tr nowrap>"; |
720a43ce |
173 | if (! $course->category) { |
f9d5fd3b |
174 | echo "<td nowrap><font size=2><a href=\"view.php?id=$log->course\">".$courses[$log->course]."</a></td>"; |
720a43ce |
175 | } |
f9d5fd3b |
176 | echo "<td nowrap align=right><font size=2>".userdate($log->time, "%a")."</td>"; |
177 | echo "<td nowrap><font size=2>".userdate($log->time, $strftimedatetime)."</td>"; |
dc0dc7d5 |
178 | echo "<td nowrap><font size=2>"; |
47f1da80 |
179 | link_to_popup_window("/lib/ipatlas/plot.php?address=$log->ip&user=$log->userid", "ipatlas","$log->ip", 400, 700); |
f9d5fd3b |
180 | echo "</td>"; |
181 | echo "<td nowrap><font size=2><a href=\"../user/view.php?id=$log->userid&course=$log->course\"><b>$log->firstname $log->lastname</b></td>"; |
182 | echo "<td nowrap><font size=2>"; |
600149be |
183 | link_to_popup_window( make_log_url($log->module,$log->url), "fromloglive","$log->module $log->action", 400, 600); |
f9d5fd3b |
184 | echo "</td>"; |
185 | echo "<td nowrap><font size=2>$log->info</td>"; |
186 | echo "</tr>"; |
f9903ed0 |
187 | } |
f9d5fd3b |
188 | echo "</table>"; |
f9903ed0 |
189 | } |
190 | |
191 | |
776dc270 |
192 | function print_all_courses($category="all", $style="full", $maxcount=999, $width=180) { |
dc0dc7d5 |
193 | global $CFG, $THEME, $USER; |
d887b5a7 |
194 | |
ba2e5d73 |
195 | if ($category == "all") { |
9fa49e22 |
196 | $courses = get_courses(); |
0a263205 |
197 | |
198 | } else if ($category == "my") { |
199 | if (isset($USER->id)) { |
9fa49e22 |
200 | if ($courses = get_courses()) { |
0a263205 |
201 | foreach ($courses as $key => $course) { |
202 | if (!isteacher($course->id) and !isstudent($course->id)) { |
203 | unset($courses[$key]); |
204 | } |
205 | } |
206 | } |
207 | } |
208 | |
ba2e5d73 |
209 | } else { |
9fa49e22 |
210 | $courses = get_courses($category); |
ba2e5d73 |
211 | } |
212 | |
393cc508 |
213 | if ($style == "minimal") { |
214 | $count = 0; |
dc0dc7d5 |
215 | if (empty($THEME->custompix)) { |
216 | $icon = "<img src=\"$CFG->wwwroot/pix/i/course.gif\" height=16 width=16 alt=\"".get_string("course")."\">"; |
217 | } else { |
218 | $icon = "<img src=\"$CFG->wwwroot/theme/$CFG->theme/pix/i/course.gif\" height=16 width=16 alt=\"".get_string("course")."\">"; |
219 | } |
393cc508 |
220 | if ($courses) { |
94361e02 |
221 | foreach ($courses as $course) { |
dc0dc7d5 |
222 | $moddata[]="<a title=\"$course->shortname\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>"; |
94361e02 |
223 | $modicon[]=$icon; |
224 | if ($count++ >= $maxcount) { |
225 | break; |
226 | } |
227 | } |
dc0dc7d5 |
228 | $fulllist = "<p><a href=\"$CFG->wwwroot/course/\">".get_string("fulllistofcourses")."</a>..."; |
94361e02 |
229 | } else { |
393cc508 |
230 | $moddata = array(); |
231 | $modicon = array(); |
232 | $fulllist = get_string("nocoursesyet"); |
233 | } |
234 | print_side_block(get_string("courses"), "", $moddata, $modicon, $fulllist, $width); |
235 | |
236 | } else if ($courses) { |
237 | foreach ($courses as $course) { |
238 | print_course($course); |
dc0dc7d5 |
239 | echo "<br />\n"; |
d887b5a7 |
240 | } |
241 | |
242 | } else { |
dc0dc7d5 |
243 | echo "<p>".get_string("nocoursesyet")."</p>"; |
d887b5a7 |
244 | } |
245 | } |
246 | |
247 | |
f9903ed0 |
248 | function print_course($course) { |
249 | |
dc0dc7d5 |
250 | global $CFG, $THEME; |
d887b5a7 |
251 | |
a83fded1 |
252 | if (! $site = get_site()) { |
f9903ed0 |
253 | error("Could not find a site!"); |
254 | } |
255 | |
dc0dc7d5 |
256 | if (empty($THEME->custompix)) { |
257 | $pixpath = "$CFG->wwwroot/pix"; |
258 | } else { |
259 | $pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix"; |
260 | } |
261 | |
d887b5a7 |
262 | print_simple_box_start("CENTER", "100%"); |
f9903ed0 |
263 | |
264 | echo "<TABLE WIDTH=100%>"; |
da5c172a |
265 | echo "<TR VALIGN=top>"; |
266 | echo "<TD VALIGN=top WIDTH=50%>"; |
7a302afc |
267 | echo "<P><FONT SIZE=3><B><A TITLE=\"".get_string("entercourse")."\" |
9481285b |
268 | HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</A></B></FONT></P>"; |
0c71c9ae |
269 | if ($teachers = get_course_teachers($course->id)) { |
f9903ed0 |
270 | echo "<P><FONT SIZE=1>\n"; |
271 | foreach ($teachers as $teacher) { |
0c71c9ae |
272 | if ($teacher->authority > 0) { |
b4d7002e |
273 | if (!$teacher->role) { |
274 | $teacher->role = $course->teacher; |
275 | } |
276 | echo "$teacher->role: <A HREF=\"$CFG->wwwroot/user/view.php?id=$teacher->id&course=$site->id\">$teacher->firstname $teacher->lastname</A><BR>"; |
0c71c9ae |
277 | } |
f9903ed0 |
278 | } |
279 | echo "</FONT></P>"; |
da5c172a |
280 | } |
f25f1e1b |
281 | if ($course->guest) { |
5e367a2d |
282 | $strallowguests = get_string("allowguests"); |
283 | echo "<A TITLE=\"$strallowguests\" HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">"; |
dc0dc7d5 |
284 | echo "<IMG VSPACE=4 ALT=\"$strallowguests\" HEIGHT=16 WIDTH=16 BORDER=0 SRC=\"$pixpath/i/user.gif\"></A> "; |
da5c172a |
285 | } |
286 | if ($course->password) { |
5e367a2d |
287 | $strrequireskey = get_string("requireskey"); |
288 | echo "<A TITLE=\"$strrequireskey\" HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">"; |
dc0dc7d5 |
289 | echo "<IMG VSPACE=4 ALT=\"$strrequireskey\" HEIGHT=16 WIDTH=16 BORDER=0 SRC=\"$pixpath/i/key.gif\"></A>"; |
da5c172a |
290 | } |
291 | |
292 | |
293 | echo "</TD><TD VALIGN=top WIDTH=50%>"; |
294 | echo "<P><FONT SIZE=2>".text_to_html($course->summary)."</FONT></P>"; |
295 | echo "</TD></TR>"; |
296 | echo "</TABLE>"; |
f9903ed0 |
297 | |
da5c172a |
298 | print_simple_box_end(); |
f9903ed0 |
299 | } |
300 | |
600149be |
301 | function print_headline($text, $size=2) { |
302 | echo "<B><FONT SIZE=\"$size\">$text</FONT></B><BR>\n"; |
303 | } |
304 | |
305 | function print_recent_activity($course) { |
306 | // $course is an object |
307 | // This function trawls through the logs looking for |
308 | // anything new since the user's last login |
309 | |
3d891989 |
310 | global $CFG, $USER; |
600149be |
311 | |
312 | if (! $USER->lastlogin ) { |
3d891989 |
313 | echo "<p align=center><font size=1>"; |
4b1371a7 |
314 | print_string("welcometocourse", "", $course->shortname); |
3d891989 |
315 | echo "</font></p>"; |
600149be |
316 | return; |
4c654ee3 |
317 | } else { |
3d891989 |
318 | echo "<p align=center><font size=1>"; |
4c654ee3 |
319 | echo get_string("yourlastlogin").":<BR>"; |
dcde9f02 |
320 | echo userdate($USER->lastlogin, get_string("strftimerecentfull")); |
3d891989 |
321 | echo "</font></p>"; |
322 | } |
323 | |
324 | $timestart = $USER->lastlogin; |
b1992e65 |
325 | $timemaxrecent = time() - COURSE_MAX_RECENT_PERIOD; |
326 | if ($timestart < $timemaxrecent) { |
327 | $timestart = $timemaxrecent; |
600149be |
328 | } |
329 | |
600149be |
330 | |
331 | // Firstly, have there been any new enrolments? |
332 | |
333 | $heading = false; |
334 | $content = false; |
1b5910c4 |
335 | |
336 | $logs = get_records_select("log", "time > '$timestart' AND course = '$course->id' AND |
337 | module = 'course' AND action = 'enrol'", "time ASC"); |
338 | |
339 | if ($logs) { |
340 | foreach ($logs as $key => $log) { |
600149be |
341 | if (! $heading) { |
4c654ee3 |
342 | print_headline(get_string("newusers").":"); |
600149be |
343 | $heading = true; |
344 | $content = true; |
345 | } |
346 | $user = get_record("user", "id", $log->info); |
d578afc8 |
347 | if (isstudent($course->id, $user->id)) { |
3d891989 |
348 | echo "<p><font size=1><a href=\"../user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</a></font></p>"; |
d578afc8 |
349 | } |
600149be |
350 | } |
351 | } |
352 | |
1b5910c4 |
353 | // Next, have there been any modifications to the course structure? |
354 | |
355 | $logs = get_records_select("log", "time > '$timestart' AND course = '$course->id' AND |
356 | module = 'course' AND action LIKE '% mod'", "time ASC"); |
357 | |
358 | if ($logs) { |
359 | foreach ($logs as $key => $log) { |
360 | $info = split(" ", $log->info); |
361 | $modname = get_field($info[0], "name", "id", $info[1]); |
362 | //Create a temp valid module structure (course,id) |
363 | $tempmod->course = $log->course; |
364 | $tempmod->id = $info[1]; |
365 | //Obtain the visible property from the instance |
366 | $modvisible = instance_is_visible($info[0],$tempmod); |
367 | |
368 | //Only if the mod is visible |
369 | if ($modvisible) { |
370 | switch ($log->action) { |
371 | case "add mod": |
372 | $stradded = get_string("added", "moodle", get_string("modulename", $info[0])); |
373 | $changelist["$log->info"] = array ("operation" => "add", "text" => "$stradded:<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>"); |
374 | break; |
375 | case "update mod": |
376 | $strupdated = get_string("updated", "moodle", get_string("modulename", $info[0])); |
377 | if (empty($changelist["$log->info"])) { |
378 | $changelist["$log->info"] = array ("operation" => "update", "text" => "$strupdated:<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>"); |
379 | } |
380 | break; |
381 | case "delete mod": |
382 | if (!empty($changelist["$log->info"]["operation"]) and |
383 | $changelist["$log->info"]["operation"] == "add") { |
384 | $changelist["$log->info"] = NULL; |
385 | } else { |
386 | $strdeleted = get_string("deletedactivity", "moodle", get_string("modulename", $info[0])); |
387 | $changelist["$log->info"] = array ("operation" => "delete", "text" => $strdeleted); |
388 | } |
389 | break; |
600149be |
390 | } |
ef25340c |
391 | } |
392 | } |
393 | } |
394 | |
9c9f7d77 |
395 | if (!empty($changelist)) { |
ef25340c |
396 | foreach ($changelist as $changeinfo => $change) { |
397 | if ($change) { |
398 | $changes[$changeinfo] = $change; |
399 | } |
400 | } |
401 | if (count($changes) > 0) { |
4c654ee3 |
402 | print_headline(get_string("courseupdates").":"); |
ef25340c |
403 | $content = true; |
404 | foreach ($changes as $changeinfo => $change) { |
3d891989 |
405 | echo "<p><font size=1>".$change["text"]."</font></p>"; |
600149be |
406 | } |
407 | } |
408 | } |
409 | |
3869a2ac |
410 | // Now display new things from each module |
600149be |
411 | |
3869a2ac |
412 | $mods = get_list_of_plugins("mod"); |
600149be |
413 | |
1b5910c4 |
414 | $isteacher = isteacher($course->id); |
415 | |
416 | foreach ($mods as $mod) { // Each module gets it's own logs and prints them |
3869a2ac |
417 | include_once("$CFG->dirroot/mod/$mod/lib.php"); |
418 | $print_recent_activity = $mod."_print_recent_activity"; |
1b5910c4 |
419 | if (function_exists($print_recent_activity)) { |
420 | $modcontent = $print_recent_activity($course, $isteacher, $timestart); |
3869a2ac |
421 | if ($modcontent) { |
422 | $content = true; |
600149be |
423 | } |
600149be |
424 | } |
425 | } |
426 | |
427 | if (! $content) { |
3d891989 |
428 | echo "<font size=2>".get_string("nothingnew")."</font>"; |
600149be |
429 | } |
600149be |
430 | } |
431 | |
e1360728 |
432 | |
d897cae4 |
433 | function get_array_of_activities($courseid) { |
434 | // For a given course, returns an array of course activity objects |
435 | // Each item in the array contains he following properties: |
436 | // cm - course module id |
437 | // mod - name of the module (eg forum) |
438 | // section - the number of the section (eg week or topic) |
439 | // name - the name of the instance |
5867bfb5 |
440 | // visible - is the instance visible or not |
d897cae4 |
441 | |
442 | $mod = array(); |
443 | |
9fa49e22 |
444 | if (!$rawmods = get_course_mods($courseid)) { |
d897cae4 |
445 | return NULL; |
446 | } |
447 | |
448 | if ($sections = get_records("course_sections", "course", $courseid, "section ASC")) { |
449 | foreach ($sections as $section) { |
74666583 |
450 | if (!empty($section->sequence)) { |
d897cae4 |
451 | $sequence = explode(",", $section->sequence); |
452 | foreach ($sequence as $seq) { |
7af6281f |
453 | if (empty($rawmods[$seq])) { |
454 | continue; |
455 | } |
d897cae4 |
456 | $mod[$seq]->cm = $rawmods[$seq]->id; |
457 | $mod[$seq]->mod = $rawmods[$seq]->modname; |
458 | $mod[$seq]->section = $section->section; |
459 | $mod[$seq]->name = urlencode(get_field($rawmods[$seq]->modname, "name", "id", $rawmods[$seq]->instance)); |
fec5a6a6 |
460 | $mod[$seq]->visible = $rawmods[$seq]->visible; |
d897cae4 |
461 | } |
462 | } |
463 | } |
464 | } |
465 | return $mod; |
466 | } |
467 | |
468 | |
469 | |
e1360728 |
470 | |
90845098 |
471 | function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) { |
472 | // Returns a number of useful structures for course displays |
7468bf01 |
473 | |
90845098 |
474 | $mods = NULL; // course modules indexed by id |
475 | $modnames = NULL; // all course module names |
94361e02 |
476 | $modnamesplural= NULL; // all course module names (plural form) |
90845098 |
477 | $modnamesused = NULL; // course module names used |
7468bf01 |
478 | |
9fa49e22 |
479 | if ($allmods = get_records("modules")) { |
90845098 |
480 | foreach ($allmods as $mod) { |
5867bfb5 |
481 | if ($mod->visible) { |
482 | $modnames[$mod->name] = get_string("modulename", "$mod->name"); |
483 | $modnamesplural[$mod->name] = get_string("modulenameplural", "$mod->name"); |
484 | } |
90845098 |
485 | } |
486 | asort($modnames); |
487 | } else { |
488 | error("No modules are installed!"); |
489 | } |
490 | |
9fa49e22 |
491 | if ($rawmods = get_course_mods($courseid)) { |
7468bf01 |
492 | foreach($rawmods as $mod) { // Index the mods |
493 | $mods[$mod->id] = $mod; |
90845098 |
494 | $mods[$mod->id]->modfullname = $modnames[$mod->modname]; |
1acfbce5 |
495 | if ($mod->visible or isteacher($courseid)) { |
496 | $modnamesused[$mod->modname] = $modnames[$mod->modname]; |
497 | } |
7468bf01 |
498 | } |
c7da6f7a |
499 | if ($modnamesused) { |
500 | asort($modnamesused); |
501 | } |
7468bf01 |
502 | } |
7468bf01 |
503 | } |
504 | |
9fa49e22 |
505 | |
7468bf01 |
506 | function get_all_sections($courseid) { |
507 | |
d26d7ed0 |
508 | return get_records("course_sections", "course", "$courseid", "section", |
7d99d695 |
509 | "section, id, course, summary, sequence, visible"); |
7468bf01 |
510 | } |
511 | |
b86fc0e2 |
512 | function course_set_display($courseid, $display=0) { |
513 | global $USER; |
514 | |
515 | if (empty($USER)) { |
516 | return false; |
517 | } |
518 | |
519 | if ($display == "all" or empty($display)) { |
520 | $display = 0; |
521 | } |
522 | |
523 | if (record_exists("course_display", "userid", $USER->id, "course", $courseid)) { |
524 | set_field("course_display", "display", $display, "userid", $USER->id, "course", $courseid); |
525 | } else { |
526 | $record->userid = $USER->id; |
527 | $record->course = $courseid; |
528 | $record->display = $display; |
529 | if (!insert_record("course_display", $record)) { |
530 | notify("Could not save your course display!"); |
531 | } |
532 | } |
533 | |
534 | return $USER->display[$courseid] = $display; // Note: = not == |
535 | } |
536 | |
7d99d695 |
537 | function set_section_visible($courseid, $sectionnumber, $visibility) { |
538 | /// For a given course section, markes it visible or hidden, |
539 | /// and does the same for every activity in that section |
540 | |
541 | if ($section = get_record("course_sections", "course", $courseid, "section", $sectionnumber)) { |
542 | set_field("course_sections", "visible", "$visibility", "id", $section->id); |
543 | if (!empty($section->sequence)) { |
544 | $modules = explode(",", $section->sequence); |
545 | foreach ($modules as $moduleid) { |
546 | set_field("course_modules", "visible", "$visibility", "id", $moduleid); |
547 | } |
548 | } |
5867bfb5 |
549 | rebuild_course_cache($courseid); |
7d99d695 |
550 | } |
551 | } |
ba2e5d73 |
552 | |
5e367a2d |
553 | function print_section_block($heading, $course, $section, $mods, $modnames, $modnamesused, |
52dcc2f9 |
554 | $absolute=true, $width="100%") { |
5e367a2d |
555 | |
556 | global $CFG; |
52dcc2f9 |
557 | static $isteacher; |
558 | static $isediting; |
559 | |
560 | if (!isset($isteacher)) { |
561 | $isteacher = isteacher($course->id); |
562 | } |
563 | if (!isset($isediting)) { |
564 | $isediting = isediting($course->id); |
565 | } |
5e367a2d |
566 | |
567 | $modinfo = unserialize($course->modinfo); |
568 | $moddata = array(); |
569 | $modicon = array(); |
570 | $editbuttons = ""; |
571 | |
74666583 |
572 | if (!empty($section->sequence)) { |
5e367a2d |
573 | |
574 | $sectionmods = explode(",", $section->sequence); |
575 | |
576 | foreach ($sectionmods as $modnumber) { |
52dcc2f9 |
577 | if (empty($mods[$modnumber])) { |
578 | continue; |
579 | } |
5e367a2d |
580 | $mod = $mods[$modnumber]; |
581 | if ($isediting) { |
1acfbce5 |
582 | $editbuttons = make_editing_buttons($mod->id, $absolute, $mod->visible); |
583 | } |
52dcc2f9 |
584 | if ($mod->visible or $isteacher) { |
1acfbce5 |
585 | $instancename = urldecode($modinfo[$modnumber]->name); |
586 | if ($mod->visible) { |
587 | $link_css = ""; |
588 | } else { |
589 | $link_css = " class=\"dimmed\" "; |
590 | } |
52dcc2f9 |
591 | $modicon[] = "<img src=\"$CFG->wwwroot/mod/$mod->modname/icon.gif\"". |
592 | " height=\"16\" width=\"16\" alt=\"$mod->modfullname\">"; |
593 | $moddata[] = "<a title=\"$mod->modfullname\" $link_css ". |
594 | "href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename</a>". |
595 | "<br />$editbuttons"; |
5e367a2d |
596 | } |
5e367a2d |
597 | } |
598 | } |
a44d18e7 |
599 | if ($isediting) { |
15ac9065 |
600 | $editmenu = popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section->section&add=", |
5e367a2d |
601 | $modnames, "section0", "", get_string("add")."...", "mods", get_string("activities"), true); |
dfec7b01 |
602 | $editmenu = "<div align=right>$editmenu</div>"; |
47f1da80 |
603 | } else { |
604 | $editmenu = ""; |
5e367a2d |
605 | } |
606 | |
607 | print_side_block($heading, "", $moddata, $modicon, $editmenu, $width); |
608 | } |
609 | |
610 | |
d897cae4 |
611 | function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%") { |
52dcc2f9 |
612 | /// Prints a section full of activity modules |
94361e02 |
613 | global $CFG; |
52dcc2f9 |
614 | static $isteacher; |
615 | static $isediting; |
616 | |
617 | if (!isset($isteacher)) { |
618 | $isteacher = isteacher($course->id); |
619 | } |
620 | if (!isset($isediting)) { |
621 | $isediting = isediting($course->id); |
622 | } |
94361e02 |
623 | |
c408b0c4 |
624 | $modinfo = unserialize($course->modinfo); |
94361e02 |
625 | |
dfec7b01 |
626 | echo "<table width=\"$width\"><tr><td>\n"; |
74666583 |
627 | if (!empty($section->sequence)) { |
94361e02 |
628 | |
629 | $sectionmods = explode(",", $section->sequence); |
630 | |
631 | foreach ($sectionmods as $modnumber) { |
9ae687af |
632 | if (empty($mods[$modnumber])) { |
633 | continue; |
634 | } |
94361e02 |
635 | $mod = $mods[$modnumber]; |
52dcc2f9 |
636 | if ($mod->visible or $isteacher) { |
1acfbce5 |
637 | $instancename = urldecode($modinfo[$modnumber]->name); |
638 | if ($mod->visible) { |
639 | $link_css = ""; |
640 | } else { |
641 | $link_css = " class=\"dimmed\" "; |
642 | } |
52dcc2f9 |
643 | echo "<img src=\"$CFG->wwwroot/mod/$mod->modname/icon.gif\"". |
644 | " height=16 width=16 alt=\"$mod->modfullname\">". |
645 | " <font size=2><a title=\"$mod->modfullname\" $link_css ". |
646 | " href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename</a></font>"; |
1acfbce5 |
647 | } |
d897cae4 |
648 | if (isediting($course->id)) { |
5e367a2d |
649 | echo " "; |
1acfbce5 |
650 | echo make_editing_buttons($mod->id, $absolute, $mod->visible); |
651 | } |
52dcc2f9 |
652 | if ($mod->visible or $isteacher) { |
dfec7b01 |
653 | echo "<br />\n"; |
94361e02 |
654 | } |
94361e02 |
655 | } |
656 | } |
dfec7b01 |
657 | echo "</td></tr></table><br />\n\n"; |
a7ad3ea6 |
658 | } |
659 | |
5867bfb5 |
660 | |
661 | function rebuild_course_cache($courseid=0) { |
662 | // Rebuilds the cached list of course activities stored in the database |
663 | // If a courseid is not specified, then all are rebuilt |
664 | |
665 | if ($courseid) { |
666 | $select = "id = '$courseid'"; |
667 | } else { |
668 | $select = ""; |
669 | } |
670 | |
671 | if ($courses = get_records_select("course", $select)) { |
672 | foreach ($courses as $course) { |
673 | $modinfo = serialize(get_array_of_activities($course->id)); |
674 | if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) { |
675 | notify("Could not cache module information for course '$course->fullname'!"); |
676 | } |
677 | } |
678 | } |
679 | } |
680 | |
681 | |
7541bc3e |
682 | function print_heading_block($heading, $width="100%", $class="headingblock") { |
5e367a2d |
683 | global $THEME; |
684 | |
7541bc3e |
685 | echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">"; |
686 | echo "<tr><td bgcolor=\"$THEME->cellheading\" class=\"$class\">"; |
5e367a2d |
687 | echo stripslashes($heading); |
688 | echo "</td></tr></table>"; |
5e367a2d |
689 | } |
690 | |
691 | function print_side_block($heading="", $content="", $list=NULL, $icons=NULL, $footer="", $width=180) { |
692 | // Prints a nice side block with an optional header. The content can either |
693 | // be a block of HTML or a list of text with optional icons. |
a7ad3ea6 |
694 | |
5e367a2d |
695 | global $THEME; |
696 | |
7541bc3e |
697 | print_side_block_start($heading, $width); |
698 | |
5e367a2d |
699 | if ($content) { |
7541bc3e |
700 | echo "$content"; |
5e367a2d |
701 | } else { |
5e367a2d |
702 | echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">"; |
703 | foreach ($list as $key => $string) { |
7541bc3e |
704 | echo "<tr bgcolor=\"$THEME->cellcontent2\">"; |
5e367a2d |
705 | if ($icons) { |
7541bc3e |
706 | echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"16\">".$icons[$key]."</td>"; |
a7ad3ea6 |
707 | } |
7541bc3e |
708 | echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"*\"><font size=\"-1\">$string</font></td>"; |
5e367a2d |
709 | echo "</tr>"; |
a7ad3ea6 |
710 | } |
5e367a2d |
711 | if ($footer) { |
7541bc3e |
712 | echo "<tr bgcolor=\"$THEME->cellcontent2\">"; |
5e367a2d |
713 | if ($icons) { |
7541bc3e |
714 | echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"16\"> </td>"; |
5e367a2d |
715 | } |
7541bc3e |
716 | echo "<td class=\"sideblocklinks\"><font size=\"-1\">$footer</td>"; |
5e367a2d |
717 | echo "</tr>"; |
718 | } |
719 | echo "</table>"; |
a7ad3ea6 |
720 | } |
5e367a2d |
721 | |
7541bc3e |
722 | print_side_block_end(); |
723 | } |
724 | |
725 | function print_side_block_start($heading="", $width=180, $class="sideblockmain") { |
726 | // Starts a nice side block with an optional header. |
727 | |
728 | global $THEME; |
729 | |
730 | echo "<table class=\"sideblock\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">"; |
731 | if ($heading) { |
732 | echo "<tr>"; |
733 | echo "<td class=\"sideblockheading\" bgcolor=\"$THEME->cellheading\">$heading</td>"; |
734 | echo "</tr>"; |
735 | } |
736 | echo "<tr>"; |
737 | echo "<td class=\"$class\" bgcolor=\"$THEME->cellcontent2\">"; |
738 | } |
739 | |
740 | function print_side_block_end() { |
741 | echo "</td></tr>"; |
7d99d695 |
742 | echo "</table><br />"; |
94361e02 |
743 | } |
744 | |
5e367a2d |
745 | |
670fddf1 |
746 | function print_admin_links ($siteid, $width=180) { |
dc0dc7d5 |
747 | global $CFG, $THEME; |
2b25f2a0 |
748 | |
dc0dc7d5 |
749 | if (empty($THEME->custompix)) { |
750 | $icon = "<img src=\"$CFG->wwwroot/pix/i/settings.gif\" height=16 width=16 alt=\"\">"; |
751 | } else { |
752 | $icon = "<img src=\"$CFG->wwwroot/theme/$CFG->theme/pix/i/settings.gif\" height=16 width=16 alt=\"\">"; |
753 | } |
754 | |
1924074c |
755 | if (isadmin()) { |
5867bfb5 |
756 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/config.php\">".get_string("configvariables")."</a>"; |
757 | $modicon[]=$icon; |
758 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/site.php\">".get_string("sitesettings")."</a>"; |
1924074c |
759 | $modicon[]=$icon; |
5867bfb5 |
760 | $moddata[]="<a href=\"$CFG->wwwroot/course/log.php?id=$siteid\">".get_string("sitelogs")."</a>"; |
1924074c |
761 | $modicon[]=$icon; |
5867bfb5 |
762 | $moddata[]="<a href=\"$CFG->wwwroot/theme/index.php\">".get_string("choosetheme")."</a>"; |
1924074c |
763 | $modicon[]=$icon; |
5867bfb5 |
764 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/lang.php\">".get_string("checklanguage")."</a>"; |
1924074c |
765 | $modicon[]=$icon; |
5867bfb5 |
766 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/modules.php\">".get_string("managemodules")."</a>"; |
1924074c |
767 | $modicon[]=$icon; |
be09831a |
768 | if (file_exists("$CFG->dirroot/$CFG->admin/$CFG->dbtype")) { |
5867bfb5 |
769 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/$CFG->dbtype/frame.php\">".get_string("managedatabase")."</a>"; |
1924074c |
770 | $modicon[]=$icon; |
771 | } |
5867bfb5 |
772 | $moddata[]="<hr>"; |
1924074c |
773 | $modicon[]=""; |
774 | } |
775 | if (iscreator()) { |
5867bfb5 |
776 | $moddata[]="<a href=\"$CFG->wwwroot/course/edit.php\">".get_string("addnewcourse")."</a>"; |
1924074c |
777 | $modicon[]=$icon; |
e808d25f |
778 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/teacher.php\">".get_string("assignteachers")."</a>"; |
1924074c |
779 | $modicon[]=$icon; |
5b337cdf |
780 | $fulladmin = ""; |
1924074c |
781 | } |
782 | if (isadmin()) { |
5867bfb5 |
783 | $moddata[]="<a href=\"$CFG->wwwroot/course/categories.php\">".get_string("categories")."</a>"; |
1924074c |
784 | $modicon[]=$icon; |
5867bfb5 |
785 | $moddata[]="<a href=\"$CFG->wwwroot/course/delete.php\">".get_string("deletecourse")."</a>"; |
1924074c |
786 | $modicon[]=$icon; |
5867bfb5 |
787 | $moddata[]="<hr>"; |
1924074c |
788 | $modicon[]=""; |
3399a22c |
789 | if($CFG->auth == "email" || $CFG->auth == "none" || $CFG->auth == "manual"){ |
5867bfb5 |
790 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/user.php?newuser=true\">".get_string("addnewuser")."</a>"; |
3399a22c |
791 | $modicon[]=$icon; |
792 | } |
5867bfb5 |
793 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/user.php\">".get_string("edituser")."</a>"; |
1924074c |
794 | $modicon[]=$icon; |
5867bfb5 |
795 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/admin.php\">".get_string("assignadmins")."</a>"; |
1924074c |
796 | $modicon[]=$icon; |
5867bfb5 |
797 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/creators.php\">".get_string("assigncreators")."</a>"; |
1924074c |
798 | $modicon[]=$icon; |
5867bfb5 |
799 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/auth.php\">".get_string("authentication")."</a>"; |
1924074c |
800 | $modicon[]=$icon; |
5867bfb5 |
801 | $fulladmin = "<p><a href=\"$CFG->wwwroot/$CFG->admin/\">".get_string("admin")."</a>..."; |
1924074c |
802 | } |
5e367a2d |
803 | |
804 | print_side_block(get_string("administration"), "", $moddata, $modicon, $fulladmin, $width); |
805 | |
dc0dc7d5 |
806 | echo "<img src=\"$CFG->wwwroot/pix/spacer.gif\" width=\"$width\" height=1><br>"; |
2b25f2a0 |
807 | } |
808 | |
b4d7002e |
809 | function print_course_admin_links($course, $width=180) { |
dc0dc7d5 |
810 | global $USER, $CFG, $THEME; |
44dad735 |
811 | |
fce1ce13 |
812 | if (isguest()) { |
813 | return true; |
814 | } |
dc0dc7d5 |
815 | if (empty($THEME->custompix)) { |
816 | $pixpath = "$CFG->wwwroot/pix"; |
817 | $modpixpath = "$CFG->wwwroot/mod"; |
818 | } else { |
819 | $pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix"; |
820 | $modpixpath = "$CFG->wwwroot/theme/$CFG->theme/pix/mod"; |
821 | } |
13469b82 |
822 | if (isteacher($course->id)) { |
dc0dc7d5 |
823 | $adminicon[]="<img src=\"$pixpath/i/edit.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
824 | if (isediting($course->id)) { |
dc0dc7d5 |
825 | $admindata[]="<a href=\"view.php?id=$course->id&edit=off\">".get_string("turneditingoff")."</a>"; |
13469b82 |
826 | } else { |
dc0dc7d5 |
827 | $admindata[]="<a href=\"view.php?id=$course->id&edit=on\">".get_string("turneditingon")."</a>"; |
13469b82 |
828 | } |
dc0dc7d5 |
829 | $admindata[]="<a href=\"edit.php?id=$course->id\">".get_string("settings")."...</a>"; |
830 | $adminicon[]="<img src=\"$pixpath/i/settings.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
831 | if (!$course->teachers) { |
832 | $course->teachers = get_string("defaultcourseteachers"); |
833 | } |
dc0dc7d5 |
834 | $admindata[]="<a href=\"teachers.php?id=$course->id\">$course->teachers...</a>"; |
835 | $adminicon[]="<img src=\"$pixpath/i/settings.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
836 | |
dc0dc7d5 |
837 | $admindata[]="<a href=\"grades.php?id=$course->id\">".get_string("grades")."...</a>"; |
838 | $adminicon[]="<img src=\"$pixpath/i/grades.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
839 | |
dc0dc7d5 |
840 | $admindata[]="<a href=\"log.php?id=$course->id\">".get_string("logs")."...</a>"; |
841 | $adminicon[]="<img src=\"$pixpath/i/log.gif\" height=16 width=16 alt=\"\">"; |
842 | |
843 | $admindata[]="<a href=\"$CFG->wwwroot/files/index.php?id=$course->id\">".get_string("files")."...</a>"; |
844 | $adminicon[]="<img src=\"$pixpath/i/files.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
845 | |
dc0dc7d5 |
846 | $admindata[]="<a href=\"$CFG->wwwroot/doc/view.php?id=$course->id&file=teacher.html\">".get_string("help")."...</a>"; |
847 | $adminicon[]="<img src=\"$modpixpath/resource/icon.gif\" height=16 width=16 alt=\"\">"; |
b4d7002e |
848 | |
13469b82 |
849 | if ($teacherforum = forum_get_course_forum($course->id, "teacher")) { |
dc0dc7d5 |
850 | $admindata[]="<a href=\"$CFG->wwwroot/mod/forum/view.php?f=$teacherforum->id\">".get_string("nameteacher", "forum")."</a>"; |
851 | $adminicon[]="<img src=\"$modpixpath/forum/icon.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
852 | } |
853 | } else { |
dc0dc7d5 |
854 | $admindata[]="<a href=\"grade.php?id=$course->id\">".get_string("grades")."...</a>"; |
855 | $adminicon[]="<img src=\"$pixpath/i/grades.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
856 | } |
44dad735 |
857 | |
5e367a2d |
858 | print_side_block(get_string("administration"), "", $admindata, $adminicon, "", $width); |
44dad735 |
859 | } |
2b25f2a0 |
860 | |
ba2e5d73 |
861 | function print_course_categories($categories, $selected="none", $width=180) { |
0a263205 |
862 | global $CFG, $THEME, $USER; |
85098089 |
863 | |
864 | $strallowguests = get_string("allowguests"); |
865 | $strrequireskey = get_string("requireskey"); |
ba2e5d73 |
866 | |
dc0dc7d5 |
867 | if (empty($THEME->custompix)) { |
868 | $pixpath = "$CFG->wwwroot/pix"; |
869 | } else { |
870 | $pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix"; |
871 | } |
872 | |
0c656181 |
873 | if ($selected == "index") { // Print comprehensive index of categories with courses |
9fa49e22 |
874 | if ($courses = get_courses()) { |
0c656181 |
875 | if (isset($USER->id) and !isadmin()) { |
39246b72 |
876 | print_simple_box_start("CENTER", "100%", $THEME->cellheading); |
dc0dc7d5 |
877 | print_heading("<a href=\"course/index.php?category=my\">".get_string("mycourses")."</a>", "left"); |
0c656181 |
878 | $some = false; |
dc0dc7d5 |
879 | echo "<ul>"; |
0c656181 |
880 | foreach ($courses as $key => $course) { |
881 | if (isteacher($course->id) or isstudent($course->id)) { |
dc0dc7d5 |
882 | echo "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>"; |
883 | echo "<br />"; |
0c656181 |
884 | $some = true; |
885 | } |
886 | } |
887 | if (!$some) { |
888 | print_string("nocoursesyet"); |
889 | } |
dc0dc7d5 |
890 | echo "</ul>"; |
0c656181 |
891 | print_simple_box_end(); |
892 | print_spacer(8,1); |
893 | } |
894 | foreach ($categories as $category) { |
bd4707bf |
895 | print_simple_box_start("CENTER", "100%"); |
dc0dc7d5 |
896 | print_heading("<a href=\"course/index.php?category=$category->id\">$category->name</a>", "left"); |
0c656181 |
897 | $some = false; |
dc0dc7d5 |
898 | echo "<ul>"; |
0c656181 |
899 | foreach ($courses as $key => $course) { |
900 | if ($course->category == $category->id) { |
dc0dc7d5 |
901 | echo "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>"; |
85098089 |
902 | echo " "; |
0c656181 |
903 | unset($courses[$key]); |
85098089 |
904 | if ($course->guest ) { |
dc0dc7d5 |
905 | echo "<a title=\"$strallowguests\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">"; |
906 | echo "<img alt=\"\" height=16 width=16 border=0 src=\"$pixpath/i/user.gif\"></a>"; |
85098089 |
907 | } |
908 | if ($course->password) { |
dc0dc7d5 |
909 | echo "<a title=\"$strrequireskey\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">"; |
910 | echo "<img alt=\"\" height=16 width=16 border=0 src=\"$pixpath/i/key.gif\"></a>"; |
85098089 |
911 | } |
dc0dc7d5 |
912 | echo "<br />"; |
0c656181 |
913 | $some = true; |
914 | } |
915 | } |
916 | if (!$some) { |
917 | print_string("nocoursesyet"); |
918 | } |
dc0dc7d5 |
919 | echo "</ul>"; |
0c656181 |
920 | print_simple_box_end(); |
921 | print_spacer(8,1); |
922 | } |
ba2e5d73 |
923 | } |
0c656181 |
924 | |
925 | } else { // Print short list of categories only |
926 | foreach ($categories as $cat) { |
dc0dc7d5 |
927 | $caticon[]="<img src=\"$pixpath/i/course.gif\" height=16 width=16>"; |
0c656181 |
928 | if ($cat->id == $selected) { |
929 | $catdata[]="$cat->name"; |
930 | } else { |
dc0dc7d5 |
931 | $catdata[]="<a href=\"$CFG->wwwroot/course/index.php?category=$cat->id\">$cat->name</a>"; |
0c656181 |
932 | } |
933 | } |
dc0dc7d5 |
934 | $catdata[] = "<a href=\"$CFG->wwwroot/course/index.php?category=all\">".get_string("fulllistofcourses")."</a>"; |
13770d0c |
935 | $caticon[] = ""; |
0c656181 |
936 | if (isset($USER->id)) { |
dc0dc7d5 |
937 | $catdata[] = "<a href=\"$CFG->wwwroot/course/index.php?category=my\">".get_string("mycourses")."</a>"; |
13770d0c |
938 | $caticon[] = ""; |
0c656181 |
939 | } |
13770d0c |
940 | print_side_block(get_string("categories"), "", $catdata, $caticon, "", $width); |
ba2e5d73 |
941 | } |
ba2e5d73 |
942 | } |
94361e02 |
943 | |
2b8cef80 |
944 | function print_log_graph($course, $userid=0, $type="course.png", $date=0) { |
945 | global $CFG; |
607809b3 |
946 | if (empty($CFG->gdversion)) { |
947 | echo "(".get_string("gdneed").")"; |
948 | } else { |
949 | echo "<IMG BORDER=0 SRC=\"$CFG->wwwroot/course/loggraph.php?id=$course->id&user=$userid&type=$type&date=$date\">"; |
950 | } |
2b8cef80 |
951 | } |
952 | |
11b0c469 |
953 | |
954 | |
955 | /// MODULE FUNCTIONS ///////////////////////////////////////////////////////////////// |
956 | |
957 | function add_course_module($mod) { |
11b0c469 |
958 | |
e5dfd0f3 |
959 | $mod->added = time(); |
11b0c469 |
960 | |
e5dfd0f3 |
961 | return insert_record("course_modules", $mod); |
11b0c469 |
962 | } |
963 | |
964 | function add_mod_to_section($mod) { |
965 | // Returns the course_sections ID where the mod is inserted |
966 | GLOBAL $db; |
967 | |
9fa49e22 |
968 | if ($section = get_record("course_sections", "course", "$mod->course", "section", "$mod->section")) { |
74666583 |
969 | if (!empty($section->sequence)) { |
e5dfd0f3 |
970 | $newsequence = "$section->sequence,$mod->coursemodule"; |
11b0c469 |
971 | } else { |
972 | $newsequence = "$mod->coursemodule"; |
973 | } |
e5dfd0f3 |
974 | if (set_field("course_sections", "sequence", $newsequence, "id", $section->id)) { |
975 | return $section->id; // Return course_sections ID that was used. |
11b0c469 |
976 | } else { |
e5dfd0f3 |
977 | return 0; |
11b0c469 |
978 | } |
979 | |
980 | } else { // Insert a new record |
e5dfd0f3 |
981 | $section->course = $mod->course; |
982 | $section->section = $mod->section; |
983 | $section->summary = ""; |
984 | $section->sequence = $mod->coursemodule; |
985 | return insert_record("course_sections", $section); |
11b0c469 |
986 | } |
987 | } |
988 | |
1acfbce5 |
989 | function hide_course_module($mod) { |
990 | return set_field("course_modules", "visible", 0, "id", $mod); |
991 | } |
992 | |
993 | function show_course_module($mod) { |
994 | return set_field("course_modules", "visible", 1, "id", $mod); |
995 | } |
996 | |
11b0c469 |
997 | function delete_course_module($mod) { |
998 | return set_field("course_modules", "deleted", 1, "id", $mod); |
999 | } |
1000 | |
1001 | function delete_mod_from_section($mod, $section) { |
11b0c469 |
1002 | |
e5dfd0f3 |
1003 | if ($section = get_record("course_sections", "id", "$section") ) { |
11b0c469 |
1004 | |
e5dfd0f3 |
1005 | $modarray = explode(",", $section->sequence); |
11b0c469 |
1006 | |
1007 | if ($key = array_keys ($modarray, $mod)) { |
1008 | array_splice($modarray, $key[0], 1); |
1009 | $newsequence = implode(",", $modarray); |
e5dfd0f3 |
1010 | return set_field("course_sections", "sequence", $newsequence, "id", $section->id); |
11b0c469 |
1011 | } else { |
1012 | return false; |
1013 | } |
1014 | |
1015 | } else { |
1016 | return false; |
1017 | } |
1018 | } |
1019 | |
12905134 |
1020 | function move_section($course, $section, $move) { |
1021 | /// Moves a whole course section up and down within the course |
1022 | |
1023 | if (!$move) { |
1024 | return true; |
1025 | } |
1026 | |
1027 | $sectiondest = $section + $move; |
1028 | |
1029 | if ($sectiondest > $course->numsections or $sectiondest < 1) { |
1030 | return false; |
1031 | } |
1032 | |
1033 | if (!$sectionrecord = get_record("course_sections", "course", $course->id, "section", $section)) { |
1034 | return false; |
1035 | } |
1036 | |
1037 | if (!$sectiondestrecord = get_record("course_sections", "course", $course->id, "section", $sectiondest)) { |
1038 | return false; |
1039 | } |
1040 | |
1041 | $sectionrecord->section = $sectiondest; |
1042 | $sectiondestrecord->section = $section; |
1043 | |
1044 | if (!update_record("course_sections", $sectionrecord)) { |
1045 | return false; |
1046 | } |
1047 | if (!update_record("course_sections", $sectiondestrecord)) { |
1048 | return false; |
1049 | } |
1050 | return true; |
1051 | } |
1052 | |
1053 | |
11b0c469 |
1054 | |
7c0f2984 |
1055 | function move_module($cm, $move) { |
12905134 |
1056 | /// Moves an activity module up and down within the course |
11b0c469 |
1057 | |
1058 | if (!$move) { |
1059 | return true; |
1060 | } |
1061 | |
11b0c469 |
1062 | if (! $thissection = get_record("course_sections", "id", $cm->section)) { |
1063 | error("This course section doesn't exist"); |
1064 | } |
1065 | |
1066 | $mods = explode(",", $thissection->sequence); |
1067 | |
1068 | $len = count($mods); |
1069 | $pos = array_keys($mods, $cm->id); |
1070 | $thepos = $pos[0]; |
1071 | |
1072 | if ($len == 0 || count($pos) == 0 ) { |
1073 | error("Very strange. Could not find the required module in this section."); |
1074 | } |
1075 | |
1076 | if ($len == 1) { |
1077 | $first = true; |
1078 | $last = true; |
1079 | } else { |
1080 | $first = ($thepos == 0); |
1081 | $last = ($thepos == $len - 1); |
1082 | } |
1083 | |
1084 | if ($move < 0) { // Moving the module up |
1085 | |
1086 | if ($first) { |
ad41694c |
1087 | if ($thissection->section == 0) { // First section, do nothing |
11b0c469 |
1088 | return true; |
ad41694c |
1089 | |
11b0c469 |
1090 | } else { // Push onto end of previous section |
1091 | $prevsectionnumber = $thissection->section - 1; |
9fa49e22 |
1092 | if (! $prevsection = get_record("course_sections", "course", "$thissection->course", |
1093 | "section", "$prevsectionnumber")) { |
11b0c469 |
1094 | error("Previous section ($prevsection->id) doesn't exist"); |
1095 | } |
1096 | |
74666583 |
1097 | if (!empty($prevsection->sequence)) { |
11b0c469 |
1098 | $newsequence = "$prevsection->sequence,$cm->id"; |
1099 | } else { |
1100 | $newsequence = "$cm->id"; |
1101 | } |
1102 | |
1103 | if (! set_field("course_sections", "sequence", $newsequence, "id", $prevsection->id)) { |
1104 | error("Previous section could not be updated"); |
1105 | } |
1106 | |
1107 | if (! set_field("course_modules", "section", $prevsection->id, "id", $cm->id)) { |
1108 | error("Module could not be updated"); |
1109 | } |
1110 | |
1111 | array_splice($mods, 0, 1); |
1112 | $newsequence = implode(",", $mods); |
1113 | if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) { |
1114 | error("Module could not be updated"); |
1115 | } |
1116 | |
1117 | return true; |
1118 | |
1119 | } |
1120 | } else { // move up within this section |
1121 | $swap = $mods[$thepos-1]; |
1122 | $mods[$thepos-1] = $mods[$thepos]; |
1123 | $mods[$thepos] = $swap; |
1124 | |
1125 | $newsequence = implode(",", $mods); |
1126 | if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) { |
1127 | error("This section could not be updated"); |
1128 | } |
1129 | return true; |
1130 | } |
1131 | |
1132 | } else { // Moving the module down |
1133 | |
1134 | if ($last) { |
1135 | $nextsectionnumber = $thissection->section + 1; |
9fa49e22 |
1136 | if ($nextsection = get_record("course_sections", "course", "$thissection->course", |
1137 | "section", "$nextsectionnumber")) { |
11b0c469 |
1138 | |
74666583 |
1139 | if (!empty($nextsection->sequence)) { |
11b0c469 |
1140 | $newsequence = "$cm->id,$nextsection->sequence"; |
1141 | } else { |
1142 | $newsequence = "$cm->id"; |
1143 | } |
1144 | |
1145 | if (! set_field("course_sections", "sequence", $newsequence, "id", $nextsection->id)) { |
1146 | error("Next section could not be updated"); |
1147 | } |
1148 | |
1149 | if (! set_field("course_modules", "section", $nextsection->id, "id", $cm->id)) { |
1150 | error("Module could not be updated"); |
1151 | } |
1152 | |
1153 | array_splice($mods, $thepos, 1); |
1154 | $newsequence = implode(",", $mods); |
1155 | if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) { |
1156 | error("This section could not be updated"); |
1157 | } |
1158 | return true; |
1159 | |
1160 | } else { // There is no next section, so just return |
1161 | return true; |
1162 | |
1163 | } |
1164 | } else { // move down within this section |
1165 | $swap = $mods[$thepos+1]; |
1166 | $mods[$thepos+1] = $mods[$thepos]; |
1167 | $mods[$thepos] = $swap; |
1168 | |
1169 | $newsequence = implode(",", $mods); |
1170 | if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) { |
1171 | error("This section could not be updated"); |
1172 | } |
1173 | return true; |
1174 | } |
1175 | } |
1176 | } |
1177 | |
4de4fdfe |
1178 | function make_editing_buttons($moduleid, $absolute=false, $visible=true) { |
dc0dc7d5 |
1179 | global $CFG, $THEME; |
94361e02 |
1180 | |
4de4fdfe |
1181 | static $str = ''; |
1acfbce5 |
1182 | if (empty($str)) { |
1183 | $str->delete = get_string("delete"); |
1184 | $str->moveup = get_string("moveup"); |
1185 | $str->movedown = get_string("movedown"); |
1186 | $str->update = get_string("update"); |
1187 | $str->hide = get_string("hide"); |
1188 | $str->show = get_string("show"); |
1189 | } |
94361e02 |
1190 | |
1191 | if ($absolute) { |
dc0dc7d5 |
1192 | $path = "$CFG->wwwroot/course"; |
1193 | } else { |
1194 | $path = "."; |
1195 | } |
1196 | |
1197 | if (empty($THEME->custompix)) { |
1198 | $pixpath = "$path/../pix"; |
94361e02 |
1199 | } else { |
dc0dc7d5 |
1200 | $pixpath = "$path/../theme/$CFG->theme/pix"; |
94361e02 |
1201 | } |
1acfbce5 |
1202 | |
1203 | if ($visible) { |
dc0dc7d5 |
1204 | $hideshow = " <a title=\"$str->hide\" href=\"$path/mod.php?hide=$moduleid\"><img |
3bb49201 |
1205 | src=\"$pixpath/t/hide.gif\" hspace=2 height=11 width=11 border=0></a>"; |
1acfbce5 |
1206 | } else { |
dc0dc7d5 |
1207 | $hideshow = " <a title=\"$str->show\" href=\"$path/mod.php?show=$moduleid\"><img |
3bb49201 |
1208 | src=\"$pixpath/t/show.gif\" hspace=2 height=11 width=11 border=0></a>"; |
1acfbce5 |
1209 | } |
1210 | |
dc0dc7d5 |
1211 | return "<a title=\"$str->delete\" href=\"$path/mod.php?delete=$moduleid\"><img |
1212 | src=\"$pixpath/t/delete.gif\" height=11 width=11 border=0></a> |
1213 | <a title=\"$str->moveup\" href=\"$path/mod.php?id=$moduleid&move=-1\"><img |
1214 | src=\"$pixpath/t/up.gif\" height=11 width=11 border=0></a> |
1215 | <a title=\"$str->movedown\" href=\"$path/mod.php?id=$moduleid&move=1\"><img |
1216 | src=\"$pixpath/t/down.gif\" height=11 width=11 border=0></a> |
1217 | <a title=\"$str->update\" href=\"$path/mod.php?update=$moduleid\"><img |
1218 | src=\"$pixpath/t/edit.gif\" height=11 width=11 border=0></a> $hideshow"; |
90845098 |
1219 | } |
1220 | |
f9903ed0 |
1221 | ?> |