--- loncom/interface/spreadsheet/Spreadsheet.pm 2007/01/23 01:36:26 1.74 +++ loncom/interface/spreadsheet/Spreadsheet.pm 2014/02/12 16:54:21 1.83 @@ -1,5 +1,5 @@ # -# $Id: Spreadsheet.pm,v 1.74 2007/01/23 01:36:26 albertel Exp $ +# $Id: Spreadsheet.pm,v 1.83 2014/02/12 16:54:21 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 @@ -711,7 +726,7 @@ sub get_values { my @num=($ld..$ud); foreach my $a (@alpha) { foreach my $n (@num) { - if (exists($sheet_values{$a.$n})) { + if ((exists($sheet_values{$a.$n})) && ($sheet_values{$a.$n} ne '')) { push(@values,$sheet_values{$a.$n}); } } @@ -727,8 +742,10 @@ sub get_values { $alpha=qq/[$la-$ua]/; } my $expression = '^'.$alpha.$num.'$'; - foreach (grep /$expression/,keys(%sheet_values)) { - push(@values,$sheet_values{$_}); + foreach my $item (grep(/$expression/,keys(%sheet_values))) { + unless ($sheet_values{$item} eq '') { + push(@values,$sheet_values{$item}); + } } return \@values; } @@ -757,7 +774,7 @@ sub calc { $depth++; if ($depth>100) { undef %sheet_values; - return $lastcalc.': Maximum calculation depth exceeded'; + return $lastcalc.': '.&mt('Maximum calculation depth exceeded'); } } return 'okay'; @@ -813,12 +830,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') { @@ -856,7 +873,7 @@ sub expandnamed { $returnvalue = $values[0]; } elsif (scalar(@matches) > 0) { # more than one match. Look for a concise one - $returnvalue = "'non-unique parameter name : $expression'"; + $returnvalue = "'".&mt('non-unique parameter name: [_1]',$expression).'"'; for (my $i=0; $i<=$#matches;$i++) { if ($matches[$i] =~ /^$expression$/) { # why do we not do this lookup here? @@ -866,7 +883,7 @@ sub expandnamed { } else { # There was a negative number of matches, which indicates # something is wrong with reality. Better warn the user. - $returnvalue = '"bizzare parameter: '.$expression.'"'; + $returnvalue = "'".&mt('bizzare parameter: [_1]',$expression)."'"; } return $returnvalue; } @@ -1250,9 +1267,9 @@ sub html_report_error { my $self = shift(); my $Str = ''; if ($self->badcalc()) { - $Str = '

'. + $Str = '

'. &mt('An error occurred while calculating this spreadsheet'). - "

\n". + "

\n". '
'.$self->calcerror()."
\n"; } return $Str; @@ -1415,7 +1432,7 @@ sub output_selector { foreach ($self->output_options()) { $output_selector.='\n"; } @@ -1492,7 +1509,7 @@ sub outsheet_excel { # # Write a link to allow them to download it $r->print('
'. - 'Your Excel spreadsheet.'."\n"); + ''.&mt('Your Excel spreadsheet').''."\n"); return; } @@ -1510,16 +1527,20 @@ 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.') + .' '.&mt('This error has been logged.') + .' '.&mt('Please alert your LON-CAPA administrator.') + .'

' + ); $r->print("
\n".$csvdata."
\n"); return 0; } @@ -1532,7 +1553,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"); @@ -1674,8 +1695,10 @@ sub load { my $sheetxml=&Apache::lonnet::getfile (&Apache::lonnet::filelocation('',$filename)); if ($sheetxml == -1) { - $sheetxml='"Error loading spreadsheet ' - .$self->filename().'"'; + $sheetxml=''. + &mt('Error loading spreadsheet [_1]', + '"'.$self->filename().'"'). + ''; } ($formulas,undef) = &parse_sheet(\$sheetxml); # Get just the filename and set the sheets filename @@ -1794,16 +1817,14 @@ 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->is_default()) { - if ($self->{'type'} eq 'studentcalc') { - &Apache::lonnet::expirespread('','','studentcalc',''); - } elsif ($self->{'type'} eq 'assesscalc') { - &Apache::lonnet::expirespread('','','assesscalc',''); - &Apache::lonnet::expirespread('','','studentcalc',''); - } + if ($self->{'type'} eq 'studentcalc') { + &Apache::lonnet::expirespread('','','studentcalc',''); + } elsif ($self->{'type'} eq 'assesscalc') { + &Apache::lonnet::expirespread('','','assesscalc',''); + &Apache::lonnet::expirespread('','','studentcalc',''); } return $reply; }