Diff for /loncom/homework/radiobuttonresponse.pm between versions 1.5 and 1.12

version 1.5, 2001/01/12 01:07:13 version 1.12, 2001/02/19 20:36:49
Line 1 Line 1
 # The LearningOnline Network with CAPA  # The LearningOnline Network with CAPA
 # mutliple choice style responses  # mutliple choice style responses
   
 # 11/23,11/24,11/28 Gerd Kortemeyer  
   
 package Apache::radiobuttonresponse;  package Apache::radiobuttonresponse;
 use strict;  use strict;
   
Line 26  sub end_radiobuttonresponse { Line 24  sub end_radiobuttonresponse {
 %Apache::response::foilgroup={};  %Apache::response::foilgroup={};
 sub start_foilgroup {  sub start_foilgroup {
   %Apache::response::foilgroup={};    %Apache::response::foilgroup={};
     return '';
 }  }
   
 sub setrandomnumber {  sub setrandomnumber {
Line 38  sub setrandomnumber { Line 37  sub setrandomnumber {
   return '';    return '';
 }  }
   
 #FIXME needs to stablely do random picks  
 sub end_foilgroup {  sub end_foilgroup {
   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;    my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
   my $name;    
   my $result;    my $result;
   &setrandomnumber();    if ($target ne 'meta') {
   my $rrargs ='';      my $name;
   if ( $#$parstack > 0 ) { $rrargs=$$parstack['-2']; }      &setrandomnumber();
   my $max = &Apache::run::run("{$rrargs;".'return $max}',$safeeval);      my ($truecnt,$falsecnt,$max) = &getfoilcounts($parstack,$safeeval);
   my $answer = int(rand $max);      my $count=0;
   if ($target eq 'web') {      # we will add in 1 of the true statements
     $result=&displayfoils($max,$answer);      if (($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; }
   } elsif ( $target eq 'grade') {      my $answer = int(rand ($count));
     if ( defined $ENV{'form.submit'}) {      &Apache::lonxml::debug("Answer is $answer, $count from $max, $falsecnt");
       my $response = $ENV{'form.HWVAL'.$Apache::inputtags::response['-1']};      if ($target eq 'web') {
       if ( $response =~ /[^\s]/) {        $result=&displayfoils($max,$answer);
  my $id = $Apache::inputtags::response['-1'];      } elsif ( $target eq 'grade') {
  $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.submission"}=$response;        if ( defined $ENV{'form.submitted'}) {
  &Apache::lonxml::debug("submitted a $response<br>\n");   my $response = $ENV{'form.HWVAL'.$Apache::inputtags::response['-1']};
  if ($response == $answer) {   if ( $response =~ /[^\s]/) {
   $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}='EXACT_ANS';    my $id = $Apache::inputtags::response['-1'];
  } else {    $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.submission"}=$response;
   $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}='INCORRECT';    &Apache::lonxml::debug("submitted a $response<br />\n");
     if ($response == $answer) {
       $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}='EXACT_ANS';
     } else {
       $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}='INCORRECT';
     }
  }   }
       }        }
     }      }
Line 68  sub end_foilgroup { Line 71  sub end_foilgroup {
   return $result;    return $result;
 }  }
   
   sub getfoilcounts {
     my ($parstack,$safeeval)=@_;
     my $rrargs ='';
     if ( $#$parstack > 0 ) { $rrargs=$$parstack['-2']; }
     my $max = &Apache::run::run("{$rrargs;".'return $max}',$safeeval);
     my @names = @{ $Apache::response::foilgroup{'names'} };
     my $truecnt=0;
     my $falsecnt=0;
     my $name;
   
     foreach $name (@names) {
       if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
         $truecnt++;
       } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
         $falsecnt++;
       }
     }
     return ($truecnt,$falsecnt,$max);
   }
   
 sub displayfoils {  sub displayfoils {
   my ($max,$answer)=@_;    my ($max,$answer)=@_;
   my @names = @{ $Apache::response::foilgroup{'names'} };    my @names = @{ $Apache::response::foilgroup{'names'} };
Line 77  sub displayfoils { Line 100  sub displayfoils {
   my $name;    my $name;
   
   foreach $name (@names) {    foreach $name (@names) {
     #result.="<br><b>$name</b> is <i> $Apache::response::foilgroup{$name.'.value'} </i>";      #result.="<br /><b>$name</b> is <i> $Apache::response::foilgroup{$name.'.value'} </i>";
     if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {      if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
       push (@truelist,$name);        push (@truelist,$name);
     } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {      } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
Line 98  sub displayfoils { Line 121  sub displayfoils {
     push (@whichfalse,$afalse);      push (@whichfalse,$afalse);
   }    }
   splice(@whichfalse,$answer,0,$truelist[$whichtrue]);    splice(@whichfalse,$answer,0,$truelist[$whichtrue]);
   my $temp=0;  
   &Apache::lonxml::debug("the true statement is $answer");    &Apache::lonxml::debug("the true statement is $answer");
   foreach $name (@whichfalse) {    if ($Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"} =~ /^correct/ ) {
     $result.="<br /><input type=\"radio\" name=\"HWVAL$Apache::inputtags::response['-1']\" value=\"$temp\">".$Apache::response::foilgroup{$name.'.text'}."</input>\n";      foreach $name (@whichfalse) {
     $temp++;        $result.="<br />";
         if ($Apache::response::foilgroup{$name.'.value'} eq 'true') { 
    $result.='Correct';
         } else {
    $result.='Incorrect';
         }
         $result.=":".$Apache::response::foilgroup{$name.'.text'}."</input>\n";
       }
     } else {
       my $temp=0;
       foreach $name (@whichfalse) {
         $result.="<br /><input type=\"radio\" name=\"HWVAL$Apache::inputtags::response['-1']\" value=\"$temp\">".$Apache::response::foilgroup{$name.'.text'}."</input>\n";
         $temp++;
       }
   }    }
   return $result."<br />";    return $result."<br />";
 }  }

Removed from v.1.5  
changed lines
  Added in v.1.12


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