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

version 1.45, 2001/03/17 16:52:30 version 1.53, 2001/04/05 21:35:02
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,03/10,03/12,03/13,03/15,03/17 Gerd Kortemeyer  # 03/05,03/08,03/10,03/12,03/13,03/15,03/17,
   # 03/19,03/20,03/21,03/27,04/05 Gerd Kortemeyer
   
 package Apache::lonspreadsheet;  package Apache::lonspreadsheet;
                           
Line 22  use HTML::TokeParser; Line 23  use HTML::TokeParser;
 #  #
   
 my %oldsheets;  my %oldsheets;
   my %loadedcaches;
   my %expiredates;
   
 #  #
 # Cache for stores of an individual user  # Cache for stores of an individual user
Line 1090  sub updatestudentassesssheet { Line 1093  sub updatestudentassesssheet {
                        &GDBM_READER,0640)) {                         &GDBM_READER,0640)) {
 # --------------------------------------------------------- Get all assessments  # --------------------------------------------------------- Get all assessments
   
  my %allkeys=();   my %allkeys=('timestamp' => 
                        'Timestamp of Last Transaction<br>timestamp');
         my %allassess=();          my %allassess=();
   
           my $adduserstr='';
           if ((&getuname($safeeval) ne $ENV{'user.name'}) ||
               (&getudom($safeeval) ne $ENV{'user.domain'})) {
               $adduserstr='&uname='.&getuname($safeeval).
    '&udom='.&getudom($safeeval);
           }
   
         map {          map {
     if ($_=~/^src\_(\d+)\.(\d+)$/) {      if ($_=~/^src\_(\d+)\.(\d+)$/) {
        my $mapid=$1;         my $mapid=$1;
Line 1105  sub updatestudentassesssheet { Line 1116  sub updatestudentassesssheet {
     '___'.$resid.'___'.      '___'.$resid.'___'.
     &Apache::lonnet::declutter($srcf);      &Apache::lonnet::declutter($srcf);
  $allassess{$symb}=   $allassess{$symb}=
     '<a href="/adm/assesscalc?usymb='.$symb.'">'.$bighash{'title_'.$id}.'</a>';              '<a href="/adm/assesscalc?usymb='.$symb.$adduserstr.'">'.
                        $bighash{'title_'.$id}.'</a>';
                  if ($stype eq 'assesscalc') {                   if ($stype eq 'assesscalc') {
                    map {                     map {
                        if (($_=~/^stores\_(.*)/) || ($_=~/^parameter\_(.*)/)) {                         if (($_=~/^stores\_(.*)/) || ($_=~/^parameter\_(.*)/)) {
Line 1257  sub loadcourse { Line 1269  sub loadcourse {
 <script>  <script>
     popwin=open('','popwin','width=400,height=100');      popwin=open('','popwin','width=400,height=100');
     popwin.document.writeln('<html><body bgcolor="#FFFFFF">'+      popwin.document.writeln('<html><body bgcolor="#FFFFFF">'+
       '<h1>Spreadsheet Calculation Progress</h1>'+        '<h3>Spreadsheet Calculation Progress</h3>'+
       '<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>');
Line 1485  sub loadrows { Line 1497  sub loadrows {
     }      }
 }  }
   
   # ======================================================= Forced recalculation?
   
   sub checkthis {
       my ($keyname,$time)=@_;
       return ($time<$expiredates{$keyname});
   }
   sub forcedrecalc {
       my ($uname,$udom,$stype,$usymb)=@_;
       my $key=$uname.':'.$udom.':'.$stype.':'.$usymb;
       my $time=$oldsheets{$key.'.time'};
       if ($ENV{'form.forcerecalc'}) { return 1; }
       unless ($time) { return 1; }
       if ($stype eq 'assesscalc') {
           my $map=(split(/\_\_\_/,$usymb))[0];
           if (&checkthis('::assesscalc:',$time) ||
               &checkthis('::assesscalc:'.$map,$time) ||
               &checkthis('::assesscalc:'.$usymb,$time) ||
               &checkthis($uname.':'.$udom.':assesscalc:',$time) ||
               &checkthis($uname.':'.$udom.':assesscalc:'.$map,$time) ||
               &checkthis($uname.':'.$udom.':assesscalc:'.$usymb,$time)) {
               return 1;
           } 
       } else {
           if (&checkthis('::studentcalc:',$time) || 
               &checkthis($uname.':'.$udom.':studentcalc:',$time)) {
       return 1;
           }
       }
       return 0; 
   }
   
 # ============================================================== Export handler  # ============================================================== Export handler
 #  #
 # Non-interactive call from with program  # Non-interactive call from with program
Line 1496  sub exportsheet { Line 1539  sub exportsheet {
 #  #
 # Check if cached  # Check if cached
 #  #
   
  my $key=$uname.':'.$udom.':'.$stype.':'.$usymb;   my $key=$uname.':'.$udom.':'.$stype.':'.$usymb;
  my $found='';   my $found='';
   
Line 1508  sub exportsheet { Line 1552  sub exportsheet {
      } split(/\_\_\_\&\_\_\_/,$oldsheets{$key});       } split(/\_\_\_\&\_\_\_/,$oldsheets{$key});
  }   }
   
    unless ($found) {
        &cachedssheets($uname,$udom,&Apache::lonnet::homeserver($uname,$udom));
        if ($oldsheets{$key}) {
           map {
               my ($name,$value)=split(/\_\_\_\=\_\_\_/,$_);
               if ($name eq $fn) {
           $found=$value;
               }
           } split(/\_\_\_\&\_\_\_/,$oldsheets{$key});
        }
    }
   #
   # Check if still valid
   #
    if ($found) {
        if (&forcedrecalc($uname,$udom,$stype,$usymb)) {
    $found='';
        }
    }
    
  if ($found) {   if ($found) {
 #  #
 # Return what was cached  # Return what was cached
Line 1517  sub exportsheet { Line 1581  sub exportsheet {
  } else {   } else {
 #  #
 # Not cached  # 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);
Line 1528  sub exportsheet { Line 1593  sub exportsheet {
 # Store now  # Store now
 #  #
     my $cid=$ENV{'request.course.id'};       my $cid=$ENV{'request.course.id'}; 
     my $current=&Apache::lonnet::reply('get:'.      my $current='';
       if ($stype eq 'studentcalc') {
          $current=&Apache::lonnet::reply('get:'.
                                      $ENV{'course.'.$cid.'.domain'}.':'.                                       $ENV{'course.'.$cid.'.domain'}.':'.
                                      $ENV{'course.'.$cid.'.num'}.                                       $ENV{'course.'.$cid.'.num'}.
      ':nohist_calculatedsheets:'.       ':nohist_calculatedsheets:'.
                                      &Apache::lonnet::escape($key),                                       &Apache::lonnet::escape($key),
                                      $ENV{'course.'.$cid.'.home'});                                       $ENV{'course.'.$cid.'.home'});
       } else {
          $current=&Apache::lonnet::reply('get:'.
                                        &getudom($thissheet).':'.
                                        &getuname($thissheet).
        ':nohist_calculatedsheets_'.
                                        $ENV{'request.course.id'}.':'.
                                        &Apache::lonnet::escape($key),
                                        &getuhome($thissheet));
   
       }
     my %currentlystored=();      my %currentlystored=();
     unless ($current=~/^error\:/) {      unless ($current=~/^error\:/) {
        map {         map {
Line 1548  sub exportsheet { Line 1625  sub exportsheet {
         if ($newstore) { $newstore.='___&___'; }          if ($newstore) { $newstore.='___&___'; }
         $newstore.=$_.'___=___'.$currentlystored{$_};          $newstore.=$_.'___=___'.$currentlystored{$_};
     } keys %currentlystored;      } keys %currentlystored;
     &Apache::lonnet::reply('put:'.      my $now=time;
       if ($stype eq 'studentcalc') {
          &Apache::lonnet::reply('put:'.
                          $ENV{'course.'.$cid.'.domain'}.':'.                           $ENV{'course.'.$cid.'.domain'}.':'.
                          $ENV{'course.'.$cid.'.num'}.                           $ENV{'course.'.$cid.'.num'}.
  ':nohist_calculatedsheets:'.   ':nohist_calculatedsheets:'.
                          &Apache::lonnet::escape($key).'='.                           &Apache::lonnet::escape($key).'='.
  &Apache::lonnet::escape($newstore),   &Apache::lonnet::escape($newstore).'&'.
                            &Apache::lonnet::escape($key).'.time='.$now,
                          $ENV{'course.'.$cid.'.home'});                           $ENV{'course.'.$cid.'.home'});
      } else {
          &Apache::lonnet::reply('put:'.
                            &getudom($thissheet).':'.
                            &getuname($thissheet).
    ':nohist_calculatedsheets_'.
                            $ENV{'request.course.id'}.':'.
                            &Apache::lonnet::escape($key).'='.
    &Apache::lonnet::escape($newstore).'&'.
                            &Apache::lonnet::escape($key).'.time='.$now,
                            &getuhome($thissheet));
      }
  }   }
  return @exportarr;   return @exportarr;
 }  }
   # ============================================================ Expiration Dates
   #
   # Load previously cached student spreadsheets for this course
   #
   
   sub expirationdates {
       undef %expiredates;
       my $cid=$ENV{'request.course.id'};
       my $reply=&Apache::lonnet::reply('dump:'.
        $ENV{'course.'.$cid.'.domain'}.':'.
                                        $ENV{'course.'.$cid.'.num'}.
        ':nohist_expirationdates',
                                        $ENV{'course.'.$cid.'.home'});
       unless ($reply=~/^error\:/) {
    map {
               my ($name,$value)=split(/\=/,$_);
               $expiredates{&Apache::lonnet::unescape($name)}
                           =&Apache::lonnet::unescape($value);
           } split(/\&/,$reply);
       }
   }
   
 # ===================================================== Calculated sheets cache  # ===================================================== Calculated sheets cache
 #  #
 # Load all previously cached spreadsheets for this course  # Load previously cached student spreadsheets for this course
 #  #
   
 sub cachedsheets {  sub cachedcsheets {
     my $cid=$ENV{'request.course.id'};      my $cid=$ENV{'request.course.id'};
     my $reply=&Apache::lonnet::reply('dump:'.      my $reply=&Apache::lonnet::reply('dump:'.
      $ENV{'course.'.$cid.'.domain'}.':'.       $ENV{'course.'.$cid.'.domain'}.':'.
                                      $ENV{'course.'.$cid.'.num'}.                                       $ENV{'course.'.$cid.'.num'}.
      ':nohist_calculatedsheets',       ':nohist_calculatedsheets',
                                      $ENV{'course.'.$cid.'.home'});                                       $ENV{'course.'.$cid.'.home'});
     undef %oldsheets;  
     unless ($reply=~/^error\:/) {      unless ($reply=~/^error\:/) {
  map {   map {
             my ($name,$value)=split(/\=/,$_);              my ($name,$value)=split(/\=/,$_);
Line 1581  sub cachedsheets { Line 1692  sub cachedsheets {
     }      }
 }  }
   
   # ===================================================== Calculated sheets cache
   #
   # Load previously cached assessment spreadsheets for this student
   #
   
   sub cachedssheets {
     my ($sname,$sdom,$shome)=@_;
     unless (($loadedcaches{$sname.'_'.$sdom}) || ($shome eq 'no_host')) {
       my $cid=$ENV{'request.course.id'};
       my $reply=&Apache::lonnet::reply('dump:'.$sdom.':'.$sname.
                ':nohist_calculatedsheets_'.
                                         $ENV{'request.course.id'},
                                        $shome);
       unless ($reply=~/^error\:/) {
    map {
               my ($name,$value)=split(/\=/,$_);
               $oldsheets{&Apache::lonnet::unescape($name)}
                         =&Apache::lonnet::unescape($value);
           } split(/\&/,$reply);
       }
       $loadedcaches{$sname.'_'.$sdom}=1;
     }
   }
   
   # ===================================================== Calculated sheets cache
   #
   # Load previously cached assessment spreadsheets for this student
   #
   
 # ================================================================ Main handler  # ================================================================ Main handler
 #  #
 # Interactive call to screen  # Interactive call to screen
Line 1713  ENDSCRIPT Line 1853  ENDSCRIPT
     $r->print('<h1>'.      $r->print('<h1>'.
             $ENV{'course.'.$ENV{'request.course.id'}.'.description'}.'</h1>');              $ENV{'course.'.$ENV{'request.course.id'}.'.description'}.'</h1>');
   
   # ---------------------------------------------------- See if user can see this
   
       if ((&gettype($asheet) eq 'classcalc') || 
           (&getuname($asheet) ne $ENV{'user.name'}) ||
           (&getudom($asheet) ne $ENV{'user.domain'})) {
           unless (&Apache::lonnet::allowed('vgr',&getcid($asheet))) {
       $r->print(
              '<h1>Access Permission Denied</h1></form></body></html>');
               return OK;
           }
       }
   
 # ---------------------------------------------------- See if something to save  # ---------------------------------------------------- See if something to save
   
Line 1735  ENDSCRIPT Line 1886  ENDSCRIPT
   
    &tmpwrite($asheet);     &tmpwrite($asheet);
   
   # ---------------------------------------------------------- Additional options
   
       $r->print(
    '<input type=submit name=forcerecalc value="Completely Recalculate Sheet"><p>'
    );
       if (&gettype($asheet) eq 'assesscalc') {
          $r->print ('<p><font size=+2><a href="/adm/studentcalc?uname='.
                                                  &getuname($asheet).
                                                  '&udom='.&getudom($asheet).
                     '">Level up: Student Sheet</a></font><p>');
       }
       
       if ((&gettype($asheet) eq 'studentcalc') && 
           (&Apache::lonnet::allowed('vgr',&getcid($asheet)))) {
          $r->print (
                      '<p><font size=+2><a href="/adm/classcalc">'.
                      'Level up: Course Sheet</a></font><p>');
       }
       
   
 # ----------------------------------------------------------------- Save dialog  # ----------------------------------------------------------------- Save dialog
   
   
Line 1749  ENDSCRIPT Line 1920  ENDSCRIPT
   
     $r->print(&hiddenfield('ufn',&getfilename($asheet)));      $r->print(&hiddenfield('ufn',&getfilename($asheet)));
   
 # ----------------------------------------------------------- Get cached sheets  # --------------------------------------------------------------- Cached sheets
   
     &cachedsheets();      &expirationdates();
   
       undef %oldsheets;
       undef %loadedcaches;
   
       if (&gettype($asheet) eq 'classcalc') {
           $r->print("Loading previously calculated student sheets ...<br>\n");
           $r->rflush();
           &cachedcsheets();
       } elsif (&gettype($asheet) eq 'studentcalc') {
           $r->print("Loading previously calculated assessment sheets ...<br>\n");
           $r->rflush();
           &cachedssheets(&getuname($asheet),&getudom($asheet),
                          &getuhome($asheet));
       }
   
 # ----------------------------------------------------- Update sheet, load rows  # ----------------------------------------------------- Update sheet, load rows
   

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


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