1: # The LearningOnline Network with CAPA
2: # implements the tags that control the hints
3: #
4: # $Id: hint.pm,v 1.21 2001/12/04 15:17:56 albertel Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::hinttags;
30:
31: use strict;
32: use Apache::lonnet;
33: use capa;
34:
35: sub BEGIN {
36: &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart','numericalhint'));
37: }
38:
39:
40: @Apache::hint::which=();
41: sub start_hintgroup {
42: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
43: my $skiptoend='0';
44: my $result;
45:
46: if ($target eq 'web') {
47: my $id=$Apache::inputtags::part;
48: my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
49: if ( $numtries eq '') { $numtries = 0; }
50: my $hinttries=&Apache::lonnet::EXT("resource.$id.hinttries");
51: if ( $hinttries eq '') { $hinttries = 1; }
52: &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
53: if ( $numtries < $hinttries ) {
54: $skiptoend='1';
55: } else {
56: if ($target eq 'web') {$result='<table bgcolor="#dddddd"><tr><td>';}
57: }
58: if ($skiptoend) {
59: &Apache::lonxml::get_all_text("/hintgroup",$$parser[$#$parser]);
60: }
61: }
62: @Apache::hint::which=();
63: return $result;
64: }
65:
66: sub end_hintgroup {
67: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
68: my $result;
69:
70: if ($target eq 'web') {
71: my $id=$Apache::inputtags::part;
72: my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
73: if ( $numtries eq '') { $numtries = 0; }
74: my $hinttries=&Apache::lonnet::EXT("resource.$id.hinttries");
75: if ( $hinttries eq '') { $hinttries = 1; }
76: &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
77: if ( $numtries >= $hinttries ) {
78: $result='</td></tr></table>';
79: }
80: } elsif ($target eq 'edit') {
81: $result.=&Apache::edit::end_table();
82: }
83: @Apache::hint::which=();
84: return $result;
85: }
86:
87: sub start_numericalhint {
88: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
89: #do everything in end, so intervening <responseparams> work
90: &Apache::response::start_hintresponse($parstack,$safeeval);
91: my $result;
92: if ($target eq 'edit') {
93: $result.=&Apache::edit::tag_start($target,$token);
94: $result.=&Apache::edit::text_arg('Name:','name',$token);
95: $result.=&Apache::edit::text_arg('Answer:','answer',$token);
96: $result.=&Apache::edit::text_arg('Unit:','unit',$token,5);
97: $result.=&Apache::edit::text_arg('Format:','format',$token,4);
98: $result.='</td></tr><tr><td colspan="3">';
99: } elsif ($target eq 'modified') {
100: my $constructtag=
101: &Apache::edit::get_new_args($token,$parstack,$safeeval,
102: 'name','answer','unit', 'format');
103: if ($constructtag) {
104: $result = &Apache::edit::rebuild_tag($token);
105: $result .= &Apache::edit::handle_insert();
106: }
107: }
108: return $result;
109: }
110:
111: sub end_numericalhint {
112: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
113: my $result;
114: if ($target eq 'web') {
115: $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
116: my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
117: &Apache::response::setup_params('numericalhint');
118: my $partid=$Apache::inputtags::part;
119: my $id=$Apache::inputtags::response['-1'];
120: #id submissions occured under
121: my $submitid=$Apache::inputtags::response['-2'];
122: my $response = $Apache::lonhomework::history{
123: "resource.$partid.$submitid.submission"};
124: &Apache::lonxml::debug("hintgroup is using $response<br />\n");
125: #build safe space expression
126: my $expression="&caparesponse_check_list('".$response."','".
127: $$parstack[$#$parstack];
128: #need to get all possible parms
129: foreach my $key (keys(%Apache::inputtags::params)) {
130: $expression.= ';my $'. #'
131: $key.'="'.$Apache::inputtags::params{$key}.'"';
132: }
133: $expression.="');";
134: $result = &Apache::run::run($expression,$safeeval);
135: &Apache::lonxml::debug("$expression:result:$result:$Apache::lonxml::curdepth");
136: my ($awards) = split /:/ , $result;
137: my ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
138: if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') { push (@Apache::hint::which,$name); }
139: $result='';
140: } elsif ($target eq 'meta') {
141: $result=&Apache::response::meta_package_write('numericalhint');
142: } elsif ($target eq 'edit') {
143: $result.='</td></tr>'.&Apache::edit::end_table;
144: }
145: &Apache::response::end_hintresponse();
146: return $result;
147: }
148:
149: # a part shows if it is on, if no specific parts are on, then default shows
150: sub start_hintpart {
151: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
152:
153: my $show ='0';
154: my $result = '';
155: if ($target eq 'web') {
156: my $on= &Apache::lonxml::get_param('on',$parstack,$safeeval);
157: &Apache::lonxml::debug("hintpart sees $on and ,$#Apache::hint::which");
158: if ( $on eq 'default' && $#Apache::hint::which == '-1') {
159: $show=1;
160: } else {
161: my $which;
162: foreach $which (@Apache::hint::which) { if ($which eq $on) { $show = 1; last } }
163: }
164: if (!$show) {
165: &Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
166: }
167: } elsif ($target eq 'grade') {
168: &Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
169: } elsif ($target eq 'edit') {
170: $result.= &Apache::edit::tag_start($target,$token,
171: &Apache::lonxml::description($token));
172: $result.= &Apache::edit::text_arg('On:','on',$token).'</td></tr><tr><td colspan="3">';
173: } elsif ($target eq 'modified') {
174: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
175: 'on');
176: if ($constructtag) {
177: $result = &Apache::edit::rebuild_tag($token);
178: $result.=&Apache::edit::handle_insert();
179: }
180: }
181: return $result;
182: }
183:
184: sub end_hintpart {
185: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
186: my $result;
187: if ($target eq 'edit') { $result.=&Apache::edit::end_table; }
188: return $result;
189: }
190:
191: 1;
192: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>