Improvements to logs for admin user (can view any course)
[moodle.git] / course / log.php
CommitLineData
f9903ed0 1<?PHP // $Id$
2
3// log.php - displays different views of the logs.
4
5 require("../config.php");
6 require("lib.php");
7
720a43ce 8 require_variable($id); // Course ID
9 optional_variable($user); // User to display
10 optional_variable($date); // Date to display
11
f9903ed0 12 require_login($id);
13
14 if (! $course = get_record("course", "id", $id) ) {
15 error("That's an invalid course id");
16 }
17
9481285b 18 if (! isteacher($course->id)) {
f9903ed0 19 error("Only teachers can view logs");
20 }
21
720a43ce 22 if (! $course->category) {
23 if (!isadmin()) {
24 error("Only administrators can look at the site logs");
25 }
26 $user = "";
27 }
28
f9903ed0 29
720a43ce 30 if ($user || $date) {
f9903ed0 31
32 $userinfo = "all users";
33 $dateinfo = "any day";
34
35 if ($user) {
36 if (!$u = get_record("user", "id", $user) ) {
37 error("That's an invalid user!");
38 }
39 $userinfo = "$u->firstname $u->lastname";
40 }
41 if ($date) {
873960de 42 $dateinfo = userdate($date, "l, j F Y");
f9903ed0 43 }
44
f3ecd2c8 45 print_header("$course->shortname: Logs", "$course->fullname",
f9903ed0 46 "<A HREF=\"view.php?id=$course->id\">$course->shortname</A> ->
47 <A HREF=\"log.php?id=$course->id\">Logs</A> -> Logs for $userinfo, $dateinfo", "");
48
720a43ce 49 print_heading("$course->fullname: $userinfo, $dateinfo (".usertimezone().")");
f9903ed0 50
51 print_log_selector_form($course, $user, $date);
52
53 print_log($course, $user, $date, "ORDER BY l.time DESC");
54
55
56 } else {
f3ecd2c8 57 print_header("$course->shortname: Logs", "$course->fullname",
f9903ed0 58 "<A HREF=\"view.php?id=$course->id\">$course->shortname</A> -> Logs", "");
59
60 print_heading("Choose which logs you want to look at");
61
62 print_log_selector_form($course);
63
64 print_heading("Or see what is happening right now");
65
66 echo "<CENTER><H3>";
67 link_to_popup_window("/course/loglive.php?id=$course->id","livelog","Live logs", 500, 800);
68 echo "</H3></CENTER>";
69
70 }
71
72 print_footer($course);
73
74 exit;
75
76?>