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

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


albertel		Wed Oct 15 15:40:43 2003 EDT

  Modified files:              
    /loncom/homework	matchresponse.pm optionresponse.pm rankresponse.pm 
    /loncom/homework/caparesponse	caparesponse.pm 
  Log:
  - match/option/rank/numerical responses now restore last state of bubbles
    in online exam mode
  - match/rank getting closer to working in scantron mode
  
  
Index: loncom/homework/matchresponse.pm
diff -u loncom/homework/matchresponse.pm:1.26 loncom/homework/matchresponse.pm:1.27
--- loncom/homework/matchresponse.pm:1.26	Mon Oct 13 15:25:30 2003
+++ loncom/homework/matchresponse.pm	Wed Oct 15 15:40:42 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Full matching style response
 #
-# $Id: matchresponse.pm,v 1.26 2003/10/13 19:25:30 albertel Exp $
+# $Id: matchresponse.pm,v 1.27 2003/10/15 19:40:42 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -294,7 +294,7 @@
 	    %{ $Apache::response::itemgroup{'letter_name_map'} };
     }
     foreach my $name (@whichfoils) {
-	my $response = $ENV{'form.HWVAL_'.$Apache::inputtags::response['-1'].":$temp"};
+	my $response = &Apache::response::getresponse($temp);
 	my $responsename = $letter_name_map{$response};
 	$responsehash{$name}=$responsename;
 	my $value=$Apache::response::foilgroup{$name.'.value'};
@@ -421,7 +421,7 @@
 		    $question.='<br />'.$text."\n";
 		}
 		if ($Apache::lonhomework::type eq 'exam') {
-		    $question.=&Apache::optionresponse::webbubbles(\@used_letters,\@used_letters,$temp);
+		    $question.=&Apache::optionresponse::webbubbles(\@used_letters,\@used_letters,$temp,$last_letter);
 		}
 	    } else {		
 		if ($Apache::lonhomework::type eq 'exam') {
Index: loncom/homework/optionresponse.pm
diff -u loncom/homework/optionresponse.pm:1.89 loncom/homework/optionresponse.pm:1.90
--- loncom/homework/optionresponse.pm:1.89	Mon Oct 13 15:25:30 2003
+++ loncom/homework/optionresponse.pm	Wed Oct 15 15:40:42 2003
@@ -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.90 2003/10/15 19:40:42 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -304,8 +304,11 @@
   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 @@
       }
       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 @@
 	  }
 	  $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 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;
 }
 
 
Index: loncom/homework/rankresponse.pm
diff -u loncom/homework/rankresponse.pm:1.21 loncom/homework/rankresponse.pm:1.22
--- loncom/homework/rankresponse.pm:1.21	Mon Oct 13 15:25:30 2003
+++ loncom/homework/rankresponse.pm	Wed Oct 15 15:40:42 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # rank style response
 #
-# $Id: rankresponse.pm,v 1.21 2003/10/13 19:25:30 albertel Exp $
+# $Id: rankresponse.pm,v 1.22 2003/10/15 19:40:42 albertel Exp $
 # Copyright Michigan State University Board of Trustees
 #
 # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
@@ -187,7 +187,7 @@
     my ($temp,$right,$wrong,$ignored)=(0,0,0,0);
     my @correctorder=&get_correct_order($tol,@whichfoils);
     foreach my $name (@whichfoils) {
-	my $response = $ENV{'form.HWVAL_'.$Apache::inputtags::response['-1'].":$temp"};
+	my $response = &Apache::response::getresponse($temp);
 	$responsehash{$name}=$response;
 	my $value=shift(@correctorder);
 	if ( $response =~ /[^\s]/) {
@@ -283,7 +283,8 @@
 		    $result.='<br />'.$text."\n";
 		}
 		if ($Apache::lonhomework::type eq 'exam') {
-		    $result.=&Apache::optionresponse::webbubbles(\@alp,\@whichopt,$temp);
+		    my @values=(1..scalar(@whichopt));
+		    $result.=&Apache::optionresponse::webbubbles(\@values,\@whichopt,$temp,$lastopt);
 		}
 	    } else {
 		if ($Apache::lonhomework::type eq 'exam') {
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.115 loncom/homework/caparesponse/caparesponse.pm:1.116
--- loncom/homework/caparesponse/caparesponse.pm:1.115	Tue Oct 14 18:53:22 2003
+++ loncom/homework/caparesponse/caparesponse.pm	Wed Oct 15 15:40:43 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.115 2003/10/14 22:53:22 albertel Exp $
+# $Id: caparesponse.pm,v 1.116 2003/10/15 19:40:43 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -220,11 +220,16 @@
 		if ($$tagstack[-1] 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"};
 		    for (my $ind=0;$ind<$number_of_bubbles;$ind++) {
+			my $checked='';
+			if ($previous eq $bubble_values[$ind]) {
+			    $checked=" checked='on' ";
+			}
 			$result.='<td><input type="radio" name="HWVAL_'.$id.
-			    '" value="'.$bubble_values[$ind].'"><b>'.
-				$alphabet[$ind].'</b>: '.
-				    $bubble_values[$ind].'</td>';
+			    '" value="'.$bubble_values[$ind].'" '.$checked
+			    .' /><b>'.$alphabet[$ind].'</b>: '.
+			    $bubble_values[$ind].'</td>';
 		    }
 		    $result.='</tr></table>';
 		} elsif ($$tagstack[-1] eq 'formularesponse') {