--- loncom/homework/grades.pm 2003/10/14 22:52:24 1.130.2.1.2.10 +++ loncom/homework/grades.pm 2003/10/16 03:51:52 1.130.2.1.2.11 @@ -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 @@ sub getSequenceDropDown { 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 @@ sub scantron_upload_scantron_data_save { $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));