Diff for /loncom/interface/Attic/lonspreadsheet.pm between versions 1.38 and 1.43

version 1.38, 2001/01/22 22:54:16 version 1.43, 2001/03/12 18:27:46
Line 3 Line 3
 #  #
 # 11/11,11/15,11/27,12/04,12/05,12/06,12/07,  # 11/11,11/15,11/27,12/04,12/05,12/06,12/07,
 # 12/08,12/09,12/11,12/12,12/15,12/16,12/18,12/19,12/30,  # 12/08,12/09,12/11,12/12,12/15,12/16,12/18,12/19,12/30,
 # 01/01/01,02/01,03/01,19/01,20/01,22/01 Gerd Kortemeyer  # 01/01/01,02/01,03/01,19/01,20/01,22/01,
   # 03/05,03/08,03/10,03/12 Gerd Kortemeyer
   
 package Apache::lonspreadsheet;  package Apache::lonspreadsheet;
                           
Line 17  use GDBM_File; Line 18  use GDBM_File;
 use HTML::TokeParser;  use HTML::TokeParser;
   
 #  #
   # Cache for stores of an individual user
   #
   
   my $cachedassess;
   my %cachedstores;
   
   #
 # These cache hashes need to be independent of user, resource and course  # These cache hashes need to be independent of user, resource and course
 # (user and course can/should be in the keys)  # (user and course can/should be in the keys)
 #  #
Line 40  my %parmhash; Line 48  my %parmhash;
 my $includedir;  my $includedir;
 my $tmpdir;  my $tmpdir;
   
   
 sub mdeb {  
     my $msg=shift;  
     my $mem='';  
     {  
  my $mfh=Apache::File->new('/proc/'.$$.'/status');  
         my $line;  
         while ($line=<$mfh>) {  
             my ($name,$value)=split(/\:/,$line);  
     if ($name eq 'VmSize') { $mem=$value; }  
         }  
         $mfh->close();  
     }  
     print $msg.$mem."<br>\n";  
 }  
   
   
   
   
 # =============================================================================  # =============================================================================
 # ===================================== Implements an instance of a spreadsheet  # ===================================== Implements an instance of a spreadsheet
   
Line 328  sub sett { Line 317  sub sett {
                     $t{$lb}=~s/\#/$trow/g;                      $t{$lb}=~s/\#/$trow/g;
                     $t{$lb}=~s/\.\.+/\,/g;                      $t{$lb}=~s/\.\.+/\,/g;
                     $t{$lb}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$v\{\'$2\'\}/g;                      $t{$lb}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$v\{\'$2\'\}/g;
                     $t{$lb}=~s/(^|[^\"\'])\[([\w\.]+)\]/$1\$c\{\'$2\'\}/g;                      $t{$lb}=~s/(^|[^\"\'])\[(\w+)\]/$1\$c\{\'$2\'\}/g;
                 }                  }
       }        }
             } keys %f;              } keys %f;
