2008-07-28 12:31:29 +00:00
|
|
|
<?php
|
|
|
|
require_once('../../../config.php');
|
2009-05-08 09:00:41 +00:00
|
|
|
require_once($CFG->libdir . '/completionlib.php');
|
2008-07-28 12:31:29 +00:00
|
|
|
|
2008-10-24 16:20:37 +00:00
|
|
|
define('COMPLETION_REPORT_PAGE',50);
|
|
|
|
|
2008-07-28 12:31:29 +00:00
|
|
|
// Get course
|
2009-09-21 07:22:57 +00:00
|
|
|
$id = required_param('course',PARAM_INT);
|
|
|
|
$course=$DB->get_record('course',array('id'=>$id));
|
2008-07-28 12:31:29 +00:00
|
|
|
if(!$course) {
|
2008-11-18 08:13:26 +00:00
|
|
|
print_error('invalidcourseid');
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Sort (default lastname, optionally firstname)
|
|
|
|
$sort=optional_param('sort','',PARAM_ALPHA);
|
|
|
|
$firstnamesort=$sort=='firstname';
|
|
|
|
|
|
|
|
// CSV format
|
2008-07-28 17:11:51 +00:00
|
|
|
$format=optional_param('format','',PARAM_ALPHA);
|
|
|
|
$excel=$format=='excelcsv';
|
|
|
|
$csv=$format=='csv' || $excel;
|
2008-07-28 12:31:29 +00:00
|
|
|
|
2008-10-24 16:20:37 +00:00
|
|
|
// Whether to start at a particular position
|
|
|
|
$start=optional_param('start',0,PARAM_INT);
|
|
|
|
|
2008-07-29 10:37:46 +00:00
|
|
|
// Whether to show idnumber
|
2008-11-18 08:13:26 +00:00
|
|
|
// TODO: This should really not be using a config option 'intended' for
|
2008-07-29 11:26:55 +00:00
|
|
|
// gradebook, but that option is also used in quiz reports as well. There ought
|
|
|
|
// to be a generic option somewhere.
|
2008-07-29 10:37:46 +00:00
|
|
|
$idnumbers=$CFG->grade_report_showuseridnumber;
|
|
|
|
|
2008-07-28 12:31:29 +00:00
|
|
|
function csv_quote($value) {
|
2008-07-28 17:11:51 +00:00
|
|
|
global $excel;
|
|
|
|
if($excel) {
|
|
|
|
$tl=textlib_get_instance();
|
|
|
|
return $tl->convert('"'.str_replace('"',"'",$value).'"','UTF-8','UTF-16LE');
|
|
|
|
} else {
|
|
|
|
return '"'.str_replace('"',"'",$value).'"';
|
|
|
|
}
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
|
|
|
|
2010-01-16 15:39:56 +00:00
|
|
|
$url = new moodle_url('/course/report/progress/index.php', array('course'=>$id));
|
2009-09-21 07:22:57 +00:00
|
|
|
if ($sort !== '') {
|
|
|
|
$url->param('sort', $sort);
|
|
|
|
}
|
|
|
|
if ($format !== '') {
|
|
|
|
$url->param('format', $format);
|
|
|
|
}
|
|
|
|
if ($start !== '') {
|
|
|
|
$url->param('start', $start);
|
|
|
|
}
|
|
|
|
$PAGE->set_url($url);
|
|
|
|
|
2008-11-29 14:22:10 +00:00
|
|
|
require_login($course);
|
2008-07-28 12:31:29 +00:00
|
|
|
|
|
|
|
// Check basic permission
|
|
|
|
$context=get_context_instance(CONTEXT_COURSE,$course->id);
|
2008-11-29 16:41:20 +00:00
|
|
|
require_capability('coursereport/progress:view',$context);
|
2008-07-28 12:31:29 +00:00
|
|
|
|
|
|
|
// Get group mode
|
|
|
|
$group=groups_get_course_group($course,true); // Supposed to verify group
|
|
|
|
if($group===0 && $course->groupmode==SEPARATEGROUPS) {
|
|
|
|
require_capability('moodle/site:accessallgroups',$context);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get data on activities and progress of all users, and give error if we've
|
|
|
|
// nothing to display (no users or no activities)
|
|
|
|
$reportsurl=$CFG->wwwroot.'/course/report.php?id='.$course->id;
|
|
|
|
$completion=new completion_info($course);
|
|
|
|
$activities=$completion->get_activities();
|
|
|
|
if(count($activities)==0) {
|
|
|
|
print_error('err_noactivities','completion',$reportsurl);
|
|
|
|
}
|
|
|
|
|
2009-03-03 17:28:05 +00:00
|
|
|
$progress=$completion->get_progress_all($firstnamesort,$group,
|
|
|
|
$csv ? 0 :COMPLETION_REPORT_PAGE,$csv ? 0 : $start);
|
2008-07-28 17:11:51 +00:00
|
|
|
|
2008-07-28 12:31:29 +00:00
|
|
|
if($csv) {
|
|
|
|
header('Content-Disposition: attachment; filename=progress.'.
|
|
|
|
preg_replace('/[^a-z0-9-]/','_',strtolower($course->shortname)).'.csv');
|
2008-07-28 17:11:51 +00:00
|
|
|
// Unicode byte-order mark for Excel
|
|
|
|
if($excel) {
|
|
|
|
header('Content-Type: text/csv; charset=UTF-16LE');
|
|
|
|
print chr(0xFF).chr(0xFE);
|
|
|
|
$sep="\t".chr(0);
|
2008-11-18 08:13:26 +00:00
|
|
|
$line="\n".chr(0);
|
2008-07-28 17:11:51 +00:00
|
|
|
} else {
|
|
|
|
header('Content-Type: text/csv; charset=UTF-8');
|
|
|
|
$sep=",";
|
|
|
|
$line="\n";
|
|
|
|
}
|
2008-07-28 12:31:29 +00:00
|
|
|
} else {
|
|
|
|
// Use SVG to draw sideways text if supported
|
2009-06-12 11:57:15 +00:00
|
|
|
$svgcleverness = can_use_rotated_text();
|
2008-07-28 12:31:29 +00:00
|
|
|
|
|
|
|
// Navigation and header
|
|
|
|
$strreports = get_string("reports");
|
|
|
|
$strcompletion = get_string('completionreport','completion');
|
2009-09-03 08:47:24 +00:00
|
|
|
|
|
|
|
$PAGE->set_title($strcompletion);
|
|
|
|
$PAGE->set_heading($course->fullname);
|
2010-01-16 15:39:56 +00:00
|
|
|
$PAGE->navbar->add($strreports, new moodle_url('/course/report.php', array('id'=>$course->id)));
|
2009-09-03 08:47:24 +00:00
|
|
|
$PAGE->navbar->add($strcompletion);
|
|
|
|
echo $OUTPUT->header();
|
|
|
|
|
2008-07-28 12:31:29 +00:00
|
|
|
if($svgcleverness) {
|
2009-12-16 20:25:14 +00:00
|
|
|
$PAGE->requires->yui2_lib('event');
|
2009-06-15 05:37:57 +00:00
|
|
|
$PAGE->requires->js('course/report/progress/textrotate.js');
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Handle groups (if enabled)
|
|
|
|
groups_print_course_menu($course,$CFG->wwwroot.'/course/report/progress/?course='.$course->id);
|
|
|
|
}
|
|
|
|
|
2008-10-24 17:54:58 +00:00
|
|
|
// Do we need a paging bar?
|
2008-10-24 16:20:37 +00:00
|
|
|
if($progress->total > COMPLETION_REPORT_PAGE) {
|
|
|
|
$pagingbar='<div class="completion_pagingbar">';
|
|
|
|
|
|
|
|
if($start>0) {
|
|
|
|
$newstart=$start-COMPLETION_REPORT_PAGE;
|
|
|
|
if($newstart<0) {
|
|
|
|
$newstart=0;
|
|
|
|
}
|
|
|
|
$pagingbar.=link_arrow_left(get_string('previous'),'./?course='.$course->id.
|
|
|
|
($newstart ? '&start='.$newstart : ''),false,'completion_prev');
|
|
|
|
}
|
|
|
|
|
|
|
|
$a=new StdClass;
|
|
|
|
$a->from=$start+1;
|
|
|
|
$a->to=$start+COMPLETION_REPORT_PAGE;
|
|
|
|
$a->total=$progress->total;
|
|
|
|
$pagingbar.='<p>'.get_string('reportpage','completion',$a).'</p>';
|
|
|
|
|
|
|
|
if($start+COMPLETION_REPORT_PAGE < $progress->total) {
|
|
|
|
$pagingbar.=link_arrow_right(get_string('next'),'./?course='.$course->id.
|
|
|
|
'&start='.($start+COMPLETION_REPORT_PAGE),false,'completion_next');
|
|
|
|
}
|
|
|
|
|
2008-11-18 08:13:26 +00:00
|
|
|
$pagingbar.='</div>';
|
2008-10-24 16:20:37 +00:00
|
|
|
} else {
|
|
|
|
$pagingbar='';
|
|
|
|
}
|
|
|
|
|
2008-07-28 12:31:29 +00:00
|
|
|
// Okay, let's draw the table of progress info,
|
|
|
|
|
2008-11-18 08:13:26 +00:00
|
|
|
// Start of table
|
2008-07-28 12:31:29 +00:00
|
|
|
if(!$csv) {
|
|
|
|
print '<br class="clearer"/>'; // ugh
|
2008-10-24 16:20:37 +00:00
|
|
|
if(count($progress->users)==0) {
|
2008-07-28 12:31:29 +00:00
|
|
|
print '<p class="nousers">'.get_string('err_nousers','completion').'</p>';
|
|
|
|
print '<p><a href="'.$reportsurl.'">'.get_string('continue').'</a></p>';
|
2009-08-06 14:10:33 +00:00
|
|
|
echo $OUTPUT->footer();
|
2008-07-28 12:31:29 +00:00
|
|
|
exit;
|
|
|
|
}
|
2008-10-24 16:20:37 +00:00
|
|
|
print $pagingbar;
|
2008-07-28 12:31:29 +00:00
|
|
|
print '<table id="completion-progress" class="generaltable flexible boxaligncenter" style="text-align:left"><tr style="vertical-align:top">';
|
|
|
|
|
|
|
|
// User heading / sort option
|
|
|
|
print '<th scope="col" class="completion-sortchoice">';
|
|
|
|
if($firstnamesort) {
|
2008-11-18 08:13:26 +00:00
|
|
|
print
|
2008-07-28 12:31:29 +00:00
|
|
|
get_string('firstname').' / <a href="./?course='.$course->id.'">'.
|
|
|
|
get_string('lastname').'</a>';
|
|
|
|
} else {
|
2008-09-18 08:21:57 +00:00
|
|
|
print '<a href="./?course='.$course->id.'&sort=firstname">'.
|
2008-07-28 12:31:29 +00:00
|
|
|
get_string('firstname').'</a> / '.
|
|
|
|
get_string('lastname');
|
|
|
|
}
|
|
|
|
print '</th>';
|
2008-11-18 08:13:26 +00:00
|
|
|
|
2008-07-29 10:37:46 +00:00
|
|
|
if($idnumbers) {
|
2008-11-18 08:13:26 +00:00
|
|
|
print '<th>'.get_string('idnumber').'</th>';
|
2008-07-29 10:37:46 +00:00
|
|
|
}
|
2008-11-18 08:13:26 +00:00
|
|
|
|
2008-07-29 10:37:46 +00:00
|
|
|
} else {
|
|
|
|
if($idnumbers) {
|
|
|
|
print $sep;
|
|
|
|
}
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Activities
|
|
|
|
foreach($activities as $activity) {
|
|
|
|
$activity->datepassed = $activity->completionexpected && $activity->completionexpected <= time();
|
|
|
|
$activity->datepassedclass=$activity->datepassed ? 'completion-expired' : '';
|
|
|
|
|
|
|
|
if($activity->completionexpected) {
|
|
|
|
$datetext=userdate($activity->completionexpected,get_string('strftimedate','langconfig'));
|
|
|
|
} else {
|
|
|
|
$datetext='';
|
|
|
|
}
|
2008-11-18 08:13:26 +00:00
|
|
|
|
2008-08-21 16:35:12 +00:00
|
|
|
// Some names (labels) come URL-encoded and can be very long, so shorten them
|
|
|
|
$activity->name=shorten_text(urldecode($activity->name));
|
2008-07-28 12:31:29 +00:00
|
|
|
|
|
|
|
if($csv) {
|
2008-10-24 10:12:33 +00:00
|
|
|
print $sep.csv_quote(strip_tags($activity->name)).$sep.csv_quote($datetext);
|
2008-07-28 12:31:29 +00:00
|
|
|
} else {
|
|
|
|
print '<th scope="col" class="'.$activity->datepassedclass.'">'.
|
|
|
|
'<a href="'.$CFG->wwwroot.'/mod/'.$activity->modname.
|
|
|
|
'/view.php?id='.$activity->id.'">'.
|
2009-12-16 21:50:45 +00:00
|
|
|
'<img src="'.$OUTPUT->pix_url('icon', $activity->modname).'/icon.gif" alt="'.
|
2008-07-28 12:31:29 +00:00
|
|
|
get_string('modulename',$activity->modname).'" /> <span class="completion-activityname">'.
|
|
|
|
format_string($activity->name).'</span></a>';
|
|
|
|
if($activity->completionexpected) {
|
|
|
|
print '<div class="completion-expected"><span>'.$datetext.'</span></div>';
|
|
|
|
}
|
|
|
|
print '</th>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($csv) {
|
2008-07-28 17:11:51 +00:00
|
|
|
print $line;
|
2008-07-28 12:31:29 +00:00
|
|
|
} else {
|
|
|
|
print '</tr>';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Row for each user
|
2008-10-24 16:20:37 +00:00
|
|
|
foreach($progress->users as $user) {
|
2008-07-28 12:31:29 +00:00
|
|
|
// User name
|
|
|
|
if($csv) {
|
|
|
|
print csv_quote(fullname($user));
|
2008-07-29 10:37:46 +00:00
|
|
|
if($idnumbers) {
|
|
|
|
print $sep.csv_quote($user->idnumber);
|
|
|
|
}
|
2008-07-28 12:31:29 +00:00
|
|
|
} else {
|
|
|
|
print '<tr><th scope="row"><a href="'.$CFG->wwwroot.'/user/view.php?id='.
|
|
|
|
$user->id.'&course='.$course->id.'">'.fullname($user).'</a></th>';
|
2008-07-29 10:37:46 +00:00
|
|
|
if($idnumbers) {
|
|
|
|
print '<td>'.htmlspecialchars($user->idnumber).'</td>';
|
|
|
|
}
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Progress for each activity
|
|
|
|
foreach($activities as $activity) {
|
|
|
|
|
|
|
|
// Get progress information and state
|
|
|
|
if(array_key_exists($activity->id,$user->progress)) {
|
2008-10-24 16:20:37 +00:00
|
|
|
$thisprogress=$user->progress[$activity->id];
|
|
|
|
$state=$thisprogress->completionstate;
|
|
|
|
$date=userdate($thisprogress->timemodified);
|
2008-07-28 12:31:29 +00:00
|
|
|
} else {
|
|
|
|
$state=COMPLETION_INCOMPLETE;
|
|
|
|
$date='';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Work out how it corresponds to an icon
|
|
|
|
switch($state) {
|
2008-11-06 17:29:07 +00:00
|
|
|
case COMPLETION_INCOMPLETE : $completiontype='n'; break;
|
|
|
|
case COMPLETION_COMPLETE : $completiontype='y'; break;
|
|
|
|
case COMPLETION_COMPLETE_PASS : $completiontype='pass'; break;
|
|
|
|
case COMPLETION_COMPLETE_FAIL : $completiontype='fail'; break;
|
2008-11-18 08:13:26 +00:00
|
|
|
}
|
2008-07-28 12:31:29 +00:00
|
|
|
|
2008-11-06 17:29:07 +00:00
|
|
|
$completionicon='completion-'.
|
|
|
|
($activity->completion==COMPLETION_TRACKING_AUTOMATIC ? 'auto' : 'manual').
|
|
|
|
'-'.$completiontype;
|
2008-11-18 08:13:26 +00:00
|
|
|
|
2008-11-06 17:29:07 +00:00
|
|
|
$describe=get_string('completion-alt-auto-'.$completiontype,'completion');
|
2008-07-28 12:31:29 +00:00
|
|
|
$a=new StdClass;
|
|
|
|
$a->state=$describe;
|
|
|
|
$a->date=$date;
|
|
|
|
$a->user=fullname($user);
|
2008-08-21 16:43:33 +00:00
|
|
|
$a->activity=strip_tags($activity->name);
|
2008-07-28 12:31:29 +00:00
|
|
|
$fulldescribe=get_string('progress-title','completion',$a);
|
|
|
|
|
|
|
|
if($csv) {
|
2008-07-28 17:11:51 +00:00
|
|
|
print $sep.csv_quote($describe).$sep.csv_quote($date);
|
2008-07-28 12:31:29 +00:00
|
|
|
} else {
|
|
|
|
print '<td class="completion-progresscell '.$activity->datepassedclass.'">'.
|
2009-12-16 21:50:45 +00:00
|
|
|
'<img src="'.$OUTPUT->pix_url('i/'.$completionicon).
|
2009-07-03 04:23:05 +00:00
|
|
|
'" alt="'.$describe.'" title="'.$fulldescribe.'" /></td>';
|
2008-07-28 12:31:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($csv) {
|
2008-07-28 17:11:51 +00:00
|
|
|
print $line;
|
2008-07-28 12:31:29 +00:00
|
|
|
} else {
|
|
|
|
print '</tr>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($csv) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
print '</table>';
|
2008-10-24 16:20:37 +00:00
|
|
|
print $pagingbar;
|
2008-07-28 12:31:29 +00:00
|
|
|
|
|
|
|
print '<ul class="progress-actions"><li><a href="index.php?course='.$course->id.
|
2008-07-28 17:11:51 +00:00
|
|
|
'&format=csv">'.get_string('csvdownload','completion').'</a></li>
|
|
|
|
<li><a href="index.php?course='.$course->id.'&format=excelcsv">'.
|
|
|
|
get_string('excelcsvdownload','completion').'</a></li></ul>';
|
2008-07-28 12:31:29 +00:00
|
|
|
|
2009-08-06 14:10:33 +00:00
|
|
|
echo $OUTPUT->footer();
|
2009-11-04 08:11:02 +00:00
|
|
|
|