File:  [LON-CAPA] / loncom / homework / radiobuttonresponse.pm
Revision 1.3: download - view: text, annotated - select for diffs
Mon Jan 8 22:06:48 2001 UTC (23 years, 3 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- moving along <foil> looks good foilgroup> is now picking proper items

    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:   #when in a radiobutton response use these
   15:   &Apache::lonxml::register('Apache::radiobuttonresponse',('foilgroup','foil'));
   16: }
   17: 
   18: sub end_radiobuttonresponse {
   19: }
   20: 
   21: %Apache::response::foilgroup={};
   22: sub start_foilgroup {
   23:   %Apache::response::foilgroup={};
   24: }
   25: 
   26: sub end_foilgroup {
   27:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
   28:   my $name;
   29:   my $result;
   30:   my @names = @{ $Apache::response::foilgroup{'names'} };
   31:   my @truelist;
   32:   my @falselist;
   33:   foreach $name (@names) {
   34:     $result.="<br><b>$name</b> is <i> $Apache::response::foilgroup{$name.'.value'} </i>";
   35:     if ($Apache::response::foilgroup{$name.'.value'} eq 'true') {
   36:       push (@truelist,$name);
   37:     } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') {
   38:       push (@falselist,$name);
   39:     } elsif ($Apache::response::foilgroup{$name.'.value'} eq 'unused') {
   40:     } else {
   41:       &Apache::lonxml::error("Unknow state $Apache::response::foilgroup{$name.'.value'} for $name in <foilgroup>");
   42:     }
   43:   }
   44:   my $whichtrue = rand $#truelist;
   45:   return $result;
   46: }
   47: 
   48: sub start_foil {
   49:   $Apache::lonxml::redirection++;
   50: }
   51: 
   52: sub end_foil {
   53:   my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
   54:   if ($target eq 'web' || $target eq 'grade') {
   55:     my $args ='';
   56:     if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
   57:     my $name = &Apache::run::run("{$args;".'return $name}',$safeeval);
   58:     push @{ $Apache::response::foilgroup{'names'} }, $name;
   59:     my $value = &Apache::run::run("{$args;".'return $value}',$safeeval);
   60:     $Apache::response::foilgroup{"$name.value"} = $value;
   61:     $Apache::response::foilgroup{"$name.text"} = $Apache::lonxml::outputstack;
   62:   }
   63:   
   64:   $Apache::lonxml::redirection--;
   65:   return '';
   66: }
   67: 
   68: 1;
   69: __END__
   70:  

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