File:  [LON-CAPA] / loncom / homework / externalresponse.pm
Revision 1.12: download - view: text, annotated - select for diffs
Mon Oct 15 09:47:29 2007 UTC (16 years, 7 months ago) by foxr
Branches: MAIN
CVS tags: version_2_6_1, version_2_6_0, version_2_5_99_1, version_2_5_99_0, HEAD
BZ 4074  Ensure the bubble lines chunk of the analysis hash gets
keyed by the concatenation of partid.resopnseid.

    1: # The LearningOnline Network with CAPA
    2: # external style responses
    3: #
    4: # $Id: externalresponse.pm,v 1.12 2007/10/15 09:47:29 foxr Exp $
    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: 
   29: package Apache::externalresponse;
   30: use strict;
   31: use HTTP::Request::Common;
   32: use Apache::loncapagrade;
   33: use Apache::lonnet;
   34: 
   35: BEGIN {
   36:     &Apache::lonxml::register('Apache::externalresponse',('externalresponse'));
   37: }
   38: 
   39: #FIXME
   40: # send of response params and their current values (form good enough?
   41: # what parameters to send?)
   42: # Need to get returned message displayed 
   43: sub start_externalresponse {
   44:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   45:     my $result;
   46:     my $id = &Apache::response::start_response($parstack,$safeeval);
   47: 
   48:     if ($target eq 'edit') {
   49:   	$result .=&Apache::edit::tag_start($target,$token);
   50: 	$result .=&Apache::edit::text_arg('URL:','url',$token,60).'<br />';
   51: 	$result .=&Apache::edit::text_arg('Answer:','answer',$token);
   52: 	$result .=&Apache::edit::text_arg('Form:','form',$token);
   53: 	$result .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
   54:     } elsif ($target eq 'modified') {
   55: 	my $constructtag =
   56: 	    &Apache::edit::get_new_args($token,$parstack,$safeeval,
   57: 					'answer','form','url');
   58: 	if ($constructtag) {
   59: 	    $result = &Apache::edit::rebuild_tag($token);
   60: 	}
   61:     } elsif ($target eq 'meta') {
   62:   	$result=&Apache::response::meta_package_write('externalresponse');
   63:     }
   64:     
   65:     return $result;
   66: }
   67: 
   68: sub end_externalresponse {
   69:     my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   70:     my $result;
   71:     my $part=$Apache::inputtags::part;
   72:     my $id = $Apache::inputtags::response['-1'];
   73:     my $increment     = 1;
   74:     if ($target eq 'grade') {
   75: 	if (  &Apache::response::submitted('scantron') ) {
   76: 	    my $increment=&Apache::response::scored_response($part,$id);
   77: 	} elsif ( &Apache::response::submitted() ) {
   78: 	    my $response = &Apache::response::getresponse();
   79: 	    if ( $response =~ /[^\s]/) {
   80: 		my $url = &Apache::lonxml::get_param('url',$parstack,$safeeval);
   81: 		my $answer = &Apache::lonxml::get_param('answer',$parstack,$safeeval);
   82: 		my %form = &Apache::lonxml::get_param_var('form',$parstack,$safeeval);
   83: 		$form{'LONCAPA_student_response'}=$response;
   84: 		$form{'LONCAPA_correct_answer'}=$answer;
   85: 		$form{'LONCAPA_language'}=
   86: 		    &Apache::lonnet::metadata($ENV{'REQUEST_URI'},'language');
   87: 		&Apache::lonxml::debug("Asking $url, with:");
   88: 		&Apache::lonhomework::showhash(%form);
   89: 		my $ua = LWP::UserAgent->new;
   90: 		my $res = $ua->request(POST $url, \%form);
   91: 		my %previous = &Apache::response::check_for_previous($response,
   92: 								     $part,$id);
   93: 		%Apache::loncapagrade::results=();
   94: 		$Apache::lonhomework::results{"resource.$part.$id.submission"}=$response;
   95: 		if ($res->is_error()) {
   96: 		    $Apache::loncapagrade::results{'awarddetail'}='ERROR';
   97: 		} else {
   98: 		    &Apache::lonxml::register('Apache::loncapagrade',
   99: 					      ('loncapagrade'));
  100: 		    @Apache::scripttag::parser_env = @_;
  101: 		    my $result=&Apache::scripttag::xmlparse($res->{_content});
  102: 		    &Apache::lonxml::debug("Got a result of :$result:");
  103: 		}
  104: 		foreach my $key (keys(%Apache::loncapagrade::results)) {
  105: 		    $Apache::lonhomework::results{"resource.$part.$id.$key"}=
  106: 			$Apache::loncapagrade::results{$key};
  107: 		}
  108: 		&Apache::response::handle_previous(\%previous,
  109: 						   $Apache::loncapagrade::results{'awarddetail'});
  110: 		&Apache::lonxml::debug("response of");
  111: 		&Apache::lonhomework::showhash(%$res);
  112: 		&Apache::lonxml::debug("capagrade of");
  113: 		&Apache::lonhomework::showhash(%Apache::loncapagrade::results);
  114: 		&Apache::lonxml::debug("results of");
  115: 		&Apache::lonhomework::showhash(%Apache::lonhomework::results);
  116: 	    }
  117: 	}
  118:     }
  119:     if ($target eq 'web') {
  120: 	&Apache::response::setup_prior_tries_hash(\&format_prior_response);
  121:     }
  122: 
  123:     if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
  124: 	$target eq 'tex' || $target eq 'analyze') {
  125: 	&Apache::lonxml::increment_counter($increment, "$part.$id");
  126: 
  127: 	if ($target eq 'analyze') {
  128: 	    &Apache::lonhomework::set_bubble_lines();
  129: 	}
  130:     }
  131:     &Apache::response::end_response();
  132:     return $result;
  133: }
  134: 
  135: sub format_prior_response {
  136:     my ($mode,$answer) =@_;
  137:     return '<span class="LC_prior_external">'.
  138: 	    &HTML::Entities::encode($answer,'"<>&').'</span>';
  139: }
  140: 
  141: 1;
  142: __END__
  143: 
  144: 

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