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', context_system
::instance())) {
36 redirect("$CFG->wwwroot/$CFG->admin/search.php?query=enablestats", 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 html_writer
::start_tag('form', array('action' => 'index.php', 'method' => 'post'));
72 echo html_writer
::start_tag('div');
74 $table = new html_table();
76 $table->align
= array('left','left','left','left','left','left');
78 $reporttypemenu = html_writer
::label(get_string('statsreporttype'), 'menureport', false, array('class' => 'accesshide'));
79 $reporttypemenu .= html_writer
::select($reportoptions,'report',$report, false);
80 $timeoptionsmenu = html_writer
::label(get_string('time'), 'menutime', false, array('class' => 'accesshide'));
81 $timeoptionsmenu .= html_writer
::select($timeoptions,'time',$time, false);
83 $table->data
[] = array(get_string('statsreporttype'),$reporttypemenu,
84 get_string('statstimeperiod'),$timeoptionsmenu,
85 html_writer
::label(get_string('numberofcourses'), 'numcourses', false, array('class' => 'accesshide')) .
86 html_writer
::empty_tag('input', array('type' => 'text', 'id' => 'numcourses', 'name' => 'numcourses', 'size' => '3', 'maxlength' => '2', 'value' => $numcourses)),
87 html_writer
::empty_tag('input', array('type' => 'submit', 'value' => get_string('view'))));
89 echo html_writer
::table($table);
90 echo html_writer
::end_tag('div');
91 echo html_writer
::end_tag('form');
93 echo $OUTPUT->heading($reportoptions[$report]);
96 if (!empty($report) && !empty($time)) {
97 $param = stats_get_parameters($time,$report,SITEID
,STATS_MODE_RANKED
);
98 if (!empty($param->sql
)) {
101 $sql = "SELECT courseid,".$param->fields
."
102 FROM {".'stats_'.$param->table
."}
103 WHERE timeend >= $param->timeafter AND stattype = 'activity' AND roleid = 0
106 ORDER BY $param->orderby";
109 $courses = $DB->get_records_sql($sql, $param->params
, 0, $numcourses);
111 if (empty($courses)) {
112 echo $OUTPUT->notification(get_string('statsnodata'));
113 echo '</td></tr></table>';
116 echo '<div class="graph"><img alt="'.get_string('courseoverviewgraph').'" src="'.$CFG->wwwroot
.'/report/courseoverview/reportsgraph.php?time='.$time.'&report='.$report.'&numcourses='.$numcourses.'" /></div>';
118 $table = new html_table();
119 $table->align
= array('left','center','center','center');
120 $table->head
= array(get_string('course'),$param->line1
);
121 if (!empty($param->line2
)) {
122 $table->head
[] = $param->line2
;
124 if (!empty($param->line3
)) {
125 $table->head
[] = $param->line3
;
128 foreach ($courses as $c) {
130 $a[] = '<a href="'.$CFG->wwwroot
.'/course/view.php?id='.$c->courseid
.'">'.$DB->get_field('course', 'shortname', array('id'=>$c->courseid
)).'</a>';
133 if (isset($c->line2
)) {
136 if (isset($c->line3
)) {
137 $a[] = round($c->line3
,2);
141 echo html_writer
::table($table);
144 echo $OUTPUT->footer();