fixes for small bugs in datetimeselector and dateselector and added custom elements...
[moodle.git] / course / lib.php
CommitLineData
e4027ac9 1<?php // $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
92890025 9define('COURSE_MAX_LOG_DISPLAY', 150); // days
10define('COURSE_MAX_LOGS_PER_PAGE', 1000); // records
11define('COURSE_LIVELOG_REFRESH', 60); // Seconds
12define('COURSE_MAX_RECENT_PERIOD', 172800); // Two days, in seconds
13define('COURSE_MAX_SUMMARIES_PER_PAGE', 10); // courses
950c35a9 14define('COURSE_MAX_COURSES_PER_DROPDOWN',1000); // max courses in log dropdown before switching to optional
92890025 15define('COURSE_MAX_USERS_PER_DROPDOWN',1000); // max users in log dropdown before switching to optional
16define('FRONTPAGENEWS', 0);
6f24e48e 17define('FRONTPAGECOURSELIST', 1);
18define('FRONTPAGECATEGORYNAMES', 2);
19define('FRONTPAGETOPICONLY', 3);
20define('FRONTPAGECATEGORYCOMBO', 4);
21define('FRONTPAGECOURSELIMIT', 200); // maximum number of courses displayed on the frontpage
22define('EXCELROWS', 65535);
23define('FIRSTUSEDEXCELROW', 3);
60fdc714 24
f9903ed0 25
587510be 26function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0, $selecteddate="lastlogin",
4581271a 27 $mod="", $modid="activity/All", $modaction="", $selectedgroup="", $selectedsort="default") {
cb83c3cb 28
29 global $USER, $CFG;
30
587510be 31 if ($advancedfilter) {
32
33 // Get all the possible users
34 $users = array();
89adb174 35
65ee9c16 36 if ($courseusers = get_course_users($course->id, '', '', 'u.id, u.firstname, u.lastname')) {
587510be 37 foreach ($courseusers as $courseuser) {
1c45e42e 38 $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
587510be 39 }
cb83c3cb 40 }
587510be 41 if ($guest = get_guest()) {
42 $users[$guest->id] = fullname($guest);
43 }
89adb174 44
51792df0 45 if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
587510be 46 if ($ccc = get_records("course", "", "", "fullname")) {
47 foreach ($ccc as $cc) {
48 if ($cc->category) {
49 $courses["$cc->id"] = "$cc->fullname";
50 } else {
51 $courses["$cc->id"] = " $cc->fullname (Site)";
89adb174 52 }
587510be 53 }
cb83c3cb 54 }
587510be 55 asort($courses);
56 }
4581271a 57
587510be 58 $activities = array();
cb83c3cb 59
587510be 60 $selectedactivity = $modid;
4581271a 61
fea43a7f 62 /// Casting $course->modinfo to string prevents one notice when the field is null
63 if ($modinfo = unserialize((string)$course->modinfo)) {
587510be 64 $section = 0;
65 if ($course->format == 'weeks') { // Body
66 $strsection = get_string("week");
67 } else {
68 $strsection = get_string("topic");
cb83c3cb 69 }
cb83c3cb 70
587510be 71 $activities["activity/All"] = "All activities";
72 $activities["activity/Assignments"] = "All assignments";
73 $activities["activity/Chats"] = "All chats";
74 $activities["activity/Forums"] = "All forums";
75 $activities["activity/Quizzes"] = "All quizzes";
76 $activities["activity/Workshops"] = "All workshops";
77
78 $activities["section/individual"] = "------------- Individual Activities --------------";
79
80 foreach ($modinfo as $mod) {
81 if ($mod->mod == "label") {
82 continue;
89adb174 83 }
3924b988 84 if (!$mod->visible and !has_capability('moodle/course:viewhiddenactivities',get_context_instance(CONTEXT_MODULE, $mod->cm))) {
9c08ad13 85 continue;
86 }
87
587510be 88 if ($mod->section > 0 and $section <> $mod->section) {
89 $activities["section/$mod->section"] = "-------------- $strsection $mod->section --------------";
90 }
91 $section = $mod->section;
235a4ee8 92 $mod->name = strip_tags(format_string(urldecode($mod->name),true));
587510be 93 if (strlen($mod->name) > 55) {
94 $mod->name = substr($mod->name, 0, 50)."...";
95 }
96 if (!$mod->visible) {
97 $mod->name = "(".$mod->name.")";
98 }
99 $activities["$mod->cm"] = $mod->name;
100
101 if ($mod->cm == $modid) {
102 $selectedactivity = "$mod->cm";
103 }
cb83c3cb 104 }
105 }
cb83c3cb 106
587510be 107 $strftimedate = get_string("strftimedate");
108 $strftimedaydate = get_string("strftimedaydate");
cb83c3cb 109
587510be 110 asort($users);
cb83c3cb 111
587510be 112 // Get all the possible dates
113 // Note that we are keeping track of real (GMT) time and user time
114 // User time is only used in displays - all calcs and passing is GMT
cb83c3cb 115
587510be 116 $timenow = time(); // GMT
cb83c3cb 117
587510be 118 // What day is it now for the user, and when is midnight that day (in GMT).
119 $timemidnight = $today = usergetmidnight($timenow);
cb83c3cb 120
587510be 121 $dates = array();
122 $dates["$USER->lastlogin"] = get_string("lastlogin").", ".userdate($USER->lastlogin, $strftimedate);
123 $dates["$timemidnight"] = get_string("today").", ".userdate($timenow, $strftimedate);
cb83c3cb 124
587510be 125 if (!$course->startdate or ($course->startdate > $timenow)) {
126 $course->startdate = $course->timecreated;
127 }
cb83c3cb 128
587510be 129 $numdates = 1;
130 while ($timemidnight > $course->startdate and $numdates < 365) {
131 $timemidnight = $timemidnight - 86400;
132 $timenow = $timenow - 86400;
133 $dates["$timemidnight"] = userdate($timenow, $strftimedaydate);
134 $numdates++;
135 }
cb83c3cb 136
96dcfb56 137 if ($selecteddate === "lastlogin") {
587510be 138 $selecteddate = $USER->lastlogin;
139 }
140
141 echo '<form action="recent.php" method="get">';
1c919752 142 echo '<input type="hidden" name="chooserecent" value="1" />';
587510be 143 echo "<center>";
144 echo "<table>";
145
51792df0 146 if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
587510be 147 echo "<tr><td><b>" . get_string("courses") . "</b></td><td>";
148 choose_from_menu ($courses, "id", $course->id, "");
149 echo "</td></tr>";
150 } else {
1c919752 151 echo '<input type="hidden" name="id" value="'.$course->id.'" />';
587510be 152 }
cb83c3cb 153
f5ffb87d 154 $sortfields = array("default" => get_string("bycourseorder"),"dateasc" => get_string("datemostrecentlast"), "datedesc" => get_string("datemostrecentfirst"));
4581271a 155
587510be 156 echo "<tr><td><b>" . get_string("participants") . "</b></td><td>";
157 choose_from_menu ($users, "user", $selecteduser, get_string("allparticipants") );
158 echo "</td>";
159
1c919752 160 echo '<td align="right"><b>' . get_string("since") . '</b></td><td>';
587510be 161 choose_from_menu ($dates, "date", $selecteddate, get_string("alldays"));
4581271a 162 echo "</td></tr>";
4581271a 163
587510be 164 echo "<tr><td><b>" . get_string("activities") . "</b></td><td>";
165 choose_from_menu ($activities, "modid", $selectedactivity, "");
166 echo "</td>";
4581271a 167
1c919752 168 echo '<td align="right"><b>' . get_string("sortby") . "</b></td><td>";
587510be 169 choose_from_menu ($sortfields, "sortby", $selectedsort, "");
170 echo "</td></tr>";
4581271a 171
587510be 172 echo '<tr>';
4581271a 173
587510be 174 $groupmode = groupmode($course);
4581271a 175
3924b988 176 if ($groupmode == VISIBLEGROUPS or ($groupmode and has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id)))) {
587510be 177 if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
4581271a 178 echo '<td><b>';
587510be 179 if ($groupmode == VISIBLEGROUPS) {
180 print_string('groupsvisible');
181 } else {
182 print_string('groupsseparate');
183 }
184 echo ':</b></td><td>';
185 choose_from_menu($groups, "selectedgroup", $selectedgroup, get_string("allgroups"), "", "");
186 echo '</td>';
187 }
188 }
189
190
1c919752 191 echo '<td colspan="2" align="right">';
192 echo '<input type="submit" value="'.get_string('showrecent').'" />';
587510be 193 echo "</td></tr>";
194
195 echo "</table>";
196
839f2456 197 $advancedlink = "<a href=\"$CFG->wwwroot/course/recent.php?id=$course->id&amp;advancedfilter=0\">" . get_string("normalfilter") . "</a>";
587510be 198 print_heading($advancedlink);
199 echo "</center>";
200 echo "</form>";
201
202 } else {
203
204 $day_list = array("1","7","14","21","30");
205 $strsince = get_string("since");
206 $strlastlogin = get_string("lastlogin");
207 $strday = get_string("day");
208 $strdays = get_string("days");
209
210 $heading = "";
211 foreach ($day_list as $count) {
212 if ($count == "1") {
213 $day = $strday;
4581271a 214 } else {
587510be 215 $day = $strdays;
4581271a 216 }
3819ed31 217 $tmpdate = time() - ($count * 3600 * 24);
587510be 218 $heading = $heading .
839f2456 219 "<a href=\"$CFG->wwwroot/course/recent.php?id=$course->id&amp;date=$tmpdate\"> $count $day</a> | ";
4581271a 220 }
4581271a 221
587510be 222 $heading = $strsince . ": <a href=\"$CFG->wwwroot/course/recent.php?id=$course->id\">$strlastlogin</a>" . " | " . $heading;
223 print_heading($heading);
4581271a 224
839f2456 225 $advancedlink = "<a href=\"$CFG->wwwroot/course/recent.php?id=$course->id&amp;advancedfilter=1\">" . get_string("advancedfilter") . "</a>";
587510be 226 print_heading($advancedlink);
227
228 }
4581271a 229
cb83c3cb 230}
9ae687af 231
f9903ed0 232
600149be 233function make_log_url($module, $url) {
234 switch ($module) {
bd7be234 235 case 'user':
236 case 'course':
237 case 'file':
238 case 'login':
239 case 'lib':
240 case 'admin':
241 case 'message':
242 case 'calendar':
243 case 'blog':
600149be 244 return "/$module/$url";
245 break;
bd7be234 246 case 'upload':
247 return $url;
c80b7585 248 break;
bd7be234 249 case 'library':
250 case '':
251 return '/';
de2dfe68 252 break;
600149be 253 default:
254 return "/mod/$module/$url";
255 break;
256 }
257}
258
92890025 259
260function build_logs_array($course, $user=0, $date=0, $order="l.time ASC", $limitfrom='', $limitnum='',
261 $modname="", $modid=0, $modaction="", $groupid=0) {
f24cffb9 262
e0161bff 263 // It is assumed that $date is the GMT time of midnight for that day,
264 // and so the next 86400 seconds worth of logs are printed.
f9903ed0 265
69c76405 266 /// Setup for group handling.
1c45e42e 267
69c76405 268 /// If the group mode is separate, and this user does not have editing privileges,
269 /// then only the user's group can be viewed.
3924b988 270 if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
69c76405 271 $groupid = get_current_group($course->id);
272 }
273 /// If this course doesn't have groups, no groupid can be specified.
274 else if (!$course->groupmode) {
275 $groupid = 0;
276 }
277
e0161bff 278 $joins = array();
a2ab3b05 279
e15ef260 280 if ($course->id != SITEID || $modid != 0) {
8f0cd6ef 281 $joins[] = "l.course='$course->id'";
e15ef260 282 }
f9903ed0 283
c469a7ef 284 if ($modname) {
e0161bff 285 $joins[] = "l.module = '$modname'";
f24cffb9 286 }
287
e21922f0 288 if ('site_errors' === $modid) {
bf35eb15 289 $joins[] = "( l.action='error' OR l.action='infected' )";
e21922f0 290 } else if ($modid) {
291 $joins[] = "l.cmid = '$modid'";
69d79bc3 292 }
293
294 if ($modaction) {
ee35e0b8 295 $firstletter = substr($modaction, 0, 1);
296 if (ctype_alpha($firstletter)) {
297 $joins[] = "lower(l.action) LIKE '%" . strtolower($modaction) . "%'";
298 } else if ($firstletter == '-') {
299 $joins[] = "lower(l.action) NOT LIKE '%" . strtolower(substr($modaction, 1)) . "%'";
300 }
f24cffb9 301 }
302
69c76405 303 /// Getting all members of a group.
304 if ($groupid and !$user) {
305 if ($gusers = get_records('groups_members', 'groupid', $groupid)) {
306 $first = true;
307 foreach($gusers as $guser) {
308 if ($first) {
309 $gselect = '(l.userid='.$guser->userid;
310 $first = false;
311 }
312 else {
313 $gselect .= ' OR l.userid='.$guser->userid;
314 }
315 }
316 if (!$first) $gselect .= ')';
317 $joins[] = $gselect;
318 }
319 }
320 else if ($user) {
e0161bff 321 $joins[] = "l.userid = '$user'";
f9903ed0 322 }
323
324 if ($date) {
325 $enddate = $date + 86400;
e0161bff 326 $joins[] = "l.time > '$date' AND l.time < '$enddate'";
f9903ed0 327 }
328
2828ff51 329 $selector = '';
e0161bff 330 for ($i = 0; $i < count($joins); $i++) {
331 $selector .= $joins[$i] . (($i == count($joins)-1) ? " " : " AND ");
332 }
333
d09f3c80 334 $totalcount = 0; // Initialise
92890025 335
336 $result = array();
337 $result['logs'] = get_logs($selector, $order, $limitfrom, $limitnum, $totalcount);
338 $result['totalcount'] = $totalcount;
339 return $result;
340}
341
342
343function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $perpage=100,
344 $url="", $modname="", $modid=0, $modaction="", $groupid=0) {
345
346 global $CFG;
347
348 if (!$logs = build_logs_array($course, $user, $date, $order, $page*$perpage, $perpage,
349 $modname, $modid, $modaction, $groupid)) {
f9903ed0 350 notify("No logs found!");
351 print_footer($course);
352 exit;
353 }
92890025 354
355 if ($course->id == SITEID) {
356 $courses[0] = '';
5ed3bf22 357 if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname,c.visible')) {
92890025 358 foreach ($ccc as $cc) {
359 $courses[$cc->id] = $cc->shortname;
360 }
361 }
362 }
363
364 $totalcount = $logs['totalcount'];
f9903ed0 365 $count=0;
2eb68e6f 366 $ldcache = array();
f9903ed0 367 $tt = getdate(time());
368 $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
1c0200e0 369
dcde9f02 370 $strftimedatetime = get_string("strftimedatetime");
371
21283ddc 372 echo "<p align=\"center\">\n";
519d369f 373 print_string("displayingrecords", "", $totalcount);
21283ddc 374 echo "</p>\n";
1c0200e0 375
8f0cd6ef 376 print_paging_bar($totalcount, $page, $perpage, "$url&amp;perpage=$perpage&amp;");
519d369f 377
21283ddc 378 echo "<table class=\"logtable\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"0\">\n";
379 echo "<tr>";
1548978d 380 if ($course->id == SITEID) {
21283ddc 381 echo "<th class=\"c0 header\">".get_string('course')."</th>\n";
1548978d 382 }
21283ddc 383 echo "<th class=\"c1 header\">".get_string('time')."</th>\n";
384 echo "<th class=\"c2 header\">".get_string('ip_address')."</th>\n";
385 echo "<th class=\"c3 header\">".get_string('fullname')."</th>\n";
386 echo "<th class=\"c4 header\">".get_string('action')."</th>\n";
387 echo "<th class=\"c5 header\">".get_string('info')."</th>\n";
388 echo "</tr>\n";
1548978d 389
2b2d182a 390 if (empty($logs['logs'])) {
391 echo "</table>\n";
392 return;
393 }
394
1548978d 395 $row = 1;
92890025 396 foreach ($logs['logs'] as $log) {
600149be 397
1548978d 398 $row = ($row + 1) % 2;
399
2eb68e6f 400 if (isset($ldcache[$log->module][$log->action])) {
401 $ld = $ldcache[$log->module][$log->action];
402 } else {
1548978d 403 $ld = get_record('log_display', 'module', $log->module, 'action', $log->action);
2eb68e6f 404 $ldcache[$log->module][$log->action] = $ld;
405 }
76feee3f 406 if ($ld && !empty($log->info)) {
181b888e 407 // ugly hack to make sure fullname is shown correctly
4068bedb 408 if (($ld->mtable == 'user') and ($ld->field == sql_concat('firstname', "' '" , 'lastname'))) {
181b888e 409 $log->info = fullname(get_record($ld->mtable, 'id', $log->info), true);
410 } else {
411 $log->info = get_field($ld->mtable, $ld->field, 'id', $log->info);
412 }
600149be 413 }
414
c8b0a50b 415 //Filter log->info
416 $log->info = format_string($log->info);
417
d7d145b1 418 $log->url = strip_tags(urldecode($log->url)); // Some XSS protection
419 $log->info = strip_tags(urldecode($log->info)); // Some XSS protection
6ac98433 420 $log->url = str_replace('&', '&amp;', $log->url); /// XHTML compatibility
d7d145b1 421
1548978d 422 echo '<tr class="r'.$row.'">';
423 if ($course->id == SITEID) {
21283ddc 424 echo "<td class=\"r$row c0\" nowrap=\"nowrap\">\n";
81e10e95 425 echo " <a href=\"{$CFG->wwwroot}/course/view.php?id={$log->course}\">".$courses[$log->course]."</a>\n";
21283ddc 426 echo "</td>\n";
720a43ce 427 }
21283ddc 428 echo "<td class=\"r$row c1\" nowrap=\"nowrap\" align=\"right\">".userdate($log->time, '%a').
429 ' '.userdate($log->time, $strftimedatetime)."</td>\n";
430 echo "<td class=\"r$row c2\" nowrap=\"nowrap\">\n";
7eca967c 431 link_to_popup_window("/iplookup/index.php?ip=$log->ip&amp;user=$log->userid", 'iplookup',$log->ip, 400, 700);
21283ddc 432 echo "</td>\n";
1c45e42e 433 $fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
21283ddc 434 echo "<td class=\"r$row c3\" nowrap=\"nowrap\">\n";
d3a75287 435 echo " <a href=\"$CFG->wwwroot/user/view.php?id={$log->userid}&amp;course={$log->course}\">$fullname</a>\n";
21283ddc 436 echo "</td>\n";
437 echo "<td class=\"r$row c4\" nowrap=\"nowrap\">\n";
2eb68e6f 438 link_to_popup_window( make_log_url($log->module,$log->url), 'fromloglive',"$log->module $log->action", 400, 600);
21283ddc 439 echo "</td>\n";;
440 echo "<td class=\"r$row c5\" nowrap=\"nowrap\">{$log->info}</td>\n";
441 echo "</tr>\n";
f9903ed0 442 }
21283ddc 443 echo "</table>\n";
519d369f 444
8f0cd6ef 445 print_paging_bar($totalcount, $page, $perpage, "$url&amp;perpage=$perpage&amp;");
f9903ed0 446}
447
448
92890025 449function print_log_csv($course, $user, $date, $order='l.time DESC', $modname,
450 $modid, $modaction, $groupid) {
4068bedb 451
954fdb42 452 $text = get_string('course')."\t".get_string('time')."\t".get_string('ip_address')."\t".
453 get_string('fullname')."\t".get_string('action')."\t".get_string('info');
454
455 if (!$logs = build_logs_array($course, $user, $date, $order, '', '',
92890025 456 $modname, $modid, $modaction, $groupid)) {
457 return false;
458 }
459
460 if ($course->id == SITEID) {
461 $courses[0] = '';
462 if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
463 foreach ($ccc as $cc) {
464 $courses[$cc->id] = $cc->shortname;
465 }
466 }
467 }
954fdb42 468
92890025 469 $count=0;
470 $ldcache = array();
471 $tt = getdate(time());
472 $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
473
474 $strftimedatetime = get_string("strftimedatetime");
92890025 475
954fdb42 476 $filename = 'logs_'.userdate(time(),get_string('backupnameformat'),99,false);
477 $filename .= '.txt';
478 header("Content-Type: application/download\n");
479 header("Content-Disposition: attachment; filename=$filename");
480 header("Expires: 0");
481 header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
482 header("Pragma: public");
483
484 echo get_string('savedat').userdate(time(), $strftimedatetime)."\n";
485 echo $text;
486
2b2d182a 487 if (empty($logs['logs'])) {
488 return true;
489 }
490
954fdb42 491 foreach ($logs['logs'] as $log) {
492 if (isset($ldcache[$log->module][$log->action])) {
493 $ld = $ldcache[$log->module][$log->action];
494 } else {
495 $ld = get_record('log_display', 'module', $log->module, 'action', $log->action);
496 $ldcache[$log->module][$log->action] = $ld;
497 }
498 if ($ld && !empty($log->info)) {
499 // ugly hack to make sure fullname is shown correctly
4068bedb 500 if (($ld->mtable == 'user') and ($ld->field == sql_concat('firstname', "' '" , 'lastname'))) {
954fdb42 501 $log->info = fullname(get_record($ld->mtable, 'id', $log->info), true);
502 } else {
503 $log->info = get_field($ld->mtable, $ld->field, 'id', $log->info);
504 }
505 }
506
507 //Filter log->info
508 $log->info = format_string($log->info);
509
510 $log->url = strip_tags(urldecode($log->url)); // Some XSS protection
511 $log->info = strip_tags(urldecode($log->info)); // Some XSS protection
512 $log->url = str_replace('&', '&amp;', $log->url); // XHTML compatibility
513
514 $firstField = $courses[$log->course];
1c45e42e 515 $fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
954fdb42 516 $row = array($firstField, userdate($log->time, $strftimedatetime), $log->ip, $fullname, $log->module.' '.$log->action, $log->info);
517 $text = implode("\t", $row);
518 echo $text." \n";
519 }
520 return true;
92890025 521}
522
523
524function print_log_xls($course, $user, $date, $order='l.time DESC', $modname,
525 $modid, $modaction, $groupid) {
526
527 global $CFG;
528
954fdb42 529 require_once("$CFG->libdir/excellib.class.php");
530
531 if (!$logs = build_logs_array($course, $user, $date, $order, '', '',
92890025 532 $modname, $modid, $modaction, $groupid)) {
533 return false;
534 }
535
536 if ($course->id == SITEID) {
537 $courses[0] = '';
538 if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
539 foreach ($ccc as $cc) {
540 $courses[$cc->id] = $cc->shortname;
541 }
542 }
543 }
954fdb42 544
92890025 545 $count=0;
546 $ldcache = array();
547 $tt = getdate(time());
548 $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
549
550 $strftimedatetime = get_string("strftimedatetime");
92890025 551
954fdb42 552 $nroPages = ceil(count($logs)/(EXCELROWS-FIRSTUSEDEXCELROW+1));
553 $filename = 'logs_'.userdate(time(),get_string('backupnameformat'),99,false);
554 $filename .= '.xls';
92890025 555
556 $workbook = new MoodleExcelWorkbook('-');
557 $workbook->send($filename);
558
954fdb42 559 $worksheet = array();
560 $headers = array(get_string('course'), get_string('time'), get_string('ip_address'),
561 get_string('fullname'), get_string('action'), get_string('info'));
562
563 // Creating worksheets
564 for ($wsnumber = 1; $wsnumber <= $nroPages; $wsnumber++) {
565 $sheettitle = get_string('excel_sheettitle', 'logs', $wsnumber).$nroPages;
566 $worksheet[$wsnumber] =& $workbook->add_worksheet($sheettitle);
567 $worksheet[$wsnumber]->set_column(1, 1, 30);
568 $worksheet[$wsnumber]->write_string(0, 0, get_string('savedat').
569 userdate(time(), $strftimedatetime));
570 $col = 0;
571 foreach ($headers as $item) {
572 $worksheet[$wsnumber]->write(FIRSTUSEDEXCELROW-1,$col,$item,'');
573 $col++;
574 }
575 }
576
2b2d182a 577 if (empty($logs['logs'])) {
578 $workbook->close();
579 return true;
580 }
581
954fdb42 582 $formatDate =& $workbook->add_format();
583 $formatDate->set_num_format(get_string('log_excel_date_format'));
584
585 $row = FIRSTUSEDEXCELROW;
586 $wsnumber = 1;
587 $myxls =& $worksheet[$wsnumber];
588 foreach ($logs['logs'] as $log) {
589 if (isset($ldcache[$log->module][$log->action])) {
590 $ld = $ldcache[$log->module][$log->action];
591 } else {
592 $ld = get_record('log_display', 'module', $log->module, 'action', $log->action);
593 $ldcache[$log->module][$log->action] = $ld;
594 }
595 if ($ld && !empty($log->info)) {
596 // ugly hack to make sure fullname is shown correctly
4068bedb 597 if (($ld->mtable == 'user') and ($ld->field == sql_concat('firstname', "' '" , 'lastname'))) {
954fdb42 598 $log->info = fullname(get_record($ld->mtable, 'id', $log->info), true);
599 } else {
600 $log->info = get_field($ld->mtable, $ld->field, 'id', $log->info);
601 }
602 }
603
604 // Filter log->info
605 $log->info = format_string($log->info);
606 $log->info = strip_tags(urldecode($log->info)); // Some XSS protection
607
608 if ($nroPages>1) {
609 if ($row > EXCELROWS) {
610 $wsnumber++;
611 $myxls =& $worksheet[$wsnumber];
612 $row = FIRSTUSEDEXCELROW;
613 }
614 }
615
616 $myxls->write($row, 0, $courses[$log->course], '');
617 // Excel counts from 1/1/1900
618 $excelTime=25569+$log->time/(3600*24);
619 $myxls->write($row, 1, $excelTime, $formatDate);
620 $myxls->write($row, 2, $log->ip, '');
1c45e42e 621 $fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
954fdb42 622 $myxls->write($row, 3, $fullname, '');
623 $myxls->write($row, 4, $log->module.' '.$log->action, '');
624 $myxls->write($row, 5, $log->info, '');
92890025 625
954fdb42 626 $row++;
627 }
628
629 $workbook->close();
630 return true;
92890025 631}
632
633/*
634// Relies on $CFG->libdir.'/phpdocwriter/lib/include.php', which is not
635// included in the default Moodle distribution.
636
637function print_log_ooo($course, $user, $date, $order='l.time DESC', $modname,
0adf53f6 638 $modid, $modaction, $groupid) {
639
640 global $CFG;
954fdb42 641 require_once($CFG->libdir.'/phpdocwriter/lib/include.php');
92890025 642
643 if (!$logs = build_logs_array($course, $user, $date, $order, '', '',
644 $modname, $modid, $modaction, $groupid)) {
645 return false;
646 }
647
648 if ($course->id == SITEID) {
649 $courses[0] = '';
650 if ($ccc = get_courses('all', 'c.id ASC', 'c.id,c.shortname')) {
651 foreach ($ccc as $cc) {
652 $courses[$cc->id] = $cc->shortname;
653 }
654 }
655 }
656
657 $count=0;
658 $ldcache = array();
659 $tt = getdate(time());
660 $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
661
662 $strftimedatetime = get_string("strftimedatetime");
92890025 663
954fdb42 664 $filename = 'logs_'.userdate(time(),get_string('backupnameformat'),99,false);
665 $filename .= '.sxw';
666 import('phpdocwriter.pdw_document');
667 header("Content-Type: application/download\n");
668 header("Content-Disposition: attachment; filename=$filename");
669 header("Expires: 0");
670 header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
671 header("Pragma: public");
672 header("Content-Transfer-Encoding: binary");
673
674 $sxw = new pdw_document;
675 $sxw->SetFileName($filename);
676 $sxw->SetAuthor('Moodle');
677 $sxw->SetTitle('logs');
678 $sxw->SetDescription('logs'.' - '.$filename);
679 $sxw->SetLanguage('es','ES');
680 $sxw->SetStdFont("Times New Roman",12);
681 $sxw->AddPageDef(array('name'=>'Standard', 'margins'=>'1,1,1,1', 'w'=>'29.7', 'h'=>'21'));
682 $sxw->Write(get_string('savedat').userdate(time(), $strftimedatetime));
92890025 683 $sxw->Ln(3);
684
685 $headers = array(get_string('course'), get_string('time'), get_string('ip_address'),
954fdb42 686 get_string('fullname'), get_string('action'), get_string('info'));
687
688 foreach($headers as $key=>$header){
689 $headers[$key] = eregi_replace ("<br?>", " ",$header);
690 }
691
692 foreach ($logs['logs'] as $log) {
693 if (isset($ldcache[$log->module][$log->action])) {
694 $ld = $ldcache[$log->module][$log->action];
695 } else {
696 $ld = get_record('log_display', 'module', $log->module, 'action', $log->action);
697 $ldcache[$log->module][$log->action] = $ld;
698 }
699 if ($ld && !empty($log->info)) {
700 // ugly hack to make sure fullname is shown correctly
4068bedb 701 if (($ld->mtable == 'user') and ($ld->field == sql_concat('firstname', "' '" , 'lastname'))) {
954fdb42 702 $log->info = fullname(get_record($ld->mtable, 'id', $log->info), true);
703 } else {
704 $log->info = get_field($ld->mtable, $ld->field, 'id', $log->info);
705 }
706 }
707
708 // Filter log->info
709 $log->info = format_string($log->info);
710
711 $log->url = strip_tags(urldecode($log->url)); // Some XSS protection
712 $log->info = strip_tags(urldecode($log->info)); // Some XSS protection
713 $log->url = str_replace('&', '&amp;', $log->url); // XHTML compatibility
714
715 $firstField = $courses[$log->course];
1c45e42e 716 $fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
954fdb42 717 $row = array($firstField, userdate($log->time, $strftimedatetime), $log->ip, $fullname, $log->module.' '.$log->action, $log->info);
718
719 $data[] = $row;
720 }
721 $sxw->Table($headers,$data);
722 $sxw->Output();
92890025 723
954fdb42 724 return true;
92890025 725}
726*/
727
c2cb4545 728function print_log_graph($course, $userid=0, $type="course.png", $date=0) {
729 global $CFG;
730 if (empty($CFG->gdversion)) {
731 echo "(".get_string("gdneed").")";
d887b5a7 732 } else {
980a5b3a 733 echo '<img src="'.$CFG->wwwroot.'/course/report/log/graph.php?id='.$course->id.
29b59206 734 '&amp;user='.$userid.'&amp;type='.$type.'&amp;date='.$date.'" alt="" />';
d887b5a7 735 }
736}
737
738
185cfb09 739function print_overview($courses) {
0d6b9d4f 740
741 global $CFG, $USER;
742
185cfb09 743 $htmlarray = array();
f8716988 744 if ($modules = get_records('modules')) {
745 foreach ($modules as $mod) {
746 if (file_exists(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php')) {
747 require_once(dirname(dirname(__FILE__)).'/mod/'.$mod->name.'/lib.php');
748 $fname = $mod->name.'_print_overview';
0d6b9d4f 749 if (function_exists($fname)) {
185cfb09 750 $fname($courses,$htmlarray);
0d6b9d4f 751 }
752 }
753 }
754 }
185cfb09 755 foreach ($courses as $course) {
fe5a1e23 756 print_simple_box_start('center', '100%', '', 5, "coursebox");
185cfb09 757 $linkcss = '';
758 if (empty($course->visible)) {
759 $linkcss = 'class="dimmed"';
760 }
761 print_heading('<a title="'.$course->fullname.'" '.$linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->fullname.'</a>');
762 if (array_key_exists($course->id,$htmlarray)) {
763 foreach ($htmlarray[$course->id] as $modname => $html) {
764 echo $html;
765 }
766 }
767 print_simple_box_end();
768 }
0d6b9d4f 769}
770
771
600149be 772function print_recent_activity($course) {
773 // $course is an object
89adb174 774 // This function trawls through the logs looking for
600149be 775 // anything new since the user's last login
776
810393c8 777 global $CFG, $USER, $SESSION;
600149be 778
e2a3a0e7 779 $context = get_context_instance(CONTEXT_COURSE, $course->id);
2ac64806 780
6f80940b 781 $timestart = time() - COURSE_MAX_RECENT_PERIOD;
0f87cb1d 782
e2a3a0e7 783 if (!has_capability('moodle/legacy:guest', $context, NULL, false)) {
784 if (!empty($USER->lastcourseaccess[$course->id])) {
785 if ($USER->lastcourseaccess[$course->id] > $timestart) {
786 $timestart = $USER->lastcourseaccess[$course->id];
787 }
9e51847a 788 }
3d891989 789 }
0f87cb1d 790
de785682 791 echo '<div class="activitydate">';
27bf9e20 792 echo get_string('activitysince', '', userdate($timestart));
de785682 793 echo '</div>';
794 echo '<div class="activityhead">';
0f87cb1d 795
de785682 796 echo '<a href="'.$CFG->wwwroot.'/course/recent.php?id='.$course->id.'">'.get_string('recentactivityreport').'</a>';
0f87cb1d 797
5fc835a5 798 echo "</div>\n";
0f87cb1d 799
600149be 800
801 // Firstly, have there been any new enrolments?
802
803 $heading = false;
804 $content = false;
1b5910c4 805
6c38b7e0 806 $users = get_recent_enrolments($course->id, $timestart);
1b5910c4 807
5fc835a5 808 //Accessibility: new users now appear in an <OL> list.
6c38b7e0 809 if ($users) {
27bf9e20 810 echo '<div class="newusers">';
5fc835a5 811 if (! $heading) {
812 print_headline(get_string("newusers").':', 3);
813 $heading = true;
814 $content = true;
815 }
816 echo "<ol class=\"list\">\n";
6c38b7e0 817 foreach ($users as $user) {
5fc835a5 818
1c45e42e 819 $fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
5fc835a5 820 echo '<li class="name"><a href="'.$CFG->wwwroot."/user/view.php?id=$user->id&amp;course=$course->id\">$fullname</a></li>\n";
600149be 821 }
5fc835a5 822 echo "</ol>\n</div>\n";
600149be 823 }
824
1b5910c4 825 // Next, have there been any modifications to the course structure?
826
27bf9e20 827 $logs = get_records_select('log', "time > '$timestart' AND course = '$course->id' AND
1b5910c4 828 module = 'course' AND action LIKE '% mod'", "time ASC");
829
830 if ($logs) {
831 foreach ($logs as $key => $log) {
27bf9e20 832 $info = split(' ', $log->info);
c9f6251e 833
27bf9e20 834 if ($info[0] == 'label') { // Labels are special activities
c9f6251e 835 continue;
836 }
837
27bf9e20 838 $modname = get_field($info[0], 'name', 'id', $info[1]);
1b5910c4 839 //Create a temp valid module structure (course,id)
840 $tempmod->course = $log->course;
841 $tempmod->id = $info[1];
842 //Obtain the visible property from the instance
843 $modvisible = instance_is_visible($info[0],$tempmod);
89adb174 844
1b5910c4 845 //Only if the mod is visible
846 if ($modvisible) {
847 switch ($log->action) {
27bf9e20 848 case 'add mod':
849 $stradded = get_string('added', 'moodle', get_string('modulename', $info[0]));
5847b267 850 $changelist[$log->info] = array ('operation' => 'add', 'text' => "$stradded:<br /><a href=\"$CFG->wwwroot/course/$log->url\">".format_string($modname,true)."</a>");
1b5910c4 851 break;
27bf9e20 852 case 'update mod':
853 $strupdated = get_string('updated', 'moodle', get_string('modulename', $info[0]));
854 if (empty($changelist[$log->info])) {
5847b267 855 $changelist[$log->info] = array ('operation' => 'update', 'text' => "$strupdated:<br /><a href=\"$CFG->wwwroot/course/$log->url\">".format_string($modname,true)."</a>");
1b5910c4 856 }
857 break;
27bf9e20 858 case 'delete mod':
859 if (!empty($changelist[$log->info]['operation']) and
860 $changelist[$log->info]['operation'] == 'add') {
861 $changelist[$log->info] = NULL;
1b5910c4 862 } else {
27bf9e20 863 $strdeleted = get_string('deletedactivity', 'moodle', get_string('modulename', $info[0]));
864 $changelist[$log->info] = array ('operation' => 'delete', 'text' => $strdeleted);
1b5910c4 865 }
866 break;
600149be 867 }
ef25340c 868 }
869 }
870 }
871
9c9f7d77 872 if (!empty($changelist)) {
ef25340c 873 foreach ($changelist as $changeinfo => $change) {
874 if ($change) {
875 $changes[$changeinfo] = $change;
876 }
877 }
8a59942e 878 if (isset($changes)){
879 if (count($changes) > 0) {
27bf9e20 880 print_headline(get_string('courseupdates').':', 3);
8a59942e 881 $content = true;
882 foreach ($changes as $changeinfo => $change) {
27bf9e20 883 echo '<p class="activity">'.$change['text'].'</p>';
8a59942e 884 }
600149be 885 }
886 }
89adb174 887 }
bf40f9c1 888
3869a2ac 889 // Now display new things from each module
600149be 890
27bf9e20 891 $mods = get_records('modules', 'visible', '1', 'name', 'id, name');
0fd7da81 892
e2a3a0e7 893 $viewfullnames = has_capability('moodle/site:viewfullnames', $context);
894
1b5910c4 895 foreach ($mods as $mod) { // Each module gets it's own logs and prints them
27bf9e20 896 include_once($CFG->dirroot.'/mod/'.$mod->name.'/lib.php');
897 $print_recent_activity = $mod->name.'_print_recent_activity';
1b5910c4 898 if (function_exists($print_recent_activity)) {
66b0b104 899 //
900 // NOTE:
e2a3a0e7 901 // $isteacher (second parameter below) is to be deprecated!
66b0b104 902 //
903 // TODO:
1172e5db 904 // 1) Make sure that all _print_recent_activity functions are
905 // not using the $isteacher value.
906 // 2) Eventually, remove the $isteacher parameter from the
907 // function calls.
66b0b104 908 //
e2a3a0e7 909 $modcontent = $print_recent_activity($course, $viewfullnames, $timestart);
3869a2ac 910 if ($modcontent) {
911 $content = true;
600149be 912 }
600149be 913 }
914 }
915
916 if (! $content) {
27bf9e20 917 echo '<p class="message">'.get_string('nothingnew').'</p>';
600149be 918 }
600149be 919}
920
e1360728 921
d897cae4 922function get_array_of_activities($courseid) {
89adb174 923// For a given course, returns an array of course activity objects
d897cae4 924// Each item in the array contains he following properties:
925// cm - course module id
926// mod - name of the module (eg forum)
927// section - the number of the section (eg week or topic)
928// name - the name of the instance
5867bfb5 929// visible - is the instance visible or not
86aa7ccf 930// extra - contains extra string to include in any link
d897cae4 931
8dddba42 932 global $CFG;
933
d897cae4 934 $mod = array();
935
9fa49e22 936 if (!$rawmods = get_course_mods($courseid)) {
d897cae4 937 return NULL;
938 }
939
940 if ($sections = get_records("course_sections", "course", $courseid, "section ASC")) {
941 foreach ($sections as $section) {
74666583 942 if (!empty($section->sequence)) {
d897cae4 943 $sequence = explode(",", $section->sequence);
944 foreach ($sequence as $seq) {
7af6281f 945 if (empty($rawmods[$seq])) {
946 continue;
947 }
d897cae4 948 $mod[$seq]->cm = $rawmods[$seq]->id;
949 $mod[$seq]->mod = $rawmods[$seq]->modname;
950 $mod[$seq]->section = $section->section;
951 $mod[$seq]->name = urlencode(get_field($rawmods[$seq]->modname, "name", "id", $rawmods[$seq]->instance));
fec5a6a6 952 $mod[$seq]->visible = $rawmods[$seq]->visible;
86aa7ccf 953 $mod[$seq]->extra = "";
8dddba42 954
955 $modname = $mod[$seq]->mod;
956 $functionname = $modname."_get_coursemodule_info";
957
958 include_once("$CFG->dirroot/mod/$modname/lib.php");
959
960 if (function_exists($functionname)) {
9d361034 961 if ($info = $functionname($rawmods[$seq])) {
962 if (!empty($info->extra)) {
963 $mod[$seq]->extra = $info->extra;
964 }
965 if (!empty($info->icon)) {
966 $mod[$seq]->icon = $info->icon;
967 }
c9f6251e 968 }
969 }
d897cae4 970 }
971 }
972 }
973 }
974 return $mod;
975}
976
977
978
e1360728 979
90845098 980function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
981// Returns a number of useful structures for course displays
7468bf01 982
90845098 983 $mods = NULL; // course modules indexed by id
e0161bff 984 $modnames = NULL; // all course module names (except resource!)
94361e02 985 $modnamesplural= NULL; // all course module names (plural form)
90845098 986 $modnamesused = NULL; // course module names used
7468bf01 987
9fa49e22 988 if ($allmods = get_records("modules")) {
90845098 989 foreach ($allmods as $mod) {
5867bfb5 990 if ($mod->visible) {
991 $modnames[$mod->name] = get_string("modulename", "$mod->name");
992 $modnamesplural[$mod->name] = get_string("modulenameplural", "$mod->name");
993 }
90845098 994 }
995 asort($modnames);
996 } else {
997 error("No modules are installed!");
998 }
999
9fa49e22 1000 if ($rawmods = get_course_mods($courseid)) {
7468bf01 1001 foreach($rawmods as $mod) { // Index the mods
959ae824 1002 if (empty($modnames[$mod->modname])) {
1003 continue;
1004 }
7468bf01 1005 $mods[$mod->id] = $mod;
959ae824 1006 $mods[$mod->id]->modfullname = $modnames[$mod->modname];
3924b988 1007 if ($mod->visible or has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $courseid))) {
959ae824 1008 $modnamesused[$mod->modname] = $modnames[$mod->modname];
1acfbce5 1009 }
7468bf01 1010 }
c7da6f7a 1011 if ($modnamesused) {
1012 asort($modnamesused);
1013 }
7468bf01 1014 }
e0161bff 1015
1016 unset($modnames['resource']);
1017 unset($modnames['label']);
7468bf01 1018}
1019
9fa49e22 1020
7468bf01 1021function get_all_sections($courseid) {
89adb174 1022
1023 return get_records("course_sections", "course", "$courseid", "section",
7d99d695 1024 "section, id, course, summary, sequence, visible");
7468bf01 1025}
1026
b86fc0e2 1027function course_set_display($courseid, $display=0) {
1028 global $USER;
1029
1066e0dc 1030 if (empty($USER->id)) {
b86fc0e2 1031 return false;
1032 }
1033
1034 if ($display == "all" or empty($display)) {
1035 $display = 0;
1036 }
1037
1038 if (record_exists("course_display", "userid", $USER->id, "course", $courseid)) {
1039 set_field("course_display", "display", $display, "userid", $USER->id, "course", $courseid);
1040 } else {
1041 $record->userid = $USER->id;
1042 $record->course = $courseid;
1043 $record->display = $display;
1044 if (!insert_record("course_display", $record)) {
1045 notify("Could not save your course display!");
1046 }
1047 }
1048
1049 return $USER->display[$courseid] = $display; // Note: = not ==
1050}
1051
7d99d695 1052function set_section_visible($courseid, $sectionnumber, $visibility) {
1053/// For a given course section, markes it visible or hidden,
1054/// and does the same for every activity in that section
1055
1056 if ($section = get_record("course_sections", "course", $courseid, "section", $sectionnumber)) {
1057 set_field("course_sections", "visible", "$visibility", "id", $section->id);
1058 if (!empty($section->sequence)) {
1059 $modules = explode(",", $section->sequence);
1060 foreach ($modules as $moduleid) {
02f66c42 1061 set_coursemodule_visible($moduleid, $visibility, true);
7d99d695 1062 }
1063 }
5867bfb5 1064 rebuild_course_cache($courseid);
7d99d695 1065 }
1066}
ba2e5d73 1067
5e367a2d 1068
d897cae4 1069function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%") {
52dcc2f9 1070/// Prints a section full of activity modules
7977cffd 1071 global $CFG, $USER;
1072
3d575e6f 1073 static $groupbuttons;
32d03b7b 1074 static $groupbuttonslink;
52dcc2f9 1075 static $isteacher;
1076 static $isediting;
7977cffd 1077 static $ismoving;
1078 static $strmovehere;
1079 static $strmovefull;
54669989 1080 static $strunreadpostsone;
52dcc2f9 1081
4877707e 1082 static $untracked;
a2d71d8e 1083 static $usetracking;
4877707e 1084
a22f8313 1085 $labelformatoptions = New stdClass;
110a32e2 1086
52dcc2f9 1087 if (!isset($isteacher)) {
9fd9c29b 1088 $groupbuttons = ($course->groupmode or (!$course->groupmodeforce));
32d03b7b 1089 $groupbuttonslink = (!$course->groupmodeforce);
52dcc2f9 1090 $isediting = isediting($course->id);
ff0c7de0 1091 $ismoving = $isediting && ismoving($course->id);
3d575e6f 1092 if ($ismoving) {
1093 $strmovehere = get_string("movehere");
1094 $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'"));
1095 }
94a6a70f 1096 include_once($CFG->dirroot.'/mod/forum/lib.php');
1097 if ($usetracking = forum_tp_can_track_forums()) {
a2d71d8e 1098 $strunreadpostsone = get_string('unreadpostsone', 'forum');
94a6a70f 1099 $untracked = forum_tp_get_untracked_forums($USER->id, $course->id);
a2d71d8e 1100 }
7977cffd 1101 }
60bd11cf 1102 $labelformatoptions->noclean = true;
94361e02 1103
fea43a7f 1104/// Casting $course->modinfo to string prevents one notice when the field is null
1105 $modinfo = unserialize((string)$course->modinfo);
94361e02 1106
c6a55371 1107 //Acccessibility: replace table with list <ul>, but don't output empty list.
74666583 1108 if (!empty($section->sequence)) {
94361e02 1109
f2d660dc 1110 // Fix bug #5027, don't want style=\"width:$width\".
1111 echo "<ul class=\"section\">\n";
94361e02 1112 $sectionmods = explode(",", $section->sequence);
1113
1114 foreach ($sectionmods as $modnumber) {
9ae687af 1115 if (empty($mods[$modnumber])) {
1116 continue;
1117 }
94361e02 1118 $mod = $mods[$modnumber];
c9f6251e 1119
3924b988 1120 if ($mod->visible or has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $course->id))) {
954fdb42 1121 echo '<li class="activity '.$mod->modname.'" id="module-'.$modnumber.'">'; // Unique ID
7977cffd 1122 if ($ismoving) {
1123 if ($mod->id == $USER->activitycopy) {
1124 continue;
1125 }
1c919752 1126 echo '<a title="'.$strmovefull.'"'.
8b92f5bb 1127 ' href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.$USER->sesskey.'">'.
446390fb 1128 '<img class="movetarget" src="'.$CFG->pixpath.'/movehere.gif" '.
1129 ' alt="'.$strmovehere.'" /></a><br />
1c919752 1130 ';
1acfbce5 1131 }
7977cffd 1132 $instancename = urldecode($modinfo[$modnumber]->name);
954fdb42 1133 $instancename = format_string($instancename, true, $course->id);
c9f6251e 1134
86aa7ccf 1135 if (!empty($modinfo[$modnumber]->extra)) {
1136 $extra = urldecode($modinfo[$modnumber]->extra);
1137 } else {
1138 $extra = "";
1139 }
c9f6251e 1140
9d361034 1141 if (!empty($modinfo[$modnumber]->icon)) {
1142 $icon = "$CFG->pixpath/".urldecode($modinfo[$modnumber]->icon);
1143 } else {
1144 $icon = "$CFG->modpixpath/$mod->modname/icon.gif";
1145 }
1146
aac94fd0 1147 if ($mod->indent) {
1148 print_spacer(12, 20 * $mod->indent, false);
1149 }
1150
c9f6251e 1151 if ($mod->modname == "label") {
aac94fd0 1152 if (!$mod->visible) {
1153 echo "<span class=\"dimmed_text\">";
1154 }
179c9a50 1155 echo format_text($extra, FORMAT_HTML, $labelformatoptions);
aac94fd0 1156 if (!$mod->visible) {
1157 echo "</span>";
1158 }
c9f6251e 1159
1160 } else { // Normal activity
1161 $linkcss = $mod->visible ? "" : " class=\"dimmed\" ";
1c919752 1162 echo '<img src="'.$icon.'"'.
446390fb 1163 ' class="activityicon" alt="'.$mod->modfullname.'" />'.
1164 ' <a title="'.$mod->modfullname.'" '.$linkcss.' '.$extra.
1c919752 1165 ' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.
446390fb 1166 $instancename.'</a>';
c9f6251e 1167 }
a2d71d8e 1168 if ($usetracking && $mod->modname == 'forum') {
f37da850 1169 $groupmode = groupmode($course, $mod);
3924b988 1170 $groupid = ($groupmode == SEPARATEGROUPS && !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) ?
a2d71d8e 1171 get_current_group($course->id) : false;
4877707e 1172
94a6a70f 1173 if (forum_tp_can_track_forums() && !isset($untracked[$mod->instance])) {
4877707e 1174 $unread = forum_tp_count_forum_unread_posts($USER->id, $mod->instance, $groupid);
1175 if ($unread) {
1176 echo '<span class="unread"> <a href="'.$CFG->wwwroot.'/mod/forum/view.php?id='.$mod->id.'">';
1177 if ($unread == 1) {
1178 echo $strunreadpostsone;
1179 } else {
1180 print_string('unreadpostsnumber', 'forum', $unread);
1181 }
1182 echo '</a> </span>';
d0388ebe 1183 }
54669989 1184 }
f37da850 1185 }
1186
c9f6251e 1187 if ($isediting) {
5f390342 1188 if ($groupbuttons and $mod->modname != 'label' and $mod->modname != 'resource') {
32d03b7b 1189 if (! $mod->groupmodelink = $groupbuttonslink) {
1190 $mod->groupmode = $course->groupmode;
1191 }
1192
1193 } else {
3d575e6f 1194 $mod->groupmode = false;
1195 }
37a88449 1196 echo '&nbsp;&nbsp;';
24e1eae4 1197 echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section);
c9f6251e 1198 }
c6a55371 1199 echo "</li>\n";
94361e02 1200 }
94361e02 1201 }
f2d660dc 1202 } elseif ($ismoving) {
1203 echo "<ul class=\"section\">\n";
1204 }
7977cffd 1205 if ($ismoving) {
64fdc686 1206 echo '<li><a title="'.$strmovefull.'"'.
8b92f5bb 1207 ' href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.$USER->sesskey.'">'.
446390fb 1208 '<img class="movetarget" src="'.$CFG->pixpath.'/movehere.gif" '.
c6a55371 1209 ' alt="'.$strmovehere.'" /></a></li>
1c919752 1210 ';
7977cffd 1211 }
c6a55371 1212 if (!empty($section->sequence) || $ismoving) {
1213 echo "</ul><!--class='section'-->\n\n";
1214 }
a7ad3ea6 1215}
1216
5867bfb5 1217
cb57e6f4 1218function print_section_add_menus($course, $section, $modnames, $vertical=false, $return=false) {
e0161bff 1219// Prints the menus to add activities and resources
1220
8b92f5bb 1221 global $CFG, $USER;
6da4b261 1222 static $straddactivity, $stractivities, $straddresource, $resources;
e0161bff 1223
1224 if (!isset($straddactivity)) {
1225 $straddactivity = get_string('addactivity');
1226 $straddresource = get_string('addresource');
6da4b261 1227
1228 /// Standard resource types
1229 require_once("$CFG->dirroot/mod/resource/lib.php");
1230 $resourceraw = resource_get_resource_types();
1231
1232 foreach ($resourceraw as $type => $name) {
839f2456 1233 $resources["resource&amp;type=$type"] = $name;
e0161bff 1234 }
0705ff84 1235 if (course_allowed_module($course,'label')) {
1236 $resources['label'] = get_string('resourcetypelabel', 'resource');
1237 }
e0161bff 1238 }
1239
d33d0cda 1240 $output = '<div style="text-align: right">';
0705ff84 1241 if (course_allowed_module($course,'resource')) {
81a5d9ca 1242 $resourceallowed = true;
0705ff84 1243 $output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&amp;sesskey=$USER->sesskey&amp;add=",
1244 $resources, "ressection$section", "", $straddresource, 'resource/types', $straddresource, true);
1245 }
cb57e6f4 1246
1247 if ($vertical) {
d33d0cda 1248 $output .= '<div>';
cb57e6f4 1249 }
1250
0705ff84 1251 // we need to loop through the forms and check to see if we can add them.
cb77cf12 1252 foreach ($modnames as $key=>$value) {
0705ff84 1253 if (!course_allowed_module($course,$key))
cb77cf12 1254 unset($modnames[$key]);
0705ff84 1255 }
1256
1257 // this is stupid but labels get put into resource, so if resource is hidden and label is not, we're in trouble.
1258 if (course_allowed_module($course,'label') && empty($resourceallowed)) {
1259 $modnames['label'] = get_string('modulename', 'label');
1260 }
1261
1c46eb03 1262 $output .= ' ';
8b92f5bb 1263 $output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&amp;sesskey=$USER->sesskey&amp;add=",
6da4b261 1264 $modnames, "section$section", "", $straddactivity, 'mods', $straddactivity, true);
d33d0cda 1265
1266 if ($vertical) {
1267 $output .= '</div>';
1268 }
1269
cb57e6f4 1270 $output .= '</div>';
1271
1272 if ($return) {
1273 return $output;
1274 } else {
1275 echo $output;
1276 }
e0161bff 1277}
1278
5867bfb5 1279function rebuild_course_cache($courseid=0) {
1280// Rebuilds the cached list of course activities stored in the database
1281// If a courseid is not specified, then all are rebuilt
1282
1283 if ($courseid) {
1284 $select = "id = '$courseid'";
1285 } else {
1286 $select = "";
1287 }
1288
1a31c2b3 1289 if ($courses = get_records_select("course", $select,'','id,fullname')) {
5867bfb5 1290 foreach ($courses as $course) {
1291 $modinfo = serialize(get_array_of_activities($course->id));
1292 if (!set_field("course", "modinfo", $modinfo, "id", $course->id)) {
1293 notify("Could not cache module information for course '$course->fullname'!");
1294 }
1295 }
1296 }
1297}
1298
1299
c2cb4545 1300
1301function make_categories_list(&$list, &$parents, $category=NULL, $path="") {
89adb174 1302/// Given an empty array, this function recursively travels the
c2cb4545 1303/// categories, building up a nice list for display. It also makes
1304/// an array that list all the parents for each category.
1305
9d866ae0 1306 // initialize the arrays if needed
1307 if (!is_array($list)) {
1308 $list = array();
1309 }
1310 if (!is_array($parents)) {
1311 $parents = array();
1312 }
1313
c2cb4545 1314 if ($category) {
1315 if ($path) {
e05bcf2f 1316 $path = $path.' / '.$category->name;
c2cb4545 1317 } else {
e05bcf2f 1318 $path = $category->name;
c2cb4545 1319 }
1320 $list[$category->id] = $path;
1321 } else {
1322 $category->id = 0;
1323 }
1324
e05bcf2f 1325 if ($categories = get_categories($category->id)) { // Print all the children recursively
c2cb4545 1326 foreach ($categories as $cat) {
1327 if (!empty($category->id)) {
3bd4de22 1328 if (isset($parents[$category->id])) {
2832badf 1329 $parents[$cat->id] = $parents[$category->id];
1330 }
c2cb4545 1331 $parents[$cat->id][] = $category->id;
1332 }
89adb174 1333 make_categories_list($list, $parents, $cat, $path);
c2cb4545 1334 }
1335 }
1336}
1337
1338
d157bd5b 1339function print_whole_category_list($category=NULL, $displaylist=NULL, $parentslist=NULL, $depth=-1, $files = true) {
89adb174 1340/// Recursive function to print out all the categories in a nice format
c2cb4545 1341/// with or without courses included
9ff5310a 1342 global $CFG;
e05bcf2f 1343
1344 if (isset($CFG->max_category_depth) && ($depth >= $CFG->max_category_depth)) {
1345 return;
9ff5310a 1346 }
c2cb4545 1347
1348 if (!$displaylist) {
e92fe848 1349 make_categories_list($displaylist, $parentslist);
c2cb4545 1350 }
1351
1352 if ($category) {
ec7a8b79 1353 if ($category->visible or has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
6f24e48e 1354 print_category_info($category, $depth, $files);
c2cb4545 1355 } else {
1356 return; // Don't bother printing children of invisible categories
1357 }
89adb174 1358
c2cb4545 1359 } else {
c2cb4545 1360 $category->id = "0";
1361 }
1362
1363 if ($categories = get_categories($category->id)) { // Print all the children recursively
1364 $countcats = count($categories);
1365 $count = 0;
1366 $first = true;
1367 $last = false;
1368 foreach ($categories as $cat) {
1369 $count++;
1370 if ($count == $countcats) {
1371 $last = true;
1372 }
1373 $up = $first ? false : true;
1374 $down = $last ? false : true;
1375 $first = false;
1376
6f24e48e 1377 print_whole_category_list($cat, $displaylist, $parentslist, $depth + 1, $files);
c2cb4545 1378 }
1379 }
c2cb4545 1380}
1381
0705ff84 1382// this function will return $options array for choose_from_menu, with whitespace to denote nesting.
1383
1384function make_categories_options() {
1385 make_categories_list($cats,$parents);
1386 foreach ($cats as $key => $value) {
1387 if (array_key_exists($key,$parents)) {
1388 if ($indent = count($parents[$key])) {
1389 for ($i = 0; $i < $indent; $i++) {
1390 $cats[$key] = '&nbsp;'.$cats[$key];
1391 }
1392 }
1393 }
1394 }
1395 return $cats;
1396}
c2cb4545 1397
6f24e48e 1398function print_category_info($category, $depth, $files = false) {
d2b6ba70 1399/// Prints the category info in indented fashion
1400/// This function is only used by print_whole_category_list() above
c2cb4545 1401
1402 global $CFG;
b48f834c 1403 static $strallowguests, $strrequireskey, $strsummary;
c2cb4545 1404
b48f834c 1405 if (empty($strsummary)) {
e05bcf2f 1406 $strallowguests = get_string('allowguests');
1407 $strrequireskey = get_string('requireskey');
1408 $strsummary = get_string('summary');
b48f834c 1409 }
ba2e5d73 1410
e05bcf2f 1411 $catlinkcss = $category->visible ? '' : ' class="dimmed" ';
d5f26b07 1412
6f24e48e 1413 $coursecount = count_records('course') <= FRONTPAGECOURSELIMIT;
1414 if ($files and $coursecount) {
839f2456 1415 $catimage = '<img src="'.$CFG->pixpath.'/i/course.gif" width="16" height="16" border="0" alt="" />';
b48f834c 1416 } else {
7b0b5c14 1417 $catimage = "&nbsp;";
8ef9cb56 1418 }
b48f834c 1419
87d32352 1420 echo "\n\n".'<table border="0" cellpadding="3" cellspacing="0" width="100%">';
d2b6ba70 1421
6f24e48e 1422 if ($files and $coursecount) {
19374e76 1423 $courses = get_courses($category->id, 'c.sortorder ASC', 'c.id,c.sortorder,c.visible,c.fullname,c.shortname,c.password,c.summary,c.guest,c.cost,c.currency');
b48f834c 1424
978abb42 1425 echo '<tr>';
b48f834c 1426
1427 if ($depth) {
1428 $indent = $depth*30;
1429 $rows = count($courses) + 1;
1c919752 1430 echo '<td rowspan="'.$rows.'" valign="top" width="'.$indent.'">';
b48f834c 1431 print_spacer(10, $indent);
e05bcf2f 1432 echo '</td>';
b48f834c 1433 }
89adb174 1434
e05bcf2f 1435 echo '<td valign="top">'.$catimage.'</td>';
290130b3 1436 echo '<td valign="top" width="100%" class="category name">';
e05bcf2f 1437 echo '<a '.$catlinkcss.' href="'.$CFG->wwwroot.'/course/category.php?id='.$category->id.'">'.$category->name.'</a>';
1438 echo '</td>';
290130b3 1439 echo '<td class="category info">&nbsp;</td>';
e05bcf2f 1440 echo '</tr>';
b48f834c 1441
9ff5310a 1442 if ($courses && !(isset($CFG->max_category_depth)&&($depth>=$CFG->max_category_depth-1))) {
c2cb4545 1443 foreach ($courses as $course) {
e05bcf2f 1444 $linkcss = $course->visible ? '' : ' class="dimmed" ';
1445 echo '<tr><td valign="top" width="30">&nbsp;';
290130b3 1446 echo '</td><td valign="top" width="100%" class="course name">';
e05bcf2f 1447 echo '<a '.$linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.$course->fullname.'</a>';
290130b3 1448 echo '</td><td align="right" valign="top" nowrap="nowrap" class="course info">';
c2cb4545 1449 if ($course->guest ) {
e05bcf2f 1450 echo '<a title="'.$strallowguests.'" href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">';
1451 echo '<img hspace="1" alt="'.$strallowguests.'" height="16" width="16" border="0" src="'.$CFG->pixpath.'/i/guest.gif" /></a>';
ebe8ddc1 1452 } else {
e05bcf2f 1453 echo '<img alt="" height="16" width="18" border="0" src="'.$CFG->pixpath.'/spacer.gif" />';
0c656181 1454 }
c2cb4545 1455 if ($course->password) {
e05bcf2f 1456 echo '<a title="'.$strrequireskey.'" href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">';
1457 echo '<img hspace="1" alt="'.$strrequireskey.'" height="16" width="16" border="0" src="'.$CFG->pixpath.'/i/key.gif" /></a>';
ebe8ddc1 1458 } else {
e05bcf2f 1459 echo '<img alt="" height="16" width="18" border="0" src="'.$CFG->pixpath.'/spacer.gif" />';
b48f834c 1460 }
1461 if ($course->summary) {
e05bcf2f 1462 link_to_popup_window ('/course/info.php?id='.$course->id, 'courseinfo',
1463 '<img hspace="1" alt="'.$strsummary.'" height="16" width="16" border="0" src="'.$CFG->pixpath.'/i/info.gif" />',
b48f834c 1464 400, 500, $strsummary);
ebe8ddc1 1465 } else {
e05bcf2f 1466 echo '<img alt="" height="16" width="18" border="0" src="'.$CFG->pixpath.'/spacer.gif" />';
0c656181 1467 }
e05bcf2f 1468 echo '</td></tr>';
0c656181 1469 }
ba2e5d73 1470 }
d2b6ba70 1471 } else {
b48f834c 1472
e0140f24 1473 echo '<tr>';
1474
b48f834c 1475 if ($depth) {
1476 $indent = $depth*20;
e05bcf2f 1477 echo '<td valign="top" width="'.$indent.'">';
b48f834c 1478 print_spacer(10, $indent);
e05bcf2f 1479 echo '</td>';
d2b6ba70 1480 }
89adb174 1481
290130b3 1482 echo '<td valign="top" width="100%" class="category name">';
e05bcf2f 1483 echo '<a '.$catlinkcss.' href="'.$CFG->wwwroot.'/course/category.php?id='.$category->id.'">'.$category->name.'</a>';
1484 echo '</td>';
290130b3 1485 echo '<td valign="top" class="category number">';
e05bcf2f 1486 if ($category->coursecount) {
1487 echo $category->coursecount;
1488 }
1489 echo '</td></tr>';
c2cb4545 1490 }
e05bcf2f 1491 echo '</table>';
c2cb4545 1492}
1493
c2cb4545 1494
8e227aa7 1495function print_courses($category, $width="100%", $hidesitecourse = false) {
c2cb4545 1496/// Category is 0 (for all courses) or an object
1497
810393c8 1498 global $CFG;
c2cb4545 1499
1500 if (empty($category)) {
90c2ca2e 1501 $categories = get_categories(0); // Parent = 0 ie top-level categories only
1502 if (count($categories) == 1) {
1503 $category = array_shift($categories);
32b9a983 1504 $courses = get_courses($category->id, 'c.sortorder ASC', 'c.id,c.category,c.sortorder,c.visible,c.fullname,c.shortname,c.password,c.summary,c.teacher,c.cost,c.currency,c.enrol,c.guest');
90c2ca2e 1505 } else {
32b9a983 1506 $courses = get_courses('all', 'c.sortorder ASC', 'c.id,c.category,c.sortorder,c.visible,c.fullname,c.shortname,c.password,c.summary,c.teacher,c.cost,c.currency,c.enrol,c.guest');
90c2ca2e 1507 }
1508 unset($categories);
607809b3 1509 } else {
c2cb4545 1510 $categories = get_categories($category->id); // sub categories
32b9a983 1511 $courses = get_courses($category->id, 'c.sortorder ASC', 'c.id,c.category,c.sortorder,c.visible,c.fullname,c.shortname,c.password,c.summary,c.teacher,c.cost,c.currency,c.enrol,c.guest');
c2cb4545 1512 }
1513
c2cb4545 1514 if ($courses) {
1515 foreach ($courses as $course) {
8e227aa7 1516 if ($hidesitecourse && !$course->category) {
1517 continue;
1518 }
c2cb4545 1519 print_course($course, $width);
c2cb4545 1520 }
1521 } else {
f9667a5a 1522 print_heading(get_string("nocoursesyet"));
954fdb42 1523 $context = get_context_instance(CONTEXT_SYSTEM, SITEID);
0468976c 1524 if (has_capability('moodle/course:create', $context)) {
255d1033 1525 $options = array();
1526 $options['category'] = $category->id;
1527 echo '<div class="addcoursebutton" align="center">';
1528 print_single_button($CFG->wwwroot.'/course/edit.php', $options, get_string("addnewcourse"));
1529 echo '</div>';
1530 }
c2cb4545 1531 }
c2cb4545 1532}
1533
1534
1535function print_course($course, $width="100%") {
1536
861efb19 1537 global $CFG, $USER;
c2cb4545 1538
88768091 1539 $context = get_context_instance(CONTEXT_COURSE, $course->id);
146bbb8f 1540
88768091 1541 print_simple_box_start('center', $width, '', 5, 'coursebox');
c2cb4545 1542
88768091 1543 $linkcss = $course->visible ? '' : ' class="dimmed" ';
22288704 1544
88768091 1545 echo '<table width="100%">';
e5e81e78 1546 echo '<tr valign="top">';
290130b3 1547 echo '<td valign="top" width="50%" class="info">';
34b5847a 1548 echo '<b><a title="'.get_string('entercourse').'"'.
e5e81e78 1549 $linkcss.' href="'.$CFG->wwwroot.'/course/view.php?id='.$course->id.'">'.
34b5847a 1550 $course->fullname.'</a></b><br />';
88768091 1551
1d546bb1 1552 if ($teachers = get_users_by_capability($context, 'moodle/course:update',
1553 'u.*, ul.timeaccess as lastaccess, ra.hidden',
0a3e9703 1554 'r.sortorder ASC', '','','','', false)) {
88768091 1555 $canseehidden = has_capability('moodle/role:viewhiddenassigns', $context);
1556 $namesarray = array();
c2cb4545 1557 foreach ($teachers as $teacher) {
88768091 1558 if (!$teacher->hidden || $canseehidden) {
1559 $roles = get_user_roles($context, $teacher->id);
1560 $role = array_shift($roles); // First one
1561 $fullname = fullname($teacher, has_capability('moodle/site:viewfullnames', $context));
1562 $namesarray[] = format_string($role->name).': <a href="'.$CFG->wwwroot.'/user/view.php?id='.
1563 $teacher->id.'&amp;course='.SITEID.'">'.$fullname.'</a>';
c2cb4545 1564 }
1565 }
88768091 1566 if ($namesarray) {
1567 echo "<ul class=\"teachers\">\n<li>";
1568 echo implode('</li><li>', $namesarray);
1569 echo "</li></ul>";
1570 }
c2cb4545 1571 }
c2cb4545 1572
88768091 1573 require_once("$CFG->dirroot/enrol/enrol.class.php");
1574 $enrol = enrolment_factory::factory($course->enrol);
146bbb8f 1575 echo $enrol->get_access_icons($course);
c2cb4545 1576
290130b3 1577 echo '</td><td valign="top" width="50%" class="summary">';
9f39c190 1578 $options = NULL;
1579 $options->noclean = true;
34b5847a 1580 $options->para = false;
9f39c190 1581 echo format_text($course->summary, FORMAT_MOODLE, $options, $course->id);
c2cb4545 1582 echo "</td></tr>";
1583 echo "</table>";
1584
1585 print_simple_box_end();
1586}
1587
1588
1589function print_my_moodle() {
1590/// Prints custom user information on the home page.
1591/// Over time this can include all sorts of information
1592
1593 global $USER, $CFG;
1594
86a1ba04 1595 if (empty($USER->id)) {
c2cb4545 1596 error("It shouldn't be possible to see My Moodle without being logged in.");
1597 }
1598
1599 if ($courses = get_my_courses($USER->id)) {
1600 foreach ($courses as $course) {
c81696e5 1601 if (!$course->category) {
1602 continue;
1603 }
c2cb4545 1604 print_course($course, "100%");
c2cb4545 1605 }
38a10939 1606
7f989948 1607 if (count_records("course") > (count($courses) + 1) ) { // Some courses not being displayed
1608 echo "<table width=\"100%\"><tr><td align=\"center\">";
1609 print_course_search("", false, "short");
1610 echo "</td><td align=\"center\">";
1611 print_single_button("$CFG->wwwroot/course/index.php", NULL, get_string("fulllistofcourses"), "get");
1612 echo "</td></tr></table>\n";
1613 }
26330001 1614 } else {
1615 if (count_records("course_categories") > 1) {
cb29b020 1616 print_simple_box_start("center", "100%", "#FFFFFF", 5, "categorybox");
26330001 1617 print_whole_category_list();
1618 print_simple_box_end();
1619 } else {
1620 print_courses(0, "100%");
1621 }
607809b3 1622 }
2b8cef80 1623}
1624
11b0c469 1625
a8b56716 1626function print_course_search($value="", $return=false, $format="plain") {
38a10939 1627
1628 global $CFG;
1629
1630 $strsearchcourses= get_string("searchcourses");
1631
1c919752 1632 if ($format == 'plain') {
87d32352 1633 $output = '<form name="coursesearch" action="'.$CFG->wwwroot.'/course/search.php" method="get">';
1634 $output .= '<center><p align="center" class="coursesearchbox">';
f8a5159a 1635 $output .= '<input type="text" size="30" name="search" alt="'.s($strsearchcourses).'" value="'.s($value, true).'" />';
9cc78ee1 1636 $output .= '<input type="submit" value="'.s($strsearchcourses).'" />';
87d32352 1637 $output .= '</p></center></form>';
1c919752 1638 } else if ($format == 'short') {
87d32352 1639 $output = '<form name="coursesearch" action="'.$CFG->wwwroot.'/course/search.php" method="get">';
1640 $output .= '<center><p align="center" class="coursesearchbox">';
f8a5159a 1641 $output .= '<input type="text" size="12" name="search" alt="'.s($strsearchcourses).'" value="'.s($value, true).'" />';
9cc78ee1 1642 $output .= '<input type="submit" value="'.s($strsearchcourses).'" />';
87d32352 1643 $output .= '</p></center></form>';
1c919752 1644 } else if ($format == 'navbar') {
87d32352 1645 $output = '<form name="coursesearch" action="'.$CFG->wwwroot.'/course/search.php" method="get">';
1646 $output .= '<table border="0" cellpadding="0" cellspacing="0"><tr><td nowrap="nowrap">';
f8a5159a 1647 $output .= '<input type="text" size="20" name="search" alt="'.s($strsearchcourses).'" value="'.s($value, true).'" />';
9cc78ee1 1648 $output .= '<input type="submit" value="'.s($strsearchcourses).'" />';
1c919752 1649 $output .= '</td></tr></table>';
87d32352 1650 $output .= '</form>';
a8b56716 1651 }
1652
1653 if ($return) {
1654 return $output;
1655 }
1656 echo $output;
38a10939 1657}
11b0c469 1658
1659/// MODULE FUNCTIONS /////////////////////////////////////////////////////////////////
1660
1661function add_course_module($mod) {
11b0c469 1662
e5dfd0f3 1663 $mod->added = time();
53f4ad2c 1664 unset($mod->id);
11b0c469 1665
e5dfd0f3 1666 return insert_record("course_modules", $mod);
11b0c469 1667}
1668
7977cffd 1669function add_mod_to_section($mod, $beforemod=NULL) {
1670/// Given a full mod object with section and course already defined
1671/// If $before is specified, then this is an existing ID which we
1672/// will insert the new module before
1673///
1674/// Returns the course_sections ID where the mod is inserted
11b0c469 1675
9fa49e22 1676 if ($section = get_record("course_sections", "course", "$mod->course", "section", "$mod->section")) {
7977cffd 1677
1678 $section->sequence = trim($section->sequence);
1679
1680 if (empty($section->sequence)) {
11b0c469 1681 $newsequence = "$mod->coursemodule";
7977cffd 1682
1683 } else if ($beforemod) {
1684 $modarray = explode(",", $section->sequence);
1685
1686 if ($key = array_keys ($modarray, $beforemod->id)) {
1687 $insertarray = array($mod->id, $beforemod->id);
1688 array_splice($modarray, $key[0], 1, $insertarray);
1689 $newsequence = implode(",", $modarray);
1690
1691 } else { // Just tack it on the end anyway
1692 $newsequence = "$section->sequence,$mod->coursemodule";
1693 }
1694
1695 } else {
1696 $newsequence = "$section->sequence,$mod->coursemodule";
11b0c469 1697 }
89adb174 1698
e5dfd0f3 1699 if (set_field("course_sections", "sequence", $newsequence, "id", $section->id)) {
1700 return $section->id; // Return course_sections ID that was used.
11b0c469 1701 } else {
e5dfd0f3 1702 return 0;
11b0c469 1703 }
89adb174 1704
11b0c469 1705 } else { // Insert a new record
e5dfd0f3 1706 $section->course = $mod->course;
1707 $section->section = $mod->section;
1708 $section->summary = "";
1709 $section->sequence = $mod->coursemodule;
1710 return insert_record("course_sections", $section);
11b0c469 1711 }
1712}
1713
48e535bc 1714function set_coursemodule_groupmode($id, $groupmode) {
3d575e6f 1715 return set_field("course_modules", "groupmode", $groupmode, "id", $id);
1716}
1717
02f66c42 1718/**
1719* $prevstateoverrides = true will set the visibility of the course module
1720* to what is defined in visibleold. This enables us to remember the current
1721* visibility when making a whole section hidden, so that when we toggle
1722* that section back to visible, we are able to return the visibility of
1723* the course module back to what it was originally.
1724*/
1725function set_coursemodule_visible($id, $visible, $prevstateoverrides=false) {
978abb42 1726 if (!$cm = get_record('course_modules', 'id', $id)) {
1727 return false;
1728 }
1729 if (!$modulename = get_field('modules', 'name', 'id', $cm->module)) {
1730 return false;
1731 }
dcd338ff 1732 if ($events = get_records_select('event', "instance = '$cm->instance' AND modulename = '$modulename'")) {
1733 foreach($events as $event) {
48e535bc 1734 if ($visible) {
1735 show_event($event);
1736 } else {
1737 hide_event($event);
1738 }
dcd338ff 1739 }
1740 }
02f66c42 1741 if ($prevstateoverrides) {
1742 if ($visible == '0') {
1743 // Remember the current visible state so we can toggle this back.
1744 set_field('course_modules', 'visibleold', $cm->visible, 'id', $id);
1745 } else {
1746 // Get the previous saved visible states.
1747 return set_field('course_modules', 'visible', $cm->visibleold, 'id', $id);
1748 }
1749 }
48e535bc 1750 return set_field("course_modules", "visible", $visible, "id", $id);
1acfbce5 1751}
1752
290130b3 1753/*
1754 * Delete a course module and any associated data at the course level (events)
1755 * Until 1.5 this function simply marked a deleted flag ... now it
1756 * deletes it completely.
1757 *
1758 */
48e535bc 1759function delete_course_module($id) {
290130b3 1760 if (!$cm = get_record('course_modules', 'id', $id)) {
1761 return true;
1762 }
dcd338ff 1763 $modulename = get_field('modules', 'name', 'id', $cm->module);
1764 if ($events = get_records_select('event', "instance = '$cm->instance' AND modulename = '$modulename'")) {
1765 foreach($events as $event) {
48e535bc 1766 delete_event($event);
dcd338ff 1767 }
1768 }
290130b3 1769 return delete_records('course_modules', 'id', $cm->id);
11b0c469 1770}
1771
1772function delete_mod_from_section($mod, $section) {
11b0c469 1773
e5dfd0f3 1774 if ($section = get_record("course_sections", "id", "$section") ) {
11b0c469 1775
e5dfd0f3 1776 $modarray = explode(",", $section->sequence);
11b0c469 1777
1778 if ($key = array_keys ($modarray, $mod)) {
1779 array_splice($modarray, $key[0], 1);
1780 $newsequence = implode(",", $modarray);
e5dfd0f3 1781 return set_field("course_sections", "sequence", $newsequence, "id", $section->id);
11b0c469 1782 } else {
1783 return false;
1784 }
89adb174 1785
11b0c469 1786 }
7977cffd 1787 return false;
11b0c469 1788}
1789
12905134 1790function move_section($course, $section, $move) {
1791/// Moves a whole course section up and down within the course
798b70a1 1792 global $USER;
12905134 1793
1794 if (!$move) {
1795 return true;
1796 }
1797
1798 $sectiondest = $section + $move;
1799
1800 if ($sectiondest > $course->numsections or $sectiondest < 1) {
1801 return false;
1802 }
1803
1804 if (!$sectionrecord = get_record("course_sections", "course", $course->id, "section", $section)) {
1805 return false;
1806 }
1807
1808 if (!$sectiondestrecord = get_record("course_sections", "course", $course->id, "section", $sectiondest)) {
1809 return false;
1810 }
1811
56e34ee4 1812 if (!set_field("course_sections", "section", $sectiondest, "id", $sectionrecord->id)) {
12905134 1813 return false;
1814 }
56e34ee4 1815 if (!set_field("course_sections", "section", $section, "id", $sectiondestrecord->id)) {
12905134 1816 return false;
1817 }
798b70a1 1818 // if the focus is on the section that is being moved, then move the focus along
1819 if (isset($USER->display[$course->id]) and ($USER->display[$course->id] == $section)) {
1820 course_set_display($course->id, $sectiondest);
1821 }
5390cbb7 1822
a987106d 1823 // Check for duplicates and fix order if needed.
5390cbb7 1824 // There is a very rare case that some sections in the same course have the same section id.
a987106d 1825 $sections = get_records_select('course_sections', "course = $course->id", 'section ASC');
1826 $n = 0;
1827 foreach ($sections as $section) {
1828 if ($section->section != $n) {
5390cbb7 1829 if (!set_field('course_sections', 'section', $n, 'id', $section->id)) {
1830 return false;
1831 }
5390cbb7 1832 }
a987106d 1833 $n++;
5390cbb7 1834 }
12905134 1835 return true;
1836}
1837
1838
7977cffd 1839function moveto_module($mod, $section, $beforemod=NULL) {
1840/// All parameters are objects
1841/// Move the module object $mod to the specified $section
1842/// If $beforemod exists then that is the module
1843/// before which $modid should be inserted
1844
1845/// Remove original module from original section
1846
1847 if (! delete_mod_from_section($mod->id, $mod->section)) {
1848 notify("Could not delete module from existing section");
1849 }
1850
1851/// Update module itself if necessary
1852
1853 if ($mod->section != $section->id) {
89adb174 1854 $mod->section = $section->id;
7977cffd 1855 if (!update_record("course_modules", $mod)) {
1856 return false;
1857 }
48e535bc 1858 // if moving to a hidden section then hide module
1859 if (!$section->visible) {
1860 set_coursemodule_visible($mod->id, 0);
1861 }
7977cffd 1862 }
1863
1864/// Add the module into the new section
1865
1866 $mod->course = $section->course;
1867 $mod->section = $section->section; // need relative reference
1868 $mod->coursemodule = $mod->id;
1869
1870 if (! add_mod_to_section($mod, $beforemod)) {
1871 return false;
1872 }
1873
1874 return true;
1875
1876}
1877
24e1eae4 1878function make_editing_buttons($mod, $absolute=false, $moveselect=true, $indent=-1, $section=-1) {
810393c8 1879 global $CFG, $USER;
94361e02 1880
3d575e6f 1881 static $str;
37a88449 1882 static $sesskey;
3d575e6f 1883
1884 if (!isset($str)) {
1885 $str->delete = get_string("delete");
1886 $str->move = get_string("move");
1887 $str->moveup = get_string("moveup");
1888 $str->movedown = get_string("movedown");
1889 $str->moveright = get_string("moveright");
1890 $str->moveleft = get_string("moveleft");
1891 $str->update = get_string("update");
d33a2a6f 1892 $str->duplicate = get_string("duplicate");
3d575e6f 1893 $str->hide = get_string("hide");
1894 $str->show = get_string("show");
1895 $str->clicktochange = get_string("clicktochange");
32d03b7b 1896 $str->forcedmode = get_string("forcedmode");
3d575e6f 1897 $str->groupsnone = get_string("groupsnone");
1898 $str->groupsseparate = get_string("groupsseparate");
1899 $str->groupsvisible = get_string("groupsvisible");
37a88449 1900 $sesskey = sesskey();
1acfbce5 1901 }
94361e02 1902
24e1eae4 1903 if ($section >= 0) {
75f087b6 1904 $section = '&amp;sr='.$section; // Section return
24e1eae4 1905 } else {
1906 $section = '';
1907 }
1908
94361e02 1909 if ($absolute) {
37a88449 1910 $path = $CFG->wwwroot.'/course';
dc0dc7d5 1911 } else {
37a88449 1912 $path = '.';
dc0dc7d5 1913 }
1914
3d575e6f 1915 if ($mod->visible) {
37a88449 1916 $hideshow = '<a title="'.$str->hide.'" href="'.$path.'/mod.php?hide='.$mod->id.
1917 '&amp;sesskey='.$sesskey.$section.'"><img'.
1918 ' src="'.$CFG->pixpath.'/t/hide.gif" hspace="2" height="11" width="11" '.
1919 ' border="0" alt="'.$str->hide.'" /></a> ';
1acfbce5 1920 } else {
37a88449 1921 $hideshow = '<a title="'.$str->show.'" href="'.$path.'/mod.php?show='.$mod->id.
1922 '&amp;sesskey='.$sesskey.$section.'"><img'.
1923 ' src="'.$CFG->pixpath.'/t/show.gif" hspace="2" height="11" width="11" '.
1924 ' border="0" alt="'.$str->show.'" /></a> ';
7977cffd 1925 }
3d575e6f 1926 if ($mod->groupmode !== false) {
1927 if ($mod->groupmode == SEPARATEGROUPS) {
32d03b7b 1928 $grouptitle = $str->groupsseparate;
37a88449 1929 $groupimage = $CFG->pixpath.'/t/groups.gif';
1930 $grouplink = $path.'/mod.php?id='.$mod->id.'&amp;groupmode=0&amp;sesskey='.$sesskey;
3d575e6f 1931 } else if ($mod->groupmode == VISIBLEGROUPS) {
32d03b7b 1932 $grouptitle = $str->groupsvisible;
37a88449 1933 $groupimage = $CFG->pixpath.'/t/groupv.gif';
1934 $grouplink = $path.'/mod.php?id='.$mod->id.'&amp;groupmode=1&amp;sesskey='.$sesskey;
32d03b7b 1935 } else {
1936 $grouptitle = $str->groupsnone;
37a88449 1937 $groupimage = $CFG->pixpath.'/t/groupn.gif';
1938 $grouplink = $path.'/mod.php?id='.$mod->id.'&amp;groupmode=2&amp;sesskey='.$sesskey;
32d03b7b 1939 }
1940 if ($mod->groupmodelink) {
37a88449 1941 $groupmode = '<a title="'.$grouptitle.' ('.$str->clicktochange.')" href="'.$grouplink.'">'.
1942 '<img src="'.$groupimage.'" hspace="2" height="11" width="11" '.
1943 'border="0" alt="'.$grouptitle.'" /></a>';
3d575e6f 1944 } else {
37a88449 1945 $groupmode = '<img title="'.$grouptitle.' ('.$str->forcedmode.')" '.
1946 ' src="'.$groupimage.'" hspace="2" height="11" width="11" '.
1947 'border="0" alt="'.$grouptitle.'" />';
3d575e6f 1948 }
1949 } else {
1950 $groupmode = "";
1951 }
7977cffd 1952
1953 if ($moveselect) {
37a88449 1954 $move = '<a title="'.$str->move.'" href="'.$path.'/mod.php?copy='.$mod->id.
1955 '&amp;sesskey='.$sesskey.$section.'"><img'.
1956 ' src="'.$CFG->pixpath.'/t/move.gif" hspace="2" height="11" width="11" '.
1957 ' border="0" alt="'.$str->move.'" /></a>';
493486c4 1958 } else {
37a88449 1959 $move = '<a title="'.$str->moveup.'" href="'.$path.'/mod.php?id='.$mod->id.
1960 '&amp;move=-1&amp;sesskey='.$sesskey.$section.'"><img'.
1961 ' src="'.$CFG->pixpath.'/t/up.gif" hspace="2" height="11" width="11" '.
1962 ' border="0" alt="'.$str->moveup.'" /></a>'.
1963 '<a title="'.$str->movedown.'" href="'.$path.'/mod.php?id='.$mod->id.
1964 '&amp;move=1&amp;sesskey='.$sesskey.$section.'"><img'.
1965 ' src="'.$CFG->pixpath.'/t/down.gif" hspace="2" height="11" width="11" '.
1966 ' border="0" alt="'.$str->movedown.'" /></a>';
7977cffd 1967 }
1968
aac94fd0 1969 $leftright = "";
1970 if ($indent > 0) {
37a88449 1971 $leftright .= '<a title="'.$str->moveleft.'" href="'.$path.'/mod.php?id='.$mod->id.
1972 '&amp;indent=-1&amp;sesskey='.$sesskey.$section.'"><img'.
1973 ' src="'.$CFG->pixpath.'/t/left.gif" hspace="2" height="11" width="11" '.
1974 ' border="0" alt="'.$str->moveleft.'" /></a>';
aac94fd0 1975 }
1976 if ($indent >= 0) {
37a88449 1977 $leftright .= '<a title="'.$str->moveright.'" href="'.$path.'/mod.php?id='.$mod->id.
1978 '&amp;indent=1&amp;sesskey='.$sesskey.$section.'"><img'.
1979 ' src="'.$CFG->pixpath.'/t/right.gif" hspace="2" height="11" width="11" '.
1980 ' border="0" alt="'.$str->moveright.'" /></a>';
1981 }
1982
1983 return '<span class="commands">'.$leftright.$move.
1984 '<a title="'.$str->update.'" href="'.$path.'/mod.php?update='.$mod->id.
1985 '&amp;sesskey='.$sesskey.$section.'"><img'.
1986 ' src="'.$CFG->pixpath.'/t/edit.gif" hspace="2" height="11" width="11" border="0" '.
1987 ' alt="'.$str->update.'" /></a>'.
1988 '<a title="'.$str->delete.'" href="'.$path.'/mod.php?delete='.$mod->id.
1989 '&amp;sesskey='.$sesskey.$section.'"><img'.
1990 ' src="'.$CFG->pixpath.'/t/delete.gif" hspace="2" height="11" width="11" border="0" '.
1991 ' alt="'.$str->delete.'" /></a>'.$hideshow.$groupmode.'</span>';
90845098 1992}
1993
b61efafb 1994/**
1995 * given a course object with shortname & fullname, this function will
1996 * truncate the the number of chars allowed and add ... if it was too long
1997 */
1998function course_format_name ($course,$max=100) {
1999
2000 $str = $course->shortname.': '.$course->fullname;
2001 if (strlen($str) <= $max) {
2002 return $str;
2003 }
2004 else {
2005 return substr($str,0,$max-3).'...';
2006 }
2007}
2008
2009/**
2010 * This function will return true if the given course is a child course at all
2011 */
2012function course_in_meta ($course) {
5f37b628 2013 return record_exists("course_meta","child_course",$course->id);
b61efafb 2014}
2015
48e535bc 2016
2017/**
2018 * Print standard form elements on module setup forms in mod/.../mod.html
2019 */
2020function print_standard_coursemodule_settings($form) {
da2224f8 2021 if (! $course = get_record('course', 'id', $form->course)) {
2022 error("This course doesn't exist");
2023 }
2024 print_groupmode_setting($form, $course);
2025 print_visible_setting($form, $course);
48e535bc 2026}
2027
2028/**
2029 * Print groupmode form element on module setup forms in mod/.../mod.html
2030 */
5ebb746b 2031function print_groupmode_setting($form, $course=NULL) {
48e535bc 2032
5ebb746b 2033 if (empty($course)) {
2034 if (! $course = get_record('course', 'id', $form->course)) {
2035 error("This course doesn't exist");
2036 }
2037 }
48e535bc 2038 if ($form->coursemodule) {
2039 if (! $cm = get_record('course_modules', 'id', $form->coursemodule)) {
2040 error("This course module doesn't exist");
2041 }
2042 } else {
2043 $cm = null;
2044 }
2045 $groupmode = groupmode($course, $cm);
2046 if ($course->groupmode or (!$course->groupmodeforce)) {
2047 echo '<tr valign="top">';
2048 echo '<td align="right"><b>'.get_string('groupmode').':</b></td>';
7bbe08a2 2049 echo '<td align="left">';
48e535bc 2050 unset($choices);
2051 $choices[NOGROUPS] = get_string('groupsnone');
2052 $choices[SEPARATEGROUPS] = get_string('groupsseparate');
2053 $choices[VISIBLEGROUPS] = get_string('groupsvisible');
2054 choose_from_menu($choices, 'groupmode', $groupmode, '', '', 0, false, $course->groupmodeforce);
2055 helpbutton('groupmode', get_string('groupmode'));
2056 echo '</td></tr>';
2057 }
2058}
2059
2060/**
2061 * Print visibility setting form element on module setup forms in mod/.../mod.html
2062 */
5ebb746b 2063function print_visible_setting($form, $course=NULL) {
1ee55c41 2064 if (empty($course)) {
2065 if (! $course = get_record('course', 'id', $form->course)) {
2066 error("This course doesn't exist");
2067 }
2068 }
48e535bc 2069 if ($form->coursemodule) {
2070 $visible = get_field('course_modules', 'visible', 'id', $form->coursemodule);
2071 } else {
2072 $visible = true;
2073 }
2074
2075 if ($form->mode == 'add') { // in this case $form->section is the section number, not the id
2076 $hiddensection = !get_field('course_sections', 'visible', 'section', $form->section, 'course', $form->course);
2077 } else {
2078 $hiddensection = !get_field('course_sections', 'visible', 'id', $form->section);
2079 }
2080 if ($hiddensection) {
2081 $visible = false;
2082 }
2083
2084 echo '<tr valign="top">';
182311e4 2085 echo '<td align="right"><b>'.get_string('visible', '').':</b></td>';
7bbe08a2 2086 echo '<td align="left">';
48e535bc 2087 unset($choices);
1f15db9d 2088 $choices[1] = get_string('show');
2089 $choices[0] = get_string('hide');
48e535bc 2090 choose_from_menu($choices, 'visible', $visible, '', '', 0, false, $hiddensection);
2091 echo '</td></tr>';
2092}
2093
0705ff84 2094function update_restricted_mods($course,$mods) {
2095 delete_records("course_allowed_modules","course",$course->id);
2096 if (empty($course->restrictmodules)) {
2097 return;
2098 }
2099 else {
2100 foreach ($mods as $mod) {
2101 if ($mod == 0)
2102 continue; // this is the 'allow none' option
2103 $am->course = $course->id;
2104 $am->module = $mod;
2105 insert_record("course_allowed_modules",$am);
2106 }
2107 }
2108}
2109
2110/**
2111 * This function will take an int (module id) or a string (module name)
2112 * and return true or false, whether it's allowed in the given course (object)
2113 * $mod is not allowed to be an object, as the field for the module id is inconsistent
2114 * depending on where in the code it's called from (sometimes $mod->id, sometimes $mod->module)
2115 */
2116
2117function course_allowed_module($course,$mod) {
2118 if (empty($course->restrictmodules)) {
2119 return true;
2120 }
51792df0 2121
2122 // i am not sure this capability is correct
2123 if (has_capability('moodle/course:update', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
0705ff84 2124 return true;
2125 }
2126 if (is_numeric($mod)) {
2127 $modid = $mod;
2128 } else if (is_string($mod)) {
cb77cf12 2129 if ($mod = get_field("modules","id","name",$mod))
0705ff84 2130 $modid = $mod;
2131 }
2132 if (empty($modid)) {
2133 return false;
2134 }
2135 return (record_exists("course_allowed_modules","course",$course->id,"module",$modid));
2136}
2137
861efb19 2138/***
2139 *** Efficiently moves many courses around while maintaining
2140 *** sortorder in order.
2141 ***
2142 *** $courseids is an array of course ids
2143 ***
2144 **/
2145
2146function move_courses ($courseids, $categoryid) {
2147
2148 global $CFG;
2149
2150 if (!empty($courseids)) {
2151
2152 $courseids = array_reverse($courseids);
2153
2154 foreach ($courseids as $courseid) {
2155
2156 if (! $course = get_record("course", "id", $courseid)) {
2157 notify("Error finding course $courseid");
2158 } else {
2159 // figure out a sortorder that we can use in the destination category
2160 $sortorder = get_field_sql('SELECT MIN(sortorder)-1 AS min
2161 FROM ' . $CFG->prefix . 'course WHERE category=' . $categoryid);
2162 if ($sortorder === false) {
2163 // the category is empty
2164 // rather than let the db default to 0
2165 // set it to > 100 and avoid extra work in fix_coursesortorder()
2166 $sortorder = 200;
2167 } else if ($sortorder < 10) {
2168 fix_course_sortorder($categoryid);
2169 }
2170
2171 $course->category = $categoryid;
2172 $course->sortorder = $sortorder;
2173 $course->fullname = addslashes($course->fullname);
2174 $course->shortname = addslashes($course->shortname);
2175 $course->summary = addslashes($course->summary);
2176 $course->password = addslashes($course->password);
2177 $course->teacher = addslashes($course->teacher);
2178 $course->teachers = addslashes($course->teachers);
2179 $course->student = addslashes($course->student);
2180 $course->students = addslashes($course->students);
2181
2182 if (!update_record('course', $course)) {
2183 notify("An error occurred - course not moved!");
2184 }
2185 }
2186 }
2187 fix_course_sortorder();
2188 }
2189 return true;
2190}
2191
b63ec9db 2192?>