File:
[LON-CAPA] /
loncom /
homework /
hint.pm
Revision
1.71:
download - view:
text,
annotated -
select for diffs
Sat Sep 13 02:08:32 2008 UTC (15 years, 11 months ago) by
raeburn
Branches:
MAIN
CVS tags:
version_2_7_X,
version_2_7_1,
HEAD
- Bug 5793
Alternative solution. Revert default_homework.lcpm to 1.138. No longer need to pass tag arg to caparesponse_check_list().
- Instead set $$args_ref{'type'} to 'ci' (the default) if type attrib is missing or null in the corresponding <stringhint> (hint.pm), or <stringresponse> (caparesponse.pm) tags.
1: # The LearningOnline Network with CAPA
2: # implements the tags that control the hints
3: #
4: # $Id: hint.pm,v 1.71 2008/09/13 02:08:32 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()",$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: if ($$args_ref{'type'} eq '') {
426: $$args_ref{'type'} = 'ci';
427: }
428: &Apache::caparesponse::add_in_tag_answer($parstack,$safeeval);
429: my (@final_awards,@final_msgs,@ans_names);
430: my %answer = &Apache::caparesponse::get_answer();
431: foreach my $ans_name (keys(%answer)) {
432: &Apache::lonxml::debug(" doing $ans_name with ".join(':',@{ $answer{$ans_name}{'answers'} }));
433: ${$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=dclone($answer{$ans_name});
434: my ($result, @msgs)=&Apache::run::run("&caparesponse_check_list()",$safeeval);
435: &Apache::lonxml::debug('msgs are'.join(':',@msgs));
436: my ($awards) = split(/:/,$result);
437: my (@awards) = split(/,/,$awards);
438: ($ad,$msg) =
439: &Apache::inputtags::finalizeawards(\@awards,\@msgs);
440: push(@final_awards,$ad);
441: push(@final_msgs,$msg);
442: push(@ans_names,$ans_name);
443: &Apache::lonxml::debug("\n<br>result:$result:$Apache::lonxml::curdepth<br>\n");
444: }
445: my ($ad, $msg, $ans_name) =
446: &Apache::inputtags::finalizeawards(\@final_awards,
447: \@final_msgs,
448: \@ans_names,1);
449: }
450: if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') {
451: push(@Apache::hint::which,$hint_name);
452: }
453: $result='';
454: } elsif ($target eq 'meta') {
455: $result=&Apache::response::meta_package_write($token->[1]);
456: } elsif ($target eq 'edit') {
457: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
458: }
459: &Apache::response::end_hintresponse();
460: return $result;
461: }
462:
463: # a part shows if it is on, if no specific parts are on, then default shows
464: sub start_hintpart {
465: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
466:
467: my $show ='0';
468: my $result = '';
469: if ($target eq 'web') {
470: my $on= &Apache::lonxml::get_param('on',$parstack,$safeeval);
471: &Apache::lonxml::debug("hintpart sees $on and ,$#Apache::hint::which");
472: if ( $on eq 'default' && $#Apache::hint::which == '-1') {
473: $show=1;
474: } else {
475: my $which;
476: foreach $which (@Apache::hint::which) { if ($which eq $on) { $show = 1; last } }
477: }
478: if (!$show) {
479: &Apache::lonxml::get_all_text("/hintpart",$parser,$style);
480: }
481: } elsif ($target eq 'grade') {
482: &Apache::lonxml::get_all_text("/hintpart",$parser,$style);
483: } elsif ($target eq 'edit') {
484: $result.= &Apache::edit::tag_start($target,$token);
485: $result.= &Apache::edit::text_arg('On:','on',$token);
486: $result.= &Apache::edit::end_row();
487: $result.= &Apache::edit::start_spanning_row();
488: } elsif ($target eq 'modified') {
489: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
490: $safeeval,'on');
491: if ($constructtag) {
492: $result = &Apache::edit::rebuild_tag($token);
493: }
494: }
495: return $result;
496: }
497:
498: sub end_hintpart {
499: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
500: my $result;
501: if ($target eq 'edit') {
502: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
503: }
504: return $result;
505: }
506:
507: sub start_optionhint {
508: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
509: my $result;
510: &Apache::response::start_hintresponse($parstack,$safeeval);
511: if ($target eq 'edit') {
512: $result.=&Apache::edit::tag_start($target,$token);
513: $result.=&Apache::edit::text_arg('Name:','name',$token);
514: $result.=&Apache::edit::text_arg('Answer:','answer',$token,40);
515: $result.=&Apache::edit::text_arg('Concept:','concept',$token,50);
516: } elsif ($target eq 'modified') {
517: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
518: $safeeval,'name',
519: 'answer','concept');
520: if ($constructtag) {
521: $result = &Apache::edit::rebuild_tag($token);
522: }
523: } elsif ($target eq 'meta') {
524: $result=&Apache::response::meta_package_write('numericalhint');
525: }
526: return $result;
527: }
528:
529: sub end_optionhint {
530: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
531: my $result;
532: if ($target eq 'web') {
533: my ($foilmatch,$conceptmatch)=(-1,-1);
534: my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
535: my $partid=$Apache::inputtags::part;
536: #id submissions occurred under
537: my $submitid=$Apache::inputtags::response[-1];
538: my $part_id="$partid.$submitid";
539: my %answer;
540: my $answer=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
541: if ($answer) {
542: eval('%answer ='.$answer);
543: &Apache::lonxml::debug("answwer hash");
544: &Apache::lonhomework::showhash(%answer);
545: my $response = $Apache::lonhomework::history{
546: "resource.$part_id.submission"};
547: my %response=&Apache::lonnet::str2hash($response);
548: &Apache::lonhomework::showhash(%response);
549: foreach my $foil (keys(%answer)) {
550: $foilmatch=1;
551: if ($answer{$foil} ne $response{$foil}) {$foilmatch=0;last;}
552: }
553: }
554: my %concept;
555: my $constr=&Apache::lonxml::get_param('concept',$parstack,$safeeval);
556: if ( $constr ) { eval('%concept ='.$constr); }
557: my $response = $Apache::lonhomework::history{
558: "resource.$part_id.submissiongrading"};
559: my %response=&Apache::lonnet::str2hash($response);
560: foreach my $concept (keys(%concept)) {
561: my $compare;
562: if ($concept{$concept} eq 'correct') {$compare=1}else{$compare=0}
563: $conceptmatch=1;
564: if (ref($Apache::hint::option{"$part_id.concepts"})) {
565: foreach my $foil (@{ $Apache::hint::option{"$part_id.concept.$concept"} }) {
566: &Apache::lonxml::debug("compare -$foil- -$response{$foil}-$compare-");
567: if ( exists($response{$foil}) &&
568: $response{$foil} ne $compare) {$conceptmatch=0;last;}
569: }
570: } else {
571: $conceptmatch=0;
572: }
573: if ($conceptmatch eq '0') { last; }
574: }
575: if ( ($conceptmatch eq '-1' || $conceptmatch eq '1') &&
576: ($foilmatch eq '-1' || $foilmatch eq '1') ) {
577: push(@Apache::hint::which,$name);
578: }
579: } elsif ($target eq 'edit') {
580: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
581: }
582: &Apache::response::end_hintresponse();
583: return $result;
584: }
585:
586: sub start_radiobuttonhint {
587: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
588: my $result;
589: &Apache::response::start_hintresponse($parstack,$safeeval);
590: if ($target eq 'edit') {
591: $result.=&Apache::edit::tag_start($target,$token);
592: $result.=&Apache::edit::text_arg('Name:','name',$token);
593: $result.=&Apache::edit::text_arg('Answer:','answer',$token);
594: } elsif ($target eq 'modified') {
595: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
596: $safeeval,'name',
597: 'answer');
598: if ($constructtag) {
599: $result = &Apache::edit::rebuild_tag($token);
600: }
601: } elsif ($target eq 'meta') {
602: $result=&Apache::response::meta_package_write('numericalhint');
603: }
604: return $result;
605: }
606:
607: sub end_radiobuttonhint {
608: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
609: my $result;
610: if ($target eq 'web') {
611: my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
612: my @answer;
613: my $answer=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
614: eval('@answer ='.$answer);
615: my $partid=$Apache::inputtags::part;
616: #id submissions occurred under
617: my $submitid=$Apache::inputtags::response[-1];
618: my $part_id="$partid.$submitid";
619: my $response = $Apache::lonhomework::history{
620: "resource.$part_id.submission"};
621: ($response)=&Apache::lonnet::str2hash($response);
622: &Apache::lonxml::debug("response is $response");
623:
624: if ($answer[0] eq 'foil') {
625: shift(@answer);
626: foreach my $answer (@answer) {
627: if ($response eq $answer) {
628: push (@Apache::hint::which,$name);
629: last;
630: }
631: }
632: } elsif ($answer[0] eq 'concept') {
633: shift(@answer);
634: foreach my $answer (@answer) {
635: if (ref($Apache::hint::radiobutton{"$part_id.concept.".$answer})) {
636: my @names=@{ $Apache::hint::radiobutton{"$part_id.concept.".$answer} };
637: if (grep(/^\Q$response\E$/,@names)) {
638: push(@Apache::hint::which,$name);
639: last;
640: }
641: }
642: }
643: }
644: } elsif ($target eq 'edit') {
645: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
646: }
647: &Apache::response::end_hintresponse();
648: return $result;
649: }
650: 1;
651: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>