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

1.21      albertel    1: # The LearningOnline Network with CAPA 
                      2: # implements the tags that control the hints
                      3: #
1.64    ! www         4: # $Id: hint.pm,v 1.63 2006/12/18 21:12:51 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.1       albertel   29: package Apache::hinttags; 
                     30: 
                     31: use strict;
1.59      albertel   32: use Apache::lonnet;
1.6       albertel   33: use capa;
1.63      www        34: use Apache::lonmaxima();
                     35: use Apache::response();
1.53      albertel   36: use Apache::lonlocal;
1.1       albertel   37: 
1.25      harris41   38: BEGIN {
1.64    ! www        39:     &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart','numericalhint','stringhint','formulahint','optionhint','radiobuttonhint','mathhint','customhint'));
1.1       albertel   40: }
                     41: 
1.2       albertel   42: 
1.15      albertel   43: @Apache::hint::which=();
1.1       albertel   44: sub start_hintgroup {
1.39      albertel   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; }
1.52      albertel   53: 	my $hinttries=&Apache::response::get_response_param($id,"hinttries",1);
1.39      albertel   54: 	&Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
1.53      albertel   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");
1.58      albertel   59: 	if ( ($showoncorrect ne 'yes' && &Apache::response::show_answer()) ||
1.53      albertel   60: 	     ( $numtries < $hinttries) ) {
                     61: 	    &Apache::lonxml::debug("Grabbin all");
1.61      albertel   62: 	    &Apache::lonxml::get_all_text("/hintgroup",$parser,$style);
1.39      albertel   63: 	}
1.40      albertel   64: 	&Apache::lonxml::startredirection;
1.39      albertel   65:     } elsif ($target eq 'tex') {
                     66: 	$result .= '\keephidden{';
1.53      albertel   67:     } elsif ($target eq 'edit') {
                     68: 	$result.=&Apache::edit::tag_start($target,$token);
1.56      albertel   69: 	$result.=&Apache::edit::select_arg('Show hint even if problem Correct:','showoncorrect',[['no',&mt('No')],['yes',&mt('Yes')]],$token);
1.53      albertel   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:        }
1.20      albertel   77:     }
1.39      albertel   78:     @Apache::hint::which=();
                     79:     return $result;
1.1       albertel   80: }
                     81: 
                     82: sub end_hintgroup {
1.39      albertel   83:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     84:     my $result;
1.20      albertel   85: 
1.39      albertel   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; }
1.52      albertel   90: 	my $hinttries=&Apache::response::get_response_param($id,"hinttries",1);
1.39      albertel   91: 	&Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
1.40      albertel   92: 	my $hinttext=&Apache::lonxml::endredirection;
                     93: 	if ($Apache::lonhomework::type ne 'exam' &&
1.41      albertel   94: 	    $numtries >= $hinttries && $hinttext =~/\S/) {
1.40      albertel   95: 	    $result='<table bgcolor="#dddddd"><tr><td>'.
                     96: 		$hinttext.'</td></tr></table>';
1.38      albertel   97: 	}
1.39      albertel   98:     } elsif ($target eq 'edit') {
1.62      albertel   99: 	$result.=&Apache::edit::end_row().&Apache::edit::end_table();
1.39      albertel  100:     } elsif ($target eq 'tex') {
                    101: 	$result .= '}';
1.19      albertel  102:     }
1.39      albertel  103:     @Apache::hint::which=();
                    104:     return $result;
1.3       albertel  105: }
                    106: 
                    107: sub start_numericalhint {
1.39      albertel  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') {
1.44      albertel  122: 	    $result.=&Apache::edit::select_arg('Type:','type',
                    123: 			    [['cs','Case Sensitive'],['ci','Case Insensitive'],
                    124: 			     ['mc','Case Insensitive, Any Order']],$token);
1.39      albertel  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();
1.28      albertel  151:     }
1.39      albertel  152:     return $result;
1.3       albertel  153: }
                    154: 
                    155: sub end_numericalhint {
1.39      albertel  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);
1.48      albertel  164: 	&Apache::response::setup_params('numericalhint',$safeeval);
1.39      albertel  165: 	my $partid=$Apache::inputtags::part;
1.60      albertel  166: 	my $id=$Apache::inputtags::hint[-1];
1.39      albertel  167: 	#id submissions occured under
1.60      albertel  168: 	my $submitid=$Apache::inputtags::response[-1];
1.39      albertel  169: 	my $response = $Apache::lonhomework::history{
1.18      albertel  170: 			    "resource.$partid.$submitid.submission"};
1.39      albertel  171: 	&Apache::lonxml::debug("hintgroup is using $response<br />\n");
1.54      albertel  172: 	my $hideunit=&Apache::response::get_response_param($partid.'_'.$submitid,'turnoffunit');
1.51      albertel  173: 	my $args_ref= \%{$safeeval->varglob('LONCAPA::CAPAresponse_args')};
                    174: 	$$args_ref{'response'}=$response;
