Merged branch 'MDL-31014-master-4' of git://git.luns.net.uk/moodle.git with conflict...
[moodle.git] / report / loglive / index.php
blob782679bc4cf5ce6bc2ccc50d66ac4f0162c76ed5
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.
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/>.
17 /**
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 require('../../config.php');
28 require_once($CFG->libdir.'/adminlib.php');
29 require_once($CFG->dirroot.'/course/lib.php');
31 if (!defined('REPORT_LOGLIVE_REFRESH')) {
32 define('REPORT_LOGLIVE_REFRESH', 60); // Seconds
35 $id = optional_param('id', $SITE->id, PARAM_INT);
36 $page = optional_param('page', 0, PARAM_INT);
37 $inpopup = optional_param('inpopup', 0, PARAM_BOOL);
39 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
41 require_login($course);
43 $context = context_course::instance($course->id);
44 require_capability('report/loglive:view', $context);
46 $strlivelogs = get_string('livelogs', 'report_loglive');
48 if ($inpopup) {
49 session_get_instance()->write_close();
51 add_to_log($course->id, 'course', 'report live', "report/loglive/index.php?id=$course->id", $course->id);
53 $date = time() - 3600;
55 $url = new moodle_url('/report/loglive/index.php', array('id'=>$course->id, 'user'=>0, 'date'=>$date, 'inpopup'=>1));
57 $strupdatesevery = get_string('updatesevery', 'moodle', REPORT_LOGLIVE_REFRESH);
59 $coursename = format_string($course->fullname, true, array('context'=>$context));
61 $PAGE->set_url($url);
62 $PAGE->set_pagelayout('popup');
63 $PAGE->set_title("$coursename: $strlivelogs ($strupdatesevery)");
64 $PAGE->set_periodic_refresh_delay(REPORT_LOGLIVE_REFRESH);
65 $PAGE->set_heading($strlivelogs);
66 echo $OUTPUT->header();
68 print_log($course, 0, $date, "l.time DESC", $page, 500, $url);
70 echo $OUTPUT->footer();
71 exit;
75 if ($course->id == SITEID) {
76 admin_externalpage_setup('reportloglive', '', null, '', array('pagelayout'=>'report'));
77 echo $OUTPUT->header();
79 } else {
80 $PAGE->set_url('/report/log/live.php', array('id'=>$course->id));
81 $PAGE->set_title($course->shortname .': '. $strlogs);
82 $PAGE->set_heading($course->fullname);
83 echo $OUTPUT->header();
86 echo $OUTPUT->heading(get_string('pluginname', 'report_loglive'));
88 echo $OUTPUT->container_start('info');
89 $link = new moodle_url('/report/loglive/index.php', array('id'=>$course->id, 'inpopup'=>1));
90 echo $OUTPUT->action_link($link, $strlivelogs, new popup_action('click', $link, 'livelog', array('height' => 500, 'width' => 800)));
91 echo $OUTPUT->container_end();
93 echo $OUTPUT->footer();