Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / admin / report / courseoverview / reportsgraph.php
blob89973d4952338fba3b26990c333c0b6041be0151
1 <?php // $Id$
3 require_once('../../../config.php');
4 require_once($CFG->dirroot.'/lib/statslib.php');
5 require_once($CFG->dirroot.'/lib/graphlib.php');
7 $report = required_param('report', PARAM_INT);
8 $time = required_param('time', PARAM_INT);
9 $numcourses = required_param('numcourses', PARAM_INT);
11 require_login();
13 require_capability('moodle/site:viewreports', get_context_instance(CONTEXT_SYSTEM, SITEID));
15 stats_check_uptodate($course->id);
17 $param = stats_get_parameters($time,$report,SITEID,STATS_MODE_RANKED);
19 if (!empty($param->sql)) {
20 $sql = $param->sql;
21 } else {
22 $sql = "SELECT courseid,".$param->fields." FROM ".$CFG->prefix.'stats_'.$param->table
23 ." WHERE timeend >= ".$param->timeafter.' AND stattype = \'activity\''
24 ." GROUP BY courseid "
25 .$param->extras
26 ." ORDER BY ".$param->orderby;
29 $courses = get_records_sql($sql, 0, $numcourses);
31 if (empty($courses)) {
32 error(get_string('statsnodata'),$CFG->wwwroot.'/'.$CFG->admin.'/report/course/index.php');
36 $graph = new graph(750,400);
38 $graph->parameter['legend'] = 'outside-right';
39 $graph->parameter['legend_size'] = 10;
40 $graph->parameter['x_axis_angle'] = 90;
41 $graph->parameter['title'] = false; // moodle will do a nicer job.
42 $graph->y_tick_labels = null;
43 $graph->offset_relation = null;
44 if ($report != STATS_REPORT_ACTIVE_COURSES) {
45 $graph->parameter['y_decimal_left'] = 2;
48 foreach ($courses as $c) {
49 $graph->x_data[] = get_field('course','shortname','id',$c->courseid);
50 $graph->y_data['bar1'][] = $c->{$param->graphline};
52 $graph->y_order = array('bar1');
53 $graph->y_format['bar1'] = array('colour' => 'blue','bar' => 'fill','legend' => $param->{$param->graphline});
55 $graph->draw_stack();