Diff for /loncom/homework/caparesponse/caparesponse.pm between versions 1.258 and 1.259

version 1.258, 2016/08/09 23:43:45 version 1.259, 2018/09/13 17:00:05
Line 664  sub end_numericalresponse { Line 664  sub end_numericalresponse {
  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);
    my ($needsdollar,$needscomma);
    if ($unit =~ /\$/) {
       $needsdollar = 1;
    }
    if ($unit =~ /\,/) {
       $needscomma = 1;
    }
   
  if ($target eq 'answer') {   if ($target eq 'answer') {
     $result.=&Apache::response::answer_header($tag,undef,      $result.=&Apache::response::answer_header($tag,undef,
       scalar(keys(%answer)));        scalar(keys(%answer)));
Line 760  sub end_numericalresponse { Line 767  sub end_numericalresponse {
  if ($unit=~/\,/) { $fmt="\,".$fmt; $unit=~s/\,//g; }   if ($unit=~/\,/) { $fmt="\,".$fmt; $unit=~s/\,//g; }
  $element = &format_number($element,$fmt,$target,   $element = &format_number($element,$fmt,$target,
   $safeeval);    $safeeval);
  if ($fmt=~/\$/ && $unit!~/\$/) { $element=~s/\$//; }   if ($fmt=~/\$/ && !$needsdollar) { $element=~s/\$//; }
     }      }
  }   }
  push(@fmt_ans,join(',',@$ans));   push(@fmt_ans,join(',',@$ans));
Line 773  sub end_numericalresponse { Line 780  sub end_numericalresponse {
  ! ($Apache::lonhomework::type eq 'exam' ||   ! ($Apache::lonhomework::type eq 'exam' ||
    lc($hideunit) eq "yes") )  {     lc($hideunit) eq "yes") )  {
  my $cleanunit=$unit;   my $cleanunit=$unit;
  $cleanunit=~s/\$\,//g;   $cleanunit=~s/[\$,]//g;
  foreach my $ans (@fmt_ans) {   foreach my $ans (@fmt_ans) {
     $ans.=" $cleanunit";      $ans.=" $cleanunit";
  }   }
Line 790  sub end_numericalresponse { Line 797  sub end_numericalresponse {
     $tag,$parstack,      $tag,$parstack,
     $safeeval,1);      $safeeval,1);
     $error=&mt("Computer's answer is incorrect ([_1]).",'"'.join(', ',@$response).'"').' ';      $error=&mt("Computer's answer is incorrect ([_1]).",'"'.join(', ',@$response).'"').' ';
                     if ($ad eq 'UNIT_INVALID_STUDENT') {                      if (($ad eq 'NO_UNIT') && $needsdollar) {
                           $error.=&mt('The unit attribute includes [_1] but the answer format does not.','$').' '.
                                   &mt('Either remove the [_1] from the unit or prepend [_1] to the answer format.','$');    
                       } elsif (($ad eq 'COMMA_FAIL') && $needscomma) {
                           $error.=&mt('The unit attribute includes [_1] but the answer format does not.',',').' '.
                                   &mt('Either remove the [_1] from the unit or prepend [_1] to the answer format.',',');
                       } elsif ($ad eq 'UNIT_INVALID_STUDENT') {
                         $error.=&mt('Unable to interpret units. Computer reads units as "[_1]".',$msg).' '.                          $error.=&mt('Unable to interpret units. Computer reads units as "[_1]".',$msg).' '.
                                 &mt('The unit attribute in the numericalresponse item needs to be a supported physical unit.');                                  &mt('The unit attribute in the numericalresponse item needs to be a supported physical unit.');
     } elsif ($sigline ne '') {      } elsif ($sigline ne '') {

Removed from v.1.258  
changed lines
  Added in v.1.259


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