1: # The LearningOnline Network with CAPA
2: # implements the tags that control the hints
3: #
4: # $Id: hint.pm,v 1.66 2006/12/19 00:49:53 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 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: $result.=&Apache::edit::handle_insert();
78: }
79: }
80: @Apache::hint::which=();
81: return $result;
82: }
83:
84: sub end_hintgroup {
85: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
86: my $result;
87:
88: if ($target eq 'web') {
89: my $id=$Apache::inputtags::part;
90: my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
91: if ( $numtries eq '') { $numtries = 0; }
92: my $hinttries=&Apache::response::get_response_param($id,"hinttries",1);
93: &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
94: my $hinttext=&Apache::lonxml::endredirection;
95: if ($Apache::lonhomework::type ne 'exam' &&
96: $numtries >= $hinttries && $hinttext =~/\S/) {
97: $result='<table bgcolor="#dddddd"><tr><td>'.
98: $hinttext.'</td></tr></table>';
99: }
100: } elsif ($target eq 'edit') {
101: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
102: } elsif ($target eq 'tex') {
103: $result .= '}';
104: }
105: @Apache::hint::which=();
106: return $result;
107: }
108:
109: sub start_numericalhint {
110: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
111: #do everything in end, so intervening <responseparams> work
112: &Apache::response::start_hintresponse($parstack,$safeeval);
113: &Apache::caparesponse::push_answer();
114: my $result;
115: if ($target eq 'edit') {
116: $result.=&Apache::edit::tag_start($target,$token);
117: $result.=&Apache::edit::text_arg('Name:','name',$token);
118: $result.=&Apache::edit::text_arg('Answer:','answer',$token);
119: if ($token->[1] eq 'numericalhint') {
120: $result.=&Apache::edit::text_arg('Unit:','unit',$token,5).
121: &Apache::loncommon::help_open_topic('Physical_Units');
122: $result.=&Apache::edit::text_arg('Format:','format',$token,4).
123: &Apache::loncommon::help_open_topic('Numerical_Response_Format');
124: } elsif ($token->[1] eq 'formulahint') {
125: $result.=&Apache::edit::text_arg('Sample Points:','samples',
126: $token,40).
127: &Apache::loncommon::help_open_topic('Formula_Response_Sampling');
128: }
129: $result.=&Apache::edit::end_row();
130: $result.=&Apache::edit::start_spanning_row();
131: } elsif ($target eq 'modified') {
132: my $constructtag;
133: if ($token->[1] eq 'numericalhint') {
134: $constructtag=&Apache::edit::get_new_args($token,$parstack,
135: $safeeval,'name',
136: 'answer','unit','format');
137: } elsif ($token->[1] eq 'formulahint') {
138: $constructtag=&Apache::edit::get_new_args($token,$parstack,
139: $safeeval,'name','answer',
140: 'samples');
141: }
142: if ($constructtag) {
143: $result = &Apache::edit::rebuild_tag($token);
144: $result .= &Apache::edit::handle_insert();
145: }
146: } elsif ($target eq 'web') {
147: &Apache::response::reset_params();
148: }
149: return $result;
150: }
151:
152: sub end_numericalhint {
153: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
154: my $result;
155: if ($target eq 'web') {
156: if (!$Apache::lonxml::default_homework_loaded) {
157: &Apache::lonxml::default_homework_load($safeeval);
158: }
159: $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
160: my $hint_name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
161: &Apache::response::setup_params('numericalhint',$safeeval);
162:
163: my $partid=$Apache::inputtags::part;
164: my $id=$Apache::inputtags::hint[-1];
165: #id submissions occured under
166: my $submitid=$Apache::inputtags::response[-1];
167:
168: my $response = $Apache::lonhomework::history{
169: "resource.$partid.$submitid.submission"};
170: &Apache::lonxml::debug("hintgroup is using $response<br />\n");
171:
172: my @args = ('type','tol','sig','ans_fmt','unit','calc','samples');
173: my $args_ref =
174: &Apache::caparesponse::setup_capa_args($safeeval,$parstack,
175: \@args,$response);
176:
177: my $hideunit=&Apache::response::get_response_param($partid.'_'.$submitid,'turnoffunit');
178: if (lc($hideunit) eq "yes") { delete($$args_ref{'unit'}); }
179:
180: if ($$tagstack[-1] eq 'formulahint') {
181: $$args_ref{'type'}='fml';
182: } elsif ($$tagstack[-1] eq 'numericalhint') {
183: $$args_ref{'type'}='float';
184: }
185: &Apache::caparesponse::add_in_tag_answer($parstack,$safeeval);
186: my %answer = &Apache::caparesponse::get_answer();
187: my (@final_awards,@final_msgs,@ans_names);
188: foreach my $ans_name (keys(%answer)) {
189: &Apache::lonxml::debug(" doing $ans_name with ".join(':',@{ $answer{$ans_name}{'answers'} }));
190:
191: ${$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=
192: dclone($answer{$ans_name});
193: &Apache::caparesponse::setup_capa_response($args_ref,$response);
194: my ($result,@msgs) =
195: &Apache::run::run("&caparesponse_check_list()",$safeeval);
196: &Apache::lonxml::debug("checking $ans_name $result with $response");
197: &Apache::lonxml::debug('msgs are '.join(':',@msgs));
198: my ($awards)=split(/:/,$result);
199: my @awards= split(/,/,$awards);
200: my ($ad, $msg) =
201: &Apache::inputtags::finalizeawards(\@awards,\@msgs);
202: push(@final_awards,$ad);
203: push(@final_msgs,$msg);
204: push(@ans_names,$ans_name);
205: }
206: my ($ad, $msg, $ans_name) =
207: &Apache::inputtags::finalizeawards(\@final_awards,
208: \@final_msgs,
209: \@ans_names,1);
210: if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') {
211: push(@Apache::hint::which,$hint_name);
212: }
213: $result='';
214: } elsif ($target eq 'meta') {
215: $result=&Apache::response::meta_package_write($token->[1]);
216: } elsif ($target eq 'edit') {
217: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
218: }
219: &Apache::caparesponse::pop_answer();
220: &Apache::response::end_hintresponse();
221: return $result;
222: }
223:
224: sub start_formulahint {
225: return &start_numericalhint(@_);
226: }
227:
228: sub end_formulahint {
229: return &end_numericalhint(@_);
230: }
231:
232: sub start_mathhint {
233: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
234: #do everything in end, so intervening <responseparams> and <answer> work
235: &Apache::response::start_hintresponse($parstack,$safeeval);
236: &Apache::lonxml::register('Apache::response',('answer'));
237: my $result;
238: if ($target eq 'edit') {
239: $result.=&Apache::edit::tag_start($target,$token);
240: $result.=&Apache::edit::text_arg('Name:','name',$token);
241: $result.=&Apache::edit::select_arg('Algebra System:',
242: 'cas',
243: ['maxima'],
244: $token);
245: $result.=&Apache::edit::text_arg('Argument Array:',
246: 'args',$token);
247: $result.=&Apache::edit::end_row();
248: $result.=&Apache::edit::start_spanning_row();
249: } elsif ($target eq 'modified') {
250: my $constructtag;
251: $constructtag=&Apache::edit::get_new_args($token,$parstack,
252: $safeeval,'name','cas',
253: 'args');
254: $result = &Apache::edit::rebuild_tag($token);
255: $result .= &Apache::edit::handle_insert();
256: } elsif ($target eq 'web') {
257: &Apache::response::reset_params();
258: }
259: return $result;
260: }
261:
262: sub end_mathhint {
263: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
264: my $result;
265: if ($target eq 'web') {
266: if (!$Apache::lonxml::default_homework_loaded) {
267: &Apache::lonxml::default_homework_load($safeeval);
268: }
269: my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
270: &Apache::response::setup_params('mathhint',$safeeval);
271: my $partid=$Apache::inputtags::part;
272: my $submitid=$Apache::inputtags::response[-1];
273: my $response = $Apache::lonhomework::history{
274: "resource.$partid.$submitid.submission"};
275:
276: my $cas = &Apache::lonxml::get_param('cas',$parstack,$safeeval);
277: my $award;
278: if ($cas eq 'maxima') {
279: my $args = [&Apache::lonxml::get_param_var('args',$parstack,$safeeval)];
280: $award=&Apache::lonmaxima::maxima_run($Apache::response::custom_answer[-1],$response,$args);
281: }
282: if ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS') {
283: push (@Apache::hint::which,$name);
284: }
285: $result='';
286: } elsif ($target eq 'meta') {
287: $result=&Apache::response::meta_package_write($token->[1]);
288: } elsif ($target eq 'edit') {
289: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
290: }
291: pop(@Apache::response::custom_answer);
292: pop(@Apache::response::custom_answer_type);
293: &Apache::response::end_hintresponse();
294: return $result;
295: }
296:
297: sub start_customhint {
298: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
299: #do everything in end, so intervening <responseparams> and <answer> work
300: &Apache::response::start_hintresponse($parstack,$safeeval);
301: &Apache::lonxml::register('Apache::response',('answer'));
302: my $result;
303: if ($target eq 'edit') {
304: $result.=&Apache::edit::tag_start($target,$token);
305: $result.=&Apache::edit::text_arg('Name:','name',$token);
306: $result.=&Apache::edit::end_row();
307: $result.=&Apache::edit::start_spanning_row();
308: } elsif ($target eq 'modified') {
309: my $constructtag;
310: $constructtag=&Apache::edit::get_new_args($token,$parstack,
311: $safeeval,'name');
312: $result = &Apache::edit::rebuild_tag($token);
313: $result .= &Apache::edit::handle_insert();
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: $result .= &Apache::edit::handle_insert();
381: } elsif ($target eq 'web') {
382: &Apache::response::reset_params();
383: }
384: return $result;
385: }
386:
387: sub end_stringhint {
388: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
389: my $result;
390: if ($target eq 'web') {
391: if (!$Apache::lonxml::default_homework_loaded) {
392: &Apache::lonxml::default_homework_load($safeeval);
393: }
394: $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
395: my $hint_name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
396: &Apache::response::setup_params('stringhint',$safeeval);
397: my $partid=$Apache::inputtags::part;
398: my $id=$Apache::inputtags::hint[-1];
399: #id submissions occured under
400: my $submitid=$Apache::inputtags::response[-1];
401: my $response = $Apache::lonhomework::history{
402: "resource.$partid.$submitid.submission"};
403: &Apache::lonxml::debug("hintgroup is using $response<br />\n");
404: my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
405: my ($ad,$msg);
406: if ($type eq 're' ) {
407: my $answer=&Apache::lonxml::get_param('answer',$parstack,
408: $safeeval);
409: ${$safeeval->varglob('LONCAPA::response')}=$response;
410: my $compare='=';
411: if ($answer=~/^\s*NOT\s*/) {
412: $answer=~s/^\s*NOT\s*//;
413: $compare='!';
414: }
415: my $test='$LONCAPA::response'.$compare.'~m'.$answer;
416: &Apache::lonxml::debug("test $test");
417: $result = &Apache::run::run("return $test",$safeeval);
418: &Apache::lonxml::debug("current $response");
419: &Apache::lonxml::debug("current $answer");
420: $ad = ($result) ? 'APPROX_ANS' : 'INCORRECT';
421: } else {
422: my @args = ('type');
423: my $args_ref =
424: &Apache::caparesponse::setup_capa_args($safeeval,$parstack,
425: \@args,$response);
426: &Apache::caparesponse::add_in_tag_answer($parstack,$safeeval);
427: my (@final_awards,@final_msgs,@ans_names);
428: my %answer = &Apache::caparesponse::get_answer();
429: foreach my $ans_name (keys(%answer)) {
430: &Apache::lonxml::debug(" doing $ans_name with ".join(':',@{ $answer{$ans_name}{'answers'} }));
431: ${$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=dclone($answer{$ans_name});
432: my ($result, @msgs)=&Apache::run::run("&caparesponse_check_list()",$safeeval);
433: &Apache::lonxml::debug('msgs are'.join(':',@msgs));
434: my ($awards) = split(/:/,$result);
435: my (@awards) = split(/,/,$awards);
436: ($ad,$msg) =
437: &Apache::inputtags::finalizeawards(\@awards,\@msgs);
438: push(@final_awards,$ad);
439: push(@final_msgs,$msg);
440: push(@ans_names,$ans_name);
441: &Apache::lonxml::debug("\n<br>result:$result:$Apache::lonxml::curdepth<br>\n");
442: }
443: my ($ad, $msg, $ans_name) =
444: &Apache::inputtags::finalizeawards(\@final_awards,
445: \@final_msgs,
446: \@ans_names,1);
447: }
448: if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') {
449: push(@Apache::hint::which,$hint_name);
450: }
451: $result='';
452: } elsif ($target eq 'meta') {
453: $result=&Apache::response::meta_package_write($token->[1]);
454: } elsif ($target eq 'edit') {
455: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
456: }
457: &Apache::response::end_hintresponse();
458: return $result;
459: }
460:
461: # a part shows if it is on, if no specific parts are on, then default shows
462: sub start_hintpart {
463: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
464:
465: my $show ='0';
466: my $result = '';
467: if ($target eq 'web') {
468: my $on= &Apache::lonxml::get_param('on',$parstack,$safeeval);
469: &Apache::lonxml::debug("hintpart sees $on and ,$#Apache::hint::which");
470: if ( $on eq 'default' && $#Apache::hint::which == '-1') {
471: $show=1;
472: } else {
473: my $which;
474: foreach $which (@Apache::hint::which) { if ($which eq $on) { $show = 1; last } }
475: }
476: if (!$show) {
477: &Apache::lonxml::get_all_text("/hintpart",$parser,$style);
478: }
479: } elsif ($target eq 'grade') {
480: &Apache::lonxml::get_all_text("/hintpart",$parser,$style);
481: } elsif ($target eq 'edit') {
482: $result.= &Apache::edit::tag_start($target,$token);
483: $result.= &Apache::edit::text_arg('On:','on',$token);
484: $result.= &Apache::edit::end_row();
485: $result.= &Apache::edit::start_spanning_row();
486: } elsif ($target eq 'modified') {
487: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
488: $safeeval,'on');
489: if ($constructtag) {
490: $result = &Apache::edit::rebuild_tag($token);
491: $result.=&Apache::edit::handle_insert();
492: }
493: }
494: return $result;
495: }
496:
497: sub end_hintpart {
498: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
499: my $result;
500: if ($target eq 'edit') {
501: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
502: }
503: return $result;
504: }
505:
506: sub start_optionhint {
507: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
508: my $result;
509: &Apache::response::start_hintresponse($parstack,$safeeval);
510: if ($target eq 'edit') {
511: $result.=&Apache::edit::tag_start($target,$token);
512: $result.=&Apache::edit::text_arg('Name:','name',$token);
513: $result.=&Apache::edit::text_arg('Answer:','answer',$token,40);
514: $result.=&Apache::edit::text_arg('Concept:','concept',$token,50);
515: } elsif ($target eq 'modified') {
516: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
517: $safeeval,'name',
518: 'answer','concept');
519: if ($constructtag) {
520: $result = &Apache::edit::rebuild_tag($token);
521: $result .= &Apache::edit::handle_insert();
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 occured 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: $result .= &Apache::edit::handle_insert();
601: }
602: } elsif ($target eq 'meta') {
603: $result=&Apache::response::meta_package_write('numericalhint');
604: }
605: return $result;
606: }
607:
608: sub end_radiobuttonhint {
609: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
610: my $result;
611: if ($target eq 'web') {
612: my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
613: my @answer;
614: my $answer=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
615: eval('@answer ='.$answer);
616: my $partid=$Apache::inputtags::part;
617: #id submissions occured under
618: my $submitid=$Apache::inputtags::response[-1];
619: my $part_id="$partid.$submitid";
620: my $response = $Apache::lonhomework::history{
621: "resource.$part_id.submission"};
622: ($response)=&Apache::lonnet::str2hash($response);
623: &Apache::lonxml::debug("response is $response");
624:
625: if ($answer[0] eq 'foil') {
626: shift(@answer);
627: foreach my $answer (@answer) {
628: if ($response eq $answer) {
629: push (@Apache::hint::which,$name);
630: last;
631: }
632: }
633: } elsif ($answer[0] eq 'concept') {
634: shift(@answer);
635: foreach my $answer (@answer) {
636: if (ref($Apache::hint::radiobutton{"$part_id.concept.".$answer})) {
637: my @names=@{ $Apache::hint::radiobutton{"$part_id.concept.".$answer} };
638: if (grep(/^\Q$response\E$/,@names)) {
639: push(@Apache::hint::which,$name);
640: last;
641: }
642: }
643: }
644: }
645: } elsif ($target eq 'edit') {
646: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
647: }
648: &Apache::response::end_hintresponse();
649: return $result;
650: }
651: 1;
652: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>