| 1 |
efrain |
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 |
*
|
|
|
20 |
* @package report_log
|
|
|
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 |
|
|
|
25 |
use core\report_helper;
|
|
|
26 |
|
|
|
27 |
require('../../config.php');
|
|
|
28 |
require_once($CFG->dirroot.'/course/lib.php');
|
|
|
29 |
require_once($CFG->dirroot.'/report/log/locallib.php');
|
|
|
30 |
require_once($CFG->libdir.'/adminlib.php');
|
|
|
31 |
require_once($CFG->dirroot.'/lib/tablelib.php');
|
|
|
32 |
|
|
|
33 |
$id = optional_param('id', 0, PARAM_INT);// Course ID.
|
|
|
34 |
$group = optional_param('group', 0, PARAM_INT); // Group to display.
|
|
|
35 |
$user = optional_param('user', 0, PARAM_INT); // User to display.
|
|
|
36 |
$date = optional_param('date', 0, PARAM_INT); // Date to display.
|
|
|
37 |
$modid = optional_param('modid', 0, PARAM_ALPHANUMEXT); // Module id or 'site_errors'.
|
| 1441 |
ariadna |
38 |
$isactivitypage = optional_param('isactivitypage', false, PARAM_BOOL); // Is this a course module page?
|
| 1 |
efrain |
39 |
$modaction = optional_param('modaction', '', PARAM_ALPHAEXT); // An action as recorded in the logs.
|
|
|
40 |
$page = optional_param('page', '0', PARAM_INT); // Which page to show.
|
|
|
41 |
$perpage = optional_param('perpage', '100', PARAM_INT); // How many per page.
|
|
|
42 |
$showcourses = optional_param('showcourses', false, PARAM_BOOL); // Whether to show courses if we're over our limit.
|
|
|
43 |
$showusers = optional_param('showusers', false, PARAM_BOOL); // Whether to show users if we're over our limit.
|
|
|
44 |
$chooselog = optional_param('chooselog', false, PARAM_BOOL);
|
|
|
45 |
$logformat = optional_param('download', '', PARAM_ALPHA);
|
|
|
46 |
$logreader = optional_param('logreader', '', PARAM_COMPONENT); // Reader which will be used for displaying logs.
|
|
|
47 |
$edulevel = optional_param('edulevel', -1, PARAM_INT); // Educational level.
|
|
|
48 |
$origin = optional_param('origin', '', PARAM_TEXT); // Event origin.
|
|
|
49 |
|
|
|
50 |
$params = array();
|
|
|
51 |
if (!empty($id)) {
|
|
|
52 |
$params['id'] = $id;
|
|
|
53 |
} else {
|
|
|
54 |
$id = $SITE->id;
|
|
|
55 |
}
|
|
|
56 |
if ($group !== 0) {
|
|
|
57 |
$params['group'] = $group;
|
|
|
58 |
}
|
|
|
59 |
if ($user !== 0) {
|
|
|
60 |
$params['user'] = $user;
|
|
|
61 |
}
|
|
|
62 |
if ($date !== 0) {
|
|
|
63 |
$params['date'] = $date;
|
|
|
64 |
}
|
|
|
65 |
if ($modid !== 0) {
|
|
|
66 |
$params['modid'] = $modid;
|
|
|
67 |
}
|
|
|
68 |
if ($modaction !== '') {
|
|
|
69 |
$params['modaction'] = $modaction;
|
|
|
70 |
}
|
|
|
71 |
if ($page !== '0') {
|
|
|
72 |
$params['page'] = $page;
|
|
|
73 |
}
|
|
|
74 |
if ($perpage !== '100') {
|
|
|
75 |
$params['perpage'] = $perpage;
|
|
|
76 |
}
|
|
|
77 |
if ($showcourses) {
|
|
|
78 |
$params['showcourses'] = $showcourses;
|
|
|
79 |
}
|
|
|
80 |
if ($showusers) {
|
|
|
81 |
$params['showusers'] = $showusers;
|
|
|
82 |
}
|
|
|
83 |
if ($chooselog) {
|
|
|
84 |
$params['chooselog'] = $chooselog;
|
|
|
85 |
}
|
|
|
86 |
if ($logformat !== '') {
|
|
|
87 |
$params['download'] = $logformat;
|
|
|
88 |
}
|
|
|
89 |
if ($logreader !== '') {
|
|
|
90 |
$params['logreader'] = $logreader;
|
|
|
91 |
}
|
|
|
92 |
if (($edulevel != -1)) {
|
|
|
93 |
$params['edulevel'] = $edulevel;
|
|
|
94 |
}
|
|
|
95 |
if ($origin !== '') {
|
|
|
96 |
$params['origin'] = $origin;
|
|
|
97 |
}
|
|
|
98 |
$url = new moodle_url("/report/log/index.php", $params);
|
|
|
99 |
|
|
|
100 |
$PAGE->set_url('/report/log/index.php', array('id' => $id));
|
|
|
101 |
$PAGE->set_pagelayout('report');
|
|
|
102 |
|
| 1441 |
ariadna |
103 |
$cminfo = null;
|
|
|
104 |
if (!is_number($modid)) {
|
|
|
105 |
$isactivitypage = false;
|
|
|
106 |
}
|
|
|
107 |
if ($isactivitypage) {
|
|
|
108 |
$modinfo = get_fast_modinfo($id);
|
|
|
109 |
$cminfo = $modinfo->cms[intval($modid)] ?? null;
|
|
|
110 |
if ($cminfo === null) {
|
|
|
111 |
throw new moodle_exception('invalidmoduleid', '', '', $modid);
|
|
|
112 |
}
|
|
|
113 |
}
|
|
|
114 |
|
| 1 |
efrain |
115 |
// Get course details.
|
| 1441 |
ariadna |
116 |
$sitecoursefilter = 0;
|
| 1 |
efrain |
117 |
if ($id != $SITE->id) {
|
| 1441 |
ariadna |
118 |
$course = $DB->get_record('course', ['id' => $id], '*');
|
|
|
119 |
if ($course) {
|
|
|
120 |
require_login($course);
|
|
|
121 |
$context = context_course::instance($course->id);
|
|
|
122 |
if ($cminfo !== null) {
|
|
|
123 |
$context = $cminfo->context;
|
|
|
124 |
$PAGE->set_cm($cminfo);
|
|
|
125 |
}
|
|
|
126 |
} else {
|
|
|
127 |
// Missing courses may have be deleted, so display them in site context.
|
|
|
128 |
$sitecoursefilter = $id;
|
|
|
129 |
}
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
if (empty($course)) {
|
| 1 |
efrain |
133 |
$course = $SITE;
|
|
|
134 |
require_login();
|
|
|
135 |
$context = context_system::instance();
|
|
|
136 |
$PAGE->set_context($context);
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
require_capability('report/log:view', $context);
|
|
|
140 |
|
|
|
141 |
// When user choose to view logs then only trigger event.
|
|
|
142 |
if ($chooselog) {
|
|
|
143 |
// Trigger a report viewed event.
|
|
|
144 |
$event = \report_log\event\report_viewed::create(array('context' => $context, 'relateduserid' => $user,
|
|
|
145 |
'other' => array('groupid' => $group, 'date' => $date, 'modid' => $modid, 'modaction' => $modaction,
|
|
|
146 |
'logformat' => $logformat)));
|
|
|
147 |
$event->trigger();
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
if (!empty($page)) {
|
|
|
151 |
$strlogs = get_string('logs'). ": ". get_string('page', 'report_log', $page + 1);
|
|
|
152 |
} else {
|
|
|
153 |
$strlogs = get_string('logs');
|
|
|
154 |
}
|
|
|
155 |
$stradministration = get_string('administration');
|
|
|
156 |
$strreports = get_string('reports');
|
|
|
157 |
|
|
|
158 |
// Before we close session, make sure we have editing information in session.
|
|
|
159 |
$adminediting = optional_param('adminedit', -1, PARAM_BOOL);
|
|
|
160 |
if ($PAGE->user_allowed_editing() && $adminediting != -1) {
|
|
|
161 |
$USER->editing = $adminediting;
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
if ($course->id == $SITE->id) {
|
|
|
165 |
admin_externalpage_setup('reportlog', '', null, '', array('pagelayout' => 'report'));
|
|
|
166 |
$PAGE->set_title($strlogs);
|
|
|
167 |
$PAGE->set_primary_active_tab('siteadminnode');
|
|
|
168 |
} else {
|
| 1441 |
ariadna |
169 |
$contexttitle = $course->shortname . ': ';
|
|
|
170 |
if ($cminfo !== null) {
|
|
|
171 |
$contexttitle .= $cminfo->name . ' - ';
|
|
|
172 |
}
|
|
|
173 |
$PAGE->set_title($contexttitle . $strlogs);
|
| 1 |
efrain |
174 |
$PAGE->set_heading($course->fullname);
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
$output = $PAGE->get_renderer('report_log');
|
| 1441 |
ariadna |
178 |
if (!report_helper::has_valid_group($context)) {
|
|
|
179 |
echo $output->header();
|
|
|
180 |
echo $output->notification(get_string('notingroup'));
|
|
|
181 |
echo $output->footer();
|
|
|
182 |
exit();
|
|
|
183 |
}
|
| 1 |
efrain |
184 |
|
| 1441 |
ariadna |
185 |
$reportlog = new report_log_renderable(
|
|
|
186 |
logreader: $logreader,
|
|
|
187 |
course: $course,
|
|
|
188 |
userid: $user,
|
|
|
189 |
modid: $modid,
|
|
|
190 |
action: $modaction,
|
|
|
191 |
groupid: $group,
|
|
|
192 |
edulevel: $edulevel,
|
|
|
193 |
showcourses: $showcourses,
|
|
|
194 |
showusers: $showusers,
|
|
|
195 |
showreport: $chooselog,
|
|
|
196 |
showselectorform: true,
|
|
|
197 |
url: $url,
|
|
|
198 |
date: $date,
|
|
|
199 |
logformat: $logformat,
|
|
|
200 |
page: $page,
|
|
|
201 |
perpage: $perpage,
|
|
|
202 |
order: 'timecreated DESC',
|
|
|
203 |
origin: $origin,
|
|
|
204 |
isactivitypage: $isactivitypage,
|
|
|
205 |
sitecoursefilter: $sitecoursefilter,
|
|
|
206 |
);
|
|
|
207 |
|
|
|
208 |
$readers = $reportlog->get_readers();
|
| 1 |
efrain |
209 |
if (empty($readers)) {
|
|
|
210 |
echo $output->header();
|
|
|
211 |
echo $output->heading(get_string('nologreaderenabled', 'report_log'));
|
|
|
212 |
} else {
|
|
|
213 |
if (!empty($chooselog)) {
|
|
|
214 |
// Delay creation of table, till called by user with filter.
|
|
|
215 |
$reportlog->setup_table();
|
|
|
216 |
|
|
|
217 |
if (empty($logformat)) {
|
|
|
218 |
echo $output->header();
|
|
|
219 |
// Print selector dropdown.
|
|
|
220 |
$pluginname = get_string('pluginname', 'report_log');
|
| 1441 |
ariadna |
221 |
if (!$isactivitypage) {
|
|
|
222 |
report_helper::print_report_selector($pluginname);
|
|
|
223 |
}
|
| 1 |
efrain |
224 |
$userinfo = get_string('allparticipants');
|
|
|
225 |
$dateinfo = get_string('alldays');
|
|
|
226 |
|
|
|
227 |
if ($user) {
|
|
|
228 |
$u = $DB->get_record('user', array('id' => $user, 'deleted' => 0), '*', MUST_EXIST);
|
|
|
229 |
$userinfo = fullname($u, has_capability('moodle/site:viewfullnames', $context));
|
|
|
230 |
}
|
|
|
231 |
if ($date) {
|
|
|
232 |
$dateinfo = userdate($date, get_string('strftimedaydate'));
|
|
|
233 |
}
|
|
|
234 |
if (!empty($course) && ($course->id != SITEID)) {
|
|
|
235 |
$PAGE->navbar->add("$userinfo, $dateinfo");
|
|
|
236 |
}
|
|
|
237 |
echo $output->render($reportlog);
|
|
|
238 |
} else {
|
|
|
239 |
\core\session\manager::write_close();
|
|
|
240 |
$reportlog->download();
|
|
|
241 |
exit();
|
|
|
242 |
}
|
|
|
243 |
} else {
|
|
|
244 |
echo $output->header();
|
|
|
245 |
// Print selector dropdown.
|
|
|
246 |
$pluginname = get_string('pluginname', 'report_log');
|
| 1441 |
ariadna |
247 |
if (!$isactivitypage) {
|
|
|
248 |
report_helper::print_report_selector($pluginname);
|
|
|
249 |
}
|
| 1 |
efrain |
250 |
echo $output->heading(get_string('chooselogs') .':', 3);
|
|
|
251 |
echo $output->render($reportlog);
|
|
|
252 |
}
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
echo $output->footer();
|