Annotation of loncom/homework/caparesponse/caparesponse.pm, revision 1.12
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.12 ! albertel 14: my ($target,$token,$parstack,$parser,$safeeval)=@_;
! 15: my $args ='';
! 16: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
! 17: my $id = &Apache::run::run("{$args;".'return $id}',$safeeval);
! 18: push (@Apache::inputtags::response,$id);
! 19:
! 20: #my $envkey;
1.8 albertel 21: #foreach $envkey (sort keys %ENV) {
22: # Apache::lonxml::debug("$envkey ---- $ENV{$envkey}<br>");
23: #}
24: #Apache::lonxml::debug("\n<br>\nreal caparesponse<br>\n");
1.3 albertel 25: }
26:
27: sub end_caparesponse {
1.7 albertel 28: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.12 ! albertel 29: my $result = '';
1.7 albertel 30: if ( defined $ENV{'form.'.$ENV{'form.request.prefix'}.'submit'}) {
31: $Apache::caparesponse::result='';
1.11 albertel 32: $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
1.12 ! albertel 33: my $response = $ENV{'form.HWVAL'.$Apache::inputtags::curvalue};
! 34: $Apache::lonhomework::results{"resource.submission.part$Apache::inputtags::part['-1'].response$Apache::inputtags::response['-1']"}=$response;
1.11 albertel 35: &Apache::lonxml::debug("submitted a $response<br>\n");
36: &Apache::lonxml::debug($$parstack[$#$parstack] . "\n<br>");
1.12 ! albertel 37: my $tol=$Apache::inputtags::{'tol'};
! 38: my $expression="&caparesponse_check('".$response."','".
! 39: $$parstack[$#$parstack].
! 40: ';my $tol='.$Apache::inputtags::{'tol'}.
! 41: "');";
! 42: $result = &Apache::run::run($expression,$safeeval);
! 43:
! 44: &Apache::lonxml::debug("\n<br>result:$Apache::caparesponse::result:$result:$Apache::lonxml::curdepth<br>\n");
1.7 albertel 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.12 ! albertel 50: pop @Apache::inputtags::part;
1.8 albertel 51: return '';
1.3 albertel 52: }
53:
1.1 albertel 54: 1;
1.3 albertel 55: __END__
56:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>