3 * This file is also required by /admin/reports/stats/index.php.
7 require_once('../../../config.php');
8 require_once($CFG->dirroot
.'/lib/statslib.php');
11 function report_stats_mode_menu($course, $mode, $time, $url) {
14 $reportoptions = stats_get_report_options($course->id, $mode);
15 $timeoptions = report_stats_timeoptions($mode);
16 if (empty($timeoptions)) {
17 print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/view.php?id='.$course->id);
22 $options[STATS_MODE_GENERAL
] = get_string('statsmodegeneral');
23 $options[STATS_MODE_DETAILED
] = get_string('statsmodedetailed');
24 if (has_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM
))) {
25 $options[STATS_MODE_RANKED
] = get_string('reports');
28 return popup_form($url."?course=$course->id&time=$time&mode=", $options, 'switchmode', $mode, '', '', '', true);
32 function report_stats_timeoptions($mode) {
35 $tableprefix = $CFG->prefix
.'stats_';
37 if ($mode == STATS_MODE_DETAILED
) {
38 $tableprefix = $CFG->prefix
.'stats_user_';
41 $earliestday = get_field_sql('SELECT timeend FROM '.$tableprefix.'daily ORDER BY timeend');
42 $earliestweek = get_field_sql('SELECT timeend FROM '.$tableprefix.'weekly ORDER BY timeend');
43 $earliestmonth = get_field_sql('SELECT timeend FROM '.$tableprefix.'monthly ORDER BY timeend');
45 if (empty($earliestday)) $earliestday = time();
46 if (empty($earliestweek)) $earliestweek = time();
47 if (empty($earliestmonth)) $earliestmonth = time();
49 $now = stats_get_base_daily();
50 $lastweekend = stats_get_base_weekly();
51 $lastmonthend = stats_get_base_monthly();
53 return stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth);