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 live view of recent logs
20 * This file generates live view of recent logs.
22 * @package report_loglive
23 * @copyright 2011 Petr Skoda
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 use core\report_helper
;
29 require('../../config.php');
30 require_once($CFG->libdir
.'/adminlib.php');
31 require_once($CFG->dirroot
.'/course/lib.php');
33 $id = optional_param('id', 0, PARAM_INT
);
34 $page = optional_param('page', 0, PARAM_INT
);
35 $logreader = optional_param('logreader', '', PARAM_COMPONENT
); // Reader which will be used for displaying logs.
38 admin_externalpage_setup('reportloglive', '', null, '', array('pagelayout' => 'report'));
39 $context = context_system
::instance();
40 $coursename = format_string($SITE->fullname
, true, array('context' => $context));
42 $course = get_course($id);
43 require_login($course);
44 $context = context_course
::instance($course->id
);
45 $coursename = format_string($course->fullname
, true, array('context' => $context));
47 require_capability('report/loglive:view', $context);
54 $params['page'] = $page;
56 if ($logreader !== '') {
57 $params['logreader'] = $logreader;
59 $url = new moodle_url("/report/loglive/index.php", $params);
62 $PAGE->set_pagelayout('report');
64 $renderable = new report_loglive_renderable($logreader, $id, $url, 0, $page);
65 $refresh = $renderable->get_refresh_rate();
66 $logreader = $renderable->selectedlogreader
;
68 $strlivelogs = get_string('livelogs', 'report_loglive');
69 $strupdatesevery = get_string('updatesevery', 'moodle', $refresh);
73 $PAGE->set_context($context);
74 $PAGE->set_title("$coursename: $strlivelogs");
75 $PAGE->set_heading($coursename);
77 $output = $PAGE->get_renderer('report_loglive');
78 echo $output->header();
80 // Print selector dropdown.
81 $pluginname = get_string('pluginname', 'report_loglive');
82 report_helper
::print_report_selector($pluginname);
83 echo html_writer
::div(get_string('livelogswithupdate', 'report_loglive', $strupdatesevery), 'mb-3');
84 echo $output->reader_selector($renderable);
85 echo $output->toggle_liveupdate_button($renderable);
86 echo $output->render($renderable);
88 // Include and trigger ajax requests.
89 if ($page == 0 && !empty($logreader)) {
90 // Tell Js to fetch new logs only, by passing the latest timestamp of records in the table.
91 $until = $renderable->get_table()->get_until();
92 $jsparams = array('since' => $until , 'courseid' => $id, 'page' => $page, 'logreader' => $logreader,
93 'interval' => $refresh, 'perpage' => $renderable->perpage
);
94 $PAGE->requires
->strings_for_js(array('pause', 'resume'), 'report_loglive');
95 $PAGE->requires
->yui_module('moodle-report_loglive-fetchlogs', 'Y.M.report_loglive.FetchLogs.init', array($jsparams));
98 // Trigger a logs viewed event.
99 $event = \report_loglive\event\report_viewed
::create(array('context' => $context));
102 echo $output->footer();