1: # The LON-CAPA hint handler.
2: #
3: # Handles the displaying of hints.
4: #
5: # YEAR=2000
6: # 12/19,12/21 Guy Albertelli
7: # YEAR=2001
8: # 1/4,1/5,1/22,2/7,2/19,3/31,4/5,4/10,5/31,6/2 Guy Albertelli
9: # 8/6 Scott Harrison
10:
11: package Apache::hinttags;
12:
13: use strict;
14: use Apache::lonnet;
15: use capa;
16:
17: # ======================================================================= BEGIN
18: sub BEGIN {
19: &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart',
20: 'numericalhint'));
21: }
22:
23: @Apache::hint::which = ();
24:
25: # ============================================================ Start hint group
26: sub start_hintgroup {
27: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
28: my $skiptoend = '0';
29: my $result;
30: if ($target eq 'web') {
31: my $id = $Apache::inputtags::part;
32: my $numtries = $Apache::lonhomework::history{"resource.$id.tries"};
33: if ( $numtries eq '') { $numtries = 0; }
34: my $hinttries = &Apache::lonnet::EXT("resource.$id.hinttries");
35: if ( $hinttries eq '') { $hinttries = 1; }
36: &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
37: if ( $numtries < $hinttries ) {
38: $skiptoend = '1';
39: } else {
40: if ($target eq 'web') {
41: $result = '<table bgcolor="#dddddd"><tr><td>';
42: }
43: }
44: }
45: if ($skiptoend) {
46: &Apache::lonxml::get_all_text("/hintgroup",$$parser[$#$parser]);
47: }
48: @Apache::hint::which = ();
49: return $result;
50: }
51:
52: # ============================================================== End hint group
53: sub end_hintgroup {
54: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
55: my $result;
56: if ($target eq 'web') {
57: my $id = $Apache::inputtags::part;
58: my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
59: if ( $numtries eq '') { $numtries = 0; }
60: my $hinttries=&Apache::lonnet::EXT("resource.$id.hinttries");
61: if ( $hinttries eq '') { $hinttries = 1; }
62: &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
63: if ( $numtries => $hinttries ) {
64: if ($target eq 'web') {$result = '</td></tr></table>';}
65: }
66: }
67: @Apache::hint::which = '';
68: return $result;
69: }
70:
71: # ======================================================== Start numerical hint
72: sub start_numericalhint {
73: #do everything in end, so intervening <responseparams> work
74: return '';
75: }
76:
77: # ========================================================== End numerical hint
78: sub end_numericalhint {
79: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
80: my $result;
81: if ($target eq 'web') {
82: $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
83: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
84: my $response = $Apache::lonhomework::history{'resource.'.
85: $Apache::inputtags::part.'.'.
86: $Apache::inputtags::response['-1'].'.submission'};
87: &Apache::lonxml::debug("hintgroup is using $response<br />\n");
88: my $expression = "&caparesponse_check_list('".$response."','".
89: $$parstack[$#$parstack].
90: ';my $tol="'.$Apache::inputtags::params{'tol'}.'"'.
91: ';my $sig="'.$Apache::inputtags::params{'sig'}.'"'.
92: "');";
93: $result = &Apache::run::run($expression,$safeeval);
94: &Apache::lonxml::debug("$expression:result:$result:".
95: $Apache::lonxml::curdepth);
96: my ($awards) = split /:/, $result;
97: my ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
98: if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') {
99: push (@Apache::hint::which,$name); }
100: $result = '';
101: }
102: return $result;
103: }
104:
105: # ======================================================= Starting part of hint
106: # a part shows if it is on, if no specific parts are on, then default shows
107: sub start_hintpart {
108: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
109: my $show ='0';
110: if ($target eq 'web') {
111: my $on= &Apache::lonxml::get_param('on',$parstack,$safeeval);
112: &Apache::lonxml::debug("hintpart sees $on and ,$#Apache::hint::which");
113: if ( $on eq 'default' && $#Apache::hint::which == '-1') {
114: $show=1;
115: } else {
116: my $which;
117: foreach $which (@Apache::hint::which) {
118: if ($which eq $on) { $show = 1; last } }
119: }
120: if (!$show) {
121: &Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
122: }
123: } elsif ($target eq 'grade') {
124: &Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
125: }
126: return '';
127: }
128:
129: # ========================================================= Ending part of hint
130: sub end_hintpart {
131: return '';
132: }
133:
134: 1;
135:
136: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>