File:  [LON-CAPA] / loncom / homework / hint.pm
Revision 1.20: download - view: text, annotated - select for diffs
Tue Oct 9 20:45:13 2001 UTC (22 years, 7 months ago) by albertel
Branches: MAIN
CVS tags: stable_2001_fall, HEAD
- made <numericalhint> and <hintpart> fully insertable and editable.

    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:     if ($skiptoend) {
   31:       &Apache::lonxml::get_all_text("/hintgroup",$$parser[$#$parser]);
   32:     }
   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:   } elsif ($target eq 'edit') {
   53:     $result.=&Apache::edit::end_table();
   54:   }
   55:   @Apache::hint::which=();
   56:   return $result;
   57: }
   58: 
   59: sub start_numericalhint {
   60:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   61:   #do everything in end, so intervening <responseparams> work
   62:   &Apache::response::start_hintresponse($parstack,$safeeval);
   63:   my $result;
   64:   if ($target eq 'edit') {
   65:     $result.=&Apache::edit::tag_start($target,$token);
   66:     $result.=&Apache::edit::text_arg('Name:','name',$token);
   67:     $result.=&Apache::edit::text_arg('Answer:','answer',$token);
   68:     $result.=&Apache::edit::text_arg('Unit:','unit',$token,5);
   69:     $result.=&Apache::edit::text_arg('Format:','format',$token,4);
   70:     $result.='</td></tr><tr><td colspan="3">';
   71:   } elsif ($target eq 'modified') {
   72:     my $constructtag=
   73:       &Apache::edit::get_new_args($token,$parstack,$safeeval,
   74: 				  'name','answer','unit', 'format');
   75:     if ($constructtag) {
   76:       $result  = &Apache::edit::rebuild_tag($token);
   77:       $result .= &Apache::edit::handle_insert();
   78:     }
   79:   }
   80:   return $result;
   81: }
   82: 
   83: sub end_numericalhint {
   84:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   85:   my $result;
   86:   if ($target eq 'web') {
   87:     $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
   88:     my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
   89:     &Apache::response::setup_params('numericalhint');
   90:     my $partid=$Apache::inputtags::part;
   91:     my $id=$Apache::inputtags::response['-1'];
   92:     #id submissions occured under
   93:     my $submitid=$Apache::inputtags::response['-2'];
   94:     my $response = $Apache::lonhomework::history{
   95: 			    "resource.$partid.$submitid.submission"};
   96:     &Apache::lonxml::debug("hintgroup is using $response<br />\n");
   97:     #build safe space expression
   98:     my $expression="&caparesponse_check_list('".$response."','".
   99:       $$parstack[$#$parstack];
  100:     #need to get all possible parms
  101:     foreach my $key (keys(%Apache::inputtags::params)) {
  102:       $expression.= ';my $'. #'
  103: 	$key.'="'.$Apache::inputtags::params{$key}.'"';
  104:     }
  105:     $expression.="');";
  106:     $result = &Apache::run::run($expression,$safeeval);
  107:     &Apache::lonxml::debug("$expression:result:$result:$Apache::lonxml::curdepth");
  108:     my ($awards) = split /:/ , $result;
  109:     my ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
  110:     if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') { push (@Apache::hint::which,$name); }
  111:     $result='';
  112:   } elsif ($target eq 'meta') {
  113:     $result=&Apache::response::meta_package_write('numericalhint');
  114:   } elsif ($target eq 'edit') {
  115:     $result.='</td></tr>'.&Apache::edit::end_table;
  116:   }
  117:   &Apache::response::end_hintresponse();
  118:   return $result;
  119: }
  120: 
  121: # a part shows if it is on, if no specific parts are on, then default shows
  122: sub start_hintpart {
  123:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  124: 
  125:   my $show ='0';
  126:   my $result = '';
  127:   if ($target eq 'web') {
  128:     my $on= &Apache::lonxml::get_param('on',$parstack,$safeeval);
  129:     &Apache::lonxml::debug("hintpart sees $on and ,$#Apache::hint::which");
  130:     if ( $on eq 'default' && $#Apache::hint::which == '-1') {
  131:       $show=1;
  132:     } else {
  133:       my $which;
  134:       foreach $which (@Apache::hint::which) { if ($which eq $on) { $show = 1; last } }
  135:     }
  136:     if (!$show) {
  137:       &Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
  138:     }
  139:   } elsif ($target eq 'grade') {
  140:     &Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
  141:   } elsif ($target eq 'edit') {
  142:     $result.= &Apache::edit::tag_start($target,$token,
  143: 				       &Apache::lonxml::description($token));
  144:     $result.= &Apache::edit::text_arg('On:','on',$token).'</td></tr><tr><td colspan="3">';
  145:   } elsif ($target eq 'modified') {
  146:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
  147: 						 'on');
  148:     if ($constructtag) {
  149:       $result = &Apache::edit::rebuild_tag($token);
  150:       $result.=&Apache::edit::handle_insert();
  151:     }
  152:   }
  153:   return $result;
  154: }
  155: 
  156: sub end_hintpart {
  157:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  158:   my $result;
  159:   if ($target eq 'edit') { $result.=&Apache::edit::end_table; }
  160:   return $result;
  161: }
  162: 
  163: 1;
  164: __END__

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