3 require_once('../../../config.php');
4 require_once($CFG->dirroot
.'/lib/statslib.php');
5 require_once($CFG->libdir
.'/adminlib.php');
7 admin_externalpage_setup('reportcourseoverview');
9 admin_externalpage_print_header();
11 $report = optional_param('report', STATS_REPORT_ACTIVE_COURSES
, PARAM_INT
);
12 $time = optional_param('time', 0, PARAM_INT
);
13 $numcourses = optional_param('numcourses', 20, PARAM_INT
);
15 require_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM
, SITEID
)); // needed?
17 if (empty($CFG->enablestats
)) {
18 redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'), 3);
23 stats_check_uptodate($course->id
);
25 $strreports = get_string('reports');
26 $strcourseoverview = get_string('courseoverview');
28 $reportoptions = stats_get_report_options($course->id
,STATS_MODE_RANKED
);
30 $tableprefix = $CFG->prefix
.'stats_';
32 $earliestday = get_field_sql('SELECT timeend FROM '.$tableprefix.'daily ORDER BY timeend');
33 $earliestweek = get_field_sql('SELECT timeend FROM '.$tableprefix.'weekly ORDER BY timeend');
34 $earliestmonth = get_field_sql('SELECT timeend FROM '.$tableprefix.'monthly ORDER BY timeend');
36 if (empty($earliestday)) $earliestday = time();
37 if (empty($earliestweek)) $earliestweek = time();
38 if (empty($earliestmonth)) $earliestmonth = time();
40 $now = stats_get_base_daily();
41 $lastweekend = stats_get_base_weekly();
42 $lastmonthend = stats_get_base_monthly();
44 $timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth);
46 if (empty($timeoptions)) {
47 error(get_string('nostatstodisplay'), $CFG->wwwroot
.'/course/view.php?id='.$course->id
);
50 echo '<form action="index.php" method="post">'."\n";
51 echo '<fieldset class="invisiblefieldset">';
54 $table->align
= array('left','left','left','left','left','left');
55 $table->data
[] = array(get_string('statsreporttype'),choose_from_menu($reportoptions,'report',$report,'','','',true),
56 get_string('statstimeperiod'),choose_from_menu($timeoptions,'time',$time,'','','',true),
57 '<input type="text" name="numcourses" size="3" maxlength="2" value="'.$numcourses.'" />',
58 '<input type="submit" value="'.get_string('view').'" />') ;
64 if (!empty($report) && !empty($time)) {
65 $param = stats_get_parameters($time,$report,SITEID
,STATS_MODE_RANKED
);
67 if (!empty($param->sql
)) {
70 $sql = "SELECT courseid,".$param->fields
." FROM ".$CFG->prefix
.'stats_'.$param->table
71 ." WHERE timeend >= ".$param->timeafter
.' AND stattype = \'activity\''
72 ." GROUP BY courseid "
74 ." ORDER BY ".$param->orderby
;
78 $courses = get_records_sql($sql, 0, $numcourses);
80 if (empty($courses)) {
81 notify(get_string('statsnodata'));echo '</td></tr></table>';echo '<p>after notify</p>';
84 if (empty($CFG->gdversion
)) {
85 echo '<div class="boxaligncenter">(' . get_string("gdneed") .')</div>';
87 echo '<div class="boxaligncenter"><img alt="'.get_string('courseoverviewgraph').'" src="'.$CFG->wwwroot
.'/'.$CFG->admin
.'/report/courseoverview/reportsgraph.php?time='.$time.'&report='.$report.'&numcourses='.$numcourses.'" /></div>';
90 $table = new StdClass
;
91 $table->align
= array('left','center','center','center');
92 $table->head
= array(get_string('course'),$param->line1
);
93 if (!empty($param->line2
)) {
94 $table->head
[] = $param->line2
;
96 if (!empty($param->line3
)) {
97 $table->head
[] = $param->line3
;
100 foreach ($courses as $c) {
102 $a[] = '<a href="'.$CFG->wwwroot
.'/course/view.php?id='.$c->courseid
.'">'.get_field('course','shortname','id',$c->courseid
).'</a>';
105 if (isset($c->line2
)) {
108 if (isset($c->line3
)) {
109 $a[] = round($c->line3
,2);
116 admin_externalpage_print_footer();