Diff for /loncom/homework/caparesponse/caparesponse.pm between versions 1.227.2.1 and 1.236

version 1.227.2.1, 2008/09/12 10:09:18 version 1.236, 2009/01/15 18:31:23
Line 310  sub start_numericalresponse { Line 310  sub start_numericalresponse {
     $safeeval);      $safeeval);
     if ($unit =~ /\S/) { $result.=" (in $unit) "; }      if ($unit =~ /\S/) { $result.=" (in $unit) "; }
  }   }
         if (($token->[1] eq 'formularesponse') &&   
             ($Apache::inputtags::status['-1'] eq 'CAN_ANSWER')) {  
             $result.=&edit_formula_button($id,"HWVAL_$id");  
         }  
  if (  &Apache::response::show_answer() ) {   if (  &Apache::response::show_answer() ) {
     &set_answertext($tag_internal_answer_name,$target,$token,$tagstack,      &set_answertext($tag_internal_answer_name,$target,$token,$tagstack,
     $parstack,$parser,$safeeval,-1);      $parstack,$parser,$safeeval,-1);
Line 322  sub start_numericalresponse { Line 318  sub start_numericalresponse {
     return $result;      return $result;
 }  }
   
 sub edit_formula_button {  
     my ($id,$field)=@_;  
     my $button=&mt('Edit Answer');  
     my $helplink=&Apache::loncommon::help_open_topic('Formula_Editor');  
     return(<<ENDFORMULABUTTON);  
 <script language="JavaScript">  
 function edit_${id}_${field} (textarea) {  
     thenumber = textarea;  
     thedata = document.forms['lonhomework'].elements[textarea].value;  
     newwin = window.open("/adm/dragmath/applet/MaximaPopup.html","","width=565,height=400,resizable");  
 }  
 </script>  
 <input type='button' value='$button' onclick="javascript:edit_${id}_${field}('${field}');void(0);" />$helplink  
 ENDFORMULABUTTON  
 }  
   
 sub set_answertext {  sub set_answertext {
     my ($name,$target,$token,$tagstack,$parstack,$parser,$safeeval,      my ($name,$target,$token,$tagstack,$parstack,$parser,$safeeval,
  $response_level) = @_;   $response_level) = @_;
Line 447  sub check_submission { Line 427  sub check_submission {
  }   }
     } elsif ($tag eq 'numericalresponse') {      } elsif ($tag eq 'numericalresponse') {
  $$args_ref{'type'}='float';   $$args_ref{'type'}='float';
       } elsif ($tag eq 'stringresponse') {
           if ($$args_ref{'type'} eq '') {
               $$args_ref{'type'} = 'ci';
           }
     }      }
       
     &add_in_tag_answer($parstack,$safeeval);      &add_in_tag_answer($parstack,$safeeval);
   
     if (!%answer) {      if (!%answer) {
Line 464  sub check_submission { Line 448  sub check_submission {
  use Time::HiRes;   use Time::HiRes;
  my $t0 = [Time::HiRes::gettimeofday()];   my $t0 = [Time::HiRes::gettimeofday()];
  my ($result,@msgs) =    my ($result,@msgs) = 
     &Apache::run::run("&caparesponse_check_list($tag)",$safeeval);      &Apache::run::run("&caparesponse_check_list()",$safeeval);
  &Apache::lonxml::debug("checking $name $result with $response took ".&Time::HiRes::tv_interval($t0));   &Apache::lonxml::debug("checking $name $result with $response took ".&Time::HiRes::tv_interval($t0));
  &Apache::lonxml::debug('msgs are '.join(':',@msgs));   &Apache::lonxml::debug('msgs are '.join(':',@msgs));
  my ($awards)=split(/:/,$result);   my ($awards)=split(/:/,$result);
Line 530  sub end_numericalresponse { Line 514  sub end_numericalresponse {
  &Apache::lonxml::debug($$parstack[-1] . "\n<br>");   &Apache::lonxml::debug($$parstack[-1] . "\n<br>");
   
  if ( &Apache::response::submitted('scantron')) {   if ( &Apache::response::submitted('scantron')) {
     &add_in_tag_answer($parstack,$safeeval);      &add_in_tag_answer($parstack,$safeeval);
     my ($values,$display)=&make_numerical_bubbles($partid,$id,      my ($values,$display)=&make_numerical_bubbles($partid,$id,
   $target,$parstack,$safeeval);    $target,$parstack,$safeeval);
     $response=$values->[$response];      $response=$values->[$response];
  }   }
  $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;   $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
  my ($ad,$msg,$name)=&check_submission($response,$partid,$id,   my ($ad,$msg,$name)=&check_submission($response,$partid,$id,
       $tag,$parstack,        $tag,$parstack,
       $safeeval);        $safeeval);
Line 622  sub end_numericalresponse { Line 606  sub end_numericalresponse {
  }   }
     }      }
  }   }
           if (($target eq 'web') && ($tag eq 'formularesponse')
               && ($Apache::lonhomework::type ne 'exam') && ($Apache::inputtags::status['-1'] eq 'CAN_ANSWER')
       && (&Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.turnoffeditor') ne 'yes')) {
               $result.=&Apache::response::edit_mathresponse_button($id,"HWVAL_$id");
           }
               
  &Apache::response::setup_prior_tries_hash(\&format_prior_response_numerical);   &Apache::response::setup_prior_tries_hash(\&format_prior_response_numerical);
     } elsif ($target eq 'edit') {      } elsif ($target eq 'edit') {
  $result.='</td></tr>'.&Apache::edit::end_table;   $result.='</td></tr>'.&Apache::edit::end_table;
Line 762  sub end_numericalresponse { Line 752  sub end_numericalresponse {
     if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {      if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {
  my $error;   my $error;
  if ($tag eq 'formularesponse') {   if ($tag eq 'formularesponse') {
     $error=&mt('Computer\'s answer is incorrect ("[_1]").',join(', ',@$response));      $error=&mt("Computer's answer is incorrect ([_1]).",'"'.join(', ',@$response).'"');
  } else {   } else {
     # answer failed check if it is sig figs that is failing      # answer failed check if it is sig figs that is failing
     my ($ad,$msg)=&check_submission($response,$partid,$id,      my ($ad,$msg)=&check_submission($response,$partid,$id,
     $tag,$parstack,      $tag,$parstack,
     $safeeval,1);      $safeeval,1);
       $error=&mt("Computer's answer is incorrect ([_1]).",'"'.join(', ',@$response).'"').' ';
     if ($sigline ne '') {      if ($sigline ne '') {
  $error=&mt('Computer\'s answer is incorrect ("[_1]"). It is likely that the tolerance range [_2] or significant figures [_3] need to be adjusted.',join(', ',@$response),$tolline,$sigline);   $error.=&mt('It is likely that the tolerance range [_1] or significant figures [_2] need to be adjusted.',$tolline,$sigline);
     } else {      } else {
  $error=&mt('Computer\'s answer is incorrect ("[_1]"). It is likely that the tolerance range [_2] needs to be adjusted.',join(', ',@$response),$tolline);   $error.=&mt('It is likely that the tolerance range [_1] needs to be adjusted.',$tolline);
     }      }
  }   }
  if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {   if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {
Line 1171  sub end_stringresponse { Line 1162  sub end_stringresponse {
     my @args = ('type');      my @args = ('type');
     my $args_ref = &setup_capa_args($safeeval,$parstack,      my $args_ref = &setup_capa_args($safeeval,$parstack,
     \@args,$response);      \@args,$response);
                       if ($$args_ref{'type'} eq '') {
                           $$args_ref{'type'} = 'ci';
                       }
     &add_in_tag_answer($parstack,$safeeval);      &add_in_tag_answer($parstack,$safeeval);
     my (@final_awards,@final_msgs,@names);      my (@final_awards,@final_msgs,@names);
     foreach my $name (keys(%answer)) {      foreach my $name (keys(%answer)) {
  &Apache::lonxml::debug(" doing $name with ".join(':',@{ $answer{$name}{'answers'} }));   &Apache::lonxml::debug(" doing $name with ".join(':',@{ $answer{$name}{'answers'} }));
  ${$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=dclone($answer{$name});   ${$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=dclone($answer{$name});
  my ($result, @msgs)=&Apache::run::run("&caparesponse_check_list($$tagstack[-1])",$safeeval);   my ($result, @msgs)=&Apache::run::run("&caparesponse_check_list()",$safeeval);
  &Apache::lonxml::debug('msgs are'.join(':',@msgs));   &Apache::lonxml::debug('msgs are'.join(':',@msgs));
  my ($awards)=split(/:/,$result);   my ($awards)=split(/:/,$result);
  my (@awards) = split(/,/,$awards);   my (@awards) = split(/,/,$awards);

Removed from v.1.227.2.1  
changed lines
  Added in v.1.236


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