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

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

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