1.39      albertel  175: 	#need to get all possible parms
1.51      albertel  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: 	}
1.39      albertel  181: 	foreach my $key (keys(%Apache::inputtags::params)) {
1.51      albertel  182: 	    $$args_ref{$key}=$Apache::inputtags::params{$key};
1.43      albertel  183: 	}
1.51      albertel  184: 	if (lc($hideunit) eq "yes") { delete($$args_ref{'unit'}); }
1.43      albertel  185: 	if ($$tagstack[-1] eq 'formulahint') {
1.51      albertel  186: 	    $$args_ref{'type'}='fml';
1.43      albertel  187: 	} elsif ($$tagstack[-1] eq 'numericalhint') {
1.51      albertel  188: 	    $$args_ref{'type'}='float';
1.39      albertel  189: 	}
1.45      albertel  190: 	my @answer=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
                    191: 	&Apache::lonxml::debug('answer is'.join(':',@answer));
1.51      albertel  192: 	@{$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=@answer;
1.45      albertel  193: 		
1.51      albertel  194: 	($result,my @msgs) = &Apache::run::run("&caparesponse_check_list()",
                    195: 						$safeeval);
1.50      albertel  196: 	&Apache::lonxml::debug('msgs are'.join(':',@msgs));
1.51      albertel  197: 	&Apache::lonxml::debug("result:$result:$Apache::lonxml::curdepth");
1.50      albertel  198: 	my ($awards)=split(/:/,$result);
                    199: 	my (@awards) = split(/,/,$awards);
                    200: 	my ($ad, $msg) = &Apache::inputtags::finalizeawards(\@awards,\@msgs);
1.39      albertel  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') {
1.62      albertel  206: 	$result.=&Apache::edit::end_row().&Apache::edit::end_table();
1.18      albertel  207:     }
1.39      albertel  208:     &Apache::response::end_hintresponse();
                    209:     return $result;
1.28      albertel  210: }
                    211: 
1.51      albertel  212: sub start_formulahint {
1.35      albertel  213:     return &start_numericalhint(@_);
1.28      albertel  214: }
                    215: 
1.51      albertel  216: sub end_formulahint {
1.35      albertel  217:     return &end_numericalhint(@_);
1.28      albertel  218: }
                    219: 
