diff --git a/course/lib.php b/course/lib.php
index f6f4f9d373e..afe086d5e30 100644
--- a/course/lib.php
+++ b/course/lib.php
@@ -14,18 +14,29 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate="today"
// Get all the possible users
$users = array();
- if ($students = get_records_sql("SELECT u.* FROM user u, user_students s
- WHERE s.course = '$course->id' AND s.user = u.id
- ORDER BY u.lastaccess DESC")) {
- foreach ($students as $student) {
- $users["$student->id"] = "$student->firstname $student->lastname";
+
+ if ($course->category) {
+ if ($students = get_records_sql("SELECT u.* FROM user u, user_students s
+ WHERE s.course = '$course->id' AND s.user = u.id
+ ORDER BY u.lastaccess DESC")) {
+ foreach ($students as $student) {
+ $users["$student->id"] = "$student->firstname $student->lastname";
+ }
+ }
+ if ($teachers = get_records_sql("SELECT u.* FROM user u, user_teachers t
+ WHERE t.course = '$course->id' AND t.user = u.id
+ ORDER BY u.lastaccess DESC")) {
+ foreach ($teachers as $teacher) {
+ $users["$teacher->id"] = "$teacher->firstname $teacher->lastname";
+ }
}
}
- if ($teachers = get_records_sql("SELECT u.* FROM user u, user_teachers t
- WHERE t.course = '$course->id' AND t.user = u.id
- ORDER BY u.lastaccess DESC")) {
- foreach ($teachers as $teacher) {
- $users["$teacher->id"] = "$teacher->firstname $teacher->lastname";
+
+ if (isadmin()) {
+ if ($ccc = get_records_sql("SELECT * FROM course ORDER BY fullname")) {
+ foreach ($ccc as $cc) {
+ $courses["$cc->id"] = "$cc->fullname";
+ }
}
}
@@ -61,8 +72,14 @@ function print_log_selector_form($course, $selecteduser=0, $selecteddate="today"
echo "
";
echo "";
@@ -90,7 +107,16 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
// 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.
- $selector = "WHERE l.course='$course->id' AND l.user = u.id";
+ if ($course->category) {
+ $selector = "WHERE l.course='$course->id' AND l.user = u.id";
+ } else {
+ $selector = "WHERE l.user = u.id"; // Show all courses
+ if ($ccc = get_records_sql("SELECT * FROM course ORDER BY fullname")) {
+ foreach ($ccc as $cc) {
+ $courses[$cc->id] = "$cc->shortname";
+ }
+ }
+ }
if ($user) {
$selector .= " AND l.user = '$user'";
@@ -120,6 +146,9 @@ function print_log($course, $user=0, $date=0, $order="ORDER BY l.time ASC") {
}
echo "";
+ if (! $course->category) {
+ echo "course\">".$courses[$log->course]." | ";
+ }
echo "".userdate($log->time, "l")." | ";
echo "".userdate($log->time, "j M Y, h:i A")." | ";
echo "ip\" HREF=\"../user/view.php?id=$log->user&course=$log->course\">$log->firstname $log->lastname | ";
diff --git a/course/log.php b/course/log.php
index eba1c37820f..580d4f6f9a5 100644
--- a/course/log.php
+++ b/course/log.php
@@ -5,6 +5,10 @@
require("../config.php");
require("lib.php");
+ require_variable($id); // Course ID
+ optional_variable($user); // User to display
+ optional_variable($date); // Date to display
+
require_login($id);
if (! $course = get_record("course", "id", $id) ) {
@@ -15,8 +19,15 @@
error("Only teachers can view logs");
}
+ if (! $course->category) {
+ if (!isadmin()) {
+ error("Only administrators can look at the site logs");
+ }
+ $user = "";
+ }
- if (isset($user) || isset($date)) {
+
+ if ($user || $date) {
$userinfo = "all users";
$dateinfo = "any day";
@@ -35,7 +46,7 @@
"id\">$course->shortname ->
id\">Logs -> Logs for $userinfo, $dateinfo", "");
- print_heading("Logs for $userinfo, $dateinfo (".usertimezone().")");
+ print_heading("$course->fullname: $userinfo, $dateinfo (".usertimezone().")");
print_log_selector_form($course, $user, $date);