Line 337  sub sett { Line 326  sub sett {
     } keys %f;      } keys %f;
     map {      map {
  if (($f{$_}) && ($_!~/template\_/)) {   if (($f{$_}) && ($_!~/template\_/)) {
             if ($_=~/^$pattern/) {              my $matches=($_=~/^$pattern(\d+)/);
               if  (($matches) && ($1)) {
         unless ($f{$_}=~/^\!/) {          unless ($f{$_}=~/^\!/) {
     $t{$_}=$c{$_};      $t{$_}=$c{$_};
                 }                  }
Line 1114  sub updatestudentassesssheet { Line 1104  sub updatestudentassesssheet {
                           my $display=                            my $display=
       &Apache::lonnet::metadata($srcf,$key.'.display');        &Apache::lonnet::metadata($srcf,$key.'.display');
                           unless ($display) {                            unless ($display) {
                               $display=                                $display.=
          &Apache::lonnet::metadata($srcf,$key.'.name');           &Apache::lonnet::metadata($srcf,$key.'.name');
                           }                            }
                             $display.='<br>'.$key;
                           $allkeys{$key}=$display;                            $allkeys{$key}=$display;
        }         }
                    } split(/\,/,&Apache::lonnet::metadata($srcf,'keys'));                     } split(/\,/,&Apache::lonnet::metadata($srcf,'keys'));
Line 1191  sub loadstudent { Line 1182  sub loadstudent {
     my $safeeval=shift;      my $safeeval=shift;
     my %c=();      my %c=();
     my %f=&getformulas($safeeval);      my %f=&getformulas($safeeval);
       $cachedassess=&getuname($safeeval).':'.&getudom($safeeval);
       %cachedstores=();
       {
         my $reply=&Apache::lonnet::reply('dump:'.&getudom($safeeval).':'.
                                                  &getuname($safeeval).':'.
                                                  &getcid($safeeval),
                                                  &getuhome($safeeval));
         unless ($reply=~/^error\:/) {
            map {
               my ($name,$value)=split(/\=/,$_);
               $cachedstores{&Apache::lonnet::unescape($name)}=
                     &Apache::lonnet::unescape($value);
            } split(/\&/,$reply);
         }
       }
     my @assessdata=();      my @assessdata=();
     map {      map {
  if ($_=~/^A(\d+)/) {   if ($_=~/^A(\d+)/) {
    my $row=$1;     my $row=$1;
            unless ($f{$_}=~/^\!/) {             unless (($f{$_}=~/^\!/) || ($row==0)) {
       @assessdata=&exportsheet(&getuname($safeeval),        @assessdata=&exportsheet(&getuname($safeeval),
                                        &getudom($safeeval),                                         &getudom($safeeval),
                                        'assesscalc',$f{$_});                                         'assesscalc',$f{$_});
               my $index=0;                my $index=0;
               map {                map {
                   if ($assessdata[$index]) {                    if ($assessdata[$index]) {
      $c{$_.$row}=$assessdata[$index];       my $col=$_;
                      unless ($_ eq 'A') {        if ($assessdata[$index]=~/\D/) {
  $f{$_.$row}='import';                           $c{$col.$row}="'".$assessdata[$index]."'";
         } else {
            $c{$col.$row}=$assessdata[$index];
        }
                        unless ($col eq 'A') { 
    $f{$col.$row}='import';
                      }                       }
   }    }
                   $index++;                    $index++;
Line 1213  sub loadstudent { Line 1224  sub loadstudent {
    }     }
         }          }
     } keys %f;      } keys %f;
       $cachedassess='';
       undef %cachedstores;
     &setformulas($safeeval,%f);      &setformulas($safeeval,%f);
     &setconstants($safeeval,%c);      &setconstants($safeeval,%c);
 }  }
Line 1231  sub loadcourse { Line 1244  sub loadcourse {
     } keys %f;      } keys %f;
     my $now=0;      my $now=0;
     my $since=time;      my $since=time;
     $r->print('<br><input type=text size=35 name=remaining value=Starting>'.      $r->print(<<ENDPOP);
               "<br><font size=0>\n");  <script>
       popwin=open('','popwin','width=400,height=100');
       popwin.document.writeln('<html><body bgcolor="#FFFFFF">'+
         '<h1>Spreadsheet Calculation Progress</h1>'+
         '<form name=popremain>'+
         '<input type=text size=35 name=remaining value=Starting></form>'+
         '</body></html>');
       popwin.document.close();
   </script>
   ENDPOP
     $r->rflush();      $r->rflush();
     map {      map {
  if ($_=~/^A(\d+)/) {   if ($_=~/^A(\d+)/) {
    my $row=$1;     my $row=$1;
            unless ($f{$_}=~/^\!/) {             unless (($f{$_}=~/^\!/)  || ($row==0)) {
       my @studentdata=&exportsheet(split(/\:/,$f{$_}),        my @studentdata=&exportsheet(split(/\:/,$f{$_}),
                                            'studentcalc');                                             'studentcalc');
               undef %userrdatas;                undef %userrdatas;
               $now++;                $now++;
               $r->print('<script>document.sheet.remaining.value="'.                $r->print('<script>popwin.document.popremain.remaining.value="'.
                   $now.'/'.$total.': '.int((time-$since)/$now*($total-$now)).                    $now.'/'.$total.': '.int((time-$since)/$now*($total-$now)).
                         ' secs remaining";</script>'."<br>\n");                          ' secs remaining";</script>');
               $r->rflush();                 $r->rflush(); 
   
               my $index=0;                my $index=0;
               map {                map {
                   if ($studentdata[$index]) {                    if ($studentdata[$index]) {
      $c{$_.$row}=$studentdata[$index];       my $col=$_;
                      unless ($_ eq 'A') {        if ($studentdata[$index]=~/\D/) {
  $f{$_.$row}='import';                           $c{$col.$row}="'".$studentdata[$index]."'";
         } else {
            $c{$col.$row}=$studentdata[$index];
        }
                        unless ($col eq 'A') { 
    $f{$col.$row}='import';
                      }                       }
   }    }
                   $index++;                    $index++;
Line 1263  sub loadcourse { Line 1290  sub loadcourse {
     } keys %f;      } keys %f;
     &setformulas($safeeval,%f);      &setformulas($safeeval,%f);
     &setconstants($safeeval,%c);      &setconstants($safeeval,%c);
     $r->print('<script>document.sheet.remaining.value="Done";</script>'.      $r->print('<script>popwin.close()</script>');
               "<br>\n</font>");  
     $r->rflush();       $r->rflush(); 
 }  }
   
Line 1286  sub loadassessment { Line 1312  sub loadassessment {
     unless ($namespace=$cid) { return ''; }      unless ($namespace=$cid) { return ''; }
   
 # ----------------------------------------------------------- Get stored values  # ----------------------------------------------------------- Get stored values
   
      my %returnhash=();
   
      if ($cachedassess eq $uname.':'.$udom) {
   #
   # get data out of the dumped stores
   # 
   
          my $version=$cachedstores{'version:'.$symb};
          my $scope;
          for ($scope=1;$scope<=$version;$scope++) {
              map {
                  $returnhash{$_}=$cachedstores{$scope.':'.$symb.':'.$_};
              } split(/\:/,$cachedstores{$scope.':keys:'.$symb}); 
          }
   
      } else {
   #
   # restore individual
   #
   
     my $answer=&Apache::lonnet::reply(      my $answer=&Apache::lonnet::reply(
        "restore:$udom:$uname:".         "restore:$udom:$uname:".
        &Apache::lonnet::escape($namespace).":".         &Apache::lonnet::escape($namespace).":".
        &Apache::lonnet::escape($symb),$uhome);         &Apache::lonnet::escape($symb),$uhome);
   
     my %returnhash=();  
     map {      map {
  my ($name,$value)=split(/\=/,$_);   my ($name,$value)=split(/\=/,$_);
         $returnhash{&Apache::lonnet::unescape($name)}=          $returnhash{&Apache::lonnet::unescape($name)}=
Line 1303  sub loadassessment { Line 1348  sub loadassessment {
           $returnhash{$_}=$returnhash{$version.':'.$_};            $returnhash{$_}=$returnhash{$version.':'.$_};
        } split(/\:/,$returnhash{$version.':keys'});         } split(/\:/,$returnhash{$version.':keys'});
     }      }
      }
 # ----------------------------- returnhash now has all stores for this resource  # ----------------------------- returnhash now has all stores for this resource
   
 # ---------------------------- initialize coursedata and userdata for this user  # ---------------------------- initialize coursedata and userdata for this user
Line 1356  sub loadassessment { Line 1401  sub loadassessment {
  if ($_=~/^A/) {   if ($_=~/^A/) {
             unless ($f{$_}=~/^\!/) {              unless ($f{$_}=~/^\!/) {
         if ($f{$_}=~/^parameter/) {          if ($f{$_}=~/^parameter/) {
           $c{$_}=&parmval($f{$_},$safeeval);                    my $val=&parmval($f{$_},$safeeval);
                     $c{$_}=$val;
                     $c{$f{$_}}=$val;
        } else {         } else {
   my $key=$f{$_};    my $key=$f{$_};
                     my $ckey=$key;
                   $key=~s/^stores\_/resource\./;                    $key=~s/^stores\_/resource\./;
                   $key=~s/\_/\./;                    $key=~s/\_/\./;
            $c{$_}=$returnhash{$key};             $c{$_}=$returnhash{$key};
                   $c{$key}=$returnhash{$key};                    $c{$ckey}=$returnhash{$key};
        }         }
    }     }
         }          }
Line 1634  ENDSCRIPT Line 1682  ENDSCRIPT
     &outsheet($r,$asheet);      &outsheet($r,$asheet);
     $r->print('</form></body></html>');      $r->print('</form></body></html>');
   
 # --------------------------------- We know this leaks, so terminate this child  
   
     $r->child_terminate();  
   
 # ------------------------------------------------------------------------ Done  # ------------------------------------------------------------------------ Done
   } else {    } else {
 # ----------------------------- Not in a course, or not allowed to modify parms  # ----------------------------- Not in a course, or not allowed to modify parms

Removed from v.1.38  
changed lines
  Added in v.1.43


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