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 |
fec5a6a6 |
440 | // visible - when the instance is visible or no |
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) { |
481 | $modnames[$mod->name] = get_string("modulename", "$mod->name"); |
482 | $modnamesplural[$mod->name] = get_string("modulenameplural", "$mod->name"); |
483 | } |
484 | asort($modnames); |
485 | } else { |
486 | error("No modules are installed!"); |
487 | } |
488 | |
9fa49e22 |
489 | if ($rawmods = get_course_mods($courseid)) { |
7468bf01 |
490 | foreach($rawmods as $mod) { // Index the mods |
491 | $mods[$mod->id] = $mod; |
90845098 |
492 | $mods[$mod->id]->modfullname = $modnames[$mod->modname]; |
1acfbce5 |
493 | if ($mod->visible or isteacher($courseid)) { |
494 | $modnamesused[$mod->modname] = $modnames[$mod->modname]; |
495 | } |
7468bf01 |
496 | } |
c7da6f7a |
497 | if ($modnamesused) { |
498 | asort($modnamesused); |
499 | } |
7468bf01 |
500 | } |
7468bf01 |
501 | } |
502 | |
9fa49e22 |
503 | |
7468bf01 |
504 | function get_all_sections($courseid) { |
505 | |
d26d7ed0 |
506 | return get_records("course_sections", "course", "$courseid", "section", |
9fa49e22 |
507 | "section, id, course, summary, sequence"); |
7468bf01 |
508 | } |
509 | |
ba2e5d73 |
510 | |
5e367a2d |
511 | function print_section_block($heading, $course, $section, $mods, $modnames, $modnamesused, |
512 | $absolute=true, $width="100%", $isediting=false) { |
513 | |
514 | global $CFG; |
515 | |
516 | $modinfo = unserialize($course->modinfo); |
517 | $moddata = array(); |
518 | $modicon = array(); |
519 | $editbuttons = ""; |
520 | |
74666583 |
521 | if (!empty($section->sequence)) { |
5e367a2d |
522 | |
523 | $sectionmods = explode(",", $section->sequence); |
524 | |
525 | foreach ($sectionmods as $modnumber) { |
526 | $mod = $mods[$modnumber]; |
527 | if ($isediting) { |
1acfbce5 |
528 | $editbuttons = make_editing_buttons($mod->id, $absolute, $mod->visible); |
529 | } |
530 | if ($mod->visible or isteacher($course->id)) { |
531 | $instancename = urldecode($modinfo[$modnumber]->name); |
532 | if ($mod->visible) { |
533 | $link_css = ""; |
534 | } else { |
535 | $link_css = " class=\"dimmed\" "; |
536 | } |
537 | $modicon[] = "<img src=\"$CFG->wwwroot/mod/$mod->modname/icon.gif\" height=\"16\" width=\"16\" alt=\"$mod->modfullname\">"; |
538 | $moddata[] = "<a title=\"$mod->modfullname\" $link_css href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename</a><BR>$editbuttons"; |
5e367a2d |
539 | } |
5e367a2d |
540 | } |
541 | } |
a44d18e7 |
542 | if ($isediting) { |
15ac9065 |
543 | $editmenu = popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section->section&add=", |
5e367a2d |
544 | $modnames, "section0", "", get_string("add")."...", "mods", get_string("activities"), true); |
545 | $editmenu = "<DIV ALIGN=right>$editmenu</DIV>"; |
47f1da80 |
546 | } else { |
547 | $editmenu = ""; |
5e367a2d |
548 | } |
549 | |
550 | print_side_block($heading, "", $moddata, $modicon, $editmenu, $width); |
551 | } |
552 | |
553 | |
d897cae4 |
554 | function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%") { |
94361e02 |
555 | global $CFG; |
556 | |
c408b0c4 |
557 | $modinfo = unserialize($course->modinfo); |
94361e02 |
558 | |
19a55d67 |
559 | echo "<TABLE WIDTH=\"$width\"><TR><TD>\n"; |
74666583 |
560 | if (!empty($section->sequence)) { |
94361e02 |
561 | |
562 | $sectionmods = explode(",", $section->sequence); |
563 | |
564 | foreach ($sectionmods as $modnumber) { |
9ae687af |
565 | if (empty($mods[$modnumber])) { |
566 | continue; |
567 | } |
94361e02 |
568 | $mod = $mods[$modnumber]; |
1acfbce5 |
569 | if ($mod->visible or isteacher($course->id)) { |
570 | $instancename = urldecode($modinfo[$modnumber]->name); |
571 | if ($mod->visible) { |
572 | $link_css = ""; |
573 | } else { |
574 | $link_css = " class=\"dimmed\" "; |
575 | } |
576 | echo "<IMG SRC=\"$CFG->wwwroot/mod/$mod->modname/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\">"; |
577 | echo " <FONT SIZE=2><A TITLE=\"$mod->modfullname\" $link_css"; |
578 | echo " HREF=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename</A></FONT>"; |
579 | } |
d897cae4 |
580 | if (isediting($course->id)) { |
5e367a2d |
581 | echo " "; |
1acfbce5 |
582 | echo make_editing_buttons($mod->id, $absolute, $mod->visible); |
583 | } |
584 | if ($mod->visible or isteacher($course->id)) { |
585 | echo "<BR>\n"; |
94361e02 |
586 | } |
94361e02 |
587 | } |
588 | } |
47ef8795 |
589 | echo "</TD></TR></TABLE><BR>\n\n"; |
a7ad3ea6 |
590 | } |
591 | |
7541bc3e |
592 | function print_heading_block($heading, $width="100%", $class="headingblock") { |
5e367a2d |
593 | global $THEME; |
594 | |
7541bc3e |
595 | echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">"; |
596 | echo "<tr><td bgcolor=\"$THEME->cellheading\" class=\"$class\">"; |
5e367a2d |
597 | echo stripslashes($heading); |
598 | echo "</td></tr></table>"; |
5e367a2d |
599 | } |
600 | |
601 | function print_side_block($heading="", $content="", $list=NULL, $icons=NULL, $footer="", $width=180) { |
602 | // Prints a nice side block with an optional header. The content can either |
603 | // be a block of HTML or a list of text with optional icons. |
a7ad3ea6 |
604 | |
5e367a2d |
605 | global $THEME; |
606 | |
7541bc3e |
607 | print_side_block_start($heading, $width); |
608 | |
5e367a2d |
609 | if ($content) { |
7541bc3e |
610 | echo "$content"; |
5e367a2d |
611 | } else { |
5e367a2d |
612 | echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">"; |
613 | foreach ($list as $key => $string) { |
7541bc3e |
614 | echo "<tr bgcolor=\"$THEME->cellcontent2\">"; |
5e367a2d |
615 | if ($icons) { |
7541bc3e |
616 | echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"16\">".$icons[$key]."</td>"; |
a7ad3ea6 |
617 | } |
7541bc3e |
618 | echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"*\"><font size=\"-1\">$string</font></td>"; |
5e367a2d |
619 | echo "</tr>"; |
a7ad3ea6 |
620 | } |
5e367a2d |
621 | if ($footer) { |
7541bc3e |
622 | echo "<tr bgcolor=\"$THEME->cellcontent2\">"; |
5e367a2d |
623 | if ($icons) { |
7541bc3e |
624 | echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"16\"> </td>"; |
5e367a2d |
625 | } |
7541bc3e |
626 | echo "<td class=\"sideblocklinks\"><font size=\"-1\">$footer</td>"; |
5e367a2d |
627 | echo "</tr>"; |
628 | } |
629 | echo "</table>"; |
a7ad3ea6 |
630 | } |
5e367a2d |
631 | |
7541bc3e |
632 | print_side_block_end(); |
633 | } |
634 | |
635 | function print_side_block_start($heading="", $width=180, $class="sideblockmain") { |
636 | // Starts a nice side block with an optional header. |
637 | |
638 | global $THEME; |
639 | |
640 | echo "<table class=\"sideblock\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">"; |
641 | if ($heading) { |
642 | echo "<tr>"; |
643 | echo "<td class=\"sideblockheading\" bgcolor=\"$THEME->cellheading\">$heading</td>"; |
644 | echo "</tr>"; |
645 | } |
646 | echo "<tr>"; |
647 | echo "<td class=\"$class\" bgcolor=\"$THEME->cellcontent2\">"; |
648 | } |
649 | |
650 | function print_side_block_end() { |
651 | echo "</td></tr>"; |
5e367a2d |
652 | echo "</table><br \>"; |
94361e02 |
653 | } |
654 | |
5e367a2d |
655 | |
670fddf1 |
656 | function print_admin_links ($siteid, $width=180) { |
dc0dc7d5 |
657 | global $CFG, $THEME; |
2b25f2a0 |
658 | |
dc0dc7d5 |
659 | if (empty($THEME->custompix)) { |
660 | $icon = "<img src=\"$CFG->wwwroot/pix/i/settings.gif\" height=16 width=16 alt=\"\">"; |
661 | } else { |
662 | $icon = "<img src=\"$CFG->wwwroot/theme/$CFG->theme/pix/i/settings.gif\" height=16 width=16 alt=\"\">"; |
663 | } |
664 | |
1924074c |
665 | if (isadmin()) { |
dae73c05 |
666 | $moddata[]="<A HREF=\"$CFG->wwwroot/$CFG->admin/config.php\">".get_string("configvariables")."</A>"; |
1924074c |
667 | $modicon[]=$icon; |
dae73c05 |
668 | $moddata[]="<A HREF=\"$CFG->wwwroot/$CFG->admin/site.php\">".get_string("sitesettings")."</A>"; |
1924074c |
669 | $modicon[]=$icon; |
670 | $moddata[]="<A HREF=\"$CFG->wwwroot/course/log.php?id=$siteid\">".get_string("sitelogs")."</A>"; |
671 | $modicon[]=$icon; |
672 | $moddata[]="<A HREF=\"$CFG->wwwroot/theme/index.php\">".get_string("choosetheme")."</A>"; |
673 | $modicon[]=$icon; |
dae73c05 |
674 | $moddata[]="<A HREF=\"$CFG->wwwroot/$CFG->admin/lang.php\">".get_string("checklanguage")."</A>"; |
1924074c |
675 | $modicon[]=$icon; |
be09831a |
676 | if (file_exists("$CFG->dirroot/$CFG->admin/$CFG->dbtype")) { |
dae73c05 |
677 | $moddata[]="<A HREF=\"$CFG->wwwroot/$CFG->admin/$CFG->dbtype/frame.php\">".get_string("managedatabase")."</A>"; |
1924074c |
678 | $modicon[]=$icon; |
679 | } |
680 | $moddata[]="<HR>"; |
681 | $modicon[]=""; |
682 | } |
683 | if (iscreator()) { |
684 | $moddata[]="<A HREF=\"$CFG->wwwroot/course/edit.php\">".get_string("addnewcourse")."</A>"; |
685 | $modicon[]=$icon; |
686 | $moddata[]="<A HREF=\"$CFG->wwwroot/course/teacher.php\">".get_string("assignteachers")."</A>"; |
687 | $modicon[]=$icon; |
5b337cdf |
688 | $fulladmin = ""; |
1924074c |
689 | } |
690 | if (isadmin()) { |
691 | $moddata[]="<A HREF=\"$CFG->wwwroot/course/categories.php\">".get_string("categories")."</A>"; |
692 | $modicon[]=$icon; |
693 | $moddata[]="<A HREF=\"$CFG->wwwroot/course/delete.php\">".get_string("deletecourse")."</A>"; |
694 | $modicon[]=$icon; |
695 | $moddata[]="<HR>"; |
696 | $modicon[]=""; |
3399a22c |
697 | if($CFG->auth == "email" || $CFG->auth == "none" || $CFG->auth == "manual"){ |
698 | $moddata[]="<A HREF=\"$CFG->wwwroot/$CFG->admin/user.php?newuser=true\">".get_string("addnewuser")."</A>"; |
699 | $modicon[]=$icon; |
700 | } |
dae73c05 |
701 | $moddata[]="<A HREF=\"$CFG->wwwroot/$CFG->admin/user.php\">".get_string("edituser")."</A>"; |
1924074c |
702 | $modicon[]=$icon; |
dae73c05 |
703 | $moddata[]="<A HREF=\"$CFG->wwwroot/$CFG->admin/admin.php\">".get_string("assignadmins")."</A>"; |
1924074c |
704 | $modicon[]=$icon; |
dae73c05 |
705 | $moddata[]="<A HREF=\"$CFG->wwwroot/$CFG->admin/creators.php\">".get_string("assigncreators")."</A>"; |
1924074c |
706 | $modicon[]=$icon; |
dae73c05 |
707 | $moddata[]="<A HREF=\"$CFG->wwwroot/$CFG->admin/auth.php\">".get_string("authentication")."</A>"; |
1924074c |
708 | $modicon[]=$icon; |
dae73c05 |
709 | $fulladmin = "<P><A HREF=\"$CFG->wwwroot/$CFG->admin/\">".get_string("admin")."</A>..."; |
1924074c |
710 | } |
5e367a2d |
711 | |
712 | print_side_block(get_string("administration"), "", $moddata, $modicon, $fulladmin, $width); |
713 | |
dc0dc7d5 |
714 | echo "<img src=\"$CFG->wwwroot/pix/spacer.gif\" width=\"$width\" height=1><br>"; |
2b25f2a0 |
715 | } |
716 | |
b4d7002e |
717 | function print_course_admin_links($course, $width=180) { |
dc0dc7d5 |
718 | global $USER, $CFG, $THEME; |
44dad735 |
719 | |
dc0dc7d5 |
720 | if (empty($THEME->custompix)) { |
721 | $pixpath = "$CFG->wwwroot/pix"; |
722 | $modpixpath = "$CFG->wwwroot/mod"; |
723 | } else { |
724 | $pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix"; |
725 | $modpixpath = "$CFG->wwwroot/theme/$CFG->theme/pix/mod"; |
726 | } |
13469b82 |
727 | if (isteacher($course->id)) { |
dc0dc7d5 |
728 | $adminicon[]="<img src=\"$pixpath/i/edit.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
729 | if (isediting($course->id)) { |
dc0dc7d5 |
730 | $admindata[]="<a href=\"view.php?id=$course->id&edit=off\">".get_string("turneditingoff")."</a>"; |
13469b82 |
731 | } else { |
dc0dc7d5 |
732 | $admindata[]="<a href=\"view.php?id=$course->id&edit=on\">".get_string("turneditingon")."</a>"; |
13469b82 |
733 | } |
dc0dc7d5 |
734 | $admindata[]="<a href=\"edit.php?id=$course->id\">".get_string("settings")."...</a>"; |
735 | $adminicon[]="<img src=\"$pixpath/i/settings.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
736 | if (!$course->teachers) { |
737 | $course->teachers = get_string("defaultcourseteachers"); |
738 | } |
dc0dc7d5 |
739 | $admindata[]="<a href=\"teachers.php?id=$course->id\">$course->teachers...</a>"; |
740 | $adminicon[]="<img src=\"$pixpath/i/settings.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
741 | |
dc0dc7d5 |
742 | $admindata[]="<a href=\"grades.php?id=$course->id\">".get_string("grades")."...</a>"; |
743 | $adminicon[]="<img src=\"$pixpath/i/grades.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
744 | |
dc0dc7d5 |
745 | $admindata[]="<a href=\"log.php?id=$course->id\">".get_string("logs")."...</a>"; |
746 | $adminicon[]="<img src=\"$pixpath/i/log.gif\" height=16 width=16 alt=\"\">"; |
747 | |
748 | $admindata[]="<a href=\"$CFG->wwwroot/files/index.php?id=$course->id\">".get_string("files")."...</a>"; |
749 | $adminicon[]="<img src=\"$pixpath/i/files.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
750 | |
dc0dc7d5 |
751 | $admindata[]="<a href=\"$CFG->wwwroot/doc/view.php?id=$course->id&file=teacher.html\">".get_string("help")."...</a>"; |
752 | $adminicon[]="<img src=\"$modpixpath/resource/icon.gif\" height=16 width=16 alt=\"\">"; |
b4d7002e |
753 | |
13469b82 |
754 | if ($teacherforum = forum_get_course_forum($course->id, "teacher")) { |
dc0dc7d5 |
755 | $admindata[]="<a href=\"$CFG->wwwroot/mod/forum/view.php?f=$teacherforum->id\">".get_string("nameteacher", "forum")."</a>"; |
756 | $adminicon[]="<img src=\"$modpixpath/forum/icon.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
757 | } |
758 | } else { |
dc0dc7d5 |
759 | $admindata[]="<a href=\"grade.php?id=$course->id\">".get_string("grades")."...</a>"; |
760 | $adminicon[]="<img src=\"$pixpath/i/grades.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
761 | } |
44dad735 |
762 | |
5e367a2d |
763 | print_side_block(get_string("administration"), "", $admindata, $adminicon, "", $width); |
44dad735 |
764 | } |
2b25f2a0 |
765 | |
ba2e5d73 |
766 | function print_course_categories($categories, $selected="none", $width=180) { |
0a263205 |
767 | global $CFG, $THEME, $USER; |
85098089 |
768 | |
769 | $strallowguests = get_string("allowguests"); |
770 | $strrequireskey = get_string("requireskey"); |
ba2e5d73 |
771 | |
dc0dc7d5 |
772 | if (empty($THEME->custompix)) { |
773 | $pixpath = "$CFG->wwwroot/pix"; |
774 | } else { |
775 | $pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix"; |
776 | } |
777 | |
0c656181 |
778 | if ($selected == "index") { // Print comprehensive index of categories with courses |
9fa49e22 |
779 | if ($courses = get_courses()) { |
0c656181 |
780 | if (isset($USER->id) and !isadmin()) { |
39246b72 |
781 | print_simple_box_start("CENTER", "100%", $THEME->cellheading); |
dc0dc7d5 |
782 | print_heading("<a href=\"course/index.php?category=my\">".get_string("mycourses")."</a>", "left"); |
0c656181 |
783 | $some = false; |
dc0dc7d5 |
784 | echo "<ul>"; |
0c656181 |
785 | foreach ($courses as $key => $course) { |
786 | if (isteacher($course->id) or isstudent($course->id)) { |
dc0dc7d5 |
787 | echo "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>"; |
788 | echo "<br />"; |
0c656181 |
789 | $some = true; |
790 | } |
791 | } |
792 | if (!$some) { |
793 | print_string("nocoursesyet"); |
794 | } |
dc0dc7d5 |
795 | echo "</ul>"; |
0c656181 |
796 | print_simple_box_end(); |
797 | print_spacer(8,1); |
798 | } |
799 | foreach ($categories as $category) { |
bd4707bf |
800 | print_simple_box_start("CENTER", "100%"); |
dc0dc7d5 |
801 | print_heading("<a href=\"course/index.php?category=$category->id\">$category->name</a>", "left"); |
0c656181 |
802 | $some = false; |
dc0dc7d5 |
803 | echo "<ul>"; |
0c656181 |
804 | foreach ($courses as $key => $course) { |
805 | if ($course->category == $category->id) { |
dc0dc7d5 |
806 | echo "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>"; |
85098089 |
807 | echo " "; |
0c656181 |
808 | unset($courses[$key]); |
85098089 |
809 | if ($course->guest ) { |
dc0dc7d5 |
810 | echo "<a title=\"$strallowguests\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">"; |
811 | echo "<img alt=\"\" height=16 width=16 border=0 src=\"$pixpath/i/user.gif\"></a>"; |
85098089 |
812 | } |
813 | if ($course->password) { |
dc0dc7d5 |
814 | echo "<a title=\"$strrequireskey\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">"; |
815 | echo "<img alt=\"\" height=16 width=16 border=0 src=\"$pixpath/i/key.gif\"></a>"; |
85098089 |
816 | } |
dc0dc7d5 |
817 | echo "<br />"; |
0c656181 |
818 | $some = true; |
819 | } |
820 | } |
821 | if (!$some) { |
822 | print_string("nocoursesyet"); |
823 | } |
dc0dc7d5 |
824 | echo "</ul>"; |
0c656181 |
825 | print_simple_box_end(); |
826 | print_spacer(8,1); |
827 | } |
ba2e5d73 |
828 | } |
0c656181 |
829 | |
830 | } else { // Print short list of categories only |
831 | foreach ($categories as $cat) { |
dc0dc7d5 |
832 | $caticon[]="<img src=\"$pixpath/i/course.gif\" height=16 width=16>"; |
0c656181 |
833 | if ($cat->id == $selected) { |
834 | $catdata[]="$cat->name"; |
835 | } else { |
dc0dc7d5 |
836 | $catdata[]="<a href=\"$CFG->wwwroot/course/index.php?category=$cat->id\">$cat->name</a>"; |
0c656181 |
837 | } |
838 | } |
dc0dc7d5 |
839 | $catdata[] = "<a href=\"$CFG->wwwroot/course/index.php?category=all\">".get_string("fulllistofcourses")."</a>"; |
13770d0c |
840 | $caticon[] = ""; |
0c656181 |
841 | if (isset($USER->id)) { |
dc0dc7d5 |
842 | $catdata[] = "<a href=\"$CFG->wwwroot/course/index.php?category=my\">".get_string("mycourses")."</a>"; |
13770d0c |
843 | $caticon[] = ""; |
0c656181 |
844 | } |
13770d0c |
845 | print_side_block(get_string("categories"), "", $catdata, $caticon, "", $width); |
ba2e5d73 |
846 | } |
ba2e5d73 |
847 | } |
94361e02 |
848 | |
2b8cef80 |
849 | function print_log_graph($course, $userid=0, $type="course.png", $date=0) { |
850 | global $CFG; |
607809b3 |
851 | if (empty($CFG->gdversion)) { |
852 | echo "(".get_string("gdneed").")"; |
853 | } else { |
854 | echo "<IMG BORDER=0 SRC=\"$CFG->wwwroot/course/loggraph.php?id=$course->id&user=$userid&type=$type&date=$date\">"; |
855 | } |
2b8cef80 |
856 | } |
857 | |
11b0c469 |
858 | |
859 | |
860 | /// MODULE FUNCTIONS ///////////////////////////////////////////////////////////////// |
861 | |
862 | function add_course_module($mod) { |
863 | GLOBAL $db; |
864 | |
e5dfd0f3 |
865 | $mod->added = time(); |
11b0c469 |
866 | |
e5dfd0f3 |
867 | return insert_record("course_modules", $mod); |
11b0c469 |
868 | } |
869 | |
870 | function add_mod_to_section($mod) { |
871 | // Returns the course_sections ID where the mod is inserted |
872 | GLOBAL $db; |
873 | |
9fa49e22 |
874 | if ($section = get_record("course_sections", "course", "$mod->course", "section", "$mod->section")) { |
74666583 |
875 | if (!empty($section->sequence)) { |
e5dfd0f3 |
876 | $newsequence = "$section->sequence,$mod->coursemodule"; |
11b0c469 |
877 | } else { |
878 | $newsequence = "$mod->coursemodule"; |
879 | } |
e5dfd0f3 |
880 | if (set_field("course_sections", "sequence", $newsequence, "id", $section->id)) { |
881 | return $section->id; // Return course_sections ID that was used. |
11b0c469 |
882 | } else { |
e5dfd0f3 |
883 | return 0; |
11b0c469 |
884 | } |
885 | |
886 | } else { // Insert a new record |
e5dfd0f3 |
887 | $section->course = $mod->course; |
888 | $section->section = $mod->section; |
889 | $section->summary = ""; |
890 | $section->sequence = $mod->coursemodule; |
891 | return insert_record("course_sections", $section); |
11b0c469 |
892 | } |
893 | } |
894 | |
1acfbce5 |
895 | function hide_course_module($mod) { |
896 | return set_field("course_modules", "visible", 0, "id", $mod); |
897 | } |
898 | |
899 | function show_course_module($mod) { |
900 | return set_field("course_modules", "visible", 1, "id", $mod); |
901 | } |
902 | |
11b0c469 |
903 | function delete_course_module($mod) { |
904 | return set_field("course_modules", "deleted", 1, "id", $mod); |
905 | } |
906 | |
907 | function delete_mod_from_section($mod, $section) { |
908 | GLOBAL $db; |
909 | |
e5dfd0f3 |
910 | if ($section = get_record("course_sections", "id", "$section") ) { |
11b0c469 |
911 | |
e5dfd0f3 |
912 | $modarray = explode(",", $section->sequence); |
11b0c469 |
913 | |
914 | if ($key = array_keys ($modarray, $mod)) { |
915 | array_splice($modarray, $key[0], 1); |
916 | $newsequence = implode(",", $modarray); |
e5dfd0f3 |
917 | return set_field("course_sections", "sequence", $newsequence, "id", $section->id); |
11b0c469 |
918 | } else { |
919 | return false; |
920 | } |
921 | |
922 | } else { |
923 | return false; |
924 | } |
925 | } |
926 | |
927 | |
7c0f2984 |
928 | function move_module($cm, $move) { |
11b0c469 |
929 | GLOBAL $db; |
930 | |
931 | if (!$move) { |
932 | return true; |
933 | } |
934 | |
11b0c469 |
935 | if (! $thissection = get_record("course_sections", "id", $cm->section)) { |
936 | error("This course section doesn't exist"); |
937 | } |
938 | |
939 | $mods = explode(",", $thissection->sequence); |
940 | |
941 | $len = count($mods); |
942 | $pos = array_keys($mods, $cm->id); |
943 | $thepos = $pos[0]; |
944 | |
945 | if ($len == 0 || count($pos) == 0 ) { |
946 | error("Very strange. Could not find the required module in this section."); |
947 | } |
948 | |
949 | if ($len == 1) { |
950 | $first = true; |
951 | $last = true; |
952 | } else { |
953 | $first = ($thepos == 0); |
954 | $last = ($thepos == $len - 1); |
955 | } |
956 | |
957 | if ($move < 0) { // Moving the module up |
958 | |
959 | if ($first) { |
960 | if ($thissection->section == 1) { // First section, do nothing |
961 | return true; |
962 | } else { // Push onto end of previous section |
963 | $prevsectionnumber = $thissection->section - 1; |
9fa49e22 |
964 | if (! $prevsection = get_record("course_sections", "course", "$thissection->course", |
965 | "section", "$prevsectionnumber")) { |
11b0c469 |
966 | error("Previous section ($prevsection->id) doesn't exist"); |
967 | } |
968 | |
74666583 |
969 | if (!empty($prevsection->sequence)) { |
11b0c469 |
970 | $newsequence = "$prevsection->sequence,$cm->id"; |
971 | } else { |
972 | $newsequence = "$cm->id"; |
973 | } |
974 | |
975 | if (! set_field("course_sections", "sequence", $newsequence, "id", $prevsection->id)) { |
976 | error("Previous section could not be updated"); |
977 | } |
978 | |
979 | if (! set_field("course_modules", "section", $prevsection->id, "id", $cm->id)) { |
980 | error("Module could not be updated"); |
981 | } |
982 | |
983 | array_splice($mods, 0, 1); |
984 | $newsequence = implode(",", $mods); |
985 | if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) { |
986 | error("Module could not be updated"); |
987 | } |
988 | |
989 | return true; |
990 | |
991 | } |
992 | } else { // move up within this section |
993 | $swap = $mods[$thepos-1]; |
994 | $mods[$thepos-1] = $mods[$thepos]; |
995 | $mods[$thepos] = $swap; |
996 | |
997 | $newsequence = implode(",", $mods); |
998 | if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) { |
999 | error("This section could not be updated"); |
1000 | } |
1001 | return true; |
1002 | } |
1003 | |
1004 | } else { // Moving the module down |
1005 | |
1006 | if ($last) { |
1007 | $nextsectionnumber = $thissection->section + 1; |
9fa49e22 |
1008 | if ($nextsection = get_record("course_sections", "course", "$thissection->course", |
1009 | "section", "$nextsectionnumber")) { |
11b0c469 |
1010 | |
74666583 |
1011 | if (!empty($nextsection->sequence)) { |
11b0c469 |
1012 | $newsequence = "$cm->id,$nextsection->sequence"; |
1013 | } else { |
1014 | $newsequence = "$cm->id"; |
1015 | } |
1016 | |
1017 | if (! set_field("course_sections", "sequence", $newsequence, "id", $nextsection->id)) { |
1018 | error("Next section could not be updated"); |
1019 | } |
1020 | |
1021 | if (! set_field("course_modules", "section", $nextsection->id, "id", $cm->id)) { |
1022 | error("Module could not be updated"); |
1023 | } |
1024 | |
1025 | array_splice($mods, $thepos, 1); |
1026 | $newsequence = implode(",", $mods); |
1027 | if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) { |
1028 | error("This section could not be updated"); |
1029 | } |
1030 | return true; |
1031 | |
1032 | } else { // There is no next section, so just return |
1033 | return true; |
1034 | |
1035 | } |
1036 | } else { // move down within this section |
1037 | $swap = $mods[$thepos+1]; |
1038 | $mods[$thepos+1] = $mods[$thepos]; |
1039 | $mods[$thepos] = $swap; |
1040 | |
1041 | $newsequence = implode(",", $mods); |
1042 | if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) { |
1043 | error("This section could not be updated"); |
1044 | } |
1045 | return true; |
1046 | } |
1047 | } |
1048 | } |
1049 | |
1acfbce5 |
1050 | function make_editing_buttons($moduleid, $absolute=false, $visible=true, $str=NULL) { |
dc0dc7d5 |
1051 | global $CFG, $THEME; |
94361e02 |
1052 | |
1acfbce5 |
1053 | if (empty($str)) { |
1054 | $str->delete = get_string("delete"); |
1055 | $str->moveup = get_string("moveup"); |
1056 | $str->movedown = get_string("movedown"); |
1057 | $str->update = get_string("update"); |
1058 | $str->hide = get_string("hide"); |
1059 | $str->show = get_string("show"); |
1060 | } |
94361e02 |
1061 | |
1062 | if ($absolute) { |
dc0dc7d5 |
1063 | $path = "$CFG->wwwroot/course"; |
1064 | } else { |
1065 | $path = "."; |
1066 | } |
1067 | |
1068 | if (empty($THEME->custompix)) { |
1069 | $pixpath = "$path/../pix"; |
94361e02 |
1070 | } else { |
dc0dc7d5 |
1071 | $pixpath = "$path/../theme/$CFG->theme/pix"; |
94361e02 |
1072 | } |
1acfbce5 |
1073 | |
1074 | if ($visible) { |
dc0dc7d5 |
1075 | $hideshow = " <a title=\"$str->hide\" href=\"$path/mod.php?hide=$moduleid\"><img |
1076 | src=\"$pixpath/t/hide.gif\" height=11 width=11 border=0></a>"; |
1acfbce5 |
1077 | } else { |
dc0dc7d5 |
1078 | $hideshow = " <a title=\"$str->show\" href=\"$path/mod.php?show=$moduleid\"><img |
1079 | src=\"$pixpath/t/show.gif\" height=11 width=11 border=0></a>"; |
1acfbce5 |
1080 | } |
1081 | |
dc0dc7d5 |
1082 | return "<a title=\"$str->delete\" href=\"$path/mod.php?delete=$moduleid\"><img |
1083 | src=\"$pixpath/t/delete.gif\" height=11 width=11 border=0></a> |
1084 | <a title=\"$str->moveup\" href=\"$path/mod.php?id=$moduleid&move=-1\"><img |
1085 | src=\"$pixpath/t/up.gif\" height=11 width=11 border=0></a> |
1086 | <a title=\"$str->movedown\" href=\"$path/mod.php?id=$moduleid&move=1\"><img |
1087 | src=\"$pixpath/t/down.gif\" height=11 width=11 border=0></a> |
1088 | <a title=\"$str->update\" href=\"$path/mod.php?update=$moduleid\"><img |
1089 | src=\"$pixpath/t/edit.gif\" height=11 width=11 border=0></a> $hideshow"; |
90845098 |
1090 | } |
1091 | |
f9903ed0 |
1092 | ?> |