Diff for /loncom/interface/Attic/lonspreadsheet.pm between versions 1.40 and 1.45

version 1.40, 2001/03/08 23:22:11 version 1.45, 2001/03/17 16:52:30
Line 4 Line 4
 # 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,  # 01/01/01,02/01,03/01,19/01,20/01,22/01,
 # 03/05,03/08 Gerd Kortemeyer  # 03/05,03/08,03/10,03/12,03/13,03/15,03/17 Gerd Kortemeyer
   
 package Apache::lonspreadsheet;  package Apache::lonspreadsheet;
                           
Line 18  use GDBM_File; Line 18  use GDBM_File;
 use HTML::TokeParser;  use HTML::TokeParser;
   
 #  #
   # Caches for previously calculated spreadsheets
   #
   
   my %oldsheets;
   
   #
 # Cache for stores of an individual user  # Cache for stores of an individual user
 #  #
   
Line 326  sub sett { Line 332  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 1018  sub updateclasssheet { Line 1025  sub updateclasssheet {
                     my $reply=&Apache::lonnet::reply('get:'.$sdom.':'.$sname.                      my $reply=&Apache::lonnet::reply('get:'.$sdom.':'.$sname.
       ':environment:firstname&middlename&lastname&generation',        ':environment:firstname&middlename&lastname&generation',
                       &Apache::lonnet::homeserver($sname,$sdom));                        &Apache::lonnet::homeserver($sname,$sdom));
                     $rowlabel=$ssec.'&nbsp;'.$reply{$sname}.'<br>';                      $rowlabel='<a href="/adm/studentcalc?uname='.$sname.
                                 '&udom='.$sdom.'">'.
                                 $ssec.'&nbsp;'.$reply{$sname}.'<br>';
                     map {                      map {
                         $rowlabel.=&Apache::lonnet::unescape($_).' ';                          $rowlabel.=&Apache::lonnet::unescape($_).' ';
                     } split(/\&/,$reply);                      } split(/\&/,$reply);
                       $rowlabel.='</a>';
                 }                  }
  $currentlist{&Apache::lonnet::unescape($name)}=$rowlabel;   $currentlist{&Apache::lonnet::unescape($name)}=$rowlabel;
             }              }
Line 1200  sub loadstudent { Line 1210  sub loadstudent {
     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 1246  sub loadcourse { Line 1261  sub loadcourse {
       '<form name=popremain>'+        '<form name=popremain>'+
       '<input type=text size=35 name=remaining value=Starting></form>'+        '<input type=text size=35 name=remaining value=Starting></form>'+
       '</body></html>');        '</body></html>');
     popwin.document.close;      popwin.document.close();
 </script>  </script>
 ENDPOP  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;
Line 1266  ENDPOP Line 1281  ENDPOP
               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 1279  ENDPOP Line 1299  ENDPOP
     } keys %f;      } keys %f;
     &setformulas($safeeval,%f);      &setformulas($safeeval,%f);
     &setconstants($safeeval,%c);      &setconstants($safeeval,%c);
     $r->print('<script>popwin.close</script>');      $r->print('<script>popwin.close()</script>');
     $r->rflush();       $r->rflush(); 
 }  }
   
