Diff for /loncom/interface/Attic/lonspreadsheet.pm between versions 1.113 and 1.118

version 1.113, 2002/09/30 18:03:39 version 1.118, 2002/10/18 13:46:01
Line 61  use Apache::Constants qw(:common :http); Line 61  use Apache::Constants qw(:common :http);
 use GDBM_File;  use GDBM_File;
 use HTML::TokeParser;  use HTML::TokeParser;
 use Apache::lonhtmlcommon;  use Apache::lonhtmlcommon;
   use Apache::loncoursedata;
 #  #
 # Caches for coursewide information   # Caches for coursewide information 
 #  #
Line 116  my $tmpdir; Line 117  my $tmpdir;
 # =============================================================================  # =============================================================================
 # ===================================== Implements an instance of a spreadsheet  # ===================================== Implements an instance of a spreadsheet
   
 sub initsheet {  ##
     my $safeeval = new Safe(shift);  ## mask - used to reside in the safe space.  
     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 = '';  
   
 sub mask {  sub mask {
     my ($lower,$upper)=@_;      my ($lower,$upper)=@_;
   
Line 193  sub mask { Line 143  sub mask {
           $alpha='['.$la.'-Za-'.$ua.']';            $alpha='['.$la.'-Za-'.$ua.']';
        }         }
     }         }   
   
     if (($ld eq '*') || ($ud eq '*')) {      if (($ld eq '*') || ($ud eq '*')) {
  $num='\d+';   $num='\d+';
     } else {      } else {
Line 213  sub mask { Line 162  sub mask {
        } else {         } else {
            my @lda=($ld=~m/\d/g);             my @lda=($ld=~m/\d/g);
            my @uda=($ud=~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++) {             for ($i=0;($i<=$#lda)&&($notdone);$i++) {
                if ($lda[$i]==$uda[$i]) {                 if ($lda[$i]==$uda[$i]) {
    $num.=$lda[$i];     $num.=$lda[$i];
Line 246  sub mask { Line 197  sub mask {
     return '^'.$alpha.$num."\$";      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)   =item UWCALC(hashname,modules,units,date) 
Line 918  sub calc { Line 928  sub calc {
     return '';      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  # This is actually used for the student spreadsheet, not the assessment sheet
 # Do not be fooled by the name!  # Do not be fooled by the name!
Line 999  sub exportrowa { Line 995  sub exportrowa {
     return @exportarray;      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"  # ------------------------------------------- End of "Inside of the safe space"
 ENDDEFS  ENDDEFS
     $safeeval->reval($code);      $safeeval->reval($code);
     return $safeeval;      return $safeeval;
 }  }
   
 # ------------------------------------------------ Add or change formula values  
   
   # ------------------------------------------------ Add or change formula values
 sub setformulas {  sub setformulas {
     my ($safeeval,%f)=@_;      my ($safeeval,%f)=@_;
     %{$safeeval->varglob('f')}=%f;      %{$safeeval->varglob('f')}=%f;
 }  }
   
 # ------------------------------------------------ Add or change formula values  # ------------------------------------------------ Add or change formula values
   
 sub setconstants {  sub setconstants {
     my ($safeeval,%c)=@_;      my ($safeeval,%c)=@_;
     %{$safeeval->varglob('c')}=%c;      %{$safeeval->varglob('c')}=%c;
 }  }
   
 # --------------------------------------------- Set names of other spreadsheets  # --------------------------------------------- Set names of other spreadsheets
   
 sub setothersheets {  sub setothersheets {
     my ($safeeval,@os)=@_;      my ($safeeval,@os)=@_;
     @{$safeeval->varglob('os')}=@os;      @{$safeeval->varglob('os')}=@os;
 }  }
   
 # ------------------------------------------------ Add or change formula values  # ------------------------------------------------ Add or change formula values
   
 sub setrowlabels {  sub setrowlabels {
     my ($safeeval,%rowlabel)=@_;      my ($safeeval,%rowlabel)=@_;
     %{$safeeval->varglob('rowlabel')}=%rowlabel;      %{$safeeval->varglob('rowlabel')}=%rowlabel;
 }  }
   
 # ------------------------------------------------------- Calculate spreadsheet  # ------------------------------------------------------- Calculate spreadsheet
   
 sub calcsheet {  sub calcsheet {
     my $safeeval=shift;      my $safeeval=shift;
     return $safeeval->reval('&calc();');      return $safeeval->reval('&calc();');
 }  }
   
 # ------------------------------------------------------------------ Get values  
   
 sub getvalues {  
     my $safeeval=shift;  
     return $safeeval->reval('%sheet_values');  
 }  
   
 # ---------------------------------------------------------------- Get formulas  # ---------------------------------------------------------------- Get formulas
   
 sub getformulas {  sub getformulas {
     my $safeeval=shift;      my $safeeval=shift;
     return %{$safeeval->varglob('f')};      return %{$safeeval->varglob('f')};
 }  }
   
 # ----------------------------------------------------- Get value of $f{'A'.$n}  # ----------------------------------------------------- Get value of $f{'A'.$n}
   
 sub getfa {  sub getfa {
     my ($safeeval,$n)=@_;      my ($safeeval,$n)=@_;
     return $safeeval->reval('$f{"A'.$n.'"}');      return $safeeval->reval('$f{"A'.$n.'"}');
 }  }
   
 # -------------------------------------------------------------------- Get type  
   
 sub gettype {  
     my $safeeval=shift;  
     return $safeeval->reval('$sheettype');  
 }  
   
 # ------------------------------------------------------------------ Set maxrow  
   
 sub setmaxrow {  
     my ($safeeval,$row)=@_;  
     $safeeval->reval('$maxrow='.$row.';');  
 }  
   
 # ------------------------------------------------------------------ Get maxrow  
   
 sub getmaxrow {  
     my $safeeval=shift;  
     return $safeeval->reval('$maxrow');  
 }  
   
 # ---------------------------------------------------------------- Set filename  
   
 sub setfilename {  
     my ($safeeval,$fn)=@_;  
     $safeeval->reval('$filename="'.$fn.'";');  
 }  
   
 # ---------------------------------------------------------------- Get filename  
   
 sub getfilename {  
     my $safeeval=shift;  
     return $safeeval->reval('$filename');  
 }  
   
 # --------------------------------------------------------------- Get course ID  
   
 sub getcid {  
     my $safeeval=shift;  
     return $safeeval->reval('$cid');  
 }  
   
 # --------------------------------------------------------- Get course filename  
   
 sub getcoursefilename {  
     my $safeeval=shift;  
     return $safeeval->reval('$coursefilename');  
 }  
   
 # ----------------------------------------------------------- Get course number  
   
 sub getcnum {  
     my $safeeval=shift;  
     return $safeeval->reval('$cnum');  
 }  
   
 # ------------------------------------------------------------- Get course home  
   
 sub getchome {  
     my $safeeval=shift;  
     return $safeeval->reval('$chome');  
 }  
   
 # ----------------------------------------------------------- Get course domain  
   
 sub getcdom {  
     my $safeeval=shift;  
     return $safeeval->reval('$cdom');  
 }  
   
 # ---------------------------------------------------------- Get course section  
   
 sub getcsec {  
     my $safeeval=shift;  
     return $safeeval->reval('$csec');  
 }  
   
 # --------------------------------------------------------------- Get user name  
   
 sub getuname {  
     my $safeeval=shift;  
     return $safeeval->reval('$uname');  
 }  
   
 # ------------------------------------------------------------- Get user domain  
   
 sub getudom {  
     my $safeeval=shift;  
     return $safeeval->reval('$udom');  
 }  
   
 # --------------------------------------------------------------- Get user home  
   
 sub getuhome {  
     my $safeeval=shift;  
     return $safeeval->reval('$uhome');  
 }  
   
 # -------------------------------------------------------------------- Get symb  
   
 sub getusymb {  
     my $safeeval=shift;  
     return $safeeval->reval('$usymb');  
 }  
   
 # ------------------------------------------------------------- Export of A-row  # ------------------------------------------------------------- Export of A-row
   
 sub exportdata {  sub exportdata {
     my $safeeval=shift;      my $safeeval=shift;
     return $safeeval->reval('&exportrowa()');      return $safeeval->reval('&exportrowa()');
Line 1183  sub exportdata { Line 1075  sub exportdata {
 # --------------------------------------------- Produce output row n from sheet  # --------------------------------------------- Produce output row n from sheet
   
 sub rown {  sub rown {
     my ($safeeval,$n)=@_;      my ($safeeval,$n,$sheetdata)=@_;
     my $defaultbg;      my $defaultbg;
     my $rowdata='';      my $rowdata='';
     my $dataflag=0;      my $dataflag=0;
Line 1200  sub rown { Line 1092  sub rown {
     my $showf=0;      my $showf=0;
     my $proc;      my $proc;
     my $maxred=1;      my $maxred=1;
     my $sheettype=&gettype($safeeval);      my $sheettype=$sheetdata->{'sheettype'};
     if ($sheettype eq 'studentcalc') {      if ($sheettype eq 'studentcalc') {
         $proc='&outrowassess';          $proc='&outrowassess';
         $maxred=26;          $maxred=26;
Line 1296  sub outsheet { Line 1188  sub outsheet {
             }              }
             $tabledata.="<b><font size=+1>$_</font></b></td>";              $tabledata.="<b><font size=+1>$_</font></b></td>";
         }          }
         $tabledata.='</tr>'.&rown($safeeval,'-').&rown($safeeval,0);          $tabledata.='</tr>'.&rown($safeeval,'-',$sheetdata).
               &rown($safeeval,0,$sheetdata);
     }      }
     $r->print($tabledata);      $r->print($tabledata);
     #      #
     # Prepare to output rows      # Prepare to output rows
     my $row;      my $row;
     my $maxrow=&getmaxrow($safeeval);      my $maxrow=$sheetdata->{'maxrow'};
     #      #
     my @sortby=();      my @sortby=();
     my @sortidx=();      my @sortidx=();
Line 1323  sub outsheet { Line 1216  sub outsheet {
     # Loop through the rows and output them one at a time      # Loop through the rows and output them one at a time
     my $n=0;      my $n=0;
     for ($row=0;$row<$maxrow;$row++) {      for ($row=0;$row<$maxrow;$row++) {
         my $thisrow=&rown($safeeval,$sortidx[$row]+1);          my $thisrow=&rown($safeeval,$sortidx[$row]+1,$sheetdata);
         if ($thisrow) {          if ($thisrow) {
             if (($n/25==int($n/25)) && (!$ENV{'form.showcsv'})) {              if (($n/25==int($n/25)) && (!$ENV{'form.showcsv'})) {
                 $r->print("</table>\n<br>\n");                  $r->print("</table>\n<br>\n");
Line 1346  sub outsheet { Line 1239  sub outsheet {
 # ----------------------------------------------- Read list of available sheets  # ----------------------------------------------- Read list of available sheets
 #   # 
 sub othersheets {  sub othersheets {
     my ($safeeval,$stype)=@_;      my ($safeeval,$stype,$sheetdata)=@_;
     #      #
     my $cnum  = &getcnum($safeeval);      my $cnum  = $sheetdata->{'cnum'};
     my $cdom  = &getcdom($safeeval);      my $cdom  = $sheetdata->{'cdom'};
     my $chome = &getchome($safeeval);      my $chome = $sheetdata->{'chome'};
     #      #
     my @alternatives=();      my @alternatives=();
     my %results=&Apache::lonnet::dump($stype.'_spreadsheets',$cdom,$cnum);      my %results=&Apache::lonnet::dump($stype.'_spreadsheets',$cdom,$cnum);
Line 1420  sub readsheet { Line 1313  sub readsheet {
         }          }
     }      }
     # $fn now has a value      # $fn now has a value
     &setfilename($safeeval,$fn);      $sheetdata->{'filename'} = $fn;
     # see if sheet is cached      # see if sheet is cached
     my $fstring='';      my $fstring='';
     if ($fstring=$spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}) {      if ($fstring=$spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}) {
Line 1480  sub makenewsheet { Line 1373  sub makenewsheet {
     $sheetdata{'uhome'} = &Apache::lonnet::homeserver($uname,$udom);      $sheetdata{'uhome'} = &Apache::lonnet::homeserver($uname,$udom);
           
     my $safeeval=initsheet($stype);      my $safeeval=initsheet($stype);
       #
       # Place all the %sheetdata items into the safe space
     my $initstring = '';      my $initstring = '';
     foreach (keys(%sheetdata)) {      foreach (keys(%sheetdata)) {
         $initstring.= qq{\$$_="$sheetdata{$_}";};          $initstring.= qq{\$$_="$sheetdata{$_}";};
Line 1490  sub makenewsheet { Line 1385  sub makenewsheet {
   
 # ------------------------------------------------------------ Save spreadsheet  # ------------------------------------------------------------ Save spreadsheet
 sub writesheet {  sub writesheet {
     my ($safeeval,$makedef)=@_;      my ($safeeval,$makedef,$sheetdata)=@_;
     my $cid=&getcid($safeeval);      my $cid=$sheetdata->{'cid'};
     if (&Apache::lonnet::allowed('opa',$cid)) {      if (&Apache::lonnet::allowed('opa',$cid)) {
         my %f=&getformulas($safeeval);          my %f=&getformulas($safeeval);
         my $stype=&gettype($safeeval);          my $stype= $sheetdata->{'sheettype'};
         my $cnum=&getcnum($safeeval);          my $cnum = $sheetdata->{'cnum'};
         my $cdom=&getcdom($safeeval);          my $cdom = $sheetdata->{'cdom'};
         my $chome=&getchome($safeeval);          my $chome= $sheetdata->{'chome'};
         my $fn=&getfilename($safeeval);          my $fn   = $sheetdata->{'filename'};
         # Cache new sheet          # Cache new sheet
         $spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}=join('___;___',%f);          $spreadsheets{$cnum.'_'.$cdom.'_'.$stype.'_'.$fn}=join('___;___',%f);
         # Write sheet          # Write sheet
Line 1541  sub writesheet { Line 1436  sub writesheet {
 # "Modified workcopy" - interactive only  # "Modified workcopy" - interactive only
 #  #
 sub tmpwrite {  sub tmpwrite {
     my $safeeval=shift;      my ($safeeval,$sheetdata) = @_;
     my $fn=$ENV{'user.name'}.'_'.      my $fn=$ENV{'user.name'}.'_'.
         $ENV{'user.domain'}.'_spreadsheet_'.&getusymb($safeeval).'_'.          $ENV{'user.domain'}.'_spreadsheet_'.$sheetdata->{'usymb'}.'_'.
            &getfilename($safeeval);             $sheetdata->{'filename'};
     $fn=~s/\W/\_/g;      $fn=~s/\W/\_/g;
     $fn=$tmpdir.$fn.'.tmp';      $fn=$tmpdir.$fn.'.tmp';
     my $fh;      my $fh;
Line 1555  sub tmpwrite { Line 1450  sub tmpwrite {
   
 # ---------------------------------------------------------- Read the temp copy  # ---------------------------------------------------------- Read the temp copy
 sub tmpread {  sub tmpread {
     my ($safeeval,$nfield,$nform)=@_;      my ($safeeval,$sheetdata,$nfield,$nform)=@_;
     my $fn=$ENV{'user.name'}.'_'.      my $fn=$ENV{'user.name'}.'_'.
            $ENV{'user.domain'}.'_spreadsheet_'.&getusymb($safeeval).'_'.             $ENV{'user.domain'}.'_spreadsheet_'.$sheetdata->{'usymb'}.'_'.
            &getfilename($safeeval);             $sheetdata->{'filename'};
     $fn=~s/\W/\_/g;      $fn=~s/\W/\_/g;
     $fn=$tmpdir.$fn.'.tmp';      $fn=$tmpdir.$fn.'.tmp';
     my $fh;      my $fh;
Line 1650  sub parmval { Line 1545  sub parmval {
     my $courselevelr = $usercourseprefix.'.'.$symbparm;      my $courselevelr = $usercourseprefix.'.'.$symbparm;
     my $courselevelm = $usercourseprefix.'.'.$mapparm;      my $courselevelm = $usercourseprefix.'.'.$mapparm;
     # fourth, check user      # fourth, check user
     if ($uname) {       if (defined($uname)) {
         return $useropt{$courselevelr} if ($useropt{$courselevelr});          return $useropt{$courselevelr} if (defined($useropt{$courselevelr}));
         return $useropt{$courselevelm} if ($useropt{$courselevelm});          return $useropt{$courselevelm} if (defined($useropt{$courselevelm}));
         return $useropt{$courselevel}  if ($useropt{$courselevel});          return $useropt{$courselevel}  if (defined($useropt{$courselevel}));
     }      }
     # third, check course      # third, check course
     if ($csec) {      if (defined($csec)) {
         return $courseopt{$seclevelr} if ($courseopt{$seclevelr});          return $courseopt{$seclevelr} if (defined($courseopt{$seclevelr}));
         return $courseopt{$seclevelm} if ($courseopt{$seclevelm});          return $courseopt{$seclevelm} if (defined($courseopt{$seclevelm}));
         return $courseopt{$seclevel}  if ($courseopt{$seclevel});          return $courseopt{$seclevel}  if (defined($courseopt{$seclevel}));
     }      }
     #      #
     return $courseopt{$courselevelr} if ($courseopt{$courselevelr});      return $courseopt{$courselevelr} if (defined($courseopt{$courselevelr}));
     return $courseopt{$courselevelm} if ($courseopt{$courselevelm});      return $courseopt{$courselevelm} if (defined($courseopt{$courselevelm}));
     return $courseopt{$courselevel}  if ($courseopt{$courselevel});      return $courseopt{$courselevel}  if (defined($courseopt{$courselevel}));
     # second, check map parms      # second, check map parms
     my $thisparm = $parmhash{$symbparm};      my $thisparm = $parmhash{$symbparm};
     return $thisparm if ($thisparm);      return $thisparm if (defined($thisparm));
     # first, check default      # first, check default
     return &Apache::lonnet::metadata($fn,$rwhat.'.default');      return &Apache::lonnet::metadata($fn,$rwhat.'.default');
 }  }
Line 1684  sub updateclasssheet { Line 1579  sub updateclasssheet {
   
     #      #
     # Read class list and row labels      # Read class list and row labels
     my %classlist;      my $classlist = &Apache::loncoursedata::get_classlist();
     my @tmp = &Apache::lonnet::dump('classlist',$cdom,$cnum);      if (! defined($classlist)) {
     if ($tmp[0] !~ /^error/) {          return 'Could not access course classlist';
         %classlist = @tmp;      } 
     } else {  
         return 'Could not access course data';  
     }  
     undef @tmp;  
     #      #
     my %currentlist=();      my %currentlist=();
     my $now=time;      foreach my $student (keys(%$classlist)) {
     foreach my $student (keys(%classlist)) {          my ($studentDomain,$studentName,$end,$start,$id,$studentSection,
         my ($end,$start)=split(/\:/,$classlist{$student});              $fullname,$status)   =   @{$classlist->{$student}};
         my $active=1;          if ($ENV{'form.Status'} eq $status || $ENV{'form.Status'} eq 'Any') {
         $active = 0 if (($end) && ($now>$end));  
         $active = 1 if ($ENV{'form.Status'} eq 'Any');  
         $active = !$active if ($ENV{'form.Status'} eq 'Expired');  
         if ($active) {  
             my $rowlabel='';              my $rowlabel='';
             my ($studentName,$studentDomain)=split(/\:/,$student);              if ($ENV{'form.showcsv'}) {
             my $studentSection=&Apache::lonnet::usection($studentDomain,                  $rowlabel= '"'.join('","',($studentName,$studentDomain,
                                                          $studentName,$cid);                                             $fullname,$studentSection,$id).'"');
             $Section{$studentName.':'.$studentDomain} = $studentSection;              } else {
 #            if ($studentSection==-1) {                  $rowlabel='<a href="/adm/studentcalc?uname='.$studentName.
 #                unless ($ENV{'form.showcsv'}) {                      '&udom='.$studentDomain.'">';
 #                    $rowlabel='<font color=red>Data not available: '.                  $rowlabel.=$studentSection.'&nbsp;'.$id."&nbsp;".$fullname;
 #                        $studentName.'</font>';                  $rowlabel.='</a>';
 #                } 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'})  
                                         ).'"';  
                 }  
  #           }  
             $currentlist{$student}=$rowlabel;              $currentlist{$student}=$rowlabel;
         } # end of if ($active)          }
     } # end of foreach my $student (keys(%classlist))      }
     #      #
     # Find discrepancies between the course row table and this      # Find discrepancies between the course row table and this
     #      #
Line 1776  sub updateclasssheet { Line 1634  sub updateclasssheet {
     }      }
     if ($changed) { &setformulas($safeeval,%f); }      if ($changed) { &setformulas($safeeval,%f); }
     #      #
     &setmaxrow($safeeval,$maxrow);      $sheetdata->{'maxrow'} = $maxrow;
     &setrowlabels($safeeval,%currentlist);      &setrowlabels($safeeval,%currentlist);
 }  }
   
Line 1897  sub updatestudentassesssheet { Line 1755  sub updatestudentassesssheet {
         }          }
     }      }
     if ($changed) { &setformulas($safeeval,%f); }      if ($changed) { &setformulas($safeeval,%f); }
     &setmaxrow($safeeval,$maxrow);      $sheetdata->{'maxrow'} = $maxrow;
     &setrowlabels($safeeval,%current);      &setrowlabels($safeeval,%current);
     #      #
     undef %current;      undef %current;
Line 2062  sub loadassessment { Line 1920  sub loadassessment {
     # This is dumb.  It is also necessary :(      # This is dumb.  It is also necessary :(
     my @oldkeys=keys %returnhash;      my @oldkeys=keys %returnhash;
     #      #
     foreach (@oldkeys) {      foreach my $name (@oldkeys) {
         my $name=$_;          my $value=$returnhash{$name};
         my $value=$returnhash{$_};          delete $returnhash{$name};
         delete $returnhash{$_};  
         $name=~s/\_/\./g;          $name=~s/\_/\./g;
         $returnhash{$name}=$value;          $returnhash{$name}=$value;
     }      }
Line 2074  sub loadassessment { Line 1931  sub loadassessment {
     undef %useropt;      undef %useropt;
   
     my $userprefix=$uname.'_'.$udom.'_';      my $userprefix=$uname.'_'.$udom.'_';
       
     unless ($uhome eq 'no_host') {       unless ($uhome eq 'no_host') { 
         # Get coursedata          # Get coursedata
         unless ((time-$courserdatas{$cid.'.last_cache'})<240) {          unless ((time-$courserdatas{$cid.'.last_cache'})<240) {
             my $reply=&Apache::lonnet::reply('dump:'.$cdom.':'.$cnum.              my %Tmp = &Apache::lonnet::dump('resourcedata',$cdom,$cnum);
                                              ':resourcedata',$chome);              $courserdatas{$cid}=\%Tmp;
             if ($reply!~/^error\:/) {              $courserdatas{$cid.'.last_cache'}=time;
                 $courserdatas{$cid}=$reply;  
                 $courserdatas{$cid.'.last_cache'}=time;  
             }  
         }          }
         foreach (split(/\&/,$courserdatas{$cid})) {          while (my ($name,$value) = each(%{$courserdatas{$cid}})) {
             my ($name,$value)=split(/\=/,$_);              $courseopt{$userprefix.$name}=$value;
             $courseopt{$userprefix.&Apache::lonnet::unescape($name)}=  
                 &Apache::lonnet::unescape($value);    
         }          }
         # Get userdata (if present)          # Get userdata (if present)
         unless ((time-$userrdatas{$uname.'___'.$udom.'.last_cache'})<240) {          unless ((time-$userrdatas{$uname.'@'.$udom.'.last_cache'})<240) {
             my $reply=              my %Tmp = &Apache::lonnet::dump('resourcedata',$udom,$uname);
                 &Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome);              $userrdatas{$cid} = \%Tmp;
             if ($reply!~/^error\:/) {              # Most of the time the user does not have a 'resourcedata.db' 
                 $userrdatas{$uname.'___'.$udom}=$reply;              # file.  We need to cache that we got nothing instead of bothering
                 $userrdatas{$uname.'___'.$udom.'.last_cache'}=time;              # with requesting it every time.
             }              $userrdatas{$uname.'@'.$udom.'.last_cache'}=time;
         }          }
         foreach (split(/\&/,$userrdatas{$uname.'___'.$udom})) {          while (my ($name,$value) = each(%{$userrdatas{$cid}})) {
             my ($name,$value)=split(/\=/,$_);              $useropt{$userprefix.$name}=$value;
             $useropt{$userprefix.&Apache::lonnet::unescape($name)}=  
                 &Apache::lonnet::unescape($value);  
         }          }
     }      }
     # now courseopt, useropt initialized for this user and course      # now courseopt, useropt initialized for this user and course
Line 2120  sub loadassessment { Line 1970  sub loadassessment {
     #      #
     my %c=();      my %c=();
     if (tie(%parmhash,'GDBM_File',      if (tie(%parmhash,'GDBM_File',
             &getcoursefilename($safeeval).'_parms.db',&GDBM_READER(),0640)) {              $sheetdata->{'coursefilename'}.'_parms.db',&GDBM_READER(),0640)) {
         my %f=&getformulas($safeeval);          my %f=&getformulas($safeeval);
         foreach (keys(%f))  {          foreach (keys(%f))  {
             next if ($_!~/^A/);              next if ($_!~/^A/);
Line 2289  sub exportsheet { Line 2139  sub exportsheet {
         &readsheet($thissheet,$sheetdata,$fn);          &readsheet($thissheet,$sheetdata,$fn);
         &updatesheet($thissheet,$sheetdata);          &updatesheet($thissheet,$sheetdata);
         &loadrows($thissheet,$sheetdata);          &loadrows($thissheet,$sheetdata);
         &calcsheet($thissheet,$sheetdata);           &calcsheet($thissheet); 
         @exportarr=&exportdata($thissheet,$sheetdata);          @exportarr=&exportdata($thissheet);
         #          #
         # Store now          # Store now
         #          #
Line 2429  sub cachedssheets { Line 2279  sub cachedssheets {
 sub handler {  sub handler {
     my $r=shift;      my $r=shift;
   
       if (! exists($ENV{'form.Status'})) {
           $ENV{'form.Status'} = 'Active';
       }
       # Check this server
     my $loaderror=&Apache::lonnet::overloaderror($r);      my $loaderror=&Apache::lonnet::overloaderror($r);
     if ($loaderror) { return $loaderror; }      if ($loaderror) { return $loaderror; }
       # Check the course homeserver
     $loaderror= &Apache::lonnet::overloaderror($r,      $loaderror= &Apache::lonnet::overloaderror($r,
                       $ENV{'course.'.$ENV{'request.course.id'}.'.home'});                        $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
     if ($loaderror) { return $loaderror; }       if ($loaderror) { return $loaderror; } 
       
     if ($r->header_only) {      if ($r->header_only) {
         $r->content_type('text/html');          $r->content_type('text/html');
         $r->send_http_header;          $r->send_http_header;
Line 2531  ENDSCRIPT Line 2386  ENDSCRIPT
     }      }
     # Read new sheet or modified worksheet      # Read new sheet or modified worksheet
     $r->uri=~/\/(\w+)$/;      $r->uri=~/\/(\w+)$/;
     my ($asheet,$asheetdata)=&makenewsheet($aname,$adom,$1,$ENV{'form.usymb'});      my ($sheet,$sheetdata)=&makenewsheet($aname,$adom,$1,$ENV{'form.usymb'});
     #      #
     # If a new formula had been entered, go from work copy      # If a new formula had been entered, go from work copy
     if ($ENV{'form.unewfield'}) {      if ($ENV{'form.unewfield'}) {
Line 2539  ENDSCRIPT Line 2394  ENDSCRIPT
         $ENV{'form.unewformula'}=~s/\'/\"/g;          $ENV{'form.unewformula'}=~s/\'/\"/g;
         $r->print('<p>New formula: '.$ENV{'form.unewfield'}.'='.          $r->print('<p>New formula: '.$ENV{'form.unewfield'}.'='.
                   $ENV{'form.unewformula'}.'<p>');                    $ENV{'form.unewformula'}.'<p>');
         &setfilename($asheet,$ENV{'form.ufn'});          $sheetdata->{'filename'} = $ENV{'form.ufn'};
         &tmpread($asheet,$ENV{'form.unewfield'},$ENV{'form.unewformula'});          &tmpread($sheet,$sheetdata,
                    $ENV{'form.unewfield'},$ENV{'form.unewformula'});
     } elsif ($ENV{'form.saveas'}) {      } elsif ($ENV{'form.saveas'}) {
         &setfilename($asheet,$ENV{'form.ufn'});          $sheetdata->{'filename'} = $ENV{'form.ufn'};
         &tmpread($asheet);          &tmpread($sheet,$sheetdata);
     } else {      } else {
         &readsheet($asheet,$asheetdata,$ENV{'form.ufn'});          &readsheet($sheet,$sheetdata,$ENV{'form.ufn'});
     }      }
     # Print out user information      # Print out user information
     unless ($asheetdata->{'sheettype'} eq 'classcalc') {      unless ($sheetdata->{'sheettype'} eq 'classcalc') {
         $r->print('<p><b>User:</b> '.$asheetdata->{'uname'}.          $r->print('<p><b>User:</b> '.$sheetdata->{'uname'}.
                   '<br><b>Domain:</b> '.$asheetdata->{'udom'});                    '<br><b>Domain:</b> '.$sheetdata->{'udom'});
 #        if (&getcsec($asheet) eq '-1') {          $r->print('<br><b>Section/Group:</b> '.$sheetdata->{'csec'});
 #            $r->print('<h3><font color=red>'.  
 #                      'Not a student in this course</font></h3>');  
 #        } else {  
             $r->print('<br><b>Section/Group:</b> '.$asheetdata->{'csec'});  
 #        }  
         if ($ENV{'form.usymb'}) {          if ($ENV{'form.usymb'}) {
             $r->print('<br><b>Assessment:</b> <tt>'.              $r->print('<br><b>Assessment:</b> <tt>'.
                       $ENV{'form.usymb'}.'</tt>');                        $ENV{'form.usymb'}.'</tt>');
Line 2564  ENDSCRIPT Line 2415  ENDSCRIPT
     }      }
     #      #
     # Check user permissions      # Check user permissions
     if (($asheetdata->{'sheettype'} eq 'classcalc'       ) ||       if (($sheetdata->{'sheettype'} eq 'classcalc'       ) || 
         ($asheetdata->{'uname'}     ne $ENV{'user.name'} ) ||          ($sheetdata->{'uname'}     ne $ENV{'user.name'} ) ||
         ($asheetdata->{'udom'}      ne $ENV{'user.domain'})) {          ($sheetdata->{'udom'}      ne $ENV{'user.domain'})) {
         unless (&Apache::lonnet::allowed('vgr',$asheetdata->{'cid'})) {          unless (&Apache::lonnet::allowed('vgr',$sheetdata->{'cid'})) {
             $r->print('<h1>Access Permission Denied</h1>'.              $r->print('<h1>Access Permission Denied</h1>'.
                       '</form></body></html>');                        '</form></body></html>');
             return OK;              return OK;
Line 2577  ENDSCRIPT Line 2428  ENDSCRIPT
     $r->print('<br />'.      $r->print('<br />'.
               '<input type="submit" name="forcerecalc" '.                '<input type="submit" name="forcerecalc" '.
               'value="Completely Recalculate Sheet"><p>');                'value="Completely Recalculate Sheet"><p>');
     if ($asheetdata->{'sheettype'} eq 'assesscalc') {      if ($sheetdata->{'sheettype'} eq 'assesscalc') {
         $r->print('<p><font size=+2>'.          $r->print('<p><font size=+2>'.
                   '<a href="/adm/studentcalc?'.                    '<a href="/adm/studentcalc?'.
                   'uname='.$asheetdata->{'uname'}.                    'uname='.$sheetdata->{'uname'}.
                   '&udom='.$asheetdata->{'udom'}.'">'.                    '&udom='.$sheetdata->{'udom'}.'">'.
                   'Level up: Student Sheet</a></font><p>');                    'Level up: Student Sheet</a></font><p>');
     }      }
     if (($asheetdata->{'sheettype'} eq 'studentcalc') &&       if (($sheetdata->{'sheettype'} eq 'studentcalc') && 
         (&Apache::lonnet::allowed('vgr',$asheetdata->{'cid'}))) {          (&Apache::lonnet::allowed('vgr',$sheetdata->{'cid'}))) {
         $r->print ('<p><font size=+2><a href="/adm/classcalc">'.          $r->print ('<p><font size=+2><a href="/adm/classcalc">'.
                    'Level up: Course Sheet</a></font><p>');                     'Level up: Course Sheet</a></font><p>');
     }      }
Line 2598  ENDSCRIPT Line 2449  ENDSCRIPT
                   '<input type=text size=20 name=newfn value="'.$fname.'">'.                    '<input type=text size=20 name=newfn value="'.$fname.'">'.
                   'make default: <input type=checkbox name="makedefufn"><p>');                    'make default: <input type=checkbox name="makedefufn"><p>');
     }      }
     $r->print(&hiddenfield('ufn',&getfilename($asheet)));      $r->print(&hiddenfield('ufn',$sheetdata->{'filename'}));
     # Load dialog      # Load dialog
     if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {      if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
         $r->print('<p><input type=submit name=load value="Load ...">'.          $r->print('<p><input type=submit name=load value="Load ...">'.
                   '<select name="loadthissheet">'.                    '<select name="loadthissheet">'.
                   '<option name="default">Default</option>');                    '<option name="default">Default</option>');
         foreach (&othersheets($asheet,$asheetdata->{'sheettype'})) {          foreach (&othersheets($sheet,$sheetdata->{'sheettype'},$sheetdata)) {
             $r->print('<option name="'.$_.'"');              $r->print('<option name="'.$_.'"');
             if ($ENV{'form.ufn'} eq $_) {              if ($ENV{'form.ufn'} eq $_) {
                 $r->print(' selected');                  $r->print(' selected');
Line 2612  ENDSCRIPT Line 2463  ENDSCRIPT
             $r->print('>'.$_.'</option>');              $r->print('>'.$_.'</option>');
         }           } 
         $r->print('</select><p>');          $r->print('</select><p>');
         if ($asheetdata->{'sheettype'} eq 'studentcalc') {          if ($sheetdata->{'sheettype'} eq 'studentcalc') {
             &setothersheets($asheet,&othersheets($asheet,'assesscalc'));              &setothersheets($sheet,
                               &othersheets($sheet,'assesscalc',$sheetdata));
         }          }
     }      }
     # Cached sheets      # Cached sheets
     &expirationdates();      &expirationdates();
     undef %oldsheets;      undef %oldsheets;
     undef %loadedcaches;      undef %loadedcaches;
     if ($asheetdata->{'sheettype'} eq 'classcalc') {      if ($sheetdata->{'sheettype'} eq 'classcalc') {
         $r->print("Loading previously calculated student sheets ...\n");          $r->print("Loading previously calculated student sheets ...\n");
         $r->rflush();          $r->rflush();
         &cachedcsheets();          &cachedcsheets();
     } elsif ($asheetdata->{'sheettype'} eq 'studentcalc') {      } elsif ($sheetdata->{'sheettype'} eq 'studentcalc') {
         $r->print("Loading previously calculated assessment sheets ...\n");          $r->print("Loading previously calculated assessment sheets ...\n");
         $r->rflush();          $r->rflush();
         &cachedssheets($asheetdata->{'uname'},$asheetdata->{'udom'},          &cachedssheets($sheetdata->{'uname'},$sheetdata->{'udom'},
                        $asheetdata->{'uhome'});                         $sheetdata->{'uhome'});
     }      }
     # Update sheet, load rows      # Update sheet, load rows
     $r->print("Loaded sheet(s), updating rows ...<br>\n");      $r->print("Loaded sheet(s), updating rows ...<br>\n");
     $r->rflush();      $r->rflush();
     #      #
     &updatesheet($asheet,$asheetdata);      &updatesheet($sheet,$sheetdata);
     $r->print("Updated rows, loading row data ...\n");      $r->print("Updated rows, loading row data ...\n");
     $r->rflush();      $r->rflush();
     #      #
     &loadrows($asheet,$asheetdata,$r);      &loadrows($sheet,$sheetdata,$r);
     $r->print("Loaded row data, calculating sheet ...<br>\n");      $r->print("Loaded row data, calculating sheet ...<br>\n");
     $r->rflush();      $r->rflush();
     #      #
     my $calcoutput=&calcsheet($asheet);      my $calcoutput=&calcsheet($sheet);
     $r->print('<h3><font color=red>'.$calcoutput.'</h3></font>');      $r->print('<h3><font color=red>'.$calcoutput.'</h3></font>');
     # See if something to save      # See if something to save
     if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {      if (&Apache::lonnet::allowed('opa',$ENV{'request.course.id'})) {
Line 2650  ENDSCRIPT Line 2502  ENDSCRIPT
         if ($ENV{'form.saveas'} && ($fname=$ENV{'form.newfn'})) {          if ($ENV{'form.saveas'} && ($fname=$ENV{'form.newfn'})) {
             $fname=~s/\W/\_/g;              $fname=~s/\W/\_/g;
             if ($fname eq 'default') { $fname='course_default'; }              if ($fname eq 'default') { $fname='course_default'; }
             $fname.='_'.$asheetdata->{'sheettype'};              $fname.='_'.$sheetdata->{'sheettype'};
             &setfilename($asheet,$fname);              $sheetdata->{'filename'} = $fname;
             $ENV{'form.ufn'}=$fname;              $ENV{'form.ufn'}=$fname;
             $r->print('<p>Saving spreadsheet: '.              $r->print('<p>Saving spreadsheet: '.
                       &writesheet($asheet,$ENV{'form.makedefufn'}).'<p>');                        &writesheet($sheet,$ENV{'form.makedefufn'},$sheetdata).
                         '<p>');
         }          }
     }      }
     #      #
     #Write the modified worksheet      # Write the modified worksheet
     $r->print('<b>Current sheet:</b> '.&getfilename($asheet).'<p>');      $r->print('<b>Current sheet:</b> '.$sheetdata->{'filename'}.'<p>');
     &tmpwrite($asheet);      &tmpwrite($sheet,$sheetdata);
     if ($asheetdata->{'sheettype'} eq 'studentcalc') {      if ($sheetdata->{'sheettype'} eq 'studentcalc') {
         $r->print('<br>Show rows with empty A column: ');          $r->print('<br>Show rows with empty A column: ');
     } else {      } else {
         $r->print('<br>Show empty rows: ');          $r->print('<br>Show empty rows: ');
Line 2684  ENDSCRIPT Line 2537  ENDSCRIPT
     $r->print('>');      $r->print('>');
     #      #
     # CSV format checkbox (classcalc sheets only)      # CSV format checkbox (classcalc sheets only)
     if ($asheetdata->{'sheettype'} eq 'classcalc') {      if ($sheetdata->{'sheettype'} eq 'classcalc') {
         $r->print(' Output CSV format: <input type="checkbox" '.          $r->print(' Output CSV format: <input type="checkbox" '.
                   'name="showcsv" onClick="submit()"');                    'name="showcsv" onClick="submit()"');
         if ($ENV{'form.showcsv'}) { $r->print(' checked'); }          if ($ENV{'form.showcsv'}) { $r->print(' checked'); }
Line 2703  value='Insert Row Top'> Line 2556  value='Insert Row Top'>
 value='Insert Row Bottom'><br>  value='Insert Row Bottom'><br>
 ENDINSERTBUTTONS  ENDINSERTBUTTONS
     # Print out sheet      # Print out sheet
     &outsheet($r,$asheet,$asheetdata);      &outsheet($r,$sheet,$sheetdata);
     $r->print('</form></body></html>');      $r->print('</form></body></html>');
     #  Done      #  Done
     return OK;      return OK;

Removed from v.1.113  
changed lines
  Added in v.1.118


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>