--- loncom/homework/externalresponse.pm 2014/12/07 02:48:55 1.30 +++ loncom/homework/externalresponse.pm 2017/05/23 03:07:34 1.33 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # external style responses # -# $Id: externalresponse.pm,v 1.30 2014/12/07 02:48:55 raeburn Exp $ +# $Id: externalresponse.pm,v 1.33 2017/05/23 03:07:34 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -40,6 +40,7 @@ use Apache::loncommon; use Apache::lonnavmaps; use Apache::essayresponse; use LONCAPA qw(:DEFAULT :match); +use LONCAPA::LWPReq; BEGIN { &Apache::lonxml::register('Apache::externalresponse',('externalresponse')); @@ -97,7 +98,8 @@ sub start_externalresponse { ($Apache::lonhomework::type eq 'anonsurveycred')) { $hiddendraft = ''; } else { - $result = &Apache::essayresponse::draft_row($part,$id,$ncol,$uploadedfiletypes); + $result = &Apache::essayresponse::draft_row($part,$id,$ncol,$uploadedfiletypes, + 'externalresponse'); } if ($ncol > 0) { $result .= &Apache::essayresponse::get_collab_row($part,$id,$coll,$ncol); @@ -261,12 +263,24 @@ sub end_externalresponse { &Apache::lonhomework::showhash(%form); my $udom = &Apache::lonnet::EXT('user.domain'); my $uname = &Apache::lonnet::EXT('user.name'); - my $symb = $env{'resource.symb'}; + my $symb = &Apache::lonnet::symbread(); my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname); - my $ua = LWP::UserAgent->new; - my $res = $ua->request(POST $url, \%form); + my $request=new HTTP::Request('POST',$url); + $request->content(join('&',map { + my $name = escape($_); + "$name=" . ( ref($form{$_}) eq 'ARRAY' + ? join("&$name=", map {escape($_) } @{$form{$_}}) + : &escape($form{$_}) ); + } keys(%form))); + my $res = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1); my @delaccess = keys(%currently_turned_in); &Apache::lonnet::automated_portfile_access('ip',undef,\@delaccess,\%info); + my @submitted_portfiles = split(/,/,$Apache::lonhomework::results{"resource.$part.$id.portfiles"}); + my @versioned_portfiles; + &Apache::lonnet::portfiles_versioning($symb,$udom,$uname,\@submitted_portfiles, + \@versioned_portfiles); + $Apache::lonhomework::results{"resource.$part.$id.portfiles"} = + join(',',@versioned_portfiles); %Apache::loncapagrade::results=(); $Apache::lonhomework::results{"resource.$part.$id.submission"}=$response; if ($res->is_error()) {