[LON-CAPA-cvs] cvs: loncom /interface lonspreadsheet.pm

matthew lon-capa-cvs@mail.lon-capa.org
Fri, 18 Oct 2002 13:46:02 -0000


This is a MIME encoded message

--matthew1034948762
Content-Type: text/plain

matthew		Fri Oct 18 09:46:02 2002 EDT

  Modified files:              
    /loncom/interface	lonspreadsheet.pm 
  Log:
  Cleanups and attempted speedups.
  Moved &mask out of the safe space.  The other items probably cannot be moved
  easily out of the safe space due to scoping issues.  More on this later.
  Modified &updateclasssheet to call loncoursedata::get_classlist.
  
  
--matthew1034948762
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20021018094602.txt"

Index: loncom/interface/lonspreadsheet.pm
diff -u loncom/interface/lonspreadsheet.pm:1.117 loncom/interface/lonspreadsheet.pm:1.118
--- loncom/interface/lonspreadsheet.pm:1.117	Wed Oct 16 12:35:42 2002
+++ loncom/interface/lonspreadsheet.pm	Fri Oct 18 09:46:01 2002
@@ -1,5 +1,5 @@
 #
-# $Id: lonspreadsheet.pm,v 1.117 2002/10/16 16:35:42 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.118 2002/10/18 13:46:01 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -61,6 +61,7 @@
 use GDBM_File;
 use HTML::TokeParser;
 use Apache::lonhtmlcommon;
+use Apache::loncoursedata;
 #
 # Caches for coursewide information 
 #
@@ -116,60 +117,9 @@
 # =============================================================================
 # ===================================== Implements an instance of a spreadsheet
 
-sub initsheet {
-    my $safeeval = new Safe(shift);
-    my $safehole = new Safe::Hole;
-    $safeeval->permit("entereval");
-    $safeeval->permit(":base_math");
-    $safeeval->permit("sort");
-    $safeeval->deny(":base_io");
-    $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
-    $safeeval->share('$@');
-    my $code=<<'ENDDEFS';
-# ---------------------------------------------------- Inside of the safe space
-
-#
-# f: formulas
-# t: intermediate format (variable references expanded)
-# v: output values
-# c: preloaded constants (A-column)
-# rl: row label
-# os: other spreadsheets (for student spreadsheet only)
-
-undef %sheet_values; 
-undef %t;
-undef %f;
-undef %c;
-undef %rowlabel;
-undef @os;
-
-$maxrow = 0;
-$sheettype = '';
-
-# filename/reference of the sheet
-$filename = '';
-
-# user data
-$uname = '';
-$uhome = '';
-$udom  = '';
-
-# course data
-
-$csec = '';
-$chome= '';
-$cnum = '';
-$cdom = '';
-$cid  = '';
-$coursefilename  = '';
-
-# symb
-
-$usymb = '';
-
-# error messages
-$errormsg = '';
-
+##
+## mask - used to reside in the safe space.  
+##
 sub mask {
     my ($lower,$upper)=@_;
 
@@ -193,7 +143,6 @@
           $alpha='['.$la.'-Za-'.$ua.']';
        }
     }   
