--- loncom/publisher/loncfile.pm 2011/10/23 23:46:07 1.110
+++ loncom/publisher/loncfile.pm 2019/03/06 02:31:16 1.125
@@ -9,7 +9,7 @@
# and displays a page showing the results of the action.
#
#
-# $Id: loncfile.pm,v 1.110 2011/10/23 23:46:07 www Exp $
+# $Id: loncfile.pm,v 1.125 2019/03/06 02:31:16 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -37,7 +37,7 @@
=head1 NAME
-Apache::loncfile - Construction space file management.
+Apache::loncfile - Authoring space file management.
=head1 SYNOPSIS
@@ -68,7 +68,6 @@ use File::Basename;
use File::Copy;
use HTML::Entities();
use Apache::Constants qw(:common :http :methods);
-use Apache::loncacc;
use Apache::lonnet;
use Apache::loncommon();
use Apache::lonlocal;
@@ -102,7 +101,7 @@ my $r; # Needs to be global for some
=cut
sub Debug {
- # Put out the indicated message butonly if DEBUG is true.
+ # Put out the indicated message but only if DEBUG is true.
if ($DEBUG) {
my ($r,$message) = @_;
$r->log_reason($message);
@@ -110,14 +109,15 @@ sub Debug {
}
sub done {
- my ($url)=@_;
- my $done=&mt("Done");
- return(< '
+ .&Apache::lonhtmlcommon::confirm_success(&mt("Done"))
+ .' '.&mt('Error: destination for operation is an existing directory.').' '.&mt('Error: destination for operation is an existing directory.').' '.&mt('Warning: target file exists, and has been published!').' '.&mt('Warning: target file exists, and has been published!').' '.&mt("Warning: a published $published_type of this name exists.").' '.&mt("Warning: a published $published_type of this name exists.").' '.&mt("Error: a published $published_type of this name exists.").' '.&mt("Error: a published $published_type of this name exists.").' '.&mt('Warning: target file exists!').' '.&mt('Warning: target file exists!').' '.&mt('Warning: change of MIME type!').' '.&mt('Warning: change of MIME type!').'> '
- .&mt("You have requested to create file in directory [_1] which doesn't exist. The requested directory path has been removed from the requested file name."
- ,&display($newpath))
- .' '
+ .&mt("You have requested to create file in directory [_1] which doesn't exist. The requested directory path has been removed from the requested filename."
+ ,&display($newpath))
+ .' '
- .&mt('Bad filename [_1]',&display($dest))
- .' '
+ .&mt('Bad filename [_1]',&display($dest))
+ .' '
- .&mt('Invalid characters in requested name have been removed.')
- .' '
+ .&mt('Invalid characters in requested name have been removed.')
+ .' '.
&mt('Invalid filename: ').&display($newfilename).' '.
&mt('The name of the new file needs to end with an appropriate file extension to indicate the type of file to create.').'
'.&mt("Continue").''
+ .''
+ .'
'
- .&mt('[_1](name).(number).(extension)[_2] not allowed.','','')
- .'
'
- .&mt('Removing the [_1].number.[_2] from requested filename.','','')
- .'
'
+ .&mt('[_1](name).(number).(extension)[_2] not allowed.','','')
+ .'
'
+ .&mt('Removing the [_1].number.[_2] from requested filename.','','')
+ .'
'.&mt('Cancel').'');
+ $request->print('
'.&mt('Cancel').'');
return;
}
+# Check if there is enough space.
+ my @fileinfo = stat($fn);
+ my ($dir,$fname) = ($fn =~ m{^(.+/)([^/]+)$});
+ my $filesize = $fileinfo[7];
+ $filesize = int($filesize/1000); #expressed in kb
+ my $output = &Apache::loncommon::excess_filesize_warning($user,$domain,'author',
+ $fname,$filesize,'copy');
+ if ($output) {
+ $request->print($output.'
'.&mt('Cancel').'');
+ return;
+ }
$request->print(
''
@@ -826,10 +840,13 @@ Parameters:
=item $domain - Name of the domain of the user
-=item $fn - Source file name
+=item $fn - Source filename
=item $newfilename
- Name of the file to be created; no path information
+
+=item $warnings - Information about changes to filename made by cleanDest().
+
=back
Side Effects:
@@ -839,15 +856,15 @@ Side Effects:
=item 2 new forms are displayed. Clicking on the confirmation button
causes the browser to attempt to load the specfied URL, allowing the
proper handler to take care of file creation. There is also a Cancel
-button which returns you to the driectory listing you came from
+button which returns you to the directory listing you came from
=back
=cut
sub NewFile1 {
- my ($request, $user, $domain, $fn, $newfilename) = @_;
- return if (&filename_check($newfilename) ne 'ok');
+ my ($request, $user, $domain, $fn, $newfilename, $warnings) = @_;
+ return if (&filename_check($newfilename,$warnings) ne 'ok');
if ($env{'form.action'} =~ /new(.+)file/) {
my $extension=$1;
@@ -860,8 +877,8 @@ sub NewFile1 {
}
}
my ($type, $result)=&exists($user,$domain,$newfilename);
- $request->print($result);
if ($type eq 'error') {
+ $request->print($warnings.$result);
$request->print('');
} else {
my $extension;
@@ -873,6 +890,7 @@ sub NewFile1 {
my @okexts = qw(xml html xhtml htm xhtm problem page sequence rights sty task library js css txt);
if (($extension eq '') || (!grep(/^\Q$extension\E/,@okexts))) {
my $validexts = '.'.join(', .',@okexts);
+ $request->print($warnings.$result);
$request->print('
'.
@@ -881,20 +899,26 @@ sub NewFile1 {
'
'.&mt('Make new file').' '.&display($newfilename).'?
'); + $request->print(''); + $request->print(''); + $request->print(''); } - - $request->print(''.&mt('Make new file').' '.&display($newfilename).'?
'); - $request->print(''); - - $request->print(''); - $request->print(''); } return; } @@ -950,8 +974,8 @@ sub phaseone { my $doingdir=0; if ($env{'form.action'} eq 'newdir') { $doingdir=1; } - my ($newfilename,$error) = - &cleanDest($r,$env{'form.newfilename'},$doingdir,$fn,$uname,$udom); + my ($newfilename,$error,$warnings) = + &cleanDest($env{'form.newfilename'},$doingdir,$fn,$uname,$udom); unless ($error) { ($newfilename,$error)=&relativeDest($fn,$newfilename,$uname,$udom); } @@ -962,58 +986,69 @@ sub phaseone { } else { $dirlist=$fn; } + if ($warnings) { + $r->print($warnings); + } $r->print(''.&mt('Return to Directory'). + '
'); return; } $r->print('' - ); - } - } elsif ($env{'form.action'} eq 'newdir') { - my $mode = ''; - if (exists($env{'form.callingmode'}) ) { - $mode = $env{'form.callingmode'}; - } - &NewDir1($r, $uname, $udom, $fn, $newfilename, $mode); - } elsif ($env{'form.action'} eq 'newfile' || - $env{'form.action'} eq 'newhtmlfile' || - $env{'form.action'} eq 'newproblemfile' || - $env{'form.action'} eq 'newpagefile' || - $env{'form.action'} eq 'newsequencefile' || - $env{'form.action'} eq 'newrightsfile' || - $env{'form.action'} eq 'newstyfile' || - $env{'form.action'} eq 'newtaskfile' || - $env{'form.action'} eq 'newlibraryfile' || - $env{'form.action'} eq 'Select Action') { + + if ($env{'form.action'} eq 'newfile' || + $env{'form.action'} eq 'newhtmlfile' || + $env{'form.action'} eq 'newproblemfile' || + $env{'form.action'} eq 'newpagefile' || + $env{'form.action'} eq 'newsequencefile' || + $env{'form.action'} eq 'newrightsfile' || + $env{'form.action'} eq 'newstyfile' || + $env{'form.action'} eq 'newtaskfile' || + $env{'form.action'} eq 'newlibraryfile' || + $env{'form.action'} eq 'Select Action') { my $empty=&mt('Type Name Here'); - if (($newfilename!~/\/$/) && ($newfilename!~/$empty$/)) { - &NewFile1($r, $uname, $udom, $fn, $newfilename); - } else { + if (($newfilename!~/\/$/) && ($newfilename!~/$empty$/)) { + &NewFile1($r, $uname, $udom, $fn, $newfilename, $warnings); + } else { + if ($warnings) { + $r->print($warnings); + } $r->print('' .&mt('No new filename specified.') .'
' ); - } + } + } else { + if ($warnings) { + $r->print($warnings); + } + if ($env{'form.action'} eq 'rename') { + &Rename1($r, $uname, $udom, $fn, $newfilename, 'rename'); + } elsif ($env{'form.action'} eq 'move') { + &Rename1($r, $uname, $udom, $fn, $newfilename, 'move'); + } elsif ($env{'form.action'} eq 'delete') { + &Delete1($r, $uname, $udom, $fn); + } elsif ($env{'form.action'} eq 'decompress') { + &Decompress1($r, $uname, $udom, $fn); + } elsif ($env{'form.action'} eq 'copy') { + if ($newfilename) { + &Copy1($r, $uname, $udom, $fn, $newfilename); + } else { + $r->print('' + .&mt('No new filename specified.') + .'
' + ); + } + } elsif ($env{'form.action'} eq 'newdir') { + my $mode = ''; + if (exists($env{'form.callingmode'}) ) { + $mode = $env{'form.callingmode'}; + } + &NewDir1($r, $uname, $udom, $fn, $newfilename, $mode); + } } } @@ -1100,7 +1135,7 @@ sub Rename2 { } } else { $request->print( - '' + '
' .&mt('No such file: [_1]', &display($oldfile)) .'
' @@ -1388,13 +1423,21 @@ sub phasetwo { $dest = $newdir."/"; } if ( ($env{'form.action'} eq 'newdir') && ($env{'form.phase'} eq 'two') && ( ($env{'form.callingmode'} eq 'testbank') || ($env{'form.callingmode'} eq 'imsimport') ) ) { - $r->print(''
+ .&Apache::lonhtmlcommon::confirm_success(&mt('Done'))
+ .'
'.&mt('Continue').''
+ .'
'.&Apache::lonhtmlcommon::confirm_success(&mt('Done')).'
' + .&Apache::lonhtmlcommon::actionbox( + [''.&mt('Return to Directory').'', + ''.$disp_newname.''])); } else { - $r->print(&done(&url($dest))); + $r->print(&done($dest)); } } } @@ -1403,7 +1446,7 @@ sub handler { $r=shift; - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['decompress','action','filename','newfilename']); + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['decompress','action','filename','newfilename','mode']); &Debug($r, "loncfile.pm - handler entered"); &Debug($r, " filename: ".$env{'form.filename'}); @@ -1442,14 +1485,11 @@ sub handler { } # ----------------------------------------------------------- Start page output - my $uname; - my $udom; - ($uname,$udom)= - &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain')); + my ($uname,$udom) = &Apache::lonnet::constructaccess($fn); &Debug($r, "loncfile::handler constructaccess uname = $uname domain = $udom"); - unless (($uname) && ($udom)) { + if (($uname eq '') || ($udom eq '')) { $r->log_reason($uname.' at '.$udom. ' trying to manipulate file '.$env{'form.filename'}. ' ('.$fn.') - not authorized', @@ -1476,28 +1516,32 @@ function writeDone() { |; $loaditem{'onload'} = "writeDone()"; } + + my $londocroot = $r->dir_config('lonDocRoot'); + my $trailfile = $fn; + $trailfile =~ s{^/(priv/)}{$londocroot/$1}; # Breadcrumbs &Apache::lonhtmlcommon::clear_breadcrumbs(); &Apache::lonhtmlcommon::add_breadcrumb({ - 'text' => 'Construction Space', - 'href' => &Apache::loncommon::authorspace(), + 'text' => 'Authoring Space', + 'href' => &Apache::loncommon::authorspace($fn), }); &Apache::lonhtmlcommon::add_breadcrumb({ 'text' => 'File Operation', - 'title' => 'Construction Space File Operation', + 'title' => 'Authoring Space File Operation', 'href' => '', }); - $r->print(&Apache::loncommon::start_page('Construction Space File Operation', + $r->print(&Apache::loncommon::start_page('Authoring Space File Operation', $js, {'add_entries' => \%loaditem,}) .&Apache::lonhtmlcommon::breadcrumbs() .&Apache::loncommon::head_subbox( - &Apache::loncommon::CSTR_pageheader()) + &Apache::loncommon::CSTR_pageheader($trailfile)) ); - $r->print(''.&mt('Location').': '.&display($fn).'
'); if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) { $r->print('' @@ -1508,37 +1552,35 @@ function writeDone() { &Debug($r, "loncfile::handler Form action is $env{'form.action'} "); - if ($env{'form.action'} eq 'delete') { - $r->print('
' - .&mt('Unknown Action').' '.$env{'form.action'} + .&mt('Unknown Action: [_1]',$env{'form.action'}) .'
' .&Apache::loncommon::end_page() ); - return OK; + return OK; } + if ($env{'form.phase'} eq 'two') { &Debug($r, "loncfile::handler entering phase2"); &phasetwo($r,$fn,$uname,$udom);