$firstnamesort=$sort=='firstname';
// CSV format
-$csv=optional_param('format','',PARAM_ALPHA)==='csv';
+$format=optional_param('format','',PARAM_ALPHA);
+$excel=$format=='excelcsv';
+$csv=$format=='csv' || $excel;
function csv_quote($value) {
- $tl=textlib_get_instance();
-
- $value=$tl->specialtoascii($value);
- return '"'.str_replace('"',"'",$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->id);
}
$progress=$completion->get_progress_all($firstnamesort,$group);
+
if($csv) {
- header('Content-Type: text/csv; charset=ISO-8859-1');
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=check_browser_version('Firefox',2.0) && !$USER->screenreader;
}
if($csv) {
- print ','.csv_quote($activity->name).','.csv_quote($datetext);
+ print $sep.csv_quote($activity->name).$sep.csv_quote($datetext);
} else {
print '<th scope="col" class="'.$activity->datepassedclass.'">'.
'<a href="'.$CFG->wwwroot.'/mod/'.$activity->modname.
}
if($csv) {
- print "\n";
+ print $line;
} else {
print '</tr>';
}
$fulldescribe=get_string('progress-title','completion',$a);
if($csv) {
- print ','.csv_quote($describe).','.csv_quote($date);
+ print $sep.csv_quote($describe).$sep.csv_quote($date);
} else {
print '<td class="completion-progresscell '.$activity->datepassedclass.'">'.
'<img src="'.$CFG->pixpath.'/i/completion-'.$completiontype.
}
if($csv) {
- print "\n";
+ print $line;
} else {
print '</tr>';
}
print '</table>';
print '<ul class="progress-actions"><li><a href="index.php?course='.$course->id.
- '&format=csv">'.get_string('csvdownload','completion').'</a></li></ul>';
+ '&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>';
print_footer($course);
?>
$string['completionview_text']='User must view activity';
$string['configenablecompletion'] = 'When enabled, this lets you turn on completion tracking (progress) features at course level.';
$string['configprogresstrackedroles'] = 'Roles that are displayed in the progress-tracking screen. (Usually includes just students and equivalent roles.)';
-$string['csvdownload']='Download in spreadsheet format (.csv)';
+$string['csvdownload']='Download in spreadsheet format (UTF-8 .csv)';
+$string['excelcsvdownload']='Download in Excel-compatible format (.csv)';
$string['enablecompletion'] = 'Enable completion tracking';
$string['err_noactivities']='Completion information is not enabled for any activity, so none can be displayed. You can enable completion information by editing the settings for an activity.';
$string['err_nousers']='There are no users on this course or group for whom completion information is displayed. (By default, completion information is displayed only for students, so if there are no students, you will see this error. Administrators can alter this option via the admin screens.)';