Diff for /loncom/interface/spreadsheet/Spreadsheet.pm between versions 1.21.2.1 and 1.23

version 1.21.2.1, 2003/12/05 22:24:20 version 1.23, 2003/09/05 01:57:54
Line 48  Spreadsheet Line 48  Spreadsheet
 package Apache::Spreadsheet;  package Apache::Spreadsheet;
   
 use strict;  use strict;
   use warnings FATAL=>'all';
   no warnings 'uninitialized';
 use Apache::Constants qw(:common :http);  use Apache::Constants qw(:common :http);
 use Apache::lonnet;  use Apache::lonnet;
 use Safe;  use Safe;
Line 90  sub new { Line 92  sub new {
         type     => $stype,          type     => $stype,
         symb     => $usymb,          symb     => $usymb,
         errorlog => '',          errorlog => '',
         maxrow   => '',          maxrow   => 0,
         cid      => $ENV{'request.course.id'},          cid      => $ENV{'request.course.id'},
         cnum     => $ENV{'course.'.$ENV{'request.course.id'}.'.num'},          cnum     => $ENV{'course.'.$ENV{'request.course.id'}.'.num'},
         cdom     => $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},          cdom     => $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
Line 229  sub initialize { Line 231  sub initialize {
     # the descendents of the spreadsheet class.      # the descendents of the spreadsheet class.
 }  }
   
   sub clear_package {
       # This method is here to remind you that it will be overridden by
       # the descendents of the spreadsheet class.
   }
   
   sub cleanup {
       my $self = shift();
       $self->clear_package();
   }
   
 sub initialize_spreadsheet_package {  sub initialize_spreadsheet_package {
     &load_spreadsheet_expirationdates();      &load_spreadsheet_expirationdates();
     &clear_spreadsheet_definition_cache();      &clear_spreadsheet_definition_cache();
Line 248  sub load_spreadsheet_expirationdates { Line 260  sub load_spreadsheet_expirationdates {
 sub check_expiration_time {  sub check_expiration_time {
     my $self = shift;      my $self = shift;
     my ($time)=@_;      my ($time)=@_;
       return 0 if (! defined($time));
     my ($key1,$key2,$key3,$key4,$key5);      my ($key1,$key2,$key3,$key4,$key5);
     # Description of keys      # Description of keys
     #      #
Line 659  sub calc { Line 672  sub calc {
             return $lastcalc.': Maximum calculation depth exceeded';              return $lastcalc.': Maximum calculation depth exceeded';
         }          }
     }      }
     return 'okay';      return '';
 }  }
   
 # ------------------------------------------- End of "Inside of the safe space"  # ------------------------------------------- End of "Inside of the safe space"
Line 1121  sub calcsheet { Line 1134  sub calcsheet {
 #    $self->logthis($self->get_errorlog());  #    $self->logthis($self->get_errorlog());
     %{$self->{'values'}} = %{$self->{'safe'}->varglob('sheet_values')};      %{$self->{'values'}} = %{$self->{'safe'}->varglob('sheet_values')};
 #    $self->logthis($self->get_errorlog());  #    $self->logthis($self->get_errorlog());
     if ($result ne 'okay') {  
         $self->set_calcerror($result);  
     }  
     return $result;      return $result;
 }  }
   
   
 sub set_badcalc {  
     my $self = shift();  
     $self->{'badcalc'} =1;  
     return;  
 }  
   
 sub badcalc {  
     my $self = shift;  
     if (exists($self->{'badcalc'}) && $self->{'badcalc'}) {  
         return 1;  
     } else {  
         return 0;  
     }  
 }  
   
 sub set_calcerror {  
     my $self = shift;  
     if (@_) {  
         $self->set_badcalc();  
         if (exists($self->{'calcerror'})) {  
             $self->{'calcerror'}.="\n".$_[0];  
         } else {  
             $self->{'calcerror'}.=$_[0];  
         }  
     }  
 }  
   
 sub calcerror {  
     my $self = shift;  
     if ($self->badcalc()) {  
         if (exists($self->{'calcerror'})) {  
             return $self->{'calcerror'};  
         }  
     }  
     return;  
 }  
   
   
 ###########################################################  ###########################################################
 ##  ##
 ## Output Helpers  ## Output Helpers
Line 1186  sub display { Line 1157  sub display {
     } elsif ($outputmode eq 'csv') {      } elsif ($outputmode eq 'csv') {
         $self->outsheet_csv($r);          $self->outsheet_csv($r);
     }      }
       $self->cleanup();
     return;      return;
 }  }
   
 ############################################  ############################################
 ##         HTML output routines           ##  ##         HTML output routines           ##
 ############################################  ############################################
 sub html_report_error {  
     my $self = shift();  
     my $Str = '';  
     if ($self->badcalc()) {  
         $Str = '<h3 style="color:red">'.  
             'An error occurred while calculating this spreadsheet'.  
             "</h3>\n".  
             '<pre>'.$self->calcerror()."</pre>\n";  
     }  
     return $Str;  
 }  
   
 sub html_export_row {  sub html_export_row {
     my $self = shift();      my $self = shift();
     my ($color) = @_;      my ($color) = @_;
Line 1391  sub create_excel_spreadsheet { Line 1351  sub create_excel_spreadsheet {
 sub outsheet_excel {  sub outsheet_excel {
     my $self = shift;      my $self = shift;
     my ($r) = @_;      my ($r) = @_;
       my $connection = $r->connection();
     $r->print("<h2>Preparing Excel Spreadsheet</h2>");      $r->print("<h2>Preparing Excel Spreadsheet</h2>");
     #      #
     # Create excel worksheet      # Create excel worksheet
Line 1414  sub outsheet_excel { Line 1375  sub outsheet_excel {
     $self->excel_output_row($worksheet,0,$rows_output++,'Summary');      $self->excel_output_row($worksheet,0,$rows_output++,'Summary');
     $rows_output++;    # skip a line      $rows_output++;    # skip a line
     #      #
     $self->excel_rows($worksheet,$cols_output,$rows_output);      $self->excel_rows($connection,$worksheet,$cols_output,$rows_output);
     #      #
     #      #
     # Close the excel file      # Close the excel file
     $workbook->close();      $workbook->close();
     $r->print($self->html_report_error());  
     #      #
     # Write a link to allow them to download it      # Write a link to allow them to download it
     $r->print('<br />'.      $r->print('<br />'.
Line 1433  sub outsheet_excel { Line 1393  sub outsheet_excel {
 sub outsheet_csv   {  sub outsheet_csv   {
     my $self = shift;      my $self = shift;
     my ($r) = @_;      my ($r) = @_;
       my $connection = $r->connection();
     my $csvdata = '';      my $csvdata = '';
     my @Values;      my @Values;
     #      #
Line 1456  sub outsheet_csv   { Line 1417  sub outsheet_csv   {
     }      }
     #      #
     # Output the body of the spreadsheet      # Output the body of the spreadsheet
     $self->csv_rows($file);      $self->csv_rows($connection,$file);
     #      #
     # Close the csv file      # Close the csv file
     close($file);      close($file);
     $r->print($self->html_report_error());  
     $r->print('<br /><br />'.      $r->print('<br /><br />'.
               '<a href="'.$filename.'">Your CSV spreadsheet.</a>'."\n");                '<a href="'.$filename.'">Your CSV spreadsheet.</a>'."\n");
     #      #
Line 1631  sub load { Line 1591  sub load {
 sub set_row_sources {  sub set_row_sources {
     my $self = shift;      my $self = shift;
     while (my ($cell,$value) = each(%{$self->{'formulas'}})) {      while (my ($cell,$value) = each(%{$self->{'formulas'}})) {
         next if ($cell !~ /^A(\d+)/ && $1 > 0);          next if ($cell !~ /^A(\d+)/ || $1 < 1);
         my $row = $1;          my $row = $1;
         $self->{'row_source'}->{$row} = $value;          $self->{'row_source'}->{$row} = $value;
     }      }
Line 1693  sub save { Line 1653  sub save {
             return $reply if ($reply ne 'ok');              return $reply if ($reply ne 'ok');
         }           } 
         if ($self->is_default()) {          if ($self->is_default()) {
             &Apache::lonnet::expirespread('','',$self->{'type'},'');              if ($self->{'type'} eq 'studentcalc') {
             if ($self->{'type'} eq 'assesscalc') {                  &Apache::lonnet::expirespread('','','studentcalc','');
               } elsif ($self->{'type'} eq 'assesscalc') {
                   &Apache::lonnet::expirespread('','','assesscalc','');
                 &Apache::lonnet::expirespread('','','studentcalc','');                  &Apache::lonnet::expirespread('','','studentcalc','');
             }              }
         }          }

Removed from v.1.21.2.1  
changed lines
  Added in v.1.23


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