2008-06-27 03:35:22 +00:00
|
|
|
<?php // $Id$
|
|
|
|
|
|
|
|
if (!defined('MOODLE_INTERNAL')) {
|
|
|
|
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
|
|
|
}
|
2006-06-06 04:15:04 +00:00
|
|
|
|
|
|
|
$courses = get_courses('all','c.shortname','c.id,c.shortname,c.fullname');
|
|
|
|
$courseoptions = array();
|
|
|
|
|
|
|
|
foreach ($courses as $c) {
|
2006-08-25 08:27:28 +00:00
|
|
|
$context = get_context_instance(CONTEXT_COURSE, $c->id);
|
|
|
|
|
2008-11-29 14:22:10 +00:00
|
|
|
if (has_capability('coursereport/stats:view', $context)) {
|
2006-06-06 04:15:04 +00:00
|
|
|
$courseoptions[$c->id] = $c->shortname;
|
|
|
|
}
|
|
|
|
}
|
2008-02-23 12:26:35 +00:00
|
|
|
|
2006-06-06 04:15:04 +00:00
|
|
|
$reportoptions = stats_get_report_options($course->id, $mode);
|
|
|
|
$timeoptions = report_stats_timeoptions($mode);
|
2006-09-23 08:52:12 +00:00
|
|
|
if (empty($timeoptions)) {
|
2008-04-04 02:54:20 +00:00
|
|
|
print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/view.php?id='.$course->id);
|
2006-09-23 08:52:12 +00:00
|
|
|
}
|
|
|
|
|
2008-02-16 18:33:50 +00:00
|
|
|
$table->width = 'auto';
|
2006-06-06 04:15:04 +00:00
|
|
|
|
|
|
|
if ($mode == STATS_MODE_DETAILED) {
|
2006-09-24 22:13:31 +00:00
|
|
|
$param = stats_get_parameters($time,null,$course->id,$mode); // we only care about the table and the time string (if we have time)
|
|
|
|
|
2008-05-31 14:35:58 +00:00
|
|
|
//TODO: lceanup this ugly mess
|
2008-02-23 12:26:35 +00:00
|
|
|
$sql = 'SELECT DISTINCT s.userid, u.firstname, u.lastname, u.idnumber
|
2008-06-05 20:35:28 +00:00
|
|
|
FROM {stats_user_'.$param->table.'} s
|
|
|
|
JOIN {user} u ON u.id = s.userid
|
2006-09-24 22:13:31 +00:00
|
|
|
WHERE courseid = '.$course->id
|
|
|
|
. ((!empty($param->stattype)) ? ' AND stattype = \''.$param->stattype.'\'' : '')
|
|
|
|
. ((!empty($time)) ? ' AND timeend >= '.$param->timeafter : '')
|
2008-02-16 18:33:50 +00:00
|
|
|
.' ORDER BY u.lastname, u.firstname ASC';
|
2008-02-23 12:26:35 +00:00
|
|
|
|
2008-05-31 14:35:58 +00:00
|
|
|
if (!$us = $DB->get_records_sql($sql, $param->params)) {
|
2008-05-13 06:15:20 +00:00
|
|
|
print_error('nousers');
|
2006-06-06 04:15:04 +00:00
|
|
|
}
|
|
|
|
|
2006-09-24 22:13:31 +00:00
|
|
|
foreach ($us as $u) {
|
2008-02-16 18:33:50 +00:00
|
|
|
$users[$u->userid] = fullname($u, true);
|
2006-06-06 04:15:04 +00:00
|
|
|
}
|
2008-02-23 12:26:35 +00:00
|
|
|
|
2006-06-06 04:15:04 +00:00
|
|
|
$table->align = array('left','left','left','left','left','left','left','left');
|
|
|
|
$table->data[] = array(get_string('course'),choose_from_menu($courseoptions,'course',$course->id,'','','',true),
|
|
|
|
get_string('users'),choose_from_menu($users,'userid',$userid,'','','',true),
|
2006-09-23 08:52:12 +00:00
|
|
|
get_string('statsreporttype'),choose_from_menu($reportoptions,'report',($report == 5) ? $report.$roleid : $report,'','','',true),
|
2006-06-06 04:15:04 +00:00
|
|
|
get_string('statstimeperiod'),choose_from_menu($timeoptions,'time',$time,'','','',true),
|
|
|
|
'<input type="submit" value="'.get_string('view').'" />') ;
|
2006-09-24 07:13:33 +00:00
|
|
|
} else if ($mode == STATS_MODE_RANKED) {
|
|
|
|
$table->align = array('left','left','left','left','left','left');
|
|
|
|
$table->data[] = array(get_string('statsreporttype'),choose_from_menu($reportoptions,'report',($report == 5) ? $report.$roleid : $report,'','','',true),
|
|
|
|
get_string('statstimeperiod'),choose_from_menu($timeoptions,'time',$time,'','','',true),
|
|
|
|
'<input type="submit" value="'.get_string('view').'" />') ;
|
|
|
|
} else if ($mode == STATS_MODE_GENERAL) {
|
2006-06-06 04:15:04 +00:00
|
|
|
$table->align = array('left','left','left','left','left','left','left');
|
|
|
|
$table->data[] = array(get_string('course'),choose_from_menu($courseoptions,'course',$course->id,'','','',true),
|
2006-09-23 08:52:12 +00:00
|
|
|
get_string('statsreporttype'),choose_from_menu($reportoptions,'report',($report == 5) ? $report.$roleid : $report,'','','',true),
|
2006-06-06 04:15:04 +00:00
|
|
|
get_string('statstimeperiod'),choose_from_menu($timeoptions,'time',$time,'','','',true),
|
|
|
|
'<input type="submit" value="'.get_string('view').'" />') ;
|
|
|
|
}
|
|
|
|
|
2007-01-15 08:15:04 +00:00
|
|
|
echo '<form action="index.php" method="post">'."\n"
|
2008-02-16 18:33:50 +00:00
|
|
|
.'<div>'."\n"
|
2007-01-15 08:15:04 +00:00
|
|
|
.'<input type="hidden" name="mode" value="'.$mode.'" />'."\n";
|
2006-06-06 04:15:04 +00:00
|
|
|
|
|
|
|
print_table($table);
|
2007-01-15 08:15:04 +00:00
|
|
|
|
2008-02-16 18:33:50 +00:00
|
|
|
echo '</div>';
|
2006-06-06 04:15:04 +00:00
|
|
|
echo '</form>';
|
|
|
|
|
|
|
|
if (!empty($report) && !empty($time)) {
|
|
|
|
if ($report == STATS_REPORT_LOGINS && $course->id != SITEID) {
|
2008-05-13 06:15:20 +00:00
|
|
|
print_error('reportnotavailable');
|
2006-06-06 04:15:04 +00:00
|
|
|
}
|
2008-02-16 18:33:50 +00:00
|
|
|
|
2006-06-06 04:15:04 +00:00
|
|
|
$param = stats_get_parameters($time,$report,$course->id,$mode);
|
2006-09-23 08:52:12 +00:00
|
|
|
|
2006-06-06 04:15:04 +00:00
|
|
|
if ($mode == STATS_MODE_DETAILED) {
|
|
|
|
$param->table = 'user_'.$param->table;
|
|
|
|
}
|
2008-02-16 18:33:50 +00:00
|
|
|
|
2006-09-24 07:13:33 +00:00
|
|
|
if (!empty($param->sql)) {
|
|
|
|
$sql = $param->sql;
|
|
|
|
} else {
|
2008-05-31 14:35:58 +00:00
|
|
|
//TODO: lceanup this ugly mess
|
2006-09-24 07:13:33 +00:00
|
|
|
$sql = 'SELECT '.((empty($param->fieldscomplete)) ? 'id,roleid,timeend,' : '').$param->fields
|
2008-06-06 14:11:20 +00:00
|
|
|
.' FROM {stats_'.$param->table.'} WHERE '
|
2006-09-24 07:13:33 +00:00
|
|
|
.(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ')
|
|
|
|
.((!empty($userid)) ? ' userid = '.$userid.' AND ' : '')
|
|
|
|
.((!empty($roleid)) ? ' roleid = '.$roleid.' AND ' : '')
|
|
|
|
. ((!empty($param->stattype)) ? ' stattype = \''.$param->stattype.'\' AND ' : '')
|
|
|
|
.' timeend >= '.$param->timeafter
|
|
|
|
.' '.$param->extras
|
|
|
|
.' ORDER BY timeend DESC';
|
|
|
|
}
|
2006-09-24 03:15:52 +00:00
|
|
|
|
2008-05-31 14:35:58 +00:00
|
|
|
$stats = $DB->get_records_sql($sql, $params);
|
2006-06-06 04:15:04 +00:00
|
|
|
|
|
|
|
if (empty($stats)) {
|
2006-09-24 05:53:45 +00:00
|
|
|
notify(get_string('statsnodata'));
|
2006-06-06 04:15:04 +00:00
|
|
|
|
|
|
|
} else {
|
2006-09-24 05:53:45 +00:00
|
|
|
|
|
|
|
$stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)));
|
|
|
|
|
2007-02-28 06:25:22 +00:00
|
|
|
print_heading(format_string($course->shortname).' - '.get_string('statsreport'.$report)
|
2006-09-24 05:53:45 +00:00
|
|
|
.((!empty($user)) ? ' '.get_string('statsreportforuser').' ' .fullname($user,true) : '')
|
2008-06-02 21:39:23 +00:00
|
|
|
.((!empty($roleid)) ? ' '.$DB->get_field('role','name', array('id'=>$roleid)) : ''));
|
2006-09-24 05:53:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (empty($CFG->gdversion)) {
|
|
|
|
echo "(".get_string("gdneed").")";
|
2006-06-06 04:15:04 +00:00
|
|
|
} else {
|
2006-09-24 05:53:45 +00:00
|
|
|
if ($mode == STATS_MODE_DETAILED) {
|
2008-02-16 18:33:50 +00:00
|
|
|
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';
|
2006-09-24 05:53:45 +00:00
|
|
|
} else {
|
2008-02-16 18:33:50 +00:00
|
|
|
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>';
|
2006-09-24 05:53:45 +00:00
|
|
|
}
|
2006-06-06 04:15:04 +00:00
|
|
|
}
|
|
|
|
|
2006-09-24 05:53:45 +00:00
|
|
|
$table = new StdClass;
|
|
|
|
$table->align = array('left','center','center','center');
|
|
|
|
$param->table = str_replace('user_','',$param->table);
|
2008-02-16 18:33:50 +00:00
|
|
|
switch ($param->table) {
|
|
|
|
case 'daily' : $period = get_string('day'); break;
|
|
|
|
case 'weekly' : $period = get_string('week'); break;
|
|
|
|
case 'monthly': $period = get_string('month', 'form'); break;
|
|
|
|
default : $period = '';
|
|
|
|
}
|
|
|
|
$table->head = array(get_string('periodending','moodle',$period));
|
2006-09-24 05:53:45 +00:00
|
|
|
if (empty($param->crosstab)) {
|
|
|
|
$table->head[] = $param->line1;
|
|
|
|
if (!empty($param->line2)) {
|
2008-02-23 12:26:35 +00:00
|
|
|
$table->head[] = $param->line2;
|
2006-09-23 08:52:12 +00:00
|
|
|
}
|
2006-09-23 12:10:42 +00:00
|
|
|
}
|
2006-09-24 05:53:45 +00:00
|
|
|
if (empty($param->crosstab)) {
|
|
|
|
foreach ($stats as $stat) {
|
|
|
|
$a = array(userdate($stat->timeend-(60*60*24),get_string('strftimedate'),$CFG->timezone),$stat->line1);
|
|
|
|
if (isset($stat->line2)) {
|
|
|
|
$a[] = $stat->line2;
|
2006-09-24 03:15:52 +00:00
|
|
|
}
|
2006-09-24 05:53:45 +00:00
|
|
|
if (empty($CFG->loglifetime) || ($stat->timeend-(60*60*24)) >= (time()-60*60*24*$CFG->loglifetime)) {
|
2008-11-30 21:33:58 +00:00
|
|
|
if (has_capability('coursereport/log:view', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
|
|
|
$a[] = '<a href="'.$CFG->wwwroot.'/course/report/log/index.php?id='.
|
|
|
|
$course->id.'&chooselog=1&showusers=1&showcourses=1&user='
|
|
|
|
.$userid.'&date='.usergetmidnight($stat->timeend-(60*60*24)).'">'
|
|
|
|
.get_string('course').' ' .get_string('logs').'</a> ';
|
|
|
|
} else {
|
|
|
|
$a[] = '';
|
|
|
|
}
|
2006-09-24 05:53:45 +00:00
|
|
|
}
|
|
|
|
$table->data[] = $a;
|
2006-09-23 12:10:42 +00:00
|
|
|
}
|
2006-09-24 05:53:45 +00:00
|
|
|
} else {
|
|
|
|
$data = array();
|
|
|
|
$roles = array();
|
|
|
|
$times = array();
|
|
|
|
$missedlines = array();
|
2008-02-23 12:26:35 +00:00
|
|
|
$rolenames = get_all_roles();
|
|
|
|
foreach ($rolenames as $r) {
|
|
|
|
$rolenames[$r->id] = $r->name;
|
|
|
|
}
|
|
|
|
$rolenames = role_fix_names($rolenames, get_context_instance(CONTEXT_COURSE, $course->id));
|
2006-09-24 05:53:45 +00:00
|
|
|
foreach ($stats as $stat) {
|
|
|
|
if (!empty($stat->zerofixed)) {
|
|
|
|
$missedlines[] = $stat->timeend;
|
|
|
|
}
|
|
|
|
$data[$stat->timeend][$stat->roleid] = $stat->line1;
|
|
|
|
if ($stat->roleid != 0) {
|
|
|
|
if (!array_key_exists($stat->roleid,$roles)) {
|
2008-02-23 12:26:35 +00:00
|
|
|
$roles[$stat->roleid] = $rolenames[$stat->roleid];
|
2006-09-24 03:15:52 +00:00
|
|
|
}
|
2008-02-16 18:33:50 +00:00
|
|
|
} else {
|
|
|
|
if (!array_key_exists($stat->roleid,$roles)) {
|
|
|
|
$roles[$stat->roleid] = get_string('all');
|
|
|
|
}
|
2006-09-24 05:53:45 +00:00
|
|
|
}
|
|
|
|
if (!array_key_exists($stat->timeend,$times)) {
|
|
|
|
$times[$stat->timeend] = userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone);
|
2006-09-24 03:15:52 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-16 18:33:50 +00:00
|
|
|
|
2006-09-24 05:53:45 +00:00
|
|
|
foreach ($data as $time => $rolesdata) {
|
|
|
|
if (in_array($time,$missedlines)) {
|
|
|
|
$rolesdata = array();
|
|
|
|
foreach ($roles as $roleid => $guff) {
|
|
|
|
$rolesdata[$roleid] = 0;
|
|
|
|
}
|
|
|
|
}
|
2007-04-11 23:53:15 +00:00
|
|
|
else {
|
|
|
|
foreach (array_keys($roles) as $r) {
|
|
|
|
if (!array_key_exists($r, $rolesdata)) {
|
|
|
|
$rolesdata[$r] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-02-23 12:26:35 +00:00
|
|
|
krsort($rolesdata);
|
2006-09-24 05:53:45 +00:00
|
|
|
$row = array_merge(array($times[$time]),$rolesdata);
|
|
|
|
if (empty($CFG->loglifetime) || ($stat->timeend-(60*60*24)) >= (time()-60*60*24*$CFG->loglifetime)) {
|
2008-11-30 21:33:58 +00:00
|
|
|
if (has_capability('coursereport/log:view', get_context_instance(CONTEXT_COURSE, $course->id))) {
|
|
|
|
$row[] = '<a href="'.$CFG->wwwroot.'/course/report/log/index.php?id='
|
|
|
|
.$course->id.'&chooselog=1&showusers=1&showcourses=1&user='.$userid
|
|
|
|
.'&date='.usergetmidnight($time-(60*60*24)).'">'
|
|
|
|
.get_string('course').' ' .get_string('logs').'</a> ';
|
|
|
|
} else {
|
|
|
|
$row[] = '';
|
|
|
|
}
|
2006-09-24 05:53:45 +00:00
|
|
|
}
|
|
|
|
$table->data[] = $row;
|
2006-09-23 08:52:12 +00:00
|
|
|
}
|
2008-02-23 12:26:35 +00:00
|
|
|
krsort($roles);
|
2006-09-24 05:53:45 +00:00
|
|
|
$table->head = array_merge($table->head,$roles);
|
2006-06-06 04:15:04 +00:00
|
|
|
}
|
2006-09-24 05:53:45 +00:00
|
|
|
$table->head[] = get_string('logs');
|
|
|
|
if (!empty($lastrecord)) {
|
|
|
|
$lastrecord[] = $lastlink;
|
|
|
|
$table->data[] = $lastrecord;
|
|
|
|
}
|
|
|
|
print_table($table);
|
2006-06-06 04:15:04 +00:00
|
|
|
}
|
2008-02-23 12:26:35 +00:00
|
|
|
}
|
2006-06-06 04:15:04 +00:00
|
|
|
|
2007-04-11 23:53:15 +00:00
|
|
|
?>
|