[LON-CAPA-cvs] cvs: loncom /interface portfolio.pm

banghart lon-capa-cvs@mail.lon-capa.org
Fri, 27 Aug 2004 15:45:34 -0000


banghart		Fri Aug 27 11:45:34 2004 EDT

  Modified files:              
    /loncom/interface	portfolio.pm 
  Log:
  
  	Cleaned up formatting, removed redundant sub clean_filename,
  	removed Fixme comment
  
  
Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.33 loncom/interface/portfolio.pm:1.34
--- loncom/interface/portfolio.pm:1.33	Wed Aug 25 14:48:26 2004
+++ loncom/interface/portfolio.pm	Fri Aug 27 11:45:33 2004
@@ -266,19 +266,6 @@
 	      $ENV{'form.currentpath'}.'" />');
 }
 
-sub clean_filename {
-    my ($fname)=@_;
-# 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;
-    return $fname;
-}
-
 sub close_form {
     my ($r)=@_;
     $r->print('<p><input type="submit" value="'.&mt('Continue').
@@ -388,21 +375,17 @@
 
 sub upload {
     my ($r)=@_;
-    #FIXME if the file already exists we need to do a confirmation pass 
-    #before overwriting
     my $fname=$ENV{'form.uploaddoc.filename'};
-    $fname=&clean_filename($fname);
-   	my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
+    $fname=&Apache::lonnet::clean_filename($fname);
+    my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'},
 						 $ENV{'user.name'}).
 						'/userfiles/portfolio';
-	my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'},
-					    $ENV{'user.domain'},
-					    $ENV{'user.name'},$portfolio_root);
-  	my $found_file = 0;
+    my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'},
+					  $ENV{'user.domain'},
+					  $ENV{'user.name'},$portfolio_root);
+    my $found_file = 0;
     foreach my $line (@dir_list) {
-    	#$strip holds directory/file name
-    	#$dom 
-    	my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); 
+        my ($filename)=split(/\&/,$line,2);
         if ($filename eq $fname){
             $found_file = 1;
         }
@@ -414,8 +397,8 @@
         my $result=&Apache::lonnet::userfileupload('uploaddoc','',
 	        	 'portfolio'.$ENV{'form.currentpath'});
         if ($result !~ m|^/uploaded/|) {
-        	$r->print('<font color="red"> An errror occured ('.$result.
-		              ') while trying to upload '.&display_file().'</font><br />');
+            $r->print('<font color="red"> An errror occured ('.$result.
+	              ') while trying to upload '.&display_file().'</font><br />');
         }
     }
     $r->print(&done());