Annotation of loncom/homework/hint.pm, revision 1.66
1.21 albertel 1: # The LearningOnline Network with CAPA
2: # implements the tags that control the hints
3: #
1.66 ! albertel 4: # $Id: hint.pm,v 1.65 2006/12/19 00:40:38 albertel Exp $
1.21 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
1.33 albertel 10: # LON-CAPA me&aree software; you can redistribute it and/or modify
1.21 albertel 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:
1.1 albertel 29: package Apache::hinttags;
30:
31: use strict;
1.65 albertel 32: use Apache::lonnet();
1.6 albertel 33: use capa;
1.65 albertel 34: use Apache::caparesponse();
1.63 www 35: use Apache::lonmaxima();
36: use Apache::response();
1.53 albertel 37: use Apache::lonlocal;
1.65 albertel 38: use Storable qw(dclone);
1.1 albertel 39:
1.25 harris41 40: BEGIN {
1.64 www 41: &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart','numericalhint','stringhint','formulahint','optionhint','radiobuttonhint','mathhint','customhint'));
1.1 albertel 42: }
43:
1.2 albertel 44:
1.15 albertel 45: @Apache::hint::which=();
1.1 albertel 46: sub start_hintgroup {
1.39 albertel 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; }
1.52 albertel 55: my $hinttries=&Apache::response::get_response_param($id,"hinttries",1);
1.39 albertel 56: &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
1.53 albertel 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");
1.58 albertel 61: if ( ($showoncorrect ne 'yes' && &Apache::response::show_answer()) ||
1.53 albertel 62: ( $numtries < $hinttries) ) {
63: &Apache::lonxml::debug("Grabbin all");
1.61 albertel 64: &Apache::lonxml::get_all_text("/hintgroup",$parser,$style);
1.39 albertel 65: }
1.40 albertel 66: &Apache::lonxml::startredirection;
1.39 albertel 67: } elsif ($target eq 'tex') {
68: $result .= '\keephidden{';
1.53 albertel 69: } elsif ($target eq 'edit') {
70: $result.=&Apache::edit::tag_start($target,$token);
1.56 albertel 71: $result.=&Apache::edit::select_arg('Show hint even if problem Correct:','showoncorrect',[['no',&mt('No')],['yes',&mt('Yes')]],$token);
1.53 albertel 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: }
1.20 albertel 79: }
1.39 albertel 80: @Apache::hint::which=();
81: return $result;
1.1 albertel 82: }
83:
84: sub end_hintgroup {
1.39 albertel 85: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
86: my $result;
1.20 albertel 87:
1.39 albertel 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; }
1.52 albertel 92: my $hinttries=&Apache::response::get_response_param($id,"hinttries",1);
1.39 albertel 93: &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
1.40 albertel 94: my $hinttext=&Apache::lonxml::endredirection;
95: if ($Apache::lonhomework::type ne 'exam' &&
1.41 albertel 96: $numtries >= $hinttries && $hinttext =~/\S/) {
1.40 albertel 97: $result='<table bgcolor="#dddddd"><tr><td>'.
98: $hinttext.'</td></tr></table>';
1.38 albertel 99: }
1.39 albertel 100: } elsif ($target eq 'edit') {
1.62 albertel 101: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
1.39 albertel 102: } elsif ($target eq 'tex') {
103: $result .= '}';
1.19 albertel 104: }
1.39 albertel 105: @Apache::hint::which=();
106: return $result;
1.3 albertel 107: }
108:
109: sub start_numericalhint {
1.39 albertel 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);
1.66 ! albertel 113: &Apache::caparesponse::push_answer();
1.39 albertel 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') {
1.65 albertel 125: $result.=&Apache::edit::text_arg('Sample Points:','samples',
126: $token,40).
127: &Apache::loncommon::help_open_topic('Formula_Response_Sampling');
1.39 albertel 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();
1.28 albertel 148: }
1.39 albertel 149: return $result;
1.3 albertel 150: }
151:
152: sub end_numericalhint {
1.39 albertel 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']);
1.65 albertel 160: my $hint_name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
1.48 albertel 161: &Apache::response::setup_params('numericalhint',$safeeval);
1.65 albertel 162:
1.39 albertel 163: my $partid=$Apache::inputtags::part;
1.60 albertel 164: my $id=$Apache::inputtags::hint[-1];
1.39 albertel 165: #id submissions occured under
1.60 albertel 166: my $submitid=$Apache::inputtags::response[-1];
1.65 albertel 167:
1.39 albertel 168: my $response = $Apache::lonhomework::history{
1.18 albertel 169: "resource.$partid.$submitid.submission"};
1.39 albertel 170: &Apache::lonxml::debug("hintgroup is using $response<br />\n");
1.65 albertel 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:
1.54 albertel 177: my $hideunit=&Apache::response::get_response_param($partid.'_'.$submitid,'turnoffunit');
1.51 albertel 178: if (lc($hideunit) eq "yes") { delete($$args_ref{'unit'}); }
1.65 albertel 179:
1.43 albertel 180: if ($$tagstack[-1] eq 'formulahint') {
1.51 albertel 181: $$args_ref{'type'}='fml';
1.43 albertel 182: } elsif ($$tagstack[-1] eq 'numericalhint') {
1.51 albertel 183: $$args_ref{'type'}='float';
1.39 albertel 184: }
1.65 albertel 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: }
1.39 albertel 213: $result='';
214: } elsif ($target eq 'meta') {
215: $result=&Apache::response::meta_package_write($token->[1]);
216: } elsif ($target eq 'edit') {
1.62 albertel 217: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
1.18 albertel 218: }
1.66 ! albertel 219: &Apache::caparesponse::pop_answer();
1.39 albertel 220: &Apache::response::end_hintresponse();
221: return $result;
1.28 albertel 222: }
223:
1.51 albertel 224: sub start_formulahint {
1.35 albertel 225: return &start_numericalhint(@_);
1.28 albertel 226: }
227:
1.51 albertel 228: sub end_formulahint {
1.35 albertel 229: return &end_numericalhint(@_);
1.28 albertel 230: }
231:
1.63 www 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:
1.64 www 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:
1.51 albertel 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;
1.28 albertel 385: }
386:
1.51 albertel 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']);
1.65 albertel 395: my $hint_name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
1.51 albertel 396: &Apache::response::setup_params('stringhint',$safeeval);
397: my $partid=$Apache::inputtags::part;
1.60 albertel 398: my $id=$Apache::inputtags::hint[-1];
1.51 albertel 399: #id submissions occured under
1.60 albertel 400: my $submitid=$Apache::inputtags::response[-1];
1.51 albertel 401: my $response = $Apache::lonhomework::history{
402: "resource.$partid.$submitid.submission"};
403: &Apache::lonxml::debug("hintgroup is using $response<br />\n");
1.65 albertel 404: my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
1.51 albertel 405: my ($ad,$msg);
406: if ($type eq 're' ) {
1.65 albertel 407: my $answer=&Apache::lonxml::get_param('answer',$parstack,
408: $safeeval);
1.51 albertel 409: ${$safeeval->varglob('LONCAPA::response')}=$response;
1.57 albertel 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);
1.51 albertel 418: &Apache::lonxml::debug("current $response");
419: &Apache::lonxml::debug("current $answer");
420: $ad = ($result) ? 'APPROX_ANS' : 'INCORRECT';
421: } else {
1.65 albertel 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");
1.51 albertel 442: }
1.65 albertel 443: my ($ad, $msg, $ans_name) =
444: &Apache::inputtags::finalizeawards(\@final_awards,
445: \@final_msgs,
446: \@ans_names,1);
1.51 albertel 447: }
448: if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') {
1.65 albertel 449: push(@Apache::hint::which,$hint_name);
1.51 albertel 450: }
451: $result='';
452: } elsif ($target eq 'meta') {
453: $result=&Apache::response::meta_package_write($token->[1]);
454: } elsif ($target eq 'edit') {
1.62 albertel 455: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
1.51 albertel 456: }
457: &Apache::response::end_hintresponse();
458: return $result;
1.1 albertel 459: }
460:
1.2 albertel 461: # a part shows if it is on, if no specific parts are on, then default shows
1.1 albertel 462: sub start_hintpart {
1.39 albertel 463: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.15 albertel 464:
1.39 albertel 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) {
1.61 albertel 477: &Apache::lonxml::get_all_text("/hintpart",$parser,$style);
1.39 albertel 478: }
479: } elsif ($target eq 'grade') {
1.61 albertel 480: &Apache::lonxml::get_all_text("/hintpart",$parser,$style);
1.39 albertel 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: }
1.20 albertel 493: }
1.39 albertel 494: return $result;
1.1 albertel 495: }
496:
497: sub end_hintpart {
1.29 albertel 498: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
499: my $result;
1.62 albertel 500: if ($target eq 'edit') {
501: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
502: }
1.29 albertel 503: return $result;
504: }
505:
506: sub start_optionhint {
507: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
508: my $result;
1.30 albertel 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: }
1.29 albertel 526: return $result;
527: }
528:
529: sub end_optionhint {
530: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
531: my $result;
1.30 albertel 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
1.60 albertel 537: my $submitid=$Apache::inputtags::response[-1];
1.30 albertel 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);
1.62 albertel 543: &Apache::lonxml::debug("answwer hash");
1.30 albertel 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: }
1.62 albertel 579: } elsif ($target eq 'edit') {
580: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
581: }
1.30 albertel 582: &Apache::response::end_hintresponse();
1.29 albertel 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;
1.1 albertel 606: }
607:
1.31 albertel 608: sub end_radiobuttonhint {
1.29 albertel 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
1.60 albertel 618: my $submitid=$Apache::inputtags::response[-1];
1.29 albertel 619: my $part_id="$partid.$submitid";
620: my $response = $Apache::lonhomework::history{
621: "resource.$part_id.submission"};
622: ($response)=&Apache::lonnet::str2hash($response);
1.42 albertel 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: }
1.29 albertel 633: } elsif ($answer[0] eq 'concept') {
1.42 albertel 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: }
1.29 albertel 642: }
643: }
644: }
1.62 albertel 645: } elsif ($target eq 'edit') {
646: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
647: }
1.29 albertel 648: &Apache::response::end_hintresponse();
649: return $result;
650: }
1.1 albertel 651: 1;
652: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>