dirroot.'/lib/statslib.php'); $report = optional_param('report',STATS_REPORT_ACTIVE_COURSES,PARAM_INT); $time = optional_param('time',0,PARAM_INT); $numcourses = optional_param('numcourses',20,PARAM_INT); if (empty($CFG->enablestats)) { error("Stats is not enabled."); } require_login(); if (!isadmin()) { error("This page is for admins only"); } $course = get_site(); stats_check_uptodate($course->id); $strheader = get_string('reports'); $strnav = ''.get_string('administration').' -> '.$strheader; $reportoptions = stats_get_report_options($course->id,STATS_MODE_RANKED); $tableprefix = $CFG->prefix.'stats_'; $earliestday = get_field_sql('SELECT timeend FROM '.$tableprefix.'daily ORDER BY timeend LIMIT 1'); $earliestweek = get_field_sql('SELECT timeend FROM '.$tableprefix.'weekly ORDER BY timeend LIMIT 1'); $earliestmonth = get_field_sql('SELECT timeend FROM '.$tableprefix.'monthly ORDER BY timeend LIMIT 1'); if (empty($earliestday)) $earliestday = time(); if (empty($earliestweek)) $earliestweek = time(); if (empty($earliestmonth)) $earliestmonth = time(); $now = stats_get_base_daily(); $lastweekend = stats_get_base_weekly(); $lastmonthend = stats_get_base_monthly(); $timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth); if (empty($timeoptions)) { error(get_string('nostatstodisplay'), $CFG->wwwroot.'/course/view.php?id='.$course->id); } print_header($strheader,$strheader,$strnav,'','',true,' '); echo '
'; if (!empty($report) && !empty($time)) { $param = stats_get_parameters($time,$report,SITEID,STATS_MODE_RANKED); $sql = "SELECT courseid,".$param->fields." FROM ".$CFG->prefix.'stats_'.$param->table ." WHERE timeend >= ".$param->timeafter ." GROUP BY courseid " .$param->extras ." ORDER BY ".$param->orderby ." LIMIT ".$numcourses; $courses = get_records_sql($sql); if (empty($courses)) { error(get_string('statsnodata'),$CFG->wwwroot.'/admin/reports.php'); } echo '