[LON-CAPA-cvs] cvs: loncom /homework grades.pm /lonnet/perl lonnet.pm
raeburn
raeburn@source.lon-capa.org
Tue, 05 May 2009 00:42:36 -0000
raeburn Tue May 5 00:42:36 2009 EDT
Modified files:
/loncom/homework grades.pm
/loncom/lonnet/perl lonnet.pm
Log:
- Upload scantron data file.
- Eliminate copy and pasted code from lonnet::userfileupload() by calling the routine directly.
- Pass scantron as a subdir name (although files still currently stored in top level userfiles directory).
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.567 loncom/homework/grades.pm:1.568
--- loncom/homework/grades.pm:1.567 Mon May 4 22:41:37 2009
+++ loncom/homework/grades.pm Tue May 5 00:42:28 2009
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.567 2009/05/04 22:41:37 raeburn Exp $
+# $Id: grades.pm,v 1.568 2009/05/05 00:42:28 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -7787,37 +7787,25 @@
return '';
}
my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
+ my $uploadedfile;
$r->print('<h3>'.&mt("Uploading file to [_1]",$coursedata{'description'}).'</h3>');
- my $fname=$env{'form.upfile.filename'};
- #FIXME
- #copied from lonnet::userfileupload()
- #make that function able to target a specified course
- # Replace Windows backslashes by forward slashes
- $fname=~s/\\/\//g;
- # Get rid of everything but the actual filename
- $fname=~s/^.*\/([^\/]+)$/$1/;
- # Replace spaces by underscores
- $fname=~s/\s+/\_/g;
- # Replace all other weird characters by nothing
- $fname=~s/[^\w\.\-]//g;
- # See if there is anything left
- unless ($fname) { return 'error: no uploaded file'; }
- my $uploadedfile=$fname;
- $fname='scantron_orig_'.$fname;
if (length($env{'form.upfile'}) < 2) {
- $r->print(&mt("<span class=\"LC_error\">Error:</span> The file you attempted to upload, [_1] contained no information. Please check that you entered the correct filename.",'<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"')."</span>"));
+ $r->print(&mt('[_1]Error:[_2] The file you attempted to upload, [_3] contained no information. Please check that you entered the correct filename.','<span class="LC_error">','</span>','<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'));
} else {
- my $result=&Apache::lonnet::finishuserfileupload($env{'form.courseid'},$env{'form.domainid'},'upfile',$fname);
- if ($result =~ m|^/uploaded/|) {
+ my $result =
+ &Apache::lonnet::userfileupload('upfile','','scantron','','','',
+ $env{'form.courseid'},$env{'form.domainid'});
+ if ($result =~ m{^/uploaded/}) {
$r->print(&mt('[_1]Success:[_2] Successfully uploaded [_3] bytes of data into location: [_4]',
'<span class="LC_success">','</span>',(length($env{'form.upfile'})-1),
'<span class="LC_filename">'.$result.'</span>'));
+ ($uploadedfile) = ($result =~ m{/([^/]+)$});
$r->print(&validate_uploaded_scantron_file($env{'form.domainid'},
- $env{'form.courseid'},$fname));
+ $env{'form.courseid'},$uploadedfile));
} else {
$r->print(&mt('[_1]Error:[_2] An error ([_3]) occurred when attempting to upload the file, [_4]',
'<span class="LC_error">','</span>',$result,
- '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"')."</span>"));
+ '<span class="LC_filename">'.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'</span>'));
}
}
if ($symb) {
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.994 loncom/lonnet/perl/lonnet.pm:1.995
--- loncom/lonnet/perl/lonnet.pm:1.994 Sat Apr 11 21:43:02 2009
+++ loncom/lonnet/perl/lonnet.pm Tue May 5 00:42:35 2009
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.994 2009/04/11 21:43:02 raeburn Exp $
+# $Id: lonnet.pm,v 1.995 2009/05/05 00:42:35 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2166,9 +2166,12 @@
close($fh);
return $fullpath.'/'.$fname;
}
-
+ if ($subdir eq 'scantron') {
+ $fname = 'scantron_orig_'.$fname;
+ } else {
# Create the directory if not present
- $fname="$subdir/$fname";
+ $fname="$subdir/$fname";
+ }
if ($coursedoc) {
my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};