Get a string from moodle.php instead of forum.php
[moodle.git] / course / lib.php
CommitLineData
f9903ed0 1<? // $Id$
2
ef58b822 3$COURSE_FORMATS = array (
b5fe4c93 4 "weeks" => "Weekly layout",
5 "social" => "Social layout",
6 "topics" => "Topics layout"
f9903ed0 7 );
8
ef58b822 9$COURSE_SECTION = array (
b5fe4c93 10 "weeks" => "week",
11 "social" => "section",
12 "topics" => "topic"
d9d1c35d 13 );
14
ef58b822 15$COURSE_MAX_LOG_DISPLAY = 150; // days
16
f9903ed0 17
f9903ed0 18function print_log_selector_form($course, $selecteduser=0, $selecteddate="today") {
19
9481285b 20 global $USER, $CFG;
21
f9903ed0 22 // Get all the possible users
23 $users = array();
720a43ce 24
25 if ($course->category) {
26 if ($students = get_records_sql("SELECT u.* FROM user u, user_students s
27 WHERE s.course = '$course->id' AND s.user = u.id
28 ORDER BY u.lastaccess DESC")) {
29 foreach ($students as $student) {
30 $users["$student->id"] = "$student->firstname $student->lastname";
31 }
32 }
33 if ($teachers = get_records_sql("SELECT u.* FROM user u, user_teachers t
34 WHERE t.course = '$course->id' AND t.user = u.id
35 ORDER BY u.lastaccess DESC")) {
36 foreach ($teachers as $teacher) {
37 $users["$teacher->id"] = "$teacher->firstname $teacher->lastname";
38 }
f9903ed0 39 }
40 }
720a43ce 41
42 if (isadmin()) {
43 if ($ccc = get_records_sql("SELECT * FROM course ORDER BY fullname")) {
44 foreach ($ccc as $cc) {
cfa5d3f2 45 if ($cc->category) {
46 $courses["$cc->id"] = "$cc->fullname";
47 } else {
48 $courses["$cc->id"] = " $cc->fullname (Site)";
49 }
720a43ce 50 }
f9903ed0 51 }
cfa5d3f2 52 asort($courses);
f9903ed0 53 }
54
55 asort($users);
56
57 // Get all the possible dates
9481285b 58 // Note that we are keeping track of real (GMT) time and user time
59 // User time is only used in displays - all calcs and passing is GMT
60
61 $timenow = time(); // GMT
62
63 // What day is it now for the user, and when is midnight that day (in GMT).
9604ccb1 64 $timemidnight = $today = usergetmidnight($timenow);
9481285b 65
66 // Put today up the top of the list
7a302afc 67 $dates = array("$timemidnight" => "Today, ".userdate($timenow, "%e %B %Y") );
9481285b 68
69 if (! $course->startdate) {
70 $course->startdate = $course->timecreated;
71 }
f9903ed0 72
9481285b 73 $numdates = 1;
74 while ($timemidnight > $course->startdate and $numdates < 365) {
f9903ed0 75 $timemidnight = $timemidnight - 86400;
9481285b 76 $timenow = $timenow - 86400;
7a302afc 77 $dates["$timemidnight"] = userdate($timenow, "%A, %e %B %Y");
9481285b 78 $numdates++;
f9903ed0 79 }
80
81 if ($selecteddate == "today") {
82 $selecteddate = $today;
83 }
84
85 echo "<CENTER>";
86 echo "<FORM ACTION=log.php METHOD=get>";
720a43ce 87 if (isadmin()) {
849bc02a 88 choose_from_menu ($courses, "id", $course->id, "");
720a43ce 89 } else {
90 echo "<INPUT TYPE=hidden NAME=id VALUE=\"$course->id\">";
91 }
92 if ($course->category) {
93 choose_from_menu ($users, "user", $selecteduser, "All participants");
94 }
f9903ed0 95 choose_from_menu ($dates, "date", $selecteddate, "Any day");
96 echo "<INPUT TYPE=submit VALUE=\"Show these logs\">";
97 echo "</FORM>";
98 echo "</CENTER>";
99}
100
600149be 101function make_log_url($module, $url) {
102 switch ($module) {
103 case "course":
104 case "user":
105 case "file":
106 case "login":
107 case "lib":
108 case "admin":
109 return "/$module/$url";
110 break;
111 default:
112 return "/mod/$module/$url";
113 break;
114 }
115}
116
117
f9903ed0 118function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
9481285b 119// It is assumed that $date is the GMT time of midnight for that day,
120// and so the next 86400 seconds worth of logs are printed.
f9903ed0 121
720a43ce 122 if ($course->category) {
123 $selector = "WHERE l.course='$course->id' AND l.user = u.id";
124 } else {
125 $selector = "WHERE l.user = u.id"; // Show all courses
126 if ($ccc = get_records_sql("SELECT * FROM course ORDER BY fullname")) {
127 foreach ($ccc as $cc) {
128 $courses[$cc->id] = "$cc->shortname";
129 }
130 }
131 }
f9903ed0 132
133 if ($user) {
134 $selector .= " AND l.user = '$user'";
135 }
136
137 if ($date) {
138 $enddate = $date + 86400;
139 $selector .= " AND l.time > '$date' AND l.time < '$enddate'";
140 }
141
142 if (!$logs = get_records_sql("SELECT l.*, u.firstname, u.lastname, u.picture
600149be 143 FROM log l, user u $selector $order")){
f9903ed0 144 notify("No logs found!");
145 print_footer($course);
146 exit;
147 }
148
149 $count=0;
150 $tt = getdate(time());
151 $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
152 echo "<P ALIGN=CENTER>Displaying ".count($logs)." records</P>";
153 echo "<TABLE BORDER=0 ALIGN=center CELLPADDING=3 CELLSPACING=3>";
154 foreach ($logs as $log) {
600149be 155
156 if ($ld = get_record_sql("SELECT * FROM log_display WHERE module='$log->module' AND action='$log->action'")) {
565f7a95 157 $log->info = get_field($ld->mtable, $ld->field, "id", $log->info);
600149be 158 }
159
f9903ed0 160 echo "<TR>";
720a43ce 161 if (! $course->category) {
162 echo "<TD><FONT SIZE=2><A HREF=\"view.php?id=$log->course\">".$courses[$log->course]."</A></TD>";
163 }
7a302afc 164 echo "<TD ALIGN=right><FONT SIZE=2>".userdate($log->time, "%A")."</TD>";
165 echo "<TD><FONT SIZE=2>".userdate($log->time, "%e %B %Y, %I:%M %p")."</TD>";
f3ecd2c8 166 echo "<TD><FONT SIZE=2><A TITLE=\"$log->ip\" HREF=\"../user/view.php?id=$log->user&course=$log->course\"><B>$log->firstname $log->lastname</B></TD>";
f9903ed0 167 echo "<TD><FONT SIZE=2>";
600149be 168 link_to_popup_window( make_log_url($log->module,$log->url), "fromloglive","$log->module $log->action", 400, 600);
f9903ed0 169 echo "</TD>";
600149be 170 echo "<TD><FONT SIZE=2>$log->info</TD>";
f9903ed0 171 echo "</TR>";
172 }
173 echo "</TABLE>";
174}
175
176
94361e02 177function print_all_courses($cat=1, $style="full", $maxcount=999) {
178 global $CFG;
d887b5a7 179
180 if ($courses = get_records("course", "category", $cat, "fullname ASC")) {
94361e02 181 if ($style == "minimal") {
182 $count = 0;
183 $icon = "<IMG SRC=\"pix/i/course.gif\" HEIGHT=16 WIDTH=16 ALT=\"Course\">";
184 foreach ($courses as $course) {
565f7a95 185 $moddata[]="<A TITLE=\"$course->shortname\" HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</A>";
94361e02 186 $modicon[]=$icon;
187 if ($count++ >= $maxcount) {
188 break;
189 }
190 }
191 $fulllist = "<P><A HREF=\"$CFG->wwwroot/course/\">".get_string("fulllistofcourses")."</A>...";
192 print_side_block("", $moddata, "$fulllist", $modicon);
193
194 } else {
195 foreach ($courses as $course) {
196 print_course($course);
197 echo "<BR>\n";
198 }
d887b5a7 199 }
200
201 } else {
202 echo "<H3>No courses have been defined yet</H3>";
203 }
204}
205
206
f9903ed0 207function print_course($course) {
208
d887b5a7 209 global $CFG;
210
a83fded1 211 if (! $site = get_site()) {
f9903ed0 212 error("Could not find a site!");
213 }
214
d887b5a7 215 print_simple_box_start("CENTER", "100%");
f9903ed0 216
217 echo "<TABLE WIDTH=100%>";
da5c172a 218 echo "<TR VALIGN=top>";
219 echo "<TD VALIGN=top WIDTH=50%>";
7a302afc 220 echo "<P><FONT SIZE=3><B><A TITLE=\"".get_string("entercourse")."\"
9481285b 221 HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</A></B></FONT></P>";
f9903ed0 222 if ($teachers = get_records_sql("SELECT u.* FROM user u, user_teachers t
223 WHERE u.id = t.user AND t.course = '$course->id'
f51ab26b 224 ORDER BY t.authority ASC")) {
f9903ed0 225
226 echo "<P><FONT SIZE=1>\n";
227 foreach ($teachers as $teacher) {
d887b5a7 228 echo "$course->teacher: <A HREF=\"$CFG->wwwroot/user/view.php?id=$teacher->id&course=$site->id\">$teacher->firstname $teacher->lastname</A><BR>";
f9903ed0 229 }
230 echo "</FONT></P>";
da5c172a 231 }
232 if ($course->guest or ($course->password == "")) {
cbc14629 233 echo "<A TITLE=\"This course allows guest users\" HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
d887b5a7 234 echo "<IMG VSPACE=4 ALT=\"\" HEIGHT=16 WIDTH=16 BORDER=0 SRC=\"$CFG->wwwroot/user/user.gif\"></A>&nbsp;&nbsp;";
da5c172a 235 }
236 if ($course->password) {
cbc14629 237 echo "<A TITLE=\"This course requires an enrolment key\" HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
d887b5a7 238 echo "<IMG VSPACE=4 ALT=\"\" HEIGHT=16 WIDTH=16 BORDER=0 SRC=\"$CFG->wwwroot/pix/i/key.gif\"></A>";
da5c172a 239 }
240
241
242 echo "</TD><TD VALIGN=top WIDTH=50%>";
243 echo "<P><FONT SIZE=2>".text_to_html($course->summary)."</FONT></P>";
244 echo "</TD></TR>";
245 echo "</TABLE>";
f9903ed0 246
da5c172a 247 print_simple_box_end();
f9903ed0 248}
249
600149be 250function print_headline($text, $size=2) {
251 echo "<B><FONT SIZE=\"$size\">$text</FONT></B><BR>\n";
252}
253
254function print_recent_activity($course) {
255 // $course is an object
256 // This function trawls through the logs looking for
257 // anything new since the user's last login
258
259 global $CFG, $USER;
260
261 if (! $USER->lastlogin ) {
262 echo "<P>Welcome to the course! Here you will find a list of what's new since your last login.</P>";
263 return;
264 }
265
266 if (! $logs = get_records_sql("SELECT * FROM log WHERE time > '$USER->lastlogin' AND course = '$course->id' ORDER BY time ASC")) {
267 return;
268 }
269
270
271 // Firstly, have there been any new enrolments?
272
273 $heading = false;
274 $content = false;
275 foreach ($logs as $log) {
276 if ($log->module == "course" and $log->action == "enrol") {
277 if (! $heading) {
ef25340c 278 print_headline("New users:");
600149be 279 $heading = true;
280 $content = true;
281 }
282 $user = get_record("user", "id", $log->info);
ef25340c 283 echo "<P><FONT SIZE=1><A HREF=\"../user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</A></FONT></P>";
600149be 284 }
285 }
286
287 // Next, have there been any changes to the course structure?
288
600149be 289 foreach ($logs as $log) {
290 if ($log->module == "course") {
291 if ($log->action == "add mod" or $log->action == "update mod" or $log->action == "delete mod") {
600149be 292 $info = split(" ", $log->info);
293 $modname = get_field($info[0], "name", "id", $info[1]);
294
600149be 295 switch ($log->action) {
296 case "add mod":
ef25340c 297 $changelist["$log->info"] = array ("operation" => "add", "text" => "Added a ".$info[0].":<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>");
600149be 298 break;
299 case "update mod":
ef25340c 300 if (! $changelist["$log->info"]) {
301 $changelist["$log->info"] = array ("operation" => "update", "text" => "Updated the ".$info[0].":<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>");
302 }
600149be 303 break;
304 case "delete mod":
ef25340c 305 if ($changelist["$log->info"]["operation"] == "add") {
306 $changelist["$log->info"] = NULL;
307 } else {
308 $changelist["$log->info"] = array ("operation" => "delete", "text" => "Deleted a ".$info[0]);
309 }
600149be 310 break;
311 }
ef25340c 312 }
313 }
314 }
315
316 if ($changelist) {
317 foreach ($changelist as $changeinfo => $change) {
318 if ($change) {
319 $changes[$changeinfo] = $change;
320 }
321 }
322 if (count($changes) > 0) {
323 print_headline("Course changes:");
324 $content = true;
325 foreach ($changes as $changeinfo => $change) {
326 echo "<P><FONT SIZE=1>".$change["text"]."</FONT></P>";
600149be 327 }
328 }
329 }
330
331
332 // Now all we need to know are the new posts.
333
ef25340c 334 $heading = false;
600149be 335 foreach ($logs as $log) {
336
501cdbd8 337 if ($log->module == "forum") {
600149be 338 $post = NULL;
339
36d4a9a1 340 if ($log->action == "add post") {
f9730aef 341 $post = get_record_sql("SELECT p.*, d.forum, u.firstname, u.lastname,
600149be 342 u.email, u.picture, u.id as userid
501cdbd8 343 FROM forum_discussions d, forum_posts p, user u
344 WHERE p.id = '$log->info' AND d.id = p.discussion AND p.user = u.id");
600149be 345
36d4a9a1 346 } else if ($log->action == "add discussion") {
f9730aef 347 $post = get_record_sql("SELECT p.*, d.forum, u.firstname, u.lastname,
600149be 348 u.email, u.picture, u.id as userid
501cdbd8 349 FROM forum_discussions d, forum_posts p, user u
600149be 350 WHERE d.id = '$log->info' AND d.firstpost = p.id AND p.user = u.id");
351 }
352
353 if ($post) {
f9730aef 354
355 $teacherpost = "";
356 if ($forum = get_record("forum", "id", $post->forum) ) {
357 if ($forum->type == "teacher") {
358 if (!isteacher($course->id)) {
359 continue;
360 } else {
361 $teacherpost = "COLOR=#666666";
362 }
363 }
364 }
600149be 365 if (! $heading) {
ef25340c 366 print_headline("Discussion Posts:");
600149be 367 $heading = true;
368 $content = true;
369 }
f9730aef 370 echo "<P><FONT SIZE=1 $teacherpost>$post->firstname $post->lastname:<BR>";
501cdbd8 371 echo "\"<A HREF=\"$CFG->wwwroot/mod/forum/$log->url\">";
600149be 372 if ($log->action == "add") {
ef25340c 373 echo "<B>$post->subject</B>";
600149be 374 } else {
ef25340c 375 echo "$post->subject";
600149be 376 }
ef25340c 377 echo "</A>\"</FONT></P>";
600149be 378 }
379
380 }
381 }
382
383 if (! $content) {
384 echo "<FONT SIZE=2>Nothing new since your last login</FONT>";
385 }
386
387}
388
e1360728 389
390function unenrol_student_in_course($user, $course) {
391 global $db;
392
393 return $db->Execute("DELETE FROM user_students WHERE user = '$user' AND course = '$course'");
394}
395
396
397
398function enrol_student_in_course($user, $course) {
399 global $db;
400
401 $timenow = time();
402
403 $rs = $db->Execute("INSERT INTO user_students (user, course, start, end, time)
404 VALUES ($user, $course, 0, 0, $timenow)");
405 if ($rs) {
406 return true;
407 } else {
408 return false;
409 }
410}
411
90845098 412function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
413// Returns a number of useful structures for course displays
7468bf01 414
90845098 415 $mods = NULL; // course modules indexed by id
416 $modnames = NULL; // all course module names
94361e02 417 $modnamesplural= NULL; // all course module names (plural form)
90845098 418 $modnamesused = NULL; // course module names used
7468bf01 419
90845098 420 if ($allmods = get_records_sql("SELECT * FROM modules") ) {
421 foreach ($allmods as $mod) {
422 $modnames[$mod->name] = get_string("modulename", "$mod->name");
423 $modnamesplural[$mod->name] = get_string("modulenameplural", "$mod->name");
424 }
425 asort($modnames);
426 } else {
427 error("No modules are installed!");
428 }
429
430 if ($rawmods = get_records_sql("SELECT cm.*, m.name as modname
431 FROM modules m, course_modules cm
432 WHERE cm.course = '$courseid'
433 AND cm.deleted = '0'
94361e02 434 AND cm.module = m.id ") ) {
7468bf01 435 foreach($rawmods as $mod) { // Index the mods
436 $mods[$mod->id] = $mod;
90845098 437 $mods[$mod->id]->modfullname = $modnames[$mod->modname];
438 $modnamesused[$mod->modname] = $modnames[$mod->modname];
7468bf01 439 }
90845098 440 asort($modnamesused);
7468bf01 441 }
7468bf01 442}
443
444function get_all_sections($courseid) {
445
446 return get_records_sql("SELECT section, id, course, summary, sequence
447 FROM course_sections
448 WHERE course = '$courseid'
449 ORDER BY section");
450}
451
94361e02 452function print_section($courseid, $section, $mods, $modnamesused, $absolute=false) {
453 global $CFG;
454
455
456 echo "<P>";
457 if ($section->sequence) {
458
459 $sectionmods = explode(",", $section->sequence);
460
461 foreach ($sectionmods as $modnumber) {
462 $mod = $mods[$modnumber];
463 $instancename = get_field("$mod->modname", "name", "id", "$mod->instance");
464 echo "<IMG SRC=\"$CFG->wwwroot/mod/$mod->modname/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\">";
465 echo " <A TITLE=\"$mod->modfullname\"";
466 echo " HREF=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename</A>";
467 if (isediting($courseid)) {
468 echo make_editing_buttons($mod->id, $absolute);
469 }
470 echo "<BR>\n";
471 }
472 }
473 echo "</P>\n";
474}
475
476
2b8cef80 477function print_log_graph($course, $userid=0, $type="course.png", $date=0) {
478 global $CFG;
479 echo "<IMG BORDER=0 SRC=\"$CFG->wwwroot/course/loggraph.php?id=$course->id&user=$userid&type=$type&date=$date\">";
480}
481
11b0c469 482
483
484/// MODULE FUNCTIONS /////////////////////////////////////////////////////////////////
485
486function add_course_module($mod) {
487 GLOBAL $db;
488
489 $timenow = time();
490
491 if (!$rs = $db->Execute("INSERT into course_modules
492 SET course = '$mod->course',
493 module = '$mod->module',
494 instance = '$mod->instance',
495 section = '$mod->section',
496 added = '$timenow' ")) {
497 return 0;
498 }
499
500 // Get it out again - this is the most compatible way to determine the ID
501 if ($rs = $db->Execute("SELECT id FROM course_modules
502 WHERE module = $mod->module AND added = $timenow")) {
503 return $rs->fields[0];
504 } else {
505 return 0;
506 }
507
508}
509
510function add_mod_to_section($mod) {
511// Returns the course_sections ID where the mod is inserted
512 GLOBAL $db;
513
514 if ($cw = get_record_sql("SELECT * FROM course_sections
515 WHERE course = '$mod->course' AND section = '$mod->section'") ) {
516
517 if ($cw->sequence) {
518 $newsequence = "$cw->sequence,$mod->coursemodule";
519 } else {
520 $newsequence = "$mod->coursemodule";
521 }
522 if (!$rs = $db->Execute("UPDATE course_sections SET sequence = '$newsequence' WHERE id = '$cw->id'")) {
523 return 0;
524 } else {
525 return $cw->id; // Return course_sections ID that was used.
526 }
527
528 } else { // Insert a new record
529 if (!$rs = $db->Execute("INSERT into course_sections
530 SET course = '$mod->course',
531 section = '$mod->section',
532 summary = '',
533 sequence = '$mod->coursemodule' ")) {
534 return 0;
535 }
536 // Get it out again - this is the most compatible way to determine the ID
537 if ($rs = $db->Execute("SELECT id FROM course_sections
538 WHERE course = '$mod->course' AND section = '$mod->section'")) {
539 return $rs->fields[0];
540 } else {
541 return 0;
542 }
543 }
544}
545
546function delete_course_module($mod) {
547 return set_field("course_modules", "deleted", 1, "id", $mod);
548}
549
550function delete_mod_from_section($mod, $section) {
551 GLOBAL $db;
552
553 if ($cw = get_record("course_sections", "id", "$section") ) {
554
555 $modarray = explode(",", $cw->sequence);
556
557 if ($key = array_keys ($modarray, $mod)) {
558 array_splice($modarray, $key[0], 1);
559 $newsequence = implode(",", $modarray);
560 return set_field("course_sections", "sequence", $newsequence, "id", $cw->id);
561 } else {
562 return false;
563 }
564
565 } else {
566 return false;
567 }
568}
569
570
571function move_module($id, $move) {
572 GLOBAL $db;
573
574 if (!$move) {
575 return true;
576 }
577
578 if (! $cm = get_record("course_modules", "id", $id)) {
579 error("This course module doesn't exist");
580 }
581
582 if (! $thissection = get_record("course_sections", "id", $cm->section)) {
583 error("This course section doesn't exist");
584 }
585
586 $mods = explode(",", $thissection->sequence);
587
588 $len = count($mods);
589 $pos = array_keys($mods, $cm->id);
590 $thepos = $pos[0];
591
592 if ($len == 0 || count($pos) == 0 ) {
593 error("Very strange. Could not find the required module in this section.");
594 }
595
596 if ($len == 1) {
597 $first = true;
598 $last = true;
599 } else {
600 $first = ($thepos == 0);
601 $last = ($thepos == $len - 1);
602 }
603
604 if ($move < 0) { // Moving the module up
605
606 if ($first) {
607 if ($thissection->section == 1) { // First section, do nothing
608 return true;
609 } else { // Push onto end of previous section
610 $prevsectionnumber = $thissection->section - 1;
611 if (! $prevsection = get_record_sql("SELECT * FROM course_sections
612 WHERE course='$thissection->course'
613 AND section='$prevsectionnumber' ")) {
614 error("Previous section ($prevsection->id) doesn't exist");
615 }
616
617 if ($prevsection->sequence) {
618 $newsequence = "$prevsection->sequence,$cm->id";
619 } else {
620 $newsequence = "$cm->id";
621 }
622
623 if (! set_field("course_sections", "sequence", $newsequence, "id", $prevsection->id)) {
624 error("Previous section could not be updated");
625 }
626
627 if (! set_field("course_modules", "section", $prevsection->id, "id", $cm->id)) {
628 error("Module could not be updated");
629 }
630
631 array_splice($mods, 0, 1);
632 $newsequence = implode(",", $mods);
633 if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
634 error("Module could not be updated");
635 }
636
637 return true;
638
639 }
640 } else { // move up within this section
641 $swap = $mods[$thepos-1];
642 $mods[$thepos-1] = $mods[$thepos];
643 $mods[$thepos] = $swap;
644
645 $newsequence = implode(",", $mods);
646 if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
647 error("This section could not be updated");
648 }
649 return true;
650 }
651
652 } else { // Moving the module down
653
654 if ($last) {
655 $nextsectionnumber = $thissection->section + 1;
656 if ($nextsection = get_record_sql("SELECT * FROM course_sections
657 WHERE course='$thissection->course'
658 AND section='$nextsectionnumber' ")) {
659
660 if ($nextsection->sequence) {
661 $newsequence = "$cm->id,$nextsection->sequence";
662 } else {
663 $newsequence = "$cm->id";
664 }
665
666 if (! set_field("course_sections", "sequence", $newsequence, "id", $nextsection->id)) {
667 error("Next section could not be updated");
668 }
669
670 if (! set_field("course_modules", "section", $nextsection->id, "id", $cm->id)) {
671 error("Module could not be updated");
672 }
673
674 array_splice($mods, $thepos, 1);
675 $newsequence = implode(",", $mods);
676 if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
677 error("This section could not be updated");
678 }
679 return true;
680
681 } else { // There is no next section, so just return
682 return true;
683
684 }
685 } else { // move down within this section
686 $swap = $mods[$thepos+1];
687 $mods[$thepos+1] = $mods[$thepos];
688 $mods[$thepos] = $swap;
689
690 $newsequence = implode(",", $mods);
691 if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
692 error("This section could not be updated");
693 }
694 return true;
695 }
696 }
697}
698
94361e02 699function make_editing_buttons($moduleid, $absolute=false) {
700 global $CFG;
701
90845098 702 $delete = get_string("delete");
703 $moveup = get_string("moveup");
704 $movedown = get_string("movedown");
705 $update = get_string("update");
94361e02 706
707 if ($absolute) {
708 $path = "$CFG->wwwroot/course/";
709 } else {
710 $path = "";
711 }
90845098 712 return "&nbsp; &nbsp;
94361e02 713 <A HREF=\"".$path."mod.php?delete=$moduleid\"><IMG
714 SRC=".$path."../pix/t/delete.gif BORDER=0 ALT=\"$delete\"></A>
715 <A HREF=\"".$path."mod.php?id=$moduleid&move=-1\"><IMG
716 SRC=".$path."../pix/t/up.gif BORDER=0 ALT=\"$moveup\"></A>
717 <A HREF=\"".$path."mod.php?id=$moduleid&move=1\"><IMG
718 SRC=".$path."../pix/t/down.gif BORDER=0 ALT=\"$movedown\"></A>
719 <A HREF=\"".$path."mod.php?update=$moduleid\"><IMG
720 SRC=".$path."../pix/t/edit.gif BORDER=0 ALT=\"$update\"></A>";
90845098 721}
722
723function print_side_block($heading="", $list=NULL, $footer="", $icons=NULL) {
724
725 echo "<TABLE WIDTH=100%>\n";
726 echo "<TR><TD COLSPAN=2><P><B><FONT SIZE=2>$heading</TD></TR>\n";
727 if ($list) {
728 foreach($list as $key => $string) {
729 echo "<TR><TD VALIGN=top WIDTH=12>";
730 if ($icons[$key]) {
731 echo $icons[$key];
732 } else {
733 echo "";
734 }
735 echo "</TD>\n<TD WIDTH=100% VALIGN=top>";
736 echo "<P><FONT SIZE=2>$string</FONT></P>";
737 echo "</TD></TR>\n";
738 }
739 }
740 if ($footer) {
741 echo "<TR><TD></TD><TD ALIGN=left><P><FONT SIZE=2>$footer</TD></TR>\n";
742 }
743 echo "</TABLE><BR>\n\n";
744}
11b0c469 745
f9903ed0 746?>