[LON-CAPA-cvs] cvs: loncom(version_1_0_2) /homework optionresponse.pm

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 15 Oct 2003 19:51:29 -0000


albertel		Wed Oct 15 15:51:29 2003 EDT

  Modified files:              (Branch: version_1_0_2)
    /loncom/homework	optionresponse.pm 
  Log:
  - backport 1.90
  
  
Index: loncom/homework/optionresponse.pm
diff -u loncom/homework/optionresponse.pm:1.84.2.1 loncom/homework/optionresponse.pm:1.84.2.2
--- loncom/homework/optionresponse.pm:1.84.2.1	Mon Sep 22 21:52:57 2003
+++ loncom/homework/optionresponse.pm	Wed Oct 15 15:51:29 2003
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: optionresponse.pm,v 1.84.2.1 2003/09/23 01:52:57 albertel Exp $
+# $Id: optionresponse.pm,v 1.84.2.2 2003/10/15 19:51:29 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -305,8 +305,11 @@
   my $status=$Apache::inputtags::status[-1];
   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 ';
@@ -333,11 +336,12 @@
       }
       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;
@@ -374,7 +378,7 @@
 	  }
 	  $result.=$break.$text."\n";
 	  if ($Apache::lonhomework::type eq 'exam') {
-	    $result.=&webbubbles(\@opt,\@alphabet,$temp);
+	    $result.=&webbubbles(\@opt,\@alphabet,$temp,$lastopt);
 	  }
 	  $temp++;
       } else {
@@ -455,18 +459,24 @@
 
 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;
 }