File:  [LON-CAPA] / loncom / homework / hint.pm
Revision 1.8: download - view: text, annotated - select for diffs
Mon Feb 19 20:32:36 2001 UTC (23 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- <br> -> <br /> cleanup

    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,$parstack,$parser,$safeeval,$style)=@_;
   15:   my $skiptoend='1';
   16:   my $result;
   17:   
   18:   if ($target ne 'meta' || $target ne 'grade') {
   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='0'; 
   27:       if ($target eq 'web') {$result='<table bgcolor="#dddddd"><tr><td>';}
   28:     }	
   29:   }
   30:   if ($skiptoend && $target ne 'meta') {
   31:     &Apache::lonxml::get_all_text("/hintgroup",$$parser[$#$parser]);
   32:   }
   33:   @Apache::hint::which=();
   34:   return $result;
   35: }
   36: 
   37: sub end_hintgroup {
   38:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
   39:   my $result;
   40: 
   41:   if ($target ne 'meta' || $target ne 'grade') {
   42:     my $id=$Apache::inputtags::part;
   43:     my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
   44:     if ( $numtries eq '') { $numtries = 0; }
   45:     my $hinttries=&Apache::lonnet::EXT("resource.$id.hinttries");
   46:     if ( $hinttries eq '') { $hinttries = 1; }
   47:     &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
   48:     if ( $numtries >= $hinttries ) {
   49:       if ($target eq 'web') {$result='</td></tr></table>';}
   50:     }	
   51:   }
   52:   @Apache::hint::which='';
   53:   return $result;
   54: }
   55: 
   56: sub start_numericalhint {
   57:   #do everything in end, so intervening <responseparams> work
   58: }
   59: 
   60: sub end_numericalhint {
   61:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
   62:   my $result;
   63:   if ($target ne 'meta' && $target ne 'grade') {
   64:     my $args ='';
   65:     $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
   66:     if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
   67:     my $name = &Apache::run::run("{$args;".'return $name}',$safeeval);
   68:     my $response = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.$Apache::inputtags::response['-1'].submission"};
   69:     &Apache::lonxml::debug("hintgroup is using $response<br />\n");
   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);
   76:     &Apache::lonxml::debug("$expression:result:$result:$Apache::lonxml::curdepth");
   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;
   83: }
   84: 
   85: # a part shows if it is on, if no specific parts are on, then default shows
   86: sub start_hintpart {
   87:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
   88: 
   89:   my $show ='0';
   90: 
   91:   if ($target ne 'meta' && $target ne 'grade') {
   92:     my $args ='';
   93:     if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
   94:     my $on = &Apache::run::run("{$args;".'return $on}',$safeeval);
   95:     if ( $on eq 'default' && $#Apache::hint::which == '-1') {
   96:     } else {
   97:       my $which;
   98:       foreach $which (@Apache::hint::which) { if ($which eq $on) { $show = 1; last } }
   99:     }
  100:     if (!$show) {
  101:       &Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
  102:     }
  103:   } else {
  104:     &Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
  105:   }
  106:   return '';
  107: }
  108: 
  109: sub end_hintpart {
  110: }
  111: 
  112: 1;
  113: __END__

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