File:  [LON-CAPA] / loncom / homework / hint.pm
Revision 1.5: download - view: text, annotated - select for diffs
Mon Jan 22 16:42:01 2001 UTC (23 years, 3 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- need to look for /hinpart not /problem

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

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