[LON-CAPA-cvs] cvs: loncom /homework/caparesponse caparesponse.pm

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 11 Dec 2003 23:39:55 -0000


This is a MIME encoded message

--albertel1071185995
Content-Type: text/plain

albertel		Thu Dec 11 18:39:55 2003 EDT

  Modified files:              
    /loncom/homework/caparesponse	caparesponse.pm 
  Log:
  - remove use of $$tagstack[-1] for corrupt problems it can cause ISE BUG#2487
  
  
--albertel1071185995
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20031211183955.txt"

Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.124 loncom/homework/caparesponse/caparesponse.pm:1.125
--- loncom/homework/caparesponse/caparesponse.pm:1.124	Tue Nov 25 09:37:11 2003
+++ loncom/homework/caparesponse/caparesponse.pm	Thu Dec 11 18:39:54 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.124 2003/11/25 14:37:11 sakharuk Exp $
+# $Id: caparesponse.pm,v 1.125 2003/12/11 23:39:54 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -95,13 +95,15 @@
     if (!$Apache::lonxml::default_homework_loaded) {
 	&Apache::lonxml::default_homework_load($safeeval);
     }
+    my $tag;
+    if (scalar(@$tagstack)) { $tag=$$tagstack[-1]; }
     if ( $target eq 'grade' && defined($ENV{'form.submitted'})) {
-	&Apache::response::setup_params($$tagstack[-1]);
+	&Apache::response::setup_params($tag);
 	$safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
 	my $partid = $Apache::inputtags::part;
 	my $id = $Apache::inputtags::response['-1'];
 	if ($Apache::lonhomework::type eq 'exam' && 
-	    $$tagstack[-1] eq 'formularesponse') {
+	    $tag eq 'formularesponse') {
 	    $increment=&Apache::response::scored_response($partid,$id);
 	} else {
 	    my $response = &Apache::response::getresponse();
@@ -142,13 +144,13 @@
 		#sig fig don't make much sense either
 		if (($Apache::lonhomework::type eq 'exam' ||
 		     $ENV{'form.submitted'} eq 'scantron') &&
-		    $$tagstack[-1] eq 'numericalresponse') {
+		    $tag eq 'numericalresponse') {
 		    $expression.=';my $sig=undef;';
 		}
 
-		if ($$tagstack[-1] eq 'formularesponse') {
+		if ($tag eq 'formularesponse') {
 		    $expression.=';my $type="fml";';
-		} elsif ($$tagstack[-1] eq 'numericalresponse') {
+		} elsif ($tag eq 'numericalresponse') {
 		    $expression.=';my $type="float";';
 		}
 		$expression.="');";
@@ -222,7 +224,7 @@
 						      $formats[0],\@incorrect);
 	    my @alphabet=('A'..'Z');
 	    if ($target eq 'web') {
-		if ($$tagstack[-1] eq 'numericalresponse') {
+		if ($tag eq 'numericalresponse') {
 		    if ($unit=~/\S/) {$result.=' (in '.$unit.')<br /><br />';}
 		    $result.= '<table border="1"><tr>';
 		    my $previous=$Apache::lonhomework::history{"resource.$Apache::inputtags::part.$id.submission"};
@@ -237,7 +239,7 @@
 			    $bubble_values[$ind].'</td>';
 		    }
 		    $result.='</tr></table>';
-		} elsif ($$tagstack[-1] eq 'formularesponse') {
+		} elsif ($tag eq 'formularesponse') {
 		    $result.= '<br /><br /><font color="red">
                            <textarea name="HWVAL_'.$id.'" rows="4" cols="50">
                            </textarea></font> <br /><br />';
@@ -246,7 +248,7 @@
 		if ((defined $unit) and ($unit=~/\S/) and ($Apache::lonhomework::type eq 'exam')) {
 		    $result.=' \textit{(in} \verb|'.$unit.'|\textit{)} ';
 		}
-		if ($$tagstack[-1] eq 'numericalresponse') {
+		if ($tag eq 'numericalresponse') {
 		    my ($celllength,$number_of_tables,@table_range)=
 			&get_table_sizes($formats[0],$number_of_bubbles);
 		    my $j=0;
@@ -286,18 +288,20 @@
 	my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
 	if ($target eq 'analyze') {
 	    push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
-	    $Apache::lonhomework::analyze{"$part_id.type"} = $$tagstack[-1];
+	    $Apache::lonhomework::analyze{"$part_id.type"} = $tag;
 	    my (@incorrect)=&Apache::lonxml::get_param_var('incorrect',$parstack,$safeeval);
 	    push (@{ $Apache::lonhomework::analyze{"$part_id.incorrect"} }, @incorrect);
 	}
-	&Apache::response::setup_params($$tagstack[-1]);
+	if (scalar(@$tagstack)) {
+	    &Apache::response::setup_params($tag);
+	}
 	my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
 	my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,$safeeval);
 	my $unit=&Apache::lonxml::get_param_var('unit',$parstack,$safeeval);
 	my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval);
 	
 	if ($target eq 'answer') {
-	    $result.=&Apache::response::answer_header($$tagstack[-1]);
+	    $result.=&Apache::response::answer_header($tag);
 	}
 	for(my $i=0;$i<=$#answers;$i++) {
 	    my $ans=$answers[$i];
@@ -311,7 +315,7 @@
 	    if ($Apache::inputtags::params{'sig'}) {
 		($sighigh,$siglow)=&get_sigrange($Apache::inputtags::params{'sig'});
 	    }
-	    if ($fmt && $$tagstack[-1] eq 'numericalresponse') {
+	    if ($fmt && $tag eq 'numericalresponse') {
 		$fmt=~s/e/E/g;
 		$ans = sprintf('%.'.$fmt,$ans);
 		if ($high) {
@@ -320,15 +324,15 @@
 		}
 	    }
 	    if ($target eq 'answer') {
-		if ($high && $$tagstack[-1] eq 'numericalresponse') { $ans.=' ['.$low.','.$high.']'; }
-		if ($sighigh && $$tagstack[-1] eq 'numericalresponse') {
+		if ($high && $tag eq 'numericalresponse') { $ans.=' ['.$low.','.$high.']'; }
+		if ($sighigh && $tag eq 'numericalresponse') {
 		    if ($ENV{'form.answer_output_mode'} eq 'tex') {
 			$ans.= " Sig $siglow - $sighigh";
 		    } else {
 			$ans.= " Sig <i>$siglow - $sighigh</i>";
 		    }
 		}
-		$result.=&Apache::response::answer_part($$tagstack[-1],$ans);
+		$result.=&Apache::response::answer_part($tag,$ans);
 	    } elsif ($target eq 'analyze') {
 		push (@{ $Apache::lonhomework::analyze{"$part_id.answer"} }, $ans);
 		if ($high) {
@@ -338,25 +342,25 @@
 	    }
 	}
 	if (defined($unit) and ($unit ne '') and
-	    $$tagstack[-1] eq 'numericalresponse') {
+	    $tag eq 'numericalresponse') {
 	    if ($target eq 'answer') {
 		if ($ENV{'form.answer_output_mode'} eq 'tex') {
-		    $result.=&Apache::response::answer_part($$tagstack[-1],
+		    $result.=&Apache::response::answer_part($tag,
 							    " Unit: $unit ");
 		} else {
-		    $result.=&Apache::response::answer_part($$tagstack[-1],
+		    $result.=&Apache::response::answer_part($tag,
 							    "Unit: <b>$unit</b>");
 		}
 	    } elsif ($target eq 'analyze') {
 		push (@{ $Apache::lonhomework::analyze{"$part_id.unit"} }, $unit);
 	    }
 	}
-	if ($$tagstack[-1] eq 'formularesponse' && $target eq 'answer') {
+	if ($tag eq 'formularesponse' && $target eq 'answer') {
 	    my $samples=&Apache::lonxml::get_param('samples',$parstack,$safeeval);
-	    $result.=&Apache::response::answer_part($$tagstack[-1],$samples);
+	    $result.=&Apache::response::answer_part($tag,$samples);
 	}
 	if ($target eq 'answer') {
-	    $result.=&Apache::response::answer_footer($$tagstack[-1]);
+	    $result.=&Apache::response::answer_footer($tag);
 	}
     }
     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || 
@@ -531,7 +535,7 @@
 	&Apache::lonxml::default_homework_load($safeeval);
     }
     if ( $target eq 'grade' && defined($ENV{'form.submitted'})) {
-	&Apache::response::setup_params($$tagstack[-1]);
+	&Apache::response::setup_params('stringresponse');
 	$safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
 	if ($Apache::lonhomework::type eq 'exam' ||
 	    $ENV{'form.submitted'} eq 'scantron') {
@@ -605,15 +609,15 @@
     } elsif ($target eq 'answer' || $target eq 'analyze') {
 	if ($target eq 'analyze') {
 	    push (@{ $Apache::lonhomework::analyze{"parts"} },"$part.$id");
-	    $Apache::lonhomework::analyze{"$part.$id.type"} = $$tagstack[-1];
+	    $Apache::lonhomework::analyze{"$part.$id.type"} = 'stringresponse';
 	}
-	&Apache::response::setup_params($$tagstack[-1]);
+	&Apache::response::setup_params('stringresponse');
 	if ($target eq 'answer') {
-	    $result.=&Apache::response::answer_header($$tagstack[-1]);
+	    $result.=&Apache::response::answer_header('stringresponse');
 	}
 #	foreach my $ans (@answers) {
 	    if ($target eq 'answer') {
-		$result.=&Apache::response::answer_part($$tagstack[-1],$answer);
+		$result.=&Apache::response::answer_part('stringresponse',$answer);
 	    } elsif ($target eq 'analyze') {
 		push (@{ $Apache::lonhomework::analyze{"$part.$id.answer"} },
 		      $answer);
@@ -631,10 +635,10 @@
 	}
 	if ($target eq 'answer') {
 	    if ($ENV{'form.answer_output_mode'} eq 'tex') {
-		$result.=&Apache::response::answer_part($$tagstack[-1],
+		$result.=&Apache::response::answer_part('stringresponse',
 							"$string");
 	    } else {
-		$result.=&Apache::response::answer_part($$tagstack[-1],
+		$result.=&Apache::response::answer_part('stringresponse',
 							"<b>$string</b>");
 	    }
 	} elsif ($target eq 'analyze') {
@@ -642,7 +646,7 @@
 		  $type);
 	}
 	if ($target eq 'answer') {
-	    $result.=&Apache::response::answer_footer($$tagstack[-1]);
+	    $result.=&Apache::response::answer_footer('stringresponse');
 	}
     } elsif ($target eq 'edit') {
 	$result.='</td></tr>'.&Apache::edit::end_table;

--albertel1071185995--