MDL-49144 blocks: Add behat test to ensury sanity of block title
[moodle.git] / report / stats / index.php
blob461bdb49a7b6eccaeb27523950ac6537e11168cc
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 * stats report
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
26 require_once('../../config.php');
27 require_once($CFG->dirroot.'/report/stats/locallib.php');
28 require_once($CFG->libdir.'/adminlib.php');
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;
37 if ($report > 50) {
38 $roleid = substr($report,1);
39 $report = 5;
42 if ($report == STATS_REPORT_USER_LOGINS) {
43 $courseid = SITEID; //override
46 if ($mode == STATS_MODE_RANKED) {
47 redirect($CFG->wwwroot.'/report/stats/index.php?time='.$time);
50 if (!$course = $DB->get_record("course", array("id"=>$courseid))) {
51 print_error("invalidcourseid");
54 if (!empty($userid)) {
55 $user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
56 } else {
57 $user = null;
60 require_login($course);
61 $context = context_course::instance($course->id);
62 require_capability('report/stats:view', $context);
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)));
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);
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');
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();
91 report_stats_report($course, $report, $mode, $user, $roleid, $time);
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');
101 echo $OUTPUT->footer();