Diff for /loncom/homework/caparesponse/caparesponse.pm between versions 1.65 and 1.72

version 1.65, 2002/10/14 20:37:27 version 1.72, 2002/11/13 23:37:56
Line 89  sub start_numericalresponse { Line 89  sub start_numericalresponse {
       $result.=&Apache::edit::text_arg('Format:','format',$token,4);        $result.=&Apache::edit::text_arg('Format:','format',$token,4);
     } elsif ($token->[1] eq 'stringresponse') {      } elsif ($token->[1] eq 'stringresponse') {
       $result.=&Apache::edit::select_arg('Type:','type',        $result.=&Apache::edit::select_arg('Type:','type',
  ['cs','ci','mc'],$token);   [['cs','Case Sensitive'],['ci','Case Insensitive'],
     ['mc','Case Insensitive, Any Order']],$token);
     } elsif ($token->[1] eq 'formularesponse') {      } elsif ($token->[1] eq 'formularesponse') {
       $result.=&Apache::edit::text_arg('Sample Points:','samples',$token,40);        $result.=&Apache::edit::text_arg('Sample Points:','samples',$token,40);
     }      }
Line 127  sub end_numericalresponse { Line 128  sub end_numericalresponse {
       my $id = $Apache::inputtags::response['-1'];        my $id = $Apache::inputtags::response['-1'];
       my $response = $ENV{'form.HWVAL'.$id};        my $response = $ENV{'form.HWVAL'.$id};
       if ( $response =~ /[^\s]/) {        if ( $response =~ /[^\s]/) {
    if (!$Apache::lonxml::default_homework_loaded) {
       &Apache::lonxml::default_homework_load($safeeval);
    }
  my %previous = &Apache::response::check_for_previous($response,$partid,$id);   my %previous = &Apache::response::check_for_previous($response,$partid,$id);
  $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;   $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
  &Apache::lonxml::debug("submitted a $response<br>\n");   &Apache::lonxml::debug("submitted a $response<br>\n");
Line 157  sub end_numericalresponse { Line 161  sub end_numericalresponse {
       }        }
     }      }
   } elsif ($target eq 'web' || $target eq 'tex') {    } elsif ($target eq 'web' || $target eq 'tex') {
     if ($Apache::lonhomework::type ne 'exam') {  
       my $award = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};        my $award = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"};
       my $status = $Apache::inputtags::status['-1'];        my $status = $Apache::inputtags::status['-1'];
       if ($award =~ /^correct/ || $status eq "SHOW_ANSWER" ) {        if ($award =~ /^correct/ || $status eq "SHOW_ANSWER" ) {
Line 199  sub end_numericalresponse { Line 202  sub end_numericalresponse {
      $result.="}. \\vskip 0 mm ";       $result.="}. \\vskip 0 mm ";
    }     }
        }         }
     } else {        if ($Apache::lonhomework::type eq 'exam') {
       my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);        my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
  my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,$safeeval);   my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,$safeeval);
  my $unit=&Apache::lonxml::get_param_var('unit',$parstack,$safeeval);   my $unit=&Apache::lonxml::get_param_var('unit',$parstack,$safeeval);
