Annotation of loncom/homework/hint.pm, revision 1.62.2.1

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

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