[LON-CAPA-cvs] cvs: loncom /interface loncommon.pm /interface/statistics lonstudentassessment.pm

matthew lon-capa-cvs@mail.lon-capa.org
Wed, 10 Sep 2003 15:06:34 -0000


matthew		Wed Sep 10 11:06:34 2003 EDT

  Modified files:              
    /loncom/interface	loncommon.pm 
    /loncom/interface/statistics	lonstudentassessment.pm 
  Log:
  Fix bug 2167, illegal characters in course names cause crashes when preparing
  excel spreadsheets which use the course name as the name of the sheet.
  Added Apache::loncommon::clean_excel_name to do the cleanups.
  
  
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.114 loncom/interface/loncommon.pm:1.115
--- loncom/interface/loncommon.pm:1.114	Tue Sep  9 14:46:28 2003
+++ loncom/interface/loncommon.pm	Wed Sep 10 11:06:34 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.114 2003/09/09 18:46:28 www Exp $
+# $Id: loncommon.pm,v 1.115 2003/09/10 15:06:34 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2539,6 +2539,23 @@
     }
     $i--;
     return($i);
+}
+
+=pod
+
+=item clean_excel_name($name)
+
+Returns a replacement for $name which does not contain any illegal characters.
+
+=cut
+
+sub clean_excel_name {
+    my ($name) = @_;
+    $name =~ s/[:\*\?\/\\]//g;
+    if (length($name) > 31) {
+        $name = substr($name,0,31);
+    }
+    return $name;
 }
 
 =pod
Index: loncom/interface/statistics/lonstudentassessment.pm
diff -u loncom/interface/statistics/lonstudentassessment.pm:1.66 loncom/interface/statistics/lonstudentassessment.pm:1.67
--- loncom/interface/statistics/lonstudentassessment.pm:1.66	Wed Sep  3 14:23:10 2003
+++ loncom/interface/statistics/lonstudentassessment.pm	Wed Sep 10 11:06:34 2003
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonstudentassessment.pm,v 1.66 2003/09/03 18:23:10 matthew Exp $
+# $Id: lonstudentassessment.pm,v 1.67 2003/09/10 15:06:34 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -931,9 +931,7 @@
     #
     # Add a worksheet
     my $sheetname = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
-    if (length($sheetname) > 31) {
-        $sheetname = substr($sheetname,0,31);
-    }
+    $sheetname = &Apache::loncommon::clean_excel_name($sheetname);
     $excel_sheet = $excel_workbook->addworksheet($sheetname);
     #
     # Put the course description in the header
@@ -1514,6 +1512,7 @@
             my $awarded = 0;
             if (exists($resource_data->{'resource.'.$part.'.awarded'})) {
                 $awarded = $resource_data->{'resource.'.$part.'.awarded'};
+                $awarded = 0 if (! $awarded);
             }
             #
             $partscore = $weight*$awarded;