Annotation of loncom/homework/radiobuttonresponse.pm, revision 1.4
1.1 albertel 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 {
1.3 albertel 10: &Apache::lonxml::register('Apache::radiobuttonresponse',('radiobuttonresponse'));
1.1 albertel 11: }
12:
13: sub start_radiobuttonresponse {
1.4 ! albertel 14: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.3 albertel 15: #when in a radiobutton response use these
16: &Apache::lonxml::register('Apache::radiobuttonresponse',('foilgroup','foil'));
1.4 ! albertel 17: my $id = &Apache::response::start_response($parstack,$safeeval);
! 18: return '';
1.1 albertel 19: }
20:
21: sub end_radiobuttonresponse {
1.4 ! albertel 22: &Apache::response::end_response;
! 23: return '';
1.1 albertel 24: }
25:
26: %Apache::response::foilgroup={};
27: sub start_foilgroup {
28: %Apache::response::foilgroup={};
29: }
30:
1.4 ! albertel 31: #FIXME needs to stablely do random picks
1.1 albertel 32: sub end_foilgroup {
33: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
34: my $name;
35: my $result;
1.3 albertel 36: my @names = @{ $Apache::response::foilgroup{'names'} };
37: my @truelist;
38: my @falselist;
1.4 ! albertel 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);
1.3 albertel 44: foreach $name (@names) {
1.2 albertel 45: $result.="<br><b>$name</b> is <i> $Apache::response::foilgroup{$name.'.value'} </i>";
1.3 albertel 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: }
1.1 albertel 54: }
1.4 ! albertel 55: my $rrargs ='';
! 56: if ( $#$parstack > 0 ) { $rrargs=$$parstack['-2']; }
! 57: my $max = &Apache::run::run("{$rrargs;".'return $max}',$safeeval);
1.3 albertel 58: my $whichtrue = rand $#truelist;
1.4 ! albertel 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: }
1.1 albertel 75: return $result;
76: }
77:
78: sub start_foil {
1.4 ! albertel 79: &Apache::lonxml::debug("redirection be $Apache::lonxml::redirection");
! 80: $Apache::lonxml::redirection--;
1.1 albertel 81: }
82:
83: sub end_foil {
84: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.3 albertel 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:
1.4 ! albertel 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: }
1.1 albertel 101: return '';
102: }
103:
104: 1;
105: __END__
106:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>