Diff for /loncom/interface/spreadsheet/Spreadsheet.pm between versions 1.70 and 1.76

version 1.70, 2006/09/03 00:39:57 version 1.76, 2007/01/23 02:14:18
Line 172  sub filename { Line 172  sub filename {
                 $newfilename = 'default_'.$self->{'type'};                  $newfilename = 'default_'.$self->{'type'};
             }              }
         }          }
         if ($newfilename !~ /\w/ || $newfilename =~ /^\W*$/) {   if ($newfilename eq &mt('LON-CAPA Standard')) {
             $newfilename = 'default_'.$self->{'type'};      undef($newfilename);
         }   } else {
         if ($newfilename !~ /^default\.$self->{'type'}$/ &&      if ($newfilename !~ /\w/ || $newfilename =~ /^\W*$/) {
             $newfilename !~ /^\/res\/(.*)spreadsheet$/) {   $newfilename = 'default_'.$self->{'type'};
             if ($newfilename !~ /_$self->{'type'}$/) {      }
                 $newfilename =~ s/[\s_]*$//;      if ($newfilename !~ /^default\.$self->{'type'}$/ &&
                 $newfilename .= '_'.$self->{'type'};   $newfilename !~ /^\/res\/(.*)spreadsheet$/) {
             }   if ($newfilename !~ /_$self->{'type'}$/) {
         }      $newfilename =~ s/[\s_]*$//;
       $newfilename .= '_'.$self->{'type'};
    }
       }
    }
         $self->{'filename'} = $newfilename;          $self->{'filename'} = $newfilename;
         return;          return;
     }      }
Line 671  sub MAXPARM { Line 675  sub MAXPARM {
     return $max;      return $max;
 }  }
   
   
   =pod
   
   =item PARM(parametername)
   
   Returns the value of the parameter matching the input parameter name.
   parametername should be a string such as 'parameter_1_opendate'.
   
   =cut
   
   #-------------------------------------------------------
   sub PARM {
       return $c{$_[0]};
   }
   
 #-------------------------------------------------------  #-------------------------------------------------------
   
 =pod  =pod