-
     if (($ld eq '*') || ($ud eq '*')) {
 	$num='\d+';
     } else {
@@ -213,7 +162,9 @@
        } else {
            my @lda=($ld=~m/\d/g);
            my @uda=($ud=~m/\d/g);
-           my $i; $j=0; $notdone=1;
+           my $i; 
+           my $j=0; 
+           my $notdone=1;
            for ($i=0;($i<=$#lda)&&($notdone);$i++) {
                if ($lda[$i]==$uda[$i]) {
 		   $num.=$lda[$i];
@@ -246,6 +197,65 @@
     return '^'.$alpha.$num."\$";
 }
 
+
+
+sub initsheet {
+    my $safeeval = new Safe(shift);
+    my $safehole = new Safe::Hole;
+    $safeeval->permit("entereval");
+    $safeeval->permit(":base_math");
+    $safeeval->permit("sort");
+    $safeeval->deny(":base_io");
+    $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
+    $safehole->wrap(\&Apache::lonspreadsheet::mask,$safeeval,'&mask');
+    $safehole->wrap(\&Apache::lonspreadsheet::templaterow,$safeeval,'&templaterow');
+    $safeeval->share('$@');
+    my $code=<<'ENDDEFS';
+# ---------------------------------------------------- Inside of the safe space
+
+#
+# f: formulas
+# t: intermediate format (variable references expanded)
+# v: output values
+# c: preloaded constants (A-column)
+# rl: row label
+# os: other spreadsheets (for student spreadsheet only)
+
+undef %sheet_values; 
+undef %t;
+undef %f;
+undef %c;
+undef %rowlabel;
+undef @os;
+
+$maxrow = 0;
+$sheettype = '';
+
+# filename/reference of the sheet
+$filename = '';
+
+# user data
+$uname = '';
+$uhome = '';
+$udom  = '';
+
+# course data
+
+$csec = '';
+$chome= '';
+$cnum = '';
+$cdom = '';
+$cid  = '';
+$coursefilename  = '';
+
+# symb
+
+$usymb = '';
+
+# error messages
+$errormsg = '';
+
+
 #-------------------------------------------------------
 
 =item UWCALC(hashname,modules,units,date) 
@@ -918,20 +928,6 @@
     return '';
 }
 
-sub templaterow {
-    my @cols=();
-    $cols[0]='<b><font size=+1>Template</font></b>';
-    foreach ('A','B','C','D','E','F','G','H','I','J','K','L','M',
-	     'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
-	     'a','b','c','d','e','f','g','h','i','j','k','l','m',
-	     'n','o','p','q','r','s','t','u','v','w','x','y','z') {
-        my $fm=$f{'template_'.$_};
-        $fm=~s/[\'\"]/\&\#34;/g;
-        push(@cols,"'template_$_','$fm'".'___eq___'.$fm);
-    }
-    return @cols;
-}
-
 #
 # This is actually used for the student spreadsheet, not the assessment sheet
 # Do not be fooled by the name!
@@ -999,12 +995,28 @@
     return @exportarray;
 }
 
+sub templaterow {
+    my @cols=();
+    $cols[0]='<b><font size=+1>Template</font></b>';
+    foreach ('A','B','C','D','E','F','G','H','I','J','K','L','M',
+	     'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
+	     'a','b','c','d','e','f','g','h','i','j','k','l','m',
+	     'n','o','p','q','r','s','t','u','v','w','x','y','z') {
+        my $fm=$f{'template_'.$_};
+        $fm=~s/[\'\"]/\&\#34;/g;
+        push(@cols,"'template_$_','$fm'".'___eq___'.$fm);
+    }
+    return @cols;
+}
+
+
 # ------------------------------------------- End of "Inside of the safe space"
 ENDDEFS
     $safeeval->reval($code);
     return $safeeval;
 }
 
+
 # ------------------------------------------------ Add or change formula values
 sub setformulas {
     my ($safeeval,%f)=@_;
@@ -1567,66 +1579,29 @@
 
     #
     # Read class list and row labels
-    my %classlist;
-    my @tmp = &Apache::lonnet::dump('classlist',$cdom,$cnum);
-    if ($tmp[0] !~ /^error/) {
-        %classlist = @tmp;
-    } else {
-        return 'Could not access course data';
-    }
-    undef @tmp;
+    my $classlist = &Apache::loncoursedata::get_classlist();
+    if (! defined($classlist)) {
+        return 'Could not access course classlist';
+    } 
     #
     my %currentlist=();
-    my $now=time;
-    foreach my $student (keys(%classlist)) {
-        my ($end,$start)=split(/\:/,$classlist{$student});
-        my $active=1;
-        $active = 0 if (($end) && ($now>$end));
-        $active = 1 if ($ENV{'form.Status'} eq 'Any');
-        $active = !$active if ($ENV{'form.Status'} eq 'Expired');
-        if ($active) {
+    foreach my $student (keys(%$classlist)) {
+        my ($studentDomain,$studentName,$end,$start,$id,$studentSection,
+            $fullname,$status)   =   @{$classlist->{$student}};
+        if ($ENV{'form.Status'} eq $status || $ENV{'form.Status'} eq 'Any') {
             my $rowlabel='';
-            my ($studentName,$studentDomain)=split(/\:/,$student);
-            my $studentSection=&Apache::lonnet::usection($studentDomain,
-                                                         $studentName,$cid);
-            $Section{$studentName.':'.$studentDomain} = $studentSection;
-#            if ($studentSection==-1) {
-#                unless ($ENV{'form.showcsv'}) {
-#                    $rowlabel='<font color=red>Data not available: '.
-#                        $studentName.'</font>';
-#                } else {
-#                    $rowlabel='ERROR","'.$studentName.
-#                        '","Data not available","","","';
-#                }
-#            } else {
-                my %reply=&Apache::lonnet::idrget($studentDomain,$studentName);
-                my %studentInformation=&Apache::lonnet::get
-                    ('environment',
-                     ['lastname','generation','firstname','middlename','id'],
-                     $studentDomain,$studentName);
-                if (! $ENV{'form.showcsv'}) {
-                    $rowlabel='<a href="/adm/studentcalc?uname='.$studentName.
-                        '&udom='.$studentDomain.'">'.
-                            $studentSection.'&nbsp;';
-                    foreach ('id','firstname','middlename',
-                             'lastname','generation'){
-                        $rowlabel.=$studentInformation{$_}."&nbsp;";
-                    }
-                    $rowlabel.='</a>';
-                } else {
-                    $rowlabel= '"'.join('","',
-                                        ($studentSection,
-                                         $studentInformation{'id'},
-                                         $studentInformation{'firstname'},
-                                         $studentInformation{'middlename'},
-                                         $studentInformation{'lastname'},
-                                         $studentInformation{'generation'})
-                                        ).'"';
-                }
- #           }
+            if ($ENV{'form.showcsv'}) {
+                $rowlabel= '"'.join('","',($studentName,$studentDomain,
+                                           $fullname,$studentSection,$id).'"');
+            } else {
+                $rowlabel='<a href="/adm/studentcalc?uname='.$studentName.
+                    '&udom='.$studentDomain.'">';
+                $rowlabel.=$studentSection.'&nbsp;'.$id."&nbsp;".$fullname;
+                $rowlabel.='</a>';
+            }
             $currentlist{$student}=$rowlabel;
-        } # end of if ($active)
-    } # end of foreach my $student (keys(%classlist))
+        }
+    }
     #
     # Find discrepancies between the course row table and this
     #
@@ -2304,6 +2279,9 @@
 sub handler {
     my $r=shift;
 
+    if (! exists($ENV{'form.Status'})) {
+        $ENV{'form.Status'} = 'Active';
+    }
     # Check this server
     my $loaderror=&Apache::lonnet::overloaderror($r);
     if ($loaderror) { return $loaderror; }

--matthew1034948762--