1.63      www       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: 
1.64    ! www       285: sub start_customhint {
        !           286:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
        !           287:     #do everything in end, so intervening <responseparams> and <answer> work
        !           288:     &Apache::response::start_hintresponse($parstack,$safeeval);
        !           289:     &Apache::lonxml::register('Apache::response',('answer'));
        !           290:     my $result;
        !           291:     if ($target eq 'edit') {
        !           292:         $result.=&Apache::edit::tag_start($target,$token);
        !           293:         $result.=&Apache::edit::text_arg('Name:','name',$token);
        !           294:         $result.=&Apache::edit::end_row();
        !           295:         $result.=&Apache::edit::start_spanning_row();
        !           296:     } elsif ($target eq 'modified') {
        !           297:         my $constructtag;
        !           298:         $constructtag=&Apache::edit::get_new_args($token,$parstack,
        !           299:                                                   $safeeval,'name');
        !           300:         $result  = &Apache::edit::rebuild_tag($token);
        !           301:         $result .= &Apache::edit::handle_insert();
        !           302:     } elsif ($target eq 'web') {
        !           303:         &Apache::response::reset_params();
        !           304:     }
        !           305:     return $result;
        !           306: }
        !           307: 
        !           308: sub end_customhint {
        !           309:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
        !           310:     my $result;
        !           311:     if ($target eq 'web') {
        !           312:         if (!$Apache::lonxml::default_homework_loaded) {
        !           313:             &Apache::lonxml::default_homework_load($safeeval);
        !           314:         }
        !           315: 	my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
        !           316:         &Apache::response::setup_params('customhint',$safeeval);
        !           317:         my $partid=$Apache::inputtags::part;
        !           318:         my $submitid=$Apache::inputtags::response[-1];
        !           319:         my $response = $Apache::lonhomework::history{
        !           320:                             "resource.$partid.$submitid.submission"};
        !           321:         my $award;	
        !           322: 	if ( $response =~ /[^\s]/ && 
        !           323: 	     $Apache::response::custom_answer_type[-1] eq 'loncapa/perl') {
        !           324: 	    if (!$Apache::lonxml::default_homework_loaded) {
        !           325: 		&Apache::lonxml::default_homework_load($safeeval);
        !           326: 	    }
        !           327: 	    ${$safeeval->varglob('LONCAPA::customresponse_submission')}=
        !           328: 		$response;
        !           329: 	    
        !           330: 	    $award = &Apache::run::run('{ my $submission=$LONCAPA::customresponse_submission;'.$Apache::response::custom_answer[-1].'}',$safeeval);
        !           331: 	}
        !           332:         if ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS') {
        !           333:             push (@Apache::hint::which,$name);
        !           334:         }
        !           335:         $result='';
        !           336:     } elsif ($target eq 'meta') {
        !           337:         $result=&Apache::response::meta_package_write($token->[1]);
        !           338:     } elsif ($target eq 'edit') {
        !           339:         $result.=&Apache::edit::end_row().&Apache::edit::end_table();
        !           340:     }
        !           341:     pop(@Apache::response::custom_answer);
        !           342:     pop(@Apache::response::custom_answer_type);
        !           343:     &Apache::response::end_hintresponse();
        !           344:     return $result;
        !           345: }
        !           346: 
1.51      albertel  347: sub start_stringhint {
                    348:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    349:     #do everything in end, so intervening <responseparams> work
                    350:     &Apache::response::start_hintresponse($parstack,$safeeval);
                    351:     my $result;
                    352:     if ($target eq 'edit') {
                    353: 	$result.=&Apache::edit::tag_start($target,$token);
                    354: 	$result.=&Apache::edit::text_arg('Name:','name',$token);
                    355: 	$result.=&Apache::edit::text_arg('Answer:','answer',$token);
                    356: 	$result.=&Apache::edit::select_arg('Type:','type',
                    357: 			 [['cs','Case Sensitive'],['ci','Case Insensitive'],
                    358: 			  ['mc','Case Insensitive, Any Order'],
                    359: 			  ['re','Regular Expression']],$token);
                    360: 	$result.=&Apache::edit::end_row();
                    361: 	$result.=&Apache::edit::start_spanning_row();
                    362:     } elsif ($target eq 'modified') {
                    363: 	my $constructtag;
                    364: 	$constructtag=&Apache::edit::get_new_args($token,$parstack,
                    365: 						  $safeeval,'name','answer',
                    366: 						  'type');
                    367: 	$result  = &Apache::edit::rebuild_tag($token);
                    368: 	$result .= &Apache::edit::handle_insert();
                    369:     } elsif ($target eq 'web') {
                    370: 	&Apache::response::reset_params();
                    371:     }
                    372:     return $result;
1.28      albertel  373: }
                    374: 
