--- loncom/interface/portfolio.pm 2004/08/25 18:48:26 1.33 +++ loncom/interface/portfolio.pm 2004/09/08 17:53:37 1.38 @@ -266,19 +266,6 @@ sub open_form { $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('

Unable to upload '.$fname.' (size = '.$filesize.' kilobytes. Disk quota will be exceeded.'. + '
Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.'); + } + elsif ($found_file){ $r->print('Unable to upload '.$fname.', a file by that name was found in '.$ENV{'form.currentpath'}.''. '
To upload, rename or delete existing '.$fname.' in '.$ENV{'form.currentpath'}); } else { my $result=&Apache::lonnet::userfileupload('uploaddoc','', 'portfolio'.$ENV{'form.currentpath'}); if ($result !~ m|^/uploaded/|) { - $r->print(' An errror occured ('.$result. - ') while trying to upload '.&display_file().'
'); + $r->print(' An errror occured ('.$result. + ') while trying to upload '.&display_file().'
'); } } $r->print(&done()); @@ -423,20 +414,37 @@ sub upload { sub createdir { my ($r)=@_; - #FIXME 1) file exists in place of dir (errormessage needs improvement) my $newdir=&Apache::lonnet::clean_filename($ENV{'form.newdir'}); if ($newdir eq '') { - $r->print(''. - &mt("Error: no valid directory name was provided."). - '
'); - $r->print(&done()); - return; + $r->print(''. + &mt("Error: no directory name was provided."). + '
'); + $r->print(&done()); + return; } - my $result=&Apache::lonnet::mkdiruserfile($ENV{'user.name'}, - $ENV{'user.domain'},'portfolio'.$ENV{'form.currentpath'}.$newdir); - if ($result ne 'ok') { - $r->print(' An errror occured ('.$result. - ') while trying to create a new directory '.&display_file().'
'); + 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; + foreach my $line (@dir_list) { + my ($filename)=split(/\&/,$line,2); + if ($filename eq $newdir){ + $found_file = 1; + } + } + if ($found_file){ + $r->print(' Unable to create a directory named '.$newdir. + ' a file or directory by that name already exists.
'); + } else { + my $result=&Apache::lonnet::mkdiruserfile($ENV{'user.name'}, + $ENV{'user.domain'},'portfolio'.$ENV{'form.currentpath'}.$newdir); + if ($result ne 'ok') { + $r->print(' An errror occured ('.$result. + ') while trying to create a new directory '.&display_file().'
'); + } } $r->print(&done()); } @@ -459,7 +467,15 @@ sub handler { &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['selectfile','currentpath', 'currentfile']); - + # make sure there is a portfolio directory off /userfiles + # Fixme -- Do this in a better way -- offload it to the LOND routine + my @dir_list=&Apache::lonnet::dirlist('/', + $ENV{'user.domain'}, + $ENV{'user.name'},$portfolio_root); + if ($dir_list[0] eq 'no_such_dir'){ + &Apache::lonnet::mkdiruserfile($ENV{'user.name'}, + $ENV{'user.domain'},'portfolio'); + } if ($ENV{'form.uploaddoc.filename'}) { &upload($r); } elsif ($ENV{'form.action'} eq 'delete' && $ENV{'form.confirmed'}) { @@ -481,7 +497,7 @@ sub handler { if ($ENV{'form.currentpath'}) { $current_path = $ENV{'form.currentpath'}; } - my @dir_list=&Apache::lonnet::dirlist($current_path, + @dir_list=&Apache::lonnet::dirlist($current_path, $ENV{'user.domain'}, $ENV{'user.name'},$portfolio_root);