Annotation of loncom/homework/hint.pm, revision 1.28

1.21      albertel    1: # The LearningOnline Network with CAPA 
                      2: # implements the tags that control the hints
                      3: #
1.28    ! albertel    4: # $Id: hint.pm,v 1.27 2002/03/06 20:39:15 sakharuk Exp $
1.21      albertel    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: 
1.1       albertel   29: package Apache::hinttags; 
                     30: 
                     31: use strict;
                     32: use Apache::lonnet;
1.6       albertel   33: use capa;
1.1       albertel   34: 
1.25      harris41   35: BEGIN {
1.28    ! albertel   36:   &Apache::lonxml::register('Apache::hinttags',('hintgroup','hintpart','numericalhint','stringhint','formulahint'));
1.1       albertel   37: }
                     38: 
1.2       albertel   39: 
1.15      albertel   40: @Apache::hint::which=();
1.1       albertel   41: sub start_hintgroup {
1.15      albertel   42:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     43:   my $skiptoend='0';
                     44:   my $result;
1.20      albertel   45: 
1.15      albertel   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>';}
1.9       albertel   57:     }
1.20      albertel   58:     if ($skiptoend) {
                     59:       &Apache::lonxml::get_all_text("/hintgroup",$$parser[$#$parser]);
                     60:     }
1.24      sakharuk   61:   } elsif ($target eq 'tex') {
1.27      sakharuk   62:     $result .= '\keephidden{'; 
1.15      albertel   63:   }
                     64:   @Apache::hint::which=();
                     65:   return $result;
1.1       albertel   66: }
                     67: 
                     68: sub end_hintgroup {
1.15      albertel   69:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     70:   my $result;
1.20      albertel   71: 
1.15      albertel   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:");
1.19      albertel   79:     if ( $numtries >= $hinttries ) {
                     80:       $result='</td></tr></table>';
                     81:     }
1.20      albertel   82:   } elsif ($target eq 'edit') {
                     83:     $result.=&Apache::edit::end_table();
1.27      sakharuk   84:   } elsif ($target eq 'tex') {
                     85:     $result .= '}'; 
1.15      albertel   86:   }
1.19      albertel   87:   @Apache::hint::which=();
1.15      albertel   88:   return $result;
1.3       albertel   89: }
                     90: 
                     91: sub start_numericalhint {
1.16      albertel   92:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.15      albertel   93:   #do everything in end, so intervening <responseparams> work
1.16      albertel   94:   &Apache::response::start_hintresponse($parstack,$safeeval);
1.20      albertel   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);
1.28    ! albertel  100:     if ($token->[1] eq 'numericalhint') {
        !           101:       $result.=&Apache::edit::text_arg('Unit:','unit',$token,5);
        !           102:       $result.=&Apache::edit::text_arg('Format:','format',$token,4);
        !           103:     } elsif ($token->[1] eq 'stringhint') {
        !           104:       $result.=&Apache::edit::select_arg('Type:','type',['cs','ci','mc'],$token);
        !           105:     } elsif ($token->[1] eq 'formulahint') {
        !           106:       $result.=&Apache::edit::text_arg('Sample Points:','samples',$token,40);
        !           107:     }
1.26      albertel  108:     $result.=&Apache::edit::end_row();
                    109:     $result.=&Apache::edit::start_spanning_row();
1.20      albertel  110:   } elsif ($target eq 'modified') {
1.28    ! albertel  111:     my $constructtag;
        !           112:     if ($token->[1] eq 'numericalhint') {
        !           113:       $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
        !           114: 						'name','answer','unit','format');
        !           115:     } elsif ($token->[1] eq 'stringhint') {
        !           116:       $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
        !           117: 						'name','answer','type');
        !           118:     } elsif ($token->[1] eq 'formulahint') {
        !           119:       $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
        !           120: 						'name','answer','samples');
        !           121:     }
1.20      albertel  122:     if ($constructtag) {
                    123:       $result  = &Apache::edit::rebuild_tag($token);
                    124:       $result .= &Apache::edit::handle_insert();
                    125:     }
                    126:   }
                    127:   return $result;