1.51      albertel  375: sub end_stringhint {
                    376:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    377:     my $result;
                    378:     if ($target eq 'web') {
                    379: 	if (!$Apache::lonxml::default_homework_loaded) {
                    380: 	    &Apache::lonxml::default_homework_load($safeeval);
                    381: 	}
                    382: 	my $answer=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
                    383: 	$safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
                    384: 	my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
                    385: 	&Apache::response::setup_params('stringhint',$safeeval);
                    386: 	my $partid=$Apache::inputtags::part;
1.60      albertel  387: 	my $id=$Apache::inputtags::hint[-1];
1.51      albertel  388: 	#id submissions occured under
1.60      albertel  389: 	my $submitid=$Apache::inputtags::response[-1];
1.51      albertel  390: 	my $response = $Apache::lonhomework::history{
                    391: 			    "resource.$partid.$submitid.submission"};
                    392: 	&Apache::lonxml::debug("hintgroup is using $response<br />\n");
                    393: 	my $args_ref= \%{$safeeval->varglob('LONCAPA::CAPAresponse_args')};
                    394: 	$$args_ref{'response'}=$response;
                    395: 	my $type=$$args_ref{'type'}=&Apache::lonxml::get_param('type',$parstack,$safeeval);
                    396: 	my ($ad,$msg);
                    397: 	if ($type eq 're' ) {
                    398: 	    ${$safeeval->varglob('LONCAPA::response')}=$response;
1.57      albertel  399: 	    my $compare='=';
                    400: 	    if ($answer=~/^\s*NOT\s*/) {
                    401: 		$answer=~s/^\s*NOT\s*//;
                    402: 		$compare='!';
                    403: 	    }
                    404: 	    my $test='$LONCAPA::response'.$compare.'~m'.$answer;
                    405: 	    &Apache::lonxml::debug("test $test");
                    406: 	    $result = &Apache::run::run("return $test",$safeeval);
1.51      albertel  407: 	    &Apache::lonxml::debug("current $response");
                    408: 	    &Apache::lonxml::debug("current $answer");
                    409: 	    $ad = ($result) ? 'APPROX_ANS' : 'INCORRECT';
                    410: 	} else { 
                    411: 	    foreach my $key (keys(%Apache::inputtags::params)) {
                    412: 		$$args_ref{$key}=$Apache::inputtags::params{$key};
                    413: 	    }
                    414: 	    &Apache::lonxml::debug('answer is'.$answer);
                    415: 	    @{$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=($answer);
                    416: 	    
                    417: 	    ($result,my @msgs)=&Apache::run::run("&caparesponse_check_list()",
                    418: 						   $safeeval);
                    419: 	    &Apache::lonxml::debug('msgs are'.join(':',@msgs));
                    420: 	    &Apache::lonxml::debug("result:$result:$Apache::lonxml::curdepth");
                    421: 	    my ($awards)=split(/:/,$result);
                    422: 	    my (@awards) = split(/,/,$awards);
                    423: 	    ($ad, $msg) = &Apache::inputtags::finalizeawards(\@awards,\@msgs);
                    424: 	}
                    425: 	if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') { 
                    426: 	    push (@Apache::hint::which,$name);
                    427: 	}
                    428: 	$result='';
                    429:     } elsif ($target eq 'meta') {
                    430: 	$result=&Apache::response::meta_package_write($token->[1]);
                    431:     } elsif ($target eq 'edit') {
1.62      albertel  432: 	$result.=&Apache::edit::end_row().&Apache::edit::end_table();
1.51      albertel  433:     }
                    434:     &Apache::response::end_hintresponse();
                    435:     return $result;
1.1       albertel  436: }
                    437: 
