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