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
)); // needed?
17 if (empty($CFG->enablestats
)) {
18 redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'), 3);
22 stats_check_uptodate($course->id
);
24 $strreports = get_string('reports');
25 $strcourseoverview = get_string('courseoverview');
27 $reportoptions = stats_get_report_options($course->id
,STATS_MODE_RANKED
);
29 $tableprefix = $CFG->prefix
.'stats_';
31 $earliestday = get_field_sql('SELECT timeend FROM '.$tableprefix.'daily ORDER BY timeend');
32 $earliestweek = get_field_sql('SELECT timeend FROM '.$tableprefix.'weekly ORDER BY timeend');
33 $earliestmonth = get_field_sql('SELECT timeend FROM '.$tableprefix.'monthly ORDER BY timeend');
35 if (empty($earliestday)) $earliestday = time();
36 if (empty($earliestweek)) $earliestweek = time();
37 if (empty($earliestmonth)) $earliestmonth = time();
39 $now = stats_get_base_daily();
40 $lastweekend = stats_get_base_weekly();
41 $lastmonthend = stats_get_base_monthly();
43 $timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth);
45 if (empty($timeoptions)) {
46 print_error('nostatstodisplay', "", $CFG->wwwroot
.'/course/view.php?id='.$course->id
);
49 echo '<form action="index.php" method="post">'."\n";
53 $table->align
= array('left','left','left','left','left','left');
54 $table->data
[] = array(get_string('statsreporttype'),choose_from_menu($reportoptions,'report',$report,'','','',true),
55 get_string('statstimeperiod'),choose_from_menu($timeoptions,'time',$time,'','','',true),
56 '<input type="text" name="numcourses" size="3" maxlength="2" value="'.$numcourses.'" />',
57 '<input type="submit" value="'.get_string('view').'" />') ;
63 print_heading($reportoptions[$report]);
66 if (!empty($report) && !empty($time)) {
67 $param = stats_get_parameters($time,$report,SITEID
,STATS_MODE_RANKED
);
68 if (!empty($param->sql
)) {
71 $sql = "SELECT courseid,".$param->fields
." FROM ".$CFG->prefix
.'stats_'.$param->table
72 ." WHERE timeend >= $param->timeafter AND stattype = 'activity' AND roleid = 0"
73 ." GROUP BY courseid "
75 ." ORDER BY ".$param->orderby
;
79 $courses = get_records_sql($sql, 0, $numcourses);
81 if (empty($courses)) {
82 notify(get_string('statsnodata'));echo '</td></tr></table>';echo '<p>after notify</p>';
85 if (empty($CFG->gdversion
)) {
86 echo '<div class="graph">(' . get_string("gdneed") .')</div>';
88 echo '<div class="graph"><img alt="'.get_string('courseoverviewgraph').'" src="'.$CFG->wwwroot
.'/'.$CFG->admin
.'/report/courseoverview/reportsgraph.php?time='.$time.'&report='.$report.'&numcourses='.$numcourses.'" /></div>';
91 $table = new StdClass
;
92 $table->align
= array('left','center','center','center');
93 $table->head
= array(get_string('course'),$param->line1
);
94 if (!empty($param->line2
)) {
95 $table->head
[] = $param->line2
;
97 if (!empty($param->line3
)) {
98 $table->head
[] = $param->line3
;
101 foreach ($courses as $c) {
103 $a[] = '<a href="'.$CFG->wwwroot
.'/course/view.php?id='.$c->courseid
.'">'.get_field('course','shortname','id',$c->courseid
).'</a>';
106 if (isset($c->line2
)) {
109 if (isset($c->line3
)) {
110 $a[] = round($c->line3
,2);
117 admin_externalpage_print_footer();