Annotation of loncom/homework/caparesponse/caparesponse.pm, revision 1.15
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.13 albertel 32: if ( defined $ENV{'form.submit'}) {
1.7 albertel 33: $Apache::caparesponse::result='';
1.11 albertel 34: $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
1.12 albertel 35: my $response = $ENV{'form.HWVAL'.$Apache::inputtags::curvalue};
1.15 ! albertel 36: $Apache::lonhomework::results{"resource.submission.$Apache::inputtags::part.$Apache::inputtags::response['-1']"}=$response;
1.11 albertel 37: &Apache::lonxml::debug("submitted a $response<br>\n");
38: &Apache::lonxml::debug($$parstack[$#$parstack] . "\n<br>");
1.12 albertel 39: my $expression="&caparesponse_check('".$response."','".
40: $$parstack[$#$parstack].
1.14 albertel 41: ';my $tol="'.$Apache::inputtags::params{'tol'}.'"'.
42: ';my $sig="'.$Apache::inputtags::params{'sig'}.'"'.
1.12 albertel 43: "');";
44: $result = &Apache::run::run($expression,$safeeval);
1.15 ! albertel 45: my ($ad) = split /:/ , $result;
! 46: $Apache::lonhomework::results{"resource.awarddetail.$Apache::inputtags::part.$Apache::inputtags::response['-1']"}=$ad;
1.14 albertel 47: &Apache::lonxml::debug("$expression");
1.12 albertel 48: &Apache::lonxml::debug("\n<br>result:$Apache::caparesponse::result:$result:$Apache::lonxml::curdepth<br>\n");
1.7 albertel 49:
1.8 albertel 50: } else {
51: #return "The correct answer is ".&Apache::run::run("{$$parstack['-1'];".'return $answer}',$safeeval)."\n";
1.7 albertel 52: }
53: #Apache::lonxml::debug("\n<br>\nreal end caparesponse<br>\n");
1.15 ! albertel 54: pop @Apache::inputtags::response;
1.8 albertel 55: return '';
1.3 albertel 56: }
57:
1.1 albertel 58: 1;
1.3 albertel 59: __END__
60:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>