Annotation of loncom/homework/caparesponse/caparesponse.pm, revision 1.72

1.3       albertel    1: # The LearningOnline Network with CAPA
                      2: # caparesponse definition
1.47      albertel    3: #
1.72    ! albertel    4: # $Id: caparesponse.pm,v 1.71 2002/11/08 20:36:27 sakharuk Exp $
1.47      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: #
1.3       albertel   28: 
                     29: package Apache::caparesponse;
                     30: use strict;
1.4       albertel   31: use capa;
1.3       albertel   32: 
1.50      harris41   33: BEGIN {
1.44      albertel   34:   &Apache::lonxml::register('Apache::caparesponse',('caparesponse','numericalresponse','stringresponse','formularesponse'));
1.3       albertel   35: }
                     36: 
                     37: sub start_caparesponse {
1.31      albertel   38:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.19      albertel   39:   my $id = &Apache::response::start_response($parstack,$safeeval);
1.13      albertel   40:   return '';
1.3       albertel   41: }
                     42: 
                     43: sub end_caparesponse {
1.31      albertel   44:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.12      albertel   45:   my $result = '';
1.16      albertel   46:   if ( $target eq 'grade' ) {
1.27      albertel   47:     if ( defined $ENV{'form.submitted'}) {
1.16      albertel   48:       $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
1.19      albertel   49:       my $response = $ENV{'form.HWVAL'.$Apache::inputtags::response['-1']};
1.18      albertel   50:       if ( $response =~ /[^\s]/) {
1.23      albertel   51: 	my $id = $Apache::inputtags::response['-1'];
                     52: 	my $previous= &Apache::response::check_for_previous($response,$id,$response);
1.22      albertel   53: 	if ( $previous ) { 
                     54: 	  $result = 'PREVIOUSLY_USED';
                     55: 	} else {
1.26      albertel   56: 	  $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.submission"}=$response;
1.22      albertel   57: 	  &Apache::lonxml::debug("submitted a $response<br>\n");
                     58: 	  &Apache::lonxml::debug($$parstack[$#$parstack] . "\n<br>");
                     59: 	  my $expression="&caparesponse_check('".$response."','".
                     60: 	    $$parstack[$#$parstack].
                     61: 	      ';my $tol="'.$Apache::inputtags::params{'tol'}.'"'.
                     62: 		';my $sig="'.$Apache::inputtags::params{'sig'}.'"'.
                     63: 		  "');";
                     64: 	  $result = &Apache::run::run($expression,$safeeval);
                     65: 	  my ($ad) = split /:/ , $result;
1.26      albertel   66: 	  $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}=$ad;
1.22      albertel   67: 	  &Apache::lonxml::debug("$expression");
                     68: 	  &Apache::lonxml::debug("\n<br>result:$result:$Apache::lonxml::curdepth<br>\n");
                     69: 	}
1.18      albertel   70:       }
1.16      albertel   71:     }
1.30      albertel   72:   } elsif ($target eq 'web') {
1.17      albertel   73:     #$result .= "The correct answer is ".&Apache::run::run("{$$parstack['-1'];".'return $answer}',$safeeval)."\n";
1.7       albertel   74:   }
                     75:   #Apache::lonxml::debug("\n<br>\nreal end caparesponse<br>\n");
1.19      albertel   76:   &Apache::response::end_response;
1.24      albertel   77:   return '';
1.21      albertel   78: }
                     79: 
                     80: sub start_numericalresponse {
1.31      albertel   81:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1.22      albertel   82:   my $id = &Apache::response::start_response($parstack,$safeeval);
1.32      albertel   83:   my $result;
                     84:   if ($target eq 'edit') {
1.49      matthew    85:     $result.=&Apache::edit::tag_start($target,$token);
1.34      albertel   86:     $result.=&Apache::edit::text_arg('Answer:','answer',$token);
                     87:     if ($token->[1] eq 'numericalresponse') {
1.36      albertel   88:       $result.=&Apache::edit::text_arg('Unit:','unit',$token,5);
                     89:       $result.=&Apache::edit::text_arg('Format:','format',$token,4);
1.44      albertel   90:     } elsif ($token->[1] eq 'stringresponse') {
1.35      albertel   91:       $result.=&Apache::edit::select_arg('Type:','type',
1.70      albertel   92: 		 [['cs','Case Sensitive'],['ci','Case Insensitive'],
                     93: 		  ['mc','Case Insensitive, Any Order']],$token);
1.44      albertel   94:     } elsif ($token->[1] eq 'formularesponse') {
1.45      albertel   95:       $result.=&Apache::edit::text_arg('Sample Points:','samples',$token,40);
1.34      albertel   96:     }
1.49      matthew    97:     $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
1.32      albertel   98:   } elsif ($target eq 'modified') {
1.34      albertel   99:     my $constructtag;
                    100:     if ($token->[1] eq 'numericalresponse') {
                    101:       $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
1.36      albertel  102: 						'answer','unit','format');
1.44      albertel  103:     } elsif ($token->[1] eq 'stringresponse') {
1.34      albertel  104:       $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
                    105: 						'answer','type');
1.44      albertel  106:     } elsif ($token->[1] eq 'formularesponse') {
                    107:       $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,
1.45      albertel  108: 						'answer','samples');
1.34      albertel  109:     }
1.33      albertel  110:     if ($constructtag) {
                    111:       $result = &Apache::edit::rebuild_tag($token);
                    112:       $result.=&Apache::edit::handle_insert();
                    113:     }
1.39      albertel  114:   } elsif ($target eq 'meta') {
1.40      albertel  115:     $result=&Apache::response::meta_package_write('numericalresponse');
1.32      albertel  116:   }
                    117:   return $result;
