get_record('course',array('id'=>required_param('course',PARAM_INT))); if(!$course) { print_error('invalidcourseid'); } // Sort (default lastname, optionally firstname) $sort=optional_param('sort','',PARAM_ALPHA); $firstnamesort=$sort=='firstname'; // CSV format $format=optional_param('format','',PARAM_ALPHA); $excel=$format=='excelcsv'; $csv=$format=='csv' || $excel; // Whether to start at a particular position $start=optional_param('start',0,PARAM_INT); // Whether to show idnumber // TODO: This should really not be using a config option 'intended' for // gradebook, but that option is also used in quiz reports as well. There ought // to be a generic option somewhere. $idnumbers=$CFG->grade_report_showuseridnumber; function csv_quote($value) { global $excel; if($excel) { $tl=textlib_get_instance(); return $tl->convert('"'.str_replace('"',"'",$value).'"','UTF-8','UTF-16LE'); } else { return '"'.str_replace('"',"'",$value).'"'; } } require_login($course); // Check basic permission $context=get_context_instance(CONTEXT_COURSE,$course->id); require_capability('coursereport/progress:view',$context); // 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); } $progress=$completion->get_progress_all($firstnamesort,$group, $csv ? 0 :COMPLETION_REPORT_PAGE,$csv ? 0 : $start); if($csv) { header('Content-Disposition: attachment; filename=progress.'. preg_replace('/[^a-z0-9-]/','_',strtolower($course->shortname)).'.csv'); // 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); $line="\n".chr(0); } else { header('Content-Type: text/csv; charset=UTF-8'); $sep=","; $line="\n"; } } else { // Use SVG to draw sideways text if supported $svgcleverness=can_use_rotated_text(); // Navigation and header $strreports = get_string("reports"); $strcompletion = get_string('completionreport','completion'); $navlinks = array(); $navlinks[] = array('name' => $strreports, 'link' => "../../report.php?id=$course->id", 'type' => 'misc'); $navlinks[] = array('name' => $strcompletion, 'link' => null, 'type' => 'misc'); if($svgcleverness) { require_js(array('yui_yahoo','yui_event','yui_dom')); } print_header($strcompletion,$course->fullname,build_navigation($navlinks)); if($svgcleverness) { require_js('course/report/progress/textrotate.js'); } // Handle groups (if enabled) groups_print_course_menu($course,$CFG->wwwroot.'/course/report/progress/?course='.$course->id); } // Do we need a paging bar? if($progress->total > COMPLETION_REPORT_PAGE) { $pagingbar='
'; } else { $pagingbar=''; } // Okay, let's draw the table of progress info, // Start of table if(!$csv) { print ''.get_string('err_nousers','completion').'
'; print ''; print_footer($course); exit; } print $pagingbar; print '| '; if($firstnamesort) { print get_string('firstname').' / '. get_string('lastname').''; } else { print ''. get_string('firstname').' / '. get_string('lastname'); } print ' | '; if($idnumbers) { print ''.get_string('idnumber').' | '; } } else { if($idnumbers) { print $sep; } } // 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=''; } // Some names (labels) come URL-encoded and can be very long, so shorten them $activity->name=shorten_text(urldecode($activity->name)); if($csv) { print $sep.csv_quote(strip_tags($activity->name)).$sep.csv_quote($datetext); } else { print ''.
''.
' '.$datetext.' ';
}
print ' | ';
}
}
if($csv) {
print $line;
} else {
print '
|---|---|---|
| '.fullname($user).' | '; if($idnumbers) { print ''.htmlspecialchars($user->idnumber).' | '; } } // Progress for each activity foreach($activities as $activity) { // Get progress information and state if(array_key_exists($activity->id,$user->progress)) { $thisprogress=$user->progress[$activity->id]; $state=$thisprogress->completionstate; $date=userdate($thisprogress->timemodified); } else { $state=COMPLETION_INCOMPLETE; $date=''; } // Work out how it corresponds to an icon switch($state) { 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; } $completionicon='completion-'. ($activity->completion==COMPLETION_TRACKING_AUTOMATIC ? 'auto' : 'manual'). '-'.$completiontype; $describe=get_string('completion-alt-auto-'.$completiontype,'completion'); $a=new StdClass; $a->state=$describe; $a->date=$date; $a->user=fullname($user); $a->activity=strip_tags($activity->name); $fulldescribe=get_string('progress-title','completion',$a); if($csv) { print $sep.csv_quote($describe).$sep.csv_quote($date); } else { print ''.
' | ';
}
}
if($csv) {
print $line;
} else {
print '