More nav cleanups
[moodle.git] / course / report / log / index.php
CommitLineData
aa6c1ced 1<?php
0a935fb3 2 // Displays different views of the logs.
3
4 require_once('../../../config.php');
5 require_once('../../lib.php');
6 require_once('lib.php');
4e03aa7a 7 require_once($CFG->libdir.'/adminlib.php');
0a935fb3 8
15ed527f 9 $id = optional_param('id', 0, PARAM_INT);// Course ID
0be6f678 10
15ed527f 11 $host_course = optional_param('host_course', '', PARAM_PATH);// Course ID
0be6f678 12
15ed527f 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 }
0be6f678 22
60ce929f 23 $group = optional_param('group', 0, PARAM_INT); // Group to display
1f411afd 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
0be6f678 30 $perpage = optional_param('perpage', '100', PARAM_INT); // how many per page
92890025 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);
0a935fb3 35
7f093351 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;
a6855934 49 $PAGE->set_url('/course/report/log/index.php', $params);
dfab77a2 50
c215b32b 51 if ($hostid == $CFG->mnet_localhost_id) {
29f83769 52 if (!$course = $DB->get_record('course', array('id'=>$id))) {
5a2a5331 53 print_error('That\'s an invalid course id'.$id);
c215b32b 54 }
15ed527f 55 } else {
29f83769 56 $course_stub = $DB->get_record('mnet_log', array('hostid'=>$hostid, 'course'=>$id), '*', true);
15ed527f 57 $course->id = $id;
58 $course->shortname = $course_stub->coursename;
59 $course->fullname = $course_stub->coursename;
0a935fb3 60 }
c215b32b 61
a2e4bf7f 62 require_login($course);
a0501fc3 63
1a3e93ff 64 $context = get_context_instance(CONTEXT_COURSE, $course->id);
4e03aa7a 65
a2e4bf7f 66 require_capability('coursereport/log:view', $context);
0a935fb3 67
0be6f678 68 add_to_log($course->id, "course", "report log", "report/log/index.php?id=$course->id", $course->id);
1f411afd 69
0a935fb3 70 $strlogs = get_string('logs');
71 $stradministration = get_string('administration');
6b2f1037 72 $strreports = get_string('reports');
0a935fb3 73
56949c17 74 session_get_instance()->write_close();
0a935fb3 75
0be6f678 76 $navlinks = array();
77
0a935fb3 78 if (!empty($chooselog)) {
79 $userinfo = get_string('allparticipants');
80 $dateinfo = get_string('alldays');
81
82 if ($user) {
29f83769 83 if (!$u = $DB->get_record('user', array('id'=>$user))) {
5a2a5331 84 print_error('That\'s an invalid user!');
0a935fb3 85 }
1a3e93ff 86 $userinfo = fullname($u, has_capability('moodle/site:viewfullnames', $context));
0a935fb3 87 }
88 if ($date) {
89 $dateinfo = userdate($date, get_string('strftimedaydate'));
90 }
c215b32b 91
92890025 92 switch ($logformat) {
93 case 'showashtml':
c215b32b 94 if ($hostid != $CFG->mnet_localhost_id || $course->id == SITEID) {
1ae083e4 95 admin_externalpage_setup('reportlog');
61ef8f9f 96 echo $OUTPUT->header();
4e03aa7a 97
98 } else {
0a122046 99 $PAGE->set_title($course->shortname .': '. $strlogs);
100 $PAGE->set_heading($course->fullname);
a6855934 101 $PAGE->navbar->add($strreports, new moodle_url('/course/report.php', array('id'=>$course->id)));
760b2edb 102 $PAGE->navbar->add($strlogs, new moodle_url('/course/report/log/index.php', array('id'=>$course->id)));
0a122046 103 $PAGE->navbar->add("$userinfo, $dateinfo");
104 echo $OUTPUT->header();
92890025 105 }
106
7c5286cd 107 echo $OUTPUT->heading(format_string($course->fullname) . ": $userinfo, $dateinfo (".usertimezone().")");
c215b32b 108 print_mnet_log_selector_form($hostid, $course, $user, $date, $modname, $modid, $modaction, $group, $showcourses, $showusers, $logformat);
0be6f678 109
c215b32b 110 if($hostid == $CFG->mnet_localhost_id) {
0be6f678 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",
c215b32b 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 }
92890025 117 break;
118 case 'downloadascsv':
119 if (!print_log_csv($course, $user, $date, 'l.time DESC', $modname,
120 $modid, $modaction, $group)) {
e6db3026 121 echo $OUTPUT->notification("No logs found!");
d60c1124 122 echo $OUTPUT->footer();
92890025 123 }
124 exit;
ea49a66c 125 case 'downloadasods':
126 if (!print_log_ods($course, $user, $date, 'l.time DESC', $modname,
92890025 127 $modid, $modaction, $group)) {
e6db3026 128 echo $OUTPUT->notification("No logs found!");
d60c1124 129 echo $OUTPUT->footer();
92890025 130 }
131 exit;
ea49a66c 132 case 'downloadasexcel':
133 if (!print_log_xls($course, $user, $date, 'l.time DESC', $modname,
92890025 134 $modid, $modaction, $group)) {
e6db3026 135 echo $OUTPUT->notification("No logs found!");
d60c1124 136 echo $OUTPUT->footer();
92890025 137 }
138 exit;
139 }
0a935fb3 140
0a935fb3 141
142 } else {
c215b32b 143 if ($hostid != $CFG->mnet_localhost_id || $course->id == SITEID) {
1ae083e4 144 admin_externalpage_setup('reportlog');
61ef8f9f 145 echo $OUTPUT->header();
4e03aa7a 146 } else {
0a122046 147 $PAGE->set_title($course->shortname .': '. $strlogs);
148 $PAGE->set_heading($course->fullname);
760b2edb
MD
149 $PAGE->navbar->add($strreports, new moodle_url('/course/report.php', array('id'=>$course->id)));
150 $PAGE->navbar->add($strlogs);
0a122046 151 echo $OUTPUT->header();
0a935fb3 152 }
153
7c5286cd 154 echo $OUTPUT->heading(get_string('chooselogs') .':');
0a935fb3 155
92890025 156 print_log_selector_form($course, $user, $date, $modname, $modid, $modaction, $group, $showcourses, $showusers, $logformat);
07a737de
MD
157
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)));
161
162 echo $OUTPUT->render($link);
0a935fb3 163 }
164
d60c1124 165 echo $OUTPUT->footer();
0a935fb3 166
167 exit;
aa6c1ced 168