--- loncom/homework/hint.pm 2003/04/08 02:21:13 1.39
+++ loncom/homework/hint.pm 2004/03/13 00:36:11 1.50
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# implements the tags that control the hints
#
-# $Id: hint.pm,v 1.39 2003/04/08 02:21:13 albertel Exp $
+# $Id: hint.pm,v 1.50 2004/03/13 00:36:11 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -48,20 +48,18 @@ sub start_hintgroup {
my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
if ( $numtries eq '') { $numtries = 0; }
my $hinttries=&Apache::lonnet::EXT("resource.$id.hinttries");
+ if ($ENV{'request.state'} eq 'construct' &&
+ defined($Apache::inputtags::params{'hinttries'})) {
+ $hinttries=$Apache::inputtags::params{'hinttries'};
+ }
+
if ( $hinttries eq '') { $hinttries = 1; }
&Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
- if ($Apache::lonhomework::type ne 'exam') {
- if ( $numtries < $hinttries ) {
- $skiptoend='1';
- } else {
- $result='
';
- }
- } else {
- &Apache::lonxml::startredirection;
- }
- if ($skiptoend) {
+ my $gradestatus=$Apache::lonhomework::history{"resource.$id.solved"};
+ if ( $numtries < $hinttries || $gradestatus =~ /^correct/) {
&Apache::lonxml::get_all_text("/hintgroup",$parser);
}
+ &Apache::lonxml::startredirection;
} elsif ($target eq 'tex') {
$result .= '\keephidden{';
}
@@ -80,12 +78,11 @@ sub end_hintgroup {
my $hinttries=&Apache::lonnet::EXT("resource.$id.hinttries");
if ( $hinttries eq '') { $hinttries = 1; }
&Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
- if ($Apache::lonhomework::type ne 'exam') {
- if ( $numtries >= $hinttries ) {
- $result=' |
';
- }
- } else {
- &Apache::lonxml::endredirection;
+ my $hinttext=&Apache::lonxml::endredirection;
+ if ($Apache::lonhomework::type ne 'exam' &&
+ $numtries >= $hinttries && $hinttext =~/\S/) {
+ $result='';
}
} elsif ($target eq 'edit') {
$result.=&Apache::edit::end_table();
@@ -111,7 +108,9 @@ sub start_numericalhint {
$result.=&Apache::edit::text_arg('Format:','format',$token,4).
&Apache::loncommon::help_open_topic('Numerical_Response_Format');
} elsif ($token->[1] eq 'stringhint') {
- $result.=&Apache::edit::select_arg('Type:','type',['cs','ci','mc'],$token);
+ $result.=&Apache::edit::select_arg('Type:','type',
+ [['cs','Case Sensitive'],['ci','Case Insensitive'],
+ ['mc','Case Insensitive, Any Order']],$token);
} elsif ($token->[1] eq 'formulahint') {
$result.=&Apache::edit::text_arg('Sample Points:','samples',$token,40);
}
@@ -151,7 +150,7 @@ sub end_numericalhint {
}
$safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
- &Apache::response::setup_params('numericalhint');
+ &Apache::response::setup_params('numericalhint',$safeeval);
my $partid=$Apache::inputtags::part;
my $id=$Apache::inputtags::response['-1'];
#id submissions occured under
@@ -164,14 +163,25 @@ sub end_numericalhint {
$$parstack[$#$parstack];
#need to get all possible parms
foreach my $key (keys(%Apache::inputtags::params)) {
- $expression.= ';my $'. #'
+ $expression.= ';my $__LC__'. #'
$key.'="'.$Apache::inputtags::params{$key}.'"';
}
+ if ($$tagstack[-1] eq 'formulahint') {
+ $expression.=';my $__LC__type="fml";';
+ } elsif ($$tagstack[-1] eq 'numericalhint') {
+ $expression.=';my $__LC__type="float";';
+ }
$expression.="');";
- $result = &Apache::run::run($expression,$safeeval);
+ my @answer=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
+ &Apache::lonxml::debug('answer is'.join(':',@answer));
+ @{$safeeval->varglob('CAPARESPONSE_CHECK_LIST_answer')}=@answer;
+
+ ($result,my @msgs) = &Apache::run::run($expression,$safeeval);
+ &Apache::lonxml::debug('msgs are'.join(':',@msgs));
&Apache::lonxml::debug("$expression:result:$result:$Apache::lonxml::curdepth");
- my ($awards) = split /:/ , $result;
- my ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
+ my ($awards)=split(/:/,$result);
+ my (@awards) = split(/,/,$awards);
+ my ($ad, $msg) = &Apache::inputtags::finalizeawards(\@awards,\@msgs);
if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') { push (@Apache::hint::which,$name); }
$result='';
} elsif ($target eq 'meta') {
@@ -357,13 +367,25 @@ sub end_radiobuttonhint {
my $response = $Apache::lonhomework::history{
"resource.$part_id.submission"};
($response)=&Apache::lonnet::str2hash($response);
- if ($answer[0] eq 'foil' && $response eq $answer[1]) {
- push (@Apache::hint::which,$name);
+ &Apache::lonxml::debug("response is $response");
+
+ if ($answer[0] eq 'foil') {
+ shift(@answer);
+ foreach my $answer (@answer) {
+ if ($response eq $answer) {
+ push (@Apache::hint::which,$name);
+ last;
+ }
+ }
} elsif ($answer[0] eq 'concept') {
- if (ref($Apache::hint::radiobutton{"$part_id.concept.".$answer[1]})) {
- my @names=@{ $Apache::hint::radiobutton{"$part_id.concept.".$answer[1]} };
- if (grep(/^\Q$response\E$/,@names)) {
- push(@Apache::hint::which,$name);
+ shift(@answer);
+ foreach my $answer (@answer) {
+ if (ref($Apache::hint::radiobutton{"$part_id.concept.".$answer})) {
+ my @names=@{ $Apache::hint::radiobutton{"$part_id.concept.".$answer} };
+ if (grep(/^\Q$response\E$/,@names)) {
+ push(@Apache::hint::which,$name);
+ last;
+ }
}
}
}