1.3       albertel  128: }
                    129: 
                    130: sub end_numericalhint {
1.15      albertel  131:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    132:   my $result;
                    133:   if ($target eq 'web') {
                    134:     $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
                    135:     my $name= &Apache::lonxml::get_param('name',$parstack,$safeeval);
1.18      albertel  136:     &Apache::response::setup_params('numericalhint');
                    137:     my $partid=$Apache::inputtags::part;
                    138:     my $id=$Apache::inputtags::response['-1'];
                    139:     #id submissions occured under
                    140:     my $submitid=$Apache::inputtags::response['-2'];
                    141:     my $response = $Apache::lonhomework::history{
                    142: 			    "resource.$partid.$submitid.submission"};
1.15      albertel  143:     &Apache::lonxml::debug("hintgroup is using $response<br />\n");
1.18      albertel  144:     #build safe space expression
1.15      albertel  145:     my $expression="&caparesponse_check_list('".$response."','".
1.18      albertel  146:       $$parstack[$#$parstack];
                    147:     #need to get all possible parms
                    148:     foreach my $key (keys(%Apache::inputtags::params)) {
                    149:       $expression.= ';my $'. #'
                    150: 	$key.'="'.$Apache::inputtags::params{$key}.'"';
                    151:     }
                    152:     $expression.="');";
1.15      albertel  153:     $result = &Apache::run::run($expression,$safeeval);
                    154:     &Apache::lonxml::debug("$expression:result:$result:$Apache::lonxml::curdepth");
                    155:     my ($awards) = split /:/ , $result;
                    156:     my ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
                    157:     if ($ad eq 'EXACT_ANS' || $ad eq 'APPROX_ANS') { push (@Apache::hint::which,$name); }
                    158:     $result='';
1.17      albertel  159:   } elsif ($target eq 'meta') {
                    160:     $result=&Apache::response::meta_package_write('numericalhint');
1.20      albertel  161:   } elsif ($target eq 'edit') {
                    162:     $result.='</td></tr>'.&Apache::edit::end_table;
1.15      albertel  163:   }
1.16      albertel  164:   &Apache::response::end_hintresponse();
1.15      albertel  165:   return $result;
1.28    ! albertel  166: }
        !           167: 
        !           168: sub start_stringhint {
        !           169:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
        !           170:   my $result;
        !           171:   if ($target eq 'meta') {
        !           172:     $result=&Apache::response::meta_package_write('stringhint');
        !           173:   } else {
        !           174:     $result.=&start_numericalhint(@_);
        !           175:   }
        !           176:   return $result;
        !           177: }
        !           178: 
        !           179: sub end_stringhint {
        !           180:   return end_numericalhint(@_);
        !           181: }
        !           182: 
        !           183: sub start_formulahint {
        !           184:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
        !           185:   my $result;
        !           186:   if ($target eq 'meta') {
        !           187:     $result=&Apache::response::meta_package_write('formulahint');
        !           188:   } else {
        !           189:     $result.=&start_numericalhint(@_);
        !           190:   }
        !           191:   return $result;
        !           192: }
        !           193: 
        !           194: sub end_formulahint {
        !           195:   return end_numericalhint(@_);
1.1       albertel  196: }
                    197: 
1.2       albertel  198: # a part shows if it is on, if no specific parts are on, then default shows
1.1       albertel  199: sub start_hintpart {
1.15      albertel  200:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    201: 
                    202:   my $show ='0';
1.20      albertel  203:   my $result = '';
1.15      albertel  204:   if ($target eq 'web') {
                    205:     my $on= &Apache::lonxml::get_param('on',$parstack,$safeeval);
                    206:     &Apache::lonxml::debug("hintpart sees $on and ,$#Apache::hint::which");
                    207:     if ( $on eq 'default' && $#Apache::hint::which == '-1') {
                    208:       $show=1;
                    209:     } else {
                    210:       my $which;
                    211:       foreach $which (@Apache::hint::which) { if ($which eq $on) { $show = 1; last } }
                    212:     }
                    213:     if (!$show) {
                    214:       &Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
1.1       albertel  215:     }
1.15      albertel  216:   } elsif ($target eq 'grade') {
                    217:     &Apache::lonxml::get_all_text("/hintpart",$$parser[$#$parser]);
1.20      albertel  218:   } elsif ($target eq 'edit') {
1.26      albertel  219:     $result.= &Apache::edit::tag_start($target,$token);
                    220:     $result.= &Apache::edit::text_arg('On:','on',$token);
                    221:     $result.= &Apache::edit::end_row();
                    222:     $result.= &Apache::edit::start_spanning_row();
1.20      albertel  223:   } elsif ($target eq 'modified') {
                    224:     my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
                    225: 						 'on');
                    226:     if ($constructtag) {
                    227:       $result = &Apache::edit::rebuild_tag($token);
                    228:       $result.=&Apache::edit::handle_insert();
                    229:     }
1.15      albertel  230:   }
1.20      albertel  231:   return $result;
1.1       albertel  232: }
                    233: 
                    234: sub end_hintpart {
1.20      albertel  235:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
                    236:   my $result;
                    237:   if ($target eq 'edit') { $result.=&Apache::edit::end_table; }
                    238:   return $result;
1.1       albertel  239: }
                    240: 
                    241: 1;
                    242: __END__

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