Annotation of loncom/homework/caparesponse/caparesponse.pm, revision 1.18
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);
1.14 albertel 18: if ($id eq '') { $id = $Apache::lonxml::curdepth; }
1.12 albertel 19: push (@Apache::inputtags::response,$id);
1.15 albertel 20: push (@Apache::inputtags::responselist,$id);
1.13 albertel 21: return '';
1.12 albertel 22: #my $envkey;
1.8 albertel 23: #foreach $envkey (sort keys %ENV) {
24: # Apache::lonxml::debug("$envkey ---- $ENV{$envkey}<br>");
25: #}
26: #Apache::lonxml::debug("\n<br>\nreal caparesponse<br>\n");
1.3 albertel 27: }
28:
29: sub end_caparesponse {
1.7 albertel 30: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.12 albertel 31: my $result = '';
1.16 albertel 32: if ( $target eq 'grade' ) {
33: if ( defined $ENV{'form.submit'}) {
34: $Apache::caparesponse::result='';
35: $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
36: my $response = $ENV{'form.HWVAL'.$Apache::inputtags::curvalue};
1.18 ! albertel 37: if ( $response =~ /[^\s]/) {
! 38: $Apache::lonhomework::results{"resource.submission.$Apache::inputtags::part.$Apache::inputtags::response['-1']"}=$response;
! 39: &Apache::lonxml::debug("submitted a $response<br>\n");
! 40: &Apache::lonxml::debug($$parstack[$#$parstack] . "\n<br>");
! 41: my $expression="&caparesponse_check('".$response."','".
! 42: $$parstack[$#$parstack].
! 43: ';my $tol="'.$Apache::inputtags::params{'tol'}.'"'.
! 44: ';my $sig="'.$Apache::inputtags::params{'sig'}.'"'.
! 45: "');";
! 46: $result = &Apache::run::run($expression,$safeeval);
! 47: my ($ad) = split /:/ , $result;
! 48: $Apache::lonhomework::results{"resource.awarddetail.$Apache::inputtags::part.$Apache::inputtags::response['-1']"}=$ad;
! 49: &Apache::lonxml::debug("$expression");
! 50: &Apache::lonxml::debug("\n<br>result:$Apache::caparesponse::result:$result:$Apache::lonxml::curdepth<br>\n");
! 51: }
1.16 albertel 52: }
1.8 albertel 53: } else {
1.17 albertel 54: #$result .= "The correct answer is ".&Apache::run::run("{$$parstack['-1'];".'return $answer}',$safeeval)."\n";
1.7 albertel 55: }
56: #Apache::lonxml::debug("\n<br>\nreal end caparesponse<br>\n");
1.15 albertel 57: pop @Apache::inputtags::response;
1.16 albertel 58: return $result;
1.3 albertel 59: }
60:
1.1 albertel 61: 1;
1.3 albertel 62: __END__
63:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>