Annotation of loncom/homework/externalresponse.pm, revision 1.6

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # external style responses
                      3: #
1.6     ! albertel    4: # $Id: externalresponse.pm,v 1.5 2005/10/18 13:58:12 albertel Exp $
1.1       albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.6     ! albertel   28: 
1.1       albertel   29: package Apache::externalresponse;
                     30: use strict;
                     31: use HTTP::Request::Common;
                     32: use Apache::loncapagrade;
1.4       albertel   33: use Apache::lonnet;
1.1       albertel   34: 
                     35: BEGIN {
1.5       albertel   36:     &Apache::lonxml::register('Apache::externalresponse',('externalresponse'));
1.1       albertel   37: }
                     38: 
                     39: #FIXME
                     40: # send of response params and there current values
                     41: # accept a string to be printed out (Where does it get shown?) (.message)
                     42: # need to get a correct answer from somewhere (probably here since randomized)
                     43: sub start_externalresponse {
1.5       albertel   44:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     45:     my $result;
                     46:     my $id = &Apache::response::start_response($parstack,$safeeval);
                     47:     return $result;
1.1       albertel   48: }
                     49: 
                     50: sub end_externalresponse {
1.5       albertel   51:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     52:     my $result;
1.6     ! albertel   53:     my $part=$Apache::inputtags::part;
        !            54:     my $id = $Apache::inputtags::response['-1'];
        !            55:     my $increment     = 1;
1.5       albertel   56:     if ($target eq 'grade') {
1.6     ! albertel   57: 	if (  &Apache::response::submitted('scantron') ) {
        !            58: 	    my $increment=&Apache::response::scored_response($part,$id);
        !            59: 	} elsif ( &Apache::response::submitted() ) {
        !            60: 	    my $response = &Apache::response::getresponse();
1.5       albertel   61: 	    if ( $response =~ /[^\s]/) {
                     62: 		my $url = &Apache::lonxml::get_param('url',$parstack,$safeeval);
                     63: 		my $answer = &Apache::lonxml::get_param('answer',$parstack,$safeeval);
                     64: 		my %form = &Apache::lonxml::get_param_var('form',$parstack,$safeeval);
                     65: 		$form{'LONCAPA_student_response'}=$response;
                     66: 		$form{'LONCAPA_correct_answer'}=$answer;
                     67: 		$form{'LONCAPA_language'}=
                     68: 		    &Apache::lonnet::metadata($ENV{'REQUEST_URI'},'language');
                     69: 		&Apache::lonxml::debug("Asking $url, with:");
                     70: 		&Apache::lonhomework::showhash(%form);
                     71: 		my $ua = LWP::UserAgent->new;
                     72: 		my $res = $ua->request(POST $url, \%form);
                     73: 		my %previous = &Apache::response::check_for_previous($response,
1.6     ! albertel   74: 								     $part,$id);
1.5       albertel   75: 		%Apache::loncapagrade::results=();
1.6     ! albertel   76: 		$Apache::lonhomework::results{"resource.$part.$id.submission"}=$response;
1.5       albertel   77: 		if ($res->{_rc} != '200') {
1.6     ! albertel   78: 		    $Apache::loncapagrade::results{'awarddetail'}='ERROR';
1.5       albertel   79: 		} else {
1.6     ! albertel   80: 		    &Apache::lonxml::register('Apache::loncapagrade',
        !            81: 					      ('loncapagrade'));
1.5       albertel   82: 		    my $result=&Apache::scripttag::xmlparse($res->{_content});
                     83: 		    &Apache::lonxml::debug("Got a result of :$result:");
                     84: 		}
1.6     ! albertel   85: 		foreach my $key (keys(%Apache::loncapagrade::results)) {
        !            86: 		    $Apache::lonhomework::results{"resource.$part.$id.$key"}=
1.5       albertel   87: 			$Apache::loncapagrade::results{$key};
                     88: 		}
                     89: 		&Apache::response::handle_previous(\%previous,
                     90: 						   $Apache::loncapagrade::results{'awarddetail'});
                     91: 		&Apache::lonxml::debug("response of");
                     92: 		&Apache::lonhomework::showhash(%$res);
1.6     ! albertel   93: 		&Apache::lonxml::debug("capagrade of");
1.5       albertel   94: 		&Apache::lonhomework::showhash(%Apache::loncapagrade::results);
1.6     ! albertel   95: 		&Apache::lonxml::debug("results of");
        !            96: 		&Apache::lonhomework::showhash(%Apache::lonhomework::results);
1.5       albertel   97: 	    }
1.1       albertel   98: 	}
                     99:     }
1.6     ! albertel  100:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
        !           101: 	$target eq 'tex' || $target eq 'analyze') {
        !           102: 	&Apache::lonxml::increment_counter($increment);
        !           103:     }
        !           104:     &Apache::response::end_response();
1.5       albertel  105:     return $result;
1.1       albertel  106: }
                    107: 
                    108: 1;
                    109: __END__
                    110: 
                    111: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>