From: ikawhero Date: Fri, 10 Mar 2006 08:07:08 +0000 (+0000) Subject: Old admin reports is now a pluggable report type X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d33a06d554d16fdd332a69c182457bc5e427411c;p=moodle.git Old admin reports is now a pluggable report type --- diff --git a/admin/report/courseoverview/index.php b/admin/report/courseoverview/index.php new file mode 100644 index 0000000000..f97a72dfbf --- /dev/null +++ b/admin/report/courseoverview/index.php @@ -0,0 +1,118 @@ +dirroot.'/lib/statslib.php'); + + $report = optional_param('report', STATS_REPORT_ACTIVE_COURSES, PARAM_INT); + $time = optional_param('time', 0, PARAM_INT); + $numcourses = optional_param('numcourses', 20, PARAM_INT); + + if (empty($CFG->enablestats)) { + error("Stats is not enabled."); + } + + require_login(); + + if (!isadmin()) { + error("This page is for admins only"); + } + + $course = get_site(); + stats_check_uptodate($course->id); + + $strreports = get_string('reports'); + $strcourseoverview = get_string('courseoverview'); + + $strnav = ''.get_string('administration').' -> '.$strreports.' -> '.$strcourseoverview; + + $reportoptions = stats_get_report_options($course->id,STATS_MODE_RANKED); + + $tableprefix = $CFG->prefix.'stats_'; + + $earliestday = get_field_sql('SELECT timeend FROM '.$tableprefix.'daily ORDER BY timeend LIMIT 1'); + $earliestweek = get_field_sql('SELECT timeend FROM '.$tableprefix.'weekly ORDER BY timeend LIMIT 1'); + $earliestmonth = get_field_sql('SELECT timeend FROM '.$tableprefix.'monthly ORDER BY timeend LIMIT 1'); + + if (empty($earliestday)) $earliestday = time(); + if (empty($earliestweek)) $earliestweek = time(); + if (empty($earliestmonth)) $earliestmonth = time(); + + $now = stats_get_base_daily(); + $lastweekend = stats_get_base_weekly(); + $lastmonthend = stats_get_base_monthly(); + + $timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth); + + if (empty($timeoptions)) { + error(get_string('nostatstodisplay'), $CFG->wwwroot.'/course/view.php?id='.$course->id); + } + + print_header($strcourseoverview, $strcourseoverview, $strnav,'','',true,' '); + + echo '
'."\n"; + + $table->width = '*'; + + $table->align = array('left','left','left','left','left','left'); + $table->data[] = array(get_string('statsreporttype'),choose_from_menu($reportoptions,'report',$report,'','','',true), + get_string('statstimeperiod'),choose_from_menu($timeoptions,'time',$time,'','','',true), + '', + '') ; + + print_table($table); + echo '
'; + + if (!empty($report) && !empty($time)) { + $param = stats_get_parameters($time,$report,SITEID,STATS_MODE_RANKED); + + $sql = "SELECT courseid,".$param->fields." FROM ".$CFG->prefix.'stats_'.$param->table + ." WHERE timeend >= ".$param->timeafter + ." GROUP BY courseid " + .$param->extras + ." ORDER BY ".$param->orderby + ." LIMIT ".$numcourses; + + $courses = get_records_sql($sql); + + if (empty($courses)) { + error(get_string('statsnodata'),$CFG->wwwroot.'/admin/report/courseoverview/index.php'); + } + + echo '
'; + + $table = new object(); + $table->align = array('left','center','center','center'); + $table->head = array(get_string('course'),$param->line1); + if (!empty($param->line2)) { + $table->head[] = $param->line2; + } + if (!empty($param->line3)) { + $table->head[] = $param->line3; + } + + foreach ($courses as $c) { + $a = array(); + $a[] = ''.get_field('course','shortname','id',$c->courseid).''; + $a[] = print_numeric_value($c->line1); + if (isset($c->line2)) { + $a[] = print_numeric_value($c->line2); + } + if (isset($c->line3)) { + $a[] = print_numeric_value($c->line3); + } + $table->data[] = $a; + } + print_table($table); + } + + print_footer(); + +function print_numeric_value($value) { + list($whole, $decimals) = split ('[.,]', $value, 2); + if (intval($decimals) > 0) + return number_format($value,2,".",","); + else + return $value; +} + +?> diff --git a/admin/report/courseoverview/mod.php b/admin/report/courseoverview/mod.php new file mode 100644 index 0000000000..93df623484 --- /dev/null +++ b/admin/report/courseoverview/mod.php @@ -0,0 +1,11 @@ +enablestats)) { + echo ''.get_string('courseoverview').''; + } +?> + diff --git a/admin/report/courseoverview/reportsgraph.php b/admin/report/courseoverview/reportsgraph.php new file mode 100644 index 0000000000..165ee9ac85 --- /dev/null +++ b/admin/report/courseoverview/reportsgraph.php @@ -0,0 +1,54 @@ +dirroot.'/lib/statslib.php'); + require_once($CFG->dirroot.'/lib/graphlib.php'); + + $report = required_param('report', PARAM_INT); + $time = required_param('time', PARAM_INT); + $numcourses = required_param('numcourses', PARAM_INT); + + require_login(); + + if (!isadmin()) { + error("You must be an admin to use this page"); + } + + stats_check_uptodate($course->id); + + $param = stats_get_parameters($time,$report,SITEID,STATS_MODE_RANKED); + + $sql = "SELECT courseid,".$param->fields." FROM ".$CFG->prefix.'stats_'.$param->table + ." WHERE timeend >= ".$param->timeafter + ." GROUP BY courseid " + .$param->extras + ." ORDER BY ".$param->orderby + ." LIMIT ".$numcourses; + + $courses = get_records_sql($sql); + + if (empty($courses)) { + error(get_string('statsnodata'),$CFG->wwwroot.'/admin/report/course/index.php'); + } + + + $graph = new graph(750,400); + + $graph->parameter['legend'] = 'outside-right'; + $graph->parameter['legend_size'] = 10; + $graph->parameter['x_axis_angle'] = 90; + $graph->parameter['title'] = false; // moodle will do a nicer job. + if ($report != STATS_REPORT_ACTIVE_COURSES) { + $graph->parameter['y_decimal_left'] = 2; + } + + foreach ($courses as $c) { + $graph->x_data[] = get_field('course','shortname','id',$c->courseid); + $graph->y_data['bar1'][] = $c->{$param->graphline}; + } + $graph->y_order = array('bar1'); + $graph->y_format['bar1'] = array('colour' => 'blue','bar' => 'fill','legend' => $param->{$param->graphline}); + + $graph->draw_stack(); + +?>