--- loncom/homework/response.pm 2011/11/14 03:08:01 1.227 +++ loncom/homework/response.pm 2013/04/29 21:09:40 1.233 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # various response type definitons response definition # -# $Id: response.pm,v 1.227 2011/11/14 03:08:01 raeburn Exp $ +# $Id: response.pm,v 1.233 2013/04/29 21:09:40 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -53,6 +53,7 @@ package Apache::response; use strict; use Apache::lonlocal; use Apache::lonnet; +use Apache::inputtags(); use Apache::lonmaxima(); use Apache::lonr(); @@ -468,6 +469,18 @@ sub end_customresponse { $error = $award; $award = 'ERROR'; } + if (($award eq 'INCORRECT' || $award eq 'APPROX_ANS' || + $award eq 'EXACT_ANS')) { + if ($Apache::lonhomework::type eq 'survey') { + $award='SUBMITTED'; + } elsif ($Apache::lonhomework::type eq 'surveycred') { + $award='SUBMITTED_CREDIT'; + } elsif ($Apache::lonhomework::type eq 'anonsurvey') { + $award='ANONYMOUS'; + } elsif ($Apache::lonhomework::type eq 'anonsurveycred') { + $award='ANONYMOUS_CREDIT'; + } + } &Apache::response::handle_previous(\%previous,$award); $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}= $award; @@ -490,7 +503,7 @@ sub end_customresponse { $result .= &Apache::response::answer_footer('customresponse'); } if ($target eq 'web') { - &setup_prior_tries_hash(\&format_prior_response_math); + &setup_prior_tries_hash(\&format_prior_response_custom); } if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze') { @@ -511,6 +524,9 @@ sub end_customresponse { sub format_prior_response_custom { my ($mode,$answer) =@_; + if (ref($answer) eq 'ARRAY') { + $answer = '('.join(', ', @{ $answer }).')'; + } return ''. &HTML::Entities::encode($answer,'"<>&').''; } @@ -610,6 +626,18 @@ sub end_mathresponse { $error = $award; $award = 'ERROR'; } + if (($award eq 'INCORRECT' || $award eq 'APPROX_ANS' || + $award eq 'EXACT_ANS')) { + if ($Apache::lonhomework::type eq 'survey') { + $award='SUBMITTED'; + } elsif ($Apache::lonhomework::type eq 'surveycred') { + $award='SUBMITTED_CREDIT'; + } elsif ($Apache::lonhomework::type eq 'anonsurvey') { + $award='ANONYMOUS'; + } elsif ($Apache::lonhomework::type eq 'anonsurveycred') { + $award='ANONYMOUS_CREDIT'; + } + } &Apache::response::handle_previous(\%previous,$award); $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}= $award; @@ -1131,8 +1159,11 @@ sub scored_response { sub whichorder { my ($max,$randomize,$showall,$hash,$rndseed)=@_; #&Apache::lonxml::debug("man $max randomize $randomize"); - if (!defined(@{ $$hash{'names'} })) { return; } - my @names = @{ $$hash{'names'} }; + my @names; + if (ref($hash->{'names'}) eq 'ARRAY') { + @names = @{$hash->{'names'}}; + } + return if (!@names); my @whichopt =(); my (%top,@toplist,%bottom,@bottomlist); if (!($showall || ($randomize eq 'no'))) { @@ -1181,11 +1212,17 @@ sub whichorder { sub show_answer { my $part = $Apache::inputtags::part; - my $award = $Apache::lonhomework::history{"resource.$part.awarded"}; + my $award = $Apache::lonhomework::history{"resource.$part.solved"}; my $status = $Apache::inputtags::status[-1]; - return ( ($award ==1 - && &Apache::lonhomework::show_problem_status()) - || $status eq "SHOW_ANSWER"); + my $canshow = 0; + if ($award =~ /^correct/) { + if (($Apache::lonhomework::history{"resource.$part.awarded"} >= 1) || + (&Apache::lonnet::EXT("resource.$part.retrypartial") !~/^1|on|yes$/)) { + $canshow = 1; + } + } + return (($canshow && &Apache::lonhomework::show_problem_status()) + || $status eq "SHOW_ANSWER"); } sub analyze_store_foilgroup { @@ -1213,8 +1250,11 @@ sub check_if_computed { sub pick_foil_for_concept { my ($target,$attrs,$hinthash,$parstack,$safeeval)=@_; - if (not defined(@{ $Apache::response::conceptgroup{'names'} })) { return; } - my @names = @{ $Apache::response::conceptgroup{'names'} }; + my @names; + if (ref($Apache::response::conceptgroup{'names'}) eq 'ARRAY') { + @names = @{ $Apache::response::conceptgroup{'names'} }; + } + return if (!@names); my $pick=int(&Math::Random::random_uniform() * ($#names+1)); my $name=$names[$pick]; push @{ $Apache::response::foilgroup{'names'} }, $name;