Annotation of loncom/homework/hint.pm, revision 1.74
1.21 albertel 1: # The LearningOnline Network with CAPA
2: # implements the tags that control the hints
3: #
1.74 ! jms 4: # $Id: hint.pm,v 1.73 2008/11/19 18:34:56 jms 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.73 jms 29:
30:
1.1 albertel 31: package Apache::hinttags;
32:
33: use strict;
1.65 albertel 34: use Apache::lonnet();
1.6 albertel 35: use capa;
1.65 albertel 36: use Apache::caparesponse();
1.63 www 37: use Apache::lonmaxima();
38: use Apache::response();
1.53 albertel 39: use Apache::lonlocal;
1.65 albertel 40: use Storable qw(dclone);
1.1 albertel 41:
1.25 harris41 42: BEGIN {
1.64 www 43: &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart','numericalhint','stringhint','formulahint','optionhint','radiobuttonhint','mathhint','customhint'));
1.1 albertel 44: }
45:
1.2 albertel 46:
1.15 albertel 47: @Apache::hint::which=();
1.1 albertel 48: sub start_hintgroup {
1.39 albertel 49: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
50: my $skiptoend='0';
51: my $result;
52:
53: if ($target eq 'web') {
54: my $id=$Apache::inputtags::part;
55: my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
56: if ( $numtries eq '') { $numtries = 0; }
1.52 albertel 57: my $hinttries=&Apache::response::get_response_param($id,"hinttries",1);
1.39 albertel 58: &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
1.53 albertel 59: my $gradestatus=
60: $Apache::lonhomework::history{"resource.$id.solved"};
61: my $showoncorrect=lc(&Apache::lonxml::get_param('showoncorrect',$parstack,$safeeval));
62: &Apache::lonxml::debug("onc orrect $showoncorrect, $gradestatus");
1.58 albertel 63: if ( ($showoncorrect ne 'yes' && &Apache::response::show_answer()) ||
1.53 albertel 64: ( $numtries < $hinttries) ) {
65: &Apache::lonxml::debug("Grabbin all");
1.61 albertel 66: &Apache::lonxml::get_all_text("/hintgroup",$parser,$style);
1.39 albertel 67: }
1.40 albertel 68: &Apache::lonxml::startredirection;
1.39 albertel 69: } elsif ($target eq 'tex') {
70: $result .= '\keephidden{';
1.53 albertel 71: } elsif ($target eq 'edit') {
72: $result.=&Apache::edit::tag_start($target,$token);
1.72 bisitz 73: $result.=&Apache::edit::select_arg('Show hint even if problem Correct:','showoncorrect',['no','yes'],$token);
1.53 albertel 74: $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
75: } elsif ($target eq 'modified') {
76: my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'showoncorrect');
77: if ($constructtag) {
78: $result =&Apache::edit::rebuild_tag($token);
79: }
1.20 albertel 80: }
1.39 albertel 81: @Apache::hint::which=();
82: return $result;
1.1 albertel 83: }
84:
85: sub end_hintgroup {
1.39 albertel 86: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
87: my $result;
1.20 albertel 88:
1.39 albertel 89: if ($target eq 'web') {
90: my $id=$Apache::inputtags::part;
91: my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
92: if ( $numtries eq '') { $numtries = 0; }
1.52 albertel 93: my $hinttries=&Apache::response::get_response_param($id,"hinttries",1);
1.39 albertel 94: &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
1.40 albertel 95: my $hinttext=&Apache::lonxml::endredirection;
96: if ($Apache::lonhomework::type ne 'exam' &&
1.41 albertel 97: $numtries >= $hinttries && $hinttext =~/\S/) {
1.40 albertel 98: $result='<table bgcolor="#dddddd"><tr><td>'.
99: $hinttext.'</td></tr></table>';
1.38 albertel 100: }
1.39 albertel 101: } elsif ($target eq 'edit') {
1.62 albertel 102: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
1.39 albertel 103: } elsif ($target eq 'tex') {
104: $result .= '}';
1.19 albertel 105: }
1.39 albertel 106: @Apache::hint::which=();
107: return $result;
1.3 albertel 108: }
109:
110: sub start_numericalhint {
1.39 albertel 111: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
112: #do everything in end, so intervening <responseparams> work
113: &Apache::response::start_hintresponse($parstack,$safeeval);
1.66 albertel 114: &Apache::caparesponse::push_answer();
1.39 albertel 115: my $result;
116: if ($target eq 'edit') {
117: $result.=&Apache::edit::tag_start($target,$token);
118: $result.=&Apache::edit::text_arg('Name:','name',$token);
119: $result.=&Apache::edit::text_arg('Answer:','answer',$token);
120: if ($token->[1] eq 'numericalhint') {
121: $result.=&Apache::edit::text_arg('Unit:','unit',$token,5).
122: &Apache::loncommon::help_open_topic('Physical_Units');
123: $result.=&Apache::edit::text_arg('Format:','format',$token,4).
124: &Apache::loncommon::help_open_topic('Numerical_Response_Format');
125: } elsif ($token->[1] eq 'formulahint') {
1.65 albertel 126: $result.=&Apache::edit::text_arg('Sample Points:','samples',
127: $token,40).
128: &Apache::loncommon::help_open_topic('Formula_Response_Sampling');
1.39 albertel 129: }
130: $result.=&Apache::edit::end_row();
131: $result.=&Apache::edit::start_spanning_row();
132: } elsif ($target eq 'modified') {
133: my $constructtag;
134: if ($token->[1] eq 'numericalhint') {
135: $constructtag=&Apache::edit::get_new_args($token,$parstack,
136: $safeeval,'name',
137: 'answer','unit','format');
138: } elsif ($token->[1] eq 'formulahint') {
139: $constructtag=&Apache::edit::get_new_args($token,$parstack,
140: $safeeval,'name','answer',
141: 'samples');
142: }
143: if ($constructtag) {
144: $result = &Apache::edit::rebuild_tag($token);
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.69 bisitz 165: #id submissions occurred 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.67 www 181: if ($$args_ref{'samples'}) {
182: $$args_ref{'type'}='fml';
183: } else {
184: $$args_ref{'type'}='math';
185: }
1.43 albertel 186: } elsif ($$tagstack[-1] eq 'numericalhint') {
1.51 albertel 187: $$args_ref{'type'}='float';
1.39 albertel 188: }
1.65 albertel 189: &Apache::caparesponse::add_in_tag_answer($parstack,$safeeval);
190: my %answer = &Apache::caparesponse::get_answer();
191: my (@final_awards,@final_msgs,@ans_names);
192: foreach my $ans_name (keys(%answer)) {
193: &Apache::lonxml::debug(" doing $ans_name with ".join(':',@{ $answer{$ans_name}{'answers'} }));
194:
195: ${$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=
196: dclone($answer{$ans_name});
197: &Apache::caparesponse::setup_capa_response($args_ref,$response);
198: my ($result,@msgs) =
1.71 raeburn 199: &Apache::run::run("&caparesponse_check_list()",$safeeval);
1.65 albertel 200: &Apache::lonxml::debug("checking $ans_name $result with $response");
201: &Apache::lonxml::debug('msgs are '.join(':',@msgs));
202: my ($awards)=split(/:/,$result);
203: my @awards= split(/,/,$awards);
204: my ($ad, $msg) =
205: &Apache::inputtags::finalizeawards(\@awards,\@msgs);
206: push(@final_awards,$ad);
207: push(@final_msgs,$msg);
208: push(@ans_names,$ans_name);
209: }
210: my ($ad, $msg, $ans_name) =
211: &Apache::inputtags::finalizeawards(\@final_awards,
212: \@final_msgs,
213: \@ans_names,1);
214: if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') {
215: push(@Apache::hint::which,$hint_name);
216: }
1.39 albertel 217: $result='';
218: } elsif ($target eq 'meta') {
219: $result=&Apache::response::meta_package_write($token->[1]);
220: } elsif ($target eq 'edit') {
1.62 albertel 221: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
1.18 albertel 222: }
1.66 albertel 223: &Apache::caparesponse::pop_answer();
1.39 albertel 224: &Apache::response::end_hintresponse();
225: return $result;
1.28 albertel 226: }
227:
1.51 albertel 228: sub start_formulahint {
1.35 albertel 229: return &start_numericalhint(@_);
1.28 albertel 230: }
231:
1.51 albertel 232: sub end_formulahint {
1.35 albertel 233: return &end_numericalhint(@_);
1.28 albertel 234: }
235:
1.63 www 236: sub start_mathhint {
237: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
238: #do everything in end, so intervening <responseparams> and <answer> work
239: &Apache::response::start_hintresponse($parstack,$safeeval);
240: &Apache::lonxml::register('Apache::response',('answer'));
241: my $result;
242: if ($target eq 'edit') {
243: $result.=&Apache::edit::tag_start($target,$token);
244: $result.=&Apache::edit::text_arg('Name:','name',$token);
245: $result.=&Apache::edit::select_arg('Algebra System:',
246: 'cas',
247: ['maxima'],
248: $token);
249: $result.=&Apache::edit::text_arg('Argument Array:',
250: 'args',$token);
251: $result.=&Apache::edit::end_row();
252: $result.=&Apache::edit::start_spanning_row();
253: } elsif ($target eq 'modified') {
254: my $constructtag;
255: $constructtag=&Apache::edit::get_new_args($token,$parstack,
256: $safeeval,'name','cas',
257: 'args');
258: $result = &Apache::edit::rebuild_tag($token);
259: } elsif ($target eq 'web') {
260: &Apache::response::reset_params();
261: }
262: return $result;
263: }
264:
265: sub end_mathhint {
266: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
267: my $result;
268: if ($target eq 'web') {
269: if (!$Apache::lonxml::default_homework_loaded) {
270: &Apache::lonxml::default_homework_load($safeeval);
271: }
272: my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
273: &Apache::response::setup_params('mathhint',$safeeval);
274: my $partid=$Apache::inputtags::part;
275: my $submitid=$Apache::inputtags::response[-1];
276: my $response = $Apache::lonhomework::history{
277: "resource.$partid.$submitid.submission"};
278:
279: my $cas = &Apache::lonxml::get_param('cas',$parstack,$safeeval);
280: my $award;
281: if ($cas eq 'maxima') {
282: my $args = [&Apache::lonxml::get_param_var('args',$parstack,$safeeval)];
283: $award=&Apache::lonmaxima::maxima_run($Apache::response::custom_answer[-1],$response,$args);
284: }
285: if ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS') {
286: push (@Apache::hint::which,$name);
287: }
288: $result='';
289: } elsif ($target eq 'meta') {
290: $result=&Apache::response::meta_package_write($token->[1]);
291: } elsif ($target eq 'edit') {
292: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
293: }
294: pop(@Apache::response::custom_answer);
295: pop(@Apache::response::custom_answer_type);
296: &Apache::response::end_hintresponse();
297: return $result;
298: }
299:
1.64 www 300: sub start_customhint {
301: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
302: #do everything in end, so intervening <responseparams> and <answer> work
303: &Apache::response::start_hintresponse($parstack,$safeeval);
304: &Apache::lonxml::register('Apache::response',('answer'));
305: my $result;
306: if ($target eq 'edit') {
307: $result.=&Apache::edit::tag_start($target,$token);
308: $result.=&Apache::edit::text_arg('Name:','name',$token);
309: $result.=&Apache::edit::end_row();
310: $result.=&Apache::edit::start_spanning_row();
311: } elsif ($target eq 'modified') {
312: my $constructtag;
313: $constructtag=&Apache::edit::get_new_args($token,$parstack,
314: $safeeval,'name');
315: $result = &Apache::edit::rebuild_tag($token);
316: } elsif ($target eq 'web') {
317: &Apache::response::reset_params();
318: }
319: return $result;
320: }
321:
322: sub end_customhint {
323: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
324: my $result;
325: if ($target eq 'web') {
326: if (!$Apache::lonxml::default_homework_loaded) {
327: &Apache::lonxml::default_homework_load($safeeval);
328: }
329: my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
330: &Apache::response::setup_params('customhint',$safeeval);
331: my $partid=$Apache::inputtags::part;
332: my $submitid=$Apache::inputtags::response[-1];
333: my $response = $Apache::lonhomework::history{
334: "resource.$partid.$submitid.submission"};
335: my $award;
336: if ( $response =~ /[^\s]/ &&
337: $Apache::response::custom_answer_type[-1] eq 'loncapa/perl') {
338: if (!$Apache::lonxml::default_homework_loaded) {
339: &Apache::lonxml::default_homework_load($safeeval);
340: }
341: ${$safeeval->varglob('LONCAPA::customresponse_submission')}=
342: $response;
343:
344: $award = &Apache::run::run('{ my $submission=$LONCAPA::customresponse_submission;'.$Apache::response::custom_answer[-1].'}',$safeeval);
345: }
346: if ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS') {
347: push (@Apache::hint::which,$name);
348: }
349: $result='';
350: } elsif ($target eq 'meta') {
351: $result=&Apache::response::meta_package_write($token->[1]);
352: } elsif ($target eq 'edit') {
353: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
354: }
355: pop(@Apache::response::custom_answer);
356: pop(@Apache::response::custom_answer_type);
357: &Apache::response::end_hintresponse();
358: return $result;
359: }
360:
1.51 albertel 361: sub start_stringhint {
362: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
363: #do everything in end, so intervening <responseparams> work
364: &Apache::response::start_hintresponse($parstack,$safeeval);
365: my $result;
366: if ($target eq 'edit') {
367: $result.=&Apache::edit::tag_start($target,$token);
368: $result.=&Apache::edit::text_arg('Name:','name',$token);
369: $result.=&Apache::edit::text_arg('Answer:','answer',$token);
370: $result.=&Apache::edit::select_arg('Type:','type',
371: [['cs','Case Sensitive'],['ci','Case Insensitive'],
372: ['mc','Case Insensitive, Any Order'],
373: ['re','Regular Expression']],$token);
374: $result.=&Apache::edit::end_row();
375: $result.=&Apache::edit::start_spanning_row();
376: } elsif ($target eq 'modified') {
377: my $constructtag;
378: $constructtag=&Apache::edit::get_new_args($token,$parstack,
379: $safeeval,'name','answer',
380: 'type');
381: $result = &Apache::edit::rebuild_tag($token);
382: } elsif ($target eq 'web') {
383: &Apache::response::reset_params();
384: }
385: return $result;
1.28 albertel 386: }
387:
1.51 albertel 388: sub end_stringhint {
389: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
390: my $result;
391: if ($target eq 'web') {
392: if (!$Apache::lonxml::default_homework_loaded) {
393: &Apache::lonxml::default_homework_load($safeeval);
394: }
395: $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
1.65 albertel 396: my $hint_name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
1.51 albertel 397: &Apache::response::setup_params('stringhint',$safeeval);
398: my $partid=$Apache::inputtags::part;
1.60 albertel 399: my $id=$Apache::inputtags::hint[-1];
1.69 bisitz 400: #id submissions occurred under
1.60 albertel 401: my $submitid=$Apache::inputtags::response[-1];
1.51 albertel 402: my $response = $Apache::lonhomework::history{
403: "resource.$partid.$submitid.submission"};
404: &Apache::lonxml::debug("hintgroup is using $response<br />\n");
1.65 albertel 405: my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
1.51 albertel 406: my ($ad,$msg);
407: if ($type eq 're' ) {
1.65 albertel 408: my $answer=&Apache::lonxml::get_param('answer',$parstack,
409: $safeeval);
1.51 albertel 410: ${$safeeval->varglob('LONCAPA::response')}=$response;
1.57 albertel 411: my $compare='=';
412: if ($answer=~/^\s*NOT\s*/) {
413: $answer=~s/^\s*NOT\s*//;
414: $compare='!';
415: }
416: my $test='$LONCAPA::response'.$compare.'~m'.$answer;
417: &Apache::lonxml::debug("test $test");
418: $result = &Apache::run::run("return $test",$safeeval);
1.51 albertel 419: &Apache::lonxml::debug("current $response");
420: &Apache::lonxml::debug("current $answer");
421: $ad = ($result) ? 'APPROX_ANS' : 'INCORRECT';
422: } else {
1.65 albertel 423: my @args = ('type');
424: my $args_ref =
425: &Apache::caparesponse::setup_capa_args($safeeval,$parstack,
426: \@args,$response);
1.71 raeburn 427: if ($$args_ref{'type'} eq '') {
428: $$args_ref{'type'} = 'ci';
429: }
1.65 albertel 430: &Apache::caparesponse::add_in_tag_answer($parstack,$safeeval);
431: my (@final_awards,@final_msgs,@ans_names);
432: my %answer = &Apache::caparesponse::get_answer();
433: foreach my $ans_name (keys(%answer)) {
434: &Apache::lonxml::debug(" doing $ans_name with ".join(':',@{ $answer{$ans_name}{'answers'} }));
435: ${$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=dclone($answer{$ans_name});
1.71 raeburn 436: my ($result, @msgs)=&Apache::run::run("&caparesponse_check_list()",$safeeval);
1.65 albertel 437: &Apache::lonxml::debug('msgs are'.join(':',@msgs));
438: my ($awards) = split(/:/,$result);
439: my (@awards) = split(/,/,$awards);
440: ($ad,$msg) =
441: &Apache::inputtags::finalizeawards(\@awards,\@msgs);
442: push(@final_awards,$ad);
443: push(@final_msgs,$msg);
444: push(@ans_names,$ans_name);
445: &Apache::lonxml::debug("\n<br>result:$result:$Apache::lonxml::curdepth<br>\n");
1.51 albertel 446: }
1.65 albertel 447: my ($ad, $msg, $ans_name) =
448: &Apache::inputtags::finalizeawards(\@final_awards,
449: \@final_msgs,
450: \@ans_names,1);
1.51 albertel 451: }
452: if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') {
1.65 albertel 453: push(@Apache::hint::which,$hint_name);
1.51 albertel 454: }
455: $result='';
456: } elsif ($target eq 'meta') {
457: $result=&Apache::response::meta_package_write($token->[1]);
458: } elsif ($target eq 'edit') {
1.62 albertel 459: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
1.51 albertel 460: }
461: &Apache::response::end_hintresponse();
462: return $result;
1.1 albertel 463: }
464:
1.2 albertel 465: # a part shows if it is on, if no specific parts are on, then default shows
1.1 albertel 466: sub start_hintpart {
1.39 albertel 467: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.15 albertel 468:
1.39 albertel 469: my $show ='0';
470: my $result = '';
471: if ($target eq 'web') {
472: my $on= &Apache::lonxml::get_param('on',$parstack,$safeeval);
473: &Apache::lonxml::debug("hintpart sees $on and ,$#Apache::hint::which");
474: if ( $on eq 'default' && $#Apache::hint::which == '-1') {
475: $show=1;
476: } else {
477: my $which;
478: foreach $which (@Apache::hint::which) { if ($which eq $on) { $show = 1; last } }
479: }
480: if (!$show) {
1.61 albertel 481: &Apache::lonxml::get_all_text("/hintpart",$parser,$style);
1.39 albertel 482: }
483: } elsif ($target eq 'grade') {
1.61 albertel 484: &Apache::lonxml::get_all_text("/hintpart",$parser,$style);
1.39 albertel 485: } elsif ($target eq 'edit') {
486: $result.= &Apache::edit::tag_start($target,$token);
487: $result.= &Apache::edit::text_arg('On:','on',$token);
488: $result.= &Apache::edit::end_row();
489: $result.= &Apache::edit::start_spanning_row();
490: } elsif ($target eq 'modified') {
491: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
492: $safeeval,'on');
493: if ($constructtag) {
494: $result = &Apache::edit::rebuild_tag($token);
495: }
1.20 albertel 496: }
1.39 albertel 497: return $result;
1.1 albertel 498: }
499:
500: sub end_hintpart {
1.29 albertel 501: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
502: my $result;
1.62 albertel 503: if ($target eq 'edit') {
504: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
505: }
1.29 albertel 506: return $result;
507: }
508:
509: sub start_optionhint {
510: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
511: my $result;
1.30 albertel 512: &Apache::response::start_hintresponse($parstack,$safeeval);
513: if ($target eq 'edit') {
514: $result.=&Apache::edit::tag_start($target,$token);
515: $result.=&Apache::edit::text_arg('Name:','name',$token);
516: $result.=&Apache::edit::text_arg('Answer:','answer',$token,40);
517: $result.=&Apache::edit::text_arg('Concept:','concept',$token,50);
518: } elsif ($target eq 'modified') {
519: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
520: $safeeval,'name',
521: 'answer','concept');
522: if ($constructtag) {
523: $result = &Apache::edit::rebuild_tag($token);
524: }
525: } elsif ($target eq 'meta') {
526: $result=&Apache::response::meta_package_write('numericalhint');
527: }
1.29 albertel 528: return $result;
529: }
530:
531: sub end_optionhint {
532: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
533: my $result;
1.30 albertel 534: if ($target eq 'web') {
535: my ($foilmatch,$conceptmatch)=(-1,-1);
536: my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
537: my $partid=$Apache::inputtags::part;
1.69 bisitz 538: #id submissions occurred under
1.60 albertel 539: my $submitid=$Apache::inputtags::response[-1];
1.30 albertel 540: my $part_id="$partid.$submitid";
541: my %answer;
542: my $answer=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
543: if ($answer) {
544: eval('%answer ='.$answer);
1.62 albertel 545: &Apache::lonxml::debug("answwer hash");
1.30 albertel 546: &Apache::lonhomework::showhash(%answer);
547: my $response = $Apache::lonhomework::history{
548: "resource.$part_id.submission"};
549: my %response=&Apache::lonnet::str2hash($response);
550: &Apache::lonhomework::showhash(%response);
551: foreach my $foil (keys(%answer)) {
552: $foilmatch=1;
553: if ($answer{$foil} ne $response{$foil}) {$foilmatch=0;last;}
554: }
555: }
556: my %concept;
557: my $constr=&Apache::lonxml::get_param('concept',$parstack,$safeeval);
558: if ( $constr ) { eval('%concept ='.$constr); }
559: my $response = $Apache::lonhomework::history{
560: "resource.$part_id.submissiongrading"};
561: my %response=&Apache::lonnet::str2hash($response);
562: foreach my $concept (keys(%concept)) {
563: my $compare;
564: if ($concept{$concept} eq 'correct') {$compare=1}else{$compare=0}
565: $conceptmatch=1;
566: if (ref($Apache::hint::option{"$part_id.concepts"})) {
567: foreach my $foil (@{ $Apache::hint::option{"$part_id.concept.$concept"} }) {
568: &Apache::lonxml::debug("compare -$foil- -$response{$foil}-$compare-");
569: if ( exists($response{$foil}) &&
570: $response{$foil} ne $compare) {$conceptmatch=0;last;}
571: }
572: } else {
573: $conceptmatch=0;
574: }
575: if ($conceptmatch eq '0') { last; }
576: }
577: if ( ($conceptmatch eq '-1' || $conceptmatch eq '1') &&
578: ($foilmatch eq '-1' || $foilmatch eq '1') ) {
579: push(@Apache::hint::which,$name);
580: }
1.62 albertel 581: } elsif ($target eq 'edit') {
582: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
583: }
1.30 albertel 584: &Apache::response::end_hintresponse();
1.29 albertel 585: return $result;
586: }
587:
588: sub start_radiobuttonhint {
589: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
590: my $result;
591: &Apache::response::start_hintresponse($parstack,$safeeval);
592: if ($target eq 'edit') {
593: $result.=&Apache::edit::tag_start($target,$token);
594: $result.=&Apache::edit::text_arg('Name:','name',$token);
595: $result.=&Apache::edit::text_arg('Answer:','answer',$token);
596: } elsif ($target eq 'modified') {
597: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
598: $safeeval,'name',
599: 'answer');
600: if ($constructtag) {
601: $result = &Apache::edit::rebuild_tag($token);
602: }
603: } elsif ($target eq 'meta') {
604: $result=&Apache::response::meta_package_write('numericalhint');
605: }
606: return $result;
1.1 albertel 607: }
608:
1.31 albertel 609: sub end_radiobuttonhint {
1.29 albertel 610: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
611: my $result;
612: if ($target eq 'web') {
613: my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
614: my @answer;
615: my $answer=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
616: eval('@answer ='.$answer);
617: my $partid=$Apache::inputtags::part;
1.69 bisitz 618: #id submissions occurred under
1.60 albertel 619: my $submitid=$Apache::inputtags::response[-1];
1.29 albertel 620: my $part_id="$partid.$submitid";
621: my $response = $Apache::lonhomework::history{
622: "resource.$part_id.submission"};
623: ($response)=&Apache::lonnet::str2hash($response);
1.42 albertel 624: &Apache::lonxml::debug("response is $response");
625:
626: if ($answer[0] eq 'foil') {
627: shift(@answer);
628: foreach my $answer (@answer) {
629: if ($response eq $answer) {
630: push (@Apache::hint::which,$name);
631: last;
632: }
633: }
1.29 albertel 634: } elsif ($answer[0] eq 'concept') {
1.42 albertel 635: shift(@answer);
636: foreach my $answer (@answer) {
637: if (ref($Apache::hint::radiobutton{"$part_id.concept.".$answer})) {
638: my @names=@{ $Apache::hint::radiobutton{"$part_id.concept.".$answer} };
639: if (grep(/^\Q$response\E$/,@names)) {
640: push(@Apache::hint::which,$name);
641: last;
642: }
1.29 albertel 643: }
644: }
645: }
1.62 albertel 646: } elsif ($target eq 'edit') {
647: $result.=&Apache::edit::end_row().&Apache::edit::end_table();
648: }
1.29 albertel 649: &Apache::response::end_hintresponse();
650: return $result;
651: }
1.1 albertel 652: 1;
653: __END__
1.74 ! jms 654:
! 655:
! 656: =head1 NAME
! 657:
! 658: Apache::hinttags
! 659:
! 660: =head1 SYNOPSIS
! 661:
! 662: This handler coordinates the delivery of hints to students working on LON-CAPA problems and assignments.
! 663:
! 664: This is part of the LearningOnline Network with CAPA project
! 665: described at http://www.lon-capa.org.
! 666:
! 667: =head1 SUBROUTINES
! 668:
! 669: =over
! 670:
! 671: =item start_hintgroup()
! 672:
! 673: =item end_hintgroup()
! 674:
! 675: =item start_numericalhint()
! 676:
! 677: =item end_numericalhint()
! 678:
! 679: =item start_formulahint()
! 680:
! 681: =item end_formulahint()
! 682:
! 683: =item start_mathhint()
! 684:
! 685: =item end_mathhint()
! 686:
! 687: =item start_customhint()
! 688:
! 689: =item end_customhint()
! 690:
! 691: =item start_stringhint()
! 692:
! 693: =item end_stringhint()
! 694:
! 695: =item start_hintpart()
! 696:
! 697: =item end_hintpart()
! 698:
! 699: =item start_optionhint()
! 700:
! 701: =item end_optionhint()
! 702:
! 703: =item start_radiobuttonhint()
! 704:
! 705: =item end_radiobuttonhint()
! 706:
! 707: =back
! 708:
! 709: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>