File:  [LON-CAPA] / loncom / homework / hint.pm
Revision 1.27: download - view: text, annotated - select for diffs
Wed Mar 6 20:39:15 2002 UTC (22 years, 2 months ago) by sakharuk
Branches: MAIN
CVS tags: version_0_5_1, version_0_5, version_0_4, stable_2002_july, stable_2002_april, STABLE, HEAD
removed hints from printout

    1: # The LearningOnline Network with CAPA 
    2: # implements the tags that control the hints
    3: #
    4: # $Id: hint.pm,v 1.27 2002/03/06 20:39:15 sakharuk Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: package Apache::hinttags; 
   30: 
   31: use strict;
   32: use Apache::lonnet;
   33: use capa;
   34: 
   35: BEGIN {
   36:   &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart','numericalhint'));
   37: }
   38: 
   39: 
   40: @Apache::hint::which=();
   41: sub start_hintgroup {
   42:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   43:   my $skiptoend='0';
   44:   my $result;
   45: 
   46:   if ($target eq 'web') {
   47:     my $id=$Apache::inputtags::part;
   48:     my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
   49:     if ( $numtries eq '') { $numtries = 0; }
   50:     my $hinttries=&Apache::lonnet::EXT("resource.$id.hinttries");
   51:     if ( $hinttries eq '') { $hinttries = 1; }
   52:     &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
   53:     if ( $numtries < $hinttries ) {
   54:       $skiptoend='1';
   55:     } else {
   56:       if ($target eq 'web') {$result='<table bgcolor="#dddddd"><tr><td>';}
   57:     }
   58:     if ($skiptoend) {
   59:       &Apache::lonxml::get_all_text("/hintgroup",$$parser[$#$parser]);
   60:     }
   61:   } elsif ($target eq 'tex') {
   62:     $result .= '\keephidden{'; 
   63:   }
   64:   @Apache::hint::which=();
   65:   return $result;
   66: }
   67: 
   68: sub end_hintgroup {
   69:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   70:   my $result;
   71: 
   72:   if ($target eq 'web') {
   73:     my $id=$Apache::inputtags::part;
   74:     my $numtries=$Apache::lonhomework::history{"resource.$id.tries"};
   75:     if ( $numtries eq '') { $numtries = 0; }
   76:     my $hinttries=&Apache::lonnet::EXT("resource.$id.hinttries");
   77:     if ( $hinttries eq '') { $hinttries = 1; }
   78:     &Apache::lonxml::debug("found :$id:$numtries:$hinttries:");
   79:     if ( $numtries >= $hinttries ) {
   80:       $result='</td></tr></table>';
   81:     }
   82:   } elsif ($target eq 'edit') {
   83:     $result.=&Apache::edit::end_table();
   84:   } elsif ($target eq 'tex') {
   85:     $result .= '}'; 
   86:   }
   87:   @Apache::hint::which=();
   88:   return $result;
   89: }
   90: 
   91: sub start_numericalhint {
   92:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   93:   #do everything in end, so intervening <responseparams> work
   94:   &Apache::response::start_hintresponse($parstack,$safeeval);
   95:   my $result;
   96:   if ($target eq 'edit') {
   97:     $result.=&Apache::edit::tag_start($target,$token);
   98:     $result.=&Apache::edit::text_arg('Name:','name',$token);
   99:     $result.=&Apache::edit::text_arg('Answer:','answer',$token);
  100:     $result.=&Apache::edit::text_arg('Unit:','unit',$token,5);
  101:     $result.=&Apache::edit::text_arg('Format:','format',$token,4);
  102:     $result.=&Apache::edit::end_row();
  103:     $result.=&Apache::edit::start_spanning_row();
  104:   } elsif ($target eq 'modified') {
  105:     my $constructtag=
  106:       &Apache::edit::get_new_args($token,$parstack,$safeeval,
  107: 				  'name','answer','unit', 'format');
  108:     if ($constructtag) {
  109:       $result  = &Apache::edit::rebuild_tag($token);
  110:       $result .= &Apache::edit::handle_insert();
  111:     }
  112:   }
  113:   return $result;
  114: }
  115: 
  116: sub end_numericalhint {
  117:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  118:   my $result;
  119:   if ($target eq 'web') {
  120:     $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
  121:     my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
  122:     &Apache::response::setup_params('numericalhint');
  123:     my $partid=$Apache::inputtags::part;
  124:     my $id=$Apache::inputtags::response['-1'];
  125:     #id submissions occured under
  126:     my $submitid=$Apache::inputtags::response['-2'];
  127:     my $response = $Apache::lonhomework::history{
  128: 			    "resource.$partid.$submitid.submission"};
  129:     &Apache::lonxml::debug("hintgroup is using $response<br />\n");
  130:     #build safe space expression
  131:     my $expression="&caparesponse_check_list('".$response."','".
  132:       $$parstack[$#$parstack];
  133:     #need to get all possible parms
  134:     foreach my $key (keys(%Apache::inputtags::params)) {
  135:       $expression.= ';my $'. #'
  136: 	$key.'="'.$Apache::inputtags::params{$key}.'"';
  137:     }
  138:     $expression.="');";
  139:     $result = &Apache::run::run($expression,$safeeval);
  140:     &Apache::lonxml::debug("$expression:result:$result:$Apache::lonxml::curdepth");
  141:     my ($awards) = split /:/ , $result;
  142:     my ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
  143:     if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') { push (@Apache::hint::which,$name); }
  144:     $result='';
  145:   } elsif ($target eq 'meta') {
  146:     $result=&Apache::response::meta_package_write('numericalhint');
  147:   } elsif ($target eq 'edit') {
  148:     $result.='</td></tr>'.&Apache::edit::end_table;
  149:   }
  150:   &Apache::response::end_hintresponse();
  151:   return $result;
  152: }
  153: 
  154: # a part shows if it is on, if no specific parts are on, then default shows
  155: sub start_hintpart {
  156:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
  157: 
  158:   my $show ='0';
  159:   my $result = '';
  160:   if ($target eq 'web') {
  161:     my $on= &Apache::lonxml::get_param('on',$parstack,$safeeval);
  162:     &Apache::lonxml::debug("hintpart sees $on and ,$#Apache::hint::which");
  163:     if ( $on eq 'default' && $#Apache::hint::which == '-1') {
  164:       $show=1;
  165:     } else {
  166:       my $which;
  167:       foreach $which (@Apache::hint::which) { if ($which eq $on) { $show = 1; last } }
  168:     }
  169:     if (!$show) {
  170:       &Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
  171:     }
  172:   } elsif ($target eq 'grade') {
  173:     &Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
  174:   } elsif ($target eq 'edit') {
  175:     $result.= &Apache::edit::tag_start($target,$token);
  176:     $result.= &Apache::edit::text_arg('On:','on',$token);
  177:     $result.= &Apache::edit::end_row();
  178:     $result.= &Apache::edit::start_spanning_row();
  179:   } elsif ($target eq 'modified') {
  180:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
  181: 						 'on');
  182:     if ($constructtag) {
  183:       $result = &Apache::edit::rebuild_tag($token);
  184:       $result.=&Apache::edit::handle_insert();
  185:     }
  186:   }
  187:   return $result;
  188: }
  189: 
  190: sub end_hintpart {
  191:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
  192:   my $result;
  193:   if ($target eq 'edit') { $result.=&Apache::edit::end_table; }
  194:   return $result;
  195: }
  196: 
  197: 1;
  198: __END__

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