version 1.33, 2004/08/25 18:48:26
|
version 1.38, 2004/09/08 17:53:37
|
Line 266 sub open_form {
|
Line 266 sub open_form {
|
$ENV{'form.currentpath'}.'" />'); |
$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 { |
sub close_form { |
my ($r)=@_; |
my ($r)=@_; |
$r->print('<p><input type="submit" value="'.&mt('Continue'). |
$r->print('<p><input type="submit" value="'.&mt('Continue'). |
Line 388 sub rename_confirmed {
|
Line 375 sub rename_confirmed {
|
|
|
sub upload { |
sub upload { |
my ($r)=@_; |
my ($r)=@_; |
#FIXME if the file already exists we need to do a confirmation pass |
|
#before overwriting |
|
my $fname=$ENV{'form.uploaddoc.filename'}; |
my $fname=$ENV{'form.uploaddoc.filename'}; |
$fname=&clean_filename($fname); |
my $filesize = (length($ENV{'form.uploaddoc'})) / 1000; #express in k (1024?) |
my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'}, |
my $disk_quota = 20000; # expressed in k |
|
$fname=&Apache::lonnet::clean_filename($fname); |
|
my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'}, |
$ENV{'user.name'}). |
$ENV{'user.name'}). |
'/userfiles/portfolio'; |
'/userfiles/portfolio'; |
my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'}, |
# Fixme --- Move the checking for existing file to LOND error return |
$ENV{'user.domain'}, |
my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'}, |
$ENV{'user.name'},$portfolio_root); |
$ENV{'user.domain'}, |
my $found_file = 0; |
$ENV{'user.name'},$portfolio_root); |
|
my $found_file = 0; |
foreach my $line (@dir_list) { |
foreach my $line (@dir_list) { |
#$strip holds directory/file name |
my ($filename)=split(/\&/,$line,2); |
#$dom |
|
my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); |
|
if ($filename eq $fname){ |
if ($filename eq $fname){ |
$found_file = 1; |
$found_file = 1; |
} |
} |
} |
} |
if ($found_file){ |
my $current_disk_usage = &Apache::lonnet::diskusage($ENV{'user.domain'}, $ENV{'user.name'},$portfolio_root); |
|
if (($current_disk_usage + $filesize) > $disk_quota){ |
|
$r->print('<font color="red">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes</strong>. Disk quota will be exceeded.'. |
|
'<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.'); |
|
} |
|
elsif ($found_file){ |
$r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>'.$ENV{'form.currentpath'}.'</strong></font>'. |
$r->print('<font color="red">Unable to upload <strong>'.$fname.'</strong>, a file by that name was found in <strong>'.$ENV{'form.currentpath'}.'</strong></font>'. |
'<br />To upload, rename or delete existing '.$fname.' in '.$ENV{'form.currentpath'}); |
'<br />To upload, rename or delete existing '.$fname.' in '.$ENV{'form.currentpath'}); |
} else { |
} else { |
my $result=&Apache::lonnet::userfileupload('uploaddoc','', |
my $result=&Apache::lonnet::userfileupload('uploaddoc','', |
'portfolio'.$ENV{'form.currentpath'}); |
'portfolio'.$ENV{'form.currentpath'}); |
if ($result !~ m|^/uploaded/|) { |
if ($result !~ m|^/uploaded/|) { |
$r->print('<font color="red"> An errror occured ('.$result. |
$r->print('<font color="red"> An errror occured ('.$result. |
') while trying to upload '.&display_file().'</font><br />'); |
') while trying to upload '.&display_file().'</font><br />'); |
} |
} |
} |
} |
$r->print(&done()); |
$r->print(&done()); |
Line 423 sub upload {
|
Line 414 sub upload {
|
|
|
sub createdir { |
sub createdir { |
my ($r)=@_; |
my ($r)=@_; |
#FIXME 1) file exists in place of dir (errormessage needs improvement) |
|
my $newdir=&Apache::lonnet::clean_filename($ENV{'form.newdir'}); |
my $newdir=&Apache::lonnet::clean_filename($ENV{'form.newdir'}); |
if ($newdir eq '') { |
if ($newdir eq '') { |
$r->print('<font color="red">'. |
$r->print('<font color="red">'. |
&mt("Error: no valid directory name was provided."). |
&mt("Error: no directory name was provided."). |
'</font><br />'); |
'</font><br />'); |
$r->print(&done()); |
$r->print(&done()); |
return; |
return; |
} |
} |
my $result=&Apache::lonnet::mkdiruserfile($ENV{'user.name'}, |
my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'}, |
$ENV{'user.domain'},'portfolio'.$ENV{'form.currentpath'}.$newdir); |
$ENV{'user.name'}). |
if ($result ne 'ok') { |
'/userfiles/portfolio'; |
$r->print('<font color="red"> An errror occured ('.$result. |
my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'}, |
') while trying to create a new directory '.&display_file().'</font><br />'); |
$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('<font color="red"> Unable to create a directory named <strong>'.$newdir. |
|
' </strong>a file or directory by that name already exists.</font><br />'); |
|
} else { |
|
my $result=&Apache::lonnet::mkdiruserfile($ENV{'user.name'}, |
|
$ENV{'user.domain'},'portfolio'.$ENV{'form.currentpath'}.$newdir); |
|
if ($result ne 'ok') { |
|
$r->print('<font color="red"> An errror occured ('.$result. |
|
') while trying to create a new directory '.&display_file().'</font><br />'); |
|
} |
} |
} |
$r->print(&done()); |
$r->print(&done()); |
} |
} |
Line 459 sub handler {
|
Line 467 sub handler {
|
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
['selectfile','currentpath', |
['selectfile','currentpath', |
'currentfile']); |
'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'}) { |
if ($ENV{'form.uploaddoc.filename'}) { |
&upload($r); |
&upload($r); |
} elsif ($ENV{'form.action'} eq 'delete' && $ENV{'form.confirmed'}) { |
} elsif ($ENV{'form.action'} eq 'delete' && $ENV{'form.confirmed'}) { |
Line 481 sub handler {
|
Line 497 sub handler {
|
if ($ENV{'form.currentpath'}) { |
if ($ENV{'form.currentpath'}) { |
$current_path = $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.domain'}, |
$ENV{'user.name'},$portfolio_root); |
$ENV{'user.name'},$portfolio_root); |
|
|