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