version 1.24, 2004/08/24 06:16:55
|
version 1.27, 2004/08/24 07:26:04
|
Line 197 sub display_directory {
|
Line 197 sub display_directory {
|
$r->print('<table border="0" cellspacing="2" cellpadding="2">'. |
$r->print('<table border="0" cellspacing="2" cellpadding="2">'. |
'<tr><th>Actions</th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th></tr>'); |
'<tr><th>Actions</th><th> </th><th>Name</th><th>Size</th><th>Last Modified</th></tr>'); |
my $href_location="/uploaded/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio/$current_path/"; |
my $href_location="/uploaded/$ENV{'user.domain'}/$ENV{'user.name'}/portfolio/$current_path/"; |
foreach my $line (@$dir_list) { |
foreach my $line (sort |
|
{ |
|
my ($afile)=split('&',$a,2); |
|
my ($bfile)=split('&',$b,2); |
|
return (lc($afile) cmp lc($bfile)); |
|
} (@$dir_list)) { |
#$strip holds directory/file name |
#$strip holds directory/file name |
#$dom |
#$dom |
my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); |
my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$line,16); |
Line 264 sub close_form {
|
Line 269 sub close_form {
|
} |
} |
|
|
sub display_file { |
sub display_file { |
return $ENV{'form.currentpath'}.$ENV{'form.selectfile'}; |
my ($path,$filename)=@_; |
|
if (!defined($path)) { $path=$ENV{'form.currentpath'}; } |
|
if (!defined($filename)) { $filename=$ENV{'form.selectfile'}; } |
|
return '<tt>'.$path.$filename.'</tt>'; |
} |
} |
|
|
sub done { |
sub done { |
return ('<h3><a href="/adm/portfolio?currentpath="'. |
return ('<h3><a href="/adm/portfolio?currentpath='. |
$ENV{'form.currentpath'}.'">'.&mt('Done').'</a></h3>'); |
$ENV{'form.currentpath'}.'">'.&mt('Done').'</a></h3>'); |
} |
} |
|
|
Line 287 sub delete_confirmed {
|
Line 295 sub delete_confirmed {
|
$ENV{'form.selectfile'}); |
$ENV{'form.selectfile'}); |
if ($result ne 'ok') { |
if ($result ne 'ok') { |
$r->print('<font color="red"> An errror occured ('.$result. |
$r->print('<font color="red"> An errror occured ('.$result. |
')while trying to delete '.&display_file().'</font><br />'); |
') while trying to delete '.&display_file().'</font><br />'); |
} |
} |
$r->print(&done()); |
$r->print(&done()); |
} |
} |
Line 295 sub delete_confirmed {
|
Line 303 sub delete_confirmed {
|
sub rename { |
sub rename { |
my ($r)=@_; |
my ($r)=@_; |
&open_form($r); |
&open_form($r); |
$r->print('<p>'.&mt('Rename').' '.&display_file().'?</p>'); |
$r->print('<p>'.&mt('Rename').' '.&display_file().' to |
|
<input name="filenewname" type="input" size="50" />?</p>'); |
&close_form($r); |
&close_form($r); |
} |
} |
|
|
sub rename_confirmed { |
sub rename_confirmed { |
my ($r)=@_; |
my ($r)=@_; |
&Apache::lonnet::renameuserfile($ENV{'form.currentpath'}.$ENV{'form.selectfile'}, 'rename', $ENV{'form.currentpath'}.$ENV{'form.filenewname'} ); |
my $filenewname=&Apache::lonnet::clean_filename($ENV{'form.filenewname'}); |
} |
if ($filenewname eq '') { |
|
$r->print('<font color="red">'. |
|
&mt("Error: no valid filename was provided to rename to."). |
|
'</font><br />'); |
|
$r->print(&done()); |
|
return; |
|
} |
|
my $result= |
|
&Apache::lonnet::renameuserfile($ENV{'user.name'},$ENV{'user.domain'}, |
|
'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.selectfile'}, |
|
'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.filenewname'}); |
|
if ($result ne 'ok') { |
|
$r->print('<font color="red"> An errror occured ('.$result. |
|
') while trying to rename '.&display_file().' to '. |
|
&display_file(undef,$filenewname).'</font><br />'); |
|
} |
|
$r->print(&done()); |
|
} |
|
|
sub upload { |
sub upload { |
my ($r)=@_; |
my ($r)=@_; |
|
#FIXME if the file already exists we need to do a confirmation pass |
|
#before overwriting |
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()); |
|
} |
|
|
|
sub createdir { |
|
my ($r)=@_; |
|
#FIXME 1) bad dirnames ( '/' etc) |
|
# 2) file exists in place of dir (errormessage needs improvement) |
|
my $result=&Apache::lonnet::mkdiruserfile($ENV{'user.name'}, |
|
$ENV{'user.domain'},'portfolio'.$ENV{'form.currentpath'}.$ENV{'form.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 318 sub upload {
|
Line 359 sub upload {
|
sub handler { |
sub handler { |
# this handles file management |
# this handles file management |
my $r = shift; |
my $r = shift; |
my @dir_list; # will hold directory listing as array |
|
my $udir; # returned from home server |
|
my $currentFile; # directory or file contained in $pathToRoot.$current_path |
|
my $action; # delete, rename, makedirectory, removedirectory, |
|
my $filenewname; # for rename action (guess what we do with it!) |
|
my $isFile; |
|
&Apache::loncommon::no_cache($r); |
&Apache::loncommon::no_cache($r); |
&Apache::loncommon::content_type($r,'text/html'); |
&Apache::loncommon::content_type($r,'text/html'); |
$r->send_http_header; |
$r->send_http_header; |
Line 337 sub handler {
|
Line 372 sub handler {
|
['selectfile','currentpath', |
['selectfile','currentpath', |
'currentfile']); |
'currentfile']); |
|
|
# if we're uploading a file, we need to do it early so it will |
|
# show in the directory list |
|
|
|
if ($ENV{'form.uploaddoc.filename'}) { |
if ($ENV{'form.uploaddoc.filename'}) { |
&upload($r); |
&upload($r); |
|
} elsif ($ENV{'form.action'} eq 'delete' && $ENV{'form.confirmed'}) { |
|
&delete_confirmed($r); |
} elsif ($ENV{'form.action'} eq 'delete') { |
} elsif ($ENV{'form.action'} eq 'delete') { |
if ($ENV{'form.confirmed'}) { |
&delete($r); |
&delete_confirmed($r); |
} elsif ($ENV{'form.action'} eq 'rename' && $ENV{'form.confirmed'}) { |
} else { |
&rename_confirmed($r); |
&delete($r); |
|
} |
|
} elsif ($ENV{'form.action'} eq 'rename') { |
} elsif ($ENV{'form.action'} eq 'rename') { |
# similarly, we need to delete or rename files before getting |
|
# directory list |
|
&rename($r); |
&rename($r); |
|
} elsif ($ENV{'form.createdir'}) { |
|
&createdir($r); |
} else { |
} else { |
my $current_path='/'; |
my $current_path='/'; |
if ($ENV{'form.currentpath'}) { |
if ($ENV{'form.currentpath'}) { |
Line 361 sub handler {
|
Line 393 sub handler {
|
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'; |
@dir_list=&Apache::lonnet::dirlist($current_path,$ENV{'user.domain'}, |
my @dir_list=&Apache::lonnet::dirlist($current_path, |
$ENV{'user.name'},$portfolio_root); |
$ENV{'user.domain'}, |
|
$ENV{'user.name'},$portfolio_root); |
|
|
# need to know if directory is empty so it can be removed if desired |
# need to know if directory is empty so it can be removed if desired |
my $is_empty=(@dir_list == 2); |
my $is_empty=(@dir_list == 2); |