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/>.
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
);
38 $roleid = substr($report,1);
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
);
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
,
68 'userid' => $userid)));
70 add_to_log($course->id
, "course", "report stats", "report/stats/index.php?course=$course->id", $course->id
);
71 stats_check_uptodate($course->id
);
73 if ($course->id
== SITEID
) {
74 admin_externalpage_setup('reportstats', '', null, '', array('pagelayout'=>'report'));
75 echo $OUTPUT->header();
77 $strreports = get_string("reports");
78 $strstats = get_string('stats');
80 $PAGE->set_title("$course->shortname: $strstats");
81 $PAGE->set_heading($course->fullname
);
82 $PAGE->set_pagelayout('report');
83 $PAGE->set_headingmenu(report_stats_mode_menu($course, $mode, $time, "$CFG->wwwroot/report/stats/index.php"));
84 echo $OUTPUT->header();
87 report_stats_report($course, $report, $mode, $user, $roleid, $time);
89 if (empty($CFG->enablestats
)) {
90 if (has_capability('moodle/site:config', context_system
::instance())) {
91 redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'), 3);
93 print_error('statsdisable');
97 echo $OUTPUT->footer();