Annotation of loncom/homework/hint.pm, revision 1.3
1.1 albertel 1: package Apache::hinttags;
2:
3: use strict;
4: use Apache::lonnet;
5:
6: sub BEGIN {
1.3 ! albertel 7: &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart','numericalhint'));
1.1 albertel 8: }
9:
1.2 albertel 10:
1.3 ! albertel 11: @Apache::hint::which=();
1.1 albertel 12: sub start_hintgroup {
1.2 albertel 13: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.3 ! albertel 14: my $skiptoend='1';
! 15: my $result;
! 16:
! 17: if ($target ne 'meta' || $target ne 'grade') {
! 18: my $id=$Apache::inputtags::part;
! 19: my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
! 20: if ( $numtries eq '') { $numtries = 0; }
! 21: my $hinttries=&Apache::lonnet::EXT("resource.$id.hinttries");
! 22: if ( $hinttries eq '') { $hinttries = 1; }
! 23: &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
! 24: if ( $numtries > $hinttries ) {
! 25: $skiptoend='0';
! 26: if ($target eq 'web') {$result='<table bgcolor="#dddddd"><tr><td>';}
! 27: }
! 28: }
! 29: if ($skiptoend) {
1.2 albertel 30: &Apache::lonxml::get_all_text("/hintgroup",$$parser[$#$parser]);
31: }
1.3 ! albertel 32: @Apache::hint::which=();
! 33: return $result;
1.1 albertel 34: }
35:
36: sub end_hintgroup {
1.3 ! albertel 37: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
! 38: my $result;
! 39:
! 40: if ($target ne 'meta' || $target ne 'grade') {
! 41: my $id=$Apache::inputtags::part;
! 42: my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
! 43: if ( $numtries eq '') { $numtries = 0; }
! 44: my $hinttries=&Apache::lonnet::EXT("resource.$id.hinttries");
! 45: if ( $hinttries eq '') { $hinttries = 1; }
! 46: &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
! 47: if ( $numtries > $hinttries ) {
! 48: if ($target eq 'web') {$result='</td></tr></table>';}
! 49: }
! 50: }
! 51: @Apache::hint::which='';
! 52: return $result;
! 53: }
! 54:
! 55: sub start_numericalhint {
! 56: #do everything in end, so intervening <responseparams> work
! 57: }
! 58:
! 59: sub end_numericalhint {
! 60: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
! 61: my $result;
! 62: if ($target ne 'meta' && $target ne 'grade') {
! 63: my $args ='';
! 64: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
! 65: my $name = &Apache::run::run("{$args;".'return $name}',$safeeval);
! 66: my $oldresponse = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.$Apache::inputtags::response['-1'].submission"};
! 67: &Apache::lonxml::debug("hintgroup is using $response<br>\n");
! 68: my $expression="&caparesponse_check_list('".$response."','".
! 69: $$parstack[$#$parstack].
! 70: ';my $tol="'.$Apache::inputtags::params{'tol'}.'"'.
! 71: ';my $sig="'.$Apache::inputtags::params{'sig'}.'"'.
! 72: "');";
! 73: $result = &Apache::run::run($expression,$safeeval);
! 74: my ($awards) = split /:/ , $result;
! 75: my ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
! 76: if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') { push (@Apache::hint::which,$name); }
! 77: &Apache::lonxml::debug("\n<br>result:$result:$Apache::lonxml::curdepth<br>\n");
! 78: $result='';
! 79: }
! 80: return $result;
1.1 albertel 81: }
82:
1.2 albertel 83: # a part shows if it is on, if no specific parts are on, then default shows
1.1 albertel 84: sub start_hintpart {
1.2 albertel 85: return '';
1.1 albertel 86: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
87:
88: my $show ='0';
89: if ($target ne 'meta' && $target ne 'grade') {
90: my $args ='';
91: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
92: my $on = &Apache::run::run("{$args;".'return $on}',$safeeval);
1.3 ! albertel 93: if ( $on eq 'default' && $#Apache::hint::which == '-1') {
1.1 albertel 94: } else {
1.3 ! albertel 95: my $which;
! 96: foreeach $which (@Apache::hint::which) { if ($which eq $name) { $show = 1; last } }
1.1 albertel 97: }
98: if (!$show) {
99: &Apache::lonxml::get_all_text("/problem",$$parser[$#$parser]);
100: }
101: } else {
102: &Apache::lonxml::get_all_text("/problem",$$parser[$#$parser]);
103: }
104: return '';
105: }
106:
107: sub end_hintpart {
108: }
109:
110: 1;
111: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>