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

raeburn raeburn@source.lon-capa.org
Sun, 19 Dec 2010 02:58:16 -0000


raeburn		Sun Dec 19 02:58:16 2010 EDT

  Modified files:              
    /loncom/homework	inputtags.pm 
  Log:
  - New Question Type - randomizetry
    - Only display submission from last try in textbox or textarea for new
      try, if rndseed for last try is the same as for current try.
    - Include item in "Try" column in previous tries display to show when a
      new problem variation was used.
    - Store questiontype in resource.$partid.type in Apache::lonhomework::results.
  
  
Index: loncom/homework/inputtags.pm
diff -u loncom/homework/inputtags.pm:1.273 loncom/homework/inputtags.pm:1.274
--- loncom/homework/inputtags.pm:1.273	Wed Nov  3 17:06:28 2010
+++ loncom/homework/inputtags.pm	Sun Dec 19 02:58:16 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # input  definitons
 #
-# $Id: inputtags.pm,v 1.273 2010/11/03 17:06:28 raeburn Exp $
+# $Id: inputtags.pm,v 1.274 2010/12/19 02:58:16 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -175,7 +175,18 @@
     if ($target eq 'web') {
 	$Apache::lonxml::evaluate--;
 	my $partid=$Apache::inputtags::part;
-	my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$resid.submission"},'<>&"');
+        my ($oldresponse,$newvariation);
+        if ((($Apache::lonhomework::history{"resource.$partid.type"} eq 'randomizetry') ||
+             ($Apache::lonhomework::type eq 'randomizetry')) &&
+             ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) {
+            if ($env{'form.'.$partid.'.rndseed'} ne
+                $Apache::lonhomework::history{"resource.$partid.rndseed"}) {
+                $newvariation = 1;
+            }
+        }
+        unless ($newvariation) {
+	    $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$resid.submission"},'<>&"');
+        }
 	if ($Apache::inputtags::status[-1] eq 'CAN_ANSWER') {
 	    my $cols = &Apache::lonxml::get_param('cols',$parstack,$safeeval);
 	    if ( $cols eq '') { $cols = 80; }
@@ -331,16 +342,26 @@
 		    $maxlength = ' maxlength="'.$size.'"';
 		}
 	    }
-	    my $oldresponse = $Apache::lonhomework::history{"resource.$partid.$id.submission"};
-	    &Apache::lonxml::debug("oldresponse $oldresponse is ".ref($oldresponse));
-
-	    if (ref($oldresponse) eq 'ARRAY') {
-		$oldresponse = $oldresponse->[$#Apache::inputtags::inputlist];
-	    }
-	    $oldresponse = &HTML::Entities::encode($oldresponse,'<>&"');
-            $oldresponse =~ s/^\s+//;
-            $oldresponse =~ s/\s+$//;
-            $oldresponse =~ s/\s+/ /g;
+            my ($oldresponse,$newvariation);
+            if ((($Apache::lonhomework::history{"resource.$partid.type"} eq 'randomizetry') ||
+                 ($Apache::lonhomework::type eq 'randomizetry')) &&
+                 ($Apache::inputtags::status[-1] eq 'CAN_ANSWER')) {
+                if ($env{'form.'.$partid.'.rndseed'} ne
+                    $Apache::lonhomework::history{"resource.$partid.rndseed"}) {
+                    $newvariation = 1;
+                }
+            }
+            unless ($newvariation) {
+	        $oldresponse = $Apache::lonhomework::history{"resource.$partid.$id.submission"};
+	        &Apache::lonxml::debug("oldresponse $oldresponse is ".ref($oldresponse));
+	        if (ref($oldresponse) eq 'ARRAY') {
+		    $oldresponse = $oldresponse->[$#Apache::inputtags::inputlist];
+	        }
+	        $oldresponse = &HTML::Entities::encode($oldresponse,'<>&"');
+                $oldresponse =~ s/^\s+//;
+                $oldresponse =~ s/\s+$//;
+                $oldresponse =~ s/\s+/ /g;
+            }
 	    if ($Apache::lonhomework::type ne 'exam') {
 		my $addchars=&Apache::lonxml::get_param('addchars',$parstack,$safeeval);
 		$result='';
@@ -1254,7 +1275,8 @@
 	&Apache::response::add_to_gradingqueue();
     }
     if (($Apache::lonhomework::type eq 'anonsurvey') ||
-        ($Apache::lonhomework::type eq 'anonsurveycred')) {
+        ($Apache::lonhomework::type eq 'anonsurveycred') || 
+        ($Apache::lonhomework::type eq 'randomizetry')) {
         $Apache::lonhomework::results{"resource.$id.type"} = $Apache::lonhomework::type;
     }
 }
@@ -1465,6 +1487,7 @@
 
     my $count;
     my %count_lookup;
+    my $lastrndseed;
 
     foreach my $i (1..$Apache::lonhomework::history{'version'}) {
 	my $prefix = $i.":resource.$id";
@@ -1478,7 +1501,7 @@
 	next if (!exists($Apache::lonhomework::history{"$prefix.award"}));
 	$count++;
 	$count_lookup{$i} = $count;
-	
+        my $curr_rndseed = $Apache::lonhomework::history{"$prefix.rndseed"};
 	my ($previousmsg,$latemessage,$message,$trystr);
 
 	($previousmsg,$latemessage,$message,$trystr) =
@@ -1500,6 +1523,11 @@
                              {$1 <strong>$txt_correct</strong>. $3}s;
 	    }
             my $trystr = "(".&mt('Try [_1]',$Apache::lonhomework::history{"$prefix.tries"}).")";
+            if ($curr_rndseed || $lastrndseed) {
+                if ($curr_rndseed ne $lastrndseed) {
+                    $trystr .= '<br /><span style="color: green; white-space: nowrap; font-style: italic; font-weight: bold; font-size: 80%;">'.&mt('New problem variation this try.').'</span>';
+                }
+            } 
 	    $message =~ s{(</td>)}{ $trystr $1};
 	}
 	my ($class) = ($message =~ m{<td.*class="([^"]*)"}); #"
@@ -1529,6 +1557,7 @@
 	    }
 	}
 	$output.=&Apache::loncommon::end_data_table_row()."\n";
+        $lastrndseed = $curr_rndseed;
     }
     return if ($output eq '');
     my $headers =