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

1.1       albertel    1: # The LearningOnline Network with CAPA
                      2: # external style responses
                      3: #
1.3     ! albertel    4: # $Id: externalresponse.pm,v 1.2 2002/09/23 07:07:02 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: #
                     28: # 1/26 Guy
                     29: package Apache::externalresponse;
                     30: use strict;
                     31: use HTTP::Request::Common;
                     32: use Apache::loncapagrade;
                     33: 
                     34: BEGIN {
                     35:   &Apache::lonxml::register('Apache::externalresponse',('externalresponse'));
                     36: }
                     37: 
                     38: #FIXME
                     39: # send of response params and there current values
                     40: # accept a string to be printed out (Where does it get shown?) (.message)
                     41: # need to get a correct answer from somewhere (probably here since randomized)
                     42: sub start_externalresponse {
                     43:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     44:   my $result;
                     45:   my $id = &Apache::response::start_response($parstack,$safeeval);
                     46:   return $result;
                     47: }
                     48: 
                     49: sub end_externalresponse {
                     50:   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
                     51:   my $result;
                     52:   if ($target eq 'grade') {
                     53:     if ( defined $ENV{'form.submitted'}) {
                     54:       my $id = $Apache::inputtags::response['-1'];
1.3     ! albertel   55:       my $response = $ENV{'form.HWVAL_'.$id};
1.1       albertel   56:       if ( $response =~ /[^\s]/) {
                     57: 	my $url = &Apache::lonxml::get_param('url',$parstack,$safeeval);
                     58: 	my $answer = &Apache::lonxml::get_param('answer',$parstack,$safeeval);
                     59: 	my %form = &Apache::lonxml::get_param_var('form',$parstack,$safeeval);
                     60: 	$form{'LONCAPA_student_response'}=$response;
                     61: 	$form{'LONCAPA_correct_answer'}=$answer;
                     62: 	$form{'LONCAPA_language'}=
1.2       albertel   63: 	  &Apache::lonnet::metadata($ENV{'REQUEST_URI'},'language');
1.1       albertel   64: 	&Apache::lonxml::debug("Asking $url, with:");
                     65: 	&Apache::lonhomework::showhash(%form);
                     66: 	my $ua = LWP::UserAgent->new;
                     67: 	my $res = $ua->request(POST $url, \%form);
                     68: 	my $partid = $Apache::inputtags::part;
                     69: 	my $id = $Apache::inputtags::response['-1'];
                     70: 	my %previous = &Apache::response::check_for_previous($response,
                     71: 							     $partid,$id);
                     72: 	%Apache::loncapagrade::results=();
                     73:         if ($res->{_rc} != '200') {
                     74: 	  $Apache::loncapagrade::results{'awardetail'}='ERROR';
                     75: 	} else {
                     76: 	  &Apache::lonxml::register('Apache::loncapagrade',('loncapagrade'));
                     77: 	  my $result=&Apache::scripttag::xmlparse($res->{_content});
                     78: 	  &Apache::lonxml::debug("Got a result of :$result:");
                     79: 	}
                     80: 	foreach my $key (%Apache::loncapagrade::results) {
                     81: 	  $Apache::lonhomework::results{"resource.$partid.$id.$key"}=
                     82: 	    $Apache::loncapagrade::results{$key};
                     83: 	}
                     84: 	&Apache::response::handle_previous(\%previous,
                     85: 		    $Apache::loncapagrade::results{'awarddetail'});
                     86: 	&Apache::lonxml::debug("response of");
                     87: 	&Apache::lonhomework::showhash(%$res);
                     88: 	&Apache::lonhomework::showhash(%Apache::loncapagrade::results);
                     89:       }
                     90:     }
                     91:   }
                     92:   &Apache::response::end_response;
                     93:   return $result;
                     94: }
                     95: 
                     96: 1;
                     97: __END__
                     98: 
                     99: 

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