Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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 live view of recent logs
  19   *
  20   * This file generates live view of recent logs.
  21   *
  22   * @package    report_loglive
  23   * @copyright  2011 Petr Skoda
  24   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  25   */
  26  
  27  require('../../config.php');
  28  require_once($CFG->libdir.'/adminlib.php');
  29  require_once($CFG->dirroot.'/course/lib.php');
  30  
  31  $id = optional_param('id', 0, PARAM_INT);
  32  $page = optional_param('page', 0, PARAM_INT);
  33  $logreader = optional_param('logreader', '', PARAM_COMPONENT); // Reader which will be used for displaying logs.
  34  
  35  if (empty($id)) {
  36      admin_externalpage_setup('reportloglive', '', null, '', array('pagelayout' => 'report'));
  37      $context = context_system::instance();
  38      $coursename = format_string($SITE->fullname, true, array('context' => $context));
  39  } else {
  40      $course = get_course($id);
  41      require_login($course);
  42      $context = context_course::instance($course->id);
  43      $coursename = format_string($course->fullname, true, array('context' => $context));
  44  }
  45  require_capability('report/loglive:view', $context);
  46  
  47  $params = array();
  48  if ($id != 0) {
  49      $params['id'] = $id;
  50  }
  51  if ($page != 0) {
  52      $params['page'] = $page;
  53  }
  54  if ($logreader !== '') {
  55      $params['logreader'] = $logreader;
  56  }
  57  $url = new moodle_url("/report/loglive/index.php", $params);
  58  
  59  $PAGE->set_url($url);
  60  $PAGE->set_pagelayout('report');
  61  
  62  $renderable = new report_loglive_renderable($logreader, $id, $url, 0, $page);
  63  $refresh = $renderable->get_refresh_rate();
  64  $logreader = $renderable->selectedlogreader;
  65  
  66  // Include and trigger ajax requests.
  67  if ($page == 0 && !empty($logreader)) {
  68      // Tell Js to fetch new logs only, by passing time().
  69      $jsparams = array('since' => time() , 'courseid' => $id, 'page' => $page, 'logreader' => $logreader,
  70              'interval' => $refresh, 'perpage' => $renderable->perpage);
  71      $PAGE->requires->strings_for_js(array('pause', 'resume'), 'report_loglive');
  72      $PAGE->requires->yui_module('moodle-report_loglive-fetchlogs', 'Y.M.report_loglive.FetchLogs.init', array($jsparams));
  73  }
  74  
  75  $strlivelogs = get_string('livelogs', 'report_loglive');
  76  $strupdatesevery = get_string('updatesevery', 'moodle', $refresh);
  77  
  78  
  79  $PAGE->set_url($url);
  80  $PAGE->set_context($context);
  81  $PAGE->set_title("$coursename: $strlivelogs ($strupdatesevery)");
  82  $PAGE->set_heading("$coursename: $strlivelogs ($strupdatesevery)");
  83  
  84  $output = $PAGE->get_renderer('report_loglive');
  85  echo $output->header();
  86  echo $output->reader_selector($renderable);
  87  echo $output->toggle_liveupdate_button($renderable);
  88  echo $output->render($renderable);
  89  
  90  // Trigger a logs viewed event.
  91  $event = \report_loglive\event\report_viewed::create(array('context' => $context));
  92  $event->trigger();
  93  
  94  echo $output->footer();