--- loncom/interface/spreadsheet/Spreadsheet.pm 2007/01/23 01:36:26 1.74 +++ loncom/interface/spreadsheet/Spreadsheet.pm 2025/01/04 23:38:38 1.87 @@ -1,5 +1,5 @@ # -# $Id: Spreadsheet.pm,v 1.74 2007/01/23 01:36:26 albertel Exp $ +# $Id: Spreadsheet.pm,v 1.87 2025/01/04 23:38:38 raeburn 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); @@ -327,6 +327,7 @@ sub initialize_safe_space { $safeeval = new Safe(shift); my $safehole = new Safe::Hole; $safeeval->permit("entereval"); + $safeeval->permit("hintseval"); $safeeval->permit(":base_math"); $safeeval->permit("sort"); $safeeval->deny(":base_io"); @@ -675,6 +676,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 +727,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 +743,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 +775,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 +831,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 +874,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 +884,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('bizarre parameter: [_1]',$expression)."'"; } return $returnvalue; } @@ -1250,9 +1268,9 @@ sub html_report_error { my $self = shift(); my $Str = ''; if ($self->badcalc()) { - $Str = '
'. &mt('An error occurred while calculating this spreadsheet'). - "\n". + "
\n". ''.$self->calcerror()."\n"; } return $Str; @@ -1334,7 +1352,7 @@ sub html_editable_cell { # # The encoding string "^A-blah" is placed in []'s inside a regexp, so # we specify the characters we want left alone by putting a '^' in front. - $formula = &HTML::Entities::encode($formula,'^A-z0-9 !#$%-;=?~'); + $formula = &HTML::Entities::encode($formula,'^A-z0-9 !#$%;=?~-'); # HTML::Entities::encode does not catch everything - we need '\' encoded $formula =~ s/\\/&\#092/g; # Escape it again - this time the only encodable character is '&' @@ -1415,7 +1433,7 @@ sub output_selector { foreach ($self->output_options()) { $output_selector.='\n"; } @@ -1492,7 +1510,7 @@ sub outsheet_excel { # # Write a link to allow them to download it $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 +1554,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('