version 1.6, 2001/01/12 15:32:29
|
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 39 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 ($truecnt,$falsecnt,$max) = &getfoilcounts($parstack,$safeeval); |
my $name; |
my $count=0; |
&setrandomnumber(); |
# we will add in 1 of the true statements |
my ($truecnt,$falsecnt,$max) = &getfoilcounts($parstack,$safeeval); |
if (($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; } |
my $count=0; |
my $answer = int(rand ($count)); |
# we will add in 1 of the true statements |
&Apache::lonxml::debug("Answer is $answer, $count from $max, $falsecnt"); |
if (($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; } |
if ($target eq 'web') { |
my $answer = int(rand ($count)); |
$result=&displayfoils($max,$answer); |
&Apache::lonxml::debug("Answer is $answer, $count from $max, $falsecnt"); |
} elsif ( $target eq 'grade') { |
if ($target eq 'web') { |
if ( defined $ENV{'form.submit'}) { |
$result=&displayfoils($max,$answer); |
my $response = $ENV{'form.HWVAL'.$Apache::inputtags::response['-1']}; |
} elsif ( $target eq 'grade') { |
if ( $response =~ /[^\s]/) { |
if ( defined $ENV{'form.submitted'}) { |
my $id = $Apache::inputtags::response['-1']; |
my $response = $ENV{'form.HWVAL'.$Apache::inputtags::response['-1']}; |
$Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.submission"}=$response; |
if ( $response =~ /[^\s]/) { |
&Apache::lonxml::debug("submitted a $response<br>\n"); |
my $id = $Apache::inputtags::response['-1']; |
if ($response == $answer) { |
$Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.submission"}=$response; |
$Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}='EXACT_ANS'; |
&Apache::lonxml::debug("submitted a $response<br />\n"); |
} else { |
if ($response == $answer) { |
$Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}='INCORRECT'; |
$Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}='EXACT_ANS'; |
|
} else { |
|
$Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}='INCORRECT'; |
|
} |
} |
} |
} |
} |
} |
} |
Line 100 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 121 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 />"; |
} |
} |