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