File:  [LON-CAPA] / loncom / homework / hint.pm
Revision 1.19: download - view: text, annotated - select for diffs
Fri Oct 5 17:01:05 2001 UTC (22 years, 7 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- bug fix

    1: package Apache::hinttags; 
    2: 
    3: use strict;
    4: use Apache::lonnet;
    5: use capa;
    6: 
    7: sub BEGIN {
    8:   &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart','numericalhint'));
    9: }
   10: 
   11: 
   12: @Apache::hint::which=();
   13: sub start_hintgroup {
   14:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   15:   my $skiptoend='0';
   16:   my $result;
   17:   
   18:   if ($target eq 'web') {
   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:");
   25:     if ( $numtries < $hinttries ) {
   26:       $skiptoend='1';
   27:     } else {
   28:       if ($target eq 'web') {$result='<table bgcolor="#dddddd"><tr><td>';}
   29:     }
   30:   }
   31:   if ($skiptoend) {
   32:     &Apache::lonxml::get_all_text("/hintgroup",$$parser[$#$parser]);
   33:   }
   34:   @Apache::hint::which=();
   35:   return $result;
   36: }
   37: 
   38: sub end_hintgroup {
   39:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   40:   my $result;
   41:   
   42:   if ($target eq 'web') {
   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:");
   49:     if ( $numtries >= $hinttries ) {
   50:       $result='</td></tr></table>';
   51:     }
   52:   }
   53:   @Apache::hint::which=();
   54:   return $result;
   55: }
   56: 
   57: sub start_numericalhint {
   58:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   59:   #do everything in end, so intervening <responseparams> work
   60:   &Apache::response::start_hintresponse($parstack,$safeeval);
   61:   return '';
   62: }
   63: 
   64: sub end_numericalhint {
   65:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   66:   my $result;
   67:   if ($target eq 'web') {
   68:     $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
   69:     my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
   70:     &Apache::response::setup_params('numericalhint');
   71:     my $partid=$Apache::inputtags::part;
   72:     my $id=$Apache::inputtags::response['-1'];
   73:     #id submissions occured under
   74:     my $submitid=$Apache::inputtags::response['-2'];
   75:     my $response = $Apache::lonhomework::history{
   76: 			    "resource.$partid.$submitid.submission"};
   77:     &Apache::lonxml::debug("hintgroup is using $response<br />\n");
   78:     #build safe space expression
   79:     my $expression="&caparesponse_check_list('".$response."','".
   80:       $$parstack[$#$parstack];
   81:     #need to get all possible parms
   82:     foreach my $key (keys(%Apache::inputtags::params)) {
   83:       $expression.= ';my $'. #'
   84: 	$key.'="'.$Apache::inputtags::params{$key}.'"';
   85:     }
   86:     $expression.="');";
   87:     $result = &Apache::run::run($expression,$safeeval);
   88:     &Apache::lonxml::debug("$expression:result:$result:$Apache::lonxml::curdepth");
   89:     my ($awards) = split /:/ , $result;
   90:     my ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
   91:     if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') { push (@Apache::hint::which,$name); }
   92:     $result='';
   93:   } elsif ($target eq 'meta') {
   94:     $result=&Apache::response::meta_package_write('numericalhint');
   95:   }
   96:   &Apache::response::end_hintresponse();
   97:   return $result;
   98: }
   99: 
  100: # a part shows if it is on, if no specific parts are on, then default shows
  101: sub start_hintpart {
  102:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  103: 
  104:   my $show ='0';
  105: 
  106:   if ($target eq 'web') {
  107:     my $on= &Apache::lonxml::get_param('on',$parstack,$safeeval);
  108:     &Apache::lonxml::debug("hintpart sees $on and ,$#Apache::hint::which");
  109:     if ( $on eq 'default' && $#Apache::hint::which == '-1') {
  110:       $show=1;
  111:     } else {
  112:       my $which;
  113:       foreach $which (@Apache::hint::which) { if ($which eq $on) { $show = 1; last } }
  114:     }
  115:     if (!$show) {
  116:       &Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
  117:     }
  118:   } elsif ($target eq 'grade') {
  119:     &Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
  120:   }
  121:   return '';
  122: }
  123: 
  124: sub end_hintpart {
  125:   return '';
  126: }
  127: 
  128: 1;
  129: __END__

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