version 1.33, 2004/08/25 18:48:26
|
version 1.36, 2004/09/06 23:11:57
|
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); |
$fname=&Apache::lonnet::clean_filename($fname); |
my $portfolio_root = &Apache::loncommon::propath($ENV{'user.domain'}, |
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'}, |
my @dir_list=&Apache::lonnet::dirlist($ENV{'form.currentpath'}, |
$ENV{'user.domain'}, |
$ENV{'user.domain'}, |
$ENV{'user.name'},$portfolio_root); |
$ENV{'user.name'},$portfolio_root); |
my $found_file = 0; |
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; |
} |
} |
} |
} |
|
$r->print('<br />'.&Apache::lonnet::diskusage($ENV{'user.domain'}, $ENV{'user.name'},$portfolio_root).'<br />'); |
if ($found_file){ |
if ($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'}); |
Line 414 sub upload {
|
Line 398 sub upload {
|
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 459 sub handler {
|
Line 443 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 |
|
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'}) { |