Diff for /loncom/homework/caparesponse/caparesponse.pm between versions 1.74 and 1.78

version 1.74, 2002/11/27 16:50:09 version 1.78, 2003/02/27 20:31:34
Line 85  sub start_numericalresponse { Line 85  sub start_numericalresponse {
     $result.=&Apache::edit::tag_start($target,$token);      $result.=&Apache::edit::tag_start($target,$token);
     $result.=&Apache::edit::text_arg('Answer:','answer',$token);      $result.=&Apache::edit::text_arg('Answer:','answer',$token);
     if ($token->[1] eq 'numericalresponse') {      if ($token->[1] eq 'numericalresponse') {
       $result.=&Apache::edit::text_arg('Unit:','unit',$token,5);        $result.=&Apache::edit::text_arg('Unit:','unit',$token,5).
       $result.=&Apache::edit::text_arg('Format:','format',$token,4);                           &Apache::loncommon::help_open_topic('Physical_Units');
         $result.=&Apache::edit::text_arg('Format:','format',$token,4).
                 &Apache::loncommon::help_open_topic('Numerical_Response_Format');
     } 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','Case Sensitive'],['ci','Case Insensitive'],   [['cs','Case Sensitive'],['ci','Case Insensitive'],
   ['mc','Case Insensitive, Any Order']],$token);    ['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).
                &Apache::loncommon::help_open_topic('Formula_Response_Sampling');
     }      }
     $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();      $result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
   } elsif ($target eq 'modified') {    } elsif ($target eq 'modified') {
Line 175  sub end_numericalresponse { Line 178  sub end_numericalresponse {
  if ($target eq 'web') {   if ($target eq 'web') {
   $result="<br />The correct answer is ";    $result="<br />The correct answer is ";
         } elsif ($target eq 'tex') {          } elsif ($target eq 'tex') {
   $result='\vskip 0 mm The correct answer is \\texttt{';    #$result='\vskip 0 mm The correct answer is \\texttt{';
         }          }
  for (my $i=0; $i <= $#answers; $i++) {   for (my $i=0; $i <= $#answers; $i++) {
    my $answer=$answers[$i];     my $answer=$answers[$i];
Line 193  sub end_numericalresponse { Line 196  sub end_numericalresponse {
      &Apache::lonxml::debug("no format answer :$answer:");       &Apache::lonxml::debug("no format answer :$answer:");
      $formatted="$answer,";       $formatted="$answer,";
    }     }
    if ($target eq 'tex') {$formatted=&Apache::lonxml::latex_special_symbols($formatted);}  
      $result.=$formatted;     if ($target eq 'tex') {
            }         $formatted='';
          #$formatted=&Apache::lonxml::latex_special_symbols($formatted);
      }
      $result.=$formatted;
          }
    chop $result;     chop $result;
    if ($target eq 'web') {     if ($target eq 'web') {
      $result.=" $unit.<br />";       $result.=" $unit.<br />";
    } elsif ($target eq 'tex') {     } elsif ($target eq 'tex') {
      $result.=&Apache::lonxml::latex_special_symbols($unit);       #$result.=&Apache::lonxml::latex_special_symbols($unit);
      $result.="}. \\vskip 0 mm ";       #$result.="}. \\vskip 0 mm ";
    }     }
        }         }
       if ($Apache::lonhomework::type eq 'exam') {        if ($Apache::lonhomework::type eq 'exam') {
Line 228  sub end_numericalresponse { Line 235  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') {
     if ($$tagstack[-1] eq 'numericalresponse') {
     my $id=$Apache::inputtags::response[-1];      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++) {
Line 250  sub end_numericalresponse { Line 258  sub end_numericalresponse {
     $result.='<td><input type="radio" name="HWVAL'.$id.'" value="'.$ans.'"><b>'.$alphabet[$ind].'</b>: '.$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 ($$tagstack[-1] eq 'formularesponse') {
       $result.= '<br /><br /><font color="red"> Formula have to be entered here! </font><br /><br />';
     }
  } elsif ($target eq 'tex') {   } elsif ($target eq 'tex') {
     my $max_val = 0;   if ($$tagstack[-1] eq 'numericalresponse') {
     if ($formats[0]=~m/^(\d+)E([^\d]*)(\d*)$/) {       my $max_val = 0;
  $max_val=$1+$2+4;       if ($formats[0]=~m/^(\d+)E([^\d]*)(\d*)$/) {
     } else {   $max_val=$1+$2+4;
  $max_val=4;       } else {
     }   $max_val=4;
     $max_val = int(0.9*$ENV{'form.textwidth'}/(($max_val+6)*2));       }
             my $celllength = 0.9*$ENV{'form.textwidth'}/$max_val-10;       $max_val = int(0.9*$ENV{'form.textwidth'}/(($max_val+6)*2));
     my @table_range = ();   my $celllength = 0.9*$ENV{'form.textwidth'}/$max_val-10;
     my $number_of_tables = int($number_of_bubbles/$max_val);       my @table_range = ();
     for (my $i=0;$i<$number_of_tables;$i++) {push @table_range,$max_val;}       my $number_of_tables = int($number_of_bubbles/$max_val);
     if ($number_of_bubbles % $max_val != 0) {   for (my $i=0;$i<$number_of_tables;$i++) {push @table_range,$max_val;}
  $number_of_tables++;       if ($number_of_bubbles % $max_val != 0) {
  push @table_range,($number_of_bubbles % $max_val);      $number_of_tables++;
     }      push @table_range,($number_of_bubbles % $max_val);
     my $j=0;  
     my $cou=0;  
     $result.='\vskip -1 mm \noindent \begin{enumerate}\item[\textbf{'.$Apache::lonxml::counter.'}.]';  
     for (my $i=0;$i<$number_of_tables;$i++) {  
  $result.='\vskip -1 mm \noindent \begin{tabular}{';  
  for ($ind=0;$ind<$table_range[$j];$ind++) {  
     $result.='lp{'.$celllength.' mm}';  
  }  
  $result.='}';  
  for ($ind=$cou;$ind<$cou+$table_range[$j];$ind++) {  
     my $ans;  
     if ($formats[0] ne '') {  
  $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 {  
  my $badans = $bubbles_values[$ind];  
  my $format = '';   
  #What is the number? (integer,decimal,floating point)  
  if ($badans=~/^(\d*\.?\d*)(E|e)(\d*)$/) {  
     $format = 'e'.$2;  
  } elsif ($badans=~/^(\d*)\.(\d*)$/) {  
     $format = '4f';  
  } elsif ($badans=~/^(\d*)$/) {  
     $format = 'd';  
  }  
  $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.='\hskip -3 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -2 mm & {\small '.$ans.'} ';  
     if ($ind != $cou+$table_range[$j]-1) {$result.=' & ';}  
  }   }
  $cou += $table_range[$j];       my $j=0;
  $j++;       my $cou=0;
  $result.='\\\\\end{tabular}\vskip 0 mm ';           $result.='\vskip -1 mm \noindent \begin{enumerate}\item[\textbf{'.$Apache::lonxml::counter.'}.]';
     }       for (my $i=0;$i<$number_of_tables;$i++) {
     $result.='\end{enumerate}';   $result.='\vskip -1 mm \noindent \begin{tabular}{';
     &Apache::lonxml::increment_counter();   for ($ind=0;$ind<$table_range[$j];$ind++) {
        $result.='lp{'.$celllength.' mm}';
    }
    $result.='}';
    for ($ind=$cou;$ind<$cou+$table_range[$j];$ind++) {
        my $ans;
        if ($formats[0] ne '') {
    $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 {
    my $badans = $bubbles_values[$ind];
    my $format = ''; 
    #What is the number? (integer,decimal,floating point)
    if ($badans=~/^(\d*\.?\d*)(E|e)(\d*)$/) {
        $format = 'e'.$2;
    } elsif ($badans=~/^(\d*)\.(\d*)$/) {
        $format = '4f';
    } elsif ($badans=~/^(\d*)$/) {
        $format = 'd';
    }
    $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.='\hskip -3 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -2 mm & {\small '.$ans.'} ';
        if ($ind != $cou+$table_range[$j]-1) {$result.=' & ';}
    }
    $cou += $table_range[$j];
    $j++;
    $result.='\\\\\end{tabular}\vskip 0 mm ';    
        }
        $result.='\end{enumerate}';
        &Apache::lonxml::increment_counter();
            } else {
        $result.='\fbox{\fbox{\parbox{\textwidth-5mm}{\strut\\\\\strut\\\\\strut\\\\\strut\\\\\strut\\\\\strut\\\\}}}';
        $result.= '\begin{enumerate}\item[\textbf{'.$Apache::lonxml::counter.'}.]\textit{Live blank on scoring form}\vskip 0 mm \end{enumerate}';
        &Apache::lonxml::increment_counter();
    }
  }   }
     }      }
   } elsif ($target eq 'edit') {    } elsif ($target eq 'edit') {

Removed from v.1.74  
changed lines
  Added in v.1.78


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