e4027ac9 |
1 | <?php // $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 | |
cb29b020 |
15 | define('COURSE_MAX_RECENT_PERIOD', 604800); // A week, in seconds |
16 | |
17 | define('COURSE_MAX_SUMMARIES_PER_PAGE', 10); // courses |
ef58b822 |
18 | |
c2cb4545 |
19 | define("FRONTPAGENEWS", 0); |
20 | define("FRONTPAGECOURSELIST", 1); |
21 | define("FRONTPAGECATEGORYNAMES", 2); |
f9903ed0 |
22 | |
9ae687af |
23 | |
f24cffb9 |
24 | function print_log_selector_form($course, $selecteduser=0, $selecteddate="today", |
25 | $mod="", $modpage="", $modid=0) { |
f9903ed0 |
26 | |
9481285b |
27 | global $USER, $CFG; |
28 | |
2ac64806 |
29 | |
30 | $isteacher = isteacher($course->id); |
f9903ed0 |
31 | // Get all the possible users |
32 | $users = array(); |
720a43ce |
33 | |
34 | if ($course->category) { |
4d744a22 |
35 | $courseusers = get_course_users($course->id); |
1a5ab449 |
36 | } else { |
37 | $courseusers = get_site_users("u.lastaccess DESC", "u.id, u.firstname, u.lastname"); |
38 | } |
39 | |
40 | if ($courseusers) { |
41 | foreach ($courseusers as $courseuser) { |
2ac64806 |
42 | $users[$courseuser->id] = fullname($courseuser, $isteacher); |
122cffc9 |
43 | } |
f9903ed0 |
44 | } |
1a5ab449 |
45 | if ($guest = get_guest()) { |
f5104a2b |
46 | $users[$guest->id] = fullname($guest); |
1a5ab449 |
47 | } |
720a43ce |
48 | |
49 | if (isadmin()) { |
9fa49e22 |
50 | if ($ccc = get_records("course", "", "", "fullname")) { |
720a43ce |
51 | foreach ($ccc as $cc) { |
cfa5d3f2 |
52 | if ($cc->category) { |
53 | $courses["$cc->id"] = "$cc->fullname"; |
54 | } else { |
55 | $courses["$cc->id"] = " $cc->fullname (Site)"; |
56 | } |
720a43ce |
57 | } |
f9903ed0 |
58 | } |
cfa5d3f2 |
59 | asort($courses); |
f9903ed0 |
60 | } |
61 | |
f24cffb9 |
62 | $activities = array(); |
63 | $selectedactivity = ""; |
64 | |
65 | if ($modinfo = unserialize($course->modinfo)) { |
66 | $section = 0; |
67 | if ($course->format == 'weeks') { // Bodgy |
68 | $strsection = get_string("week"); |
69 | } else { |
70 | $strsection = get_string("topic"); |
71 | } |
72 | foreach ($modinfo as $mod) { |
73 | if ($mod->mod == "label") { |
74 | continue; |
75 | } |
76 | if ($mod->section > 0 and $section <> $mod->section) { |
77 | $activities["section/$mod->section"] = "-------------- $strsection $mod->section --------------"; |
78 | } |
79 | $section = $mod->section; |
80 | $mod->name = urldecode($mod->name); |
81 | if (strlen($mod->name) > 55) { |
82 | $mod->name = substr($mod->name, 0, 50)."..."; |
83 | } |
84 | if (!$mod->visible) { |
85 | $mod->name = "(".$mod->name.")"; |
86 | } |
87 | $activities["$mod->mod/view.php?id=$mod->cm"] = $mod->name; |
88 | |
89 | if ($mod->cm == $modid) { |
90 | $selectedactivity = "$mod->mod/view.php?id=$mod->cm"; |
91 | } |
92 | } |
93 | } |
dcde9f02 |
94 | |
95 | $strftimedate = get_string("strftimedate"); |
96 | $strftimedaydate = get_string("strftimedaydate"); |
97 | |
f9903ed0 |
98 | asort($users); |
99 | |
100 | // Get all the possible dates |
9481285b |
101 | // Note that we are keeping track of real (GMT) time and user time |
102 | // User time is only used in displays - all calcs and passing is GMT |
103 | |
104 | $timenow = time(); // GMT |
105 | |
106 | // What day is it now for the user, and when is midnight that day (in GMT). |
9604ccb1 |
107 | $timemidnight = $today = usergetmidnight($timenow); |
9481285b |
108 | |
109 | // Put today up the top of the list |
dcde9f02 |
110 | $dates = array("$timemidnight" => get_string("today").", ".userdate($timenow, $strftimedate) ); |
9481285b |
111 | |
3695f5b4 |
112 | if (!$course->startdate or ($course->startdate > $timenow)) { |
9481285b |
113 | $course->startdate = $course->timecreated; |
114 | } |
f9903ed0 |
115 | |
9481285b |
116 | $numdates = 1; |
117 | while ($timemidnight > $course->startdate and $numdates < 365) { |
f9903ed0 |
118 | $timemidnight = $timemidnight - 86400; |
9481285b |
119 | $timenow = $timenow - 86400; |
dcde9f02 |
120 | $dates["$timemidnight"] = userdate($timenow, $strftimedaydate); |
9481285b |
121 | $numdates++; |
f9903ed0 |
122 | } |
123 | |
124 | if ($selecteddate == "today") { |
125 | $selecteddate = $today; |
126 | } |
127 | |
f24cffb9 |
128 | echo '<center>'; |
129 | echo '<form action="log.php" method="get">'; |
130 | echo '<input type=hidden name=chooselog value="1">'; |
720a43ce |
131 | if (isadmin()) { |
849bc02a |
132 | choose_from_menu ($courses, "id", $course->id, ""); |
720a43ce |
133 | } else { |
f24cffb9 |
134 | echo "<input type=hidden name=id value=\"$course->id\">"; |
720a43ce |
135 | } |
1a5ab449 |
136 | choose_from_menu ($users, "user", $selecteduser, get_string("allparticipants") ); |
97c270e9 |
137 | choose_from_menu ($dates, "date", $selecteddate, get_string("alldays")); |
f24cffb9 |
138 | choose_from_menu ($activities, "url", $selectedactivity, get_string("allactivities"), "", ""); |
139 | echo "<input type=submit value=\"".get_string("showtheselogs")."\">"; |
140 | echo "</form>"; |
141 | echo "</center>"; |
f9903ed0 |
142 | } |
143 | |
600149be |
144 | function make_log_url($module, $url) { |
145 | switch ($module) { |
146 | case "course": |
147 | case "user": |
148 | case "file": |
149 | case "login": |
150 | case "lib": |
151 | case "admin": |
152 | return "/$module/$url"; |
153 | break; |
154 | default: |
155 | return "/mod/$module/$url"; |
156 | break; |
157 | } |
158 | } |
159 | |
160 | |
f24cffb9 |
161 | function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $perpage=100, |
162 | $url="", $mod="", $modpage="", $modid=0) { |
163 | |
9481285b |
164 | // It is assumed that $date is the GMT time of midnight for that day, |
165 | // and so the next 86400 seconds worth of logs are printed. |
f9903ed0 |
166 | |
f24cffb9 |
167 | global $CFG, $db; |
47f1da80 |
168 | |
720a43ce |
169 | if ($course->category) { |
519d369f |
170 | $selector = "l.course='$course->id' AND l.userid = u.id"; |
a2ab3b05 |
171 | |
720a43ce |
172 | } else { |
519d369f |
173 | $selector = "l.userid = u.id"; // Show all courses |
1a5ab449 |
174 | if ($ccc = get_courses("all", "c.id ASC", "c.id,c.shortname")) { |
720a43ce |
175 | foreach ($ccc as $cc) { |
176 | $courses[$cc->id] = "$cc->shortname"; |
177 | } |
178 | } |
179 | } |
f9903ed0 |
180 | |
f24cffb9 |
181 | if ($mod) { |
182 | $selector .= " AND l.module = '$mod'"; |
183 | } |
184 | |
185 | if ($modpage and $modid) { |
bb95c08b |
186 | $LIKE = $CFG->dbtype == "mysql" ? "LIKE" : "ILIKE"; |
187 | $selector .= " AND l.url $LIKE '$modpage.php?id=$modid%'"; |
f24cffb9 |
188 | } |
189 | |
f9903ed0 |
190 | if ($user) { |
ebc3bd2b |
191 | $selector .= " AND l.userid = '$user'"; |
f9903ed0 |
192 | } |
193 | |
194 | if ($date) { |
195 | $enddate = $date + 86400; |
196 | $selector .= " AND l.time > '$date' AND l.time < '$enddate'"; |
197 | } |
198 | |
f24cffb9 |
199 | |
d09f3c80 |
200 | $totalcount = 0; // Initialise |
201 | |
519d369f |
202 | if (!$logs = get_logs($selector, $order, $page*$perpage, $perpage, $totalcount)) { |
f9903ed0 |
203 | notify("No logs found!"); |
204 | print_footer($course); |
205 | exit; |
206 | } |
207 | |
208 | $count=0; |
209 | $tt = getdate(time()); |
210 | $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]); |
1c0200e0 |
211 | |
dcde9f02 |
212 | $strftimedatetime = get_string("strftimedatetime"); |
2ac64806 |
213 | $isteacher = isteacher($course->id); |
dcde9f02 |
214 | |
f9d5fd3b |
215 | echo "<p align=center>"; |
519d369f |
216 | print_string("displayingrecords", "", $totalcount); |
f9d5fd3b |
217 | echo "</p>"; |
1c0200e0 |
218 | |
519d369f |
219 | print_paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage&"); |
220 | |
f9d5fd3b |
221 | echo "<table border=0 align=center cellpadding=3 cellspacing=3>"; |
f9903ed0 |
222 | foreach ($logs as $log) { |
600149be |
223 | |
9fa49e22 |
224 | if ($ld = get_record("log_display", "module", "$log->module", "action", "$log->action")) { |
565f7a95 |
225 | $log->info = get_field($ld->mtable, $ld->field, "id", $log->info); |
600149be |
226 | } |
227 | |
f9d5fd3b |
228 | echo "<tr nowrap>"; |
720a43ce |
229 | if (! $course->category) { |
f9d5fd3b |
230 | echo "<td nowrap><font size=2><a href=\"view.php?id=$log->course\">".$courses[$log->course]."</a></td>"; |
720a43ce |
231 | } |
f9d5fd3b |
232 | echo "<td nowrap align=right><font size=2>".userdate($log->time, "%a")."</td>"; |
233 | echo "<td nowrap><font size=2>".userdate($log->time, $strftimedatetime)."</td>"; |
dc0dc7d5 |
234 | echo "<td nowrap><font size=2>"; |
47f1da80 |
235 | link_to_popup_window("/lib/ipatlas/plot.php?address=$log->ip&user=$log->userid", "ipatlas","$log->ip", 400, 700); |
f9d5fd3b |
236 | echo "</td>"; |
2ac64806 |
237 | $fullname = fullname($log, $isteacher); |
238 | echo "<td nowrap><font size=2><a href=\"../user/view.php?id=$log->userid&course=$log->course\"><b>$fullname</b></td>"; |
f9d5fd3b |
239 | echo "<td nowrap><font size=2>"; |
600149be |
240 | link_to_popup_window( make_log_url($log->module,$log->url), "fromloglive","$log->module $log->action", 400, 600); |
f9d5fd3b |
241 | echo "</td>"; |
242 | echo "<td nowrap><font size=2>$log->info</td>"; |
243 | echo "</tr>"; |
f9903ed0 |
244 | } |
f9d5fd3b |
245 | echo "</table>"; |
519d369f |
246 | |
247 | print_paging_bar($totalcount, $page, $perpage, "$url&perpage=$perpage&"); |
f9903ed0 |
248 | } |
249 | |
250 | |
c2cb4545 |
251 | function print_log_graph($course, $userid=0, $type="course.png", $date=0) { |
252 | global $CFG; |
253 | if (empty($CFG->gdversion)) { |
254 | echo "(".get_string("gdneed").")"; |
d887b5a7 |
255 | } else { |
c2cb4545 |
256 | echo "<IMG BORDER=0 SRC=\"$CFG->wwwroot/course/loggraph.php?id=$course->id&user=$userid&type=$type&date=$date\">"; |
d887b5a7 |
257 | } |
258 | } |
259 | |
260 | |
f9903ed0 |
261 | |
600149be |
262 | function print_recent_activity($course) { |
263 | // $course is an object |
264 | // This function trawls through the logs looking for |
265 | // anything new since the user's last login |
266 | |
bf40f9c1 |
267 | global $CFG, $USER, $THEME, $SESSION; |
600149be |
268 | |
2ac64806 |
269 | $isteacher = isteacher($course->id); |
270 | |
600149be |
271 | if (! $USER->lastlogin ) { |
3d891989 |
272 | echo "<p align=center><font size=1>"; |
4b1371a7 |
273 | print_string("welcometocourse", "", $course->shortname); |
3d891989 |
274 | echo "</font></p>"; |
600149be |
275 | return; |
4c654ee3 |
276 | } else { |
3d891989 |
277 | echo "<p align=center><font size=1>"; |
4c654ee3 |
278 | echo get_string("yourlastlogin").":<BR>"; |
dcde9f02 |
279 | echo userdate($USER->lastlogin, get_string("strftimerecentfull")); |
3d891989 |
280 | echo "</font></p>"; |
281 | } |
282 | |
283 | $timestart = $USER->lastlogin; |
b1992e65 |
284 | $timemaxrecent = time() - COURSE_MAX_RECENT_PERIOD; |
285 | if ($timestart < $timemaxrecent) { |
286 | $timestart = $timemaxrecent; |
600149be |
287 | } |
288 | |
600149be |
289 | |
290 | // Firstly, have there been any new enrolments? |
291 | |
292 | $heading = false; |
293 | $content = false; |
1b5910c4 |
294 | |
6c38b7e0 |
295 | $users = get_recent_enrolments($course->id, $timestart); |
1b5910c4 |
296 | |
6c38b7e0 |
297 | if ($users) { |
e2b7251d |
298 | echo "<p>"; |
6c38b7e0 |
299 | foreach ($users as $user) { |
600149be |
300 | if (! $heading) { |
4c654ee3 |
301 | print_headline(get_string("newusers").":"); |
600149be |
302 | $heading = true; |
303 | $content = true; |
304 | } |
2ac64806 |
305 | $fullname = fullname($user, $isteacher); |
306 | echo "<font size=1><a href=\"../user/view.php?id=$user->id&course=$course->id\">$fullname</a></font><br />"; |
600149be |
307 | } |
e2b7251d |
308 | echo "</p>"; |
600149be |
309 | } |
310 | |
1b5910c4 |
311 | // Next, have there been any modifications to the course structure? |
312 | |
313 | $logs = get_records_select("log", "time > '$timestart' AND course = '$course->id' AND |
314 | module = 'course' AND action LIKE '% mod'", "time ASC"); |
315 | |
316 | if ($logs) { |
317 | foreach ($logs as $key => $log) { |
318 | $info = split(" ", $log->info); |
c9f6251e |
319 | |
320 | if ($info[0] == "label") { // Labels are special activities |
321 | continue; |
322 | } |
323 | |
1b5910c4 |
324 | $modname = get_field($info[0], "name", "id", $info[1]); |
325 | //Create a temp valid module structure (course,id) |
326 | $tempmod->course = $log->course; |
327 | $tempmod->id = $info[1]; |
328 | //Obtain the visible property from the instance |
329 | $modvisible = instance_is_visible($info[0],$tempmod); |
330 | |
331 | //Only if the mod is visible |
332 | if ($modvisible) { |
333 | switch ($log->action) { |
334 | case "add mod": |
335 | $stradded = get_string("added", "moodle", get_string("modulename", $info[0])); |
336 | $changelist["$log->info"] = array ("operation" => "add", "text" => "$stradded:<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>"); |
337 | break; |
338 | case "update mod": |
339 | $strupdated = get_string("updated", "moodle", get_string("modulename", $info[0])); |
340 | if (empty($changelist["$log->info"])) { |
341 | $changelist["$log->info"] = array ("operation" => "update", "text" => "$strupdated:<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>"); |
342 | } |
343 | break; |
344 | case "delete mod": |
345 | if (!empty($changelist["$log->info"]["operation"]) and |
346 | $changelist["$log->info"]["operation"] == "add") { |
347 | $changelist["$log->info"] = NULL; |
348 | } else { |
349 | $strdeleted = get_string("deletedactivity", "moodle", get_string("modulename", $info[0])); |
350 | $changelist["$log->info"] = array ("operation" => "delete", "text" => $strdeleted); |
351 | } |
352 | break; |
600149be |
353 | } |
ef25340c |
354 | } |
355 | } |
356 | } |
357 | |
9c9f7d77 |
358 | if (!empty($changelist)) { |
ef25340c |
359 | foreach ($changelist as $changeinfo => $change) { |
360 | if ($change) { |
361 | $changes[$changeinfo] = $change; |
362 | } |
363 | } |
8a59942e |
364 | if (isset($changes)){ |
365 | if (count($changes) > 0) { |
366 | print_headline(get_string("courseupdates").":"); |
367 | $content = true; |
368 | foreach ($changes as $changeinfo => $change) { |
369 | echo "<p><font size=1>".$change["text"]."</font></p>"; |
370 | } |
600149be |
371 | } |
372 | } |
bf40f9c1 |
373 | } |
374 | |
375 | |
376 | // If this site uses Library module, then print recent items |
377 | if (!empty($CFG->librarypath)) { |
378 | if (file_exists("$CFG->dirroot/$CFG->librarypath/librarylib.php")) { |
379 | include_once("$CFG->dirroot/$CFG->librarypath/librarylib.php"); |
380 | if (librarysummarize(5, '', date('YmdHis',$USER->lastlogin))) { |
381 | $content = true; |
382 | } |
383 | } |
600149be |
384 | } |
385 | |
3869a2ac |
386 | // Now display new things from each module |
600149be |
387 | |
0fd7da81 |
388 | $mods = get_records("modules", "visible", "1", "name", "id, name"); |
389 | |
1b5910c4 |
390 | foreach ($mods as $mod) { // Each module gets it's own logs and prints them |
0fd7da81 |
391 | include_once("$CFG->dirroot/mod/$mod->name/lib.php"); |
392 | $print_recent_activity = $mod->name."_print_recent_activity"; |
1b5910c4 |
393 | if (function_exists($print_recent_activity)) { |
394 | $modcontent = $print_recent_activity($course, $isteacher, $timestart); |
3869a2ac |
395 | if ($modcontent) { |
396 | $content = true; |
600149be |
397 | } |
600149be |
398 | } |
399 | } |
400 | |
401 | if (! $content) { |
3d891989 |
402 | echo "<font size=2>".get_string("nothingnew")."</font>"; |
600149be |
403 | } |
600149be |
404 | } |
405 | |
e1360728 |
406 | |
d897cae4 |
407 | function get_array_of_activities($courseid) { |
408 | // For a given course, returns an array of course activity objects |
409 | // Each item in the array contains he following properties: |
410 | // cm - course module id |
411 | // mod - name of the module (eg forum) |
412 | // section - the number of the section (eg week or topic) |
413 | // name - the name of the instance |
5867bfb5 |
414 | // visible - is the instance visible or not |
86aa7ccf |
415 | // extra - contains extra string to include in any link |
d897cae4 |
416 | |
8dddba42 |
417 | global $CFG; |
418 | |
d897cae4 |
419 | $mod = array(); |
420 | |
9fa49e22 |
421 | if (!$rawmods = get_course_mods($courseid)) { |
d897cae4 |
422 | return NULL; |
423 | } |
424 | |
425 | if ($sections = get_records("course_sections", "course", $courseid, "section ASC")) { |
426 | foreach ($sections as $section) { |
74666583 |
427 | if (!empty($section->sequence)) { |
d897cae4 |
428 | $sequence = explode(",", $section->sequence); |
429 | foreach ($sequence as $seq) { |
7af6281f |
430 | if (empty($rawmods[$seq])) { |
431 | continue; |
432 | } |
d897cae4 |
433 | $mod[$seq]->cm = $rawmods[$seq]->id; |
434 | $mod[$seq]->mod = $rawmods[$seq]->modname; |
435 | $mod[$seq]->section = $section->section; |
436 | $mod[$seq]->name = urlencode(get_field($rawmods[$seq]->modname, "name", "id", $rawmods[$seq]->instance)); |
fec5a6a6 |
437 | $mod[$seq]->visible = $rawmods[$seq]->visible; |
86aa7ccf |
438 | $mod[$seq]->extra = ""; |
8dddba42 |
439 | |
440 | $modname = $mod[$seq]->mod; |
441 | $functionname = $modname."_get_coursemodule_info"; |
442 | |
443 | include_once("$CFG->dirroot/mod/$modname/lib.php"); |
444 | |
445 | if (function_exists($functionname)) { |
446 | if ($extra = $functionname($rawmods[$seq])) { |
447 | $mod[$seq]->extra = $extra; |
c9f6251e |
448 | } |
449 | } |
d897cae4 |
450 | } |
451 | } |
452 | } |
453 | } |
454 | return $mod; |
455 | } |
456 | |
457 | |
458 | |
e1360728 |
459 | |
90845098 |
460 | function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) { |
461 | // Returns a number of useful structures for course displays |
7468bf01 |
462 | |
90845098 |
463 | $mods = NULL; // course modules indexed by id |
464 | $modnames = NULL; // all course module names |
94361e02 |
465 | $modnamesplural= NULL; // all course module names (plural form) |
90845098 |
466 | $modnamesused = NULL; // course module names used |
7468bf01 |
467 | |
9fa49e22 |
468 | if ($allmods = get_records("modules")) { |
90845098 |
469 | foreach ($allmods as $mod) { |
5867bfb5 |
470 | if ($mod->visible) { |
471 | $modnames[$mod->name] = get_string("modulename", "$mod->name"); |
472 | $modnamesplural[$mod->name] = get_string("modulenameplural", "$mod->name"); |
473 | } |
90845098 |
474 | } |
475 | asort($modnames); |
476 | } else { |
477 | error("No modules are installed!"); |
478 | } |
479 | |
9fa49e22 |
480 | if ($rawmods = get_course_mods($courseid)) { |
7468bf01 |
481 | foreach($rawmods as $mod) { // Index the mods |
482 | $mods[$mod->id] = $mod; |
90845098 |
483 | $mods[$mod->id]->modfullname = $modnames[$mod->modname]; |
1acfbce5 |
484 | if ($mod->visible or isteacher($courseid)) { |
485 | $modnamesused[$mod->modname] = $modnames[$mod->modname]; |
486 | } |
7468bf01 |
487 | } |
c7da6f7a |
488 | if ($modnamesused) { |
489 | asort($modnamesused); |
490 | } |
7468bf01 |
491 | } |
7468bf01 |
492 | } |
493 | |
9fa49e22 |
494 | |
7468bf01 |
495 | function get_all_sections($courseid) { |
496 | |
d26d7ed0 |
497 | return get_records("course_sections", "course", "$courseid", "section", |
7d99d695 |
498 | "section, id, course, summary, sequence, visible"); |
7468bf01 |
499 | } |
500 | |
b86fc0e2 |
501 | function course_set_display($courseid, $display=0) { |
502 | global $USER; |
503 | |
504 | if (empty($USER)) { |
505 | return false; |
506 | } |
507 | |
508 | if ($display == "all" or empty($display)) { |
509 | $display = 0; |
510 | } |
511 | |
512 | if (record_exists("course_display", "userid", $USER->id, "course", $courseid)) { |
513 | set_field("course_display", "display", $display, "userid", $USER->id, "course", $courseid); |
514 | } else { |
515 | $record->userid = $USER->id; |
516 | $record->course = $courseid; |
517 | $record->display = $display; |
518 | if (!insert_record("course_display", $record)) { |
519 | notify("Could not save your course display!"); |
520 | } |
521 | } |
522 | |
523 | return $USER->display[$courseid] = $display; // Note: = not == |
524 | } |
525 | |
7d99d695 |
526 | function set_section_visible($courseid, $sectionnumber, $visibility) { |
527 | /// For a given course section, markes it visible or hidden, |
528 | /// and does the same for every activity in that section |
529 | |
530 | if ($section = get_record("course_sections", "course", $courseid, "section", $sectionnumber)) { |
531 | set_field("course_sections", "visible", "$visibility", "id", $section->id); |
532 | if (!empty($section->sequence)) { |
533 | $modules = explode(",", $section->sequence); |
534 | foreach ($modules as $moduleid) { |
535 | set_field("course_modules", "visible", "$visibility", "id", $moduleid); |
536 | } |
537 | } |
5867bfb5 |
538 | rebuild_course_cache($courseid); |
7d99d695 |
539 | } |
540 | } |
ba2e5d73 |
541 | |
5e367a2d |
542 | function print_section_block($heading, $course, $section, $mods, $modnames, $modnamesused, |
52dcc2f9 |
543 | $absolute=true, $width="100%") { |
5e367a2d |
544 | |
2c8cb30c |
545 | global $CFG, $USER, $THEME; |
52dcc2f9 |
546 | static $isteacher; |
547 | static $isediting; |
2c8cb30c |
548 | static $ismoving; |
549 | static $strmovehere; |
550 | static $strmovefull; |
52dcc2f9 |
551 | |
552 | if (!isset($isteacher)) { |
553 | $isteacher = isteacher($course->id); |
554 | } |
555 | if (!isset($isediting)) { |
556 | $isediting = isediting($course->id); |
557 | } |
2c8cb30c |
558 | if (!isset($ismoving)) { |
559 | $ismoving = ismoving($course->id); |
560 | } |
5e367a2d |
561 | |
562 | $modinfo = unserialize($course->modinfo); |
563 | $moddata = array(); |
564 | $modicon = array(); |
565 | $editbuttons = ""; |
566 | |
74666583 |
567 | if (!empty($section->sequence)) { |
5e367a2d |
568 | |
569 | $sectionmods = explode(",", $section->sequence); |
570 | |
2c8cb30c |
571 | if ($ismoving) { |
572 | $strmovehere = get_string("movehere"); |
f36b1996 |
573 | $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'")); |
2c8cb30c |
574 | $stractivityclipboard = $USER->activitycopyname; |
575 | $strcancel= get_string("cancel"); |
c9f6251e |
576 | $modicon[] = " <img align=bottom src=\"$CFG->pixpath/t/move.gif\" height=\"11\" width=\"11\">"; |
2c8cb30c |
577 | $moddata[] = "$USER->activitycopyname (<a href=\"$CFG->wwwroot/course/mod.php?cancelcopy=true\">$strcancel</a>)"; |
578 | } |
579 | |
5e367a2d |
580 | foreach ($sectionmods as $modnumber) { |
52dcc2f9 |
581 | if (empty($mods[$modnumber])) { |
582 | continue; |
583 | } |
5e367a2d |
584 | $mod = $mods[$modnumber]; |
2c8cb30c |
585 | if ($isediting and !$ismoving) { |
586 | $editbuttons = "<br />".make_editing_buttons($mod->id, $absolute, $mod->visible, true); |
587 | } else { |
588 | $editbuttons = ""; |
1acfbce5 |
589 | } |
52dcc2f9 |
590 | if ($mod->visible or $isteacher) { |
2c8cb30c |
591 | if ($ismoving) { |
592 | if ($mod->id == $USER->activitycopy) { |
593 | continue; |
594 | } |
595 | $modicon[] = ""; |
6951a894 |
596 | $moddata[] = "<a title=\"$strmovefull\"". |
597 | " href=\"$CFG->wwwroot/course/mod.php?moveto=$mod->id\">". |
598 | "<img height=\"16\" width=\"80\" src=\"$CFG->pixpath/movehere.gif\" ". |
599 | " alt=\"$strmovehere\" border=\"0\"></a>"; |
2c8cb30c |
600 | } |
1acfbce5 |
601 | $instancename = urldecode($modinfo[$modnumber]->name); |
c2cb4545 |
602 | $linkcss = $mod->visible ? "" : " class=\"dimmed\" "; |
3ee3e01a |
603 | if (!empty($modinfo[$modnumber]->extra)) { |
604 | $extra = urldecode($modinfo[$modnumber]->extra); |
605 | } else { |
606 | $extra = ""; |
607 | } |
7977cffd |
608 | |
c9f6251e |
609 | if ($mod->modname == "label") { |
610 | $modicon[] = ""; |
611 | $moddata[] = format_text($extra, FORMAT_HTML).$editbuttons; |
612 | } else { |
e845dee2 |
613 | $modicon[] = "<img src=\"$CFG->modpixpath/$mod->modname/icon.gif\"". |
c9f6251e |
614 | " height=\"16\" width=\"16\" alt=\"$mod->modfullname\">"; |
615 | $moddata[] = "<a title=\"$mod->modfullname\" $linkcss $extra". |
616 | "href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename</a>". |
617 | "$editbuttons"; |
618 | } |
5e367a2d |
619 | } |
5e367a2d |
620 | } |
621 | } |
2c8cb30c |
622 | if ($ismoving) { |
623 | $modicon[] = ""; |
6951a894 |
624 | $moddata[] = "<a title=\"$strmovefull\"". |
625 | " href=\"$CFG->wwwroot/course/mod.php?movetosection=$section->id\">". |
626 | "<img height=\"16\" width=\"80\" src=\"$CFG->pixpath/movehere.gif\" ". |
627 | " alt=\"$strmovehere\" border=\"0\"></a>"; |
2c8cb30c |
628 | } |
a44d18e7 |
629 | if ($isediting) { |
15ac9065 |
630 | $editmenu = popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section->section&add=", |
5e367a2d |
631 | $modnames, "section0", "", get_string("add")."...", "mods", get_string("activities"), true); |
dfec7b01 |
632 | $editmenu = "<div align=right>$editmenu</div>"; |
47f1da80 |
633 | } else { |
634 | $editmenu = ""; |
5e367a2d |
635 | } |
636 | |
637 | print_side_block($heading, "", $moddata, $modicon, $editmenu, $width); |
638 | } |
639 | |
640 | |
d897cae4 |
641 | function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%") { |
52dcc2f9 |
642 | /// Prints a section full of activity modules |
7977cffd |
643 | global $CFG, $USER; |
644 | |
52dcc2f9 |
645 | static $isteacher; |
646 | static $isediting; |
7977cffd |
647 | static $ismoving; |
648 | static $strmovehere; |
649 | static $strmovefull; |
52dcc2f9 |
650 | |
651 | if (!isset($isteacher)) { |
652 | $isteacher = isteacher($course->id); |
653 | } |
654 | if (!isset($isediting)) { |
655 | $isediting = isediting($course->id); |
656 | } |
7977cffd |
657 | if (!isset($ismoving)) { |
658 | $ismoving = ismoving($course->id); |
659 | } |
660 | if ($ismoving) { |
661 | $strmovehere = get_string("movehere"); |
f36b1996 |
662 | $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'")); |
7977cffd |
663 | } |
94361e02 |
664 | |
c408b0c4 |
665 | $modinfo = unserialize($course->modinfo); |
94361e02 |
666 | |
567df742 |
667 | echo "<table width=\"$width\" cellpadding=1 cellspacing=0>\n"; |
74666583 |
668 | if (!empty($section->sequence)) { |
94361e02 |
669 | |
670 | $sectionmods = explode(",", $section->sequence); |
671 | |
672 | foreach ($sectionmods as $modnumber) { |
9ae687af |
673 | if (empty($mods[$modnumber])) { |
674 | continue; |
675 | } |
94361e02 |
676 | $mod = $mods[$modnumber]; |
c9f6251e |
677 | |
52dcc2f9 |
678 | if ($mod->visible or $isteacher) { |
c9f6251e |
679 | echo "<tr><td class=\"activity$mod->modname\">"; |
7977cffd |
680 | if ($ismoving) { |
681 | if ($mod->id == $USER->activitycopy) { |
682 | continue; |
683 | } |
6951a894 |
684 | echo "<a title=\"$strmovefull\"". |
685 | " href=\"mod.php?moveto=$mod->id\">". |
686 | "<img height=\"16\" width=\"80\" src=\"$CFG->pixpath/movehere.gif\" ". |
687 | " alt=\"$strmovehere\" border=\"0\"></a><br />\n"; |
1acfbce5 |
688 | } |
7977cffd |
689 | $instancename = urldecode($modinfo[$modnumber]->name); |
c9f6251e |
690 | |
86aa7ccf |
691 | if (!empty($modinfo[$modnumber]->extra)) { |
692 | $extra = urldecode($modinfo[$modnumber]->extra); |
693 | } else { |
694 | $extra = ""; |
695 | } |
c9f6251e |
696 | |
aac94fd0 |
697 | if ($mod->indent) { |
698 | print_spacer(12, 20 * $mod->indent, false); |
699 | } |
700 | |
c9f6251e |
701 | if ($mod->modname == "label") { |
aac94fd0 |
702 | if (!$mod->visible) { |
703 | echo "<span class=\"dimmed_text\">"; |
704 | } |
c9f6251e |
705 | echo format_text($extra, FORMAT_HTML); |
aac94fd0 |
706 | if (!$mod->visible) { |
707 | echo "</span>"; |
708 | } |
c9f6251e |
709 | |
710 | } else { // Normal activity |
711 | $linkcss = $mod->visible ? "" : " class=\"dimmed\" "; |
e845dee2 |
712 | echo "<img src=\"$CFG->modpixpath/$mod->modname/icon.gif\"". |
c9f6251e |
713 | " height=16 width=16 alt=\"$mod->modfullname\">". |
714 | " <font size=2><a title=\"$mod->modfullname\" $linkcss $extra". |
715 | " href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename</a></font>"; |
716 | } |
c9f6251e |
717 | if ($isediting) { |
ffc69cd3 |
718 | echo " "; |
aac94fd0 |
719 | echo make_editing_buttons($mod->id, $absolute, $mod->visible, true, $mod->indent); |
c9f6251e |
720 | } |
ffc69cd3 |
721 | echo "</td>"; |
c9f6251e |
722 | echo "</tr>"; |
94361e02 |
723 | } |
94361e02 |
724 | } |
725 | } |
7977cffd |
726 | if ($ismoving) { |
6951a894 |
727 | echo "<tr><td><a title=\"$strmovefull\"". |
728 | " href=\"mod.php?movetosection=$section->id\">". |
729 | "<img height=\"16\" width=\"80\" src=\"$CFG->pixpath/movehere.gif\" ". |
730 | " alt=\"$strmovehere\" border=\"0\"></a></td></tr>\n"; |
7977cffd |
731 | } |
c9f6251e |
732 | echo "</table>\n\n"; |
a7ad3ea6 |
733 | } |
734 | |
5867bfb5 |
735 | |
736 | function rebuild_course_cache($courseid=0) { |
737 | // Rebuilds the cached list of course activities stored in the database |
738 | // If a courseid is not specified, then all are rebuilt |
739 | |
740 | if ($courseid) { |
741 | $select = "id = '$courseid'"; |
742 | } else { |
743 | $select = ""; |
744 | } |
745 | |
746 | if ($courses = get_records_select("course", $select)) { |
747 | foreach ($courses as $course) { |
748 | $modinfo = serialize(get_array_of_activities($course->id)); |
749 | if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) { |
750 | notify("Could not cache module information for course '$course->fullname'!"); |
751 | } |
752 | } |
753 | } |
754 | } |
755 | |
756 | |
7541bc3e |
757 | function print_heading_block($heading, $width="100%", $class="headingblock") { |
5e367a2d |
758 | global $THEME; |
759 | |
7541bc3e |
760 | echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">"; |
761 | echo "<tr><td bgcolor=\"$THEME->cellheading\" class=\"$class\">"; |
5e367a2d |
762 | echo stripslashes($heading); |
763 | echo "</td></tr></table>"; |
5e367a2d |
764 | } |
765 | |
766 | function print_side_block($heading="", $content="", $list=NULL, $icons=NULL, $footer="", $width=180) { |
767 | // Prints a nice side block with an optional header. The content can either |
768 | // be a block of HTML or a list of text with optional icons. |
a7ad3ea6 |
769 | |
5e367a2d |
770 | global $THEME; |
771 | |
7541bc3e |
772 | print_side_block_start($heading, $width); |
773 | |
5e367a2d |
774 | if ($content) { |
7541bc3e |
775 | echo "$content"; |
5e367a2d |
776 | } else { |
5e367a2d |
777 | echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">"; |
778 | foreach ($list as $key => $string) { |
7541bc3e |
779 | echo "<tr bgcolor=\"$THEME->cellcontent2\">"; |
5e367a2d |
780 | if ($icons) { |
7541bc3e |
781 | echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"16\">".$icons[$key]."</td>"; |
a7ad3ea6 |
782 | } |
7541bc3e |
783 | echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"*\"><font size=\"-1\">$string</font></td>"; |
5e367a2d |
784 | echo "</tr>"; |
a7ad3ea6 |
785 | } |
5e367a2d |
786 | if ($footer) { |
7541bc3e |
787 | echo "<tr bgcolor=\"$THEME->cellcontent2\">"; |
5e367a2d |
788 | if ($icons) { |
7541bc3e |
789 | echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"16\"> </td>"; |
5e367a2d |
790 | } |
7541bc3e |
791 | echo "<td class=\"sideblocklinks\"><font size=\"-1\">$footer</td>"; |
5e367a2d |
792 | echo "</tr>"; |
793 | } |
794 | echo "</table>"; |
a7ad3ea6 |
795 | } |
5e367a2d |
796 | |
7541bc3e |
797 | print_side_block_end(); |
798 | } |
799 | |
800 | function print_side_block_start($heading="", $width=180, $class="sideblockmain") { |
801 | // Starts a nice side block with an optional header. |
802 | |
803 | global $THEME; |
804 | |
805 | echo "<table class=\"sideblock\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">"; |
806 | if ($heading) { |
807 | echo "<tr>"; |
808 | echo "<td class=\"sideblockheading\" bgcolor=\"$THEME->cellheading\">$heading</td>"; |
809 | echo "</tr>"; |
810 | } |
811 | echo "<tr>"; |
812 | echo "<td class=\"$class\" bgcolor=\"$THEME->cellcontent2\">"; |
813 | } |
814 | |
815 | function print_side_block_end() { |
816 | echo "</td></tr>"; |
7d99d695 |
817 | echo "</table><br />"; |
94361e02 |
818 | } |
819 | |
5e367a2d |
820 | |
670fddf1 |
821 | function print_admin_links ($siteid, $width=180) { |
dc0dc7d5 |
822 | global $CFG, $THEME; |
2b25f2a0 |
823 | |
440eb0d7 |
824 | if (isadmin()) { |
0d0e550f |
825 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/configure.php\">".get_string("configuration")."</a>..."; |
826 | $modicon[]="<img src=\"$CFG->pixpath/i/admin.gif\" height=16 width=16 alt=\"\" />"; |
2f4d324b |
827 | |
0d0e550f |
828 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/users.php\">".get_string("users")."</a>..."; |
829 | $modicon[]="<img src=\"$CFG->pixpath/i/users.gif\" height=16 width=16 alt=\"\" />"; |
440eb0d7 |
830 | } |
2f4d324b |
831 | |
55e4b5f9 |
832 | if (iscreator()) { |
0d0e550f |
833 | $moddata[]="<a href=\"$CFG->wwwroot/course/index.php?edit=on\">".get_string("courses")."</a>"; |
834 | $modicon[]="<img src=\"$CFG->pixpath/i/course.gif\" height=16 width=16 alt=\"\" />"; |
55e4b5f9 |
835 | $fulladmin = ""; |
836 | } |
2f4d324b |
837 | |
1924074c |
838 | if (isadmin()) { |
0d0e550f |
839 | $moddata[]="<a href=\"$CFG->wwwroot/course/log.php?id=$siteid\">".get_string("logs")."</a>"; |
840 | $modicon[]="<img src=\"$CFG->pixpath/i/log.gif\" height=16 width=16 alt=\"\" />"; |
2f4d324b |
841 | |
0d0e550f |
842 | $moddata[]="<a href=\"$CFG->wwwroot/files/index.php?id=$siteid\">".get_string("sitefiles")."</a>"; |
843 | $modicon[]="<img src=\"$CFG->pixpath/i/files.gif\" height=16 width=16 alt=\"\" />"; |
2f4d324b |
844 | |
0d0e550f |
845 | if (file_exists("$CFG->dirroot/$CFG->admin/$CFG->dbtype")) { |
2f4d324b |
846 | $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/$CFG->dbtype/frame.php\">". |
847 | get_string("managedatabase")."</a>"; |
0d0e550f |
848 | $modicon[]="<img src=\"$CFG->pixpath/i/db.gif\" height=16 width=16 alt=\"\" />"; |
849 | } |
5867bfb5 |
850 | $fulladmin = "<p><a href=\"$CFG->wwwroot/$CFG->admin/\">".get_string("admin")."</a>..."; |
1924074c |
851 | } |
5e367a2d |
852 | |
853 | print_side_block(get_string("administration"), "", $moddata, $modicon, $fulladmin, $width); |
854 | |
dc0dc7d5 |
855 | echo "<img src=\"$CFG->wwwroot/pix/spacer.gif\" width=\"$width\" height=1><br>"; |
2b25f2a0 |
856 | } |
857 | |
b4d7002e |
858 | function print_course_admin_links($course, $width=180) { |
dc0dc7d5 |
859 | global $USER, $CFG, $THEME; |
44dad735 |
860 | |
fce1ce13 |
861 | if (isguest()) { |
862 | return true; |
863 | } |
eef16119 |
864 | |
13469b82 |
865 | if (isteacher($course->id)) { |
eef16119 |
866 | |
867 | $isteacheredit = isteacheredit($course->id); |
868 | |
869 | if ($isteacheredit) { |
c9f6251e |
870 | $adminicon[]="<img src=\"$CFG->pixpath/i/edit.gif\" height=16 width=16 alt=\"\">"; |
02ebf404 |
871 | if (isediting($course->id)) { |
872 | $admindata[]="<a href=\"view.php?id=$course->id&edit=off\">".get_string("turneditingoff")."</a>"; |
873 | } else { |
874 | $admindata[]="<a href=\"view.php?id=$course->id&edit=on\">".get_string("turneditingon")."</a>"; |
875 | } |
876 | $admindata[]="<a href=\"edit.php?id=$course->id\">".get_string("settings")."...</a>"; |
c9f6251e |
877 | $adminicon[]="<img src=\"$CFG->pixpath/i/settings.gif\" height=16 width=16 alt=\"\">"; |
3b1bb969 |
878 | |
879 | if (iscreator() or !empty($CFG->teacherassignteachers)) { |
880 | if (!$course->teachers) { |
881 | $course->teachers = get_string("defaultcourseteachers"); |
882 | } |
883 | $admindata[]="<a href=\"teacher.php?id=$course->id\">$course->teachers...</a>"; |
c9f6251e |
884 | $adminicon[]="<img src=\"$CFG->pixpath/i/users.gif\" height=16 width=16 alt=\"\">"; |
02ebf404 |
885 | } |
4d9d90c0 |
886 | } |
02ebf404 |
887 | |
a33c4ae8 |
888 | if (!$course->students) { |
889 | $course->students = get_string("defaultcoursestudents"); |
3b1bb969 |
890 | } |
4d9d90c0 |
891 | $admindata[]="<a href=\"student.php?id=$course->id\">$course->students...</a>"; |
c9f6251e |
892 | $adminicon[]="<img src=\"$CFG->pixpath/i/users.gif\" height=16 width=16 alt=\"\">"; |
7d569d28 |
893 | |
eef16119 |
894 | if ($isteacheredit) { |
02ebf404 |
895 | $admindata[]="<a href=\"$CFG->wwwroot/backup/backup.php?id=$course->id\">".get_string("backup")."...</a>"; |
c9f6251e |
896 | $adminicon[]="<img src=\"$CFG->pixpath/i/backup.gif\" height=16 width=16 alt=\"\">"; |
02ebf404 |
897 | |
07bc2435 |
898 | $admindata[]="<a href=\"$CFG->wwwroot/files/index.php?id=$course->id&wdir=/backupdata\">".get_string("restore")."...</a>"; |
c9f6251e |
899 | $adminicon[]="<img src=\"$CFG->pixpath/i/restore.gif\" height=16 width=16 alt=\"\">"; |
02ebf404 |
900 | $admindata[]="<a href=\"scales.php?id=$course->id\">".get_string("scales")."...</a>"; |
c9f6251e |
901 | $adminicon[]="<img src=\"$CFG->pixpath/i/scales.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
902 | } |
13469b82 |
903 | |
dc0dc7d5 |
904 | $admindata[]="<a href=\"grades.php?id=$course->id\">".get_string("grades")."...</a>"; |
c9f6251e |
905 | $adminicon[]="<img src=\"$CFG->pixpath/i/grades.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
906 | |
dc0dc7d5 |
907 | $admindata[]="<a href=\"log.php?id=$course->id\">".get_string("logs")."...</a>"; |
c9f6251e |
908 | $adminicon[]="<img src=\"$CFG->pixpath/i/log.gif\" height=16 width=16 alt=\"\">"; |
dc0dc7d5 |
909 | |
eef16119 |
910 | if ($isteacheredit) { |
911 | $admindata[]="<a href=\"$CFG->wwwroot/files/index.php?id=$course->id\">".get_string("files")."...</a>"; |
912 | $adminicon[]="<img src=\"$CFG->pixpath/i/files.gif\" height=16 width=16 alt=\"\">"; |
913 | } |
f354106d |
914 | |
dc0dc7d5 |
915 | $admindata[]="<a href=\"$CFG->wwwroot/doc/view.php?id=$course->id&file=teacher.html\">".get_string("help")."...</a>"; |
c9f6251e |
916 | $adminicon[]="<img src=\"$CFG->modpixpath/resource/icon.gif\" height=16 width=16 alt=\"\">"; |
b4d7002e |
917 | |
13469b82 |
918 | if ($teacherforum = forum_get_course_forum($course->id, "teacher")) { |
eafc0b44 |
919 | $admindata[]="<a href=\"$CFG->wwwroot/mod/forum/view.php?f=$teacherforum->id\">$teacherforum->name</a>"; |
c9f6251e |
920 | $adminicon[]="<img src=\"$CFG->modpixpath/forum/icon.gif\" height=16 width=16 alt=\"\">"; |
13469b82 |
921 | } |
f354106d |
922 | |
e550e2d6 |
923 | } else if (!isguest()) { // Students menu |
5b8540e0 |
924 | if ($course->showgrades) { |
fff79722 |
925 | $admindata[]="<a href=\"grade.php?id=$course->id\">".get_string("grades")."...</a>"; |
c9f6251e |
926 | $adminicon[]="<img src=\"$CFG->pixpath/i/grades.gif\" height=16 width=16 alt=\"\">"; |
fff79722 |
927 | } |
3f125001 |
928 | if ($course->showreports) { |
929 | $admindata[]="<a href=\"user.php?id=$course->id&user=$USER->id\">".get_string("activityreport")."...</a>"; |
930 | $adminicon[]="<img src=\"$CFG->pixpath/i/report.gif\" height=16 width=16 alt=\"\">"; |
931 | } |
4fc2eb7a |
932 | if (is_internal_auth()) { |
e550e2d6 |
933 | $admindata[]="<a href=\"$CFG->wwwroot/login/change_password.php?id=$course->id\">". |
934 | get_string("changepassword")."...</a>"; |
c9f6251e |
935 | $adminicon[]="<img src=\"$CFG->pixpath/i/user.gif\" height=16 width=16 alt=\"\">"; |
e550e2d6 |
936 | } else if ($CFG->changepassword) { |
937 | $admindata[]="<a href=\"$CFG->changepassword\">".get_string("changepassword")."...</a>"; |
c9f6251e |
938 | $adminicon[]="<img src=\"$CFG->pixpath/i/user.gif\" height=16 width=16 alt=\"\">"; |
e550e2d6 |
939 | } |
5204d831 |
940 | if ($CFG->allowunenroll) { |
941 | $admindata[]="<a href=\"unenrol.php?id=$course->id\">".get_string("unenrolme", "", $course->shortname)."...</a>"; |
3f125001 |
942 | $adminicon[]="<img src=\"$CFG->pixpath/i/user.gif\" height=16 width=16 alt=\"\">"; |
5204d831 |
943 | } |
13469b82 |
944 | } |
44dad735 |
945 | |
f354106d |
946 | if (!empty($admindata)) { |
947 | print_side_block(get_string("administration"), "", $admindata, $adminicon, "", $width); |
948 | } |
44dad735 |
949 | } |
2b25f2a0 |
950 | |
c2cb4545 |
951 | |
952 | function make_categories_list(&$list, &$parents, $category=NULL, $path="") { |
953 | /// Given an empty array, this function recursively travels the |
954 | /// categories, building up a nice list for display. It also makes |
955 | /// an array that list all the parents for each category. |
956 | |
957 | if ($category) { |
958 | if ($path) { |
959 | $path = "$path / $category->name"; |
960 | } else { |
961 | $path = "$category->name"; |
962 | } |
963 | $list[$category->id] = $path; |
964 | } else { |
965 | $category->id = 0; |
966 | } |
967 | |
968 | if ($categories = get_categories("$category->id")) { // Print all the children recursively |
969 | foreach ($categories as $cat) { |
970 | if (!empty($category->id)) { |
3bd4de22 |
971 | if (isset($parents[$category->id])) { |
2832badf |
972 | $parents[$cat->id] = $parents[$category->id]; |
973 | } |
c2cb4545 |
974 | $parents[$cat->id][] = $category->id; |
975 | } |
e92fe848 |
976 | make_categories_list($list, $parents, $cat, $path); |
c2cb4545 |
977 | } |
978 | } |
979 | } |
980 | |
981 | |
c2cb4545 |
982 | function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1) { |
983 | /// Recursive function to print out all the categories in a nice format |
984 | /// with or without courses included |
985 | |
986 | if (!$displaylist) { |
e92fe848 |
987 | make_categories_list($displaylist, $parentslist); |
c2cb4545 |
988 | } |
989 | |
990 | if ($category) { |
3af6e1db |
991 | if ($category->visible or iscreator()) { |
d2b6ba70 |
992 | print_category_info($category, $depth); |
c2cb4545 |
993 | } else { |
994 | return; // Don't bother printing children of invisible categories |
995 | } |
996 | |
997 | } else { |
c2cb4545 |
998 | $category->id = "0"; |
999 | } |
1000 | |
1001 | if ($categories = get_categories($category->id)) { // Print all the children recursively |
1002 | $countcats = count($categories); |
1003 | $count = 0; |
1004 | $first = true; |
1005 | $last = false; |
1006 | foreach ($categories as $cat) { |
1007 | $count++; |
1008 | if ($count == $countcats) { |
1009 | $last = true; |
1010 | } |
1011 | $up = $first ? false : true; |
1012 | $down = $last ? false : true; |
1013 | $first = false; |
1014 | |
1015 | print_whole_category_list($cat, $displaylist, $parentslist, $depth + 1); |
1016 | } |
1017 | } |
c2cb4545 |
1018 | } |
1019 | |
1020 | |
d2b6ba70 |
1021 | function print_category_info($category, $depth) { |
1022 | /// Prints the category info in indented fashion |
1023 | /// This function is only used by print_whole_category_list() above |
c2cb4545 |
1024 | |
1025 | global $CFG; |
b48f834c |
1026 | static $strallowguests, $strrequireskey, $strsummary; |
c2cb4545 |
1027 | |
b48f834c |
1028 | if (empty($strsummary)) { |
1029 | $strallowguests = get_string("allowguests"); |
1030 | $strrequireskey = get_string("requireskey"); |
1031 | $strsummary = get_string("summary"); |
1032 | } |
ba2e5d73 |
1033 | |
d5f26b07 |
1034 | $catlinkcss = $category->visible ? "" : " class=\"dimmed\" "; |
1035 | |
8ef9cb56 |
1036 | if ($CFG->frontpage == FRONTPAGECOURSELIST) { |
c9f6251e |
1037 | $catimage = "<img src=\"$CFG->pixpath/i/course.gif\" width=16 height=16 border=0>"; |
b48f834c |
1038 | } else { |
1039 | $catimage = " "; |
8ef9cb56 |
1040 | } |
b48f834c |
1041 | |
1042 | echo "\n\n<table border=0 cellpadding=3 cellspacing=0 width=\"100%\"><tr>"; |
d2b6ba70 |
1043 | |
c2cb4545 |
1044 | if ($CFG->frontpage == FRONTPAGECOURSELIST) { |
b48f834c |
1045 | $courses = get_courses($category->id); |
1046 | |
1047 | echo "<tr>"; |
1048 | |
1049 | if ($depth) { |
1050 | $indent = $depth*30; |
1051 | $rows = count($courses) + 1; |
1052 | echo "<td rowspan=\"$rows\" valign=\"top\" width=\"$indent\">"; |
1053 | print_spacer(10, $indent); |
1054 | echo "</td>"; |
1055 | } |
1056 | |
1057 | echo "<td valign=\"top\">$catimage</td>"; |
cb29b020 |
1058 | echo "<td valign=\"top\" width=\"100%\" class=\"categoryname\">"; |
b48f834c |
1059 | echo "<a $catlinkcss href=\"$CFG->wwwroot/course/category.php?id=$category->id\">$category->name</a>"; |
cb29b020 |
1060 | echo "</td>"; |
1061 | echo "<td class=\"categoryname\"> </td>"; |
b48f834c |
1062 | echo "</tr>\n"; |
1063 | |
1064 | if ($courses) { |
c2cb4545 |
1065 | foreach ($courses as $course) { |
1066 | $linkcss = $course->visible ? "" : " class=\"dimmed\" "; |
b48f834c |
1067 | echo "<tr><td valign=\"top\" width=\"30\"> "; |
cb29b020 |
1068 | echo "</td>\n<td valign=\"top\" width=\"100%\" class=\"coursename\">"; |
a6870f0c |
1069 | echo "<a $linkcss href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>"; |
cb29b020 |
1070 | echo "</td>\n<td align=\"right\" valign=\"top\" nowrap class=\"coursename\">"; |
c2cb4545 |
1071 | if ($course->guest ) { |
1072 | echo "<a title=\"$strallowguests\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">"; |
9928b09e |
1073 | echo "<img hspace=1 alt=\"$strallowguests\" height=16 width=16 border=0 src=\"$CFG->pixpath/i/guest.gif\"></a>"; |
ebe8ddc1 |
1074 | } else { |
c9f6251e |
1075 | echo "<img alt=\"\" height=16 width=18 border=0 src=\"$CFG->pixpath/spacer.gif\">"; |
0c656181 |
1076 | } |
c2cb4545 |
1077 | if ($course->password) { |
1078 | echo "<a title=\"$strrequireskey\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">"; |
9928b09e |
1079 | echo "<img hspace=1 alt=\"$strrequireskey\" height=16 width=16 border=0 src=\"$CFG->pixpath/i/key.gif\"></a>"; |
ebe8ddc1 |
1080 | } else { |
c9f6251e |
1081 | echo "<img alt=\"\" height=16 width=18 border=0 src=\"$CFG->pixpath/spacer.gif\">"; |
b48f834c |
1082 | } |
1083 | if ($course->summary) { |
1084 | link_to_popup_window ("/course/info.php?id=$course->id", "courseinfo", |
9928b09e |
1085 | "<img hspace=1 alt=\"$strsummary\" height=16 width=16 border=0 src=\"$CFG->pixpath/i/info.gif\">", |
b48f834c |
1086 | 400, 500, $strsummary); |
ebe8ddc1 |
1087 | } else { |
c9f6251e |
1088 | echo "<img alt=\"\" height=16 width=18 border=0 src=\"$CFG->pixpath/spacer.gif\">"; |
0c656181 |
1089 | } |
b48f834c |
1090 | echo "</td></tr>\n"; |
0c656181 |
1091 | } |
ba2e5d73 |
1092 | } |
d2b6ba70 |
1093 | } else { |
b48f834c |
1094 | |
1095 | if ($depth) { |
1096 | $indent = $depth*20; |
1097 | echo "<td valign=\"top\" width=\"$indent\">"; |
1098 | print_spacer(10, $indent); |
1099 | echo "</td>"; |
d2b6ba70 |
1100 | } |
b48f834c |
1101 | |
cb29b020 |
1102 | echo "<td valign=\"top\" width=\"100%\" class=\"categoryname\">"; |
b48f834c |
1103 | echo "<a $catlinkcss href=\"$CFG->wwwroot/course/category.php?id=$category->id\">$category->name</a>"; |
cb29b020 |
1104 | echo "</td>"; |
a0456978 |
1105 | echo "<td valign=\"top\" class=\"categorynumber\">$category->coursecount</td></tr>"; |
c2cb4545 |
1106 | } |
b48f834c |
1107 | echo "\n</table>\n"; |
c2cb4545 |
1108 | } |
1109 | |
1110 | function print_courses_sideblock($category=0, $width="100%") { |
f3120024 |
1111 | global $CFG, $THEME, $USER; |
c2cb4545 |
1112 | |
1113 | if (empty($THEME->custompix)) { |
1114 | $icon = "<img src=\"$CFG->wwwroot/pix/i/course.gif\"". |
1115 | " height=\"16\" width=\"16\" alt=\"".get_string("course")."\">"; |
1116 | } else { |
1117 | $icon = "<img src=\"$CFG->wwwroot/theme/$CFG->theme/pix/i/course.gif\"". |
1118 | " height=\"16\" width=\"16\" alt=\"".get_string("course")."\">"; |
1119 | } |
1120 | |
f3120024 |
1121 | if (isset($USER->id) and !isadmin()) { // Just print My Courses |
1122 | if ($courses = get_my_courses($USER->id)) { |
1123 | foreach ($courses as $course) { |
c81696e5 |
1124 | if (!$course->category) { |
1125 | continue; |
1126 | } |
d1d74247 |
1127 | $linkcss = $course->visible ? "" : " class=\"dimmed\" "; |
f3120024 |
1128 | $moddata[]="<a $linkcss title=\"$course->shortname\" ". |
1129 | "href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>"; |
1130 | $modicon[]=$icon; |
1131 | } |
5dc3d80e |
1132 | $fulllist = "<p><a href=\"$CFG->wwwroot/course/index.php\">".get_string("fulllistofcourses")."</a>..."; |
f3120024 |
1133 | print_side_block( get_string("mycourses"), "", $moddata, $modicon, $fulllist, $width); |
1134 | return; |
1135 | } |
1136 | } |
1137 | |
c571f3fc |
1138 | $categories = get_categories("0"); // Parent = 0 ie top-level categories only |
c2cb4545 |
1139 | if (count($categories) > 1) { // Just print top level category links |
1140 | foreach ($categories as $category) { |
1141 | $linkcss = $category->visible ? "" : " class=\"dimmed\" "; |
d2b6ba70 |
1142 | $moddata[]="<a $linkcss href=\"$CFG->wwwroot/course/category.php?id=$category->id\">$category->name</a>"; |
c2cb4545 |
1143 | $modicon[]=$icon; |
0c656181 |
1144 | } |
b5333476 |
1145 | $fulllist = "<p><a href=\"$CFG->wwwroot/course/\">".get_string("searchcourses")."</a>..."; |
c2cb4545 |
1146 | } else { // Just print course names of single category |
90c2ca2e |
1147 | $category = array_shift($categories); |
d2b6ba70 |
1148 | $courses = get_courses($category->id); |
1149 | |
c2cb4545 |
1150 | if ($courses) { |
1151 | foreach ($courses as $course) { |
1152 | $linkcss = $course->visible ? "" : " class=\"dimmed\" "; |
1153 | $moddata[]="<a $linkcss title=\"$course->shortname\" ". |
1154 | "href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>"; |
1155 | $modicon[]=$icon; |
1156 | } |
5dc3d80e |
1157 | $fulllist = "<p><a href=\"$CFG->wwwroot/course/index.php\">".get_string("fulllistofcourses")."</a>..."; |
c2cb4545 |
1158 | } else { |
1159 | $moddata = array(); |
1160 | $modicon = array(); |
1161 | $fulllist = get_string("nocoursesyet"); |
0c656181 |
1162 | } |
ba2e5d73 |
1163 | } |
c2cb4545 |
1164 | |
f3120024 |
1165 | print_side_block( get_string("courses"), "", $moddata, $modicon, $fulllist, $width); |
ba2e5d73 |
1166 | } |
94361e02 |
1167 | |
c2cb4545 |
1168 | |
1169 | function print_courses($category, $width="100%") { |
1170 | /// Category is 0 (for all courses) or an object |
1171 | |
1172 | global $CFG, $THEME; |
1173 | |
1174 | if (empty($category)) { |
90c2ca2e |
1175 | $categories = get_categories(0); // Parent = 0 ie top-level categories only |
1176 | if (count($categories) == 1) { |
1177 | $category = array_shift($categories); |
d2b6ba70 |
1178 | $courses = get_courses($category->id); |
90c2ca2e |
1179 | } else { |
d2b6ba70 |
1180 | $courses = get_courses("all"); |
90c2ca2e |
1181 | } |
1182 | unset($categories); |
607809b3 |
1183 | } else { |
c2cb4545 |
1184 | $categories = get_categories($category->id); // sub categories |
d2b6ba70 |
1185 | $courses = get_courses($category->id); |
c2cb4545 |
1186 | } |
1187 | |
c2cb4545 |
1188 | if ($courses) { |
1189 | foreach ($courses as $course) { |
1190 | print_course($course, $width); |
1191 | echo "<br />\n"; |
1192 | } |
1193 | } else { |
1194 | print_heading(get_string("nocoursesyet")); |
1195 | } |
1196 | |
1197 | } |
1198 | |
1199 | |
1200 | function print_course($course, $width="100%") { |
1201 | |
1202 | global $CFG, $THEME; |
1203 | |
1204 | if (! $site = get_site()) { |
1205 | error("Could not find a site!"); |
1206 | } |
1207 | |
1b6a4b1d |
1208 | print_simple_box_start("center", "$width", $THEME->cellcontent, 5, "coursebox"); |
c2cb4545 |
1209 | |
22288704 |
1210 | $linkcss = $course->visible ? "" : " class=\"dimmed\" "; |
1211 | |
c2cb4545 |
1212 | echo "<table width=\"100%\">"; |
1213 | echo "<tr valign=top>"; |
1b6a4b1d |
1214 | echo "<td valign=top width=\"50%\" class=\"courseboxinfo\">"; |
c2cb4545 |
1215 | echo "<p><font size=3><b><a title=\"".get_string("entercourse")."\" |
22288704 |
1216 | $linkcss href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a></b></font></p>"; |
c2cb4545 |
1217 | if ($teachers = get_course_teachers($course->id)) { |
1218 | echo "<p><font size=\"1\">\n"; |
1219 | foreach ($teachers as $teacher) { |
1220 | if ($teacher->authority > 0) { |
1221 | if (!$teacher->role) { |
1222 | $teacher->role = $course->teacher; |
1223 | } |
2ac64806 |
1224 | $fullname = fullname($teacher, isteacher($course->id)); // is the USER a teacher of that course |
1225 | echo "$teacher->role: <a href=\"$CFG->wwwroot/user/view.php?id=$teacher->id&course=$site->id\">$fullname</a><br />"; |
c2cb4545 |
1226 | } |
1227 | } |
1228 | echo "</font></p>"; |
1229 | } |
1230 | if ($course->guest) { |
1231 | $strallowguests = get_string("allowguests"); |
1232 | echo "<a title=\"$strallowguests\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">"; |
a9a070e0 |
1233 | echo "<img vspace=4 alt=\"$strallowguests\" height=16 width=16 border=0 src=\"$CFG->pixpath/i/guest.gif\"></a> "; |
c2cb4545 |
1234 | } |
1235 | if ($course->password) { |
1236 | $strrequireskey = get_string("requireskey"); |
1237 | echo "<a title=\"$strrequireskey\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">"; |
c9f6251e |
1238 | echo "<img vspace=4 alt=\"$strrequireskey\" height=16 width=16 border=0 src=\"$CFG->pixpath/i/key.gif\"></a>"; |
c2cb4545 |
1239 | } |
1240 | |
1241 | |
1b6a4b1d |
1242 | echo "</td><td valign=top width=\"50%\" class=\"courseboxsummary\">"; |
0d0e550f |
1243 | echo "<p><font size=2>".filter_text(text_to_html($course->summary), $course->id)."</font></p>"; |
c2cb4545 |
1244 | echo "</td></tr>"; |
1245 | echo "</table>"; |
1246 | |
1247 | print_simple_box_end(); |
1248 | } |
1249 | |
1250 | |
1251 | function print_my_moodle() { |
1252 | /// Prints custom user information on the home page. |
1253 | /// Over time this can include all sorts of information |
1254 | |
1255 | global $USER, $CFG; |
1256 | |
1257 | if (!isset($USER->id)) { |
1258 | error("It shouldn't be possible to see My Moodle without being logged in."); |
1259 | } |
1260 | |
1261 | if ($courses = get_my_courses($USER->id)) { |
1262 | foreach ($courses as $course) { |
c81696e5 |
1263 | if (!$course->category) { |
1264 | continue; |
1265 | } |
c2cb4545 |
1266 | print_course($course, "100%"); |
1267 | echo "<br />\n"; |
1268 | } |
38a10939 |
1269 | |
7f989948 |
1270 | if (count_records("course") > (count($courses) + 1) ) { // Some courses not being displayed |
1271 | echo "<table width=\"100%\"><tr><td align=\"center\">"; |
1272 | print_course_search("", false, "short"); |
1273 | echo "</td><td align=\"center\">"; |
1274 | print_single_button("$CFG->wwwroot/course/index.php", NULL, get_string("fulllistofcourses"), "get"); |
1275 | echo "</td></tr></table>\n"; |
1276 | } |
26330001 |
1277 | } else { |
1278 | if (count_records("course_categories") > 1) { |
cb29b020 |
1279 | print_simple_box_start("center", "100%", "#FFFFFF", 5, "categorybox"); |
26330001 |
1280 | print_whole_category_list(); |
1281 | print_simple_box_end(); |
1282 | } else { |
1283 | print_courses(0, "100%"); |
1284 | } |
607809b3 |
1285 | } |
2b8cef80 |
1286 | } |
1287 | |
11b0c469 |
1288 | |
a8b56716 |
1289 | function print_course_search($value="", $return=false, $format="plain") { |
38a10939 |
1290 | |
1291 | global $CFG; |
1292 | |
1293 | $strsearchcourses= get_string("searchcourses"); |
1294 | |
a8b56716 |
1295 | if ($format == "plain") { |
1296 | $output = "<center><p align=\"center\" class=\"coursesearchbox\">"; |
1297 | $output .= "<form name=\"coursesearch\" action=\"$CFG->wwwroot/course/search.php\" method=\"get\">"; |
1298 | $output .= "<input type=\"text\" size=30 name=\"search\" value=\"$value\">"; |
1299 | $output .= "<input type=\"submit\" value=\"$strsearchcourses\">"; |
1300 | $output .= "</form></p></center>"; |
e4027ac9 |
1301 | } else if ($format == "short") { |
1302 | $output = "<center><p align=\"center\" class=\"coursesearchbox\">"; |
1303 | $output .= "<form name=\"coursesearch\" action=\"$CFG->wwwroot/course/search.php\" method=\"get\">"; |
1304 | $output .= "<input type=\"text\" size=12 name=\"search\" value=\"$value\">"; |
1305 | $output .= "<input type=\"submit\" value=\"$strsearchcourses\">"; |
1306 | $output .= "</form></p></center>"; |
a8b56716 |
1307 | } else if ($format == "navbar") { |
1308 | $output = "<table border=0 cellpadding=0 cellspacing=0><tr><td nowrap>"; |
1309 | $output .= "<form name=\"coursesearch\" action=\"$CFG->wwwroot/course/search.php\" method=\"get\">"; |
1310 | $output .= "<input type=\"text\" size=20 name=\"search\" value=\"$value\">"; |
1311 | $output .= "<input type=\"submit\" value=\"$strsearchcourses\">"; |
a8b56716 |
1312 | $output .= "</form>"; |
1313 | $output .= "</td></tr></table>"; |
1314 | } |
1315 | |
1316 | if ($return) { |
1317 | return $output; |
1318 | } |
1319 | echo $output; |
38a10939 |
1320 | } |
11b0c469 |
1321 | |
1322 | /// MODULE FUNCTIONS ///////////////////////////////////////////////////////////////// |
1323 | |
1324 | function add_course_module($mod) { |
11b0c469 |
1325 | |
e5dfd0f3 |
1326 | $mod->added = time(); |
11b0c469 |
1327 | |
e5dfd0f3 |
1328 | return insert_record("course_modules", $mod); |
11b0c469 |
1329 | } |
1330 | |
7977cffd |
1331 | function add_mod_to_section($mod, $beforemod=NULL) { |
1332 | /// Given a full mod object with section and course already defined |
1333 | /// If $before is specified, then this is an existing ID which we |
1334 | /// will insert the new module before |
1335 | /// |
1336 | /// Returns the course_sections ID where the mod is inserted |
11b0c469 |
1337 | |
9fa49e22 |
1338 | if ($section = get_record("course_sections", "course", "$mod->course", "section", "$mod->section")) { |
7977cffd |
1339 | |
1340 | $section->sequence = trim($section->sequence); |
1341 | |
1342 | if (empty($section->sequence)) { |
11b0c469 |
1343 | $newsequence = "$mod->coursemodule"; |
7977cffd |
1344 | |
1345 | } else if ($beforemod) { |
1346 | $modarray = explode(",", $section->sequence); |
1347 | |
1348 | if ($key = array_keys ($modarray, $beforemod->id)) { |
1349 | $insertarray = array($mod->id, $beforemod->id); |
1350 | array_splice($modarray, $key[0], 1, $insertarray); |
1351 | $newsequence = implode(",", $modarray); |
1352 | |
1353 | } else { // Just tack it on the end anyway |
1354 | $newsequence = "$section->sequence,$mod->coursemodule"; |
1355 | } |
1356 | |
1357 | } else { |
1358 | $newsequence = "$section->sequence,$mod->coursemodule"; |
11b0c469 |
1359 | } |
7977cffd |
1360 | |
e5dfd0f3 |
1361 | if (set_field("course_sections", "sequence", $newsequence, "id", $section->id)) { |
1362 | return $section->id; // Return course_sections ID that was used. |
11b0c469 |
1363 | } else { |
e5dfd0f3 |
1364 | return 0; |
11b0c469 |
1365 | } |
1366 | |
1367 | } else { // Insert a new record |
e5dfd0f3 |
1368 | $section->course = $mod->course; |
1369 | $section->section = $mod->section; |
1370 | $section->summary = ""; |
1371 | $section->sequence = $mod->coursemodule; |
1372 | return insert_record("course_sections", $section); |
11b0c469 |
1373 | } |
1374 | } |
1375 | |
1acfbce5 |
1376 | function hide_course_module($mod) { |
1377 | return set_field("course_modules", "visible", 0, "id", $mod); |
1378 | } |
1379 | |
1380 | function show_course_module($mod) { |
1381 | return set_field("course_modules", "visible", 1, "id", $mod); |
1382 | } |
1383 | |
11b0c469 |
1384 | function delete_course_module($mod) { |
1385 | return set_field("course_modules", "deleted", 1, "id", $mod); |
1386 | } |
1387 | |
1388 | function delete_mod_from_section($mod, $section) { |
11b0c469 |
1389 | |
e5dfd0f3 |
1390 | if ($section = get_record("course_sections", "id", "$section") ) { |
11b0c469 |
1391 | |
e5dfd0f3 |
1392 | $modarray = explode(",", $section->sequence); |
11b0c469 |
1393 | |
1394 | if ($key = array_keys ($modarray, $mod)) { |
1395 | array_splice($modarray, $key[0], 1); |
1396 | $newsequence = implode(",", $modarray); |
e5dfd0f3 |
1397 | return set_field("course_sections", "sequence", $newsequence, "id", $section->id); |
11b0c469 |
1398 | } else { |
1399 | return false; |
1400 | } |
1401 | |
11b0c469 |
1402 | } |
7977cffd |
1403 | return false; |
11b0c469 |
1404 | } |
1405 | |
12905134 |
1406 | function move_section($course, $section, $move) { |
1407 | /// Moves a whole course section up and down within the course |
1408 | |
1409 | if (!$move) { |
1410 | return true; |
1411 | } |
1412 | |
1413 | $sectiondest = $section + $move; |
1414 | |
1415 | if ($sectiondest > $course->numsections or $sectiondest < 1) { |
1416 | return false; |
1417 | } |
1418 | |
1419 | if (!$sectionrecord = get_record("course_sections", "course", $course->id, "section", $section)) { |
1420 | return false; |
1421 | } |
1422 | |
1423 | if (!$sectiondestrecord = get_record("course_sections", "course", $course->id, "section", $sectiondest)) { |
1424 | return false; |
1425 | } |
1426 | |
56e34ee4 |
1427 | if (!set_field("course_sections", "section", $sectiondest, "id", $sectionrecord->id)) { |
12905134 |
1428 | return false; |
1429 | } |
56e34ee4 |
1430 | if (!set_field("course_sections", "section", $section, "id", $sectiondestrecord->id)) { |
12905134 |
1431 | return false; |
1432 | } |
1433 | return true; |
1434 | } |
1435 | |
1436 | |
7977cffd |
1437 | function moveto_module($mod, $section, $beforemod=NULL) { |
1438 | /// All parameters are objects |
1439 | /// Move the module object $mod to the specified $section |
1440 | /// If $beforemod exists then that is the module |
1441 | /// before which $modid should be inserted |
1442 | |
1443 | /// Remove original module from original section |
1444 | |
1445 | if (! delete_mod_from_section($mod->id, $mod->section)) { |
1446 | notify("Could not delete module from existing section"); |
1447 | } |
1448 | |
1449 | /// Update module itself if necessary |
1450 | |
1451 | if ($mod->section != $section->id) { |
1452 | $mod->section = $section->id; |
1453 | |
1454 | if (!update_record("course_modules", $mod)) { |
1455 | return false; |
1456 | } |
1457 | } |
1458 | |
1459 | /// Add the module into the new section |
1460 | |
1461 | $mod->course = $section->course; |
1462 | $mod->section = $section->section; // need relative reference |
1463 | $mod->coursemodule = $mod->id; |
1464 | |
1465 | if (! add_mod_to_section($mod, $beforemod)) { |
1466 | return false; |
1467 | } |
1468 | |
1469 | return true; |
1470 | |
1471 | } |
1472 | |
1473 | |
11b0c469 |
1474 | |
7c0f2984 |
1475 | function move_module($cm, $move) { |
12905134 |
1476 | /// Moves an activity module up and down within the course |
11b0c469 |
1477 | |
1478 | if (!$move) { |
1479 | return true; |
1480 | } |
1481 | |
11b0c469 |
1482 | if (! $thissection = get_record("course_sections", "id", $cm->section)) { |
1483 | error("This course section doesn't exist"); |
1484 | } |
1485 | |
1486 | $mods = explode(",", $thissection->sequence); |
1487 | |
1488 | $len = count($mods); |
1489 | $pos = array_keys($mods, $cm->id); |
1490 | $thepos = $pos[0]; |
1491 | |
1492 | if ($len == 0 || count($pos) == 0 ) { |
1493 | error("Very strange. Could not find the required module in this section."); |
1494 | } |
1495 | |
1496 | if ($len == 1) { |
1497 | $first = true; |
1498 | $last = true; |
1499 | } else { |
1500 | $first = ($thepos == 0); |
1501 | $last = ($thepos == $len - 1); |
1502 | } |
1503 | |
1504 | if ($move < 0) { // Moving the module up |
1505 | |
1506 | if ($first) { |
ad41694c |
1507 | if ($thissection->section == 0) { // First section, do nothing |
11b0c469 |
1508 | return true; |
ad41694c |
1509 | |
11b0c469 |
1510 | } else { // Push onto end of previous section |
1511 | $prevsectionnumber = $thissection->section - 1; |
9fa49e22 |
1512 | if (! $prevsection = get_record("course_sections", "course", "$thissection->course", |
1513 | "section", "$prevsectionnumber")) { |
11b0c469 |
1514 | error("Previous section ($prevsection->id) doesn't exist"); |
1515 | } |
1516 | |
74666583 |
1517 | if (!empty($prevsection->sequence)) { |
11b0c469 |
1518 | $newsequence = "$prevsection->sequence,$cm->id"; |
1519 | } else { |
1520 | $newsequence = "$cm->id"; |
1521 | } |
1522 | |
1523 | if (! set_field("course_sections", "sequence", $newsequence, "id", $prevsection->id)) { |
1524 | error("Previous section could not be updated"); |
1525 | } |
1526 | |
1527 | if (! set_field("course_modules", "section", $prevsection->id, "id", $cm->id)) { |
1528 | error("Module could not be updated"); |
1529 | } |
1530 | |
1531 | array_splice($mods, 0, 1); |
1532 | $newsequence = implode(",", $mods); |
1533 | if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) { |
1534 | error("Module could not be updated"); |
1535 | } |
1536 | |
1537 | return true; |
1538 | |
1539 | } |
1540 | } else { // move up within this section |
1541 | $swap = $mods[$thepos-1]; |
1542 | $mods[$thepos-1] = $mods[$thepos]; |
1543 | $mods[$thepos] = $swap; |
1544 | |
1545 | $newsequence = implode(",", $mods); |
1546 | if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) { |
1547 | error("This section could not be updated"); |
1548 | } |
1549 | return true; |
1550 | } |
1551 | |
1552 | } else { // Moving the module down |
1553 | |
1554 | if ($last) { |
1555 | $nextsectionnumber = $thissection->section + 1; |
9fa49e22 |
1556 | if ($nextsection = get_record("course_sections", "course", "$thissection->course", |
1557 | "section", "$nextsectionnumber")) { |
11b0c469 |
1558 | |
74666583 |
1559 | if (!empty($nextsection->sequence)) { |
11b0c469 |
1560 | $newsequence = "$cm->id,$nextsection->sequence"; |
1561 | } else { |
1562 | $newsequence = "$cm->id"; |
1563 | } |
1564 | |
1565 | if (! set_field("course_sections", "sequence", $newsequence, "id", $nextsection->id)) { |
1566 | error("Next section could not be updated"); |
1567 | } |
1568 | |
1569 | if (! set_field("course_modules", "section", $nextsection->id, "id", $cm->id)) { |
1570 | error("Module could not be updated"); |
1571 | } |
1572 | |
1573 | array_splice($mods, $thepos, 1); |
1574 | $newsequence = implode(",", $mods); |
1575 | if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) { |
1576 | error("This section could not be updated"); |
1577 | } |
1578 | return true; |
1579 | |
1580 | } else { // There is no next section, so just return |
1581 | return true; |
1582 | |
1583 | } |
1584 | } else { // move down within this section |
1585 | $swap = $mods[$thepos+1]; |
1586 | $mods[$thepos+1] = $mods[$thepos]; |
1587 | $mods[$thepos] = $swap; |
1588 | |
1589 | $newsequence = implode(",", $mods); |
1590 | if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) { |
1591 | error("This section could not be updated"); |
1592 | } |
1593 | return true; |
1594 | } |
1595 | } |
1596 | } |
1597 | |
aac94fd0 |
1598 | function make_editing_buttons($moduleid, $absolute=false, $visible=true, $moveselect=true, $indent=-1) { |
dc0dc7d5 |
1599 | global $CFG, $THEME; |
94361e02 |
1600 | |
4de4fdfe |
1601 | static $str = ''; |
1acfbce5 |
1602 | if (empty($str)) { |
1603 | $str->delete = get_string("delete"); |
493486c4 |
1604 | $str->move = get_string("move"); |
1acfbce5 |
1605 | $str->moveup = get_string("moveup"); |
1606 | $str->movedown = get_string("movedown"); |
aac94fd0 |
1607 | $str->moveright = get_string("moveright"); |
1608 | $str->moveleft = get_string("moveleft"); |
1acfbce5 |
1609 | $str->update = get_string("update"); |
1610 | $str->hide = get_string("hide"); |
1611 | $str->show = get_string("show"); |
1612 | } |
94361e02 |
1613 | |
1614 | if ($absolute) { |
dc0dc7d5 |
1615 | $path = "$CFG->wwwroot/course"; |
1616 | } else { |
1617 | $path = "."; |
1618 | } |
1619 | |
1620 | if (empty($THEME->custompix)) { |
1621 | $pixpath = "$path/../pix"; |
94361e02 |
1622 | } else { |
dc0dc7d5 |
1623 | $pixpath = "$path/../theme/$CFG->theme/pix"; |
94361e02 |
1624 | } |
1acfbce5 |
1625 | |
1626 | if ($visible) { |
7977cffd |
1627 | $hideshow = "<a title=\"$str->hide\" href=\"$path/mod.php?hide=$moduleid\"><img". |
1628 | " src=\"$pixpath/t/hide.gif\" hspace=2 height=11 width=11 border=0></a> "; |
1acfbce5 |
1629 | } else { |
7977cffd |
1630 | $hideshow = "<a title=\"$str->show\" href=\"$path/mod.php?show=$moduleid\"><img". |
1631 | " src=\"$pixpath/t/show.gif\" hspace=2 height=11 width=11 border=0></a> "; |
1632 | } |
1633 | |
1634 | if ($moveselect) { |
1635 | $move = "<a title=\"$str->move\" href=\"$path/mod.php?copy=$moduleid\"><img". |
bf1241ad |
1636 | " src=\"$pixpath/t/move.gif\" hspace=\"2\" height=\"11\" width=\"11\" border=\"0\"></a>"; |
493486c4 |
1637 | } else { |
1638 | $move = "<a title=\"$str->moveup\" href=\"$path/mod.php?id=$moduleid&move=-1\"><img". |
bf1241ad |
1639 | " src=\"$pixpath/t/up.gif\" hspace=\"2\" height=11 width=11 border=0></a>". |
493486c4 |
1640 | "<a title=\"$str->movedown\" href=\"$path/mod.php?id=$moduleid&move=1\"><img". |
bf1241ad |
1641 | " src=\"$pixpath/t/down.gif\" hspace=\"2\" height=11 width=11 border=0></a>"; |
7977cffd |
1642 | } |
1643 | |
aac94fd0 |
1644 | $leftright = ""; |
1645 | if ($indent > 0) { |
1646 | $leftright .= "<a title=\"$str->moveleft\" href=\"$path/mod.php?id=$moduleid&indent=-1\"><img". |
bf1241ad |
1647 | " src=\"$pixpath/t/left.gif\" hspace=\"2\" height=11 width=11 border=0></a>"; |
aac94fd0 |
1648 | } |
1649 | if ($indent >= 0) { |
1650 | $leftright .= "<a title=\"$str->moveright\" href=\"$path/mod.php?id=$moduleid&indent=1\"><img". |
bf1241ad |
1651 | " src=\"$pixpath/t/right.gif\" hspace=\"2\" height=11 width=11 border=0></a>"; |
aac94fd0 |
1652 | } |
1653 | |
bf1241ad |
1654 | return "$leftright$move". |
7977cffd |
1655 | "<a title=\"$str->update\" href=\"$path/mod.php?update=$moduleid\"><img". |
bf1241ad |
1656 | " src=\"$pixpath/t/edit.gif\" hspace=\"2\" height=11 width=11 border=0></a>". |
1657 | "<a title=\"$str->delete\" href=\"$path/mod.php?delete=$moduleid\"><img". |
1658 | " src=\"$pixpath/t/delete.gif\" hspace=\"2\" height=11 width=11 border=0></a>$hideshow"; |
90845098 |
1659 | } |
1660 | |
f9903ed0 |
1661 | ?> |