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_recent_activity($course) { |
302 | // $course is an object |
303 | // This function trawls through the logs looking for |
304 | // anything new since the user's last login |
305 | |
3d891989 |
306 | global $CFG, $USER; |
600149be |
307 | |
308 | if (! $USER->lastlogin ) { |
3d891989 |
309 | echo "<p align=center><font size=1>"; |
4b1371a7 |
310 | print_string("welcometocourse", "", $course->shortname); |
3d891989 |
311 | echo "</font></p>"; |
600149be |
312 | return; |
4c654ee3 |
313 | } else { |
3d891989 |
314 | echo "<p align=center><font size=1>"; |
4c654ee3 |
315 | echo get_string("yourlastlogin").":<BR>"; |
dcde9f02 |
316 | echo userdate($USER->lastlogin, get_string("strftimerecentfull")); |
3d891989 |
317 | echo "</font></p>"; |
318 | } |
319 | |
320 | $timestart = $USER->lastlogin; |
b1992e65 |
321 | $timemaxrecent = time() - COURSE_MAX_RECENT_PERIOD; |
322 | if ($timestart < $timemaxrecent) { |
323 | $timestart = $timemaxrecent; |
600149be |
324 | } |
325 | |
600149be |
326 | |
327 | // Firstly, have there been any new enrolments? |
328 | |
329 | $heading = false; |
330 | $content = false; |
1b5910c4 |
331 | |
332 | $logs = get_records_select("log", "time > '$timestart' AND course = '$course->id' AND |
333 | module = 'course' AND action = 'enrol'", "time ASC"); |
334 | |
335 | if ($logs) { |
336 | foreach ($logs as $key => $log) { |
600149be |
337 | if (! $heading) { |
4c654ee3 |
338 | print_headline(get_string("newusers").":"); |
600149be |
339 | $heading = true; |
340 | $content = true; |
341 | } |
342 | $user = get_record("user", "id", $log->info); |
d578afc8 |
343 | if (isstudent($course->id, $user->id)) { |
3d891989 |
344 | echo "<p><font size=1><a href=\"../user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</a></font></p>"; |
d578afc8 |
345 | } |
600149be |
346 | } |
347 | } |
348 | |
1b5910c4 |
349 | // Next, have there been any modifications to the course structure? |
350 | |
351 | $logs = get_records_select("log", "time > '$timestart' AND course = '$course->id' AND |
352 | module = 'course' AND action LIKE '% mod'", "time ASC"); |
353 | |
354 | if ($logs) { |
355 | foreach ($logs as $key => $log) { |
356 | $info = split(" ", $log->info); |
357 | $modname = get_field($info[0], "name", "id", $info[1]); |
358 | //Create a temp valid module structure (course,id) |
359 | $tempmod->course = $log->course; |
360 | $tempmod->id = $info[1]; |
361 | //Obtain the visible property from the instance |
362 | $modvisible = instance_is_visible($info[0],$tempmod); |
363 | |
364 | //Only if the mod is visible |
365 | if ($modvisible) { |
366 | switch ($log->action) { |
367 | case "add mod": |
368 | $stradded = get_string("added", "moodle", get_string("modulename", $info[0])); |
369 | $changelist["$log->info"] = array ("operation" => "add", "text" => "$stradded:<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>"); |
370 | break; |
371 | case "update mod": |
372 | $strupdated = get_string("updated", "moodle", get_string("modulename", $info[0])); |
373 | if (empty($changelist["$log->info"])) { |
374 | $changelist["$log->info"] = array ("operation" => "update", "text" => "$strupdated:<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>"); |
375 | } |
376 | break; |
377 | case "delete mod": |
378 | if (!empty($changelist["$log->info"]["operation"]) and |
379 | $changelist["$log->info"]["operation"] == "add") { |
380 | $changelist["$log->info"] = NULL; |
381 | } else { |
382 | $strdeleted = get_string("deletedactivity", "moodle", get_string("modulename", $info[0])); |
383 | $changelist["$log->info"] = array ("operation" => "delete", "text" => $strdeleted); |
384 | } |
385 | break; |
600149be |
386 | } |
ef25340c |
387 | } |
388 | } |
389 | } |
390 | |
9c9f7d77 |
391 | if (!empty($changelist)) { |
ef25340c |
392 | foreach ($changelist as $changeinfo => $change) { |
393 | if ($change) { |
394 | $changes[$changeinfo] = $change; |
395 | } |
396 | } |
397 | if (count($changes) > 0) { |
4c654ee3 |
398 | print_headline(get_string("courseupdates").":"); |
ef25340c |
399 | $content = true; |
400 | foreach ($changes as $changeinfo => $change) { |
3d891989 |
401 | echo "<p><font size=1>".$change["text"]."</font></p>"; |
600149be |
402 | } |
403 | } |
404 | } |
405 | |
3869a2ac |
406 | // Now display new things from each module |
600149be |
407 | |
3869a2ac |
408 | $mods = get_list_of_plugins("mod"); |
600149be |
409 | |
1b5910c4 |
410 | $isteacher = isteacher($course->id); |
411 | |
412 | foreach ($mods as $mod) { // Each module gets it's own logs and prints them |
3869a2ac |
413 | include_once("$CFG->dirroot/mod/$mod/lib.php"); |
414 | $print_recent_activity = $mod."_print_recent_activity"; |
1b5910c4 |
415 | if (function_exists($print_recent_activity)) { |
416 | $modcontent = $print_recent_activity($course, $isteacher, $timestart); |
3869a2ac |
417 | if ($modcontent) { |
418 | $content = true; |
600149be |
419 | } |
600149be |
420 | } |
421 | } |
422 | |
423 | if (! $content) { |
3d891989 |
424 | echo "<font size=2>".get_string("nothingnew")."</font>"; |
600149be |
425 | } |
600149be |
426 | } |
427 | |
e1360728 |
428 | |
d897cae4 |
429 | function get_array_of_activities($courseid) { |
430 | // For a given course, returns an array of course activity objects |
431 | // Each item in the array contains he following properties: |
432 | // cm - course module id |
433 | // mod - name of the module (eg forum) |
434 | // section - the number of the section (eg week or topic) |
435 | // name - the name of the instance |
5867bfb5 |
436 | // visible - is the instance visible or not |
86aa7ccf |
437 | // extra - contains extra string to include in any link |
d897cae4 |
438 | |
439 | $mod = array(); |
440 | |
9fa49e22 |
441 | if (!$rawmods = get_course_mods($courseid)) { |
d897cae4 |
442 | return NULL; |
443 | } |
444 | |
445 | if ($sections = get_records("course_sections", "course", $courseid, "section ASC")) { |
446 | foreach ($sections as $section) { |
74666583 |
447 | if (!empty($section->sequence)) { |
d897cae4 |
448 | $sequence = explode(",", $section->sequence); |
449 | foreach ($sequence as $seq) { |
7af6281f |
450 | if (empty($rawmods[$seq])) { |
451 | continue; |
452 | } |
d897cae4 |
453 | $mod[$seq]->cm = $rawmods[$seq]->id; |
454 | $mod[$seq]->mod = $rawmods[$seq]->modname; |
455 | $mod[$seq]->section = $section->section; |
456 | $mod[$seq]->name = urlencode(get_field($rawmods[$seq]->modname, "name", "id", $rawmods[$seq]->instance)); |
fec5a6a6 |
457 | $mod[$seq]->visible = $rawmods[$seq]->visible; |
86aa7ccf |
458 | $mod[$seq]->extra = ""; |
459 | |
460 | // This part is an ugly hack that doesn't belong here// |
461 | if ($mod[$seq]->mod == "resource") { |
462 | if ($resource = get_record("resource", "id", $rawmods[$seq]->instance)) { |
463 | if ($resource->type == 5 and $resource->alltext) { |
23b8ce89 |
464 | $mod[$seq]->extra = urlencode("target=\"resource$resource->id\" onClick=\"return ". |
86aa7ccf |
465 | "openpopup('/mod/resource/view.php?id=". |
466 | $mod[$seq]->cm. |
93faa0c4 |
467 | "','resource$resource->id','$resource->alltext');\""); |
86aa7ccf |
468 | } |
469 | } |
470 | } |
d897cae4 |
471 | } |
472 | } |
473 | } |
474 | } |
475 | return $mod; |
476 | } |
477 | |
478 | |
479 | |
e1360728 |
480 | |
90845098 |
481 | function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) { |
482 | // Returns a number of useful structures for course displays |
7468bf01 |
483 | |
90845098 |
484 | $mods = NULL; // course modules indexed by id |
485 | $modnames = NULL; // all course module names |
94361e02 |
486 | $modnamesplural= NULL; // all course module names (plural form) |
90845098 |
487 | $modnamesused = NULL; // course module names used |
7468bf01 |
488 | |
9fa49e22 |
489 | if ($allmods = get_records("modules")) { |
90845098 |
490 | foreach ($allmods as $mod) { |
5867bfb5 |
491 | if ($mod->visible) { |
492 | $modnames[$mod->name] = get_string("modulename", "$mod->name"); |
493 | $modnamesplural[$mod->name] = get_string("modulenameplural", "$mod->name"); |
494 | } |
90845098 |
495 | } |
496 | asort($modnames); |
497 | } else { |
498 | error("No modules are installed!"); |
499 | } |
500 | |
9fa49e22 |
501 | if ($rawmods = get_course_mods($courseid)) { |
7468bf01 |
502 | foreach($rawmods as $mod) { // Index the mods |
503 | $mods[$mod->id] = $mod; |
90845098 |
504 | $mods[$mod->id]->modfullname = $modnames[$mod->modname]; |
1acfbce5 |
505 | if ($mod->visible or isteacher($courseid)) { |
506 | $modnamesused[$mod->modname] = $modnames[$mod->modname]; |
507 | } |
7468bf01 |
508 | } |
c7da6f7a |
509 | if ($modnamesused) { |
510 | asort($modnamesused); |
511 | } |
7468bf01 |
512 | } |
7468bf01 |
513 | } |
514 | |
9fa49e22 |
515 | |
7468bf01 |
516 | function get_all_sections($courseid) { |
517 | |
d26d7ed0 |
518 | return get_records("course_sections", "course", "$courseid", "section", |
7d99d695 |
519 | "section, id, course, summary, sequence, visible"); |
7468bf01 |
520 | } |
521 | |
b86fc0e2 |
522 | function course_set_display($courseid, $display=0) { |
523 | global $USER; |
524 | |
525 | if (empty($USER)) { |
526 | return false; |
527 | } |
528 | |
529 | if ($display == "all" or empty($display)) { |
530 | $display = 0; |
531 | } |
532 | |
533 | if (record_exists("course_display", "userid", $USER->id, "course", $courseid)) { |
534 | set_field("course_display", "display", $display, "userid", $USER->id, "course", $courseid); |
535 | } else { |
536 | $record->userid = $USER->id; |
537 | $record->course = $courseid; |
538 | $record->display = $display; |
539 | if (!insert_record("course_display", $record)) { |
540 | notify("Could not save your course display!"); |
541 | } |
542 | } |
543 | |
544 | return $USER->display[$courseid] = $display; // Note: = not == |
545 | } |
546 | |
7d99d695 |
547 | function set_section_visible($courseid, $sectionnumber, $visibility) { |
548 | /// For a given course section, markes it visible or hidden, |
549 | /// and does the same for every activity in that section |
550 | |
551 | if ($section = get_record("course_sections", "course", $courseid, "section", $sectionnumber)) { |
552 | set_field("course_sections", "visible", "$visibility", "id", $section->id); |
553 | if (!empty($section->sequence)) { |
554 | $modules = explode(",", $section->sequence); |
555 | foreach ($modules as $moduleid) { |
556 | set_field("course_modules", "visible", "$visibility", "id", $moduleid); |
557 | } |
558 | } |
5867bfb5 |
559 | rebuild_course_cache($courseid); |
7d99d695 |
560 | } |
561 | } |
ba2e5d73 |
562 | |
5e367a2d |
563 | function print_section_block($heading, $course, $section, $mods, $modnames, $modnamesused, |
52dcc2f9 |
564 | $absolute=true, $width="100%") { |
5e367a2d |
565 | |
566 | global $CFG; |
52dcc2f9 |
567 | static $isteacher; |
568 | static $isediting; |
569 | |
570 | if (!isset($isteacher)) { |
571 | $isteacher = isteacher($course->id); |
572 | } |
573 | if (!isset($isediting)) { |
574 | $isediting = isediting($course->id); |
575 | } |
5e367a2d |
576 | |
577 | $modinfo = unserialize($course->modinfo); |
578 | $moddata = array(); |
579 | $modicon = array(); |
580 | $editbuttons = ""; |
581 | |
74666583 |
582 | if (!empty($section->sequence)) { |
5e367a2d |
583 | |
584 | $sectionmods = explode(",", $section->sequence); |
585 | |
586 | foreach ($sectionmods as $modnumber) { |
52dcc2f9 |
587 | if (empty($mods[$modnumber])) { |
588 | continue; |
589 | } |
5e367a2d |
590 | $mod = $mods[$modnumber]; |
591 | if ($isediting) { |
7977cffd |
592 | $editbuttons = make_editing_buttons($mod->id, $absolute, $mod->visible, false); |
1acfbce5 |
593 | } |
52dcc2f9 |
594 | if ($mod->visible or $isteacher) { |
1acfbce5 |
595 | $instancename = urldecode($modinfo[$modnumber]->name); |
7977cffd |
596 | $link_css = $mod->visible ? "" : " class=\"dimmed\" "; |
3ee3e01a |
597 | if (!empty($modinfo[$modnumber]->extra)) { |
598 | $extra = urldecode($modinfo[$modnumber]->extra); |
599 | } else { |
600 | $extra = ""; |
601 | } |
7977cffd |
602 | |
52dcc2f9 |
603 | $modicon[] = "<img src=\"$CFG->wwwroot/mod/$mod->modname/icon.gif\"". |
604 | " height=\"16\" width=\"16\" alt=\"$mod->modfullname\">"; |
3ee3e01a |
605 | $moddata[] = "<a title=\"$mod->modfullname\" $link_css $extra". |
52dcc2f9 |
606 | "href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename</a>". |
607 | "<br />$editbuttons"; |
5e367a2d |
608 | } |
5e367a2d |
609 | } |
610 | } |
a44d18e7 |
611 | if ($isediting) { |
15ac9065 |
612 | $editmenu = popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section->section&add=", |
5e367a2d |
613 | $modnames, "section0", "", get_string("add")."...", "mods", get_string("activities"), true); |
dfec7b01 |
614 | $editmenu = "<div align=right>$editmenu</div>"; |
47f1da80 |
615 | } else { |
616 | $editmenu = ""; |
5e367a2d |
617 | } |
618 | |
619 | print_side_block($heading, "", $moddata, $modicon, $editmenu, $width); |
620 | } |
621 | |
622 | |
d897cae4 |
623 | function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%") { |
52dcc2f9 |
624 | /// Prints a section full of activity modules |
7977cffd |
625 | global $CFG, $USER; |
626 | |
52dcc2f9 |
627 | static $isteacher; |
628 | static $isediting; |
7977cffd |
629 | static $ismoving; |
630 | static $strmovehere; |
631 | static $strmovefull; |
52dcc2f9 |
632 | |
633 | if (!isset($isteacher)) { |
634 | $isteacher = isteacher($course->id); |
635 | } |
636 | if (!isset($isediting)) { |
637 | $isediting = isediting($course->id); |
638 | } |
7977cffd |
639 | if (!isset($ismoving)) { |
640 | $ismoving = ismoving($course->id); |
641 | } |
642 | if ($ismoving) { |
643 | $strmovehere = get_string("movehere"); |
644 | $strmovefull = get_string("movefull", "", "'$USER->activitycopyname'"); |
645 | } |
94361e02 |
646 | |
c408b0c4 |
647 | $modinfo = unserialize($course->modinfo); |
94361e02 |
648 | |
dfec7b01 |
649 | echo "<table width=\"$width\"><tr><td>\n"; |
74666583 |
650 | if (!empty($section->sequence)) { |
94361e02 |
651 | |
652 | $sectionmods = explode(",", $section->sequence); |
653 | |
654 | foreach ($sectionmods as $modnumber) { |
9ae687af |
655 | if (empty($mods[$modnumber])) { |
656 | continue; |
657 | } |
94361e02 |
658 | $mod = $mods[$modnumber]; |
52dcc2f9 |
659 | if ($mod->visible or $isteacher) { |
7977cffd |
660 | if ($ismoving) { |
661 | if ($mod->id == $USER->activitycopy) { |
662 | continue; |
663 | } |
664 | echo "<font size=\"2\"> -> <a title=\"$strmovefull\"". |
665 | " href=\"mod.php?moveto=$mod->id\">$strmovehere</a></font><br />\n"; |
1acfbce5 |
666 | } |
7977cffd |
667 | $instancename = urldecode($modinfo[$modnumber]->name); |
86aa7ccf |
668 | if (!empty($modinfo[$modnumber]->extra)) { |
669 | $extra = urldecode($modinfo[$modnumber]->extra); |
670 | } else { |
671 | $extra = ""; |
672 | } |
7977cffd |
673 | $link_css = $mod->visible ? "" : " class=\"dimmed\" "; |
52dcc2f9 |
674 | echo "<img src=\"$CFG->wwwroot/mod/$mod->modname/icon.gif\"". |
675 | " height=16 width=16 alt=\"$mod->modfullname\">". |
86aa7ccf |
676 | " <font size=2><a title=\"$mod->modfullname\" $link_css $extra". |
52dcc2f9 |
677 | " href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename</a></font>"; |
1acfbce5 |
678 | } |
d897cae4 |
679 | if (isediting($course->id)) { |
5e367a2d |
680 | echo " "; |
1acfbce5 |
681 | echo make_editing_buttons($mod->id, $absolute, $mod->visible); |
682 | } |
52dcc2f9 |
683 | if ($mod->visible or $isteacher) { |
dfec7b01 |
684 | echo "<br />\n"; |
94361e02 |
685 | } |
94361e02 |
686 | } |
687 | } |
7977cffd |
688 | if ($ismoving) { |
689 | echo "<font size=\"2\"> -> <a title=\"$strmovefull\"". |
690 | " href=\"mod.php?movetosection=$section->id\">$strmovehere</a></font><br />\n"; |
691 | } |
dfec7b01 |
692 | echo "</td></tr></table><br />\n\n"; |
a7ad3ea6 |
693 | } |
694 | |
5867bfb5 |
695 | |
696 | function rebuild_course_cache($courseid=0) { |
697 | // Rebuilds the cached list of course activities stored in the database |
698 | // If a courseid is not specified, then all are rebuilt |
699 | |
700 | if ($courseid) { |
701 | $select = "id = '$courseid'"; |
702 | } else { |
703 | $select = ""; |
704 | } |
705 | |
706 | if ($courses = get_records_select("course", $select)) { |
707 | foreach ($courses as $course) { |
708 | $modinfo = serialize(get_array_of_activities($course->id)); |
709 | if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) { |
710 | notify("Could not cache module information for course '$course->fullname'!"); |
711 | } |
712 | } |
713 | } |
714 | } |
715 | |
716 | |
7541bc3e |
717 | function print_heading_block($heading, $width="100%", $class="headingblock") { |
5e367a2d |
718 | global $THEME; |
719 | |
7541bc3e |
720 | echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">"; |
721 | echo "<tr><td bgcolor=\"$THEME->cellheading\" class=\"$class\">"; |
5e367a2d |
722 | echo stripslashes($heading); |
723 | echo "</td></tr></table>"; |
5e367a2d |
724 | } |
725 | |
726 | function print_side_block($heading="", $content="", $list=NULL, $icons=NULL, $footer="", $width=180) { |
727 | // Prints a nice side block with an optional header. The content can either |
728 | // be a block of HTML or a list of text with optional icons. |
a7ad3ea6 |
729 | |
5e367a2d |
730 | global $THEME; |
731 | |
7541bc3e |
732 | print_side_block_start($heading, $width); |
733 | |
5e367a2d |
734 | if ($content) { |
7541bc3e |
735 | echo "$content"; |
5e367a2d |
736 | } else { |
5e367a2d |
737 | echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">"; |
738 | foreach ($list as $key => $string) { |
7541bc3e |
739 | echo "<tr bgcolor=\"$THEME->cellcontent2\">"; |
5e367a2d |
740 | if ($icons) { |
7541bc3e |
741 | echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"16\">".$icons[$key]."</td>"; |
a7ad3ea6 |
742 | } |
7541bc3e |
743 | echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"*\"><font size=\"-1\">$string</font></td>"; |
5e367a2d |
744 | echo "</tr>"; |
a7ad3ea6 |
745 | } |
5e367a2d |
746 | if ($footer) { |
7541bc3e |
747 | echo "<tr bgcolor=\"$THEME->cellcontent2\">"; |
5e367a2d |
748 | if ($icons) { |
7541bc3e |
749 | echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"16\"> </td>"; |
5e367a2d |
750 | } |
7541bc3e |
751 | echo "<td class=\"sideblocklinks\"><font size=\"-1\">$footer</td>"; |
5e367a2d |
752 | echo "</tr>"; |
753 | } |
754 | echo "</table>"; |
a7ad3ea6 |
755 | } |
5e367a2d |
756 | |
7541bc3e |
757 | print_side_block_end(); |
758 | } |
759 | |
760 | function print_side_block_start($heading="", $width=180, $class="sideblockmain") { |
761 | // Starts a nice side block with an optional header. |
762 | |
763 | global $THEME; |
764 | |
765 | echo "<table class=\"sideblock\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">"; |
766 | if ($heading) { |
767 | echo "<tr>"; |
768 | echo "<td class=\"sideblockheading\" bgcolor=\"$THEME->cellheading\">$heading</td>"; |
769 | echo "</tr>"; |
770 | } |
771 | echo "<tr>"; |
772 | echo "<td class=\"$class\" bgcolor=\"$THEME->cellcontent2\">"; |
773 | } |
774 | |
775 | function print_side_block_end() { |
776 | echo "</td></tr>"; |
7d99d695 |
777 | echo "</table><br />"; |
94361e02 |
778 | } |
779 | |
5e367a2d |
780 | |
670fddf1 |
781 | function print_admin_links ($siteid, $width=180) { |
dc0dc7d5 |
782 | global $CFG, $THEME; |
2b25f2a0 |
783 | |
dc0dc7d5 |
784 | if (empty($THEME->custompix)) { |
785 | $icon = "<img src=\"$CFG->wwwroot/pix/i/settings.gif\" height=16 width=16 alt=\"\">"; |
786 | } else { |
787 | $icon = "<img src=\"$CFG->wwwroot/theme/$CFG->theme/pix/i/settings.gif\" height=16 width=16 alt=\"\">"; |
788 | } |
789 | |
1924074c |
790 | if (isadmin()) { |
5867bfb5 |
791 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/config.php\">".get_string("configvariables")."</a>"; |
792 | $modicon[]=$icon; |
793 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/site.php\">".get_string("sitesettings")."</a>"; |
1924074c |
794 | $modicon[]=$icon; |
5867bfb5 |
795 | $moddata[]="<a href=\"$CFG->wwwroot/course/log.php?id=$siteid\">".get_string("sitelogs")."</a>"; |
1924074c |
796 | $modicon[]=$icon; |
5867bfb5 |
797 | $moddata[]="<a href=\"$CFG->wwwroot/theme/index.php\">".get_string("choosetheme")."</a>"; |
1924074c |
798 | $modicon[]=$icon; |
5867bfb5 |
799 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/lang.php\">".get_string("checklanguage")."</a>"; |
1924074c |
800 | $modicon[]=$icon; |
5867bfb5 |
801 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/modules.php\">".get_string("managemodules")."</a>"; |
1924074c |
802 | $modicon[]=$icon; |
be09831a |
803 | if (file_exists("$CFG->dirroot/$CFG->admin/$CFG->dbtype")) { |
5867bfb5 |
804 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/$CFG->dbtype/frame.php\">".get_string("managedatabase")."</a>"; |
1924074c |
805 | $modicon[]=$icon; |
806 | } |
5867bfb5 |
807 | $moddata[]="<hr>"; |
1924074c |
808 | $modicon[]=""; |
809 | } |
810 | if (iscreator()) { |
5867bfb5 |
811 | $moddata[]="<a href=\"$CFG->wwwroot/course/edit.php\">".get_string("addnewcourse")."</a>"; |
1924074c |
812 | $modicon[]=$icon; |
e808d25f |
813 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/teacher.php\">".get_string("assignteachers")."</a>"; |
1924074c |
814 | $modicon[]=$icon; |
5b337cdf |
815 | $fulladmin = ""; |
1924074c |
816 | } |
817 | if (isadmin()) { |
5867bfb5 |
818 | $moddata[]="<a href=\"$CFG->wwwroot/course/categories.php\">".get_string("categories")."</a>"; |
1924074c |
819 | $modicon[]=$icon; |
5867bfb5 |
820 | $moddata[]="<a href=\"$CFG->wwwroot/course/delete.php\">".get_string("deletecourse")."</a>"; |
1924074c |
821 | $modicon[]=$icon; |
5867bfb5 |
822 | $moddata[]="<hr>"; |
1924074c |
823 | $modicon[]=""; |
3399a22c |
824 | if($CFG->auth == "email" || $CFG->auth == "none" || $CFG->auth == "manual"){ |
5867bfb5 |
825 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/user.php?newuser=true\">".get_string("addnewuser")."</a>"; |
3399a22c |
826 | $modicon[]=$icon; |
827 | } |
5867bfb5 |
828 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/user.php\">".get_string("edituser")."</a>"; |
1924074c |
829 | $modicon[]=$icon; |
5867bfb5 |
830 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/admin.php\">".get_string("assignadmins")."</a>"; |
1924074c |
831 | $modicon[]=$icon; |
5867bfb5 |
832 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/creators.php\">".get_string("assigncreators")."</a>"; |
1924074c |
833 | $modicon[]=$icon; |
5867bfb5 |
834 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/auth.php\">".get_string("authentication")."</a>"; |
1924074c |
835 | $modicon[]=$icon; |
5867bfb5 |
836 | $fulladmin = "<p><a href=\"$CFG->wwwroot/$CFG->admin/\">".get_string("admin")."</a>..."; |
1924074c |
837 | } |
5e367a2d |
838 | |
839 | print_side_block(get_string("administration"), "", $moddata, $modicon, $fulladmin, $width); |
840 | |
dc0dc7d5 |
841 | echo "<img src=\"$CFG->wwwroot/pix/spacer.gif\" width=\"$width\" height=1><br>"; |
2b25f2a0 |
842 | } |
843 | |
b4d7002e |
844 | function print_course_admin_links($course, $width=180) { |
dc0dc7d5 |
845 | global $USER, $CFG, $THEME; |
44dad735 |
846 | |
fce1ce13 |
847 | if (isguest()) { |
848 | return true; |
849 | } |
dc0dc7d5 |
850 | if (empty($THEME->custompix)) { |
851 | $pixpath = "$CFG->wwwroot/pix"; |
852 | $modpixpath = "$CFG->wwwroot/mod"; |
853 | } else { |
854 | $pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix"; |
855 | $modpixpath = "$CFG->wwwroot/theme/$CFG->theme/pix/mod"; |
856 | } |
13469b82 |
857 | if (isteacher($course->id)) { |
dc0dc7d5 |
858 | $adminicon[]="<img src=\"$pixpath/i/edit.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
859 | if (isediting($course->id)) { |
dc0dc7d5 |
860 | $admindata[]="<a href=\"view.php?id=$course->id&edit=off\">".get_string("turneditingoff")."</a>"; |
13469b82 |
861 | } else { |
dc0dc7d5 |
862 | $admindata[]="<a href=\"view.php?id=$course->id&edit=on\">".get_string("turneditingon")."</a>"; |
13469b82 |
863 | } |
dc0dc7d5 |
864 | $admindata[]="<a href=\"edit.php?id=$course->id\">".get_string("settings")."...</a>"; |
865 | $adminicon[]="<img src=\"$pixpath/i/settings.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
866 | if (!$course->teachers) { |
867 | $course->teachers = get_string("defaultcourseteachers"); |
868 | } |
dc0dc7d5 |
869 | $admindata[]="<a href=\"teachers.php?id=$course->id\">$course->teachers...</a>"; |
870 | $adminicon[]="<img src=\"$pixpath/i/settings.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
871 | |
dc0dc7d5 |
872 | $admindata[]="<a href=\"grades.php?id=$course->id\">".get_string("grades")."...</a>"; |
873 | $adminicon[]="<img src=\"$pixpath/i/grades.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
874 | |
dc0dc7d5 |
875 | $admindata[]="<a href=\"log.php?id=$course->id\">".get_string("logs")."...</a>"; |
876 | $adminicon[]="<img src=\"$pixpath/i/log.gif\" height=16 width=16 alt=\"\">"; |
877 | |
878 | $admindata[]="<a href=\"$CFG->wwwroot/files/index.php?id=$course->id\">".get_string("files")."...</a>"; |
879 | $adminicon[]="<img src=\"$pixpath/i/files.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
880 | |
dc0dc7d5 |
881 | $admindata[]="<a href=\"$CFG->wwwroot/doc/view.php?id=$course->id&file=teacher.html\">".get_string("help")."...</a>"; |
882 | $adminicon[]="<img src=\"$modpixpath/resource/icon.gif\" height=16 width=16 alt=\"\">"; |
b4d7002e |
883 | |
13469b82 |
884 | if ($teacherforum = forum_get_course_forum($course->id, "teacher")) { |
dc0dc7d5 |
885 | $admindata[]="<a href=\"$CFG->wwwroot/mod/forum/view.php?f=$teacherforum->id\">".get_string("nameteacher", "forum")."</a>"; |
886 | $adminicon[]="<img src=\"$modpixpath/forum/icon.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
887 | } |
888 | } else { |
dc0dc7d5 |
889 | $admindata[]="<a href=\"grade.php?id=$course->id\">".get_string("grades")."...</a>"; |
890 | $adminicon[]="<img src=\"$pixpath/i/grades.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
891 | } |
44dad735 |
892 | |
5e367a2d |
893 | print_side_block(get_string("administration"), "", $admindata, $adminicon, "", $width); |
44dad735 |
894 | } |
2b25f2a0 |
895 | |
ba2e5d73 |
896 | function print_course_categories($categories, $selected="none", $width=180) { |
0a263205 |
897 | global $CFG, $THEME, $USER; |
85098089 |
898 | |
899 | $strallowguests = get_string("allowguests"); |
900 | $strrequireskey = get_string("requireskey"); |
ba2e5d73 |
901 | |
dc0dc7d5 |
902 | if (empty($THEME->custompix)) { |
903 | $pixpath = "$CFG->wwwroot/pix"; |
904 | } else { |
905 | $pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix"; |
906 | } |
907 | |
0c656181 |
908 | if ($selected == "index") { // Print comprehensive index of categories with courses |
9fa49e22 |
909 | if ($courses = get_courses()) { |
0c656181 |
910 | if (isset($USER->id) and !isadmin()) { |
39246b72 |
911 | print_simple_box_start("CENTER", "100%", $THEME->cellheading); |
dc0dc7d5 |
912 | print_heading("<a href=\"course/index.php?category=my\">".get_string("mycourses")."</a>", "left"); |
0c656181 |
913 | $some = false; |
dc0dc7d5 |
914 | echo "<ul>"; |
0c656181 |
915 | foreach ($courses as $key => $course) { |
916 | if (isteacher($course->id) or isstudent($course->id)) { |
dc0dc7d5 |
917 | echo "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>"; |
918 | echo "<br />"; |
0c656181 |
919 | $some = true; |
920 | } |
921 | } |
922 | if (!$some) { |
923 | print_string("nocoursesyet"); |
924 | } |
dc0dc7d5 |
925 | echo "</ul>"; |
0c656181 |
926 | print_simple_box_end(); |
927 | print_spacer(8,1); |
928 | } |
929 | foreach ($categories as $category) { |
bd4707bf |
930 | print_simple_box_start("CENTER", "100%"); |
dc0dc7d5 |
931 | print_heading("<a href=\"course/index.php?category=$category->id\">$category->name</a>", "left"); |
0c656181 |
932 | $some = false; |
dc0dc7d5 |
933 | echo "<ul>"; |
0c656181 |
934 | foreach ($courses as $key => $course) { |
935 | if ($course->category == $category->id) { |
dc0dc7d5 |
936 | echo "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>"; |
85098089 |
937 | echo " "; |
0c656181 |
938 | unset($courses[$key]); |
85098089 |
939 | if ($course->guest ) { |
dc0dc7d5 |
940 | echo "<a title=\"$strallowguests\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">"; |
941 | echo "<img alt=\"\" height=16 width=16 border=0 src=\"$pixpath/i/user.gif\"></a>"; |
85098089 |
942 | } |
943 | if ($course->password) { |
dc0dc7d5 |
944 | echo "<a title=\"$strrequireskey\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">"; |
945 | echo "<img alt=\"\" height=16 width=16 border=0 src=\"$pixpath/i/key.gif\"></a>"; |
85098089 |
946 | } |
dc0dc7d5 |
947 | echo "<br />"; |
0c656181 |
948 | $some = true; |
949 | } |
950 | } |
951 | if (!$some) { |
952 | print_string("nocoursesyet"); |
953 | } |
dc0dc7d5 |
954 | echo "</ul>"; |
0c656181 |
955 | print_simple_box_end(); |
956 | print_spacer(8,1); |
957 | } |
ba2e5d73 |
958 | } |
0c656181 |
959 | |
960 | } else { // Print short list of categories only |
961 | foreach ($categories as $cat) { |
dc0dc7d5 |
962 | $caticon[]="<img src=\"$pixpath/i/course.gif\" height=16 width=16>"; |
0c656181 |
963 | if ($cat->id == $selected) { |
964 | $catdata[]="$cat->name"; |
965 | } else { |
dc0dc7d5 |
966 | $catdata[]="<a href=\"$CFG->wwwroot/course/index.php?category=$cat->id\">$cat->name</a>"; |
0c656181 |
967 | } |
968 | } |
dc0dc7d5 |
969 | $catdata[] = "<a href=\"$CFG->wwwroot/course/index.php?category=all\">".get_string("fulllistofcourses")."</a>"; |
13770d0c |
970 | $caticon[] = ""; |
0c656181 |
971 | if (isset($USER->id)) { |
dc0dc7d5 |
972 | $catdata[] = "<a href=\"$CFG->wwwroot/course/index.php?category=my\">".get_string("mycourses")."</a>"; |
13770d0c |
973 | $caticon[] = ""; |
0c656181 |
974 | } |
13770d0c |
975 | print_side_block(get_string("categories"), "", $catdata, $caticon, "", $width); |
ba2e5d73 |
976 | } |
ba2e5d73 |
977 | } |
94361e02 |
978 | |
2b8cef80 |
979 | function print_log_graph($course, $userid=0, $type="course.png", $date=0) { |
980 | global $CFG; |
607809b3 |
981 | if (empty($CFG->gdversion)) { |
982 | echo "(".get_string("gdneed").")"; |
983 | } else { |
984 | echo "<IMG BORDER=0 SRC=\"$CFG->wwwroot/course/loggraph.php?id=$course->id&user=$userid&type=$type&date=$date\">"; |
985 | } |
2b8cef80 |
986 | } |
987 | |
11b0c469 |
988 | |
989 | |
990 | /// MODULE FUNCTIONS ///////////////////////////////////////////////////////////////// |
991 | |
992 | function add_course_module($mod) { |
11b0c469 |
993 | |
e5dfd0f3 |
994 | $mod->added = time(); |
11b0c469 |
995 | |
e5dfd0f3 |
996 | return insert_record("course_modules", $mod); |
11b0c469 |
997 | } |
998 | |
7977cffd |
999 | function add_mod_to_section($mod, $beforemod=NULL) { |
1000 | /// Given a full mod object with section and course already defined |
1001 | /// If $before is specified, then this is an existing ID which we |
1002 | /// will insert the new module before |
1003 | /// |
1004 | /// Returns the course_sections ID where the mod is inserted |
11b0c469 |
1005 | |
9fa49e22 |
1006 | if ($section = get_record("course_sections", "course", "$mod->course", "section", "$mod->section")) { |
7977cffd |
1007 | |
1008 | $section->sequence = trim($section->sequence); |
1009 | |
1010 | if (empty($section->sequence)) { |
11b0c469 |
1011 | $newsequence = "$mod->coursemodule"; |
7977cffd |
1012 | |
1013 | } else if ($beforemod) { |
1014 | $modarray = explode(",", $section->sequence); |
1015 | |
1016 | if ($key = array_keys ($modarray, $beforemod->id)) { |
1017 | $insertarray = array($mod->id, $beforemod->id); |
1018 | array_splice($modarray, $key[0], 1, $insertarray); |
1019 | $newsequence = implode(",", $modarray); |
1020 | |
1021 | } else { // Just tack it on the end anyway |
1022 | $newsequence = "$section->sequence,$mod->coursemodule"; |
1023 | } |
1024 | |
1025 | } else { |
1026 | $newsequence = "$section->sequence,$mod->coursemodule"; |
11b0c469 |
1027 | } |
7977cffd |
1028 | |
e5dfd0f3 |
1029 | if (set_field("course_sections", "sequence", $newsequence, "id", $section->id)) { |
1030 | return $section->id; // Return course_sections ID that was used. |
11b0c469 |
1031 | } else { |
e5dfd0f3 |
1032 | return 0; |
11b0c469 |
1033 | } |
1034 | |
1035 | } else { // Insert a new record |
e5dfd0f3 |
1036 | $section->course = $mod->course; |
1037 | $section->section = $mod->section; |
1038 | $section->summary = ""; |
1039 | $section->sequence = $mod->coursemodule; |
1040 | return insert_record("course_sections", $section); |
11b0c469 |
1041 | } |
1042 | } |
1043 | |
1acfbce5 |
1044 | function hide_course_module($mod) { |
1045 | return set_field("course_modules", "visible", 0, "id", $mod); |
1046 | } |
1047 | |
1048 | function show_course_module($mod) { |
1049 | return set_field("course_modules", "visible", 1, "id", $mod); |
1050 | } |
1051 | |
11b0c469 |
1052 | function delete_course_module($mod) { |
1053 | return set_field("course_modules", "deleted", 1, "id", $mod); |
1054 | } |
1055 | |
1056 | function delete_mod_from_section($mod, $section) { |
11b0c469 |
1057 | |
e5dfd0f3 |
1058 | if ($section = get_record("course_sections", "id", "$section") ) { |
11b0c469 |
1059 | |
e5dfd0f3 |
1060 | $modarray = explode(",", $section->sequence); |
11b0c469 |
1061 | |
1062 | if ($key = array_keys ($modarray, $mod)) { |
1063 | array_splice($modarray, $key[0], 1); |
1064 | $newsequence = implode(",", $modarray); |
e5dfd0f3 |
1065 | return set_field("course_sections", "sequence", $newsequence, "id", $section->id); |
11b0c469 |
1066 | } else { |
1067 | return false; |
1068 | } |
1069 | |
11b0c469 |
1070 | } |
7977cffd |
1071 | return false; |
11b0c469 |
1072 | } |
1073 | |
12905134 |
1074 | function move_section($course, $section, $move) { |
1075 | /// Moves a whole course section up and down within the course |
1076 | |
1077 | if (!$move) { |
1078 | return true; |
1079 | } |
1080 | |
1081 | $sectiondest = $section + $move; |
1082 | |
1083 | if ($sectiondest > $course->numsections or $sectiondest < 1) { |
1084 | return false; |
1085 | } |
1086 | |
1087 | if (!$sectionrecord = get_record("course_sections", "course", $course->id, "section", $section)) { |
1088 | return false; |
1089 | } |
1090 | |
1091 | if (!$sectiondestrecord = get_record("course_sections", "course", $course->id, "section", $sectiondest)) { |
1092 | return false; |
1093 | } |
1094 | |
1095 | $sectionrecord->section = $sectiondest; |
1096 | $sectiondestrecord->section = $section; |
1097 | |
1098 | if (!update_record("course_sections", $sectionrecord)) { |
1099 | return false; |
1100 | } |
1101 | if (!update_record("course_sections", $sectiondestrecord)) { |
1102 | return false; |
1103 | } |
1104 | return true; |
1105 | } |
1106 | |
1107 | |
7977cffd |
1108 | function moveto_module($mod, $section, $beforemod=NULL) { |
1109 | /// All parameters are objects |
1110 | /// Move the module object $mod to the specified $section |
1111 | /// If $beforemod exists then that is the module |
1112 | /// before which $modid should be inserted |
1113 | |
1114 | /// Remove original module from original section |
1115 | |
1116 | if (! delete_mod_from_section($mod->id, $mod->section)) { |
1117 | notify("Could not delete module from existing section"); |
1118 | } |
1119 | |
1120 | /// Update module itself if necessary |
1121 | |
1122 | if ($mod->section != $section->id) { |
1123 | $mod->section = $section->id; |
1124 | |
1125 | if (!update_record("course_modules", $mod)) { |
1126 | return false; |
1127 | } |
1128 | } |
1129 | |
1130 | /// Add the module into the new section |
1131 | |
1132 | $mod->course = $section->course; |
1133 | $mod->section = $section->section; // need relative reference |
1134 | $mod->coursemodule = $mod->id; |
1135 | |
1136 | if (! add_mod_to_section($mod, $beforemod)) { |
1137 | return false; |
1138 | } |
1139 | |
1140 | return true; |
1141 | |
1142 | } |
1143 | |
1144 | |
11b0c469 |
1145 | |
7c0f2984 |
1146 | function move_module($cm, $move) { |
12905134 |
1147 | /// Moves an activity module up and down within the course |
11b0c469 |
1148 | |
1149 | if (!$move) { |
1150 | return true; |
1151 | } |
1152 | |
11b0c469 |
1153 | if (! $thissection = get_record("course_sections", "id", $cm->section)) { |
1154 | error("This course section doesn't exist"); |
1155 | } |
1156 | |
1157 | $mods = explode(",", $thissection->sequence); |
1158 | |
1159 | $len = count($mods); |
1160 | $pos = array_keys($mods, $cm->id); |
1161 | $thepos = $pos[0]; |
1162 | |
1163 | if ($len == 0 || count($pos) == 0 ) { |
1164 | error("Very strange. Could not find the required module in this section."); |
1165 | } |
1166 | |
1167 | if ($len == 1) { |
1168 | $first = true; |
1169 | $last = true; |
1170 | } else { |
1171 | $first = ($thepos == 0); |
1172 | $last = ($thepos == $len - 1); |
1173 | } |
1174 | |
1175 | if ($move < 0) { // Moving the module up |
1176 | |
1177 | if ($first) { |
ad41694c |
1178 | if ($thissection->section == 0) { // First section, do nothing |
11b0c469 |
1179 | return true; |
ad41694c |
1180 | |
11b0c469 |
1181 | } else { // Push onto end of previous section |
1182 | $prevsectionnumber = $thissection->section - 1; |
9fa49e22 |
1183 | if (! $prevsection = get_record("course_sections", "course", "$thissection->course", |
1184 | "section", "$prevsectionnumber")) { |
11b0c469 |
1185 | error("Previous section ($prevsection->id) doesn't exist"); |
1186 | } |
1187 | |
74666583 |
1188 | if (!empty($prevsection->sequence)) { |
11b0c469 |
1189 | $newsequence = "$prevsection->sequence,$cm->id"; |
1190 | } else { |
1191 | $newsequence = "$cm->id"; |
1192 | } |
1193 | |
1194 | if (! set_field("course_sections", "sequence", $newsequence, "id", $prevsection->id)) { |
1195 | error("Previous section could not be updated"); |
1196 | } |
1197 | |
1198 | if (! set_field("course_modules", "section", $prevsection->id, "id", $cm->id)) { |
1199 | error("Module could not be updated"); |
1200 | } |
1201 | |
1202 | array_splice($mods, 0, 1); |
1203 | $newsequence = implode(",", $mods); |
1204 | if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) { |
1205 | error("Module could not be updated"); |
1206 | } |
1207 | |
1208 | return true; |
1209 | |
1210 | } |
1211 | } else { // move up within this section |
1212 | $swap = $mods[$thepos-1]; |
1213 | $mods[$thepos-1] = $mods[$thepos]; |
1214 | $mods[$thepos] = $swap; |
1215 | |
1216 | $newsequence = implode(",", $mods); |
1217 | if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) { |
1218 | error("This section could not be updated"); |
1219 | } |
1220 | return true; |
1221 | } |
1222 | |
1223 | } else { // Moving the module down |
1224 | |
1225 | if ($last) { |
1226 | $nextsectionnumber = $thissection->section + 1; |
9fa49e22 |
1227 | if ($nextsection = get_record("course_sections", "course", "$thissection->course", |
1228 | "section", "$nextsectionnumber")) { |
11b0c469 |
1229 | |
74666583 |
1230 | if (!empty($nextsection->sequence)) { |
11b0c469 |
1231 | $newsequence = "$cm->id,$nextsection->sequence"; |
1232 | } else { |
1233 | $newsequence = "$cm->id"; |
1234 | } |
1235 | |
1236 | if (! set_field("course_sections", "sequence", $newsequence, "id", $nextsection->id)) { |
1237 | error("Next section could not be updated"); |
1238 | } |
1239 | |
1240 | if (! set_field("course_modules", "section", $nextsection->id, "id", $cm->id)) { |
1241 | error("Module could not be updated"); |
1242 | } |
1243 | |
1244 | array_splice($mods, $thepos, 1); |
1245 | $newsequence = implode(",", $mods); |
1246 | if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) { |
1247 | error("This section could not be updated"); |
1248 | } |
1249 | return true; |
1250 | |
1251 | } else { // There is no next section, so just return |
1252 | return true; |
1253 | |
1254 | } |
1255 | } else { // move down within this section |
1256 | $swap = $mods[$thepos+1]; |
1257 | $mods[$thepos+1] = $mods[$thepos]; |
1258 | $mods[$thepos] = $swap; |
1259 | |
1260 | $newsequence = implode(",", $mods); |
1261 | if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) { |
1262 | error("This section could not be updated"); |
1263 | } |
1264 | return true; |
1265 | } |
1266 | } |
1267 | } |
1268 | |
7977cffd |
1269 | function make_editing_buttons($moduleid, $absolute=false, $visible=true, $moveselect=true) { |
dc0dc7d5 |
1270 | global $CFG, $THEME; |
94361e02 |
1271 | |
4de4fdfe |
1272 | static $str = ''; |
1acfbce5 |
1273 | if (empty($str)) { |
1274 | $str->delete = get_string("delete"); |
493486c4 |
1275 | $str->move = get_string("move"); |
1acfbce5 |
1276 | $str->moveup = get_string("moveup"); |
1277 | $str->movedown = get_string("movedown"); |
1278 | $str->update = get_string("update"); |
1279 | $str->hide = get_string("hide"); |
1280 | $str->show = get_string("show"); |
1281 | } |
94361e02 |
1282 | |
1283 | if ($absolute) { |
dc0dc7d5 |
1284 | $path = "$CFG->wwwroot/course"; |
1285 | } else { |
1286 | $path = "."; |
1287 | } |
1288 | |
1289 | if (empty($THEME->custompix)) { |
1290 | $pixpath = "$path/../pix"; |
94361e02 |
1291 | } else { |
dc0dc7d5 |
1292 | $pixpath = "$path/../theme/$CFG->theme/pix"; |
94361e02 |
1293 | } |
1acfbce5 |
1294 | |
1295 | if ($visible) { |
7977cffd |
1296 | $hideshow = "<a title=\"$str->hide\" href=\"$path/mod.php?hide=$moduleid\"><img". |
1297 | " src=\"$pixpath/t/hide.gif\" hspace=2 height=11 width=11 border=0></a> "; |
1acfbce5 |
1298 | } else { |
7977cffd |
1299 | $hideshow = "<a title=\"$str->show\" href=\"$path/mod.php?show=$moduleid\"><img". |
1300 | " src=\"$pixpath/t/show.gif\" hspace=2 height=11 width=11 border=0></a> "; |
1301 | } |
1302 | |
1303 | if ($moveselect) { |
1304 | $move = "<a title=\"$str->move\" href=\"$path/mod.php?copy=$moduleid\"><img". |
1305 | " src=\"$pixpath/t/move.gif\" height=\"11\" width=\"11\" border=\"0\"></a> "; |
493486c4 |
1306 | } else { |
1307 | $move = "<a title=\"$str->moveup\" href=\"$path/mod.php?id=$moduleid&move=-1\"><img". |
1308 | " src=\"$pixpath/t/up.gif\" height=11 width=11 border=0></a> ". |
1309 | "<a title=\"$str->movedown\" href=\"$path/mod.php?id=$moduleid&move=1\"><img". |
1310 | " src=\"$pixpath/t/down.gif\" height=11 width=11 border=0></a> "; |
7977cffd |
1311 | } |
1312 | |
1313 | return "<a title=\"$str->delete\" href=\"$path/mod.php?delete=$moduleid\"><img". |
493486c4 |
1314 | " src=\"$pixpath/t/delete.gif\" height=11 width=11 border=0></a> $move". |
7977cffd |
1315 | "<a title=\"$str->update\" href=\"$path/mod.php?update=$moduleid\"><img". |
1316 | " src=\"$pixpath/t/edit.gif\" height=11 width=11 border=0></a> $hideshow"; |
90845098 |
1317 | } |
1318 | |
f9903ed0 |
1319 | ?> |