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