| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: report.php,v 1.17.2.4 2008/06/27 03:34:27 moodler Exp $ 2 3 if (!defined('MOODLE_INTERNAL')) { 4 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page 5 } 6 7 $courses = get_courses('all','c.shortname','c.id,c.shortname,c.fullname'); 8 $courseoptions = array(); 9 10 foreach ($courses as $c) { 11 $context = get_context_instance(CONTEXT_COURSE, $c->id); 12 13 if (has_capability('moodle/site:viewreports', $context)) { 14 $courseoptions[$c->id] = $c->shortname; 15 } 16 } 17 18 $reportoptions = stats_get_report_options($course->id, $mode); 19 $timeoptions = report_stats_timeoptions($mode); 20 if (empty($timeoptions)) { 21 print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/view.php?id='.$course->id); 22 } 23 24 $table->width = 'auto'; 25 26 if ($mode == STATS_MODE_DETAILED) { 27 $param = stats_get_parameters($time,null,$course->id,$mode); // we only care about the table and the time string (if we have time) 28 29 $sql = 'SELECT DISTINCT s.userid, u.firstname, u.lastname, u.idnumber 30 FROM '.$CFG->prefix.'stats_user_'.$param->table.' s 31 JOIN '.$CFG->prefix.'user u ON u.id = s.userid 32 WHERE courseid = '.$course->id 33 . ((!empty($param->stattype)) ? ' AND stattype = \''.$param->stattype.'\'' : '') 34 . ((!empty($time)) ? ' AND timeend >= '.$param->timeafter : '') 35 .' ORDER BY u.lastname, u.firstname ASC'; 36 37 if (!$us = get_records_sql($sql)) { 38 error('Cannot enter detailed view: No users found for this course.'); 39 } 40 41 foreach ($us as $u) { 42 $users[$u->userid] = fullname($u, true); 43 } 44 45 $table->align = array('left','left','left','left','left','left','left','left'); 46 $table->data[] = array(get_string('course'),choose_from_menu($courseoptions,'course',$course->id,'','','',true), 47 get_string('users'),choose_from_menu($users,'userid',$userid,'','','',true), 48 get_string('statsreporttype'),choose_from_menu($reportoptions,'report',($report == 5) ? $report.$roleid : $report,'','','',true), 49 get_string('statstimeperiod'),choose_from_menu($timeoptions,'time',$time,'','','',true), 50 '<input type="submit" value="'.get_string('view').'" />') ; 51 } else if ($mode == STATS_MODE_RANKED) { 52 $table->align = array('left','left','left','left','left','left'); 53 $table->data[] = array(get_string('statsreporttype'),choose_from_menu($reportoptions,'report',($report == 5) ? $report.$roleid : $report,'','','',true), 54 get_string('statstimeperiod'),choose_from_menu($timeoptions,'time',$time,'','','',true), 55 '<input type="submit" value="'.get_string('view').'" />') ; 56 } else if ($mode == STATS_MODE_GENERAL) { 57 $table->align = array('left','left','left','left','left','left','left'); 58 $table->data[] = array(get_string('course'),choose_from_menu($courseoptions,'course',$course->id,'','','',true), 59 get_string('statsreporttype'),choose_from_menu($reportoptions,'report',($report == 5) ? $report.$roleid : $report,'','','',true), 60 get_string('statstimeperiod'),choose_from_menu($timeoptions,'time',$time,'','','',true), 61 '<input type="submit" value="'.get_string('view').'" />') ; 62 } 63 64 echo '<form action="index.php" method="post">'."\n" 65 .'<div>'."\n" 66 .'<input type="hidden" name="mode" value="'.$mode.'" />'."\n"; 67 68 print_table($table); 69 70 echo '</div>'; 71 echo '</form>'; 72 73 if (!empty($report) && !empty($time)) { 74 if ($report == STATS_REPORT_LOGINS && $course->id != SITEID) { 75 error('This type of report is only available for the site course'); 76 } 77 78 $param = stats_get_parameters($time,$report,$course->id,$mode); 79 80 if ($mode == STATS_MODE_DETAILED) { 81 $param->table = 'user_'.$param->table; 82 } 83 84 if (!empty($param->sql)) { 85 $sql = $param->sql; 86 } else { 87 $sql = 'SELECT '.((empty($param->fieldscomplete)) ? 'id,roleid,timeend,' : '').$param->fields 88 .' FROM '.$CFG->prefix.'stats_'.$param->table.' WHERE ' 89 .(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ') 90 .((!empty($userid)) ? ' userid = '.$userid.' AND ' : '') 91 .((!empty($roleid)) ? ' roleid = '.$roleid.' AND ' : '') 92 . ((!empty($param->stattype)) ? ' stattype = \''.$param->stattype.'\' AND ' : '') 93 .' timeend >= '.$param->timeafter 94 .' '.$param->extras 95 .' ORDER BY timeend DESC'; 96 } 97 98 $stats = get_records_sql($sql); 99 100 if (empty($stats)) { 101 notify(get_string('statsnodata')); 102 103 } else { 104 105 $stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2))); 106 107 print_heading(format_string($course->shortname).' - '.get_string('statsreport'.$report) 108 .((!empty($user)) ? ' '.get_string('statsreportforuser').' ' .fullname($user,true) : '') 109 .((!empty($roleid)) ? ' '.get_field('role','name','id',$roleid) : '')); 110 111 112 if (empty($CFG->gdversion)) { 113 echo "(".get_string("gdneed").")"; 114 } else { 115 if ($mode == STATS_MODE_DETAILED) { 116 echo '<div class="graph"><img src="'.$CFG->wwwroot.'/course/report/stats/graph.php?mode='.$mode.'&course='.$course->id.'&time='.$time.'&report='.$report.'&userid='.$userid.'" alt="'.get_string('statisticsgraph').'" /></div'; 117 } else { 118 echo '<div class="graph"><img src="'.$CFG->wwwroot.'/course/report/stats/graph.php?mode='.$mode.'&course='.$course->id.'&time='.$time.'&report='.$report.'&roleid='.$roleid.'" alt="'.get_string('statisticsgraph').'" /></div>'; 119 } 120 } 121 122 $table = new StdClass; 123 $table->align = array('left','center','center','center'); 124 $param->table = str_replace('user_','',$param->table); 125 switch ($param->table) { 126 case 'daily' : $period = get_string('day'); break; 127 case 'weekly' : $period = get_string('week'); break; 128 case 'monthly': $period = get_string('month', 'form'); break; 129 default : $period = ''; 130 } 131 $table->head = array(get_string('periodending','moodle',$period)); 132 if (empty($param->crosstab)) { 133 $table->head[] = $param->line1; 134 if (!empty($param->line2)) { 135 $table->head[] = $param->line2; 136 } 137 } 138 if (empty($param->crosstab)) { 139 foreach ($stats as $stat) { 140 $a = array(userdate($stat->timeend-(60*60*24),get_string('strftimedate'),$CFG->timezone),$stat->line1); 141 if (isset($stat->line2)) { 142 $a[] = $stat->line2; 143 } 144 if (empty($CFG->loglifetime) || ($stat->timeend-(60*60*24)) >= (time()-60*60*24*$CFG->loglifetime)) { 145 $a[] = '<a href="'.$CFG->wwwroot.'/course/report/log/index.php?id='. 146 $course->id.'&chooselog=1&showusers=1&showcourses=1&user=' 147 .$userid.'&date='.usergetmidnight($stat->timeend-(60*60*24)).'">' 148 .get_string('course').' ' .get_string('logs').'</a> '; 149 } 150 $table->data[] = $a; 151 } 152 } else { 153 $data = array(); 154 $roles = array(); 155 $times = array(); 156 $missedlines = array(); 157 $rolenames = get_all_roles(); 158 foreach ($rolenames as $r) { 159 $rolenames[$r->id] = $r->name; 160 } 161 $rolenames = role_fix_names($rolenames, get_context_instance(CONTEXT_COURSE, $course->id)); 162 foreach ($stats as $stat) { 163 if (!empty($stat->zerofixed)) { 164 $missedlines[] = $stat->timeend; 165 } 166 $data[$stat->timeend][$stat->roleid] = $stat->line1; 167 if ($stat->roleid != 0) { 168 if (!array_key_exists($stat->roleid,$roles)) { 169 $roles[$stat->roleid] = $rolenames[$stat->roleid]; 170 } 171 } else { 172 if (!array_key_exists($stat->roleid,$roles)) { 173 $roles[$stat->roleid] = get_string('all'); 174 } 175 } 176 if (!array_key_exists($stat->timeend,$times)) { 177 $times[$stat->timeend] = userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone); 178 } 179 } 180 181 foreach ($data as $time => $rolesdata) { 182 if (in_array($time,$missedlines)) { 183 $rolesdata = array(); 184 foreach ($roles as $roleid => $guff) { 185 $rolesdata[$roleid] = 0; 186 } 187 } 188 else { 189 foreach (array_keys($roles) as $r) { 190 if (!array_key_exists($r, $rolesdata)) { 191 $rolesdata[$r] = 0; 192 } 193 } 194 } 195 krsort($rolesdata); 196 $row = array_merge(array($times[$time]),$rolesdata); 197 if (empty($CFG->loglifetime) || ($stat->timeend-(60*60*24)) >= (time()-60*60*24*$CFG->loglifetime)) { 198 $row[] = '<a href="'.$CFG->wwwroot.'/course/report/log/index.php?id=' 199 .$course->id.'&chooselog=1&showusers=1&showcourses=1&user='.$userid 200 .'&date='.usergetmidnight($time-(60*60*24)).'">' 201 .get_string('course').' ' .get_string('logs').'</a> '; 202 } 203 $table->data[] = $row; 204 } 205 krsort($roles); 206 $table->head = array_merge($table->head,$roles); 207 } 208 $table->head[] = get_string('logs'); 209 if (!empty($lastrecord)) { 210 $lastrecord[] = $lastlink; 211 $table->data[] = $lastrecord; 212 } 213 print_table($table); 214 } 215 } 216 217 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |