Diff for /loncom/homework/caparesponse/caparesponse.pm between versions 1.93 and 1.102

version 1.93, 2003/04/18 07:12:13 version 1.102, 2003/05/19 21:15:21
Line 79  sub start_numericalresponse { Line 79  sub start_numericalresponse {
  $result=&Apache::response::meta_package_write('numericalresponse');   $result=&Apache::response::meta_package_write('numericalresponse');
     } elsif ($target eq 'answer' || $target eq 'grade') {      } elsif ($target eq 'answer' || $target eq 'grade') {
  &Apache::response::reset_params();   &Apache::response::reset_params();
       } elsif ($target eq 'web') {
    my $partid = $Apache::inputtags::part;
    my $hideunit=&Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.turnoffunit');
    &Apache::lonxml::debug("Got unit $hideunit for $partid $id");
    #no way to enter units, with radio buttons
    if (lc($hideunit) eq "yes") {
       my $unit=&Apache::lonxml::get_param_var('unit',$parstack,
       $safeeval);
       if ($unit =~ /\S/) { $result.=" (in $unit) "; }
    }
     }      }
     return $result;      return $result;
 }  }
Line 90  sub end_numericalresponse { Line 100  sub end_numericalresponse {
     if (!$Apache::lonxml::default_homework_loaded) {      if (!$Apache::lonxml::default_homework_loaded) {
  &Apache::lonxml::default_homework_load($safeeval);   &Apache::lonxml::default_homework_load($safeeval);
     }      }
     if ( $target eq 'grade' && defined $ENV{'form.submitted'}) {      if ( $target eq 'grade' && defined($ENV{'form.submitted'})) {
  &Apache::response::setup_params($$tagstack[-1]);   &Apache::response::setup_params($$tagstack[-1]);
  $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);   $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
  my $partid = $Apache::inputtags::part;   my $partid = $Apache::inputtags::part;
  my $id = $Apache::inputtags::response['-1'];   my $id = $Apache::inputtags::response['-1'];
  my $response = &Apache::response::getresponse();   if ($Apache::lonhomework::type eq 'exam' && 
  if ( $response =~ /[^\s]/) {      ($$tagstack[-1] eq 'formularesponse' ||
     my $ad;       $$tagstack[-1] eq 'stringresponse')) {
     my %previous = &Apache::response::check_for_previous($response,$partid,$id);      $increment=&Apache::response::scored_response($partid,$id);
     $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;   } else {
     &Apache::lonxml::debug("submitted a $response<br>\n");      my $response = &Apache::response::getresponse();
     &Apache::lonxml::debug($$parstack[-1] . "\n<br>");      if ( $response =~ /[^\s]/) {
    my $ad;
     if ($ENV{'form.submitted'} eq 'scantron') {   my %previous = &Apache::response::check_for_previous($response,$partid,$id);
  my $number_of_bubbles = 8;#default values for number of bubbles   $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
  my (@formats)=&Apache::lonxml::get_param_var('format',   &Apache::lonxml::debug("submitted a $response<br>\n");
  $parstack,$safeeval);   &Apache::lonxml::debug($$parstack[-1] . "\n<br>");
  my (@answers)=&Apache::lonxml::get_param_var('answer',  
  $parstack,$safeeval);   if ($ENV{'form.submitted'} eq 'scantron') {
  my @values=&make_numerical_bubbles($number_of_bubbles,$target,      my $number_of_bubbles = 8;#default values for number of bubbles
    $answers[0],$formats[0]);      my (@formats)=&Apache::lonxml::get_param_var('format',
  $response=$values[$response];   $parstack,$safeeval);
     } else {      my (@answers)=&Apache::lonxml::get_param_var('answer',
  $response =~ s/\\/\\\\/g;   $parstack,$safeeval);
  $response =~ s/\'/\\\'/g;      my @values=&make_numerical_bubbles($number_of_bubbles,$target,
     }         $answers[0],$formats[0]);
     &Apache::lonxml::debug("current $response");      $response=$values[$response];
     my $expression="&caparesponse_check_list('".$response."','".   } else {
  $$parstack[-1];      $response =~ s/\\/\\\\/g;
     #no way to enter units, with radio buttons      $response =~ s/\'/\\\'/g;
     if ($Apache::lonhomework::type eq 'exam') {   }
  $expression.=';my $unit=undef;';   &Apache::lonxml::debug("current $response");
     }   my $expression="&caparesponse_check_list('".$response."','".
     foreach my $key (keys(%Apache::inputtags::params)) {      $$parstack[-1];
  $expression.= ';my $'. #'   my $hideunit=&Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.turnoffunit');
     $key.'="'.$Apache::inputtags::params{$key}.'"';   #no way to enter units, with radio buttons
     }   if ($Apache::lonhomework::type eq 'exam' ||
     if ($$tagstack[-1] eq 'formularesponse') {      lc($hideunit) eq "yes") {
  $expression.=';my $type="fml";';      $expression.=';my $unit=undef;';
     } elsif ($$tagstack[-1] eq 'numericalresponse') {   }
  $expression.=';my $type="float";';   foreach my $key (keys(%Apache::inputtags::params)) {
     }      $expression.= ';my $'. #'
     $expression.="');";   $key.'="'.$Apache::inputtags::params{$key}.'"';
     $result = &Apache::run::run($expression,$safeeval);   }
     my ($awards) = split /:/ , $result;   if ($$tagstack[-1] eq 'formularesponse') {
     ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);      $expression.=';my $type="fml";';
     &Apache::lonxml::debug("$expression");   } elsif ($$tagstack[-1] eq 'numericalresponse') {
     &Apache::lonxml::debug("\n<br>result:$result:$Apache::lonxml::curdepth<br>\n");      $expression.=';my $type="float";';
     &Apache::response::handle_previous(\%previous,$ad);   }
     $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;   $expression.="');";
     $result='';   $result = &Apache::run::run($expression,$safeeval);
    my ($awards) = split /:/ , $result;
    ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
    &Apache::lonxml::debug("$expression");
    &Apache::lonxml::debug("\n<br>result:$result:$Apache::lonxml::curdepth<br>\n");
    &Apache::response::handle_previous(\%previous,$ad);
    $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
    $result='';
       }
  }   }
     } elsif ($target eq 'web' || $target eq 'tex') {      } elsif ($target eq 'web' || $target eq 'tex') {
  my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,   my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,
      $safeeval);       $safeeval);
  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/
                   && lc($Apache::lonhomework::problemstatus) ne 'no')
                || $status eq "SHOW_ANSWER"
                || $ENV{'form.texaward'} eq 'SHOW_ANSWER') {
     my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,      my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,
  $safeeval);   $safeeval);
     my $unit=&Apache::lonxml::get_param_var('unit',$parstack,      my $unit=&Apache::lonxml::get_param_var('unit',$parstack,
Line 155  sub end_numericalresponse { Line 176  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{';   if ($ENV{'form.texaward'} eq 'SHOW_ANSWER') {
       $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 173  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 ($ENV{'form.texaward'} eq 'SHOW_ANSWER') {
       $result.=$formatted;
    }
  if ($target eq 'tex') {   if ($target eq 'tex') {
     $formatted='';      $formatted='';
     #$formatted=&Apache::lonxml::latex_special_symbols($formatted);      #$formatted=&Apache::lonxml::latex_special_symbols($formatted);
Line 183  sub end_numericalresponse { Line 208  sub end_numericalresponse {
     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);   if ($ENV{'form.texaward'} eq 'SHOW_ANSWER') {
  #$result.="}. \\vskip 0 mm ";      $result.=&Apache::lonxml::latex_special_symbols($unit);
       $result.="}. \\vskip 0 mm ";
    }
     }      }
  }   }
  if ($Apache::lonhomework::type eq 'exam') {   if ($Apache::lonhomework::type eq 'exam') {
Line 282  sub end_numericalresponse { Line 309  sub end_numericalresponse {
     if ($Apache::inputtags::params{'sig'}) {      if ($Apache::inputtags::params{'sig'}) {
  ($sighigh,$siglow)=&get_sigrange($Apache::inputtags::params{'sig'});   ($sighigh,$siglow)=&get_sigrange($Apache::inputtags::params{'sig'});
     }      }
     if ($fmt) {      if ($fmt && $$tagstack[-1] eq 'numericalresponse') {
  $ans = sprintf('%.'.$fmt,$ans);   $ans = sprintf('%.'.$fmt,$ans);
  if ($high) {   if ($high) {
     $high=sprintf('%.'.$fmt,$high);      $high=sprintf('%.'.$fmt,$high);
Line 290  sub end_numericalresponse { Line 317  sub end_numericalresponse {
  }   }
     }      }
     if ($target eq 'answer') {      if ($target eq 'answer') {
  if ($high) { $ans.=' ['.$low.','.$high.']'; }   if ($high && $$tagstack[-1] eq 'numericalresponse') { $ans.=' ['.$low.','.$high.']'; }
  if ($sighigh) { $ans.= " Sig <i>$siglow - $sighigh</i>"; }   if ($sighigh && $$tagstack[-1] eq 'numericalresponse') {
       if ($ENV{'form.answer_output_mode'} eq 'tex') {
    $ans.= " Sig \\textit{$siglow - $sighigh}";
       } else {
    $ans.= " Sig <i>$siglow - $sighigh</i>";
       }
    }
  $result.=&Apache::response::answer_part($$tagstack[-1],$ans);   $result.=&Apache::response::answer_part($$tagstack[-1],$ans);
     } elsif ($target eq 'analyze') {      } elsif ($target eq 'analyze') {
  push (@{ $Apache::lonhomework::analyze{"$part_id.answer"} }, $ans);   push (@{ $Apache::lonhomework::analyze{"$part_id.answer"} }, $ans);
Line 301  sub end_numericalresponse { Line 334  sub end_numericalresponse {
  }   }
     }      }
  }   }
  if ($unit) {   if (defined($unit) and ($unit ne '') and
       $$tagstack[-1] eq 'numericalresponse') {
     if ($target eq 'answer') {      if ($target eq 'answer') {
  $result.=&Apache::response::answer_part($$tagstack[-1],   if ($ENV{'form.answer_output_mode'} eq 'tex') {
  "Unit: <b>$unit</b>");      $result.=&Apache::response::answer_part($$tagstack[-1],
       "Unit: \\verb|$unit|");
    } else {
       $result.=&Apache::response::answer_part($$tagstack[-1],
       "Unit: <b>$unit</b>");
    }
     } elsif ($target eq 'analyze') {      } elsif ($target eq 'analyze') {
  push (@{ $Apache::lonhomework::analyze{"$part_id.unit"} },   push (@{ $Apache::lonhomework::analyze{"$part_id.unit"} },
       $unit);        $unit);
Line 322  sub end_numericalresponse { Line 361  sub end_numericalresponse {
  $string='Formula';   $string='Formula';
     }      }
     if ($target eq 'answer') {      if ($target eq 'answer') {
  $result.=&Apache::response::answer_part($$tagstack[-1],   if ($ENV{'form.answer_output_mode'} eq 'tex') {
  '<b>'.$string.'</b>');      $result.=&Apache::response::answer_part($$tagstack[-1],
     "\\textbf{$string}");
    } else {
       $result.=&Apache::response::answer_part($$tagstack[-1],
       "<b>$string</b>");
    }
     } elsif ($target eq 'analyze') {      } elsif ($target eq 'analyze') {
  push (@{ $Apache::lonhomework::analyze{"$part_id.type"} },   push (@{ $Apache::lonhomework::analyze{"$part_id.type"} },
       $type);        $type);

Removed from v.1.93  
changed lines
  Added in v.1.102


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