Annotation of loncom/homework/caparesponse/caparesponse.pm, revision 1.23
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 {
1.21 albertel 9: &Apache::lonxml::register('Apache::caparesponse',('caparesponse','numericalresponse'));
1.3 albertel 10: }
11:
12: sub start_caparesponse {
1.12 albertel 13: my ($target,$token,$parstack,$parser,$safeeval)=@_;
1.19 albertel 14: my $id = &Apache::response::start_response($parstack,$safeeval);
1.13 albertel 15: return '';
1.3 albertel 16: }
17:
18: sub end_caparesponse {
1.7 albertel 19: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.12 albertel 20: my $result = '';
1.16 albertel 21: if ( $target eq 'grade' ) {
22: if ( defined $ENV{'form.submit'}) {
23: $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
1.19 albertel 24: my $response = $ENV{'form.HWVAL'.$Apache::inputtags::response['-1']};
1.18 albertel 25: if ( $response =~ /[^\s]/) {
1.23 ! albertel 26: my $id = $Apache::inputtags::response['-1'];
! 27: my $previous= &Apache::response::check_for_previous($response,$id,$response);
1.22 albertel 28: if ( $previous ) {
29: $result = 'PREVIOUSLY_USED';
30: } else {
31: $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$Apache::inputtags::response['-1'].submission"}=$response;
32: &Apache::lonxml::debug("submitted a $response<br>\n");
33: &Apache::lonxml::debug($$parstack[$#$parstack] . "\n<br>");
34: my $expression="&caparesponse_check('".$response."','".
35: $$parstack[$#$parstack].
36: ';my $tol="'.$Apache::inputtags::params{'tol'}.'"'.
37: ';my $sig="'.$Apache::inputtags::params{'sig'}.'"'.
38: "');";
39: $result = &Apache::run::run($expression,$safeeval);
40: my ($ad) = split /:/ , $result;
41: $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$Apache::inputtags::response['-1'].awarddetail"}=$ad;
42: &Apache::lonxml::debug("$expression");
43: &Apache::lonxml::debug("\n<br>result:$result:$Apache::lonxml::curdepth<br>\n");
44: }
1.18 albertel 45: }
1.16 albertel 46: }
1.8 albertel 47: } else {
1.17 albertel 48: #$result .= "The correct answer is ".&Apache::run::run("{$$parstack['-1'];".'return $answer}',$safeeval)."\n";
1.7 albertel 49: }
50: #Apache::lonxml::debug("\n<br>\nreal end caparesponse<br>\n");
1.19 albertel 51: &Apache::response::end_response;
1.16 albertel 52: return $result;
1.21 albertel 53: }
54:
55: sub start_numericalresponse {
1.22 albertel 56: my ($target,$token,$parstack,$parser,$safeeval)=@_;
57: my $id = &Apache::response::start_response($parstack,$safeeval);
58: return '';
1.21 albertel 59: }
60:
61: sub end_numericalresponse {
1.22 albertel 62: my ($target,$token,$parstack,$parser,$safeeval,$style)=@_;
63: my $result = '';
64: if ( $target eq 'grade' ) {
65: if ( defined $ENV{'form.submit'}) {
66: $safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
67: my $response = $ENV{'form.HWVAL'.$Apache::inputtags::response['-1']};
68: if ( $response =~ /[^\s]/) {
1.23 ! albertel 69: my $id = $Apache::inputtags::response['-1'];
! 70: my $previous= &Apache::response::check_for_previous($response,$id,$response);
1.22 albertel 71: if ( $previous ) {
72: $result = 'PREVIOUSLY_USED';
73: } else {
74: $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$Apache::inputtags::response['-1'].submission"}=$response;
75: &Apache::lonxml::debug("submitted a $response<br>\n");
76: &Apache::lonxml::debug($$parstack[$#$parstack] . "\n<br>");
1.23 ! albertel 77: my $expression="&caparesponse_check_list('".$response."','".
1.22 albertel 78: $$parstack[$#$parstack].
79: ';my $tol="'.$Apache::inputtags::params{'tol'}.'"'.
80: ';my $sig="'.$Apache::inputtags::params{'sig'}.'"'.
81: "');";
82: $result = &Apache::run::run($expression,$safeeval);
1.23 ! albertel 83: my ($awards) = split /:/ , $result;
! 84: my ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
1.22 albertel 85: $Apache::lonhomework::results{"resource.$Apache::inputtags::part.$Apache::inputtags::response['-1'].awarddetail"}=$ad;
86: &Apache::lonxml::debug("$expression");
87: &Apache::lonxml::debug("\n<br>result:$Apache::caparesponse::result:$result:$Apache::lonxml::curdepth<br>\n");
88: }
89: }
90: }
91: }
92: &Apache::response::end_response;
93: return $result;
1.3 albertel 94: }
95:
1.1 albertel 96: 1;
1.3 albertel 97: __END__
98:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>