Line 223  sub end_numericalresponse { Line 226  sub end_numericalresponse {
  my @alphabet = ('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',   my @alphabet = ('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
  'Q','R','S','T','U','V','W','X','Y','Z');   'Q','R','S','T','U','V','W','X','Y','Z');
         if ($target eq 'web') {          if ($target eq 'web') {
       my $id=$Apache::inputtags::response[-1];
     $result.= '<table border="1"><tr>';      $result.= '<table border="1"><tr>';
     for ($ind=0;$ind<$number_of_bubbles;$ind++) {      for ($ind=0;$ind<$number_of_bubbles;$ind++) {
  my $ans;   my $ans;
Line 241  sub end_numericalresponse { Line 245  sub end_numericalresponse {
     }      }
     $ans = sprintf('%.'.$format,$bubbles_values[$ind]);      $ans = sprintf('%.'.$format,$bubbles_values[$ind]);
  }   }
     $result.='<td>'.$alphabet[$ind].': '.$ans.'</td>';      $result.='<td><input type="radio" name="HWVAL'.$id.'" value="'.$ans.'"><b>'.$alphabet[$ind].'</b>: '.$ans.'</td>';
     }      }
     $result.='</tr></table>';      $result.='</tr></table>';
  } elsif ($target eq 'tex') {   } elsif ($target eq 'tex') {
Line 249  sub end_numericalresponse { Line 253  sub end_numericalresponse {
     if ($formats[0]=~m/^(\d+)E([^\d]*)(\d*)$/) {      if ($formats[0]=~m/^(\d+)E([^\d]*)(\d*)$/) {
  $max_val=$1+$2+4;   $max_val=$1+$2+4;
     } else {      } else {
  $max_val=5;   $max_val=4;
     }      }
     $max_val = int(90/(($max_val+6)*2));      $max_val = int(0.9*$ENV{'form.textwidth'}/(($max_val+6)*2));
             my $celllength = 90/$max_val-12;              my $celllength = 0.9*$ENV{'form.textwidth'}/$max_val-10;
     my @table_range = ();      my @table_range = ();
     my $number_of_tables = int($number_of_bubbles/$max_val);      my $number_of_tables = int($number_of_bubbles/$max_val);
     for (my $i=0;$i<$number_of_tables;$i++) {push @table_range,$max_val;}      for (my $i=0;$i<$number_of_tables;$i++) {push @table_range,$max_val;}
Line 262  sub end_numericalresponse { Line 266  sub end_numericalresponse {
     }      }
     my $j=0;      my $j=0;
     my $cou=0;      my $cou=0;
     $result.='\vskip 2 mm \noindent ';      $result.='\vskip -1 mm \noindent \begin{enumerate}\item[\textbf{'.$Apache::lonxml::counter.'}.]';
     for (my $i=0;$i<$number_of_tables;$i++) {      for (my $i=0;$i<$number_of_tables;$i++) {
  $result.='\vskip 0 mm \noindent \begin{tabular}{|';   $result.='\vskip -1 mm \noindent \begin{tabular}{';
  for ($ind=0;$ind<$table_range[$j];$ind++) {   for ($ind=0;$ind<$table_range[$j];$ind++) {
     $result.='lp{'.$celllength.' mm}|';      $result.='lp{'.$celllength.' mm}';
  }   }
  $result.='}\hline';   $result.='}';
  for ($ind=$cou;$ind<$cou+$table_range[$j];$ind++) {   for ($ind=$cou;$ind<$cou+$table_range[$j];$ind++) {
     my $ans;      my $ans;
     if ($formats[0] ne '') {      if ($formats[0] ne '') {
  $ans = sprintf('%.'.$formats[0],$bubbles_values[$ind]);   $ans = sprintf('%.'.$formats[0],$bubbles_values[$ind]);
    if ($ans =~ m/([0-9\.\-\+]+)E([0-9\-\+]+)/ ) {
       my $number = $1;
       my $power = $2;
       $power=~s/^\+//;
       $power=~s/^(-?)0+(\d+)//;
       $ans=$number.'$\times 10^{'.$1.$2.'}$'; #'stupidemacs
    } 
     } else {      } else {
  my $badans = $bubbles_values[$ind];   my $badans = $bubbles_values[$ind];
  my $format = '';    my $format = ''; 
Line 284  sub end_numericalresponse { Line 295  sub end_numericalresponse {
  } elsif ($badans=~/^(\d*)$/) {   } elsif ($badans=~/^(\d*)$/) {
     $format = 'd';      $format = 'd';
  }   }
  $ans = sprintf('%.'.$format,$bubbles_values[$ind]);   $ans = sprintf('%.'.$format,$bubbles_values[$ind]);
    if ($ans =~ m/([0-9\.\-\+]+)E([0-9\-\+]+)/ ) {
       my $number = $1;
       my $power = $2;
       $power=~s/^\+//;
       $power=~s/^(-?)0+(\d+)//;
       $ans=$number.'$\times 10^{'.$1.$2.'}$'; #'stupidemacs
    } 
     }      }
     $result.=' '.$alphabet[$ind].': & '.$ans.' ';      $result.='\hskip -3 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -2 mm & {\small '.$ans.'} ';
     if ($ind != $cou+$table_range[$j]-1) {$result.=' & ';}      if ($ind != $cou+$table_range[$j]-1) {$result.=' & ';}
  }   }
  $cou += $table_range[$j];   $cou += $table_range[$j];
  $j++;   $j++;
  $result.='\\\\\hline\end{tabular}\vskip 0 mm ';   $result.='\\\\\end{tabular}\vskip 0 mm ';    
     }          }
       $result.='\end{enumerate}';
       &Apache::lonxml::increment_counter();
  }   }
     }      }
   } elsif ($target eq 'edit') {    } elsif ($target eq 'edit') {

Removed from v.1.65  
changed lines
  Added in v.1.72


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