Annotation of loncom/homework/caparesponse/caparesponse.pm, revision 1.9
1.3 albertel 1: # The LearningOnline Network with CAPA
2: # caparesponse definition
3:
4: package Apache::caparesponse;
5: use strict;
1.4 albertel 6: use capa;
1.3 albertel 7:
8: sub BEGIN {
9: &Apache::lonxml::register('Apache::caparesponse',('caparesponse'));
10: }
11:
1.7 albertel 12: $Apache::caparesponse::result='';
1.3 albertel 13: sub start_caparesponse {
1.7 albertel 14: my $envkey;
15:
1.8 albertel 16: #foreach $envkey (sort keys %ENV) {
17: # Apache::lonxml::debug("$envkey ---- $ENV{$envkey}<br>");
18: #}
1.7 albertel 19:
1.8 albertel 20: #Apache::lonxml::debug("\n<br>\nreal caparesponse<br>\n");
1.3 albertel 21: }
22:
23: sub end_caparesponse {
1.7 albertel 24: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
25: if ( defined $ENV{'form.'.$ENV{'form.request.prefix'}.'submit'}) {
26: $Apache::caparesponse::result='';
27: $safeeval->share('&caparesponse_capa_check_answer');
28: $safeeval->share('$Apache::caparesponse::result');
29: my $response = $ENV{'form.'.$ENV{'form.request.prefix'}.'HWVAL'.$Apache::inputtags::curvalue};
1.9 ! albertel 30: #Apache::lonxml::debug("submitted a $response<br>\n");
! 31: #Apache::lonxml::debug($$parstack[$#$parstack] . "\n<br>");
1.7 albertel 32: my $expression="caparesponse_check $response $$parstack[$#$parstack];";
1.9 ! albertel 33: #&Apache::run::run($expression,$safeeval);
1.7 albertel 34:
1.9 ! albertel 35: #&Apache::lonxml::debug("\n<br>result:$Apache::caparesponse::result:<br>\n");
! 36: my $args ='';
! 37: if ( $#$parstack > -1 ) {
! 38: $args=$$parstack[$#$parstack];
! 39: }
! 40: my $answer = &Apache::run::run("{$args;".'return $answer}',$safeeval);
! 41: if ( $answer eq $response ) {
! 42: return "Correct, Computer had $answer<br></br>";
! 43: } else {
! 44: return "Incorrect, Computer had $answer<br></br>";
! 45: }
1.8 albertel 46: } else {
47: #return "The correct answer is ".&Apache::run::run("{$$parstack['-1'];".'return $answer}',$safeeval)."\n";
1.7 albertel 48: }
49: #Apache::lonxml::debug("\n<br>\nreal end caparesponse<br>\n");
1.8 albertel 50: return '';
1.3 albertel 51: }
52:
1.1 albertel 53: 1;
1.3 albertel 54: __END__
55:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>