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

1.14    ! harris41    1: # The LON-CAPA hint handler.
        !             2: #
        !             3: # Handles the displaying of hints.
        !             4: #
        !             5: # YEAR=2000
        !             6: # 12/19,12/21 Guy Albertelli
        !             7: # YEAR=2001
        !             8: # 1/4,1/5,1/22,2/7,2/19,3/31,4/5,4/10,5/31,6/2 Guy Albertelli
        !             9: # 8/6 Scott Harrison
        !            10: 
1.1       albertel   11: package Apache::hinttags; 
                     12: 
                     13: use strict;
                     14: use Apache::lonnet;
1.6       albertel   15: use capa;
1.1       albertel   16: 
1.14    ! harris41   17: # ======================================================================= BEGIN
1.1       albertel   18: sub BEGIN {
1.14    ! harris41   19:   &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart',
        !            20: 						'numericalhint'));
1.1       albertel   21: }
                     22: 
1.14    ! harris41   23: @Apache::hint::which = ();
1.2       albertel   24: 
1.14    ! harris41   25: # ============================================================ Start hint group
1.1       albertel   26: sub start_hintgroup {
1.14    ! harris41   27:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
        !            28:     my $skiptoend = '0';
        !            29:     my $result;
        !            30:     if ($target eq 'web') {
        !            31: 	my $id = $Apache::inputtags::part;
        !            32: 	my $numtries = $Apache::lonhomework::history{"resource.$id.tries"};
        !            33: 	if ( $numtries eq '') { $numtries = 0; }
        !            34: 	my $hinttries = &Apache::lonnet::EXT("resource.$id.hinttries");
        !            35: 	if ( $hinttries eq '') { $hinttries = 1; }
        !            36: 	&Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
        !            37: 	if ( $numtries < $hinttries ) {
        !            38: 	    $skiptoend = '1';
        !            39: 	} else {
        !            40: 	    if ($target eq 'web') {
        !            41: 		$result = '<table bgcolor="#dddddd"><tr><td>';
        !            42: 	    }
        !            43: 	}
        !            44:     }
        !            45:     if ($skiptoend) {
        !            46: 	&Apache::lonxml::get_all_text("/hintgroup",$$parser[$#$parser]);
1.9       albertel   47:     }
1.14    ! harris41   48:     @Apache::hint::which = ();
        !            49:     return $result;
1.1       albertel   50: }
                     51: 
1.14    ! harris41   52: # ============================================================== End hint group
1.1       albertel   53: sub end_hintgroup {
1.14    ! harris41   54:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
        !            55:     my $result;
        !            56:     if ($target eq 'web') {
        !            57: 	my $id = $Apache::inputtags::part;
        !            58: 	my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
        !            59: 	if ( $numtries eq '') { $numtries = 0; }
        !            60: 	my $hinttries=&Apache::lonnet::EXT("resource.$id.hinttries");
        !            61: 	if ( $hinttries eq '') { $hinttries = 1; }
        !            62: 	&Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
        !            63: 	if ( $numtries => $hinttries ) {
        !            64: 	    if ($target eq 'web') {$result = '</td></tr></table>';}
        !            65: 	}	
        !            66:     }
        !            67:     @Apache::hint::which = '';
        !            68:     return $result;
1.3       albertel   69: }
                     70: 
1.14    ! harris41   71: # ======================================================== Start numerical hint
1.3       albertel   72: sub start_numericalhint {
1.14    ! harris41   73:     #do everything in end, so intervening <responseparams> work
        !            74:     return '';
1.3       albertel   75: }
                     76: 
1.14    ! harris41   77: # ========================================================== End numerical hint
1.3       albertel   78: sub end_numericalhint {
1.14    ! harris41   79:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
        !            80:     my $result;
        !            81:     if ($target eq 'web') {
        !            82: 	$safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
        !            83: 	my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
        !            84: 	my $response = $Apache::lonhomework::history{'resource.'.
        !            85: 		       $Apache::inputtags::part.'.'.
        !            86: 		       $Apache::inputtags::response['-1'].'.submission'};
        !            87: 	&Apache::lonxml::debug("hintgroup is using $response<br />\n");
        !            88: 	my $expression = "&caparesponse_check_list('".$response."','".
        !            89:   	                 $$parstack[$#$parstack].
        !            90: 	                 ';my $tol="'.$Apache::inputtags::params{'tol'}.'"'.
        !            91: 	                 ';my $sig="'.$Apache::inputtags::params{'sig'}.'"'.
        !            92: 		         "');";
        !            93: 	$result = &Apache::run::run($expression,$safeeval);
        !            94: 	&Apache::lonxml::debug("$expression:result:$result:".
        !            95: 			       $Apache::lonxml::curdepth);
        !            96: 	my ($awards) = split /:/, $result;
        !            97: 	my ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
        !            98: 	if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') {
        !            99: 	    push (@Apache::hint::which,$name); }
        !           100: 	$result = '';
        !           101:     }
        !           102:     return $result;
1.1       albertel  103: }
                    104: 
1.14    ! harris41  105: # ======================================================= Starting part of hint
1.2       albertel  106: # a part shows if it is on, if no specific parts are on, then default shows
1.1       albertel  107: sub start_hintpart {
1.14    ! harris41  108:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
        !           109:     my $show ='0';
        !           110:     if ($target eq 'web') {
        !           111: 	my $on= &Apache::lonxml::get_param('on',$parstack,$safeeval);
        !           112: 	&Apache::lonxml::debug("hintpart sees $on and ,$#Apache::hint::which");
        !           113: 	if ( $on eq 'default' && $#Apache::hint::which == '-1') {
        !           114: 	    $show=1;
        !           115: 	} else {
        !           116: 	    my $which;
        !           117: 	    foreach $which (@Apache::hint::which) {
        !           118: 		if ($which eq $on) { $show = 1; last } }
        !           119: 	}
        !           120: 	if (!$show) {
        !           121: 	    &Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
        !           122: 	}
        !           123:     } elsif ($target eq 'grade') {
        !           124: 	&Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
1.1       albertel  125:     }
1.14    ! harris41  126:     return '';
1.1       albertel  127: }
                    128: 
1.14    ! harris41  129: # ========================================================= Ending part of hint
1.1       albertel  130: sub end_hintpart {
1.11      albertel  131:   return '';
1.1       albertel  132: }
                    133: 
                    134: 1;
1.14    ! harris41  135: 
1.1       albertel  136: __END__

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