1.21      albertel  118: }
                    119: 
                    120: sub end_numericalresponse {
1.31      albertel  121:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
1.22      albertel  122:   my $result = '';
                    123:   if ( $target eq 'grade' ) {
1.27      albertel  124:     if ( defined $ENV{'form.submitted'}) {
1.45      albertel  125:       &Apache::response::setup_params($$tagstack[-1]);
1.22      albertel  126:       $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
1.38      albertel  127:       my $partid = $Apache::inputtags::part;
                    128:       my $id = $Apache::inputtags::response['-1'];
                    129:       my $response = $ENV{'form.HWVAL'.$id};
1.22      albertel  130:       if ( $response =~ /[^\s]/) {
1.72    ! albertel  131: 	if (!$Apache::lonxml::default_homework_loaded) {
        !           132: 	    &Apache::lonxml::default_homework_load($safeeval);
        !           133: 	}
1.38      albertel  134: 	my %previous = &Apache::response::check_for_previous($response,$partid,$id);
                    135: 	$Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
                    136: 	&Apache::lonxml::debug("submitted a $response<br>\n");
                    137: 	&Apache::lonxml::debug($$parstack[$#$parstack] . "\n<br>");
                    138: 	$response =~ s/\\/\\\\/g;
                    139: 	$response =~ s/\'/\\\'/g;
                    140: 	&Apache::lonxml::debug("current $response");
                    141: 	my $expression="&caparesponse_check_list('".$response."','".
1.41      albertel  142: 	  $$parstack[$#$parstack];
                    143: 	foreach my $key (keys(%Apache::inputtags::params)) {
                    144: 	  $expression.= ';my $'. #'
                    145: 	    $key.'="'.$Apache::inputtags::params{$key}.'"';
                    146: 	}
1.45      albertel  147: 	if ($$tagstack[-1] eq 'formularesponse') {
1.46      albertel  148: 	  $expression.=';my $type="fml";';
                    149: 	} elsif ($$tagstack[-1] eq 'numericalresponse') {
                    150: 	  $expression.=';my $type="float";';
1.45      albertel  151: 	}
1.41      albertel  152: 	$expression.="');";
1.38      albertel  153: 	$result = &Apache::run::run($expression,$safeeval);
                    154: 	my ($awards) = split /:/ , $result;
                    155: 	my ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
1.48      albertel  156: 	&Apache::response::handle_previous(\%previous,$ad);
1.38      albertel  157: 	$Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
                    158: 	&Apache::lonxml::debug("$expression");
                    159: 	&Apache::lonxml::debug("\n<br>result:$result:$Apache::lonxml::curdepth<br>\n");
                    160: 	$result='';
1.22      albertel  161:       }
1.24      albertel  162:     }
1.53      sakharuk  163:   } elsif ($target eq 'web' || $target eq 'tex') {
1.58      sakharuk  164:       my $award = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
                    165:       my $status = $Apache::inputtags::status['-1'];
                    166:       if ($award =~ /^correct/ || $status eq "SHOW_ANSWER" ) {
                    167: 	my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,
                    168: 						     $safeeval);
                    169: 	my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,
                    170: 						     $safeeval);
                    171: 	my $unit=&Apache::lonxml::get_param_var('unit',$parstack,$safeeval);
                    172: 	
                    173: 	if ($target eq 'web') {
1.64      albertel  174: 	  $result="<br />The correct answer is ";
1.58      sakharuk  175:         } elsif ($target eq 'tex') {
1.64      albertel  176: 	  $result='\vskip 0 mm The correct answer is \\texttt{';
1.58      sakharuk  177:         }
                    178: 	for (my $i=0; $i <= $#answers; $i++) {
                    179: 	   my $answer=$answers[$i];
                    180: 	   my $format;
                    181: 	   if ($#formats > 0) {
                    182: 	     $format=$formats[$i];
                    183: 	   } else {
                    184: 	     $format=$formats[0];
                    185: 	   }
                    186: 	   my $formatted;
                    187: 	   if ((defined($format)) && ($format ne '')) {
                    188: 	     &Apache::lonxml::debug("formatting with :$format: answer :$answer:");
                    189: 	     $formatted=sprintf('%.'.$format,$answer).',';
                    190: 	   } else {
                    191: 	     &Apache::lonxml::debug("no format answer :$answer:");
                    192: 	     $formatted="$answer,";
                    193: 	   }
                    194: 	   if ($target eq 'tex') {$formatted=&Apache::lonxml::latex_special_symbols($formatted);}
                    195: 	     $result.=$formatted;
                    196:            }
                    197: 	   chop $result;
                    198: 	   if ($target eq 'web') {
                    199: 	     $result.=" $unit.<br />";
                    200: 	   } elsif ($target eq 'tex') {
                    201: 	     $result.=&Apache::lonxml::latex_special_symbols($unit);
                    202: 	     $result.="}. \\vskip 0 mm ";
                    203: 	   }
                    204:        }
1.69      sakharuk  205:       if ($Apache::lonhomework::type eq 'exam') {
1.58      sakharuk  206:       	my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
                    207: 	my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,$safeeval);
                    208: 	my $unit=&Apache::lonxml::get_param_var('unit',$parstack,$safeeval);
                    209: 	my $number_of_bubbles = 8; #default values for number of bubbles
                    210: 	my @bubbles_values = (); 
                    211: 	my @factors = (1.13,1.17,1.25,1.33,1.45); #default values of factors
                    212: 	my @powers = (1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0); #default values for powers
                    213: 	my $factors_number = 5; #default values for number of factors
                    214: 	my $powers_number = 8; #default values for number of powers
                    215: 	my $symb;
                    216: 	if ($ENV{'form.symb'}=~/___\d+___/) {$symb=$ENV{'form.symb'};} else {$symb=$ENV{'request.symb'};}
                    217: 	my $randomseed = srand(&Apache::lonnet::rndseed($symb,$ENV{'request.course.id'},
                    218:                                                               $ENV{'user.domain'},$ENV{'user.name'}));
                    219: 	my $ind=1+int(rand()*($factors_number-1));
                    220: 	my $factor = $factors[$ind];
                    221: 	$ind=1+int(rand()*($powers_number-1));
                    222: 	my $power = $powers[$ind];
                    223: 	for ($ind=0;$ind<$number_of_bubbles;$ind++) {
                    224: 	    $bubbles_values[$ind] = $answers[0]*$factor**($power-$powers[$powers_number-$ind-1]);
                    225: 	}	    
1.60      sakharuk  226: 	my @alphabet = ('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
                    227: 			'Q','R','S','T','U','V','W','X','Y','Z');
1.58      sakharuk  228:         if ($target eq 'web') {
1.71      sakharuk  229: 	    my $id=$Apache::inputtags::response[-1];
1.58      sakharuk  230: 	    $result.= '<table border="1"><tr>';
                    231: 	    for ($ind=0;$ind<$number_of_bubbles;$ind++) {
1.62      sakharuk  232: 		my $ans;
1.61      sakharuk  233: 		if ($formats[0] ne '') {
1.62      sakharuk  234: 		    $ans = sprintf('%.'.$formats[0],$bubbles_values[$ind]);
1.60      sakharuk  235: 		} else {
1.62      sakharuk  236: 		    my $badans = $bubbles_values[$ind];
                    237: 		    my $format = ''; 
                    238:                     #What is the number? (integer,decimal,floating point)
                    239:                     if ($badans=~/^(\d*\.?\d*)(E|e)(\d*)$/) {
                    240: 			$format = 'e'.$2;
                    241: 		    } elsif ($badans=~/^(\d*)\.(\d*)$/) {
                    242: 			$format = '4f';
                    243: 		    } elsif ($badans=~/^(\d*)$/) {
                    244: 			$format = 'd';
                    245: 		    }
                    246: 		    $ans = sprintf('%.'.$format,$bubbles_values[$ind]);
                    247: 		}
1.71      sakharuk  248: 		    $result.='<td><input type="radio" name="HWVAL'.$id.'" value="'.$ans.'"><b>'.$alphabet[$ind].'</b>: '.$ans.'</td>';
1.60      sakharuk  249: 	    }
1.58      sakharuk  250: 	    $result.='</tr></table>';
                    251: 	} elsif ($target eq 'tex') {
                    252: 	    my $max_val = 0;
                    253: 	    if ($formats[0]=~m/^(\d+)E([^\d]*)(\d*)$/) {
                    254: 		$max_val=$1+$2+4;
1.60      sakharuk  255: 	    } else {
1.66      sakharuk  256: 		$max_val=4;
1.58      sakharuk  257: 	    }
1.66      sakharuk  258: 	    $max_val = int(0.9*$ENV{'form.textwidth'}/(($max_val+6)*2));
                    259:             my $celllength = 0.9*$ENV{'form.textwidth'}/$max_val-10;
1.58      sakharuk  260: 	    my @table_range = ();
                    261: 	    my $number_of_tables = int($number_of_bubbles/$max_val);
                    262: 	    for (my $i=0;$i<$number_of_tables;$i++) {push @table_range,$max_val;}
                    263: 	    if ($number_of_bubbles % $max_val != 0) {
                    264: 		$number_of_tables++;
                    265: 		push @table_range,($number_of_bubbles % $max_val);
                    266: 	    }
                    267: 	    my $j=0;
                    268: 	    my $cou=0;
1.66      sakharuk  269: 	    $result.='\vskip -1 mm \noindent \begin{enumerate}\item[\textbf{'.$Apache::lonxml::counter.'}.]';
1.58      sakharuk  270: 	    for (my $i=0;$i<$number_of_tables;$i++) {
1.66      sakharuk  271: 		$result.='\vskip -1 mm \noindent \begin{tabular}{';
1.58      sakharuk  272: 		for ($ind=0;$ind<$table_range[$j];$ind++) {
1.66      sakharuk  273: 		    $result.='lp{'.$celllength.' mm}';
1.58      sakharuk  274: 		}
1.66      sakharuk  275: 		$result.='}';
1.58      sakharuk  276: 		for ($ind=$cou;$ind<$cou+$table_range[$j];$ind++) {
1.62      sakharuk  277: 		    my $ans;
1.61      sakharuk  278: 		    if ($formats[0] ne '') {
1.62      sakharuk  279: 			$ans = sprintf('%.'.$formats[0],$bubbles_values[$ind]);
1.66      sakharuk  280: 			if ($ans =~ m/([0-9\.\-\+]+)E([0-9\-\+]+)/ ) {
                    281: 			    my $number = $1;
                    282: 			    my $power = $2;
                    283: 			    $power=~s/^\+//;
                    284: 			    $power=~s/^(-?)0+(\d+)//;
1.67      albertel  285: 			    $ans=$number.'$\times 10^{'.$1.$2.'}$'; #'stupidemacs
1.66      sakharuk  286: 			} 
1.60      sakharuk  287: 		    } else {
1.62      sakharuk  288: 			my $badans = $bubbles_values[$ind];
                    289: 			my $format = ''; 
                    290: 			#What is the number? (integer,decimal,floating point)
                    291: 			if ($badans=~/^(\d*\.?\d*)(E|e)(\d*)$/) {
                    292: 			    $format = 'e'.$2;
                    293: 			} elsif ($badans=~/^(\d*)\.(\d*)$/) {
                    294: 			    $format = '4f';
                    295: 			} elsif ($badans=~/^(\d*)$/) {
                    296: 			    $format = 'd';
                    297: 			}
1.66      sakharuk  298: 			$ans = sprintf('%.'.$format,$bubbles_values[$ind]);			
                    299: 			if ($ans =~ m/([0-9\.\-\+]+)E([0-9\-\+]+)/ ) {
                    300: 			    my $number = $1;
                    301: 			    my $power = $2;
                    302: 			    $power=~s/^\+//;
                    303: 			    $power=~s/^(-?)0+(\d+)//;
1.67      albertel  304: 			    $ans=$number.'$\times 10^{'.$1.$2.'}$'; #'stupidemacs
1.66      sakharuk  305: 			} 
1.60      sakharuk  306: 		    }
1.66      sakharuk  307: 		    $result.='\hskip -3 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -2 mm & {\small '.$ans.'} ';
1.58      sakharuk  308: 		    if ($ind != $cou+$table_range[$j]-1) {$result.=' & ';}
                    309: 		}
1.63      sakharuk  310: 		$cou += $table_range[$j];
1.58      sakharuk  311: 		$j++;
1.66      sakharuk  312: 		$result.='\\\\\end{tabular}\vskip 0 mm ';    
                    313: 	    }
                    314: 	    $result.='\end{enumerate}';
1.67      albertel  315: 	    &Apache::lonxml::increment_counter();
1.36      albertel  316: 	}
1.69      sakharuk  317:     }
1.32      albertel  318:   } elsif ($target eq 'edit') {
                    319:     $result.='</td></tr>'.&Apache::edit::end_table;
1.65      albertel  320:   } elsif ($target eq 'answer' || $target eq 'analyze') {
1.44      albertel  321: 
1.65      albertel  322:       my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
                    323:       if ($target eq 'analyze') {
                    324: 	  push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
                    325: 	  $Apache::lonhomework::analyze{"$part_id.type"} = $$tagstack[-1];
                    326:       }
                    327:       &Apache::response::setup_params($$tagstack[-1]);
                    328:       my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
                    329:       my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,$safeeval);
                    330:       my $unit=&Apache::lonxml::get_param_var('unit',$parstack,$safeeval);
                    331:       my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval);
