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   * stats report
  19   *
  20   * @package    report
  21   * @subpackage stats
  22   * @copyright  1999 onwards Martin Dougiamas (http://dougiamas.com)
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  require_once('../../config.php');
  27  require_once($CFG->dirroot.'/report/stats/locallib.php');
  28  require_once($CFG->libdir.'/adminlib.php');
  29  
  30  $courseid = optional_param('course', SITEID, PARAM_INT);
  31  $report   = optional_param('report', 0, PARAM_INT);
  32  $time     = optional_param('time', 0, PARAM_INT);
  33  $mode     = optional_param('mode', STATS_MODE_GENERAL, PARAM_INT);
  34  $userid   = optional_param('userid', 0, PARAM_INT);
  35  $roleid   = 0;
  36  
  37  if ($report > 50) {
  38      $roleid = substr($report,1);
  39      $report = 5;
  40  }
  41  
  42  if ($report == STATS_REPORT_USER_LOGINS) {
  43      $courseid = SITEID; //override
  44  }
  45  
  46  if ($mode == STATS_MODE_RANKED) {
  47      redirect($CFG->wwwroot.'/report/stats/index.php?time='.$time);
  48  }
  49  
  50  if (!$course = $DB->get_record("course", array("id"=>$courseid))) {
  51      print_error("invalidcourseid");
  52  }
  53  
  54  if (!empty($userid)) {
  55      $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
  56  } else {
  57      $user = null;
  58  }
  59  
  60  require_login($course);
  61  $context = context_course::instance($course->id);
  62  require_capability('report/stats:view', $context);
  63  
  64  $PAGE->set_url(new moodle_url('/report/stats/index.php', array('course' => $course->id,
  65                                                                 'report' => $report,
  66                                                                 'time'   => $time,
  67                                                                 'mode'   => $mode,
  68                                                                 'userid' => $userid)));
  69  navigation_node::override_active_url(new moodle_url('/report/stats/index.php', array('course' => $course->id)));
  70  
  71  // Trigger a content view event.
  72  $event = \report_stats\event\report_viewed::create(array('context' => $context, 'relateduserid' => $userid,
  73          'other' => array('report' => $report, 'time' => $time, 'mode' => $mode)));
  74  $event->trigger();
  75  stats_check_uptodate($course->id);
  76  
  77  if ($course->id == SITEID) {
  78      admin_externalpage_setup('reportstats', '', null, '', array('pagelayout'=>'report'));
  79      echo $OUTPUT->header();
  80  } else {
  81      $strreports = get_string("reports");
  82      $strstats = get_string('stats');
  83  
  84      $PAGE->set_title("$course->shortname: $strstats");
  85      $PAGE->set_heading($course->fullname);
  86      $PAGE->set_pagelayout('report');
  87      $PAGE->set_headingmenu(report_stats_mode_menu($course, $mode, $time, "$CFG->wwwroot/report/stats/index.php"));
  88      echo $OUTPUT->header();
  89  }
  90  
  91  report_stats_report($course, $report, $mode, $user, $roleid, $time);
  92  
  93  if (empty($CFG->enablestats)) {
  94      if (has_capability('moodle/site:config', context_system::instance())) {
  95          redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'), 3);
  96      } else {
  97          print_error('statsdisable');
  98      }
  99  }
 100  
 101  echo $OUTPUT->footer();
 102  
 103