version 1.13, 2003/06/18 15:32:37
|
version 1.18, 2003/06/25 15:33:49
|
Line 816 sub expandnamed {
|
Line 816 sub expandnamed {
|
# 4. If there is a collision, return 'bad parameter name error' |
# 4. If there is a collision, return 'bad parameter name error' |
my $returnvalue = ''; |
my $returnvalue = ''; |
my @matches = (); |
my @matches = (); |
|
my @values = (); |
$#matches = -1; |
$#matches = -1; |
study $expression; |
study $expression; |
my $parameter; |
while (my($parameter,$value) = each(%{$self->{'constants'}})) { |
foreach $parameter (keys(%{$self->{'constants'}})) { |
next if ($parameter !~ /$expression/); |
push @matches,$parameter if ($parameter =~ /$expression/); |
push(@matches,$parameter); |
|
push(@values,$value); |
} |
} |
if (scalar(@matches) == 0) { |
if (scalar(@matches) == 0) { |
$returnvalue = '""';#'"unmatched parameter: '.$parameter.'"'; |
$returnvalue = '""';#'"unmatched parameter: '.$parameter.'"'; |
} elsif (scalar(@matches) == 1) { |
} elsif (scalar(@matches) == 1) { |
# why do we not do this lookup here, instead of delaying it? |
# why do we not do this lookup here, instead of delaying it? |
$returnvalue = '$c{\''.$matches[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 = "'non-unique parameter name : $expression'"; |
foreach (@matches) { |
for (my $i=0; $i<=$#matches;$i++) { |
if (/^$expression$/) { |
if ($matches[$i] =~ /^$expression$/) { |
# why do we not do this lookup here? |
# why do we not do this lookup here? |
$returnvalue = '$c{\''.$_.'\'}'; |
$returnvalue = $values[$i]; |
} |
} |
} |
} |
} 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: '.$parameter.'"'; |
$returnvalue = '"bizzare parameter: '.$expression.'"'; |
} |
} |
return $returnvalue; |
return $returnvalue; |
} |
} |
Line 1141 sub display {
|
Line 1143 sub display {
|
############################################ |
############################################ |
sub html_export_row { |
sub html_export_row { |
my $self = shift(); |
my $self = shift(); |
|
my ($color) = @_; |
|
$color = '#CCCCFF' if (! defined($color)); |
my $allowed = &Apache::lonnet::allowed('mgr',$ENV{'request.course.id'}); |
my $allowed = &Apache::lonnet::allowed('mgr',$ENV{'request.course.id'}); |
my $row_html; |
my $row_html; |
my @rowdata = $self->get_row(0); |
my @rowdata = $self->get_row(0); |
foreach my $cell (@rowdata) { |
foreach my $cell (@rowdata) { |
if ($cell->{'name'} =~ /^[A-Z]/) { |
if ($cell->{'name'} =~ /^[A-Z]/) { |
$row_html .= '<td bgcolor="#CCCCFF">'. |
$row_html .= '<td bgcolor="'.$color.'">'. |
&html_editable_cell($cell,'#CCCCFF',$allowed).'</td>'; |
&html_editable_cell($cell,$color,$allowed).'</td>'; |
} else { |
} else { |
$row_html .= '<td bgcolor="#DDCCFF">'. |
$row_html .= '<td bgcolor="#DDCCFF">'. |
&html_editable_cell($cell,'#DDCCFF',$allowed).'</td>'; |
&html_editable_cell($cell,'#DDCCFF',$allowed).'</td>'; |
Line 1159 sub html_export_row {
|
Line 1163 sub html_export_row {
|
sub html_template_row { |
sub html_template_row { |
my $self = shift(); |
my $self = shift(); |
my $allowed = &Apache::lonnet::allowed('mgr',$ENV{'request.course.id'}); |
my $allowed = &Apache::lonnet::allowed('mgr',$ENV{'request.course.id'}); |
my ($num_uneditable) = @_; |
my ($num_uneditable,$importcolor) = @_; |
my $row_html; |
my $row_html; |
my @rowdata = $self->get_template_row(); |
my @rowdata = $self->get_template_row(); |
my $count = 0; |
my $count = 0; |
for (my $i = 0; $i<=$#rowdata; $i++) { |
for (my $i = 0; $i<=$#rowdata; $i++) { |
my $cell = $rowdata[$i]; |
my $cell = $rowdata[$i]; |
if ($i < $num_uneditable) { |
if ($i < $num_uneditable) { |
$row_html .= '<td bgcolor="#FFDDDD">'. |
$row_html .= '<td bgcolor="'.$importcolor.'">'. |
&html_uneditable_cell($cell,'#FFDDDD',$allowed).'</td>'; |
&html_uneditable_cell($cell,'#FFDDDD',$allowed).'</td>'; |
} else { |
} else { |
$row_html .= '<td bgcolor="#EOFFDD">'. |
$row_html .= '<td bgcolor="#EOFFDD">'. |
Line 1198 sub html_editable_cell {
|
Line 1202 sub html_editable_cell {
|
$value = &HTML::Entities::encode($value) if ($value !~/ /); |
$value = &HTML::Entities::encode($value) if ($value !~/ /); |
} |
} |
return $value if (! $allowed); |
return $value if (! $allowed); |
# Make the formula safe for outputting |
# |
$formula =~ s/\'/\"/g; |
|
# The formula will be parsed by the browser twice before being |
# The formula will be parsed by the browser twice before being |
# displayed to the user for editing. |
# displayed to the user for editing. |
$formula = &HTML::Entities::encode(&HTML::Entities::encode($formula)); |
# |
# Escape newlines so they make it into the edit window |
# The encoding string "^A-blah" is placed in []'s inside a regexp, so |
$formula =~ s/\n/\\n/gs; |
# we specify the characters we want left alone by putting a '^' in front. |
|
$formula = &HTML::Entities::encode($formula,"^A-z0-9 !#\$%-;=?~"); |
|
# Escape it again - this time the only encodable character is '&' |
|
$formula =~ s/\&/\&/g; |
# Glue everything together |
# Glue everything together |
$result .= "<a href=\"javascript:celledit(\'". |
$result .= "<a href=\"javascript:celledit(\'". |
$name."','".$formula."');\">".$value."</a>"; |
$name."','".$formula."');\">".$value."</a>"; |
Line 1220 sub html_uneditable_cell {
|
Line 1226 sub html_uneditable_cell {
|
|
|
sub html_row { |
sub html_row { |
my $self = shift(); |
my $self = shift(); |
my ($num_uneditable,$row) = @_; |
my ($num_uneditable,$row,$exportcolor,$importcolor) = @_; |
my $allowed = &Apache::lonnet::allowed('mgr',$ENV{'request.course.id'}); |
my $allowed = &Apache::lonnet::allowed('mgr',$ENV{'request.course.id'}); |
my @rowdata = $self->get_row($row); |
my @rowdata = $self->get_row($row); |
my $num_cols_output = 0; |
my $num_cols_output = 0; |
my $row_html; |
my $row_html; |
|
my $color = $importcolor; |
|
if ($row == 0) { |
|
$color = $exportcolor; |
|
} |
|
$color = '#FFDDDD' if (! defined($color)); |
foreach my $cell (@rowdata) { |
foreach my $cell (@rowdata) { |
if ($num_cols_output++ < $num_uneditable) { |
if ($num_cols_output++ < $num_uneditable) { |
$row_html .= '<td bgcolor="#FFDDDD">'; |
$row_html .= '<td bgcolor="'.$color.'">'; |
$row_html .= &html_uneditable_cell($cell,'#FFDDDD'); |
$row_html .= &html_uneditable_cell($cell,'#FFDDDD'); |
} else { |
} else { |
$row_html .= '<td bgcolor="#EOFFDD">'; |
$row_html .= '<td bgcolor="#EOFFDD">'; |
Line 1529 sub load {
|
Line 1540 sub load {
|
} else { |
} else { |
$self->filename($newfilename); |
$self->filename($newfilename); |
} |
} |
} elsif ($filename =~ /^default\.$self->{'type'}/) { |
|
# if there is an Original_$stype, load it instead |
|
$formulas = $self->load_system_default_sheet(); |
|
} else { |
} else { |
# 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); |
Line 1619 sub save {
|
Line 1627 sub save {
|
} |
} |
if ($self->is_default()) { |
if ($self->is_default()) { |
&Apache::lonnet::expirespread('','',$self->{'type'},''); |
&Apache::lonnet::expirespread('','',$self->{'type'},''); |
|
if ($self->{'type'} eq 'assesscalc') { |
|
&Apache::lonnet::expirespread('','','studentcalc',''); |
|
} |
} |
} |
return $reply; |
return $reply; |
} |
} |