version 1.5, 2000/10/02 22:23:39
|
version 1.9, 2000/12/01 00:44:48
|
Line 5 package Apache::inputtags;
|
Line 5 package Apache::inputtags;
|
use strict; |
use strict; |
|
|
sub BEGIN { |
sub BEGIN { |
&Apache::lonxml::register('Apache::inputtags',('textline','answergroup')); |
&Apache::lonxml::register('Apache::inputtags',('textarea','textline','answergroup','datasubmission')); |
} |
} |
|
|
|
|
sub initialize_inputtags { |
sub initialize_inputtags { |
$Apache::inputtags::curvalue=0; |
@Apache::inputtags::input=(); |
|
@Apache::inputtags::response=(); |
|
@Apache::inputtags::responselist=(); |
|
@Apache::inputtags::answergroup=(); |
|
$Apache::inputtags::part=''; |
|
%Apache::inputtags::params=(); |
|
} |
|
|
|
sub start_textarea { |
|
my ($target,$token,$parstack,$parser,$safeeval)=@_; |
|
my $result = ""; |
|
$Apache::inputtags::curvalue++; |
|
if ($target eq 'web') { |
|
$result= '<textarea name="HWVAL'.$Apache::inputtags::curvalue.'" value="">'; |
|
} |
|
return $result; |
|
} |
|
|
|
sub end_textarea { |
|
my ($target,$token,$parstack,$parser,$safeeval)=@_; |
|
return "</textarea>"; |
} |
} |
|
|
sub start_textline { |
sub start_textline { |
my ($target,$token,$parstack,$parser,$safeeval)=@_; |
my ($target,$token,$parstack,$parser,$safeeval)=@_; |
my $result = ""; |
my $result = ""; |
$Apache::inputtags::curvalue++; |
$Apache::inputtags::curvalue++; |
|
my $args =''; |
|
if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; } |
|
my $size = &Apache::run::run("{$args;".'return $size}',$safeeval); |
|
if ($size eq '') { $size=20; } |
if ($target eq 'web') { |
if ($target eq 'web') { |
$result= '<input name="'.$ENV{'form.request.prefix'}.'HWVAL'.$Apache::inputtags::curvalue.'" value="">'; |
$result= '<input type="text" name="HWVAL'.$Apache::inputtags::curvalue.'" value="" size="'.$size.'">'; |
} |
} |
return $result; |
return $result; |
} |
} |
|
|
sub end_textline { |
sub end_textline { |
my ($target,$token,$parstack,$parser,$safeeval)=@_; |
my ($target,$token,$parstack,$parser,$safeeval)=@_; |
|
return ""; |
} |
} |
|
|
sub start_answergroup { |
sub start_answergroup { |
|
my ($target,$token,$parstack,$parser,$safeeval)=@_; |
|
my $args =''; |
|
if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; } |
|
my $id = &Apache::run::run("{$args;".'return $id}',$safeeval); |
|
push (@Apache::inputtags::answergroup,$id); |
|
if ($target == 'web') { |
|
|
|
} |
|
return ''; |
} |
} |
|
|
sub end_answergroup { |
sub end_answergroup { |
my ($target,$token,$parstack,$parser,$safeeval)=@_; |
my ($target,$token,$parstack,$parser,$safeeval)=@_; |
|
return ''; # <answergroup> has ben deprecated |
|
my $args =''; |
|
if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; } |
|
my $id = &Apache::run::run("{$args;".'return $id}',$safeeval); |
|
push (@Apache::inputtags::answergroup,$id); |
|
my $result=''; |
|
my $button='<input type="submit" name="submit" value="Submit All Answers">'; |
|
my $showbutton='1'; |
|
my $usedtry='1'; |
|
my $response=''; |
if ( $target == 'web' ) { |
if ( $target == 'web' ) { |
return '<input type="submit" name="'.$ENV{'form.request.prefix'}.'submit" value="Submit All Answers">'; |
if ( defined $ENV{'form.submit'}) { |
|
} |
|
if ($showbutton > 0) { $result.=$button } |
} |
} |
|
pop @Apache::inputtags::answergroup; |
|
return $result; |
|
} |
|
|
|
|
|
sub start_datasubmission { |
|
} |
|
|
|
sub end_datasubmission { |
|
my ($target,$token,$parstack,$parser,$safeeval)=@_; |
|
if ( $target == 'web' ) { |
|
return '<input type="submit" name="submit" value="Submit All Data">'; |
|
} |
|
} |
|
|
|
sub finalizeawards { |
|
my $result=''; |
|
my $award; |
|
if ($#_ == '-1') { $result = "NO_RESPONSE"; } |
|
foreach $award (@_) { if ($award eq '') {$result='MISSING_ANSWER'; last;}} |
|
if ($result eq '' ) { |
|
foreach $award (@_) { |
|
if ($award eq 'UNIT_FAIL' || |
|
$award eq 'NO_UNIT' || |
|
$award eq 'UNIT_NOTNEEDED') { |
|
$result=$award; last; |
|
} |
|
} |
|
} |
|
&Apache::lonxml::debug("1 $result"); |
|
if ($result eq '' ) { |
|
foreach $award (@_) { |
|
if ($award eq 'WANTED_NUMERIC' || |
|
$award eq 'BAD_FORMULA') {$result=$award; last;} |
|
} |
|
} |
|
&Apache::lonxml::debug("2 $result"); |
|
if ($result eq '' ) { |
|
foreach $award (@_) { if ($award eq 'SIG_FAIL') {$result=$award; last;} } |
|
} |
|
&Apache::lonxml::debug("3 $result"); |
|
if ($result eq '' ) { |
|
foreach $award (@_) { if ($award eq 'INCORRECT') {$result=$award; last;} } |
|
} |
|
&Apache::lonxml::debug("4 $result"); |
|
if ($result eq '' ) { |
|
foreach $award (@_) { if ($award eq 'APPROX_ANS') {$result=$award; last;} } |
|
} |
|
&Apache::lonxml::debug("5 $result"); |
|
if ($result eq '' ) { $result='EXACT_ANS'; } |
|
&Apache::lonxml::debug("6 $result"); |
|
return $result |
|
} |
|
|
|
sub grade { |
|
my ($target) = @_; |
|
my $id = $Apache::inputtags::part; |
|
my $result=''; |
|
my $button='<input type="submit" name="submit" value="Submit All Answers">'; |
|
my $showbutton='1'; |
|
my $usedtry='1'; |
|
my $response=''; |
|
if ( $target == 'web' ) { |
|
if ( defined $ENV{'form.submit'}) { |
|
my @awards = (); |
|
foreach $response (@Apache::inputtags::responselist) { |
|
my $value=$Apache::lonhomework::results{"response.awarddetail.$id.$response"}; |
|
if ( $value ne '' ) { |
|
&Apache::lonxml::debug("keep ing $value from $response for $id"); |
|
push (@awards,$value); |
|
} else { |
|
&Apache::lonxml::debug("skipping $value from $response for $id"); |
|
} |
|
} |
|
my $finalaward = &finalizeawards(@awards); |
|
&Apache::lonxml::debug("final award $finalaward"); |
|
} |
|
if ($showbutton > 0) { $result.=$button } |
|
} |
|
return $result; |
} |
} |
|
|
1; |
1; |