Line 1471  sub loadrows { Line 1491  sub loadrows {
 #  #
   
 sub exportsheet {  sub exportsheet {
     my ($uname,$udom,$stype,$usymb,$fn)=@_;
     my ($uname,$udom,$stype,$usymb,$fn)=@_;   my @exportarr=();
   #
   # Check if cached
   #
    my $key=$uname.':'.$udom.':'.$stype.':'.$usymb;
    my $found='';
   
    if ($oldsheets{$key}) {
        map {
            my ($name,$value)=split(/\_\_\_\=\_\_\_/,$_);
            if ($name eq $fn) {
        $found=$value;
            }
        } split(/\_\_\_\&\_\_\_/,$oldsheets{$key});
    }
   
    if ($found) {
   #
   # Return what was cached
   #
        @exportarr=split(/\_\_\_\;\_\_\_/,$found);
   
    } else {
   #
   # Not cached
   # 
     my $thissheet=&makenewsheet($uname,$udom,$stype,$usymb);      my $thissheet=&makenewsheet($uname,$udom,$stype,$usymb);
     &readsheet($thissheet,$fn);      &readsheet($thissheet,$fn);
     &updatesheet($thissheet);      &updatesheet($thissheet);
     &loadrows($thissheet);      &loadrows($thissheet);
     &calcsheet($thissheet);      &calcsheet($thissheet); 
     return &exportdata($thissheet);      @exportarr=&exportdata($thissheet);
   #
   # Store now
   #
       my $cid=$ENV{'request.course.id'}; 
       my $current=&Apache::lonnet::reply('get:'.
                                        $ENV{'course.'.$cid.'.domain'}.':'.
                                        $ENV{'course.'.$cid.'.num'}.
        ':nohist_calculatedsheets:'.
                                        &Apache::lonnet::escape($key),
                                        $ENV{'course.'.$cid.'.home'});
       my %currentlystored=();
       unless ($current=~/^error\:/) {
          map {
              my ($name,$value)=split(/\_\_\_\=\_\_\_/,$_);
              $currentlystored{$name}=$value;
          } split(/\_\_\_\&\_\_\_/,&Apache::lonnet::unescape($current));
       }
       $currentlystored{$fn}=join('___;___',@exportarr);
   
       my $newstore='';
       map {
           if ($newstore) { $newstore.='___&___'; }
           $newstore.=$_.'___=___'.$currentlystored{$_};
       } keys %currentlystored;
       &Apache::lonnet::reply('put:'.
                            $ENV{'course.'.$cid.'.domain'}.':'.
                            $ENV{'course.'.$cid.'.num'}.
    ':nohist_calculatedsheets:'.
                            &Apache::lonnet::escape($key).'='.
    &Apache::lonnet::escape($newstore),
                            $ENV{'course.'.$cid.'.home'});
    }
    return @exportarr;
   }
   
   # ===================================================== Calculated sheets cache
   #
   # Load all previously cached spreadsheets for this course
   #
   
   sub cachedsheets {
       my $cid=$ENV{'request.course.id'};
       my $reply=&Apache::lonnet::reply('dump:'.
        $ENV{'course.'.$cid.'.domain'}.':'.
                                        $ENV{'course.'.$cid.'.num'}.
        ':nohist_calculatedsheets',
                                        $ENV{'course.'.$cid.'.home'});
       undef %oldsheets;
       unless ($reply=~/^error\:/) {
    map {
               my ($name,$value)=split(/\=/,$_);
               $oldsheets{&Apache::lonnet::unescape($name)}
                         =&Apache::lonnet::unescape($value);
           } split(/\&/,$reply);
       }
 }  }
   
 # ================================================================ Main handler  # ================================================================ Main handler
Line 1649  ENDSCRIPT Line 1749  ENDSCRIPT
   
     $r->print(&hiddenfield('ufn',&getfilename($asheet)));      $r->print(&hiddenfield('ufn',&getfilename($asheet)));
   
   # ----------------------------------------------------------- Get cached sheets
   
       &cachedsheets();
   
 # ----------------------------------------------------- Update sheet, load rows  # ----------------------------------------------------- Update sheet, load rows
   
     $r->print("Loaded sheet, updating rows ...<br>\n");      $r->print("Loaded sheet(s), updating rows ...<br>\n");
     $r->rflush();      $r->rflush();
   
     &updatesheet($asheet);      &updatesheet($asheet);
Line 1684  ENDSCRIPT Line 1787  ENDSCRIPT
   
 1;  1;
 __END__  __END__
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   

Removed from v.1.40  
changed lines
  Added in v.1.45


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