Annotation of loncom/homework/hint.pm, revision 1.20
1.1 albertel 1: package Apache::hinttags;
2:
3: use strict;
4: use Apache::lonnet;
1.6 albertel 5: use capa;
1.1 albertel 6:
7: sub BEGIN {
1.15 albertel 8: &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart','numericalhint'));
1.1 albertel 9: }
10:
1.2 albertel 11:
1.15 albertel 12: @Apache::hint::which=();
1.1 albertel 13: sub start_hintgroup {
1.15 albertel 14: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
15: my $skiptoend='0';
16: my $result;
1.20 ! albertel 17:
1.15 albertel 18: if ($target eq 'web') {
19: my $id=$Apache::inputtags::part;
20: my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
21: if ( $numtries eq '') { $numtries = 0; }
22: my $hinttries=&Apache::lonnet::EXT("resource.$id.hinttries");
23: if ( $hinttries eq '') { $hinttries = 1; }
24: &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
25: if ( $numtries < $hinttries ) {
26: $skiptoend='1';
27: } else {
28: if ($target eq 'web') {$result='<table bgcolor="#dddddd"><tr><td>';}
1.9 albertel 29: }
1.20 ! albertel 30: if ($skiptoend) {
! 31: &Apache::lonxml::get_all_text("/hintgroup",$$parser[$#$parser]);
! 32: }
1.15 albertel 33: }
34: @Apache::hint::which=();
35: return $result;
1.1 albertel 36: }
37:
38: sub end_hintgroup {
1.15 albertel 39: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
40: my $result;
1.20 ! albertel 41:
1.15 albertel 42: if ($target eq 'web') {
43: my $id=$Apache::inputtags::part;
44: my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
45: if ( $numtries eq '') { $numtries = 0; }
46: my $hinttries=&Apache::lonnet::EXT("resource.$id.hinttries");
47: if ( $hinttries eq '') { $hinttries = 1; }
48: &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
1.19 albertel 49: if ( $numtries >= $hinttries ) {
50: $result='</td></tr></table>';
51: }
1.20 ! albertel 52: } elsif ($target eq 'edit') {
! 53: $result.=&Apache::edit::end_table();
1.15 albertel 54: }
1.19 albertel 55: @Apache::hint::which=();
1.15 albertel 56: return $result;
1.3 albertel 57: }
58:
59: sub start_numericalhint {
1.16 albertel 60: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.15 albertel 61: #do everything in end, so intervening <responseparams> work
1.16 albertel 62: &Apache::response::start_hintresponse($parstack,$safeeval);
1.20 ! albertel 63: my $result;
! 64: if ($target eq 'edit') {
! 65: $result.=&Apache::edit::tag_start($target,$token);
! 66: $result.=&Apache::edit::text_arg('Name:','name',$token);
! 67: $result.=&Apache::edit::text_arg('Answer:','answer',$token);
! 68: $result.=&Apache::edit::text_arg('Unit:','unit',$token,5);
! 69: $result.=&Apache::edit::text_arg('Format:','format',$token,4);
! 70: $result.='</td></tr><tr><td colspan="3">';
! 71: } elsif ($target eq 'modified') {
! 72: my $constructtag=
! 73: &Apache::edit::get_new_args($token,$parstack,$safeeval,
! 74: 'name','answer','unit', 'format');
! 75: if ($constructtag) {
! 76: $result = &Apache::edit::rebuild_tag($token);
! 77: $result .= &Apache::edit::handle_insert();
! 78: }
! 79: }
! 80: return $result;
1.3 albertel 81: }
82:
83: sub end_numericalhint {
1.15 albertel 84: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
85: my $result;
86: if ($target eq 'web') {
87: $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
88: my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
1.18 albertel 89: &Apache::response::setup_params('numericalhint');
90: my $partid=$Apache::inputtags::part;
91: my $id=$Apache::inputtags::response['-1'];
92: #id submissions occured under
93: my $submitid=$Apache::inputtags::response['-2'];
94: my $response = $Apache::lonhomework::history{
95: "resource.$partid.$submitid.submission"};
1.15 albertel 96: &Apache::lonxml::debug("hintgroup is using $response<br />\n");
1.18 albertel 97: #build safe space expression
1.15 albertel 98: my $expression="&caparesponse_check_list('".$response."','".
1.18 albertel 99: $$parstack[$#$parstack];
100: #need to get all possible parms
101: foreach my $key (keys(%Apache::inputtags::params)) {
102: $expression.= ';my $'. #'
103: $key.'="'.$Apache::inputtags::params{$key}.'"';
104: }
105: $expression.="');";
1.15 albertel 106: $result = &Apache::run::run($expression,$safeeval);
107: &Apache::lonxml::debug("$expression:result:$result:$Apache::lonxml::curdepth");
108: my ($awards) = split /:/ , $result;
109: my ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
110: if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') { push (@Apache::hint::which,$name); }
111: $result='';
1.17 albertel 112: } elsif ($target eq 'meta') {
113: $result=&Apache::response::meta_package_write('numericalhint');
1.20 ! albertel 114: } elsif ($target eq 'edit') {
! 115: $result.='</td></tr>'.&Apache::edit::end_table;
1.15 albertel 116: }
1.16 albertel 117: &Apache::response::end_hintresponse();
1.15 albertel 118: return $result;
1.1 albertel 119: }
120:
1.2 albertel 121: # a part shows if it is on, if no specific parts are on, then default shows
1.1 albertel 122: sub start_hintpart {
1.15 albertel 123: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
124:
125: my $show ='0';
1.20 ! albertel 126: my $result = '';
1.15 albertel 127: if ($target eq 'web') {
128: my $on= &Apache::lonxml::get_param('on',$parstack,$safeeval);
129: &Apache::lonxml::debug("hintpart sees $on and ,$#Apache::hint::which");
130: if ( $on eq 'default' && $#Apache::hint::which == '-1') {
131: $show=1;
132: } else {
133: my $which;
134: foreach $which (@Apache::hint::which) { if ($which eq $on) { $show = 1; last } }
135: }
136: if (!$show) {
137: &Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
1.1 albertel 138: }
1.15 albertel 139: } elsif ($target eq 'grade') {
140: &Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
1.20 ! albertel 141: } elsif ($target eq 'edit') {
! 142: $result.= &Apache::edit::tag_start($target,$token,
! 143: &Apache::lonxml::description($token));
! 144: $result.= &Apache::edit::text_arg('On:','on',$token).'</td></tr><tr><td colspan="3">';
! 145: } elsif ($target eq 'modified') {
! 146: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
! 147: 'on');
! 148: if ($constructtag) {
! 149: $result = &Apache::edit::rebuild_tag($token);
! 150: $result.=&Apache::edit::handle_insert();
! 151: }
1.15 albertel 152: }
1.20 ! albertel 153: return $result;
1.1 albertel 154: }
155:
156: sub end_hintpart {
1.20 ! albertel 157: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
! 158: my $result;
! 159: if ($target eq 'edit') { $result.=&Apache::edit::end_table; }
! 160: return $result;
1.1 albertel 161: }
162:
163: 1;
164: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>