2001-11-22 06:23:56 +00:00
|
|
|
<? // $Id$
|
2002-08-11 15:41:54 +00:00
|
|
|
// Library of useful functions
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
|
2002-08-11 15:41:54 +00:00
|
|
|
$COURSE_MAX_LOG_DISPLAY = 150; // days
|
2002-06-25 07:56:26 +00:00
|
|
|
|
2002-08-11 15:41:54 +00:00
|
|
|
$COURSE_TEACHER_COLOR = "#990000"; // To hilight certain items that are teacher-only
|
2002-08-10 13:50:38 +00:00
|
|
|
|
2002-08-11 15:41:54 +00:00
|
|
|
$COURSE_LIVELOG_REFRESH = 60; // Seconds
|
2002-08-01 15:48:27 +00:00
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
function print_log_selector_form($course, $selecteduser=0, $selecteddate="today") {
|
|
|
|
|
2002-06-10 09:44:37 +00:00
|
|
|
global $USER, $CFG;
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
// Get all the possible users
|
|
|
|
$users = array();
|
2002-06-12 04:22:41 +00:00
|
|
|
|
|
|
|
if ($course->category) {
|
2002-12-20 14:44:14 +00:00
|
|
|
if (!$users = get_course_users($course->id, "u.lastaccess DESC")) {
|
|
|
|
$users = array();
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($guest = get_guest()) {
|
2002-09-11 02:26:56 +00:00
|
|
|
$users["$guest->id"] = "$guest->firstname $guest->lastname";
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2002-06-12 04:22:41 +00:00
|
|
|
|
|
|
|
if (isadmin()) {
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($ccc = get_records("course", "", "", "fullname")) {
|
2002-06-12 04:22:41 +00:00
|
|
|
foreach ($ccc as $cc) {
|
2002-06-12 04:29:03 +00:00
|
|
|
if ($cc->category) {
|
|
|
|
$courses["$cc->id"] = "$cc->fullname";
|
|
|
|
} else {
|
|
|
|
$courses["$cc->id"] = " $cc->fullname (Site)";
|
|
|
|
}
|
2002-06-12 04:22:41 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
2002-06-12 04:29:03 +00:00
|
|
|
asort($courses);
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
asort($users);
|
|
|
|
|
|
|
|
// Get all the possible dates
|
2002-06-10 09:44:37 +00:00
|
|
|
// Note that we are keeping track of real (GMT) time and user time
|
|
|
|
// User time is only used in displays - all calcs and passing is GMT
|
|
|
|
|
|
|
|
$timenow = time(); // GMT
|
|
|
|
|
|
|
|
// What day is it now for the user, and when is midnight that day (in GMT).
|
2002-06-11 04:28:01 +00:00
|
|
|
$timemidnight = $today = usergetmidnight($timenow);
|
2002-06-10 09:44:37 +00:00
|
|
|
|
|
|
|
// Put today up the top of the list
|
2002-11-19 14:27:57 +00:00
|
|
|
$dates = array("$timemidnight" => get_string("today").", ".userdate($timenow, "%d %B %Y") );
|
2002-06-10 09:44:37 +00:00
|
|
|
|
|
|
|
if (! $course->startdate) {
|
|
|
|
$course->startdate = $course->timecreated;
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-06-10 09:44:37 +00:00
|
|
|
$numdates = 1;
|
|
|
|
while ($timemidnight > $course->startdate and $numdates < 365) {
|
2001-11-22 06:23:56 +00:00
|
|
|
$timemidnight = $timemidnight - 86400;
|
2002-06-10 09:44:37 +00:00
|
|
|
$timenow = $timenow - 86400;
|
2002-11-19 14:27:57 +00:00
|
|
|
$dates["$timemidnight"] = userdate($timenow, "%A, %d %B %Y");
|
2002-06-10 09:44:37 +00:00
|
|
|
$numdates++;
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($selecteddate == "today") {
|
|
|
|
$selecteddate = $today;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "<CENTER>";
|
|
|
|
echo "<FORM ACTION=log.php METHOD=get>";
|
2002-06-12 04:22:41 +00:00
|
|
|
if (isadmin()) {
|
2002-06-12 04:31:08 +00:00
|
|
|
choose_from_menu ($courses, "id", $course->id, "");
|
2002-06-12 04:22:41 +00:00
|
|
|
} else {
|
|
|
|
echo "<INPUT TYPE=hidden NAME=id VALUE=\"$course->id\">";
|
|
|
|
}
|
|
|
|
if ($course->category) {
|
2002-08-11 15:41:54 +00:00
|
|
|
choose_from_menu ($users, "user", $selecteduser, get_string("allparticipants") );
|
2002-06-12 04:22:41 +00:00
|
|
|
}
|
2002-08-11 15:41:54 +00:00
|
|
|
choose_from_menu ($dates, "date", $selecteddate, get_string("alldays"));
|
|
|
|
echo "<INPUT TYPE=submit VALUE=\"".get_string("showtheselogs")."\">";
|
2001-11-22 06:23:56 +00:00
|
|
|
echo "</FORM>";
|
|
|
|
echo "</CENTER>";
|
|
|
|
}
|
|
|
|
|
2002-05-31 09:34:50 +00:00
|
|
|
function make_log_url($module, $url) {
|
|
|
|
switch ($module) {
|
|
|
|
case "course":
|
|
|
|
case "user":
|
|
|
|
case "file":
|
|
|
|
case "login":
|
|
|
|
case "lib":
|
|
|
|
case "admin":
|
|
|
|
return "/$module/$url";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return "/mod/$module/$url";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
|
2002-06-10 09:44:37 +00:00
|
|
|
// It is assumed that $date is the GMT time of midnight for that day,
|
|
|
|
// and so the next 86400 seconds worth of logs are printed.
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-12-30 05:13:43 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2002-06-12 04:22:41 +00:00
|
|
|
if ($course->category) {
|
2002-12-23 09:39:26 +00:00
|
|
|
$selector = "WHERE l.course='$course->id' AND l.userid = u.id";
|
2002-08-08 16:22:44 +00:00
|
|
|
|
2002-06-12 04:22:41 +00:00
|
|
|
} else {
|
2002-12-23 09:39:26 +00:00
|
|
|
$selector = "WHERE l.userid = u.id"; // Show all courses
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($ccc = get_courses(-1)) {
|
2002-06-12 04:22:41 +00:00
|
|
|
foreach ($ccc as $cc) {
|
|
|
|
$courses[$cc->id] = "$cc->shortname";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
if ($user) {
|
2002-12-23 09:39:26 +00:00
|
|
|
$selector .= " AND l.userid = '$user'";
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($date) {
|
|
|
|
$enddate = $date + 86400;
|
|
|
|
$selector .= " AND l.time > '$date' AND l.time < '$enddate'";
|
|
|
|
}
|
|
|
|
|
2002-12-23 10:27:57 +00:00
|
|
|
if (!$logs = get_logs($selector, $order)) {
|
2001-11-22 06:23:56 +00:00
|
|
|
notify("No logs found!");
|
|
|
|
print_footer($course);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
$count=0;
|
|
|
|
$tt = getdate(time());
|
|
|
|
$today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]);
|
2002-12-20 14:44:14 +00:00
|
|
|
echo "<P ALIGN=CENTER>";
|
|
|
|
print_string("displayingrecords", "", count($logs));
|
|
|
|
echo "</P>";
|
2001-11-22 06:23:56 +00:00
|
|
|
echo "<TABLE BORDER=0 ALIGN=center CELLPADDING=3 CELLSPACING=3>";
|
|
|
|
foreach ($logs as $log) {
|
2002-05-31 09:34:50 +00:00
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($ld = get_record("log_display", "module", "$log->module", "action", "$log->action")) {
|
2002-08-04 02:08:43 +00:00
|
|
|
$log->info = get_field($ld->mtable, $ld->field, "id", $log->info);
|
2002-05-31 09:34:50 +00:00
|
|
|
}
|
|
|
|
|
2002-08-15 13:05:14 +00:00
|
|
|
echo "<TR NOWRAP>";
|
2002-06-12 04:22:41 +00:00
|
|
|
if (! $course->category) {
|
2002-08-15 13:05:14 +00:00
|
|
|
echo "<TD NOWRAP><FONT SIZE=2><A HREF=\"view.php?id=$log->course\">".$courses[$log->course]."</A></TD>";
|
2002-06-12 04:22:41 +00:00
|
|
|
}
|
2002-08-15 13:05:14 +00:00
|
|
|
echo "<TD NOWRAP ALIGN=right><FONT SIZE=2>".userdate($log->time, "%A")."</TD>";
|
2002-11-19 14:27:57 +00:00
|
|
|
echo "<TD NOWRAP><FONT SIZE=2>".userdate($log->time, "%d %B %Y, %I:%M %p")."</TD>";
|
2002-08-26 09:00:57 +00:00
|
|
|
echo "<TD NOWRAP><FONT SIZE=2>";
|
2002-12-30 05:13:43 +00:00
|
|
|
link_to_popup_window("/lib/ipatlas/plot.php?address=$log->ip&user=$log->userid", "ipatlas","$log->ip", 400, 700);
|
2002-08-26 09:00:57 +00:00
|
|
|
echo "</TD>";
|
2002-12-23 09:39:26 +00:00
|
|
|
echo "<TD NOWRAP><FONT SIZE=2><A HREF=\"../user/view.php?id=$log->userid&course=$log->course\"><B>$log->firstname $log->lastname</B></TD>";
|
2002-08-15 13:05:14 +00:00
|
|
|
echo "<TD NOWRAP><FONT SIZE=2>";
|
2002-05-31 09:34:50 +00:00
|
|
|
link_to_popup_window( make_log_url($log->module,$log->url), "fromloglive","$log->module $log->action", 400, 600);
|
2001-11-22 06:23:56 +00:00
|
|
|
echo "</TD>";
|
2002-08-15 13:05:14 +00:00
|
|
|
echo "<TD NOWRAP><FONT SIZE=2>$log->info</TD>";
|
2001-11-22 06:23:56 +00:00
|
|
|
echo "</TR>";
|
|
|
|
}
|
|
|
|
echo "</TABLE>";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-09 07:52:47 +00:00
|
|
|
function print_all_courses($category="all", $style="full", $maxcount=999, $width=180) {
|
2002-09-09 12:37:34 +00:00
|
|
|
global $CFG, $USER;
|
2002-06-10 05:19:03 +00:00
|
|
|
|
2002-09-09 11:48:11 +00:00
|
|
|
if ($category == "all") {
|
2002-12-20 14:44:14 +00:00
|
|
|
$courses = get_courses();
|
2002-09-09 12:37:34 +00:00
|
|
|
|
|
|
|
} else if ($category == "my") {
|
|
|
|
if (isset($USER->id)) {
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($courses = get_courses()) {
|
2002-09-09 12:37:34 +00:00
|
|
|
foreach ($courses as $key => $course) {
|
|
|
|
if (!isteacher($course->id) and !isstudent($course->id)) {
|
|
|
|
unset($courses[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-09 11:48:11 +00:00
|
|
|
} else {
|
2002-12-20 14:44:14 +00:00
|
|
|
$courses = get_courses($category);
|
2002-09-09 11:48:11 +00:00
|
|
|
}
|
|
|
|
|
2002-12-15 06:00:58 +00:00
|
|
|
if ($style == "minimal") {
|
|
|
|
$count = 0;
|
|
|
|
$icon = "<IMG SRC=\"pix/i/course.gif\" HEIGHT=16 WIDTH=16 ALT=\"".get_string("course")."\">";
|
|
|
|
if ($courses) {
|
2002-08-03 08:16:31 +00:00
|
|
|
foreach ($courses as $course) {
|
2002-08-04 02:08:43 +00:00
|
|
|
$moddata[]="<A TITLE=\"$course->shortname\" HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</A>";
|
2002-08-03 08:16:31 +00:00
|
|
|
$modicon[]=$icon;
|
|
|
|
if ($count++ >= $maxcount) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$fulllist = "<P><A HREF=\"$CFG->wwwroot/course/\">".get_string("fulllistofcourses")."</A>...";
|
|
|
|
} else {
|
2002-12-15 06:00:58 +00:00
|
|
|
$moddata = array();
|
|
|
|
$modicon = array();
|
|
|
|
$fulllist = get_string("nocoursesyet");
|
|
|
|
}
|
|
|
|
print_side_block(get_string("courses"), "", $moddata, $modicon, $fulllist, $width);
|
|
|
|
|
|
|
|
} else if ($courses) {
|
|
|
|
foreach ($courses as $course) {
|
|
|
|
print_course($course);
|
|
|
|
echo "<BR>\n";
|
2002-06-10 05:19:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2002-12-15 06:00:58 +00:00
|
|
|
echo "<P>".get_string("nocoursesyet")."</P>";
|
2002-06-10 05:19:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
function print_course($course) {
|
|
|
|
|
2002-06-10 05:19:03 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2002-07-11 05:30:10 +00:00
|
|
|
if (! $site = get_site()) {
|
2001-11-22 06:23:56 +00:00
|
|
|
error("Could not find a site!");
|
|
|
|
}
|
|
|
|
|
2002-06-10 05:19:03 +00:00
|
|
|
print_simple_box_start("CENTER", "100%");
|
2001-11-22 06:23:56 +00:00
|
|
|
|
|
|
|
echo "<TABLE WIDTH=100%>";
|
2002-06-09 14:14:07 +00:00
|
|
|
echo "<TR VALIGN=top>";
|
|
|
|
echo "<TD VALIGN=top WIDTH=50%>";
|
2002-07-02 07:02:28 +00:00
|
|
|
echo "<P><FONT SIZE=3><B><A TITLE=\"".get_string("entercourse")."\"
|
2002-06-10 09:44:37 +00:00
|
|
|
HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</A></B></FONT></P>";
|
2002-09-01 14:47:03 +00:00
|
|
|
if ($teachers = get_course_teachers($course->id)) {
|
2001-11-22 06:23:56 +00:00
|
|
|
echo "<P><FONT SIZE=1>\n";
|
|
|
|
foreach ($teachers as $teacher) {
|
2002-09-01 14:47:03 +00:00
|
|
|
if ($teacher->authority > 0) {
|
2002-09-08 03:24:38 +00:00
|
|
|
if (!$teacher->role) {
|
|
|
|
$teacher->role = $course->teacher;
|
|
|
|
}
|
|
|
|
echo "$teacher->role: <A HREF=\"$CFG->wwwroot/user/view.php?id=$teacher->id&course=$site->id\">$teacher->firstname $teacher->lastname</A><BR>";
|
2002-09-01 14:47:03 +00:00
|
|
|
}
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
echo "</FONT></P>";
|
2002-06-09 14:14:07 +00:00
|
|
|
}
|
2002-09-26 11:10:20 +00:00
|
|
|
if ($course->guest) {
|
2002-12-09 07:35:40 +00:00
|
|
|
$strallowguests = get_string("allowguests");
|
|
|
|
echo "<A TITLE=\"$strallowguests\" HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
|
|
|
|
echo "<IMG VSPACE=4 ALT=\"$strallowguests\" HEIGHT=16 WIDTH=16 BORDER=0 SRC=\"$CFG->wwwroot/user/user.gif\"></A> ";
|
2002-06-09 14:14:07 +00:00
|
|
|
}
|
|
|
|
if ($course->password) {
|
2002-12-09 07:35:40 +00:00
|
|
|
$strrequireskey = get_string("requireskey");
|
|
|
|
echo "<A TITLE=\"$strrequireskey\" HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
|
|
|
|
echo "<IMG VSPACE=4 ALT=\"$strrequireskey\" HEIGHT=16 WIDTH=16 BORDER=0 SRC=\"$CFG->wwwroot/pix/i/key.gif\"></A>";
|
2002-06-09 14:14:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
echo "</TD><TD VALIGN=top WIDTH=50%>";
|
|
|
|
echo "<P><FONT SIZE=2>".text_to_html($course->summary)."</FONT></P>";
|
|
|
|
echo "</TD></TR>";
|
|
|
|
echo "</TABLE>";
|
2001-11-22 06:23:56 +00:00
|
|
|
|
2002-06-09 14:14:07 +00:00
|
|
|
print_simple_box_end();
|
2001-11-22 06:23:56 +00:00
|
|
|
}
|
|
|
|
|
2002-05-31 09:34:50 +00:00
|
|
|
function print_headline($text, $size=2) {
|
|
|
|
echo "<B><FONT SIZE=\"$size\">$text</FONT></B><BR>\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_recent_activity($course) {
|
|
|
|
// $course is an object
|
|
|
|
// This function trawls through the logs looking for
|
|
|
|
// anything new since the user's last login
|
|
|
|
|
2002-08-11 15:41:54 +00:00
|
|
|
global $CFG, $USER, $COURSE_TEACHER_COLOR;
|
2002-05-31 09:34:50 +00:00
|
|
|
|
|
|
|
if (! $USER->lastlogin ) {
|
2002-08-10 14:27:14 +00:00
|
|
|
echo "<P ALIGN=CENTER><FONT SIZE=1>";
|
2002-08-11 05:11:50 +00:00
|
|
|
print_string("welcometocourse", "", $course->shortname);
|
2002-08-10 14:27:14 +00:00
|
|
|
echo "</FONT></P>";
|
2002-05-31 09:34:50 +00:00
|
|
|
return;
|
2002-08-10 14:27:14 +00:00
|
|
|
} else {
|
|
|
|
echo "<P ALIGN=CENTER><FONT SIZE=1>";
|
|
|
|
echo get_string("yourlastlogin").":<BR>";
|
2002-11-19 14:27:57 +00:00
|
|
|
echo userdate($USER->lastlogin, "%A, %d %b %Y, %H:%M");
|
2002-08-10 14:27:14 +00:00
|
|
|
echo "</FONT></P>";
|
2002-05-31 09:34:50 +00:00
|
|
|
}
|
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
if (! $logs = get_records_select("log", "time > '$USER->lastlogin' AND course = '$course->id'", "time ASC")) {
|
2002-05-31 09:34:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Firstly, have there been any new enrolments?
|
|
|
|
|
|
|
|
$heading = false;
|
|
|
|
$content = false;
|
|
|
|
foreach ($logs as $log) {
|
|
|
|
if ($log->module == "course" and $log->action == "enrol") {
|
|
|
|
if (! $heading) {
|
2002-08-10 14:27:14 +00:00
|
|
|
print_headline(get_string("newusers").":");
|
2002-05-31 09:34:50 +00:00
|
|
|
$heading = true;
|
|
|
|
$content = true;
|
|
|
|
}
|
|
|
|
$user = get_record("user", "id", $log->info);
|
2002-09-22 14:06:38 +00:00
|
|
|
if (isstudent($course->id, $user->id)) {
|
|
|
|
echo "<P><FONT SIZE=1><A HREF=\"../user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname</A></FONT></P>";
|
|
|
|
}
|
2002-05-31 09:34:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next, have there been any changes to the course structure?
|
|
|
|
|
|
|
|
foreach ($logs as $log) {
|
|
|
|
if ($log->module == "course") {
|
|
|
|
if ($log->action == "add mod" or $log->action == "update mod" or $log->action == "delete mod") {
|
|
|
|
$info = split(" ", $log->info);
|
|
|
|
$modname = get_field($info[0], "name", "id", $info[1]);
|
|
|
|
|
|
|
|
switch ($log->action) {
|
|
|
|
case "add mod":
|
2002-08-11 05:24:25 +00:00
|
|
|
$stradded = get_string("added", "moodle", get_string("modulename", $info[0]));
|
2002-08-10 14:27:14 +00:00
|
|
|
$changelist["$log->info"] = array ("operation" => "add", "text" => "$stradded:<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>");
|
2002-05-31 09:34:50 +00:00
|
|
|
break;
|
|
|
|
case "update mod":
|
2002-08-11 05:24:25 +00:00
|
|
|
$strupdated = get_string("updated", "moodle", get_string("modulename", $info[0]));
|
2002-12-30 05:13:43 +00:00
|
|
|
if (empty($changelist["$log->info"])) {
|
2002-08-10 14:27:14 +00:00
|
|
|
$changelist["$log->info"] = array ("operation" => "update", "text" => "$strupdated:<BR><A HREF=\"$CFG->wwwroot/course/$log->url\">$modname</A>");
|
2002-06-01 09:23:37 +00:00
|
|
|
}
|
2002-05-31 09:34:50 +00:00
|
|
|
break;
|
|
|
|
case "delete mod":
|
2002-06-01 09:23:37 +00:00
|
|
|
if ($changelist["$log->info"]["operation"] == "add") {
|
|
|
|
$changelist["$log->info"] = NULL;
|
|
|
|
} else {
|
2002-08-11 05:24:25 +00:00
|
|
|
$strdeleted = get_string("deletedactivity", "moodle", get_string("modulename", $info[0]));
|
2002-08-10 14:27:14 +00:00
|
|
|
$changelist["$log->info"] = array ("operation" => "delete", "text" => $strdeleted);
|
2002-06-01 09:23:37 +00:00
|
|
|
}
|
2002-05-31 09:34:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-06-01 09:23:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-29 17:32:32 +00:00
|
|
|
if (!empty($changelist)) {
|
2002-06-01 09:23:37 +00:00
|
|
|
foreach ($changelist as $changeinfo => $change) {
|
|
|
|
if ($change) {
|
|
|
|
$changes[$changeinfo] = $change;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (count($changes) > 0) {
|
2002-08-10 14:27:14 +00:00
|
|
|
print_headline(get_string("courseupdates").":");
|
2002-06-01 09:23:37 +00:00
|
|
|
$content = true;
|
|
|
|
foreach ($changes as $changeinfo => $change) {
|
|
|
|
echo "<P><FONT SIZE=1>".$change["text"]."</FONT></P>";
|
2002-05-31 09:34:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-21 17:11:08 +00:00
|
|
|
// Now display new things from each module
|
2002-05-31 09:34:50 +00:00
|
|
|
|
2002-09-21 17:11:08 +00:00
|
|
|
$mods = get_list_of_plugins("mod");
|
2002-05-31 09:34:50 +00:00
|
|
|
|
2002-09-21 17:11:08 +00:00
|
|
|
foreach ($mods as $mod) {
|
|
|
|
include_once("$CFG->dirroot/mod/$mod/lib.php");
|
|
|
|
$print_recent_activity = $mod."_print_recent_activity";
|
|
|
|
if (function_exists($print_recent_activity)) {
|
|
|
|
$modcontent = $print_recent_activity($logs, isteacher($course->id));
|
|
|
|
if ($modcontent) {
|
|
|
|
$content = true;
|
2002-05-31 09:34:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-21 17:11:08 +00:00
|
|
|
|
2002-05-31 09:34:50 +00:00
|
|
|
if (! $content) {
|
2002-08-11 15:41:54 +00:00
|
|
|
echo "<FONT SIZE=2>".get_string("nothingnew")."</FONT>";
|
2002-05-31 09:34:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-04 06:30:51 +00:00
|
|
|
|
2002-11-10 07:37:15 +00:00
|
|
|
function get_array_of_activities($courseid) {
|
|
|
|
// For a given course, returns an array of course activity objects
|
|
|
|
// Each item in the array contains he following properties:
|
|
|
|
// cm - course module id
|
|
|
|
// mod - name of the module (eg forum)
|
|
|
|
// section - the number of the section (eg week or topic)
|
|
|
|
// name - the name of the instance
|
|
|
|
|
|
|
|
$mod = array();
|
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
if (!$rawmods = get_course_mods($courseid)) {
|
2002-11-10 07:37:15 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($sections = get_records("course_sections", "course", $courseid, "section ASC")) {
|
|
|
|
foreach ($sections as $section) {
|
|
|
|
if ($section->sequence) {
|
|
|
|
$sequence = explode(",", $section->sequence);
|
|
|
|
foreach ($sequence as $seq) {
|
|
|
|
$mod[$seq]->cm = $rawmods[$seq]->id;
|
|
|
|
$mod[$seq]->mod = $rawmods[$seq]->modname;
|
|
|
|
$mod[$seq]->section = $section->section;
|
|
|
|
$mod[$seq]->name = urlencode(get_field($rawmods[$seq]->modname, "name", "id", $rawmods[$seq]->instance));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $mod;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-06-04 06:30:51 +00:00
|
|
|
|
2002-08-02 17:38:18 +00:00
|
|
|
function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modnamesused) {
|
|
|
|
// Returns a number of useful structures for course displays
|
2002-07-23 16:24:12 +00:00
|
|
|
|
2002-08-02 17:38:18 +00:00
|
|
|
$mods = NULL; // course modules indexed by id
|
|
|
|
$modnames = NULL; // all course module names
|
2002-08-03 08:16:31 +00:00
|
|
|
$modnamesplural= NULL; // all course module names (plural form)
|
2002-08-02 17:38:18 +00:00
|
|
|
$modnamesused = NULL; // course module names used
|
2002-07-23 16:24:12 +00:00
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($allmods = get_records("modules")) {
|
2002-08-02 17:38:18 +00:00
|
|
|
foreach ($allmods as $mod) {
|
|
|
|
$modnames[$mod->name] = get_string("modulename", "$mod->name");
|
|
|
|
$modnamesplural[$mod->name] = get_string("modulenameplural", "$mod->name");
|
|
|
|
}
|
|
|
|
asort($modnames);
|
|
|
|
} else {
|
|
|
|
error("No modules are installed!");
|
|
|
|
}
|
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($rawmods = get_course_mods($courseid)) {
|
2002-07-23 16:24:12 +00:00
|
|
|
foreach($rawmods as $mod) { // Index the mods
|
|
|
|
$mods[$mod->id] = $mod;
|
2002-08-02 17:38:18 +00:00
|
|
|
$mods[$mod->id]->modfullname = $modnames[$mod->modname];
|
|
|
|
$modnamesused[$mod->modname] = $modnames[$mod->modname];
|
2002-07-23 16:24:12 +00:00
|
|
|
}
|
2002-08-02 17:38:18 +00:00
|
|
|
asort($modnamesused);
|
2002-07-23 16:24:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
|
2002-07-23 16:24:12 +00:00
|
|
|
function get_all_sections($courseid) {
|
|
|
|
|
2002-12-22 06:15:44 +00:00
|
|
|
return get_records("course_sections", "course", "$courseid", "section",
|
2002-12-20 14:44:14 +00:00
|
|
|
"section, id, course, summary, sequence");
|
2002-07-23 16:24:12 +00:00
|
|
|
}
|
|
|
|
|
2002-09-09 11:48:11 +00:00
|
|
|
|
2002-12-09 07:35:40 +00:00
|
|
|
function print_section_block($heading, $course, $section, $mods, $modnames, $modnamesused,
|
|
|
|
$absolute=true, $width="100%", $isediting=false) {
|
|
|
|
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
$modinfo = unserialize($course->modinfo);
|
|
|
|
$moddata = array();
|
|
|
|
$modicon = array();
|
|
|
|
$editbuttons = "";
|
|
|
|
|
|
|
|
if ($section->sequence) {
|
|
|
|
|
|
|
|
$sectionmods = explode(",", $section->sequence);
|
|
|
|
|
|
|
|
foreach ($sectionmods as $modnumber) {
|
|
|
|
$mod = $mods[$modnumber];
|
|
|
|
if ($isediting) {
|
|
|
|
$editbuttons = make_editing_buttons($mod->id, $absolute);
|
|
|
|
}
|
|
|
|
$instancename = urldecode($modinfo[$modnumber]->name);
|
|
|
|
$modicon[] = "<img src=\"$CFG->wwwroot/mod/$mod->modname/icon.gif\" height=\"16\" width=\"16\" alt=\"$mod->modfullname\">";
|
|
|
|
$moddata[] = "<a title=\"$mod->modfullname\" href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename</a><BR>$editbuttons";
|
|
|
|
}
|
|
|
|
}
|
2002-12-29 17:32:32 +00:00
|
|
|
if (isediting($course->id)) {
|
2002-12-09 07:35:40 +00:00
|
|
|
$editmenu = popup_form("$CFG->wwwroot/course/mod.php?id=$course->id§ion=0&add=",
|
|
|
|
$modnames, "section0", "", get_string("add")."...", "mods", get_string("activities"), true);
|
|
|
|
$editmenu = "<DIV ALIGN=right>$editmenu</DIV>";
|
2002-12-30 05:13:43 +00:00
|
|
|
} else {
|
|
|
|
$editmenu = "";
|
2002-12-09 07:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print_side_block($heading, "", $moddata, $modicon, $editmenu, $width);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-10 07:37:15 +00:00
|
|
|
function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%") {
|
2002-08-03 08:16:31 +00:00
|
|
|
global $CFG;
|
|
|
|
|
2002-11-10 08:55:11 +00:00
|
|
|
$modinfo = unserialize($course->modinfo);
|
2002-08-03 08:16:31 +00:00
|
|
|
|
2002-08-23 03:55:49 +00:00
|
|
|
echo "<TABLE WIDTH=\"$width\"><TR><TD>\n";
|
2002-08-03 08:16:31 +00:00
|
|
|
if ($section->sequence) {
|
|
|
|
|
|
|
|
$sectionmods = explode(",", $section->sequence);
|
|
|
|
|
|
|
|
foreach ($sectionmods as $modnumber) {
|
|
|
|
$mod = $mods[$modnumber];
|
2002-11-10 08:55:11 +00:00
|
|
|
$instancename = urldecode($modinfo[$modnumber]->name);
|
2002-08-03 08:16:31 +00:00
|
|
|
echo "<IMG SRC=\"$CFG->wwwroot/mod/$mod->modname/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"$mod->modfullname\">";
|
2002-08-04 13:25:53 +00:00
|
|
|
echo " <FONT SIZE=2><A TITLE=\"$mod->modfullname\"";
|
|
|
|
echo " HREF=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">$instancename</A></FONT>";
|
2002-11-10 07:37:15 +00:00
|
|
|
if (isediting($course->id)) {
|
2002-12-09 07:35:40 +00:00
|
|
|
echo " ";
|
2002-08-03 08:16:31 +00:00
|
|
|
echo make_editing_buttons($mod->id, $absolute);
|
|
|
|
}
|
|
|
|
echo "<BR>\n";
|
|
|
|
}
|
|
|
|
}
|
2002-08-04 13:27:20 +00:00
|
|
|
echo "</TD></TR></TABLE><BR>\n\n";
|
2002-08-04 13:25:53 +00:00
|
|
|
}
|
|
|
|
|
2002-12-09 13:36:55 +00:00
|
|
|
function print_heading_block($heading, $width="100%", $class="headingblock") {
|
2002-12-09 07:35:40 +00:00
|
|
|
global $THEME;
|
|
|
|
|
2002-12-09 13:36:55 +00:00
|
|
|
echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">";
|
|
|
|
echo "<tr><td bgcolor=\"$THEME->cellheading\" class=\"$class\">";
|
2002-12-09 07:35:40 +00:00
|
|
|
echo stripslashes($heading);
|
|
|
|
echo "</td></tr></table>";
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_side_block($heading="", $content="", $list=NULL, $icons=NULL, $footer="", $width=180) {
|
|
|
|
// Prints a nice side block with an optional header. The content can either
|
|
|
|
// be a block of HTML or a list of text with optional icons.
|
2002-08-04 13:25:53 +00:00
|
|
|
|
2002-12-09 07:35:40 +00:00
|
|
|
global $THEME;
|
|
|
|
|
2002-12-09 13:36:55 +00:00
|
|
|
print_side_block_start($heading, $width);
|
|
|
|
|
2002-12-09 07:35:40 +00:00
|
|
|
if ($content) {
|
2002-12-09 13:36:55 +00:00
|
|
|
echo "$content";
|
2002-12-09 07:35:40 +00:00
|
|
|
} else {
|
|
|
|
echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">";
|
|
|
|
foreach ($list as $key => $string) {
|
2002-12-09 13:36:55 +00:00
|
|
|
echo "<tr bgcolor=\"$THEME->cellcontent2\">";
|
2002-12-09 07:35:40 +00:00
|
|
|
if ($icons) {
|
2002-12-09 13:36:55 +00:00
|
|
|
echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"16\">".$icons[$key]."</td>";
|
2002-08-04 13:25:53 +00:00
|
|
|
}
|
2002-12-09 13:36:55 +00:00
|
|
|
echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"*\"><font size=\"-1\">$string</font></td>";
|
2002-12-09 07:35:40 +00:00
|
|
|
echo "</tr>";
|
2002-08-04 13:25:53 +00:00
|
|
|
}
|
2002-12-09 07:35:40 +00:00
|
|
|
if ($footer) {
|
2002-12-09 13:36:55 +00:00
|
|
|
echo "<tr bgcolor=\"$THEME->cellcontent2\">";
|
2002-12-09 07:35:40 +00:00
|
|
|
if ($icons) {
|
2002-12-09 13:36:55 +00:00
|
|
|
echo "<td class=\"sideblocklinks\" valign=\"top\" width=\"16\"> </td>";
|
2002-12-09 07:35:40 +00:00
|
|
|
}
|
2002-12-09 13:36:55 +00:00
|
|
|
echo "<td class=\"sideblocklinks\"><font size=\"-1\">$footer</td>";
|
2002-12-09 07:35:40 +00:00
|
|
|
echo "</tr>";
|
|
|
|
}
|
|
|
|
echo "</table>";
|
2002-08-04 13:25:53 +00:00
|
|
|
}
|
2002-12-09 07:35:40 +00:00
|
|
|
|
2002-12-09 13:36:55 +00:00
|
|
|
print_side_block_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_side_block_start($heading="", $width=180, $class="sideblockmain") {
|
|
|
|
// Starts a nice side block with an optional header.
|
|
|
|
|
|
|
|
global $THEME;
|
|
|
|
|
|
|
|
echo "<table class=\"sideblock\" width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">";
|
|
|
|
if ($heading) {
|
|
|
|
echo "<tr>";
|
|
|
|
echo "<td class=\"sideblockheading\" bgcolor=\"$THEME->cellheading\">$heading</td>";
|
|
|
|
echo "</tr>";
|
|
|
|
}
|
|
|
|
echo "<tr>";
|
|
|
|
echo "<td class=\"$class\" bgcolor=\"$THEME->cellcontent2\">";
|
|
|
|
}
|
|
|
|
|
|
|
|
function print_side_block_end() {
|
|
|
|
echo "</td></tr>";
|
2002-12-09 07:35:40 +00:00
|
|
|
echo "</table><br \>";
|
2002-08-03 08:16:31 +00:00
|
|
|
}
|
|
|
|
|
2002-12-09 07:35:40 +00:00
|
|
|
|
2002-08-26 20:38:56 +00:00
|
|
|
function print_admin_links ($siteid, $width=180) {
|
2002-08-08 15:51:23 +00:00
|
|
|
global $THEME, $CFG;
|
|
|
|
|
|
|
|
$icon = "<IMG SRC=\"$CFG->wwwroot/pix/i/settings.gif\" HEIGHT=16 WIDTH=16 ALT=\"\">";
|
2002-09-19 12:01:55 +00:00
|
|
|
$moddata[]="<A HREF=\"$CFG->wwwroot/admin/config.php\">".get_string("configvariables")."</A>";
|
2002-08-08 15:51:23 +00:00
|
|
|
$modicon[]=$icon;
|
|
|
|
$moddata[]="<A HREF=\"$CFG->wwwroot/admin/site.php\">".get_string("sitesettings")."</A>";
|
|
|
|
$modicon[]=$icon;
|
2002-09-19 12:01:55 +00:00
|
|
|
$moddata[]="<A HREF=\"$CFG->wwwroot/course/log.php?id=$siteid\">".get_string("sitelogs")."</A>";
|
|
|
|
$modicon[]=$icon;
|
2002-08-17 13:01:06 +00:00
|
|
|
$moddata[]="<A HREF=\"$CFG->wwwroot/theme/index.php\">".get_string("choosetheme")."</A>";
|
|
|
|
$modicon[]=$icon;
|
2002-09-03 14:29:39 +00:00
|
|
|
$moddata[]="<A HREF=\"$CFG->wwwroot/admin/lang.php\">".get_string("checklanguage")."</A>";
|
|
|
|
$modicon[]=$icon;
|
2002-09-27 06:19:49 +00:00
|
|
|
if (file_exists("$CFG->dirroot/admin/$CFG->dbtype")) {
|
|
|
|
$moddata[]="<A HREF=\"$CFG->wwwroot/admin/$CFG->dbtype/\">".get_string("managedatabase")."</A>";
|
|
|
|
$modicon[]=$icon;
|
|
|
|
}
|
2002-09-19 12:01:55 +00:00
|
|
|
$moddata[]="<HR>";
|
|
|
|
$modicon[]="";
|
2002-08-08 15:51:23 +00:00
|
|
|
$moddata[]="<A HREF=\"$CFG->wwwroot/course/edit.php\">".get_string("addnewcourse")."</A>";
|
|
|
|
$modicon[]=$icon;
|
2002-09-09 11:48:11 +00:00
|
|
|
$moddata[]="<A HREF=\"$CFG->wwwroot/course/categories.php\">".get_string("categories")."</A>";
|
|
|
|
$modicon[]=$icon;
|
2002-08-08 15:51:23 +00:00
|
|
|
$moddata[]="<A HREF=\"$CFG->wwwroot/course/teacher.php\">".get_string("assignteachers")."</A>";
|
|
|
|
$modicon[]=$icon;
|
|
|
|
$moddata[]="<A HREF=\"$CFG->wwwroot/course/delete.php\">".get_string("deletecourse")."</A>";
|
|
|
|
$modicon[]=$icon;
|
2002-09-19 12:01:55 +00:00
|
|
|
$moddata[]="<HR>";
|
|
|
|
$modicon[]="";
|
2002-08-08 15:51:23 +00:00
|
|
|
$moddata[]="<A HREF=\"$CFG->wwwroot/admin/user.php?newuser=true\">".get_string("addnewuser")."</A>";
|
|
|
|
$modicon[]=$icon;
|
|
|
|
$moddata[]="<A HREF=\"$CFG->wwwroot/admin/user.php\">".get_string("edituser")."</A>";
|
|
|
|
$modicon[]=$icon;
|
2002-12-11 14:59:37 +00:00
|
|
|
$moddata[]="<A HREF=\"$CFG->wwwroot/admin/admin.php\">".get_string("assignadmins")."</A>";
|
|
|
|
$modicon[]=$icon;
|
2002-11-19 09:55:54 +00:00
|
|
|
$moddata[]="<A HREF=\"$CFG->wwwroot/admin/auth.php\">".get_string("authentication")."</A>";
|
|
|
|
$modicon[]=$icon;
|
2002-08-08 15:51:23 +00:00
|
|
|
$fulladmin = "<P><A HREF=\"$CFG->wwwroot/admin/\">".get_string("admin")."</A>...";
|
2002-12-09 07:35:40 +00:00
|
|
|
|
|
|
|
print_side_block(get_string("administration"), "", $moddata, $modicon, $fulladmin, $width);
|
|
|
|
|
2002-08-23 03:55:49 +00:00
|
|
|
echo "<IMG SRC=\"$CFG->wwwroot/pix/spacer.gif\" WIDTH=\"$width\" HEIGHT=1><BR>";
|
2002-08-08 15:51:23 +00:00
|
|
|
}
|
|
|
|
|
2002-09-08 03:24:38 +00:00
|
|
|
function print_course_admin_links($course, $width=180) {
|
2002-08-18 16:16:24 +00:00
|
|
|
global $THEME, $CFG;
|
|
|
|
|
|
|
|
$adminicon[]="<IMG SRC=\"$CFG->wwwroot/pix/i/edit.gif\" HEIGHT=16 WIDTH=16 ALT=\"\">";
|
2002-09-08 03:24:38 +00:00
|
|
|
if (isediting($course->id)) {
|
|
|
|
$admindata[]="<A HREF=\"view.php?id=$course->id&edit=off\">".get_string("turneditingoff")."</A>";
|
2002-08-18 16:16:24 +00:00
|
|
|
} else {
|
2002-09-08 03:24:38 +00:00
|
|
|
$admindata[]="<A HREF=\"view.php?id=$course->id&edit=on\">".get_string("turneditingon")."</A>";
|
|
|
|
}
|
|
|
|
$admindata[]="<A HREF=\"edit.php?id=$course->id\">".get_string("settings")."...</A>";
|
|
|
|
$adminicon[]="<IMG SRC=\"$CFG->wwwroot/pix/i/settings.gif\" HEIGHT=16 WIDTH=16 ALT=\"\">";
|
|
|
|
if (!$course->teachers) {
|
|
|
|
$course->teachers = get_string("defaultcourseteachers");
|
2002-08-18 16:16:24 +00:00
|
|
|
}
|
2002-09-08 03:24:38 +00:00
|
|
|
$admindata[]="<A HREF=\"teachers.php?id=$course->id\">$course->teachers...</A>";
|
2002-08-18 16:16:24 +00:00
|
|
|
$adminicon[]="<IMG SRC=\"$CFG->wwwroot/pix/i/settings.gif\" HEIGHT=16 WIDTH=16 ALT=\"\">";
|
2002-09-08 03:24:38 +00:00
|
|
|
|
2002-10-17 07:23:12 +00:00
|
|
|
$admindata[]="<A HREF=\"grades.php?id=$course->id\">".get_string("grades")."...</A>";
|
|
|
|
$adminicon[]="<IMG SRC=\"$CFG->wwwroot/pix/i/grades.gif\" HEIGHT=16 WIDTH=16 ALT=\"\">";
|
|
|
|
|
2002-09-08 03:24:38 +00:00
|
|
|
$admindata[]="<A HREF=\"log.php?id=$course->id\">".get_string("logs")."...</A>";
|
2002-08-18 16:16:24 +00:00
|
|
|
$adminicon[]="<IMG SRC=\"$CFG->wwwroot/pix/i/log.gif\" HEIGHT=16 WIDTH=16 ALT=\"\">";
|
2002-09-08 03:24:38 +00:00
|
|
|
$admindata[]="<A HREF=\"$CFG->wwwroot/files/index.php?id=$course->id\">".get_string("files")."...</A>";
|
2002-08-18 16:16:24 +00:00
|
|
|
$adminicon[]="<IMG SRC=\"$CFG->wwwroot/files/pix/files.gif\" HEIGHT=16 WIDTH=16 ALT=\"\">";
|
|
|
|
|
2002-09-08 03:24:38 +00:00
|
|
|
$admindata[]="<A HREF=\"$CFG->wwwroot/doc/view.php?id=$course->id&file=teacher.html\">".get_string("help")."...</A>";
|
2002-10-17 14:03:59 +00:00
|
|
|
$adminicon[]="<IMG SRC=\"$CFG->wwwroot/mod/resource/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"\">";
|
2002-08-18 16:16:24 +00:00
|
|
|
|
2002-09-08 03:24:38 +00:00
|
|
|
|
|
|
|
if ($teacherforum = forum_get_course_forum($course->id, "teacher")) {
|
|
|
|
$admindata[]="<A HREF=\"$CFG->wwwroot/mod/forum/view.php?f=$teacherforum->id\">".get_string("nameteacher", "forum")."</A>";
|
2002-08-18 16:16:24 +00:00
|
|
|
$adminicon[]="<IMG SRC=\"$CFG->wwwroot/mod/forum/icon.gif\" HEIGHT=16 WIDTH=16 ALT=\"\">";
|
|
|
|
}
|
|
|
|
|
2002-12-09 07:35:40 +00:00
|
|
|
print_side_block(get_string("administration"), "", $admindata, $adminicon, "", $width);
|
2002-08-18 16:16:24 +00:00
|
|
|
}
|
2002-08-08 15:51:23 +00:00
|
|
|
|
2002-09-09 11:48:11 +00:00
|
|
|
function print_course_categories($categories, $selected="none", $width=180) {
|
2002-09-09 12:37:34 +00:00
|
|
|
global $CFG, $THEME, $USER;
|
2002-11-29 14:17:36 +00:00
|
|
|
|
|
|
|
$strallowguests = get_string("allowguests");
|
|
|
|
$strrequireskey = get_string("requireskey");
|
2002-09-09 11:48:11 +00:00
|
|
|
|
2002-09-10 13:47:56 +00:00
|
|
|
if ($selected == "index") { // Print comprehensive index of categories with courses
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($courses = get_courses()) {
|
2002-09-10 13:47:56 +00:00
|
|
|
if (isset($USER->id) and !isadmin()) {
|
2002-11-29 14:22:34 +00:00
|
|
|
print_simple_box_start("CENTER", "100%", $THEME->cellheading);
|
2002-09-10 13:47:56 +00:00
|
|
|
print_heading("<A HREF=\"course/index.php?category=my\">".get_string("mycourses")."</A>", "LEFT");
|
|
|
|
$some = false;
|
|
|
|
echo "<UL>";
|
|
|
|
foreach ($courses as $key => $course) {
|
|
|
|
if (isteacher($course->id) or isstudent($course->id)) {
|
2002-11-29 14:17:36 +00:00
|
|
|
echo "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</A>";
|
|
|
|
echo "<BR>";
|
2002-09-10 13:47:56 +00:00
|
|
|
$some = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$some) {
|
|
|
|
print_string("nocoursesyet");
|
|
|
|
}
|
|
|
|
echo "</UL>";
|
|
|
|
print_simple_box_end();
|
|
|
|
print_spacer(8,1);
|
|
|
|
}
|
|
|
|
foreach ($categories as $category) {
|
2002-11-20 09:41:02 +00:00
|
|
|
print_simple_box_start("CENTER", "100%");
|
2002-09-12 02:42:22 +00:00
|
|
|
print_heading("<A HREF=\"course/index.php?category=$category->id\">$category->name</A>", "LEFT");
|
2002-09-10 13:47:56 +00:00
|
|
|
$some = false;
|
|
|
|
echo "<UL>";
|
|
|
|
foreach ($courses as $key => $course) {
|
|
|
|
if ($course->category == $category->id) {
|
2002-11-29 14:17:36 +00:00
|
|
|
echo "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->fullname</A>";
|
|
|
|
echo " ";
|
2002-09-10 13:47:56 +00:00
|
|
|
unset($courses[$key]);
|
2002-11-29 14:17:36 +00:00
|
|
|
if ($course->guest ) {
|
|
|
|
echo "<A TITLE=\"$strallowguests\" HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
|
|
|
|
echo "<IMG ALT=\"\" HEIGHT=16 WIDTH=16 BORDER=0 SRC=\"$CFG->wwwroot/user/user.gif\"></A>";
|
|
|
|
}
|
|
|
|
if ($course->password) {
|
|
|
|
echo "<A TITLE=\"$strrequireskey\" HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
|
|
|
|
echo "<IMG ALT=\"\" HEIGHT=16 WIDTH=16 BORDER=0 SRC=\"$CFG->wwwroot/pix/i/key.gif\"></A>";
|
|
|
|
}
|
|
|
|
echo "<BR>";
|
2002-09-10 13:47:56 +00:00
|
|
|
$some = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$some) {
|
|
|
|
print_string("nocoursesyet");
|
|
|
|
}
|
|
|
|
echo "</UL>";
|
|
|
|
print_simple_box_end();
|
|
|
|
print_spacer(8,1);
|
|
|
|
}
|
2002-09-09 11:48:11 +00:00
|
|
|
}
|
2002-09-10 13:47:56 +00:00
|
|
|
|
|
|
|
} else { // Print short list of categories only
|
|
|
|
foreach ($categories as $cat) {
|
|
|
|
$caticon[]="<IMG SRC=\"$CFG->wwwroot/pix/i/course.gif\" HEIGHT=16 WIDTH=16>";
|
|
|
|
if ($cat->id == $selected) {
|
|
|
|
$catdata[]="$cat->name";
|
|
|
|
} else {
|
|
|
|
$catdata[]="<A HREF=\"$CFG->wwwroot/course/index.php?category=$cat->id\">$cat->name</A>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$catdata[] = "<A HREF=\"$CFG->wwwroot/course/index.php?category=all\">".get_string("fulllistofcourses")."</A>";
|
|
|
|
if (isset($USER->id)) {
|
|
|
|
$catdata[] = "<A HREF=\"$CFG->wwwroot/course/index.php?category=my\">".get_string("mycourses")."</A>";
|
|
|
|
}
|
2002-12-09 07:35:40 +00:00
|
|
|
print_side_block(get_string("categories"), "", $catdata, $caticon, $showall.$mine, $width);
|
2002-09-09 11:48:11 +00:00
|
|
|
}
|
|
|
|
}
|
2002-08-03 08:16:31 +00:00
|
|
|
|
2002-07-27 09:44:01 +00:00
|
|
|
function print_log_graph($course, $userid=0, $type="course.png", $date=0) {
|
|
|
|
global $CFG;
|
|
|
|
echo "<IMG BORDER=0 SRC=\"$CFG->wwwroot/course/loggraph.php?id=$course->id&user=$userid&type=$type&date=$date\">";
|
|
|
|
}
|
|
|
|
|
2002-08-01 03:50:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// MODULE FUNCTIONS /////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
function add_course_module($mod) {
|
|
|
|
GLOBAL $db;
|
|
|
|
|
2002-10-21 03:00:40 +00:00
|
|
|
$mod->added = time();
|
2002-08-01 03:50:27 +00:00
|
|
|
|
2002-10-21 03:00:40 +00:00
|
|
|
return insert_record("course_modules", $mod);
|
2002-08-01 03:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function add_mod_to_section($mod) {
|
|
|
|
// Returns the course_sections ID where the mod is inserted
|
|
|
|
GLOBAL $db;
|
|
|
|
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($section = get_record("course_sections", "course", "$mod->course", "section", "$mod->section")) {
|
2002-10-21 03:00:40 +00:00
|
|
|
if ($section->sequence) {
|
|
|
|
$newsequence = "$section->sequence,$mod->coursemodule";
|
2002-08-01 03:50:27 +00:00
|
|
|
} else {
|
|
|
|
$newsequence = "$mod->coursemodule";
|
|
|
|
}
|
2002-10-21 03:00:40 +00:00
|
|
|
if (set_field("course_sections", "sequence", $newsequence, "id", $section->id)) {
|
|
|
|
return $section->id; // Return course_sections ID that was used.
|
2002-08-01 03:50:27 +00:00
|
|
|
} else {
|
2002-10-21 03:00:40 +00:00
|
|
|
return 0;
|
2002-08-01 03:50:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else { // Insert a new record
|
2002-10-21 03:00:40 +00:00
|
|
|
$section->course = $mod->course;
|
|
|
|
$section->section = $mod->section;
|
|
|
|
$section->summary = "";
|
|
|
|
$section->sequence = $mod->coursemodule;
|
|
|
|
return insert_record("course_sections", $section);
|
2002-08-01 03:50:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function delete_course_module($mod) {
|
|
|
|
return set_field("course_modules", "deleted", 1, "id", $mod);
|
|
|
|
}
|
|
|
|
|
|
|
|
function delete_mod_from_section($mod, $section) {
|
|
|
|
GLOBAL $db;
|
|
|
|
|
2002-10-21 03:00:40 +00:00
|
|
|
if ($section = get_record("course_sections", "id", "$section") ) {
|
2002-08-01 03:50:27 +00:00
|
|
|
|
2002-10-21 03:00:40 +00:00
|
|
|
$modarray = explode(",", $section->sequence);
|
2002-08-01 03:50:27 +00:00
|
|
|
|
|
|
|
if ($key = array_keys ($modarray, $mod)) {
|
|
|
|
array_splice($modarray, $key[0], 1);
|
|
|
|
$newsequence = implode(",", $modarray);
|
2002-10-21 03:00:40 +00:00
|
|
|
return set_field("course_sections", "sequence", $newsequence, "id", $section->id);
|
2002-08-01 03:50:27 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-10 14:45:11 +00:00
|
|
|
function move_module($cm, $move) {
|
2002-08-01 03:50:27 +00:00
|
|
|
GLOBAL $db;
|
|
|
|
|
|
|
|
if (!$move) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $thissection = get_record("course_sections", "id", $cm->section)) {
|
|
|
|
error("This course section doesn't exist");
|
|
|
|
}
|
|
|
|
|
|
|
|
$mods = explode(",", $thissection->sequence);
|
|
|
|
|
|
|
|
$len = count($mods);
|
|
|
|
$pos = array_keys($mods, $cm->id);
|
|
|
|
$thepos = $pos[0];
|
|
|
|
|
|
|
|
if ($len == 0 || count($pos) == 0 ) {
|
|
|
|
error("Very strange. Could not find the required module in this section.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($len == 1) {
|
|
|
|
$first = true;
|
|
|
|
$last = true;
|
|
|
|
} else {
|
|
|
|
$first = ($thepos == 0);
|
|
|
|
$last = ($thepos == $len - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($move < 0) { // Moving the module up
|
|
|
|
|
|
|
|
if ($first) {
|
|
|
|
if ($thissection->section == 1) { // First section, do nothing
|
|
|
|
return true;
|
|
|
|
} else { // Push onto end of previous section
|
|
|
|
$prevsectionnumber = $thissection->section - 1;
|
2002-12-20 14:44:14 +00:00
|
|
|
if (! $prevsection = get_record("course_sections", "course", "$thissection->course",
|
|
|
|
"section", "$prevsectionnumber")) {
|
2002-08-01 03:50:27 +00:00
|
|
|
error("Previous section ($prevsection->id) doesn't exist");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($prevsection->sequence) {
|
|
|
|
$newsequence = "$prevsection->sequence,$cm->id";
|
|
|
|
} else {
|
|
|
|
$newsequence = "$cm->id";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! set_field("course_sections", "sequence", $newsequence, "id", $prevsection->id)) {
|
|
|
|
error("Previous section could not be updated");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! set_field("course_modules", "section", $prevsection->id, "id", $cm->id)) {
|
|
|
|
error("Module could not be updated");
|
|
|
|
}
|
|
|
|
|
|
|
|
array_splice($mods, 0, 1);
|
|
|
|
$newsequence = implode(",", $mods);
|
|
|
|
if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
|
|
|
|
error("Module could not be updated");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
} else { // move up within this section
|
|
|
|
$swap = $mods[$thepos-1];
|
|
|
|
$mods[$thepos-1] = $mods[$thepos];
|
|
|
|
$mods[$thepos] = $swap;
|
|
|
|
|
|
|
|
$newsequence = implode(",", $mods);
|
|
|
|
if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
|
|
|
|
error("This section could not be updated");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else { // Moving the module down
|
|
|
|
|
|
|
|
if ($last) {
|
|
|
|
$nextsectionnumber = $thissection->section + 1;
|
2002-12-20 14:44:14 +00:00
|
|
|
if ($nextsection = get_record("course_sections", "course", "$thissection->course",
|
|
|
|
"section", "$nextsectionnumber")) {
|
2002-08-01 03:50:27 +00:00
|
|
|
|
|
|
|
if ($nextsection->sequence) {
|
|
|
|
$newsequence = "$cm->id,$nextsection->sequence";
|
|
|
|
} else {
|
|
|
|
$newsequence = "$cm->id";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! set_field("course_sections", "sequence", $newsequence, "id", $nextsection->id)) {
|
|
|
|
error("Next section could not be updated");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! set_field("course_modules", "section", $nextsection->id, "id", $cm->id)) {
|
|
|
|
error("Module could not be updated");
|
|
|
|
}
|
|
|
|
|
|
|
|
array_splice($mods, $thepos, 1);
|
|
|
|
$newsequence = implode(",", $mods);
|
|
|
|
if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
|
|
|
|
error("This section could not be updated");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} else { // There is no next section, so just return
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
} else { // move down within this section
|
|
|
|
$swap = $mods[$thepos+1];
|
|
|
|
$mods[$thepos+1] = $mods[$thepos];
|
|
|
|
$mods[$thepos] = $swap;
|
|
|
|
|
|
|
|
$newsequence = implode(",", $mods);
|
|
|
|
if (! set_field("course_sections", "sequence", $newsequence, "id", $thissection->id)) {
|
|
|
|
error("This section could not be updated");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-03 08:16:31 +00:00
|
|
|
function make_editing_buttons($moduleid, $absolute=false) {
|
|
|
|
global $CFG;
|
|
|
|
|
2002-08-02 17:38:18 +00:00
|
|
|
$delete = get_string("delete");
|
|
|
|
$moveup = get_string("moveup");
|
|
|
|
$movedown = get_string("movedown");
|
|
|
|
$update = get_string("update");
|
2002-08-03 08:16:31 +00:00
|
|
|
|
|
|
|
if ($absolute) {
|
|
|
|
$path = "$CFG->wwwroot/course/";
|
|
|
|
} else {
|
|
|
|
$path = "";
|
|
|
|
}
|
2002-12-09 07:35:40 +00:00
|
|
|
return "<A TITLE=\"$delete\" HREF=\"".$path."mod.php?delete=$moduleid\"><IMG
|
2002-08-11 15:41:54 +00:00
|
|
|
SRC=".$path."../pix/t/delete.gif BORDER=0></A>
|
|
|
|
<A TITLE=\"$moveup\" HREF=\"".$path."mod.php?id=$moduleid&move=-1\"><IMG
|
|
|
|
SRC=".$path."../pix/t/up.gif BORDER=0></A>
|
|
|
|
<A TITLE=\"$movedown\" HREF=\"".$path."mod.php?id=$moduleid&move=1\"><IMG
|
|
|
|
SRC=".$path."../pix/t/down.gif BORDER=0></A>
|
|
|
|
<A TITLE=\"$update\" HREF=\"".$path."mod.php?update=$moduleid\"><IMG
|
|
|
|
SRC=".$path."../pix/t/edit.gif BORDER=0></A>";
|
2002-08-02 17:38:18 +00:00
|
|
|
}
|
|
|
|
|
2001-11-22 06:23:56 +00:00
|
|
|
?>
|