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

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

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