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

raeburn raeburn@source.lon-capa.org
Sun, 19 Dec 2010 04:24:29 -0000


raeburn		Sun Dec 19 04:24:29 2010 EDT

  Modified files:              
    /loncom/homework	radiobuttonresponse.pm 
  Log:
  - New Question Type - randomizetry
    - Only check radiobutton checked in last try when displaying new try 
      if rndseed for last try is the same as for current try.
  
  
Index: loncom/homework/radiobuttonresponse.pm
diff -u loncom/homework/radiobuttonresponse.pm:1.146 loncom/homework/radiobuttonresponse.pm:1.147
--- loncom/homework/radiobuttonresponse.pm:1.146	Mon Jun 14 02:08:28 2010
+++ loncom/homework/radiobuttonresponse.pm	Sun Dec 19 04:24:29 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # mutliple choice style responses
 #
-# $Id: radiobuttonresponse.pm,v 1.146 2010/06/14 02:08:28 raeburn Exp $
+# $Id: radiobuttonresponse.pm,v 1.147 2010/12/19 04:24:29 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -141,7 +141,7 @@
     my $result;
     %Apache::response::foilgroup=();
     $Apache::radiobuttonresponse::conceptgroup=0;
-    &Apache::response::pushrandomnumber();
+    &Apache::response::pushrandomnumber(undef,$target);
     if ($target eq 'tex' && $Apache::lonhomework::type eq 'exam') {
 	$result.='\item[\textbf{'.$Apache::lonxml::counter.'}.]';
     }
@@ -337,13 +337,24 @@
     my $id=$Apache::inputtags::response['-1'];
     my $part=$Apache::inputtags::part;
     my $lastresponse;
-    unless ((($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') || ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) && (defined($env{'form.grade_symb'}))) {
+    my ($lastresponse,$newvariation,$showanswer);
+    if ((($Apache::lonhomework::history{"resource.$part.type"} eq 'randomizetry') ||
+        ($Apache::lonhomework::type eq 'randomizetry')) &&
+        ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) {
+        if ($env{'form.'.$part.'.rndseed'} ne
+            $Apache::lonhomework::history{"resource.$part.rndseed"}) {
+            $newvariation = 1;
+        }
+    }
+    $showanswer = &Apache::response::show_answer();
+    unless ((($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurvey') || ($Apache::lonhomework::history{"resource.$part.type"} eq 'anonsurveycred')) && (defined($env{'form.grade_symb'})) ||
+           ($newvariation && !$showanswer)) {
         $lastresponse = 
 	    $Apache::lonhomework::history{"resource.$part.$id.submission"};
     }
     if ($direction eq 'horizontal') { $result.='<table><tr>'; }
     my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
-    if (&Apache::response::show_answer() ) {
+    if ($showanswer) {
 	foreach my $name (@names) {
 	    if ($Apache::response::foilgroup{$name.'.value'} ne 'unused') {
 		if (($direction eq 'horizontal') && ($target ne 'tex')) {
@@ -400,6 +411,7 @@
                        type=\"radio\"
                        name=\"HWVAL_$Apache::inputtags::response['-1']\"
                        value=\"$temp\"";
+
 		    if (defined($lastresponse{$name})) { $result .= ' checked="checked"'; }
 		    $result .= ' />'.$Apache::response::foilgroup{$name.'.text'}.
 			'</label>';
@@ -617,7 +629,18 @@
 	my $temp=0;  
 	my $id=$Apache::inputtags::response['-1'];
 	my $part=$Apache::inputtags::part;
-	my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
+        my ($lastresponse,$newvariation);
+        if ((($Apache::lonhomework::history{"resource.$part.type"} eq 'randomizetry') ||
+             ($Apache::lonhomework::type eq 'randomizetry')) && 
+        ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) {
+            if ($env{'form.'.$part.'.rndseed'} ne
+                $Apache::lonhomework::history{"resource.$part.rndseed"}) {
+                $newvariation = 1;
+            }
+        }
+        unless ($newvariation) {
+	    $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"};
+        }
 	my %lastresponse=&Apache::lonnet::str2hash($lastresponse);
 	if ($target ne 'tex' && $direction eq 'horizontal') {
 	    $result.="<table><tr>";