dirroot.'/lib/statslib.php'); if (empty($CFG->enablestats)) { error("Stats is not enabled."); } $courseid = required_param('course',PARAM_INT); $report = optional_param('report',0,PARAM_INT); $time = optional_param('time',0,PARAM_INT); $mode = optional_param('mode',STATS_MODE_GENERAL,PARAM_INT); $userid = optional_param('userid',0,PARAM_INT); if ($report == STATS_REPORT_USER_LOGINS) { $courseid = SITEID; //override } if ($mode == STATS_MODE_RANKED) { redirect($CFG->wwwroot.'/admin/reports.php?time='.$time); } if (!$course = get_record("course","id",$courseid)) { error("That's an invalid course id"); } if (!empty($userid)) { if (!$user = get_record('user','id',$userid)) { error("That's an invalid user id"); } } require_login(); if (!isteacher($course->id)) { error("You need to be a teacher to use this page"); } stats_check_uptodate($course->id); $strheader = get_string('stats'); $strnav = (($course->id != SITEID) ? ''.$course->shortname.' -> ' : '').$strheader; $reportoptions = stats_get_report_options($courseid,$mode); $courses = get_courses('all','c.shortname','c.id,c.shortname,c.fullname'); $courseoptions = array(); foreach ($courses as $c) { if (isteacher($c->id)) { $courseoptions[$c->id] = $c->shortname; } } $tableprefix = $CFG->prefix.'stats_'; if ($mode == STATS_MODE_DETAILED) { $tableprefix = $CFG->prefix.'stats_user_'; } $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); } $options = array(); $options[STATS_MODE_GENERAL] = get_string('statsmodegeneral'); $options[STATS_MODE_DETAILED] = get_string('statsmodedetailed'); if (isadmin()) { $options[STATS_MODE_RANKED] = get_string('reports'); } $menu = choose_from_menu($options,'mode',$mode,'','this.form.submit();',0,true); $menu = '
'; print_header($strheader,$strheader,$strnav,'','',true,' ',$menu); echo ''; if (!empty($report) && !empty($time)) { if ($report == STATS_REPORT_LOGINS && $course->id != SITEID) { error("This type of report is only available for the site course"); } $param = stats_get_parameters($time,$report,$course->id,$mode); if ($mode == STATS_MODE_DETAILED) { $param->table = 'user_'.$param->table; } $sql = 'SELECT timeend,'.$param->fields.' FROM '.$CFG->prefix.'stats_'.$param->table.' WHERE ' .(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ') .((!empty($userid)) ? ' userid = '.$userid.' AND ' : '') . ((!empty($param->stattype)) ? ' stattype = \''.$param->stattype.'\' AND ' : '') .' timeend >= '.$param->timeafter .$param->extras .' ORDER BY timeend DESC'; $stats = get_records_sql($sql); if (empty($stats)) { error(get_string('statsnodata'.((!empty($user)) ? 'user' : '')),$CFG->wwwroot.'/stats/index.php?course='.$course->id.'&mode='.$mode.'&time='.$time); } $stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2))); print_heading($course->shortname.' - '.get_string('statsreport'.$report).((!empty($user)) ? ' '.get_string('statsreportforuser').' ' .fullname($user,true) : '')); if (empty($CFG->gdversion)) { echo "(".get_string("gdneed").")"; } else { if ($mode == STATS_MODE_DETAILED) { echo '