File:  [LON-CAPA] / loncom / homework / radiobuttonresponse.pm
Revision 1.4: download - view: text, annotated - select for diffs
Thu Jan 11 22:17:30 2001 UTC (23 years, 3 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- radiobuttons appear

    1: # The LearningOnline Network with CAPA
    2: # mutliple choice style responses
    3: 
    4: # 11/23,11/24,11/28 Gerd Kortemeyer
    5: 
    6: package Apache::radiobuttonresponse;
    7: use strict;
    8: 
    9: sub BEGIN {
   10:   &Apache::lonxml::register('Apache::radiobuttonresponse',('radiobuttonresponse'));
   11: }
   12: 
   13: sub start_radiobuttonresponse {
   14:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
   15:   #when in a radiobutton response use these
   16:   &Apache::lonxml::register('Apache::radiobuttonresponse',('foilgroup','foil'));
   17:   my $id = &Apache::response::start_response($parstack,$safeeval);
   18:   return '';
   19: }
   20: 
   21: sub end_radiobuttonresponse {
   22:   &Apache::response::end_response;
   23:   return '';
   24: }
   25: 
   26: %Apache::response::foilgroup={};
   27: sub start_foilgroup {
   28:   %Apache::response::foilgroup={};
   29: }
   30: 
   31: #FIXME needs to stablely do random picks
   32: sub end_foilgroup {
   33:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
   34:   my $name;
   35:   my $result;
   36:   my @names = @{ $Apache::response::foilgroup{'names'} };
   37:   my @truelist;
   38:   my @falselist;
   39:   my $rndseed=&Apache::lonnet::rndseed();
   40:   $rndseed=$rndseed
   41:     +&Apache::lonnet::numval($Apache::inputtags::part)
   42:       +&Apache::lonnet::numval($Apache::inputtags::response['-1']);
   43:   srand($rndseed*10);
   44:   foreach $name (@names) {
   45:     $result.="<br><b>$name</b> is <i> $Apache::response::foilgroup{$name.'.value'} </i>";
   46:     if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
   47:       push (@truelist,$name);
   48:     } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
   49:       push (@falselist,$name);
   50:     } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'unused') {
   51:     } else {
   52:       &Apache::lonxml::error("Unknow state $Apache::response::foilgroup{$name.'.value'} for $name in <foilgroup>");
   53:     }
   54:   }
   55:   my $rrargs ='';
   56:   if ( $#$parstack > 0 ) { $rrargs=$$parstack['-2']; }
   57:   my $max = &Apache::run::run("{$rrargs;".'return $max}',$safeeval);
   58:   my $whichtrue = rand $#truelist;
   59:   &Apache::lonxml::debug("Max is $max, From $#truelist elms, picking $whichtrue");
   60:   my @whichfalse =();
   61:   my $temp=0;
   62:   while ((($#whichfalse+2) < $max) && ($#falselist > -1)) {
   63:     my $afalse=rand $#falselist;
   64:     &Apache::lonxml::debug("From $#falselist elms, picking $afalse");
   65:     $afalse=splice(@falselist,$afalse,1);
   66:     &Apache::lonxml::debug("Picked $afalse");
   67:     push (@whichfalse,$afalse);
   68:   }
   69:   my $where = rand $max;
   70:   splice(@whichfalse,$where,0,$truelist[$whichtrue]);
   71:   my $temp;
   72:   foreach $temp (@whichfalse) {
   73:     $result.='<input type="radio" name="bob">'.$Apache::response::foilgroup{$temp.'.text'}."</input><br />\n";
   74:   }
   75:   return $result;
   76: }
   77: 
   78: sub start_foil {
   79:   &Apache::lonxml::debug("redirection be  $Apache::lonxml::redirection");
   80:   $Apache::lonxml::redirection--;
   81: }
   82: 
   83: sub end_foil {
   84:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
   85:   if ($target eq 'web' || $target eq 'grade') {
   86:     my $args ='';
   87:     if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
   88:     my $name = &Apache::run::run("{$args;".'return $name}',$safeeval);
   89:     push @{ $Apache::response::foilgroup{'names'} }, $name;
   90:     my $value = &Apache::run::run("{$args;".'return $value}',$safeeval);
   91:     $Apache::response::foilgroup{"$name.value"} = $value;
   92:     $Apache::response::foilgroup{"$name.text"} = $Apache::lonxml::outputstack;
   93:   }
   94:   
   95:   $Apache::lonxml::redirection++;
   96:   &Apache::lonxml::debug("redirection is  $Apache::lonxml::redirection");
   97:   if ($Apache::lonxml::redirection == 1) { 
   98:     &Apache::lonxml::debug("reset $Apache::lonxml::outputstack");
   99:     $Apache::lonxml::outputstack=''; 
  100:   }
  101:   return '';
  102: }
  103: 
  104: 1;
  105: __END__
  106:  

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