2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Displays different views of the logs.
21 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require('../../config.php');
26 require_once($CFG->dirroot
.'/course/lib.php');
27 require_once($CFG->dirroot
.'/report/log/locallib.php');
28 require_once($CFG->libdir
.'/adminlib.php');
30 $id = optional_param('id', 0, PARAM_INT
);// Course ID
31 $host_course = optional_param('host_course', '', PARAM_PATH
);// Course ID
33 if (empty($host_course)) {
34 $hostid = $CFG->mnet_localhost_id
;
40 list($hostid, $id) = explode('/', $host_course);
43 $group = optional_param('group', 0, PARAM_INT
); // Group to display
44 $user = optional_param('user', 0, PARAM_INT
); // User to display
45 $date = optional_param('date', 0, PARAM_INT
); // Date to display
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
);
60 if ($host_course !== '') {
61 $params['host_course'] = $host_course;
64 $params['group'] = $group;
67 $params['user'] = $user;
70 $params['date'] = $date;
72 if ($modname !== '') {
73 $params['modname'] = $modname;
76 $params['modid'] = $modid;
78 if ($modaction !== '') {
79 $params['modaction'] = $modaction;
82 $params['page'] = $page;
84 if ($perpage !== '100') {
85 $params['perpage'] = $perpage;
87 if ($showcourses !== 0) {
88 $params['showcourses'] = $showcourses;
90 if ($showusers !== 0) {
91 $params['showusers'] = $showusers;
93 if ($chooselog !== 0) {
94 $params['chooselog'] = $chooselog;
96 if ($logformat !== 'showashtml') {
97 $params['logformat'] = $logformat;
99 $PAGE->set_url('/report/log/index.php', $params);
100 $PAGE->set_pagelayout('report');
102 if ($hostid == $CFG->mnet_localhost_id
) {
103 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST
);
106 $course_stub = $DB->get_record('mnet_log', array('hostid'=>$hostid, 'course'=>$id), '*', true);
108 $course->shortname
= $course_stub->coursename
;
109 $course->fullname
= $course_stub->coursename
;
112 require_login($course);
114 $context = get_context_instance(CONTEXT_COURSE
, $course->id
);
116 require_capability('report/log:view', $context);
118 add_to_log($course->id
, "course", "report log", "report/log/index.php?id=$course->id", $course->id
);
120 $strlogs = get_string('logs');
121 $stradministration = get_string('administration');
122 $strreports = get_string('reports');
124 // Before we close session, make sure we have editing information in session.
125 $adminediting = optional_param('adminedit', -1, PARAM_BOOL
);
126 if ($PAGE->user_allowed_editing() && $adminediting != -1) {
127 $USER->editing
= $adminediting;
129 session_get_instance()->write_close();
131 if (!empty($chooselog)) {
132 $userinfo = get_string('allparticipants');
133 $dateinfo = get_string('alldays');
136 $u = $DB->get_record('user', array('id'=>$user, 'deleted'=>0), '*', MUST_EXIST
);
137 $userinfo = fullname($u, has_capability('moodle/site:viewfullnames', $context));
140 $dateinfo = userdate($date, get_string('strftimedaydate'));
143 switch ($logformat) {
145 if ($hostid != $CFG->mnet_localhost_id ||
$course->id
== SITEID
) {
146 admin_externalpage_setup('reportlog');
147 echo $OUTPUT->header();
150 $PAGE->set_title($course->shortname
.': '. $strlogs);
151 $PAGE->set_heading($course->fullname
);
152 $PAGE->navbar
->add("$userinfo, $dateinfo");
153 echo $OUTPUT->header();
156 echo $OUTPUT->heading(format_string($course->fullname
) . ": $userinfo, $dateinfo (".usertimezone().")");
157 report_log_print_mnet_selector_form($hostid, $course, $user, $date, $modname, $modid, $modaction, $group, $showcourses, $showusers, $logformat);
159 if ($hostid == $CFG->mnet_localhost_id
) {
160 print_log($course, $user, $date, 'l.time DESC', $page, $perpage,
161 "index.php?id=$course->id&chooselog=1&user=$user&date=$date&modid=$modid&modaction=$modaction&group=$group",
162 $modname, $modid, $modaction, $group);
164 print_mnet_log($hostid, $id, $user, $date, 'l.time DESC', $page, $perpage, "", $modname, $modid, $modaction, $group);
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();
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();
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();
192 if ($hostid != $CFG->mnet_localhost_id ||
$course->id
== SITEID
) {
193 admin_externalpage_setup('reportlog', '', null, '', array('pagelayout'=>'report'));
194 echo $OUTPUT->header();
196 $PAGE->set_title($course->shortname
.': '. $strlogs);
197 $PAGE->set_heading($course->fullname
);
198 echo $OUTPUT->header();
201 echo $OUTPUT->heading(get_string('chooselogs') .':');
203 report_log_print_selector_form($course, $user, $date, $modname, $modid, $modaction, $group, $showcourses, $showusers, $logformat);
206 echo $OUTPUT->footer();