version 1.73, 2007/01/23 01:29:15
|
version 1.87, 2025/01/04 23:38:38
|
Line 210 sub make_default {
|
Line 210 sub make_default {
|
{'spreadsheet_default_'.$self->{'type'} => $self->filename()}, |
{'spreadsheet_default_'.$self->{'type'} => $self->filename()}, |
$self->{'cdom'},$self->{'cnum'}); |
$self->{'cdom'},$self->{'cnum'}); |
return $result if ($result ne 'ok'); |
return $result if ($result ne 'ok'); |
&Apache::lonnet::appenv('course.'.$self->{'cid'}.'.spreadsheet_default_'. |
&Apache::lonnet::appenv({'course.'.$self->{'cid'}.'.spreadsheet_default_'. |
$self->{'type'} => $self->filename()); |
$self->{'type'} => $self->filename()}); |
my $symb = $self->{'symb'}; |
my $symb = $self->{'symb'}; |
$symb = '' if (! defined($symb)); |
$symb = '' if (! defined($symb)); |
&Apache::lonnet::expirespread('','',$self->{'type'},$symb); |
&Apache::lonnet::expirespread('','',$self->{'type'},$symb); |
Line 327 sub initialize_safe_space {
|
Line 327 sub initialize_safe_space {
|
$safeeval = new Safe(shift); |
$safeeval = new Safe(shift); |
my $safehole = new Safe::Hole; |
my $safehole = new Safe::Hole; |
$safeeval->permit("entereval"); |
$safeeval->permit("entereval"); |
|
$safeeval->permit("hintseval"); |
$safeeval->permit(":base_math"); |
$safeeval->permit(":base_math"); |
$safeeval->permit("sort"); |
$safeeval->permit("sort"); |
$safeeval->deny(":base_io"); |
$safeeval->deny(":base_io"); |
Line 675 sub MAXPARM {
|
Line 676 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 711 sub get_values {
|
Line 727 sub get_values {
|
my @num=($ld..$ud); |
my @num=($ld..$ud); |
foreach my $a (@alpha) { |
foreach my $a (@alpha) { |
foreach my $n (@num) { |
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}); |
push(@values,$sheet_values{$a.$n}); |
} |
} |
} |
} |
Line 727 sub get_values {
|
Line 743 sub get_values {
|
$alpha=qq/[$la-$ua]/; |
$alpha=qq/[$la-$ua]/; |
} |
} |
my $expression = '^'.$alpha.$num.'$'; |
my $expression = '^'.$alpha.$num.'$'; |
foreach (grep /$expression/,keys(%sheet_values)) { |
foreach my $item (grep(/$expression/,keys(%sheet_values))) { |
push(@values,$sheet_values{$_}); |
unless ($sheet_values{$item} eq '') { |
|
push(@values,$sheet_values{$item}); |
|
} |
} |
} |
return \@values; |
return \@values; |
} |
} |
Line 757 sub calc {
|
Line 775 sub calc {
|
$depth++; |
$depth++; |
if ($depth>100) { |
if ($depth>100) { |
undef %sheet_values; |
undef %sheet_values; |
return $lastcalc.': Maximum calculation depth exceeded'; |
return $lastcalc.': '.&mt('Maximum calculation depth exceeded'); |
} |
} |
} |
} |
return 'okay'; |
return 'okay'; |
Line 805 sub expandnamed {
|
Line 823 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 |
# make the list uniq |
@vars = keys(%{{ map { $_ => 1 } @vars }}); |
@vars = keys(%{{ map { $_ => 1 } @vars }}); |
Line 813 sub expandnamed {
|
Line 831 sub expandnamed {
|
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 856 sub expandnamed {
|
Line 874 sub expandnamed {
|
$returnvalue = $values[0]; |
$returnvalue = $values[0]; |
} elsif (scalar(@matches) > 0) { |
} elsif (scalar(@matches) > 0) { |
# more than one match. Look for a concise one |
# 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++) { |
for (my $i=0; $i<=$#matches;$i++) { |
if ($matches[$i] =~ /^$expression$/) { |
if ($matches[$i] =~ /^$expression$/) { |
# why do we not do this lookup here? |
# why do we not do this lookup here? |
Line 866 sub expandnamed {
|
Line 884 sub expandnamed {
|
} else { |
} else { |
# There was a negative number of matches, which indicates |
# There was a negative number of matches, which indicates |
# something is wrong with reality. Better warn the user. |
# something is wrong with reality. Better warn the user. |
$returnvalue = '"bizzare parameter: '.$expression.'"'; |
$returnvalue = "'".&mt('bizarre parameter: [_1]',$expression)."'"; |
} |
} |
return $returnvalue; |
return $returnvalue; |
} |
} |
Line 892 sub sett {
|
Line 910 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 904 sub sett {
|
Line 922 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 915 sub sett {
|
Line 933 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 1250 sub html_report_error {
|
Line 1268 sub html_report_error {
|
my $self = shift(); |
my $self = shift(); |
my $Str = ''; |
my $Str = ''; |
if ($self->badcalc()) { |
if ($self->badcalc()) { |
$Str = '<h3 style="color:red">'. |
$Str = '<p class="LC_error">'. |
&mt('An error occurred while calculating this spreadsheet'). |
&mt('An error occurred while calculating this spreadsheet'). |
"</h3>\n". |
"</p>\n". |
'<pre>'.$self->calcerror()."</pre>\n"; |
'<pre>'.$self->calcerror()."</pre>\n"; |
} |
} |
return $Str; |
return $Str; |
Line 1334 sub html_editable_cell {
|
Line 1352 sub html_editable_cell {
|
# |
# |
# The encoding string "^A-blah" is placed in []'s inside a regexp, so |
# 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. |
# 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 |
# HTML::Entities::encode does not catch everything - we need '\' encoded |
$formula =~ s/\\/&\#092/g; |
$formula =~ s/\\/&\#092/g; |
# Escape it again - this time the only encodable character is '&' |
# Escape it again - this time the only encodable character is '&' |
Line 1415 sub output_selector {
|
Line 1433 sub output_selector {
|
foreach ($self->output_options()) { |
foreach ($self->output_options()) { |
$output_selector.='<option value="'.$_->{'value'}.'"'; |
$output_selector.='<option value="'.$_->{'value'}.'"'; |
if ($_->{'value'} eq $default) { |
if ($_->{'value'} eq $default) { |
$output_selector .= ' selected'; |
$output_selector .= ' selected="selected"'; |
} |
} |
$output_selector .= ">".&mt($_->{'description'})."</option>\n"; |
$output_selector .= ">".&mt($_->{'description'})."</option>\n"; |
} |
} |
Line 1492 sub outsheet_excel {
|
Line 1510 sub outsheet_excel {
|
# |
# |
# Write a link to allow them to download it |
# Write a link to allow them to download it |
$r->print('<br />'. |
$r->print('<br />'. |
'<a href="'.$filename.'">Your Excel spreadsheet.</a>'."\n"); |
'<a href="'.$filename.'">'.&mt('Your Excel spreadsheet').'</a>'."\n"); |
return; |
return; |
} |
} |
|
|
Line 1510 sub outsheet_csv {
|
Line 1528 sub outsheet_csv {
|
my $csvdata = ''; |
my $csvdata = ''; |
my @Values; |
my @Values; |
# |
# |
# Open the csv file |
# Open the CSV file |
my $filename = '/prtspool/'. |
my $filename = '/prtspool/'. |
$env{'user.name'}.'_'.$env{'user.domain'}.'_'. |
$env{'user.name'}.'_'.$env{'user.domain'}.'_'. |
time.'_'.rand(1000000000).'.csv'; |
time.'_'.rand(1000000000).'.csv'; |
my $file; |
my $file; |
unless ($file = Apache::File->new('>'.'/home/httpd'.$filename)) { |
unless ($file = Apache::File->new('>'.'/home/httpd'.$filename)) { |
$r->log_error("Couldn't open $filename for output $!"); |
$r->log_error("Couldn't open $filename for output $!"); |
$r->print(&mt("Problems occured in writing the csv file. ". |
$r->print( |
"This error has been logged. ". |
'<p class="LC_error">' |
"Please alert your LON-CAPA administrator.")); |
.&mt('Problems occurred in writing the CSV file.') |
|
.' '.&mt('This error has been logged.') |
|
.' '.&mt('Please alert your LON-CAPA administrator.') |
|
.'</p>' |
|
); |
$r->print("<pre>\n".$csvdata."</pre>\n"); |
$r->print("<pre>\n".$csvdata."</pre>\n"); |
return 0; |
return 0; |
} |
} |
Line 1532 sub outsheet_csv {
|
Line 1554 sub outsheet_csv {
|
# Output the body of the spreadsheet |
# Output the body of the spreadsheet |
$self->csv_rows($connection,$file); |
$self->csv_rows($connection,$file); |
# |
# |
# Close the csv file |
# Close the CSV file |
close($file); |
close($file); |
$r->print('<br /><br />'. |
$r->print('<br /><br />'. |
'<a href="'.$filename.'">'.&mt('Your CSV spreadsheet.').'</a>'."\n"); |
'<a href="'.$filename.'">'.&mt('Your CSV spreadsheet.').'</a>'."\n"); |
Line 1674 sub load {
|
Line 1696 sub load {
|
my $sheetxml=&Apache::lonnet::getfile |
my $sheetxml=&Apache::lonnet::getfile |
(&Apache::lonnet::filelocation('',$filename)); |
(&Apache::lonnet::filelocation('',$filename)); |
if ($sheetxml == -1) { |
if ($sheetxml == -1) { |
$sheetxml='<field row="0" col="A">"Error loading spreadsheet ' |
$sheetxml='<field row="0" col="A">'. |
.$self->filename().'"</field>'; |
&mt('Error loading spreadsheet [_1]', |
|
'"'.$self->filename().'"'). |
|
'</field>'; |
} |
} |
($formulas,undef) = &parse_sheet(\$sheetxml); |
($formulas,undef) = &parse_sheet(\$sheetxml); |
# Get just the filename and set the sheets filename |
# Get just the filename and set the sheets filename |
Line 1794 sub save {
|
Line 1818 sub save {
|
{'spreadsheet_default_'.$stype => $filename }, |
{'spreadsheet_default_'.$stype => $filename }, |
$cdom,$cnum); |
$cdom,$cnum); |
return $reply if ($reply ne 'ok'); |
return $reply if ($reply ne 'ok'); |
&Apache::lonnet::appenv('course.'.$self->{'cid'}.'.spreadsheet_default_'. |
&Apache::lonnet::appenv({'course.'.$self->{'cid'}.'.spreadsheet_default_'. |
$self->{'type'} => $self->filename()); |
$self->{'type'} => $self->filename()}); |
} |
} |
if ($self->is_default()) { |
if ($self->{'type'} eq 'studentcalc') { |
if ($self->{'type'} eq 'studentcalc') { |
&Apache::lonnet::expirespread('','','studentcalc',''); |
&Apache::lonnet::expirespread('','','studentcalc',''); |
} elsif ($self->{'type'} eq 'assesscalc') { |
} elsif ($self->{'type'} eq 'assesscalc') { |
&Apache::lonnet::expirespread('','','assesscalc',''); |
&Apache::lonnet::expirespread('','','assesscalc',''); |
&Apache::lonnet::expirespread('','','studentcalc',''); |
&Apache::lonnet::expirespread('','','studentcalc',''); |
|
} |
|
} |
} |
return $reply; |
return $reply; |
} |
} |