Improvements to logs for admin user (can view any course)
[moodle.git] / course / log.php
1 <?PHP // $Id$
3 //  log.php - displays different views of the logs.
5     require("../config.php");
6     require("lib.php");
8     require_variable($id);    // Course ID
9     optional_variable($user); // User to display
10     optional_variable($date); // Date to display
12     require_login($id);
14     if (! $course = get_record("course", "id", $id) ) {
15         error("That's an invalid course id");
16     }
18     if (! isteacher($course->id)) {
19         error("Only teachers can view logs");
20     }
22     if (! $course->category) {
23         if (!isadmin()) {
24             error("Only administrators can look at the site logs");
25         }
26         $user = "";
27     }
30     if ($user || $date) {
32         $userinfo = "all users";
33         $dateinfo = "any day";
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) {
42             $dateinfo = userdate($date, "l, j F Y");
43         }
45         print_header("$course->shortname: Logs", "$course->fullname", 
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         
49         print_heading("$course->fullname: $userinfo, $dateinfo (".usertimezone().")");
51         print_log_selector_form($course, $user, $date);
53         print_log($course, $user, $date, "ORDER BY l.time DESC");
56     } else {
57         print_header("$course->shortname: Logs", "$course->fullname", 
58                  "<A HREF=\"view.php?id=$course->id\">$course->shortname</A> -> Logs", "");
60         print_heading("Choose which logs you want to look at");
62         print_log_selector_form($course);
64         print_heading("Or see what is happening right now");
66         echo "<CENTER><H3>";
67         link_to_popup_window("/course/loglive.php?id=$course->id","livelog","Live logs", 500, 800);
68         echo "</H3></CENTER>";
70     }
72     print_footer($course);
74     exit;
76 ?>