File:  [LON-CAPA] / loncom / homework / hint.pm
Revision 1.63: download - view: text, annotated - select for diffs
Mon Dec 18 21:12:51 2006 UTC (17 years, 4 months ago) by www
Branches: MAIN
CVS tags: HEAD
<mathhint> functionality

    1: # The LearningOnline Network with CAPA 
    2: # implements the tags that control the hints
    3: #
    4: # $Id: hint.pm,v 1.63 2006/12/18 21:12:51 www Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA me&aree software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: package Apache::hinttags; 
   30: 
   31: use strict;
   32: use Apache::lonnet;
   33: use capa;
   34: use Apache::lonmaxima();
   35: use Apache::response();
   36: use Apache::lonlocal;
   37: 
   38: BEGIN {
   39:     &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart','numericalhint','stringhint','formulahint','optionhint','radiobuttonhint','mathhint'));
   40: }
   41: 
   42: 
   43: @Apache::hint::which=();
   44: sub start_hintgroup {
   45:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   46:     my $skiptoend='0';
   47:     my $result;
   48: 
   49:     if ($target eq 'web') {
   50: 	my $id=$Apache::inputtags::part;
   51: 	my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
   52: 	if ( $numtries eq '') { $numtries = 0; }
   53: 	my $hinttries=&Apache::response::get_response_param($id,"hinttries",1);
   54: 	&Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
   55: 	my $gradestatus=
   56: 	    $Apache::lonhomework::history{"resource.$id.solved"};
   57: 	my $showoncorrect=lc(&Apache::lonxml::get_param('showoncorrect',$parstack,$safeeval));	
   58: 	&Apache::lonxml::debug("onc orrect $showoncorrect, $gradestatus");
   59: 	if ( ($showoncorrect ne 'yes' && &Apache::response::show_answer()) ||
   60: 	     ( $numtries < $hinttries) ) {
   61: 	    &Apache::lonxml::debug("Grabbin all");
   62: 	    &Apache::lonxml::get_all_text("/hintgroup",$parser,$style);
   63: 	}
   64: 	&Apache::lonxml::startredirection;
   65:     } elsif ($target eq 'tex') {
   66: 	$result .= '\keephidden{';
   67:     } elsif ($target eq 'edit') {
   68: 	$result.=&Apache::edit::tag_start($target,$token);
   69: 	$result.=&Apache::edit::select_arg('Show hint even if problem Correct:','showoncorrect',[['no',&mt('No')],['yes',&mt('Yes')]],$token);
   70: 	$result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
   71:     } elsif ($target eq 'modified') {
   72: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'showoncorrect');
   73:        if ($constructtag) {
   74:            $result =&Apache::edit::rebuild_tag($token);
   75:            $result.=&Apache::edit::handle_insert();
   76:        }
   77:     }
   78:     @Apache::hint::which=();
   79:     return $result;
   80: }
   81: 
   82: sub end_hintgroup {
   83:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   84:     my $result;
   85: 
   86:     if ($target eq 'web') {
   87: 	my $id=$Apache::inputtags::part;
   88: 	my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
   89: 	if ( $numtries eq '') { $numtries = 0; }
   90: 	my $hinttries=&Apache::response::get_response_param($id,"hinttries",1);
   91: 	&Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
   92: 	my $hinttext=&Apache::lonxml::endredirection;
   93: 	if ($Apache::lonhomework::type ne 'exam' &&
   94: 	    $numtries >= $hinttries && $hinttext =~/\S/) {
   95: 	    $result='<table bgcolor="#dddddd"><tr><td>'.
   96: 		$hinttext.'</td></tr></table>';
   97: 	}
   98:     } elsif ($target eq 'edit') {
   99: 	$result.=&Apache::edit::end_row().&Apache::edit::end_table();
  100:     } elsif ($target eq 'tex') {
  101: 	$result .= '}';
  102:     }
  103:     @Apache::hint::which=();
  104:     return $result;
  105: }
  106: 
  107: sub start_numericalhint {
  108:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  109:     #do everything in end, so intervening <responseparams> work
  110:     &Apache::response::start_hintresponse($parstack,$safeeval);
  111:     my $result;
  112:     if ($target eq 'edit') {
  113: 	$result.=&Apache::edit::tag_start($target,$token);
  114: 	$result.=&Apache::edit::text_arg('Name:','name',$token);
  115: 	$result.=&Apache::edit::text_arg('Answer:','answer',$token);
  116: 	if ($token->[1] eq 'numericalhint') {
  117: 	    $result.=&Apache::edit::text_arg('Unit:','unit',$token,5).
  118: 		&Apache::loncommon::help_open_topic('Physical_Units');
  119: 	    $result.=&Apache::edit::text_arg('Format:','format',$token,4).
  120: 		&Apache::loncommon::help_open_topic('Numerical_Response_Format');
  121: 	} elsif ($token->[1] eq 'stringhint') {
  122: 	    $result.=&Apache::edit::select_arg('Type:','type',
  123: 			    [['cs','Case Sensitive'],['ci','Case Insensitive'],
  124: 			     ['mc','Case Insensitive, Any Order']],$token);
  125: 	} elsif ($token->[1] eq 'formulahint') {
  126: 	    $result.=&Apache::edit::text_arg('Sample Points:','samples',$token,40);
  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 'stringhint') {
  137: 	    $constructtag=&Apache::edit::get_new_args($token,$parstack,
  138: 						     $safeeval,'name','answer',
  139: 						     'type');
  140: 	} elsif ($token->[1] eq 'formulahint') {
  141: 	    $constructtag=&Apache::edit::get_new_args($token,$parstack,
  142: 						     $safeeval,'name','answer',
  143: 						     'samples');
  144: 	}
  145: 	if ($constructtag) {
  146: 	    $result  = &Apache::edit::rebuild_tag($token);
  147: 	    $result .= &Apache::edit::handle_insert();
  148: 	}
  149:     } elsif ($target eq 'web') {
  150: 	&Apache::response::reset_params();
  151:     }
  152:     return $result;
  153: }
  154: 
  155: sub end_numericalhint {
  156:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  157:     my $result;
  158:     if ($target eq 'web') {
  159: 	if (!$Apache::lonxml::default_homework_loaded) {
  160: 	    &Apache::lonxml::default_homework_load($safeeval);
  161: 	}
  162: 	$safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
  163: 	my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
  164: 	&Apache::response::setup_params('numericalhint',$safeeval);
  165: 	my $partid=$Apache::inputtags::part;
  166: 	my $id=$Apache::inputtags::hint[-1];
  167: 	#id submissions occured under
  168: 	my $submitid=$Apache::inputtags::response[-1];
  169: 	my $response = $Apache::lonhomework::history{
  170: 			    "resource.$partid.$submitid.submission"};
  171: 	&Apache::lonxml::debug("hintgroup is using $response<br />\n");
  172: 	my $hideunit=&Apache::response::get_response_param($partid.'_'.$submitid,'turnoffunit');
  173: 	my $args_ref= \%{$safeeval->varglob('LONCAPA::CAPAresponse_args')};
  174: 	$$args_ref{'response'}=$response;
  175: 	#need to get all possible parms
  176: 	foreach my $arg ('type','tol','sig','ans_fmt','unit','calc',
  177: 			 'samples') {
  178: 	    $$args_ref{$arg}=
  179: 		&Apache::lonxml::get_param($arg,$parstack,$safeeval);
  180: 	}
  181: 	foreach my $key (keys(%Apache::inputtags::params)) {
  182: 	    $$args_ref{$key}=$Apache::inputtags::params{$key};
  183: 	}
  184: 	if (lc($hideunit) eq "yes") { delete($$args_ref{'unit'}); }
  185: 	if ($$tagstack[-1] eq 'formulahint') {
  186: 	    $$args_ref{'type'}='fml';
  187: 	} elsif ($$tagstack[-1] eq 'numericalhint') {
  188: 	    $$args_ref{'type'}='float';
  189: 	}
  190: 	my @answer=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
  191: 	&Apache::lonxml::debug('answer is'.join(':',@answer));
  192: 	@{$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=@answer;
  193: 		
  194: 	($result,my @msgs) = &Apache::run::run("&caparesponse_check_list()",
  195: 						$safeeval);
  196: 	&Apache::lonxml::debug('msgs are'.join(':',@msgs));
  197: 	&Apache::lonxml::debug("result:$result:$Apache::lonxml::curdepth");
  198: 	my ($awards)=split(/:/,$result);
  199: 	my (@awards) = split(/,/,$awards);
  200: 	my ($ad, $msg) = &Apache::inputtags::finalizeawards(\@awards,\@msgs);
  201: 	if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') { push (@Apache::hint::which,$name); }
  202: 	$result='';
  203:     } elsif ($target eq 'meta') {
  204: 	$result=&Apache::response::meta_package_write($token->[1]);
  205:     } elsif ($target eq 'edit') {
  206: 	$result.=&Apache::edit::end_row().&Apache::edit::end_table();
  207:     }
  208:     &Apache::response::end_hintresponse();
  209:     return $result;
  210: }
  211: 
  212: sub start_formulahint {
  213:     return &start_numericalhint(@_);
  214: }
  215: 
  216: sub end_formulahint {
  217:     return &end_numericalhint(@_);
  218: }
  219: 
  220: sub start_mathhint {
  221:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  222:     #do everything in end, so intervening <responseparams> and <answer> work
  223:     &Apache::response::start_hintresponse($parstack,$safeeval);
  224:     &Apache::lonxml::register('Apache::response',('answer'));
  225:     my $result;
  226:     if ($target eq 'edit') {
  227:         $result.=&Apache::edit::tag_start($target,$token);
  228:         $result.=&Apache::edit::text_arg('Name:','name',$token);
  229:         $result.=&Apache::edit::select_arg('Algebra System:',
  230:                                            'cas',
  231:                                            ['maxima'],
  232:                                            $token);
  233:         $result.=&Apache::edit::text_arg('Argument Array:',
  234:                                          'args',$token);
  235:         $result.=&Apache::edit::end_row();
  236:         $result.=&Apache::edit::start_spanning_row();
  237:     } elsif ($target eq 'modified') {
  238:         my $constructtag;
  239:         $constructtag=&Apache::edit::get_new_args($token,$parstack,
  240:                                                   $safeeval,'name','cas',
  241:                                                   'args');
  242:         $result  = &Apache::edit::rebuild_tag($token);
  243:         $result .= &Apache::edit::handle_insert();
  244:     } elsif ($target eq 'web') {
  245:         &Apache::response::reset_params();
  246:     }
  247:     return $result;
  248: }
  249: 
  250: sub end_mathhint {
  251:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  252:     my $result;
  253:     if ($target eq 'web') {
  254:         if (!$Apache::lonxml::default_homework_loaded) {
  255:             &Apache::lonxml::default_homework_load($safeeval);
  256:         }
  257: 	my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
  258:         &Apache::response::setup_params('mathhint',$safeeval);
  259:         my $partid=$Apache::inputtags::part;
  260:         my $submitid=$Apache::inputtags::response[-1];
  261:         my $response = $Apache::lonhomework::history{
  262:                             "resource.$partid.$submitid.submission"};
  263: 	
  264: 	my $cas = &Apache::lonxml::get_param('cas',$parstack,$safeeval);
  265: 	my $award;
  266: 	if ($cas eq 'maxima') {
  267: 	    my $args = [&Apache::lonxml::get_param_var('args',$parstack,$safeeval)];
  268: 	    $award=&Apache::lonmaxima::maxima_run($Apache::response::custom_answer[-1],$response,$args);
  269: 	}
  270:         if ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS') {
  271:             push (@Apache::hint::which,$name);
  272:         }
  273:         $result='';
  274:     } elsif ($target eq 'meta') {
  275:         $result=&Apache::response::meta_package_write($token->[1]);
  276:     } elsif ($target eq 'edit') {
  277:         $result.=&Apache::edit::end_row().&Apache::edit::end_table();
  278:     }
  279:     pop(@Apache::response::custom_answer);
  280:     pop(@Apache::response::custom_answer_type);
  281:     &Apache::response::end_hintresponse();
  282:     return $result;
  283: }
  284: 
  285: sub start_stringhint {
  286:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  287:     #do everything in end, so intervening <responseparams> work
  288:     &Apache::response::start_hintresponse($parstack,$safeeval);
  289:     my $result;
  290:     if ($target eq 'edit') {
  291: 	$result.=&Apache::edit::tag_start($target,$token);
  292: 	$result.=&Apache::edit::text_arg('Name:','name',$token);
  293: 	$result.=&Apache::edit::text_arg('Answer:','answer',$token);
  294: 	$result.=&Apache::edit::select_arg('Type:','type',
  295: 			 [['cs','Case Sensitive'],['ci','Case Insensitive'],
  296: 			  ['mc','Case Insensitive, Any Order'],
  297: 			  ['re','Regular Expression']],$token);
  298: 	$result.=&Apache::edit::end_row();
  299: 	$result.=&Apache::edit::start_spanning_row();
  300:     } elsif ($target eq 'modified') {
  301: 	my $constructtag;
  302: 	$constructtag=&Apache::edit::get_new_args($token,$parstack,
  303: 						  $safeeval,'name','answer',
  304: 						  'type');
  305: 	$result  = &Apache::edit::rebuild_tag($token);
  306: 	$result .= &Apache::edit::handle_insert();
  307:     } elsif ($target eq 'web') {
  308: 	&Apache::response::reset_params();
  309:     }
  310:     return $result;
  311: }
  312: 
  313: sub end_stringhint {
  314:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  315:     my $result;
  316:     if ($target eq 'web') {
  317: 	if (!$Apache::lonxml::default_homework_loaded) {
  318: 	    &Apache::lonxml::default_homework_load($safeeval);
  319: 	}
  320: 	my $answer=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
  321: 	$safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
  322: 	my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
  323: 	&Apache::response::setup_params('stringhint',$safeeval);
  324: 	my $partid=$Apache::inputtags::part;
  325: 	my $id=$Apache::inputtags::hint[-1];
  326: 	#id submissions occured under
  327: 	my $submitid=$Apache::inputtags::response[-1];
  328: 	my $response = $Apache::lonhomework::history{
  329: 			    "resource.$partid.$submitid.submission"};
  330: 	&Apache::lonxml::debug("hintgroup is using $response<br />\n");
  331: 	my $args_ref= \%{$safeeval->varglob('LONCAPA::CAPAresponse_args')};
  332: 	$$args_ref{'response'}=$response;
  333: 	my $type=$$args_ref{'type'}=&Apache::lonxml::get_param('type',$parstack,$safeeval);
  334: 	my ($ad,$msg);
  335: 	if ($type eq 're' ) {
  336: 	    ${$safeeval->varglob('LONCAPA::response')}=$response;
  337: 	    my $compare='=';
  338: 	    if ($answer=~/^\s*NOT\s*/) {
  339: 		$answer=~s/^\s*NOT\s*//;
  340: 		$compare='!';
  341: 	    }
  342: 	    my $test='$LONCAPA::response'.$compare.'~m'.$answer;
  343: 	    &Apache::lonxml::debug("test $test");
  344: 	    $result = &Apache::run::run("return $test",$safeeval);
  345: 	    &Apache::lonxml::debug("current $response");
  346: 	    &Apache::lonxml::debug("current $answer");
  347: 	    $ad = ($result) ? 'APPROX_ANS' : 'INCORRECT';
  348: 	} else { 
  349: 	    foreach my $key (keys(%Apache::inputtags::params)) {
  350: 		$$args_ref{$key}=$Apache::inputtags::params{$key};
  351: 	    }
  352: 	    &Apache::lonxml::debug('answer is'.$answer);
  353: 	    @{$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=($answer);
  354: 	    
  355: 	    ($result,my @msgs)=&Apache::run::run("&caparesponse_check_list()",
  356: 						   $safeeval);
  357: 	    &Apache::lonxml::debug('msgs are'.join(':',@msgs));
  358: 	    &Apache::lonxml::debug("result:$result:$Apache::lonxml::curdepth");
  359: 	    my ($awards)=split(/:/,$result);
  360: 	    my (@awards) = split(/,/,$awards);
  361: 	    ($ad, $msg) = &Apache::inputtags::finalizeawards(\@awards,\@msgs);
  362: 	}
  363: 	if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') { 
  364: 	    push (@Apache::hint::which,$name);
  365: 	}
  366: 	$result='';
  367:     } elsif ($target eq 'meta') {
  368: 	$result=&Apache::response::meta_package_write($token->[1]);
  369:     } elsif ($target eq 'edit') {
  370: 	$result.=&Apache::edit::end_row().&Apache::edit::end_table();
  371:     }
  372:     &Apache::response::end_hintresponse();
  373:     return $result;
  374: }
  375: 
  376: # a part shows if it is on, if no specific parts are on, then default shows
  377: sub start_hintpart {
  378:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  379: 
  380:     my $show ='0';
  381:     my $result = '';
  382:     if ($target eq 'web') {
  383: 	my $on= &Apache::lonxml::get_param('on',$parstack,$safeeval);
  384: 	&Apache::lonxml::debug("hintpart sees $on and ,$#Apache::hint::which");
  385: 	if ( $on eq 'default' && $#Apache::hint::which == '-1') {
  386: 	    $show=1;
  387: 	} else {
  388: 	    my $which;
  389: 	    foreach $which (@Apache::hint::which) { if ($which eq $on) { $show = 1; last } }
  390: 	}
  391: 	if (!$show) {
  392: 	    &Apache::lonxml::get_all_text("/hintpart",$parser,$style);
  393: 	}
  394:     } elsif ($target eq 'grade') {
  395: 	&Apache::lonxml::get_all_text("/hintpart",$parser,$style);
  396:     } elsif ($target eq 'edit') {
  397: 	$result.= &Apache::edit::tag_start($target,$token);
  398: 	$result.= &Apache::edit::text_arg('On:','on',$token);
  399: 	$result.= &Apache::edit::end_row();
  400: 	$result.= &Apache::edit::start_spanning_row();
  401:     } elsif ($target eq 'modified') {
  402: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  403: 						     $safeeval,'on');
  404: 	if ($constructtag) {
  405: 	    $result = &Apache::edit::rebuild_tag($token);
  406: 	    $result.=&Apache::edit::handle_insert();
  407: 	}
  408:     }
  409:     return $result;
  410: }
  411: 
  412: sub end_hintpart {
  413:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  414:     my $result;
  415:     if ($target eq 'edit') {
  416: 	$result.=&Apache::edit::end_row().&Apache::edit::end_table();
  417:     }
  418:     return $result;
  419: }
  420: 
  421: sub start_optionhint {
  422:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  423:     my $result;
  424:     &Apache::response::start_hintresponse($parstack,$safeeval);
  425:     if ($target eq 'edit') {
  426: 	$result.=&Apache::edit::tag_start($target,$token);
  427: 	$result.=&Apache::edit::text_arg('Name:','name',$token);
  428: 	$result.=&Apache::edit::text_arg('Answer:','answer',$token,40);
  429: 	$result.=&Apache::edit::text_arg('Concept:','concept',$token,50);
  430:     } elsif ($target eq 'modified') {
  431: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  432: 						     $safeeval,'name',
  433: 						     'answer','concept');
  434: 	if ($constructtag) {
  435: 	    $result  = &Apache::edit::rebuild_tag($token);
  436: 	    $result .= &Apache::edit::handle_insert();
  437: 	}
  438:     } elsif ($target eq 'meta') {
  439: 	$result=&Apache::response::meta_package_write('numericalhint');
  440:     }
  441:     return $result;
  442: }
  443: 
  444: sub end_optionhint {
  445:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  446:     my $result;
  447:     if ($target eq 'web') {
  448: 	my ($foilmatch,$conceptmatch)=(-1,-1);
  449: 	my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
  450: 	my $partid=$Apache::inputtags::part;
  451: 	#id submissions occured under
  452: 	my $submitid=$Apache::inputtags::response[-1];
  453: 	my $part_id="$partid.$submitid";
  454: 	my %answer;
  455: 	my $answer=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
  456: 	if ($answer) {
  457: 	    eval('%answer ='.$answer);
  458: 	    &Apache::lonxml::debug("answwer hash");
  459: 	    &Apache::lonhomework::showhash(%answer);
  460: 	    my $response = $Apache::lonhomework::history{
  461: 				            "resource.$part_id.submission"};
  462: 	    my %response=&Apache::lonnet::str2hash($response);
  463: 	    &Apache::lonhomework::showhash(%response);
  464: 	    foreach my $foil (keys(%answer)) {
  465: 		$foilmatch=1;
  466: 		if ($answer{$foil} ne $response{$foil}) {$foilmatch=0;last;}
  467: 	    }
  468: 	}
  469: 	my %concept;
  470: 	my $constr=&Apache::lonxml::get_param('concept',$parstack,$safeeval);
  471: 	if ( $constr ) { eval('%concept ='.$constr);	}
  472: 	my $response = $Apache::lonhomework::history{
  473: 					"resource.$part_id.submissiongrading"};
  474: 	my %response=&Apache::lonnet::str2hash($response);
  475: 	foreach my $concept (keys(%concept)) {
  476: 	    my $compare;
  477: 	    if ($concept{$concept} eq 'correct') {$compare=1}else{$compare=0}
  478: 	    $conceptmatch=1;
  479: 	    if (ref($Apache::hint::option{"$part_id.concepts"})) {
  480: 		foreach my $foil (@{ $Apache::hint::option{"$part_id.concept.$concept"} }) {
  481: 		    &Apache::lonxml::debug("compare -$foil- -$response{$foil}-$compare-");
  482: 		    if ( exists($response{$foil}) && 
  483: 			 $response{$foil} ne $compare) {$conceptmatch=0;last;}
  484: 		}
  485: 	    } else {
  486: 		$conceptmatch=0;
  487: 	    }
  488: 	    if ($conceptmatch eq '0') { last; }
  489: 	}
  490: 	if ( ($conceptmatch eq '-1' || $conceptmatch eq '1') &&
  491: 	     ($foilmatch    eq '-1' || $foilmatch    eq '1') ) {
  492: 	    push(@Apache::hint::which,$name);
  493: 	}
  494:     } elsif ($target eq 'edit') {
  495: 	$result.=&Apache::edit::end_row().&Apache::edit::end_table();
  496:     }
  497:     &Apache::response::end_hintresponse();
  498:     return $result;
  499: }
  500: 
  501: sub start_radiobuttonhint {
  502:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  503:     my $result;
  504:     &Apache::response::start_hintresponse($parstack,$safeeval);
  505:     if ($target eq 'edit') {
  506: 	$result.=&Apache::edit::tag_start($target,$token);
  507: 	$result.=&Apache::edit::text_arg('Name:','name',$token);
  508: 	$result.=&Apache::edit::text_arg('Answer:','answer',$token);
  509:     } elsif ($target eq 'modified') {
  510: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
  511: 						     $safeeval,'name',
  512: 						     'answer');
  513: 	if ($constructtag) {
  514: 	    $result  = &Apache::edit::rebuild_tag($token);
  515: 	    $result .= &Apache::edit::handle_insert();
  516: 	}
  517:     } elsif ($target eq 'meta') {
  518: 	$result=&Apache::response::meta_package_write('numericalhint');
  519:     }
  520:     return $result;
  521: }
  522: 
  523: sub end_radiobuttonhint {
  524:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  525:     my $result;
  526:     if ($target eq 'web') {
  527: 	my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
  528: 	my @answer;
  529: 	my $answer=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
  530: 	eval('@answer ='.$answer);
  531: 	my $partid=$Apache::inputtags::part;
  532: 	#id submissions occured under
  533: 	my $submitid=$Apache::inputtags::response[-1];
  534: 	my $part_id="$partid.$submitid";
  535: 	my $response = $Apache::lonhomework::history{
  536: 			    "resource.$part_id.submission"};
  537: 	($response)=&Apache::lonnet::str2hash($response);
  538: 	&Apache::lonxml::debug("response is $response");
  539: 	
  540: 	if ($answer[0] eq 'foil') {
  541: 	    shift(@answer);
  542: 	    foreach my $answer (@answer) {
  543: 		if ($response eq $answer) {
  544: 		    push (@Apache::hint::which,$name);
  545: 		    last;
  546: 		}
  547: 	    }
  548: 	} elsif ($answer[0] eq 'concept') {
  549: 	    shift(@answer);
  550: 	    foreach my $answer (@answer) {
  551: 		if (ref($Apache::hint::radiobutton{"$part_id.concept.".$answer})) {
  552: 		    my @names=@{ $Apache::hint::radiobutton{"$part_id.concept.".$answer} };
  553: 		    if (grep(/^\Q$response\E$/,@names)) {
  554: 			push(@Apache::hint::which,$name);
  555: 			last;
  556: 		    }
  557: 		}
  558: 	    }
  559: 	}
  560:     } elsif ($target eq 'edit') {
  561: 	$result.=&Apache::edit::end_row().&Apache::edit::end_table();
  562:     }
  563:     &Apache::response::end_hintresponse();
  564:     return $result;
  565: }
  566: 1;
  567: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>