[LON-CAPA-cvs] cvs: loncom(version_1_0_2_scantron) /homework grades.pm

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 16 Oct 2003 03:51:52 -0000


albertel		Wed Oct 15 23:51:52 2003 EDT

  Modified files:              (Branch: version_1_0_2_scantron)
    /loncom/homework	grades.pm 
  Log:
  - removing 1.1 dependencies
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.130.2.1.2.10 loncom/homework/grades.pm:1.130.2.1.2.11
--- loncom/homework/grades.pm:1.130.2.1.2.10	Tue Oct 14 18:52:24 2003
+++ loncom/homework/grades.pm	Wed Oct 15 23:51:52 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.130.2.1.2.10 2003/10/14 22:52:24 albertel Exp $
+# $Id: grades.pm,v 1.130.2.1.2.11 2003/10/16 03:51:52 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3145,13 +3145,24 @@
     return $result;
 }
 
+#FIXME, I am in loncreatecourse, use that one instead
+sub propath {
+    my ($udom,$uname)=@_;
+    $udom=~s/\W//g;
+    $uname=~s/\W//g;
+    my $subdir=$uname.'__';
+    $subdir =~ s/(.)(.)(.).*/$1\/$2\/$3/;
+    my $proname="$Apache::lonnet::perlvar{'lonUsersDir'}/$udom/$subdir/$uname";
+    return $proname;
+} 
+
 sub scantron_uploads {
     if (!-e $Apache::lonnet::perlvar{'lonScansDir'}) { return ''};
     my $result=	'<select name="scantron_selectfile">';
     my $cdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
     my $cname=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
     my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname,
-			      &Apache::loncreatecourse::propath($cdom,$cname));
+				       &propath($cdom,$cname));
     foreach my $filename (@files) {
 	($filename)=split(/&/,$filename);
 	if ($filename!~/^scantron_orig_/) { next ; }
@@ -3959,7 +3970,22 @@
     $r->print("Doing upload to ".$ENV{'form.courseid'});
     my $home=&Apache::lonnet::homeserver($ENV{'form.courseid'},
 					 $ENV{'form.domainid'});
-    my $fname='scantron_orig_'.$ENV{'form.upfile.filename'};
+    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'; }
+    $fname='scantron_orig_'.$fname;
+    &Apache::lonnet::logthis("fname is $fname");
     $r->print(&Apache::lonnet::finishuserfileupload($ENV{'form.courseid'},
 						    $ENV{'form.domainid'},
 						    $home,'upfile',$fname));