Merge branch 'MDL-36752-MOODLE_23_STABLE-2' of git://git.luns.net.uk/moodle into...
[moodle.git] / report / log / index.php
CommitLineData
033af4b7
PS
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Displays different views of the logs.
19 *
04252d3a 20 * @package report_log
033af4b7
PS
21 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25require('../../config.php');
26require_once($CFG->dirroot.'/course/lib.php');
27require_once($CFG->dirroot.'/report/log/locallib.php');
28require_once($CFG->libdir.'/adminlib.php');
29
30$id = optional_param('id', 0, PARAM_INT);// Course ID
31$host_course = optional_param('host_course', '', PARAM_PATH);// Course ID
32
33if (empty($host_course)) {
34 $hostid = $CFG->mnet_localhost_id;
35 if (empty($id)) {
36 $site = get_site();
37 $id = $site->id;
38 }
39} else {
40 list($hostid, $id) = explode('/', $host_course);
41}
42
43$group = optional_param('group', 0, PARAM_INT); // Group to display
44$user = optional_param('user', 0, PARAM_INT); // User to display
eb7b030a 45$date = optional_param('date', 0, PARAM_INT); // Date to display
033af4b7
PS
46$modname = optional_param('modname', '', PARAM_PLUGIN); // course_module->id
47$modid = optional_param('modid', 0, PARAM_FILE); // number or 'site_errors'
48$modaction = optional_param('modaction', '', PARAM_PATH); // an action as recorded in the logs
49$page = optional_param('page', '0', PARAM_INT); // which page to show
50$perpage = optional_param('perpage', '100', PARAM_INT); // how many per page
51$showcourses = optional_param('showcourses', 0, PARAM_INT); // whether to show courses if we're over our limit.
52$showusers = optional_param('showusers', 0, PARAM_INT); // whether to show users if we're over our limit.
53$chooselog = optional_param('chooselog', 0, PARAM_INT);
54$logformat = optional_param('logformat', 'showashtml', PARAM_ALPHA);
55
56$params = array();
fad8e024
PS
57if ($id !== 0) {
58 $params['id'] = $id;
59}
60if ($host_course !== '') {
61 $params['host_course'] = $host_course;
62}
63if ($group !== 0) {
64 $params['group'] = $group;
65}
66if ($user !== 0) {
67 $params['user'] = $user;
68}
69if ($date !== 0) {
70 $params['date'] = $date;
71}
72if ($modname !== '') {
73 $params['modname'] = $modname;
74}
75if ($modid !== 0) {
76 $params['modid'] = $modid;
77}
78if ($modaction !== '') {
79 $params['modaction'] = $modaction;
80}
81if ($page !== '0') {
82 $params['page'] = $page;
83}
84if ($perpage !== '100') {
85 $params['perpage'] = $perpage;
86}
87if ($showcourses !== 0) {
88 $params['showcourses'] = $showcourses;
89}
90if ($showusers !== 0) {
91 $params['showusers'] = $showusers;
92}
93if ($chooselog !== 0) {
94 $params['chooselog'] = $chooselog;
95}
96if ($logformat !== 'showashtml') {
97 $params['logformat'] = $logformat;
98}
033af4b7
PS
99$PAGE->set_url('/report/log/index.php', $params);
100$PAGE->set_pagelayout('report');
101
102if ($hostid == $CFG->mnet_localhost_id) {
fad8e024
PS
103 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
104
033af4b7
PS
105} else {
106 $course_stub = $DB->get_record('mnet_log', array('hostid'=>$hostid, 'course'=>$id), '*', true);
107 $course->id = $id;
108 $course->shortname = $course_stub->coursename;
109 $course->fullname = $course_stub->coursename;
110}
111
112require_login($course);
113
114$context = get_context_instance(CONTEXT_COURSE, $course->id);
115
116require_capability('report/log:view', $context);
117
118add_to_log($course->id, "course", "report log", "report/log/index.php?id=$course->id", $course->id);
119
120$strlogs = get_string('logs');
121$stradministration = get_string('administration');
122$strreports = get_string('reports');
123
05d1f6cb
RT
124// Before we close session, make sure we have editing information in session.
125$adminediting = optional_param('adminedit', -1, PARAM_BOOL);
126if ($PAGE->user_allowed_editing() && $adminediting != -1) {
127 $USER->editing = $adminediting;
128}
033af4b7
PS
129session_get_instance()->write_close();
130
033af4b7
PS
131if (!empty($chooselog)) {
132 $userinfo = get_string('allparticipants');
133 $dateinfo = get_string('alldays');
134
135 if ($user) {
fad8e024 136 $u = $DB->get_record('user', array('id'=>$user, 'deleted'=>0), '*', MUST_EXIST);
033af4b7
PS
137 $userinfo = fullname($u, has_capability('moodle/site:viewfullnames', $context));
138 }
139 if ($date) {
140 $dateinfo = userdate($date, get_string('strftimedaydate'));
141 }
142
143 switch ($logformat) {
144 case 'showashtml':
145 if ($hostid != $CFG->mnet_localhost_id || $course->id == SITEID) {
146 admin_externalpage_setup('reportlog');
147 echo $OUTPUT->header();
148
149 } else {
150 $PAGE->set_title($course->shortname .': '. $strlogs);
151 $PAGE->set_heading($course->fullname);
152 $PAGE->navbar->add("$userinfo, $dateinfo");
153 echo $OUTPUT->header();
154 }
155
156 echo $OUTPUT->heading(format_string($course->fullname) . ": $userinfo, $dateinfo (".usertimezone().")");
fad8e024 157 report_log_print_mnet_selector_form($hostid, $course, $user, $date, $modname, $modid, $modaction, $group, $showcourses, $showusers, $logformat);
033af4b7 158
fad8e024 159 if ($hostid == $CFG->mnet_localhost_id) {
033af4b7
PS
160 print_log($course, $user, $date, 'l.time DESC', $page, $perpage,
161 "index.php?id=$course->id&amp;chooselog=1&amp;user=$user&amp;date=$date&amp;modid=$modid&amp;modaction=$modaction&amp;group=$group",
162 $modname, $modid, $modaction, $group);
163 } else {
164 print_mnet_log($hostid, $id, $user, $date, 'l.time DESC', $page, $perpage, "", $modname, $modid, $modaction, $group);
165 }
166 break;
167 case 'downloadascsv':
168 if (!print_log_csv($course, $user, $date, 'l.time DESC', $modname,
169 $modid, $modaction, $group)) {
170 echo $OUTPUT->notification("No logs found!");
171 echo $OUTPUT->footer();
172 }
173 exit;
174 case 'downloadasods':
175 if (!print_log_ods($course, $user, $date, 'l.time DESC', $modname,
176 $modid, $modaction, $group)) {
177 echo $OUTPUT->notification("No logs found!");
178 echo $OUTPUT->footer();
179 }
180 exit;
181 case 'downloadasexcel':
182 if (!print_log_xls($course, $user, $date, 'l.time DESC', $modname,
183 $modid, $modaction, $group)) {
184 echo $OUTPUT->notification("No logs found!");
185 echo $OUTPUT->footer();
186 }
187 exit;
188 }
189
190
191} else {
192 if ($hostid != $CFG->mnet_localhost_id || $course->id == SITEID) {
98dd8e72 193 admin_externalpage_setup('reportlog', '', null, '', array('pagelayout'=>'report'));
033af4b7
PS
194 echo $OUTPUT->header();
195 } else {
196 $PAGE->set_title($course->shortname .': '. $strlogs);
197 $PAGE->set_heading($course->fullname);
198 echo $OUTPUT->header();
199 }
200
201 echo $OUTPUT->heading(get_string('chooselogs') .':');
202
fad8e024 203 report_log_print_selector_form($course, $user, $date, $modname, $modid, $modaction, $group, $showcourses, $showusers, $logformat);
033af4b7
PS
204}
205
206echo $OUTPUT->footer();
207