More debug...
[moodle.git] / course / lib.php
CommitLineData
f9903ed0 1<? // $Id$
97c270e9 2 // Library of useful functions
f9903ed0 3
f9903ed0 4
3d891989 5if (defined('COURSE_MAX_LOG_DISPLAY')) { // Being included again - should never happen!!
9ae687af 6 return;
7}
8
3d891989 9define('COURSE_MAX_LOG_DISPLAY', 150); // days
d9d1c35d 10
3d891989 11define('COURSE_MAX_LOGS_PER_PAGE', 1000); // records
1c0200e0 12
3d891989 13define('COURSE_LIVELOG_REFRESH', 60); // Seconds
87ffed0d 14
10a95b43 15define('COURSE_MAX_RECENT_PERIOD', 604800); // A week, in seconds
ef58b822 16
f9903ed0 17
9ae687af 18
f9903ed0 19function 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 100function 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 117function 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 192function 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 248function 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>&nbsp;&nbsp;";
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 301function print_headline($text, $size=2) {
302 echo "<B><FONT SIZE=\"$size\">$text</FONT></B><BR>\n";
303}
304
305function 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 433function get_array_of_activities($courseid) {
434// For a given course, returns an array of course activity objects
435// Each item in the array contains he following properties:
436// cm - course module id
437// mod - name of the module (eg forum)
438// section - the number of the section (eg week or topic)
439// name - the name of the instance
5867bfb5 440// visible - is the instance visible or not
d897cae4 441
442 $mod = array();
443
9fa49e22 444 if (!$rawmods = get_course_mods($courseid)) {
d897cae4 445 return NULL;
446 }
447
448 if ($sections = get_records("course_sections", "course", $courseid, "section ASC")) {
449 foreach ($sections as $section) {
74666583 450 if (!empty($section->sequence)) {
d897cae4 451 $sequence = explode(",", $section->sequence);
452 foreach ($sequence as $seq) {
7af6281f 453 if (empty($rawmods[$seq])) {
454 continue;
455 }
d897cae4 456 $mod[$seq]->cm = $rawmods[$seq]->id;
457 $mod[$seq]->mod = $rawmods[$seq]->modname;
458 $mod[$seq]->section = $section->section;
459 $mod[$seq]->name = urlencode(get_field($rawmods[$seq]->modname, "name", "id", $rawmods[$seq]->instance));
fec5a6a6 460 $mod[$seq]->visible = $rawmods[$seq]->visible;
d897cae4 461 }
462 }
463 }
464 }
465 return $mod;
466}
467
468
469
e1360728 470
90845098 471function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
472// Returns a number of useful structures for course displays
7468bf01 473
90845098 474 $mods = NULL; // course modules indexed by id
475 $modnames = NULL; // all course module names
94361e02 476 $modnamesplural= NULL; // all course module names (plural form)
90845098 477 $modnamesused = NULL; // course module names used
7468bf01 478
9fa49e22 479 if ($allmods = get_records("modules")) {
90845098 480 foreach ($allmods as $mod) {
5867bfb5 481 if ($mod->visible) {
482 $modnames[$mod->name] = get_string("modulename", "$mod->name");
483 $modnamesplural[$mod->name] = get_string("modulenameplural", "$mod->name");
484 }
90845098 485 }
486 asort($modnames);
487 } else {
488 error("No modules are installed!");
489 }
490
9fa49e22 491 if ($rawmods = get_course_mods($courseid)) {
7468bf01 492 foreach($rawmods as $mod) { // Index the mods
493 $mods[$mod->id] = $mod;
90845098 494 $mods[$mod->id]->modfullname = $modnames[$mod->modname];
1acfbce5 495 if ($mod->visible or isteacher($courseid)) {
496 $modnamesused[$mod->modname] = $modnames[$mod->modname];
497 }
7468bf01 498 }
c7da6f7a 499 if ($modnamesused) {
500 asort($modnamesused);
501 }
7468bf01 502 }
7468bf01 503}
504
9fa49e22 505
7468bf01 506function get_all_sections($courseid) {
507
d26d7ed0 508 return get_records("course_sections", "course", "$courseid", "section",
7d99d695 509 "section, id, course, summary, sequence, visible");
7468bf01 510}
511
b86fc0e2 512function course_set_display($courseid, $display=0) {
513 global $USER;
514
515 if (empty($USER)) {
516 return false;
517 }
518
519 if ($display == "all" or empty($display)) {
520 $display = 0;
521 }
522
523 if (record_exists("course_display", "userid", $USER->id, "course", $courseid)) {
524 set_field("course_display", "display", $display, "userid", $USER->id, "course", $courseid);
525 } else {
526 $record->userid = $USER->id;
527 $record->course = $courseid;
528 $record->display = $display;
529 if (!insert_record("course_display", $record)) {
530 notify("Could not save your course display!");
531 }
532 }
533
534 return $USER->display[$courseid] = $display; // Note: = not ==
535}
536
7d99d695 537function set_section_visible($courseid, $sectionnumber, $visibility) {
538/// For a given course section, markes it visible or hidden,
539/// and does the same for every activity in that section
540
541 if ($section = get_record("course_sections", "course", $courseid, "section", $sectionnumber)) {
542 set_field("course_sections", "visible", "$visibility", "id", $section->id);
543 if (!empty($section->sequence)) {
544 $modules = explode(",", $section->sequence);
545 foreach ($modules as $moduleid) {
546 set_field("course_modules", "visible", "$visibility", "id", $moduleid);
547 }
548 }
5867bfb5 549 rebuild_course_cache($courseid);
7d99d695 550 }
551}
ba2e5d73 552
5e367a2d 553function print_section_block($heading, $course, $section, $mods, $modnames, $modnamesused,
554 $absolute=true, $width="100%", $isediting=false) {
555
556 global $CFG;
557
558 $modinfo = unserialize($course->modinfo);
559 $moddata = array();
560 $modicon = array();
561 $editbuttons = "";
562
74666583 563 if (!empty($section->sequence)) {
5e367a2d 564
565 $sectionmods = explode(",", $section->sequence);
566
567 foreach ($sectionmods as $modnumber) {
568 $mod = $mods[$modnumber];
569 if ($isediting) {
1acfbce5 570 $editbuttons = make_editing_buttons($mod->id, $absolute, $mod->visible);
571 }
572 if ($mod->visible or isteacher($course->id)) {
573 $instancename = urldecode($modinfo[$modnumber]->name);
574 if ($mod->visible) {
575 $link_css = "";
576 } else {
577 $link_css = " class=\"dimmed\" ";
578 }
579 $modicon[] = "<img src=\"$CFG->wwwroot/mod/$mod->modname/icon.gif\" height=\"16\" width=\"16\" alt=\"$mod->modfullname\">";
580 $moddata[] = "<a title=\"$mod->modfullname\" $link_css href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename</a><BR>$editbuttons";
5e367a2d 581 }
5e367a2d 582 }
583 }
a44d18e7 584 if ($isediting) {
15ac9065 585 $editmenu = popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section->section&add=",
5e367a2d 586 $modnames, "section0", "", get_string("add")."...", "mods", get_string("activities"), true);
dfec7b01 587 $editmenu = "<div align=right>$editmenu</div>";
47f1da80 588 } else {
589 $editmenu = "";
5e367a2d 590 }
591
592 print_side_block($heading, "", $moddata, $modicon, $editmenu, $width);
593}
594
595
d897cae4 596function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%") {
94361e02 597 global $CFG;
598
c408b0c4 599 $modinfo = unserialize($course->modinfo);
94361e02 600
dfec7b01 601 echo "<table width=\"$width\"><tr><td>\n";
74666583 602 if (!empty($section->sequence)) {
94361e02 603
604 $sectionmods = explode(",", $section->sequence);
605
606 foreach ($sectionmods as $modnumber) {
9ae687af 607 if (empty($mods[$modnumber])) {
608 continue;
609 }
94361e02 610 $mod = $mods[$modnumber];
1acfbce5 611 if ($mod->visible or isteacher($course->id)) {
612 $instancename = urldecode($modinfo[$modnumber]->name);
613 if ($mod->visible) {
614 $link_css = "";
615 } else {
616 $link_css = " class=\"dimmed\" ";
617 }
dfec7b01 618 echo "<img src=\"$CFG->wwwroot/mod/$mod->modname/icon.gif\" height=16 width=16 alt=\"$mod->modfullname\">";
619 echo " <font size=2><a title=\"$mod->modfullname\" $link_css";
620 echo " href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename</a></font>";
1acfbce5 621 }
d897cae4 622 if (isediting($course->id)) {
5e367a2d 623 echo "&nbsp;&nbsp;";
1acfbce5 624 echo make_editing_buttons($mod->id, $absolute, $mod->visible);
625 }
626 if ($mod->visible or isteacher($course->id)) {
dfec7b01 627 echo "<br />\n";
94361e02 628 }
94361e02 629 }
630 }
dfec7b01 631 echo "</td></tr></table><br />\n\n";
a7ad3ea6 632}
633
5867bfb5 634
635function rebuild_course_cache($courseid=0) {
636// Rebuilds the cached list of course activities stored in the database
637// If a courseid is not specified, then all are rebuilt
638
639 if ($courseid) {
640 $select = "id = '$courseid'";
641 } else {
642 $select = "";
643 }
644
645 if ($courses = get_records_select("course", $select)) {
646 foreach ($courses as $course) {
647 $modinfo = serialize(get_array_of_activities($course->id));
648 if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) {
649 notify("Could not cache module information for course '$course->fullname'!");
650 }
651 }
652 }
653}
654
655
7541bc3e 656function print_heading_block($heading, $width="100%", $class="headingblock") {
5e367a2d 657 global $THEME;
658
7541bc3e 659 echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">";
660 echo "<tr><td bgcolor=\"$THEME->cellheading\" class=\"$class\">";
5e367a2d 661 echo stripslashes($heading);
662 echo "</td></tr></table>";
5e367a2d 663}
664
665function print_side_block($heading="", $content="", $list=NULL, $icons=NULL, $footer="", $width=180) {
666// Prints a nice side block with an optional header. The content can either
667// be a block of HTML or a list of text with optional icons.
a7ad3ea6 668
5e367a2d 669 global $THEME;
670
7541bc3e 671 print_side_block_start($heading, $width);
672
5e367a2d 673 if ($content) {
7541bc3e 674 echo "$content";
5e367a2d 675 } else {
5e367a2d 676 echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">";
677 foreach ($list as $key => $string) {
7541bc3e 678 echo "<tr bgcolor=\"$THEME->cellcontent2\">";
5e367a2d 679 if ($icons) {
7541bc3e 680 echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"16\">".$icons[$key]."</td>";
a7ad3ea6 681 }
7541bc3e 682 echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"*\"><font size=\"-1\">$string</font></td>";
5e367a2d 683 echo "</tr>";
a7ad3ea6 684 }
5e367a2d 685 if ($footer) {
7541bc3e 686 echo "<tr bgcolor=\"$THEME->cellcontent2\">";
5e367a2d 687 if ($icons) {
7541bc3e 688 echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"16\">&nbsp;</td>";
5e367a2d 689 }
7541bc3e 690 echo "<td class=\"sideblocklinks\"><font size=\"-1\">$footer</td>";
5e367a2d 691 echo "</tr>";
692 }
693 echo "</table>";
a7ad3ea6 694 }
5e367a2d 695
7541bc3e 696 print_side_block_end();
697}
698
699function print_side_block_start($heading="", $width=180, $class="sideblockmain") {
700// Starts a nice side block with an optional header.
701
702 global $THEME;
703
704 echo "<table class=\"sideblock\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">";
705 if ($heading) {
706 echo "<tr>";
707 echo "<td class=\"sideblockheading\" bgcolor=\"$THEME->cellheading\">$heading</td>";
708 echo "</tr>";
709 }
710 echo "<tr>";
711 echo "<td class=\"$class\" bgcolor=\"$THEME->cellcontent2\">";
712}
713
714function print_side_block_end() {
715 echo "</td></tr>";
7d99d695 716 echo "</table><br />";
94361e02 717}
718
5e367a2d 719
670fddf1 720function print_admin_links ($siteid, $width=180) {
dc0dc7d5 721 global $CFG, $THEME;
2b25f2a0 722
dc0dc7d5 723 if (empty($THEME->custompix)) {
724 $icon = "<img src=\"$CFG->wwwroot/pix/i/settings.gif\" height=16 width=16 alt=\"\">";
725 } else {
726 $icon = "<img src=\"$CFG->wwwroot/theme/$CFG->theme/pix/i/settings.gif\" height=16 width=16 alt=\"\">";
727 }
728
1924074c 729 if (isadmin()) {
5867bfb5 730 $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/config.php\">".get_string("configvariables")."</a>";
731 $modicon[]=$icon;
732 $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/site.php\">".get_string("sitesettings")."</a>";
1924074c 733 $modicon[]=$icon;
5867bfb5 734 $moddata[]="<a href=\"$CFG->wwwroot/course/log.php?id=$siteid\">".get_string("sitelogs")."</a>";
1924074c 735 $modicon[]=$icon;
5867bfb5 736 $moddata[]="<a href=\"$CFG->wwwroot/theme/index.php\">".get_string("choosetheme")."</a>";
1924074c 737 $modicon[]=$icon;
5867bfb5 738 $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/lang.php\">".get_string("checklanguage")."</a>";
1924074c 739 $modicon[]=$icon;
5867bfb5 740 $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/modules.php\">".get_string("managemodules")."</a>";
1924074c 741 $modicon[]=$icon;
be09831a 742 if (file_exists("$CFG->dirroot/$CFG->admin/$CFG->dbtype")) {
5867bfb5 743 $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/$CFG->dbtype/frame.php\">".get_string("managedatabase")."</a>";
1924074c 744 $modicon[]=$icon;
745 }
5867bfb5 746 $moddata[]="<hr>";
1924074c 747 $modicon[]="";
748 }
749 if (iscreator()) {
5867bfb5 750 $moddata[]="<a href=\"$CFG->wwwroot/course/edit.php\">".get_string("addnewcourse")."</a>";
1924074c 751 $modicon[]=$icon;
e808d25f 752 $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/teacher.php\">".get_string("assignteachers")."</a>";
1924074c 753 $modicon[]=$icon;
5b337cdf 754 $fulladmin = "";
1924074c 755 }
756 if (isadmin()) {
5867bfb5 757 $moddata[]="<a href=\"$CFG->wwwroot/course/categories.php\">".get_string("categories")."</a>";
1924074c 758 $modicon[]=$icon;
5867bfb5 759 $moddata[]="<a href=\"$CFG->wwwroot/course/delete.php\">".get_string("deletecourse")."</a>";
1924074c 760 $modicon[]=$icon;
5867bfb5 761 $moddata[]="<hr>";
1924074c 762 $modicon[]="";
3399a22c 763 if($CFG->auth == "email" || $CFG->auth == "none" || $CFG->auth == "manual"){
5867bfb5 764 $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/user.php?newuser=true\">".get_string("addnewuser")."</a>";
3399a22c 765 $modicon[]=$icon;
766 }
5867bfb5 767 $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/user.php\">".get_string("edituser")."</a>";
1924074c 768 $modicon[]=$icon;
5867bfb5 769 $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/admin.php\">".get_string("assignadmins")."</a>";
1924074c 770 $modicon[]=$icon;
5867bfb5 771 $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/creators.php\">".get_string("assigncreators")."</a>";
1924074c 772 $modicon[]=$icon;
5867bfb5 773 $moddata[]="<a href=\"$CFG->wwwroot/$CFG->admin/auth.php\">".get_string("authentication")."</a>";
1924074c 774 $modicon[]=$icon;
5867bfb5 775 $fulladmin = "<p><a href=\"$CFG->wwwroot/$CFG->admin/\">".get_string("admin")."</a>...";
1924074c 776 }
5e367a2d 777
778 print_side_block(get_string("administration"), "", $moddata, $modicon, $fulladmin, $width);
779
dc0dc7d5 780 echo "<img src=\"$CFG->wwwroot/pix/spacer.gif\" width=\"$width\" height=1><br>";
2b25f2a0 781}
782
b4d7002e 783function print_course_admin_links($course, $width=180) {
dc0dc7d5 784 global $USER, $CFG, $THEME;
44dad735 785
fce1ce13 786 if (isguest()) {
787 return true;
788 }
dc0dc7d5 789 if (empty($THEME->custompix)) {
790 $pixpath = "$CFG->wwwroot/pix";
791 $modpixpath = "$CFG->wwwroot/mod";
792 } else {
793 $pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix";
794 $modpixpath = "$CFG->wwwroot/theme/$CFG->theme/pix/mod";
795 }
13469b82 796 if (isteacher($course->id)) {
dc0dc7d5 797 $adminicon[]="<img src=\"$pixpath/i/edit.gif\" height=16 width=16 alt=\"\">";
13469b82 798 if (isediting($course->id)) {
dc0dc7d5 799 $admindata[]="<a href=\"view.php?id=$course->id&edit=off\">".get_string("turneditingoff")."</a>";
13469b82 800 } else {
dc0dc7d5 801 $admindata[]="<a href=\"view.php?id=$course->id&edit=on\">".get_string("turneditingon")."</a>";
13469b82 802 }
dc0dc7d5 803 $admindata[]="<a href=\"edit.php?id=$course->id\">".get_string("settings")."...</a>";
804 $adminicon[]="<img src=\"$pixpath/i/settings.gif\" height=16 width=16 alt=\"\">";
13469b82 805 if (!$course->teachers) {
806 $course->teachers = get_string("defaultcourseteachers");
807 }
dc0dc7d5 808 $admindata[]="<a href=\"teachers.php?id=$course->id\">$course->teachers...</a>";
809 $adminicon[]="<img src=\"$pixpath/i/settings.gif\" height=16 width=16 alt=\"\">";
13469b82 810
dc0dc7d5 811 $admindata[]="<a href=\"grades.php?id=$course->id\">".get_string("grades")."...</a>";
812 $adminicon[]="<img src=\"$pixpath/i/grades.gif\" height=16 width=16 alt=\"\">";
13469b82 813
dc0dc7d5 814 $admindata[]="<a href=\"log.php?id=$course->id\">".get_string("logs")."...</a>";
815 $adminicon[]="<img src=\"$pixpath/i/log.gif\" height=16 width=16 alt=\"\">";
816
817 $admindata[]="<a href=\"$CFG->wwwroot/files/index.php?id=$course->id\">".get_string("files")."...</a>";
818 $adminicon[]="<img src=\"$pixpath/i/files.gif\" height=16 width=16 alt=\"\">";
13469b82 819
dc0dc7d5 820 $admindata[]="<a href=\"$CFG->wwwroot/doc/view.php?id=$course->id&file=teacher.html\">".get_string("help")."...</a>";
821 $adminicon[]="<img src=\"$modpixpath/resource/icon.gif\" height=16 width=16 alt=\"\">";
b4d7002e 822
13469b82 823 if ($teacherforum = forum_get_course_forum($course->id, "teacher")) {
dc0dc7d5 824 $admindata[]="<a href=\"$CFG->wwwroot/mod/forum/view.php?f=$teacherforum->id\">".get_string("nameteacher", "forum")."</a>";
825 $adminicon[]="<img src=\"$modpixpath/forum/icon.gif\" height=16 width=16 alt=\"\">";
13469b82 826 }
827 } else {
dc0dc7d5 828 $admindata[]="<a href=\"grade.php?id=$course->id\">".get_string("grades")."...</a>";
829 $adminicon[]="<img src=\"$pixpath/i/grades.gif\" height=16 width=16 alt=\"\">";
13469b82 830 }
44dad735 831
5e367a2d 832 print_side_block(get_string("administration"), "", $admindata, $adminicon, "", $width);
44dad735 833}
2b25f2a0 834
ba2e5d73 835function print_course_categories($categories, $selected="none", $width=180) {
0a263205 836 global $CFG, $THEME, $USER;
85098089 837
838 $strallowguests = get_string("allowguests");
839 $strrequireskey = get_string("requireskey");
ba2e5d73 840
dc0dc7d5 841 if (empty($THEME->custompix)) {
842 $pixpath = "$CFG->wwwroot/pix";
843 } else {
844 $pixpath = "$CFG->wwwroot/theme/$CFG->theme/pix";
845 }
846
0c656181 847 if ($selected == "index") { // Print comprehensive index of categories with courses
9fa49e22 848 if ($courses = get_courses()) {
0c656181 849 if (isset($USER->id) and !isadmin()) {
39246b72 850 print_simple_box_start("CENTER", "100%", $THEME->cellheading);
dc0dc7d5 851 print_heading("<a href=\"course/index.php?category=my\">".get_string("mycourses")."</a>", "left");
0c656181 852 $some = false;
dc0dc7d5 853 echo "<ul>";
0c656181 854 foreach ($courses as $key => $course) {
855 if (isteacher($course->id) or isstudent($course->id)) {
dc0dc7d5 856 echo "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>";
857 echo "<br />";
0c656181 858 $some = true;
859 }
860 }
861 if (!$some) {
862 print_string("nocoursesyet");
863 }
dc0dc7d5 864 echo "</ul>";
0c656181 865 print_simple_box_end();
866 print_spacer(8,1);
867 }
868 foreach ($categories as $category) {
bd4707bf 869 print_simple_box_start("CENTER", "100%");
dc0dc7d5 870 print_heading("<a href=\"course/index.php?category=$category->id\">$category->name</a>", "left");
0c656181 871 $some = false;
dc0dc7d5 872 echo "<ul>";
0c656181 873 foreach ($courses as $key => $course) {
874 if ($course->category == $category->id) {
dc0dc7d5 875 echo "<a href=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</a>";
85098089 876 echo "&nbsp;&nbsp;";
0c656181 877 unset($courses[$key]);
85098089 878 if ($course->guest ) {
dc0dc7d5 879 echo "<a title=\"$strallowguests\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
880 echo "<img alt=\"\" height=16 width=16 border=0 src=\"$pixpath/i/user.gif\"></a>";
85098089 881 }
882 if ($course->password) {
dc0dc7d5 883 echo "<a title=\"$strrequireskey\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
884 echo "<img alt=\"\" height=16 width=16 border=0 src=\"$pixpath/i/key.gif\"></a>";
85098089 885 }
dc0dc7d5 886 echo "<br />";
0c656181 887 $some = true;
888 }
889 }
890 if (!$some) {
891 print_string("nocoursesyet");
892 }
dc0dc7d5 893 echo "</ul>";
0c656181 894 print_simple_box_end();
895 print_spacer(8,1);
896 }
ba2e5d73 897 }
0c656181 898
899 } else { // Print short list of categories only
900 foreach ($categories as $cat) {
dc0dc7d5 901 $caticon[]="<img src=\"$pixpath/i/course.gif\" height=16 width=16>";
0c656181 902 if ($cat->id == $selected) {
903 $catdata[]="$cat->name";
904 } else {
dc0dc7d5 905 $catdata[]="<a href=\"$CFG->wwwroot/course/index.php?category=$cat->id\">$cat->name</a>";
0c656181 906 }
907 }
dc0dc7d5 908 $catdata[] = "<a href=\"$CFG->wwwroot/course/index.php?category=all\">".get_string("fulllistofcourses")."</a>";
13770d0c 909 $caticon[] = "";
0c656181 910 if (isset($USER->id)) {
dc0dc7d5 911 $catdata[] = "<a href=\"$CFG->wwwroot/course/index.php?category=my\">".get_string("mycourses")."</a>";
13770d0c 912 $caticon[] = "";
0c656181 913 }
13770d0c 914 print_side_block(get_string("categories"), "", $catdata, $caticon, "", $width);
ba2e5d73 915 }
ba2e5d73 916}
94361e02 917
2b8cef80 918function print_log_graph($course, $userid=0, $type="course.png", $date=0) {
919 global $CFG;
607809b3 920 if (empty($CFG->gdversion)) {
921 echo "(".get_string("gdneed").")";
922 } else {
923 echo "<IMG BORDER=0 SRC=\"$CFG->wwwroot/course/loggraph.php?id=$course->id&user=$userid&type=$type&date=$date\">";
924 }
2b8cef80 925}
926
11b0c469 927
928
929/// MODULE FUNCTIONS /////////////////////////////////////////////////////////////////
930
931function add_course_module($mod) {
932 GLOBAL $db;
933
e5dfd0f3 934 $mod->added = time();
11b0c469 935
e5dfd0f3 936 return insert_record("course_modules", $mod);
11b0c469 937}
938
939function add_mod_to_section($mod) {
940// Returns the course_sections ID where the mod is inserted
941 GLOBAL $db;
942
9fa49e22 943 if ($section = get_record("course_sections", "course", "$mod->course", "section", "$mod->section")) {
74666583 944 if (!empty($section->sequence)) {
e5dfd0f3 945 $newsequence = "$section->sequence,$mod->coursemodule";
11b0c469 946 } else {
947 $newsequence = "$mod->coursemodule";
948 }
e5dfd0f3 949 if (set_field("course_sections", "sequence", $newsequence, "id", $section->id)) {
950 return $section->id; // Return course_sections ID that was used.
11b0c469 951 } else {
e5dfd0f3 952 return 0;
11b0c469 953 }
954
955 } else { // Insert a new record
e5dfd0f3 956 $section->course = $mod->course;
957 $section->section = $mod->section;
958 $section->summary = "";
959 $section->sequence = $mod->coursemodule;
960 return insert_record("course_sections", $section);
11b0c469 961 }
962}
963
1acfbce5 964function hide_course_module($mod) {
965 return set_field("course_modules", "visible", 0, "id", $mod);
966}
967
968function show_course_module($mod) {
969 return set_field("course_modules", "visible", 1, "id", $mod);
970}
971
11b0c469 972function delete_course_module($mod) {
973 return set_field("course_modules", "deleted", 1, "id", $mod);
974}
975
976function delete_mod_from_section($mod, $section) {
977 GLOBAL $db;
978
e5dfd0f3 979 if ($section = get_record("course_sections", "id", "$section") ) {
11b0c469 980
e5dfd0f3 981 $modarray = explode(",", $section->sequence);
11b0c469 982
983 if ($key = array_keys ($modarray, $mod)) {
984 array_splice($modarray, $key[0], 1);
985 $newsequence = implode(",", $modarray);
e5dfd0f3 986 return set_field("course_sections", "sequence", $newsequence, "id", $section->id);
11b0c469 987 } else {
988 return false;
989 }
990
991 } else {
992 return false;
993 }
994}
995
996
7c0f2984 997function move_module($cm, $move) {
11b0c469 998 GLOBAL $db;
999
1000 if (!$move) {
1001 return true;
1002 }
1003
11b0c469 1004 if (! $thissection = get_record("course_sections", "id", $cm->section)) {
1005 error("This course section doesn't exist");
1006 }
1007
1008 $mods = explode(",", $thissection->sequence);
1009
1010 $len = count($mods);
1011 $pos = array_keys($mods, $cm->id);
1012 $thepos = $pos[0];
1013
1014 if ($len == 0 || count($pos) == 0 ) {
1015 error("Very strange. Could not find the required module in this section.");
1016 }
1017
1018 if ($len == 1) {
1019 $first = true;
1020 $last = true;
1021 } else {
1022 $first = ($thepos == 0);
1023 $last = ($thepos == $len - 1);
1024 }
1025
1026 if ($move < 0) { // Moving the module up
1027
1028 if ($first) {
ad41694c 1029 if ($thissection->section == 0) { // First section, do nothing
11b0c469 1030 return true;
ad41694c 1031
11b0c469 1032 } else { // Push onto end of previous section
1033 $prevsectionnumber = $thissection->section - 1;
9fa49e22 1034 if (! $prevsection = get_record("course_sections", "course", "$thissection->course",
1035 "section", "$prevsectionnumber")) {
11b0c469 1036 error("Previous section ($prevsection->id) doesn't exist");
1037 }
1038
74666583 1039 if (!empty($prevsection->sequence)) {
11b0c469 1040 $newsequence = "$prevsection->sequence,$cm->id";
1041 } else {
1042 $newsequence = "$cm->id";
1043 }
1044
1045 if (! set_field("course_sections", "sequence", $newsequence, "id", $prevsection->id)) {
1046 error("Previous section could not be updated");
1047 }
1048
1049 if (! set_field("course_modules", "section", $prevsection->id, "id", $cm->id)) {
1050 error("Module could not be updated");
1051 }
1052
1053 array_splice($mods, 0, 1);
1054 $newsequence = implode(",", $mods);
1055 if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
1056 error("Module could not be updated");
1057 }
1058
1059 return true;
1060
1061 }
1062 } else { // move up within this section
1063 $swap = $mods[$thepos-1];
1064 $mods[$thepos-1] = $mods[$thepos];
1065 $mods[$thepos] = $swap;
1066
1067 $newsequence = implode(",", $mods);
1068 if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
1069 error("This section could not be updated");
1070 }
1071 return true;
1072 }
1073
1074 } else { // Moving the module down
1075
1076 if ($last) {
1077 $nextsectionnumber = $thissection->section + 1;
9fa49e22 1078 if ($nextsection = get_record("course_sections", "course", "$thissection->course",
1079 "section", "$nextsectionnumber")) {
11b0c469 1080
74666583 1081 if (!empty($nextsection->sequence)) {
11b0c469 1082 $newsequence = "$cm->id,$nextsection->sequence";
1083 } else {
1084 $newsequence = "$cm->id";
1085 }
1086
1087 if (! set_field("course_sections", "sequence", $newsequence, "id", $nextsection->id)) {
1088 error("Next section could not be updated");
1089 }
1090
1091 if (! set_field("course_modules", "section", $nextsection->id, "id", $cm->id)) {
1092 error("Module could not be updated");
1093 }
1094
1095 array_splice($mods, $thepos, 1);
1096 $newsequence = implode(",", $mods);
1097 if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
1098 error("This section could not be updated");
1099 }
1100 return true;
1101
1102 } else { // There is no next section, so just return
1103 return true;
1104
1105 }
1106 } else { // move down within this section
1107 $swap = $mods[$thepos+1];
1108 $mods[$thepos+1] = $mods[$thepos];
1109 $mods[$thepos] = $swap;
1110
1111 $newsequence = implode(",", $mods);
1112 if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
1113 error("This section could not be updated");
1114 }
1115 return true;
1116 }
1117 }
1118}
1119
1acfbce5 1120function make_editing_buttons($moduleid, $absolute=false, $visible=true, $str=NULL) {
dc0dc7d5 1121 global $CFG, $THEME;
94361e02 1122
1acfbce5 1123 if (empty($str)) {
1124 $str->delete = get_string("delete");
1125 $str->moveup = get_string("moveup");
1126 $str->movedown = get_string("movedown");
1127 $str->update = get_string("update");
1128 $str->hide = get_string("hide");
1129 $str->show = get_string("show");
1130 }
94361e02 1131
1132 if ($absolute) {
dc0dc7d5 1133 $path = "$CFG->wwwroot/course";
1134 } else {
1135 $path = ".";
1136 }
1137
1138 if (empty($THEME->custompix)) {
1139 $pixpath = "$path/../pix";
94361e02 1140 } else {
dc0dc7d5 1141 $pixpath = "$path/../theme/$CFG->theme/pix";
94361e02 1142 }
1acfbce5 1143
1144 if ($visible) {
dc0dc7d5 1145 $hideshow = " <a title=\"$str->hide\" href=\"$path/mod.php?hide=$moduleid\"><img
3bb49201 1146 src=\"$pixpath/t/hide.gif\" hspace=2 height=11 width=11 border=0></a>";
1acfbce5 1147 } else {
dc0dc7d5 1148 $hideshow = " <a title=\"$str->show\" href=\"$path/mod.php?show=$moduleid\"><img
3bb49201 1149 src=\"$pixpath/t/show.gif\" hspace=2 height=11 width=11 border=0></a>";
1acfbce5 1150 }
1151
dc0dc7d5 1152 return "<a title=\"$str->delete\" href=\"$path/mod.php?delete=$moduleid\"><img
1153 src=\"$pixpath/t/delete.gif\" height=11 width=11 border=0></a>
1154 <a title=\"$str->moveup\" href=\"$path/mod.php?id=$moduleid&move=-1\"><img
1155 src=\"$pixpath/t/up.gif\" height=11 width=11 border=0></a>
1156 <a title=\"$str->movedown\" href=\"$path/mod.php?id=$moduleid&move=1\"><img
1157 src=\"$pixpath/t/down.gif\" height=11 width=11 border=0></a>
1158 <a title=\"$str->update\" href=\"$path/mod.php?update=$moduleid\"><img
1159 src=\"$pixpath/t/edit.gif\" height=11 width=11 border=0></a> $hideshow";
90845098 1160}
1161
f9903ed0 1162?>