More nav cleanups
[moodle.git] / course / report / log / index.php
1 <?php
2       // Displays different views of the logs.
4     require_once('../../../config.php');
5     require_once('../../lib.php');
6     require_once('lib.php');
7     require_once($CFG->libdir.'/adminlib.php');
9     $id          = optional_param('id', 0, PARAM_INT);// Course ID
11     $host_course = optional_param('host_course', '', PARAM_PATH);// Course ID
13     if (empty($host_course)) {
14         $hostid = $CFG->mnet_localhost_id;
15         if (empty($id)) {
16             $site = get_site();
17             $id = $site->id;
18         }
19     } else {
20         list($hostid, $id) = explode('/', $host_course);
21     }
23     $group       = optional_param('group', 0, PARAM_INT); // Group to display
24     $user        = optional_param('user', 0, PARAM_INT); // User to display
25     $date        = optional_param('date', 0, PARAM_FILE); // Date to display - number or some string
26     $modname     = optional_param('modname', '', PARAM_CLEAN); // course_module->id
27     $modid       = optional_param('modid', 0, PARAM_FILE); // number or 'site_errors'
28     $modaction   = optional_param('modaction', '', PARAM_PATH); // an action as recorded in the logs
29     $page        = optional_param('page', '0', PARAM_INT);     // which page to show
30     $perpage     = optional_param('perpage', '100', PARAM_INT); // how many per page
31     $showcourses = optional_param('showcourses', 0, PARAM_INT); // whether to show courses if we're over our limit.
32     $showusers   = optional_param('showusers', 0, PARAM_INT); // whether to show users if we're over our limit.
33     $chooselog   = optional_param('chooselog', 0, PARAM_INT);
34     $logformat   = optional_param('logformat', 'showashtml', PARAM_ALPHA);
36     $params = array();
37     if ($group !== 0) $params['group'] = $group;
38     if ($user !== 0) $params['user'] = $user;
39     if ($date !== 0) $params['date'] = $date;
40     if ($modname !== 0) $params['modname'] = $modname;
41     if ($modid !== 0) $params['modid'] = $modid;
42     if ($modaction !== '') $params['modaction'] = $modaction;
43     if ($page !== '0') $params['page'] = $page;
44     if ($perpage !== '100') $params['perpage'] = $perpage;
45     if ($showcourses !== 0) $params['showcourses'] = $showcourses;
46     if ($showusers !== 0) $params['showusers'] = $showusers;
47     if ($chooselog !== 0) $params['chooselog'] = $chooselog;
48     if ($logformat !== 'showashtml') $params['logformat'] = $logformat;
49     $PAGE->set_url('/course/report/log/index.php', $params);
51     if ($hostid == $CFG->mnet_localhost_id) {
52         if (!$course = $DB->get_record('course', array('id'=>$id))) {
53             print_error('That\'s an invalid course id'.$id);
54         }
55     } else {
56         $course_stub       = $DB->get_record('mnet_log', array('hostid'=>$hostid, 'course'=>$id), '*', true);
57         $course->id        = $id;
58         $course->shortname = $course_stub->coursename;
59         $course->fullname  = $course_stub->coursename;
60     }
62     require_login($course);
64     $context = get_context_instance(CONTEXT_COURSE, $course->id);
66     require_capability('coursereport/log:view', $context);
68     add_to_log($course->id, "course", "report log", "report/log/index.php?id=$course->id", $course->id);
70     $strlogs = get_string('logs');
71     $stradministration = get_string('administration');
72     $strreports = get_string('reports');
74     session_get_instance()->write_close();
76     $navlinks = array();
78     if (!empty($chooselog)) {
79         $userinfo = get_string('allparticipants');
80         $dateinfo = get_string('alldays');
82         if ($user) {
83             if (!$u = $DB->get_record('user', array('id'=>$user))) {
84                 print_error('That\'s an invalid user!');
85             }
86             $userinfo = fullname($u, has_capability('moodle/site:viewfullnames', $context));
87         }
88         if ($date) {
89             $dateinfo = userdate($date, get_string('strftimedaydate'));
90         }
92         switch ($logformat) {
93             case 'showashtml':
94                 if ($hostid != $CFG->mnet_localhost_id || $course->id == SITEID) {
95                     admin_externalpage_setup('reportlog');
96                     echo $OUTPUT->header();
98                 } else {
99                     $PAGE->set_title($course->shortname .': '. $strlogs);
100                     $PAGE->set_heading($course->fullname);
101                     $PAGE->navbar->add($strreports, new moodle_url('/course/report.php', array('id'=>$course->id)));
102                     $PAGE->navbar->add($strlogs, new moodle_url('/course/report/log/index.php', array('id'=>$course->id)));
103                     $PAGE->navbar->add("$userinfo, $dateinfo");
104                     echo $OUTPUT->header();
105                 }
107                 echo $OUTPUT->heading(format_string($course->fullname) . ": $userinfo, $dateinfo (".usertimezone().")");
108                 print_mnet_log_selector_form($hostid, $course, $user, $date, $modname, $modid, $modaction, $group, $showcourses, $showusers, $logformat);
110                 if($hostid == $CFG->mnet_localhost_id) {
111                     print_log($course, $user, $date, 'l.time DESC', $page, $perpage,
112                             "index.php?id=$course->id&amp;chooselog=1&amp;user=$user&amp;date=$date&amp;modid=$modid&amp;modaction=$modaction&amp;group=$group",
113                             $modname, $modid, $modaction, $group);
114                 } else {
115                     print_mnet_log($hostid, $id, $user, $date, 'l.time DESC', $page, $perpage, "", $modname, $modid, $modaction, $group);
116                 }
117                 break;
118             case 'downloadascsv':
119                 if (!print_log_csv($course, $user, $date, 'l.time DESC', $modname,
120                         $modid, $modaction, $group)) {
121                     echo $OUTPUT->notification("No logs found!");
122                     echo $OUTPUT->footer();
123                 }
124                 exit;
125             case 'downloadasods':
126                 if (!print_log_ods($course, $user, $date, 'l.time DESC', $modname,
127                         $modid, $modaction, $group)) {
128                     echo $OUTPUT->notification("No logs found!");
129                     echo $OUTPUT->footer();
130                 }
131                 exit;
132             case 'downloadasexcel':
133                 if (!print_log_xls($course, $user, $date, 'l.time DESC', $modname,
134                         $modid, $modaction, $group)) {
135                     echo $OUTPUT->notification("No logs found!");
136                     echo $OUTPUT->footer();
137                 }
138                 exit;
139         }
142     } else {
143         if ($hostid != $CFG->mnet_localhost_id || $course->id == SITEID) {
144                     admin_externalpage_setup('reportlog');
145                     echo $OUTPUT->header();
146         } else {
147             $PAGE->set_title($course->shortname .': '. $strlogs);
148             $PAGE->set_heading($course->fullname);
149             $PAGE->navbar->add($strreports, new moodle_url('/course/report.php', array('id'=>$course->id)));
150             $PAGE->navbar->add($strlogs);
151             echo $OUTPUT->header();
152         }
154         echo $OUTPUT->heading(get_string('chooselogs') .':');
156         print_log_selector_form($course, $user, $date, $modname, $modid, $modaction, $group, $showcourses, $showusers, $logformat);
158         $livelogs = get_string('livelogs');
159         $url = new moodle_url('/course/report/log/live.php', array('id'=>$course->id));
160         $link = new action_link($url, $livelogs, new popup_action('click', $url, 'livelog', array('height' => 500, 'width' => 800)));
162         echo $OUTPUT->render($link);
163     }
165     echo $OUTPUT->footer();
167     exit;