Diff for /loncom/interface/spreadsheet/Spreadsheet.pm between versions 1.53 and 1.55

version 1.53, 2005/08/24 18:14:47 version 1.55, 2005/09/01 21:47:14
Line 191  sub make_default { Line 191  sub make_default {
             {'spreadsheet_default_'.$self->{'type'} => $self->filename()},              {'spreadsheet_default_'.$self->{'type'} => $self->filename()},
                                      $self->{'cdom'},$self->{'cnum'});                                       $self->{'cdom'},$self->{'cnum'});
     return $result if ($result ne 'ok');      return $result if ($result ne 'ok');
       &Apache::lonnet::appenv('course.'.$self->{'cid'}.'.spreadsheet_default_'.
       $self->{'type'} => $self->filename());
     my $symb = $self->{'symb'};      my $symb = $self->{'symb'};
     $symb = '' if (! defined($symb));      $symb = '' if (! defined($symb));
     &Apache::lonnet::expirespread('','',$self->{'type'},$symb);          &Apache::lonnet::expirespread('','',$self->{'type'},$symb);    
Line 968  sub formulas { Line 970  sub formulas {
         $self->{'formulas'} = $formulas;          $self->{'formulas'} = $formulas;
         $self->{'rows'} = [];          $self->{'rows'} = [];
         $self->{'template_cells'} = [];          $self->{'template_cells'} = [];
    $self->{'loaded'} = 1;
         return;          return;
     } else {      } else {
  if (!$self->{'loaded'}) {   $self->check_formulas_loaded();
     $self->{'loaded'}=1;  
     # Load in the spreadsheet definition  
     if (exists($env{'form.workcopy'}) &&   
  $self->{'type'} eq $env{'form.workcopy'}) {  
  $self->load_tmp();  
     } else {  
  $self->load();  
     }  
  }  
         return %{$self->{'formulas'}};          return %{$self->{'formulas'}};
     }      }
 }  }
   
   sub check_formulas_loaded {
       my $self=shift;
       if (!$self->{'loaded'}) {
    $self->{'loaded'}=1;
    # Load in the spreadsheet definition
    if (exists($env{'form.workcopy'}) && 
       $self->{'type'} eq $env{'form.workcopy'}) {
       $self->load_tmp();
    } else {
       $self->load();
    }
       }
   }
   
 sub set_formula {  sub set_formula {
     my $self = shift;      my $self = shift;
     my ($cell,$formula) = @_;      my ($cell,$formula) = @_;
       $self->check_formulas_loaded();
     $self->{'formulas'}->{$cell}=$formula;      $self->{'formulas'}->{$cell}=$formula;
     return;      return;
 }  }
Line 996  sub set_formula { Line 1005  sub set_formula {
 ##  ##
 sub formulas_keys {  sub formulas_keys {
     my $self = shift;      my $self = shift;
     my @keys = keys(%{$self->{'formulas'}});      $self->check_formulas_loaded();
     return keys(%{$self->{'formulas'}});      return keys(%{$self->{'formulas'}});
 }  }
   
Line 1007  sub formulas_keys { Line 1016  sub formulas_keys {
 sub formula {  sub formula {
     my $self = shift;      my $self = shift;
     my $cell = shift;      my $cell = shift;
       $self->check_formulas_loaded();
     if (defined($cell) && exists($self->{'formulas'}->{$cell})) {      if (defined($cell) && exists($self->{'formulas'}->{$cell})) {
         return $self->{'formulas'}->{$cell};          return $self->{'formulas'}->{$cell};
     }      }
Line 1085  sub rebuild_stats { Line 1095  sub rebuild_stats {
     my $self = shift;      my $self = shift;
     $self->{'rows'}=[];      $self->{'rows'}=[];
     $self->{'template_cells'}=[];      $self->{'template_cells'}=[];
       $self->check_formulas_loaded();
     while (my ($cell,$formula) = each(%{$self->{'formulas'}})) {      while (my ($cell,$formula) = each(%{$self->{'formulas'}})) {
         push(@{$self->{'rows'}},$1) if ($cell =~ /^A(\d+)/ && $1 != 0);          push(@{$self->{'rows'}},$1) if ($cell =~ /^A(\d+)/ && $1 != 0);
         push(@{$self->{'template_cells'}},$1) if ($cell =~ /^template_(\w+)/);          push(@{$self->{'template_cells'}},$1) if ($cell =~ /^template_(\w+)/);
Line 1525  sub outsheet_xml   { Line 1536  sub outsheet_xml   {
     ## Will be rendered for the user      ## Will be rendered for the user
     ## But not on this day      ## But not on this day
     my $Str = '<spreadsheet type="'.$self->{'type'}.'">'."\n";      my $Str = '<spreadsheet type="'.$self->{'type'}.'">'."\n";
       $self->check_formulas_loaded();
     while (my ($cell,$formula) = each(%{$self->{'formulas'}})) {      while (my ($cell,$formula) = each(%{$self->{'formulas'}})) {
         if ($cell =~ /^template_(\w+)/) {          if ($cell =~ /^template_(\w+)/) {
             my $col = $1;              my $col = $1;
Line 1674  sub load { Line 1686  sub load {
   
 sub set_row_sources {  sub set_row_sources {
     my $self = shift;      my $self = shift;
       $self->check_formulas_loaded();
     while (my ($cell,$value) = each(%{$self->{'formulas'}})) {      while (my ($cell,$value) = each(%{$self->{'formulas'}})) {
         next if ($cell !~ /^A(\d+)/ || $1 < 1);          next if ($cell !~ /^A(\d+)/ || $1 < 1);
         my $row = $1;          my $row = $1;
Line 1684  sub set_row_sources { Line 1697  sub set_row_sources {
   
 sub set_row_numbers {  sub set_row_numbers {
     my $self = shift;      my $self = shift;
       $self->check_formulas_loaded();
     while (my ($cell,$value) = each(%{$self->{'formulas'}})) {      while (my ($cell,$value) = each(%{$self->{'formulas'}})) {
  next if ($cell !~ /^A(\d+)$/);   next if ($cell !~ /^A(\d+)$/);
         next if (! defined($value));          next if (! defined($value));
Line 1737  sub save { Line 1751  sub save {
                                 {'spreadsheet_default_'.$stype => $filename },                                  {'spreadsheet_default_'.$stype => $filename },
                                           $cdom,$cnum);                                            $cdom,$cnum);
             return $reply if ($reply ne 'ok');              return $reply if ($reply ne 'ok');
       &Apache::lonnet::appenv('course.'.$self->{'cid'}.'.spreadsheet_default_'.
       $self->{'type'} => $self->filename());
         }           } 
         if ($self->is_default()) {          if ($self->is_default()) {
             if ($self->{'type'} eq 'studentcalc') {              if ($self->{'type'} eq 'studentcalc') {

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


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