--- loncom/homework/optionresponse.pm	2003/10/13 19:25:30	1.89
+++ loncom/homework/optionresponse.pm	2003/10/24 17:56:42	1.91
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: optionresponse.pm,v 1.89 2003/10/13 19:25:30 albertel Exp $
+# $Id: optionresponse.pm,v 1.91 2003/10/24 17:56:42 sakharuk Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -246,7 +246,7 @@ sub end_foilgroup {
 	}
       }
     }
-    &Apache::lonxml::increment_counter(&getfoilcounts($max));
+    if ($target ne 'answer') {&Apache::lonxml::increment_counter(&getfoilcounts($max));}
   } elsif ($target eq 'edit') {
     $result.=&Apache::edit::end_table();
   }
@@ -304,8 +304,11 @@ sub displayfoils {
   my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
   if ( ($target ne 'tex') &&
        &Apache::response::show_answer() ) {
+    my $temp=1;
     foreach $name (@whichopt) {
 	my $text=$Apache::response::foilgroup{$name.'.text'};
+	my %lastresponse=&Apache::lonnet::str2hash($Apache::lonhomework::history{"resource.$part.$id.submission"});
+	my $lastopt=$lastresponse{$name};
 	if ($text!~/^\s*$/) {
 	    if ($target eq 'tex') {
 		$break='\vskip 0 mm ';
@@ -332,11 +335,12 @@ sub displayfoils {
       }
       if ($Apache::lonhomework::type eq 'exam') {
 	if ($target ne 'tex') {
-	  $result.=&webbubbles(\@opt,\@alphabet);
+	  $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
         } else {
 	  $result.=&bubbles(\@alphabet,\@opt);
         }
       }
+      $temp++;
     }
   } else {
     my $temp=1;
@@ -373,7 +377,7 @@ sub displayfoils {
 	  }
 	  $result.=$break.$text."\n";
 	  if ($Apache::lonhomework::type eq 'exam') {
-	    $result.=&webbubbles(\@opt,\@alphabet,$temp);
+	    $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
 	  }
 	  $temp++;
       } else {
@@ -454,18 +458,24 @@ sub optionlist_correction {
 
 sub webbubbles {
 
-    my ($ropt,$ralphabet,$temp)=@_;
+    my ($ropt,$ralphabet,$temp,$lastopt)=@_;
     my @opt=@$ropt; 
     my @alphabet=@$ralphabet;
     my $result='';
-	my $number_of_bubbles = $#opt + 1;
-	$result.= '<table border="1"><tr>';
-	for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
-	   $result.='<td><input type="radio" name="HWVAL_'.$Apache::inputtags::response['-1'].':'.$temp.
-                    '" value='.$opt[$ind].'>'.$alphabet[$ind].': '.$opt[$ind].'</td>';
+    my $number_of_bubbles = $#opt + 1;
+    $result.= '<table border="1"><tr>';
+    for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
+	my $checked='';
+	if ($lastopt eq $opt[$ind]) {
+	    $checked=' checked="on" ';
 	}
-	$result.='</tr></table>';
-	return $result;
+	$result.='<td><input type="radio" name="HWVAL_'.
+	    $Apache::inputtags::response['-1'].':'.$temp.
+	    '" value="'.$opt[$ind].'" '.$checked.' />'.$alphabet[$ind].': '.
+	    $opt[$ind].'</td>';
+    }
+    $result.='</tr></table>';
+    return $result;
 }