]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-15498: Completion fix: provided full UTF-8 support and Excel support for progress...
authorsam_marshall <sam_marshall>
Mon, 28 Jul 2008 17:11:51 +0000 (17:11 +0000)
committersam_marshall <sam_marshall>
Mon, 28 Jul 2008 17:11:51 +0000 (17:11 +0000)
course/report/progress/index.php
lang/en_utf8/completion.php

index 2f52a68ca807e5580b2d7481ea7d8f926c45b69f..68ee2d2ba0bf18eb04b59228a2ad9012ee192c51 100644 (file)
@@ -14,13 +14,18 @@ $sort=optional_param('sort','',PARAM_ALPHA);
 $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);
@@ -45,10 +50,21 @@ if(count($activities)==0) {
 }
 $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;
@@ -110,7 +126,7 @@ foreach($activities as $activity) {
     }
 
     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.
@@ -126,7 +142,7 @@ foreach($activities as $activity) {
 }
 
 if($csv) {
-    print "\n";
+    print $line;
 } else {
     print '</tr>';
 }
@@ -174,7 +190,7 @@ foreach($progress as $user) {
         $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.
@@ -183,7 +199,7 @@ foreach($progress as $user) {
     }
 
     if($csv) {
-        print "\n";
+        print $line;
     } else {
         print '</tr>';
     }
@@ -195,7 +211,9 @@ if($csv) {
 print '</table>';
 
 print '<ul class="progress-actions"><li><a href="index.php?course='.$course->id.
-    '&amp;format=csv">'.get_string('csvdownload','completion').'</a></li></ul>';
+    '&amp;format=csv">'.get_string('csvdownload','completion').'</a></li>
+    <li><a href="index.php?course='.$course->id.'&amp;format=excelcsv">'.
+    get_string('excelcsvdownload','completion').'</a></li></ul>';
 
 print_footer($course);
 ?>
index 9df67eb69f979e30287712a845b6f1d72dc0df54..38e1bd4a852db88ea181f86ff301133b3f10baa5 100644 (file)
@@ -29,7 +29,8 @@ $string['completionview']='Require view';
 $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.)';