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