|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00026 require_once('../../config.php'); 00027 require_once($CFG->dirroot.'/lib/statslib.php'); 00028 require_once($CFG->libdir.'/adminlib.php'); 00029 00030 $report = optional_param('report', STATS_REPORT_ACTIVE_COURSES, PARAM_INT); 00031 $time = optional_param('time', 0, PARAM_INT); 00032 $numcourses = optional_param('numcourses', 20, PARAM_INT); 00033 00034 if (empty($CFG->enablestats)) { 00035 if (has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { 00036 redirect("$CFG->wwwroot/$CFG->admin/settings.php?section=stats", get_string('mustenablestats', 'admin'), 3); 00037 } else { 00038 print_error('statsdisable'); 00039 } 00040 } 00041 00042 admin_externalpage_setup('reportcourseoverview', '', null, '', array('pagelayout'=>'report')); 00043 echo $OUTPUT->header(); 00044 00045 $course = get_site(); 00046 stats_check_uptodate($course->id); 00047 00048 $strreports = get_string('reports'); 00049 $strcourseoverview = get_string('courseoverview'); 00050 00051 $reportoptions = stats_get_report_options($course->id,STATS_MODE_RANKED); 00052 00053 $earliestday = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_daily}'); 00054 $earliestweek = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_weekly}'); 00055 $earliestmonth = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_monthly}'); 00056 00057 if (empty($earliestday)) $earliestday = time(); 00058 if (empty($earliestweek)) $earliestweek = time(); 00059 if (empty($earliestmonth)) $earliestmonth = time(); 00060 00061 $now = stats_get_base_daily(); 00062 $lastweekend = stats_get_base_weekly(); 00063 $lastmonthend = stats_get_base_monthly(); 00064 00065 $timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth); 00066 00067 if (empty($timeoptions)) { 00068 print_error('nostatstodisplay', 'error', $CFG->wwwroot.'/course/view.php?id='.$course->id); 00069 } 00070 00071 echo '<form action="index.php" method="post">'."\n"; 00072 echo '<div>'; 00073 00074 $table = new html_table(); 00075 $table->width = '*'; 00076 $table->align = array('left','left','left','left','left','left'); 00077 00078 $reporttypemenu = html_writer::select($reportoptions,'report',$report, false); 00079 $timeoptionsmenu = html_writer::select($timeoptions,'time',$time, false); 00080 00081 $table->data[] = array(get_string('statsreporttype'),$reporttypemenu, 00082 get_string('statstimeperiod'),$timeoptionsmenu, 00083 '<input type="text" name="numcourses" size="3" maxlength="2" value="'.$numcourses.'" />', 00084 '<input type="submit" value="'.get_string('view').'" />') ; 00085 00086 echo html_writer::table($table); 00087 echo '</div>'; 00088 echo '</form>'; 00089 00090 echo $OUTPUT->heading($reportoptions[$report]); 00091 00092 00093 if (!empty($report) && !empty($time)) { 00094 $param = stats_get_parameters($time,$report,SITEID,STATS_MODE_RANKED); 00095 if (!empty($param->sql)) { 00096 $sql = $param->sql; 00097 } else { 00098 $sql = "SELECT courseid,".$param->fields." 00099 FROM {".'stats_'.$param->table."} 00100 WHERE timeend >= $param->timeafter AND stattype = 'activity' AND roleid = 0 00101 GROUP BY courseid 00102 $param->extras 00103 ORDER BY $param->orderby"; 00104 } 00105 00106 $courses = $DB->get_records_sql($sql, $param->params, 0, $numcourses); 00107 00108 if (empty($courses)) { 00109 echo $OUTPUT->notification(get_string('statsnodata')); 00110 echo '</td></tr></table>'; 00111 00112 } else { 00113 if (empty($CFG->gdversion)) { 00114 echo '<div class="graph">(' . get_string("gdneed") .')</div>'; 00115 } else { 00116 echo '<div class="graph"><img alt="'.get_string('courseoverviewgraph').'" src="'.$CFG->wwwroot.'/report/courseoverview/reportsgraph.php?time='.$time.'&report='.$report.'&numcourses='.$numcourses.'" /></div>'; 00117 } 00118 00119 $table = new html_table(); 00120 $table->align = array('left','center','center','center'); 00121 $table->head = array(get_string('course'),$param->line1); 00122 if (!empty($param->line2)) { 00123 $table->head[] = $param->line2; 00124 } 00125 if (!empty($param->line3)) { 00126 $table->head[] = $param->line3; 00127 } 00128 00129 foreach ($courses as $c) { 00130 $a = array(); 00131 $a[] = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$c->courseid.'">'.$DB->get_field('course', 'shortname', array('id'=>$c->courseid)).'</a>'; 00132 00133 $a[] = $c->line1; 00134 if (isset($c->line2)) { 00135 $a[] = $c->line2; 00136 } 00137 if (isset($c->line3)) { 00138 $a[] = round($c->line3,2); 00139 } 00140 $table->data[] = $a; 00141 } 00142 echo html_writer::table($table); 00143 } 00144 } 00145 echo $OUTPUT->footer();