1.44      albertel  332: 
1.65      albertel  333:       if ($target eq 'answer') {
                    334: 	  $result.=&Apache::response::answer_header($$tagstack[-1]);
                    335:       }
                    336:       for(my $i=0;$i<=$#answers;$i++) {
                    337: 	  my $ans=$answers[$i];
                    338: 	  my $fmt;
                    339: 	  if (@formats) {
                    340: 	      if ($#formats) {
                    341: 		  $fmt=$formats[$i];
                    342: 	      } else {
                    343: 		  $fmt=$formats[0];
                    344: 	      }
                    345: 	  }
                    346: 	  my ($high,$low);
                    347: 	  if ($Apache::inputtags::params{'tol'}) {
                    348: 	      ($high,$low)=&get_tolrange($ans,$Apache::inputtags::params{'tol'});
                    349: 	  }
                    350: 	  my ($sighigh,$siglow);
                    351: 	  if ($Apache::inputtags::params{'sig'}) {
                    352: 	      ($sighigh,$siglow)=&get_sigrange($Apache::inputtags::params{'sig'});
                    353: 	  }
                    354: 	  if ($fmt) {
                    355: 	      $ans = sprintf('%.'.$fmt,$ans);
                    356: 	      if ($high) {
                    357: 		  $high = sprintf('%.'.$fmt,$high); $low = sprintf('%.'.$fmt,$low);
                    358: 	      }
                    359: 	  }
                    360: 	  if ($target eq 'answer') {
                    361: 	      if ($high) { $ans.=' ['.$low.','.$high.'] '; }
                    362: 	      if ($sighigh) { $ans.= "Sig <i>$siglow - $sighigh</i>"; }
                    363: 	      $result.=&Apache::response::answer_part($$tagstack[-1],$ans);
                    364: 	  } elsif ($target eq 'analyze') {
                    365: 	      push (@{ $Apache::lonhomework::analyze{"$part_id.answer"} },
                    366: 		    $ans);
                    367: 	      if ($high) {
                    368: 		  push (@{ $Apache::lonhomework::analyze{"$part_id.ans_high"} }, $high);
                    369: 		  push (@{ $Apache::lonhomework::analyze{"$part_id.ans_low"} }, $low);
                    370: 	      }
                    371: 	  }
                    372:       }
                    373:       if ($unit) {
                    374: 	  if ($target eq 'answer') {
                    375: 	      $result.=&Apache::response::answer_part($$tagstack[-1],
                    376: 						      "Unit: <b>$unit</b>");
                    377: 	  } elsif ($target eq 'analyze') {
                    378: 	      push (@{ $Apache::lonhomework::analyze{"$part_id.unit"} },
                    379: 		    $unit);
                    380: 	  }
1.44      albertel  381:       }
1.65      albertel  382:       if ($type || $token->[1] eq 'stringresponse') {
                    383: 	  my $string='Case Insensitive';
                    384: 	  if ($type eq 'mc') {
                    385: 	      $string='Multiple Choice';
                    386: 	  } elsif ($type eq 'cs') {
                    387: 	      $string='Case Sensitive';
                    388: 	  } elsif ($type eq 'ci') {
                    389: 	      $string='Case Insensitive';
                    390: 	  } elsif ($type eq 'fml') {
                    391: 	      $string='Formula';
                    392: 	  }
                    393: 	  if ($target eq 'answer') {
                    394: 	      $result.=&Apache::response::answer_part($$tagstack[-1],
                    395: 						      '<b>'.$string.'</b>');
                    396: 	  } elsif ($target eq 'analyze') {
                    397: 	      push (@{ $Apache::lonhomework::analyze{"$part_id.type"} },
                    398: 		    $type);
                    399: 	  }
1.52      albertel  400:       }
1.65      albertel  401:       if ($$tagstack[-1] eq 'formularesponse' && $target eq 'answer') {
                    402: 	  my $samples=&Apache::lonxml::get_param('samples',$parstack,$safeeval);
                    403: 	  $result.=&Apache::response::answer_part($$tagstack[-1],$samples);
1.51      albertel  404:       }
1.65      albertel  405:       if ($target eq 'answer') {
                    406: 	  $result.=&Apache::response::answer_footer($$tagstack[-1]);
1.44      albertel  407:       }
1.22      albertel  408:   }
1.59      albertel  409:   &Apache::response::end_response;
1.22      albertel  410:   return $result;
1.51      albertel  411: }
                    412: 
                    413: sub get_tolrange {
                    414:   my ($ans,$tol)=@_;
                    415:   my ($high,$low);
                    416:   if ($tol =~ /%$/) {
                    417:     chop($tol);
                    418:     my $change=$ans*($tol/100.0);
                    419:     $high=$ans+$change;
                    420:     $low=$ans-$change;
                    421:   } else {
                    422:     $high=$ans+$tol;
                    423:     $low=$ans-$tol;
                    424:   }
                    425:   return ($high,$low);
1.52      albertel  426: }
                    427: 
                    428: sub get_sigrange {
                    429:   my ($sig)=@_;
                    430:   &Apache::lonxml::debug("Got a sig of :$sig:");
                    431:   my $sig_lbound;
                    432:   my $sig_ubound;
                    433:   if ($sig eq '') {
                    434:     $sig_lbound = 0; #SIG_LB_DEFAULT
                    435:     $sig_ubound =15; #SIG_UB_DEFAULT
                    436:   } else {
                    437:     ($sig_lbound,$sig_ubound) = split(/,/,$sig);
                    438:     if (!$sig_lbound) {
                    439:       $sig_lbound = 0; #SIG_LB_DEFAULT
                    440:       $sig_ubound =15; #SIG_UB_DEFAULT
                    441:     }
                    442:     if (!$sig_ubound) { $sig_ubound=$sig_lbound; }
                    443:   }
                    444:   return ($sig_ubound,$sig_lbound);
1.34      albertel  445: }
                    446: 
                    447: sub start_stringresponse {
1.42      albertel  448:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    449:   my $result;
                    450:   if ($target eq 'meta') {
                    451:     $result=&Apache::response::meta_package_write('stringresponse');
                    452:   } else {
                    453:     $result.=&start_numericalresponse(@_);
                    454:   }
                    455:   return $result;
1.34      albertel  456: }
                    457: 
                    458: sub end_stringresponse {
1.44      albertel  459:   return end_numericalresponse(@_);
                    460: }
                    461: 
                    462: sub start_formularesponse {
                    463:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                    464:   my $result;
                    465:   if ($target eq 'meta') {
                    466:     $result=&Apache::response::meta_package_write('formularesponse');
                    467:   } else {
                    468:     $result.=&start_numericalresponse(@_);
                    469:   }
                    470:   return $result;
                    471: }
                    472: 
                    473: sub end_formularesponse {
1.34      albertel  474:   return end_numericalresponse(@_);
1.3       albertel  475: }
                    476: 
1.1       albertel  477: 1;
1.3       albertel  478: __END__
                    479:  

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