1.2       albertel  438: # a part shows if it is on, if no specific parts are on, then default shows
1.1       albertel  439: sub start_hintpart {
1.39      albertel  440:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.15      albertel  441: 
1.39      albertel  442:     my $show ='0';
                    443:     my $result = '';
                    444:     if ($target eq 'web') {
                    445: 	my $on= &Apache::lonxml::get_param('on',$parstack,$safeeval);
                    446: 	&Apache::lonxml::debug("hintpart sees $on and ,$#Apache::hint::which");
                    447: 	if ( $on eq 'default' && $#Apache::hint::which == '-1') {
                    448: 	    $show=1;
                    449: 	} else {
                    450: 	    my $which;
                    451: 	    foreach $which (@Apache::hint::which) { if ($which eq $on) { $show = 1; last } }
                    452: 	}
                    453: 	if (!$show) {
1.61      albertel  454: 	    &Apache::lonxml::get_all_text("/hintpart",$parser,$style);
1.39      albertel  455: 	}
                    456:     } elsif ($target eq 'grade') {
1.61      albertel  457: 	&Apache::lonxml::get_all_text("/hintpart",$parser,$style);
1.39      albertel  458:     } elsif ($target eq 'edit') {
                    459: 	$result.= &Apache::edit::tag_start($target,$token);
                    460: 	$result.= &Apache::edit::text_arg('On:','on',$token);
                    461: 	$result.= &Apache::edit::end_row();
                    462: 	$result.= &Apache::edit::start_spanning_row();
                    463:     } elsif ($target eq 'modified') {
                    464: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    465: 						     $safeeval,'on');
                    466: 	if ($constructtag) {
                    467: 	    $result = &Apache::edit::rebuild_tag($token);
                    468: 	    $result.=&Apache::edit::handle_insert();
                    469: 	}
1.20      albertel  470:     }
1.39      albertel  471:     return $result;
1.1       albertel  472: }
                    473: 
                    474: sub end_hintpart {
1.29      albertel  475:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    476:     my $result;
1.62      albertel  477:     if ($target eq 'edit') {
                    478: 	$result.=&Apache::edit::end_row().&Apache::edit::end_table();
                    479:     }
1.29      albertel  480:     return $result;
                    481: }
                    482: 
                    483: sub start_optionhint {
                    484:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    485:     my $result;
1.30      albertel  486:     &Apache::response::start_hintresponse($parstack,$safeeval);
                    487:     if ($target eq 'edit') {
                    488: 	$result.=&Apache::edit::tag_start($target,$token);
                    489: 	$result.=&Apache::edit::text_arg('Name:','name',$token);
                    490: 	$result.=&Apache::edit::text_arg('Answer:','answer',$token,40);
                    491: 	$result.=&Apache::edit::text_arg('Concept:','concept',$token,50);
                    492:     } elsif ($target eq 'modified') {
                    493: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    494: 						     $safeeval,'name',
                    495: 						     'answer','concept');
                    496: 	if ($constructtag) {
                    497: 	    $result  = &Apache::edit::rebuild_tag($token);
                    498: 	    $result .= &Apache::edit::handle_insert();
                    499: 	}
                    500:     } elsif ($target eq 'meta') {
                    501: 	$result=&Apache::response::meta_package_write('numericalhint');
                    502:     }
1.29      albertel  503:     return $result;
                    504: }
                    505: 
                    506: sub end_optionhint {
                    507:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    508:     my $result;
1.30      albertel  509:     if ($target eq 'web') {
                    510: 	my ($foilmatch,$conceptmatch)=(-1,-1);
                    511: 	my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
                    512: 	my $partid=$Apache::inputtags::part;
                    513: 	#id submissions occured under
1.60      albertel  514: 	my $submitid=$Apache::inputtags::response[-1];
1.30      albertel  515: 	my $part_id="$partid.$submitid";
                    516: 	my %answer;
                    517: 	my $answer=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
                    518: 	if ($answer) {
                    519: 	    eval('%answer ='.$answer);
1.62      albertel  520: 	    &Apache::lonxml::debug("answwer hash");
1.30      albertel  521: 	    &Apache::lonhomework::showhash(%answer);
                    522: 	    my $response = $Apache::lonhomework::history{
                    523: 				            "resource.$part_id.submission"};
                    524: 	    my %response=&Apache::lonnet::str2hash($response);
                    525: 	    &Apache::lonhomework::showhash(%response);
                    526: 	    foreach my $foil (keys(%answer)) {
                    527: 		$foilmatch=1;
                    528: 		if ($answer{$foil} ne $response{$foil}) {$foilmatch=0;last;}
                    529: 	    }
                    530: 	}
                    531: 	my %concept;
                    532: 	my $constr=&Apache::lonxml::get_param('concept',$parstack,$safeeval);
                    533: 	if ( $constr ) { eval('%concept ='.$constr);	}
                    534: 	my $response = $Apache::lonhomework::history{
                    535: 					"resource.$part_id.submissiongrading"};
                    536: 	my %response=&Apache::lonnet::str2hash($response);
                    537: 	foreach my $concept (keys(%concept)) {
                    538: 	    my $compare;
                    539: 	    if ($concept{$concept} eq 'correct') {$compare=1}else{$compare=0}
                    540: 	    $conceptmatch=1;
                    541: 	    if (ref($Apache::hint::option{"$part_id.concepts"})) {
                    542: 		foreach my $foil (@{ $Apache::hint::option{"$part_id.concept.$concept"} }) {
                    543: 		    &Apache::lonxml::debug("compare -$foil- -$response{$foil}-$compare-");
                    544: 		    if ( exists($response{$foil}) && 
                    545: 			 $response{$foil} ne $compare) {$conceptmatch=0;last;}
                    546: 		}
                    547: 	    } else {
                    548: 		$conceptmatch=0;
                    549: 	    }
                    550: 	    if ($conceptmatch eq '0') { last; }
                    551: 	}
                    552: 	if ( ($conceptmatch eq '-1' || $conceptmatch eq '1') &&
                    553: 	     ($foilmatch    eq '-1' || $foilmatch    eq '1') ) {
                    554: 	    push(@Apache::hint::which,$name);
                    555: 	}
1.62      albertel  556:     } elsif ($target eq 'edit') {
                    557: 	$result.=&Apache::edit::end_row().&Apache::edit::end_table();
                    558:     }
1.30      albertel  559:     &Apache::response::end_hintresponse();
1.29      albertel  560:     return $result;
                    561: }
                    562: 
                    563: sub start_radiobuttonhint {
                    564:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    565:     my $result;
                    566:     &Apache::response::start_hintresponse($parstack,$safeeval);
                    567:     if ($target eq 'edit') {
                    568: 	$result.=&Apache::edit::tag_start($target,$token);
                    569: 	$result.=&Apache::edit::text_arg('Name:','name',$token);
                    570: 	$result.=&Apache::edit::text_arg('Answer:','answer',$token);
                    571:     } elsif ($target eq 'modified') {
                    572: 	my $constructtag=&Apache::edit::get_new_args($token,$parstack,
                    573: 						     $safeeval,'name',
                    574: 						     'answer');
                    575: 	if ($constructtag) {
                    576: 	    $result  = &Apache::edit::rebuild_tag($token);
                    577: 	    $result .= &Apache::edit::handle_insert();
                    578: 	}
                    579:     } elsif ($target eq 'meta') {
                    580: 	$result=&Apache::response::meta_package_write('numericalhint');
                    581:     }
                    582:     return $result;
1.1       albertel  583: }
                    584: 
