Annotation of loncom/homework/hint.pm, revision 1.72
1.21 albertel 1: # The LearningOnline Network with CAPA
2: # implements the tags that control the hints
3: #
1.72 ! bisitz 4: # $Id: hint.pm,v 1.71 2008/09/13 02:08:32 raeburn 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.72 ! bisitz 71: $result.=&Apache::edit::select_arg('Show hint even if problem Correct:','showoncorrect',['no','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: }
1.20 albertel 78: }
1.39 albertel 79: @Apache::hint::which=();
80: return $result;
1.1 albertel 81: }
82:
83: sub end_hintgroup {
1.39 albertel 84: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
85: my $result;
1.20 albertel 86:
1.39 albertel 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; }
1.52 albertel 91: my $hinttries=&Apache::response::get_response_param($id,"hinttries",1);
1.39 albertel 92: &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
1.40 albertel 93: my $hinttext=&Apache::lonxml::endredirection;
94: if ($Apache::lonhomework::type ne 'exam' &&
1.41 albertel 95: $numtries >= $hinttries && $hinttext =~/\S/) {
1.40 albertel 96: $result='<table bgcolor="#dddddd"><tr><td>'.
97: $hinttext.'</td></tr></table>';
1.38 albertel 98: }
1.39 albertel 99: } elsif ($target eq 'edit') {
1.62 albertel 100: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
1.39 albertel 101: } elsif ($target eq 'tex') {
102: $result .= '}';
1.19 albertel 103: }
1.39 albertel 104: @Apache::hint::which=();
105: return $result;
1.3 albertel 106: }
107:
108: sub start_numericalhint {
1.39 albertel 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);
1.66 albertel 112: &Apache::caparesponse::push_answer();
1.39 albertel 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') {
1.65 albertel 124: $result.=&Apache::edit::text_arg('Sample Points:','samples',
125: $token,40).
126: &Apache::loncommon::help_open_topic('Formula_Response_Sampling');
1.39 albertel 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();
1.28 albertel 146: }
1.39 albertel 147: return $result;
1.3 albertel 148: }
149:
150: sub end_numericalhint {
1.39 albertel 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']);
1.65 albertel 158: my $hint_name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
1.48 albertel 159: &Apache::response::setup_params('numericalhint',$safeeval);
1.65 albertel 160:
1.39 albertel 161: my $partid=$Apache::inputtags::part;
1.60 albertel 162: my $id=$Apache::inputtags::hint[-1];
1.69 bisitz 163: #id submissions occurred under
1.60 albertel 164: my $submitid=$Apache::inputtags::response[-1];
1.65 albertel 165:
1.39 albertel 166: my $response = $Apache::lonhomework::history{
1.18 albertel 167: "resource.$partid.$submitid.submission"};
1.39 albertel 168: &Apache::lonxml::debug("hintgroup is using $response<br />\n");
1.65 albertel 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:
1.54 albertel 175: my $hideunit=&Apache::response::get_response_param($partid.'_'.$submitid,'turnoffunit');
1.51 albertel 176: if (lc($hideunit) eq "yes") { delete($$args_ref{'unit'}); }
1.65 albertel 177:
1.43 albertel 178: if ($$tagstack[-1] eq 'formulahint') {
1.67 www 179: if ($$args_ref{'samples'}) {
180: $$args_ref{'type'}='fml';
181: } else {
182: $$args_ref{'type'}='math';
183: }
1.43 albertel 184: } elsif ($$tagstack[-1] eq 'numericalhint') {
1.51 albertel 185: $$args_ref{'type'}='float';
1.39 albertel 186: }
1.65 albertel 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) =
1.71 raeburn 197: &Apache::run::run("&caparesponse_check_list()",$safeeval);
1.65 albertel 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: }
1.39 albertel 215: $result='';
216: } elsif ($target eq 'meta') {
217: $result=&Apache::response::meta_package_write($token->[1]);
218: } elsif ($target eq 'edit') {
1.62 albertel 219: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
1.18 albertel 220: }
1.66 albertel 221: &Apache::caparesponse::pop_answer();
1.39 albertel 222: &Apache::response::end_hintresponse();
223: return $result;
1.28 albertel 224: }
225:
1.51 albertel 226: sub start_formulahint {
1.35 albertel 227: return &start_numericalhint(@_);
1.28 albertel 228: }
229:
1.51 albertel 230: sub end_formulahint {
1.35 albertel 231: return &end_numericalhint(@_);
1.28 albertel 232: }
233:
1.63 www 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:
1.64 www 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:
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: } elsif ($target eq 'web') {
381: &Apache::response::reset_params();
382: }
383: return $result;
1.28 albertel 384: }
385:
1.51 albertel 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']);
1.65 albertel 394: my $hint_name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
1.51 albertel 395: &Apache::response::setup_params('stringhint',$safeeval);
396: my $partid=$Apache::inputtags::part;
1.60 albertel 397: my $id=$Apache::inputtags::hint[-1];
1.69 bisitz 398: #id submissions occurred under
1.60 albertel 399: my $submitid=$Apache::inputtags::response[-1];
1.51 albertel 400: my $response = $Apache::lonhomework::history{
401: "resource.$partid.$submitid.submission"};
402: &Apache::lonxml::debug("hintgroup is using $response<br />\n");
1.65 albertel 403: my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
1.51 albertel 404: my ($ad,$msg);
405: if ($type eq 're' ) {
1.65 albertel 406: my $answer=&Apache::lonxml::get_param('answer',$parstack,
407: $safeeval);
1.51 albertel 408: ${$safeeval->varglob('LONCAPA::response')}=$response;
1.57 albertel 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);
1.51 albertel 417: &Apache::lonxml::debug("current $response");
418: &Apache::lonxml::debug("current $answer");
419: $ad = ($result) ? 'APPROX_ANS' : 'INCORRECT';
420: } else {
1.65 albertel 421: my @args = ('type');
422: my $args_ref =
423: &Apache::caparesponse::setup_capa_args($safeeval,$parstack,
424: \@args,$response);
1.71 raeburn 425: if ($$args_ref{'type'} eq '') {
426: $$args_ref{'type'} = 'ci';
427: }
1.65 albertel 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});
1.71 raeburn 434: my ($result, @msgs)=&Apache::run::run("&caparesponse_check_list()",$safeeval);
1.65 albertel 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");
1.51 albertel 444: }
1.65 albertel 445: my ($ad, $msg, $ans_name) =
446: &Apache::inputtags::finalizeawards(\@final_awards,
447: \@final_msgs,
448: \@ans_names,1);
1.51 albertel 449: }
450: if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') {
1.65 albertel 451: push(@Apache::hint::which,$hint_name);
1.51 albertel 452: }
453: $result='';
454: } elsif ($target eq 'meta') {
455: $result=&Apache::response::meta_package_write($token->[1]);
456: } elsif ($target eq 'edit') {
1.62 albertel 457: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
1.51 albertel 458: }
459: &Apache::response::end_hintresponse();
460: return $result;
1.1 albertel 461: }
462:
1.2 albertel 463: # a part shows if it is on, if no specific parts are on, then default shows
1.1 albertel 464: sub start_hintpart {
1.39 albertel 465: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.15 albertel 466:
1.39 albertel 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) {
1.61 albertel 479: &Apache::lonxml::get_all_text("/hintpart",$parser,$style);
1.39 albertel 480: }
481: } elsif ($target eq 'grade') {
1.61 albertel 482: &Apache::lonxml::get_all_text("/hintpart",$parser,$style);
1.39 albertel 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: }
1.20 albertel 494: }
1.39 albertel 495: return $result;
1.1 albertel 496: }
497:
498: sub end_hintpart {
1.29 albertel 499: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
500: my $result;
1.62 albertel 501: if ($target eq 'edit') {
502: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
503: }
1.29 albertel 504: return $result;
505: }
506:
507: sub start_optionhint {
508: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
509: my $result;
1.30 albertel 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: }
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;
1.69 bisitz 536: #id submissions occurred 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: }
601: } elsif ($target eq 'meta') {
602: $result=&Apache::response::meta_package_write('numericalhint');
603: }
604: return $result;
1.1 albertel 605: }
606:
1.31 albertel 607: sub end_radiobuttonhint {
1.29 albertel 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;
1.69 bisitz 616: #id submissions occurred under
1.60 albertel 617: my $submitid=$Apache::inputtags::response[-1];
1.29 albertel 618: my $part_id="$partid.$submitid";
619: my $response = $Apache::lonhomework::history{
620: "resource.$part_id.submission"};
621: ($response)=&Apache::lonnet::str2hash($response);
1.42 albertel 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: }
1.29 albertel 632: } elsif ($answer[0] eq 'concept') {
1.42 albertel 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: }
1.29 albertel 641: }
642: }
643: }
1.62 albertel 644: } elsif ($target eq 'edit') {
645: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
646: }
1.29 albertel 647: &Apache::response::end_hintresponse();
648: return $result;
649: }
1.1 albertel 650: 1;
651: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>