Line 801  sub expandnamed { Line 820  sub expandnamed {
     my $self = shift;      my $self = shift;
     my $expression=shift;      my $expression=shift;
     if ($expression=~/^\&/) {      if ($expression=~/^\&/) {
  my ($func,$var,$formula)=($expression=~/^\&(\w+)\(([^\;]+)\;(.*)\)/);   my ($func,$var,$formula)=($expression=~/^\&(\w+)\(([^\;]+)\;(.*)\)/s);
  my @vars=split(/\W+/,$formula);   my @vars=split(/\W+/,$formula);
    # make the list uniq
    @vars = keys(%{{ map { $_ => 1 } @vars }});
         my %values=();          my %values=();
  foreach my $varname ( @vars ) {   foreach my $varname ( @vars ) {
             if ($varname=~/^(parameter|stores|timestamp)/) {              if ($varname=~/^(parameter|stores|timestamp)/) {
                 $formula=~s/$varname/'$c{\''.$varname.'\'}'/ge;                  $formula=~s/$varname/'$c{\''.$varname.'\'}'/ge;
                $varname=~s/$var/\([\\w:\\- ]\+\)/g;   $varname=~s/$var/\([\\w:\\- ]\+\)/g;
        foreach (keys(%{$self->{'constants'}})) {   foreach (keys(%{$self->{'constants'}})) {
   if ($_=~/$varname/) {      if ($_=~/$varname/) {
       $values{$1}=1;   $values{$1}=1;
                   }      }
                }   }
     }      }
         }          }
         if ($func eq 'EXPANDSUM') {          if ($func eq 'EXPANDSUM') {
Line 886  sub sett { Line 907  sub sett {
             # Replace 'A0' with the value from 'A0'              # Replace 'A0' with the value from 'A0'
             $t{$cell}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$sheet_values\{\'$2\'\}/g;              $t{$cell}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$sheet_values\{\'$2\'\}/g;
             # Replace parameters              # Replace parameters
             $t{$cell}=~s/(^|[^\"\'])\[([^\]]+)\]/$1.$self->expandnamed($2)/ge;              $t{$cell}=~s/(^|[^\"\'])\[([^\]]+)\]/$1.$self->expandnamed($2)/sge;
         }          }
     }      }
     #      #
Line 898  sub sett { Line 919  sub sett {
             $t{$cell}=$formula;              $t{$cell}=$formula;
             $t{$cell}=~s/\.\.+/\,/g;              $t{$cell}=~s/\.\.+/\,/g;
             $t{$cell}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$sheet_values\{\'$2\'\}/g;              $t{$cell}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$sheet_values\{\'$2\'\}/g;
             $t{$cell}=~s/(^|[^\"\'])\[([^\]]+)\]/$1.$self->expandnamed($2)/ge;              $t{$cell}=~s/(^|[^\"\'])\[([^\]]+)\]/$1.$self->expandnamed($2)/sge;
         } elsif  ( $col  =~ /^[A-Z]$/  ) {          } elsif  ( $col  =~ /^[A-Z]$/  ) {
             if ($formula !~ /^\!/ && exists($self->{'constants'}->{$cell})              if ($formula !~ /^\!/ && exists($self->{'constants'}->{$cell})
  && $self->{'constants'}->{$cell} ne '') {   && $self->{'constants'}->{$cell} ne '') {
Line 909  sub sett { Line 930  sub sett {
             $t{$cell}=$formula;              $t{$cell}=$formula;
             $t{$cell}=~s/\.\.+/\,/g;              $t{$cell}=~s/\.\.+/\,/g;
             $t{$cell}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$sheet_values\{\'$2\'\}/g;              $t{$cell}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$sheet_values\{\'$2\'\}/g;
             $t{$cell}=~s/(^|[^\"\'])\[([^\]]+)\]/$1.$self->expandnamed($2)/ge;              $t{$cell}=~s/(^|[^\"\'])\[([^\]]+)\]/$1.$self->expandnamed($2)/sge;
         }          }
     }      }
     %{$self->{'safe'}->varglob('t')}=%t;      %{$self->{'safe'}->varglob('t')}=%t;
Line 1684  sub load { Line 1705  sub load {
             # Load the spreadsheet definition file from the save file              # Load the spreadsheet definition file from the save file
             my %tmphash = &Apache::lonnet::dump($filename,$cdom,$cnum);              my %tmphash = &Apache::lonnet::dump($filename,$cdom,$cnum);
             my ($tmp) = keys(%tmphash);              my ($tmp) = keys(%tmphash);
             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {              if (%tmphash
    && $tmp !~ /^(con_lost|error|no_such_host)/i) {
                 while (my ($cell,$formula) = each(%tmphash)) {                  while (my ($cell,$formula) = each(%tmphash)) {
                     $formulas->{$cell}=$formula;                      $formulas->{$cell}=$formula;
                 }                  }
Line 1881  sub othersheets { Line 1903  sub othersheets {
     my ($stype) = @_;      my ($stype) = @_;
     $stype = $self->{'type'} if (! defined($stype) || $stype !~ /calc$/);      $stype = $self->{'type'} if (! defined($stype) || $stype !~ /calc$/);
     #      #
     my @alternatives=();      my @alternatives=(&mt('Default'), &mt('LON-CAPA Standard'));
     my %results=&Apache::lonnet::dump($stype.'_spreadsheets',      my %results=&Apache::lonnet::dump($stype.'_spreadsheets',
                                       $self->{'cdom'}, $self->{'cnum'});                                        $self->{'cdom'}, $self->{'cnum'});
     my ($tmp) = keys(%results);      my ($tmp) = keys(%results);
     if ($tmp =~ /^(con_lost|error|no_such_host)/i ) {      if (%results
         @alternatives = (&mt('Default'));   && $tmp !~ /^(con_lost|error|no_such_host)/i ) {
     } else {          push(@alternatives, sort(keys(%results)));
         @alternatives = (&mt('Default'), sort (keys(%results)));  
     }      }
     return @alternatives;       return @alternatives; 
 }  }

Removed from v.1.70  
changed lines
  Added in v.1.76


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