--- loncom/interface/spreadsheet/Spreadsheet.pm 2007/01/25 22:00:07 1.73.2.1 +++ loncom/interface/spreadsheet/Spreadsheet.pm 2008/09/12 14:35:46 1.80 @@ -1,5 +1,5 @@ # -# $Id: Spreadsheet.pm,v 1.73.2.1 2007/01/25 22:00:07 albertel Exp $ +# $Id: Spreadsheet.pm,v 1.80 2008/09/12 14:35:46 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -210,8 +210,8 @@ sub make_default { {'spreadsheet_default_'.$self->{'type'} => $self->filename()}, $self->{'cdom'},$self->{'cnum'}); return $result if ($result ne 'ok'); - &Apache::lonnet::appenv('course.'.$self->{'cid'}.'.spreadsheet_default_'. - $self->{'type'} => $self->filename()); + &Apache::lonnet::appenv({'course.'.$self->{'cid'}.'.spreadsheet_default_'. + $self->{'type'} => $self->filename()}); my $symb = $self->{'symb'}; $symb = '' if (! defined($symb)); &Apache::lonnet::expirespread('','',$self->{'type'},$symb); @@ -675,6 +675,21 @@ sub MAXPARM { 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 @@ -805,7 +820,7 @@ sub expandnamed { my $self = shift; my $expression=shift; if ($expression=~/^\&/) { - my ($func,$var,$formula)=($expression=~/^\&(\w+)\(([^\;]+)\;(.*)\)/); + my ($func,$var,$formula)=($expression=~/^\&(\w+)\(([^\;]+)\;(.*)\)/s); my @vars=split(/\W+/,$formula); # make the list uniq @vars = keys(%{{ map { $_ => 1 } @vars }}); @@ -813,12 +828,12 @@ sub expandnamed { foreach my $varname ( @vars ) { if ($varname=~/^(parameter|stores|timestamp)/) { $formula=~s/$varname/'$c{\''.$varname.'\'}'/ge; - $varname=~s/$var/\([\\w:\\- ]\+\)/g; - foreach (keys(%{$self->{'constants'}})) { - if ($_=~/$varname/) { - $values{$1}=1; - } - } + $varname=~s/$var/\([\\w:\\- ]\+\)/g; + foreach (keys(%{$self->{'constants'}})) { + if ($_=~/$varname/) { + $values{$1}=1; + } + } } } if ($func eq 'EXPANDSUM') { @@ -892,7 +907,7 @@ sub sett { # Replace 'A0' with the value from 'A0' $t{$cell}=~s/(^|[^\"\'])([A-Za-z]\d+)/$1\$sheet_values\{\'$2\'\}/g; # Replace parameters - $t{$cell}=~s/(^|[^\"\'])\[([^\]]+)\]/$1.$self->expandnamed($2)/ge; + $t{$cell}=~s/(^|[^\"\'])\[([^\]]+)\]/$1.$self->expandnamed($2)/sge; } } # @@ -904,7 +919,7 @@ sub sett { $t{$cell}=$formula; $t{$cell}=~s/\.\.+/\,/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]$/ ) { if ($formula !~ /^\!/ && exists($self->{'constants'}->{$cell}) && $self->{'constants'}->{$cell} ne '') { @@ -915,7 +930,7 @@ sub sett { $t{$cell}=$formula; $t{$cell}=~s/\.\.+/\,/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; @@ -1510,16 +1525,16 @@ sub outsheet_csv { my $csvdata = ''; my @Values; # - # Open the csv file + # Open the CSV file my $filename = '/prtspool/'. $env{'user.name'}.'_'.$env{'user.domain'}.'_'. time.'_'.rand(1000000000).'.csv'; my $file; unless ($file = Apache::File->new('>'.'/home/httpd'.$filename)) { $r->log_error("Couldn't open $filename for output $!"); - $r->print(&mt("Problems occured in writing the csv file. ". - "This error has been logged. ". - "Please alert your LON-CAPA administrator.")); + $r->print(&mt('Problems occurred in writing the CSV file. ' + .'This error has been logged. ' + .'Please alert your LON-CAPA administrator.')); $r->print("
\n".$csvdata."
\n"); return 0; } @@ -1532,7 +1547,7 @@ sub outsheet_csv { # Output the body of the spreadsheet $self->csv_rows($connection,$file); # - # Close the csv file + # Close the CSV file close($file); $r->print('

'. ''.&mt('Your CSV spreadsheet.').''."\n"); @@ -1794,8 +1809,8 @@ sub save { {'spreadsheet_default_'.$stype => $filename }, $cdom,$cnum); return $reply if ($reply ne 'ok'); - &Apache::lonnet::appenv('course.'.$self->{'cid'}.'.spreadsheet_default_'. - $self->{'type'} => $self->filename()); + &Apache::lonnet::appenv({'course.'.$self->{'cid'}.'.spreadsheet_default_'. + $self->{'type'} => $self->filename()}); } if ($self->{'type'} eq 'studentcalc') { &Apache::lonnet::expirespread('','','studentcalc','');