--- loncom/homework/essayresponse.pm 2011/01/29 19:41:41 1.114
+++ loncom/homework/essayresponse.pm 2014/01/21 14:38:55 1.118
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# essay (ungraded) style responses
#
-# $Id: essayresponse.pm,v 1.114 2011/01/29 19:41:41 raeburn Exp $
+# $Id: essayresponse.pm,v 1.118 2014/01/21 14:38:55 kruse Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -91,7 +91,7 @@ sub start_essayresponse {
'
';
+ ''.&HTML::Entities::encode($answer, '"<>&').'
';
}
return ''.$output.'
';
@@ -397,8 +397,11 @@ sub file_submission {
my ($path,$filename) = ($file =~ m{^(.*/)([^/]+)$});
my $fullpath = '/userfiles/portfolio'.$path;
if (!exists($dirlist{$fullpath})) {
- my @list = &Apache::lonnet::dirlist($fullpath,$udom,$uname,1);
- $dirlist{$fullpath} = \@list;
+ my ($listref,$listerror) =
+ &Apache::lonnet::dirlist($fullpath,$udom,$uname,1);
+ if (ref($listref) eq 'ARRAY') {
+ $dirlist{$fullpath} = $listref;
+ }
}
if (ref($dirlist{$fullpath}) eq 'ARRAY') {
foreach my $dir_line (@{$dirlist{$fullpath}}) {
@@ -441,81 +444,58 @@ sub file_submission {
}
}
if ($accepted_upload ne '') {
- my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
- my $turnindir;
- my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
- $turnindir = $userhash{'turnindir'};
- if ($turnindir eq '') {
- $turnindir = &mt('turned in');
- $turnindir =~ s/\W+/_/g;
- my %newhash = (
- 'turnindir' => $turnindir,
- );
- &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
- }
- my $prefix = 'portfolio';
- my $path = '/'.$turnindir.'/';
- my $restitle=&Apache::lonnet::gettitle($symb);
- $restitle =~ s/\W+/_/g;
- if ($restitle eq '') {
- $restitle = ($resurl =~ m{/[^/]+$});
- if ($restitle eq '') {
- $restitle = time;
- }
- }
- my @pathitems;
- my $navmap = Apache::lonnavmaps::navmap->new();
- if (defined($navmap)) {
- my $mapres = $navmap->getResourceByUrl($map);
- if (ref($mapres)) {
- my $pcslist = $mapres->map_hierarchy();
- if ($pcslist ne '') {
- foreach my $pc (split(/,/,$pcslist)) {
- my $res = $navmap->getByMapPc($pc);
- if (ref($res)) {
- my $title = $res->compTitle();
- $title =~ s/\W+/_/g;
- if ($title ne '') {
- push(@pathitems,$title);
- }
+ my ($path,$multiresp) =
+ &Apache::loncommon::get_turnedin_filepath($symb,$uname,$udom,
+ 'submission');
+ if ($path eq '') {
+ $$award = 'INTERNAL_ERROR';
+ } else {
+ if ($multiresp) {
+ $path .= '/'.$jspart.'_'.$id;
+ }
+ my $prefix = 'portfolio';
+ my $formelement = 'HWFILE'.$jspart.'_'.$id;
+ my $fname = &Apache::lonnet::clean_filename($env{'form.'.$formelement.'.filename'});
+ my $url = '/uploaded/'.$udom.'/'.$uname.'/'.$prefix.$path.'/'.$fname;
+ my @stat = &Apache::lonnet::stat_file($url);
+ my $conflicts = 0;
+ if (@stat && $stat[0] ne 'no_such_dir') {
+ my $current_permissions =
+ &Apache::lonnet::get_portfile_permissions($udom,$uname);
+ if (ref($current_permissions) eq 'HASH') {
+ if (ref($current_permissions->{$path.'/'.$fname}) eq 'ARRAY') {
+ foreach my $record (@{$current_permissions->{$path.'/'.$fname}}) {
+ if (ref($record) eq 'ARRAY') {
+ next if (($record->[0] eq $symb) &&
+ ($record->[1] eq $crsid));
+ $conflicts ++;
+ }
}
}
}
- my $maptitle = $mapres->compTitle();
- $maptitle =~ s/\W+/_/g;
- if ($maptitle ne '') {
- push(@pathitems,$maptitle);
+ if ($conflicts) {
+ $$award = 'FILENAME_INUSE';
}
- } else {
- $$award = 'INTERNAL_ERROR';
}
- } else {
- $$award = 'INTERNAL_ERROR';
- }
- push(@pathitems,$restitle);
- $path .= join('/',@pathitems);
- my $formelement = 'HWFILE'.$jspart.'_'.$id;
- my $fname = &Apache::lonnet::clean_filename($env{'form.'.$formelement.'.filename'});
- my $url = '/uploaded/'.$udom.'/'.$uname.'/'.$prefix.$path.'/'.$fname;
- my @stat = &Apache::lonnet::stat_file($url);
- if (@stat && $stat[0] ne 'no_such_dir') {
- $$award = 'FILENAME_INUSE';
- } else {
- my ($mode,%allfiles,%codebase);
- my $result = &Apache::lonnet::userfileupload($formelement,'',
+ unless ($conflicts) {
+ my ($mode,%allfiles,%codebase);
+ my $result = &Apache::lonnet::userfileupload($formelement,'',
$prefix.$path,$mode,\%allfiles,\%codebase);
- if ($result =~ m{^/uploaded/}) {
- $stored_upload = $path.'/'.$fname;
- $Apache::lonhomework::results{"resource.$part.$id.portfiles"} = $stored_upload;
- push(@tolock,$stored_upload);
- } else {
- $$award = 'INTERNAL_ERROR';
+ if ($result =~ m{^/uploaded/}) {
+ $stored_upload = $path.'/'.$fname;
+ unless (grep(/^\Q$stored_upload\E$/,@accepted_portfiles)) {
+ $Apache::lonhomework::results{"resource.$part.$id.portfiles"} = $stored_upload;
+ push(@tolock,$stored_upload);
+ }
+ } else {
+ $$award = 'INTERNAL_ERROR';
+ }
}
}
delete($env{'form.HWFILE'.$jspart.'_'.$id});
}
if (@accepted_portfiles) {
- if ($stored_upload) {
+ if ($Apache::lonhomework::results{"resource.$part.$id.portfiles"}) {
$Apache::lonhomework::results{"resource.$part.$id.portfiles"} .= ',';
}
$Apache::lonhomework::results{"resource.$part.$id.portfiles"}.=join(',',@accepted_portfiles);