2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Course overview report
21 * @subpackage courseoverview
22 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once('../../config.php');
27 require_once($CFG->dirroot
.'/lib/statslib.php');
28 require_once($CFG->libdir
.'/adminlib.php');
30 $report = optional_param('report', STATS_REPORT_ACTIVE_COURSES
, PARAM_INT
);
31 $time = optional_param('time', 0, PARAM_INT
);
32 $numcourses = optional_param('numcourses', 20, PARAM_INT
);
34 if (empty($CFG->enablestats
)) {
35 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM
))) {
36 redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'), 3);
38 print_error('statsdisable');
42 admin_externalpage_setup('reportcourseoverview', '', null, '', array('pagelayout'=>'report'));
43 echo $OUTPUT->header();
46 stats_check_uptodate($course->id
);
48 $strreports = get_string('reports');
49 $strcourseoverview = get_string('courseoverview');
51 $reportoptions = stats_get_report_options($course->id
,STATS_MODE_RANKED
);
53 $earliestday = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_daily}');
54 $earliestweek = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_weekly}');
55 $earliestmonth = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_monthly}');
57 if (empty($earliestday)) $earliestday = time();
58 if (empty($earliestweek)) $earliestweek = time();
59 if (empty($earliestmonth)) $earliestmonth = time();
61 $now = stats_get_base_daily();
62 $lastweekend = stats_get_base_weekly();
63 $lastmonthend = stats_get_base_monthly();
65 $timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth);
67 if (empty($timeoptions)) {
68 print_error('nostatstodisplay', 'error', $CFG->wwwroot
.'/course/view.php?id='.$course->id
);
71 echo '<form action="index.php" method="post">'."\n";
74 $table = new html_table();
76 $table->align
= array('left','left','left','left','left','left');
78 $reporttypemenu = html_writer
::select($reportoptions,'report',$report, false);
79 $timeoptionsmenu = html_writer
::select($timeoptions,'time',$time, false);
81 $table->data
[] = array(get_string('statsreporttype'),$reporttypemenu,
82 get_string('statstimeperiod'),$timeoptionsmenu,
83 '<input type="text" name="numcourses" size="3" maxlength="2" value="'.$numcourses.'" />',
84 '<input type="submit" value="'.get_string('view').'" />') ;
86 echo html_writer
::table($table);
90 echo $OUTPUT->heading($reportoptions[$report]);
93 if (!empty($report) && !empty($time)) {
94 $param = stats_get_parameters($time,$report,SITEID
,STATS_MODE_RANKED
);
95 if (!empty($param->sql
)) {
98 $sql = "SELECT courseid,".$param->fields
."
99 FROM {".'stats_'.$param->table
."}
100 WHERE timeend >= $param->timeafter AND stattype = 'activity' AND roleid = 0
103 ORDER BY $param->orderby";
106 $courses = $DB->get_records_sql($sql, $param->params
, 0, $numcourses);
108 if (empty($courses)) {
109 echo $OUTPUT->notification(get_string('statsnodata'));
110 echo '</td></tr></table>';
113 if (empty($CFG->gdversion
)) {
114 echo '<div class="graph">(' . get_string("gdneed") .')</div>';
116 echo '<div class="graph"><img alt="'.get_string('courseoverviewgraph').'" src="'.$CFG->wwwroot
.'/report/courseoverview/reportsgraph.php?time='.$time.'&report='.$report.'&numcourses='.$numcourses.'" /></div>';
119 $table = new html_table();
120 $table->align
= array('left','center','center','center');
121 $table->head
= array(get_string('course'),$param->line1
);
122 if (!empty($param->line2
)) {
123 $table->head
[] = $param->line2
;
125 if (!empty($param->line3
)) {
126 $table->head
[] = $param->line3
;
129 foreach ($courses as $c) {
131 $a[] = '<a href="'.$CFG->wwwroot
.'/course/view.php?id='.$c->courseid
.'">'.$DB->get_field('course', 'shortname', array('id'=>$c->courseid
)).'</a>';
134 if (isset($c->line2
)) {
137 if (isset($c->line3
)) {
138 $a[] = round($c->line3
,2);
142 echo html_writer
::table($table);
145 echo $OUTPUT->footer();