File:
[LON-CAPA] /
loncom /
homework /
hint.pm
Revision
1.70:
download - view:
text,
annotated -
select for diffs
Fri Sep 12 09:56:09 2008 UTC (15 years, 11 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Bug 5531 (although should really be a separate bug).
RegExp used to separate units from numerical part of an answer can truncate responses to stringresponse items for which the type has not been explicitly set (as ci, cs, mc or re).
- Include the tagname of the response item in calls to caparesponse_check_list(), so that if the type attribute is unspecified, stringresponse submissions are not subjected to the unit extractor.
Perhaps there is a reason why this ambiguity has not been eliminated previously by passing the tagname to caparesponse_check_list() - run in the safe space?
Testing needed.
1: # The LearningOnline Network with CAPA
2: # implements the tags that control the hints
3: #
4: # $Id: hint.pm,v 1.70 2008/09/12 09:56:09 raeburn 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 me&aree 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: use Apache::caparesponse();
35: use Apache::lonmaxima();
36: use Apache::response();
37: use Apache::lonlocal;
38: use Storable qw(dclone);
39:
40: BEGIN {
41: &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart','numericalhint','stringhint','formulahint','optionhint','radiobuttonhint','mathhint','customhint'));
42: }
43:
44:
45: @Apache::hint::which=();
46: sub start_hintgroup {
47: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
48: my $skiptoend='0';
49: my $result;
50:
51: if ($target eq 'web') {
52: my $id=$Apache::inputtags::part;
53: my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
54: if ( $numtries eq '') { $numtries = 0; }
55: my $hinttries=&Apache::response::get_response_param($id,"hinttries",1);
56: &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
57: my $gradestatus=
58: $Apache::lonhomework::history{"resource.$id.solved"};
59: my $showoncorrect=lc(&Apache::lonxml::get_param('showoncorrect',$parstack,$safeeval));
60: &Apache::lonxml::debug("onc orrect $showoncorrect, $gradestatus");
61: if ( ($showoncorrect ne 'yes' && &Apache::response::show_answer()) ||
62: ( $numtries < $hinttries) ) {
63: &Apache::lonxml::debug("Grabbin all");
64: &Apache::lonxml::get_all_text("/hintgroup",$parser,$style);
65: }
66: &Apache::lonxml::startredirection;
67: } elsif ($target eq 'tex') {
68: $result .= '\keephidden{';
69: } elsif ($target eq 'edit') {
70: $result.=&Apache::edit::tag_start($target,$token);
71: $result.=&Apache::edit::select_arg('Show hint even if problem Correct:','showoncorrect',[['no',&mt('No')],['yes',&mt('Yes')]],$token);
72: $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
73: } elsif ($target eq 'modified') {
74: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'showoncorrect');
75: if ($constructtag) {
76: $result =&Apache::edit::rebuild_tag($token);
77: }
78: }
79: @Apache::hint::which=();
80: return $result;
81: }
82:
83: sub end_hintgroup {
84: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
85: my $result;
86:
87: if ($target eq 'web') {
88: my $id=$Apache::inputtags::part;
89: my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
90: if ( $numtries eq '') { $numtries = 0; }
91: my $hinttries=&Apache::response::get_response_param($id,"hinttries",1);
92: &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
93: my $hinttext=&Apache::lonxml::endredirection;
94: if ($Apache::lonhomework::type ne 'exam' &&
95: $numtries >= $hinttries && $hinttext =~/\S/) {
96: $result='<table bgcolor="#dddddd"><tr><td>'.
97: $hinttext.'</td></tr></table>';
98: }
99: } elsif ($target eq 'edit') {
100: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
101: } elsif ($target eq 'tex') {
102: $result .= '}';
103: }
104: @Apache::hint::which=();
105: return $result;
106: }
107:
108: sub start_numericalhint {
109: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
110: #do everything in end, so intervening <responseparams> work
111: &Apache::response::start_hintresponse($parstack,$safeeval);
112: &Apache::caparesponse::push_answer();
113: my $result;
114: if ($target eq 'edit') {
115: $result.=&Apache::edit::tag_start($target,$token);
116: $result.=&Apache::edit::text_arg('Name:','name',$token);
117: $result.=&Apache::edit::text_arg('Answer:','answer',$token);
118: if ($token->[1] eq 'numericalhint') {
119: $result.=&Apache::edit::text_arg('Unit:','unit',$token,5).
120: &Apache::loncommon::help_open_topic('Physical_Units');
121: $result.=&Apache::edit::text_arg('Format:','format',$token,4).
122: &Apache::loncommon::help_open_topic('Numerical_Response_Format');
123: } elsif ($token->[1] eq 'formulahint') {
124: $result.=&Apache::edit::text_arg('Sample Points:','samples',
125: $token,40).
126: &Apache::loncommon::help_open_topic('Formula_Response_Sampling');
127: }
128: $result.=&Apache::edit::end_row();
129: $result.=&Apache::edit::start_spanning_row();
130: } elsif ($target eq 'modified') {
131: my $constructtag;
132: if ($token->[1] eq 'numericalhint') {
133: $constructtag=&Apache::edit::get_new_args($token,$parstack,
134: $safeeval,'name',
135: 'answer','unit','format');
136: } elsif ($token->[1] eq 'formulahint') {
137: $constructtag=&Apache::edit::get_new_args($token,$parstack,
138: $safeeval,'name','answer',
139: 'samples');
140: }
141: if ($constructtag) {
142: $result = &Apache::edit::rebuild_tag($token);
143: }
144: } elsif ($target eq 'web') {
145: &Apache::response::reset_params();
146: }
147: return $result;
148: }
149:
150: sub end_numericalhint {
151: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
152: my $result;
153: if ($target eq 'web') {
154: if (!$Apache::lonxml::default_homework_loaded) {
155: &Apache::lonxml::default_homework_load($safeeval);
156: }
157: $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
158: my $hint_name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
159: &Apache::response::setup_params('numericalhint',$safeeval);
160:
161: my $partid=$Apache::inputtags::part;
162: my $id=$Apache::inputtags::hint[-1];
163: #id submissions occurred under
164: my $submitid=$Apache::inputtags::response[-1];
165:
166: my $response = $Apache::lonhomework::history{
167: "resource.$partid.$submitid.submission"};
168: &Apache::lonxml::debug("hintgroup is using $response<br />\n");
169:
170: my @args = ('type','tol','sig','ans_fmt','unit','calc','samples');
171: my $args_ref =
172: &Apache::caparesponse::setup_capa_args($safeeval,$parstack,
173: \@args,$response);
174:
175: my $hideunit=&Apache::response::get_response_param($partid.'_'.$submitid,'turnoffunit');
176: if (lc($hideunit) eq "yes") { delete($$args_ref{'unit'}); }
177:
178: if ($$tagstack[-1] eq 'formulahint') {
179: if ($$args_ref{'samples'}) {
180: $$args_ref{'type'}='fml';
181: } else {
182: $$args_ref{'type'}='math';
183: }
184: } elsif ($$tagstack[-1] eq 'numericalhint') {
185: $$args_ref{'type'}='float';
186: }
187: &Apache::caparesponse::add_in_tag_answer($parstack,$safeeval);
188: my %answer = &Apache::caparesponse::get_answer();
189: my (@final_awards,@final_msgs,@ans_names);
190: foreach my $ans_name (keys(%answer)) {
191: &Apache::lonxml::debug(" doing $ans_name with ".join(':',@{ $answer{$ans_name}{'answers'} }));
192:
193: ${$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=
194: dclone($answer{$ans_name});
195: &Apache::caparesponse::setup_capa_response($args_ref,$response);
196: my ($result,@msgs) =
197: &Apache::run::run("&caparesponse_check_list($$tagstack[-1])",$safeeval);
198: &Apache::lonxml::debug("checking $ans_name $result with $response");
199: &Apache::lonxml::debug('msgs are '.join(':',@msgs));
200: my ($awards)=split(/:/,$result);
201: my @awards= split(/,/,$awards);
202: my ($ad, $msg) =
203: &Apache::inputtags::finalizeawards(\@awards,\@msgs);
204: push(@final_awards,$ad);
205: push(@final_msgs,$msg);
206: push(@ans_names,$ans_name);
207: }
208: my ($ad, $msg, $ans_name) =
209: &Apache::inputtags::finalizeawards(\@final_awards,
210: \@final_msgs,
211: \@ans_names,1);
212: if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') {
213: push(@Apache::hint::which,$hint_name);
214: }
215: $result='';
216: } elsif ($target eq 'meta') {
217: $result=&Apache::response::meta_package_write($token->[1]);
218: } elsif ($target eq 'edit') {
219: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
220: }
221: &Apache::caparesponse::pop_answer();
222: &Apache::response::end_hintresponse();
223: return $result;
224: }
225:
226: sub start_formulahint {
227: return &start_numericalhint(@_);
228: }
229:
230: sub end_formulahint {
231: return &end_numericalhint(@_);
232: }
233:
234: sub start_mathhint {
235: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
236: #do everything in end, so intervening <responseparams> and <answer> work
237: &Apache::response::start_hintresponse($parstack,$safeeval);
238: &Apache::lonxml::register('Apache::response',('answer'));
239: my $result;
240: if ($target eq 'edit') {
241: $result.=&Apache::edit::tag_start($target,$token);
242: $result.=&Apache::edit::text_arg('Name:','name',$token);
243: $result.=&Apache::edit::select_arg('Algebra System:',
244: 'cas',
245: ['maxima'],
246: $token);
247: $result.=&Apache::edit::text_arg('Argument Array:',
248: 'args',$token);
249: $result.=&Apache::edit::end_row();
250: $result.=&Apache::edit::start_spanning_row();
251: } elsif ($target eq 'modified') {
252: my $constructtag;
253: $constructtag=&Apache::edit::get_new_args($token,$parstack,
254: $safeeval,'name','cas',
255: 'args');
256: $result = &Apache::edit::rebuild_tag($token);
257: } elsif ($target eq 'web') {
258: &Apache::response::reset_params();
259: }
260: return $result;
261: }
262:
263: sub end_mathhint {
264: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
265: my $result;
266: if ($target eq 'web') {
267: if (!$Apache::lonxml::default_homework_loaded) {
268: &Apache::lonxml::default_homework_load($safeeval);
269: }
270: my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
271: &Apache::response::setup_params('mathhint',$safeeval);
272: my $partid=$Apache::inputtags::part;
273: my $submitid=$Apache::inputtags::response[-1];
274: my $response = $Apache::lonhomework::history{
275: "resource.$partid.$submitid.submission"};
276:
277: my $cas = &Apache::lonxml::get_param('cas',$parstack,$safeeval);
278: my $award;
279: if ($cas eq 'maxima') {
280: my $args = [&Apache::lonxml::get_param_var('args',$parstack,$safeeval)];
281: $award=&Apache::lonmaxima::maxima_run($Apache::response::custom_answer[-1],$response,$args);
282: }
283: if ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS') {
284: push (@Apache::hint::which,$name);
285: }
286: $result='';
287: } elsif ($target eq 'meta') {
288: $result=&Apache::response::meta_package_write($token->[1]);
289: } elsif ($target eq 'edit') {
290: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
291: }
292: pop(@Apache::response::custom_answer);
293: pop(@Apache::response::custom_answer_type);
294: &Apache::response::end_hintresponse();
295: return $result;
296: }
297:
298: sub start_customhint {
299: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
300: #do everything in end, so intervening <responseparams> and <answer> work
301: &Apache::response::start_hintresponse($parstack,$safeeval);
302: &Apache::lonxml::register('Apache::response',('answer'));
303: my $result;
304: if ($target eq 'edit') {
305: $result.=&Apache::edit::tag_start($target,$token);
306: $result.=&Apache::edit::text_arg('Name:','name',$token);
307: $result.=&Apache::edit::end_row();
308: $result.=&Apache::edit::start_spanning_row();
309: } elsif ($target eq 'modified') {
310: my $constructtag;
311: $constructtag=&Apache::edit::get_new_args($token,$parstack,
312: $safeeval,'name');
313: $result = &Apache::edit::rebuild_tag($token);
314: } elsif ($target eq 'web') {
315: &Apache::response::reset_params();
316: }
317: return $result;
318: }
319:
320: sub end_customhint {
321: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
322: my $result;
323: if ($target eq 'web') {
324: if (!$Apache::lonxml::default_homework_loaded) {
325: &Apache::lonxml::default_homework_load($safeeval);
326: }
327: my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
328: &Apache::response::setup_params('customhint',$safeeval);
329: my $partid=$Apache::inputtags::part;
330: my $submitid=$Apache::inputtags::response[-1];
331: my $response = $Apache::lonhomework::history{
332: "resource.$partid.$submitid.submission"};
333: my $award;
334: if ( $response =~ /[^\s]/ &&
335: $Apache::response::custom_answer_type[-1] eq 'loncapa/perl') {
336: if (!$Apache::lonxml::default_homework_loaded) {
337: &Apache::lonxml::default_homework_load($safeeval);
338: }
339: ${$safeeval->varglob('LONCAPA::customresponse_submission')}=
340: $response;
341:
342: $award = &Apache::run::run('{ my $submission=$LONCAPA::customresponse_submission;'.$Apache::response::custom_answer[-1].'}',$safeeval);
343: }
344: if ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS') {
345: push (@Apache::hint::which,$name);
346: }
347: $result='';
348: } elsif ($target eq 'meta') {
349: $result=&Apache::response::meta_package_write($token->[1]);
350: } elsif ($target eq 'edit') {
351: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
352: }
353: pop(@Apache::response::custom_answer);
354: pop(@Apache::response::custom_answer_type);
355: &Apache::response::end_hintresponse();
356: return $result;
357: }
358:
359: sub start_stringhint {
360: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
361: #do everything in end, so intervening <responseparams> work
362: &Apache::response::start_hintresponse($parstack,$safeeval);
363: my $result;
364: if ($target eq 'edit') {
365: $result.=&Apache::edit::tag_start($target,$token);
366: $result.=&Apache::edit::text_arg('Name:','name',$token);
367: $result.=&Apache::edit::text_arg('Answer:','answer',$token);
368: $result.=&Apache::edit::select_arg('Type:','type',
369: [['cs','Case Sensitive'],['ci','Case Insensitive'],
370: ['mc','Case Insensitive, Any Order'],
371: ['re','Regular Expression']],$token);
372: $result.=&Apache::edit::end_row();
373: $result.=&Apache::edit::start_spanning_row();
374: } elsif ($target eq 'modified') {
375: my $constructtag;
376: $constructtag=&Apache::edit::get_new_args($token,$parstack,
377: $safeeval,'name','answer',
378: 'type');
379: $result = &Apache::edit::rebuild_tag($token);
380: } elsif ($target eq 'web') {
381: &Apache::response::reset_params();
382: }
383: return $result;
384: }
385:
386: sub end_stringhint {
387: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
388: my $result;
389: if ($target eq 'web') {
390: if (!$Apache::lonxml::default_homework_loaded) {
391: &Apache::lonxml::default_homework_load($safeeval);
392: }
393: $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
394: my $hint_name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
395: &Apache::response::setup_params('stringhint',$safeeval);
396: my $partid=$Apache::inputtags::part;
397: my $id=$Apache::inputtags::hint[-1];
398: #id submissions occurred under
399: my $submitid=$Apache::inputtags::response[-1];
400: my $response = $Apache::lonhomework::history{
401: "resource.$partid.$submitid.submission"};
402: &Apache::lonxml::debug("hintgroup is using $response<br />\n");
403: my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
404: my ($ad,$msg);
405: if ($type eq 're' ) {
406: my $answer=&Apache::lonxml::get_param('answer',$parstack,
407: $safeeval);
408: ${$safeeval->varglob('LONCAPA::response')}=$response;
409: my $compare='=';
410: if ($answer=~/^\s*NOT\s*/) {
411: $answer=~s/^\s*NOT\s*//;
412: $compare='!';
413: }
414: my $test='$LONCAPA::response'.$compare.'~m'.$answer;
415: &Apache::lonxml::debug("test $test");
416: $result = &Apache::run::run("return $test",$safeeval);
417: &Apache::lonxml::debug("current $response");
418: &Apache::lonxml::debug("current $answer");
419: $ad = ($result) ? 'APPROX_ANS' : 'INCORRECT';
420: } else {
421: my @args = ('type');
422: my $args_ref =
423: &Apache::caparesponse::setup_capa_args($safeeval,$parstack,
424: \@args,$response);
425: &Apache::caparesponse::add_in_tag_answer($parstack,$safeeval);
426: my (@final_awards,@final_msgs,@ans_names);
427: my %answer = &Apache::caparesponse::get_answer();
428: foreach my $ans_name (keys(%answer)) {
429: &Apache::lonxml::debug(" doing $ans_name with ".join(':',@{ $answer{$ans_name}{'answers'} }));
430: ${$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=dclone($answer{$ans_name});
431: my ($result, @msgs)=&Apache::run::run("&caparesponse_check_list($$tagstack[-1])",$safeeval);
432: &Apache::lonxml::debug('msgs are'.join(':',@msgs));
433: my ($awards) = split(/:/,$result);
434: my (@awards) = split(/,/,$awards);
435: ($ad,$msg) =
436: &Apache::inputtags::finalizeawards(\@awards,\@msgs);
437: push(@final_awards,$ad);
438: push(@final_msgs,$msg);
439: push(@ans_names,$ans_name);
440: &Apache::lonxml::debug("\n<br>result:$result:$Apache::lonxml::curdepth<br>\n");
441: }
442: my ($ad, $msg, $ans_name) =
443: &Apache::inputtags::finalizeawards(\@final_awards,
444: \@final_msgs,
445: \@ans_names,1);
446: }
447: if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') {
448: push(@Apache::hint::which,$hint_name);
449: }
450: $result='';
451: } elsif ($target eq 'meta') {
452: $result=&Apache::response::meta_package_write($token->[1]);
453: } elsif ($target eq 'edit') {
454: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
455: }
456: &Apache::response::end_hintresponse();
457: return $result;
458: }
459:
460: # a part shows if it is on, if no specific parts are on, then default shows
461: sub start_hintpart {
462: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
463:
464: my $show ='0';
465: my $result = '';
466: if ($target eq 'web') {
467: my $on= &Apache::lonxml::get_param('on',$parstack,$safeeval);
468: &Apache::lonxml::debug("hintpart sees $on and ,$#Apache::hint::which");
469: if ( $on eq 'default' && $#Apache::hint::which == '-1') {
470: $show=1;
471: } else {
472: my $which;
473: foreach $which (@Apache::hint::which) { if ($which eq $on) { $show = 1; last } }
474: }
475: if (!$show) {
476: &Apache::lonxml::get_all_text("/hintpart",$parser,$style);
477: }
478: } elsif ($target eq 'grade') {
479: &Apache::lonxml::get_all_text("/hintpart",$parser,$style);
480: } elsif ($target eq 'edit') {
481: $result.= &Apache::edit::tag_start($target,$token);
482: $result.= &Apache::edit::text_arg('On:','on',$token);
483: $result.= &Apache::edit::end_row();
484: $result.= &Apache::edit::start_spanning_row();
485: } elsif ($target eq 'modified') {
486: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
487: $safeeval,'on');
488: if ($constructtag) {
489: $result = &Apache::edit::rebuild_tag($token);
490: }
491: }
492: return $result;
493: }
494:
495: sub end_hintpart {
496: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
497: my $result;
498: if ($target eq 'edit') {
499: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
500: }
501: return $result;
502: }
503:
504: sub start_optionhint {
505: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
506: my $result;
507: &Apache::response::start_hintresponse($parstack,$safeeval);
508: if ($target eq 'edit') {
509: $result.=&Apache::edit::tag_start($target,$token);
510: $result.=&Apache::edit::text_arg('Name:','name',$token);
511: $result.=&Apache::edit::text_arg('Answer:','answer',$token,40);
512: $result.=&Apache::edit::text_arg('Concept:','concept',$token,50);
513: } elsif ($target eq 'modified') {
514: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
515: $safeeval,'name',
516: 'answer','concept');
517: if ($constructtag) {
518: $result = &Apache::edit::rebuild_tag($token);
519: }
520: } elsif ($target eq 'meta') {
521: $result=&Apache::response::meta_package_write('numericalhint');
522: }
523: return $result;
524: }
525:
526: sub end_optionhint {
527: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
528: my $result;
529: if ($target eq 'web') {
530: my ($foilmatch,$conceptmatch)=(-1,-1);
531: my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
532: my $partid=$Apache::inputtags::part;
533: #id submissions occurred under
534: my $submitid=$Apache::inputtags::response[-1];
535: my $part_id="$partid.$submitid";
536: my %answer;
537: my $answer=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
538: if ($answer) {
539: eval('%answer ='.$answer);
540: &Apache::lonxml::debug("answwer hash");
541: &Apache::lonhomework::showhash(%answer);
542: my $response = $Apache::lonhomework::history{
543: "resource.$part_id.submission"};
544: my %response=&Apache::lonnet::str2hash($response);
545: &Apache::lonhomework::showhash(%response);
546: foreach my $foil (keys(%answer)) {
547: $foilmatch=1;
548: if ($answer{$foil} ne $response{$foil}) {$foilmatch=0;last;}
549: }
550: }
551: my %concept;
552: my $constr=&Apache::lonxml::get_param('concept',$parstack,$safeeval);
553: if ( $constr ) { eval('%concept ='.$constr); }
554: my $response = $Apache::lonhomework::history{
555: "resource.$part_id.submissiongrading"};
556: my %response=&Apache::lonnet::str2hash($response);
557: foreach my $concept (keys(%concept)) {
558: my $compare;
559: if ($concept{$concept} eq 'correct') {$compare=1}else{$compare=0}
560: $conceptmatch=1;
561: if (ref($Apache::hint::option{"$part_id.concepts"})) {
562: foreach my $foil (@{ $Apache::hint::option{"$part_id.concept.$concept"} }) {
563: &Apache::lonxml::debug("compare -$foil- -$response{$foil}-$compare-");
564: if ( exists($response{$foil}) &&
565: $response{$foil} ne $compare) {$conceptmatch=0;last;}
566: }
567: } else {
568: $conceptmatch=0;
569: }
570: if ($conceptmatch eq '0') { last; }
571: }
572: if ( ($conceptmatch eq '-1' || $conceptmatch eq '1') &&
573: ($foilmatch eq '-1' || $foilmatch eq '1') ) {
574: push(@Apache::hint::which,$name);
575: }
576: } elsif ($target eq 'edit') {
577: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
578: }
579: &Apache::response::end_hintresponse();
580: return $result;
581: }
582:
583: sub start_radiobuttonhint {
584: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
585: my $result;
586: &Apache::response::start_hintresponse($parstack,$safeeval);
587: if ($target eq 'edit') {
588: $result.=&Apache::edit::tag_start($target,$token);
589: $result.=&Apache::edit::text_arg('Name:','name',$token);
590: $result.=&Apache::edit::text_arg('Answer:','answer',$token);
591: } elsif ($target eq 'modified') {
592: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
593: $safeeval,'name',
594: 'answer');
595: if ($constructtag) {
596: $result = &Apache::edit::rebuild_tag($token);
597: }
598: } elsif ($target eq 'meta') {
599: $result=&Apache::response::meta_package_write('numericalhint');
600: }
601: return $result;
602: }
603:
604: sub end_radiobuttonhint {
605: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
606: my $result;
607: if ($target eq 'web') {
608: my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
609: my @answer;
610: my $answer=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
611: eval('@answer ='.$answer);
612: my $partid=$Apache::inputtags::part;
613: #id submissions occurred under
614: my $submitid=$Apache::inputtags::response[-1];
615: my $part_id="$partid.$submitid";
616: my $response = $Apache::lonhomework::history{
617: "resource.$part_id.submission"};
618: ($response)=&Apache::lonnet::str2hash($response);
619: &Apache::lonxml::debug("response is $response");
620:
621: if ($answer[0] eq 'foil') {
622: shift(@answer);
623: foreach my $answer (@answer) {
624: if ($response eq $answer) {
625: push (@Apache::hint::which,$name);
626: last;
627: }
628: }
629: } elsif ($answer[0] eq 'concept') {
630: shift(@answer);
631: foreach my $answer (@answer) {
632: if (ref($Apache::hint::radiobutton{"$part_id.concept.".$answer})) {
633: my @names=@{ $Apache::hint::radiobutton{"$part_id.concept.".$answer} };
634: if (grep(/^\Q$response\E$/,@names)) {
635: push(@Apache::hint::which,$name);
636: last;
637: }
638: }
639: }
640: }
641: } elsif ($target eq 'edit') {
642: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
643: }
644: &Apache::response::end_hintresponse();
645: return $result;
646: }
647: 1;
648: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>