--- loncom/homework/inputtags.pm 2010/11/09 17:41:47 1.271.2.1 +++ loncom/homework/inputtags.pm 2010/12/20 19:34:47 1.271.2.2 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # input definitons # -# $Id: inputtags.pm,v 1.271.2.1 2010/11/09 17:41:47 raeburn Exp $ +# $Id: inputtags.pm,v 1.271.2.2 2010/12/20 19:34:47 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -175,7 +175,17 @@ sub start_textfield { if ($target eq 'web') { $Apache::lonxml::evaluate--; my $partid=$Apache::inputtags::part; - my $oldresponse = &HTML::Entities::encode($Apache::lonhomework::history{"resource.$partid.$resid.submission"},'<>&"'); + 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 +341,27 @@ sub start_textline { $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=''; @@ -1244,9 +1265,13 @@ sub setgradedata { &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; } + if ($Apache::lonhomework::type eq 'randomizetry') { + $Apache::lonhomework::results{"resource.$id.rndseed"} = $env{'form.'.$id.'.rndseed'}; + } } sub find_which_previous { @@ -1455,6 +1480,7 @@ sub previous_tries { my $count; my %count_lookup; + my $lastrndseed; foreach my $i (1..$Apache::lonhomework::history{'version'}) { my $prefix = $i.":resource.$id"; @@ -1468,7 +1494,8 @@ sub previous_tries { 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) = @@ -1490,6 +1517,11 @@ sub previous_tries { {$1 $txt_correct. $3}s; } my $trystr = "(".&mt('Try [_1]',$Apache::lonhomework::history{"$prefix.tries"}).")"; + if ($curr_rndseed || $lastrndseed) { + if ($curr_rndseed ne $lastrndseed) { + $trystr .= '
'.&mt('New problem variation this try.').''; + } + } $message =~ s{()}{ $trystr $1}; } my ($class) = ($message =~ m{