1.31      albertel  585: sub end_radiobuttonhint {
1.29      albertel  586:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    587:     my $result;
                    588:     if ($target eq 'web') {
                    589: 	my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
                    590: 	my @answer;
                    591: 	my $answer=&Apache::lonxml::get_param('answer',$parstack,$safeeval);
                    592: 	eval('@answer ='.$answer);
                    593: 	my $partid=$Apache::inputtags::part;
                    594: 	#id submissions occured under
1.60      albertel  595: 	my $submitid=$Apache::inputtags::response[-1];
1.29      albertel  596: 	my $part_id="$partid.$submitid";
                    597: 	my $response = $Apache::lonhomework::history{
                    598: 			    "resource.$part_id.submission"};
                    599: 	($response)=&Apache::lonnet::str2hash($response);
1.42      albertel  600: 	&Apache::lonxml::debug("response is $response");
                    601: 	
                    602: 	if ($answer[0] eq 'foil') {
                    603: 	    shift(@answer);
                    604: 	    foreach my $answer (@answer) {
                    605: 		if ($response eq $answer) {
                    606: 		    push (@Apache::hint::which,$name);
                    607: 		    last;
                    608: 		}
                    609: 	    }
1.29      albertel  610: 	} elsif ($answer[0] eq 'concept') {
1.42      albertel  611: 	    shift(@answer);
                    612: 	    foreach my $answer (@answer) {
                    613: 		if (ref($Apache::hint::radiobutton{"$part_id.concept.".$answer})) {
                    614: 		    my @names=@{ $Apache::hint::radiobutton{"$part_id.concept.".$answer} };
                    615: 		    if (grep(/^\Q$response\E$/,@names)) {
                    616: 			push(@Apache::hint::which,$name);
                    617: 			last;
                    618: 		    }
1.29      albertel  619: 		}
                    620: 	    }
                    621: 	}
1.62      albertel  622:     } elsif ($target eq 'edit') {
                    623: 	$result.=&Apache::edit::end_row().&Apache::edit::end_table();
                    624:     }
1.29      albertel  625:     &Apache::response::end_hintresponse();
                    626:     return $result;
                    627: }
1.1       albertel  628: 1;
                    629: __END__

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