--- loncom/publisher/loncfile.pm 2005/07/14 22:49:26 1.70 +++ loncom/publisher/loncfile.pm 2006/11/22 22:10:58 1.78 @@ -9,7 +9,7 @@ # and displays a page showing the results of the action. # # -# $Id: loncfile.pm,v 1.70 2005/07/14 22:49:26 raeburn Exp $ +# $Id: loncfile.pm,v 1.78 2006/11/22 22:10:58 banghart Exp $ # # Copyright Michigan State University Board of Trustees # @@ -69,10 +69,12 @@ use File::Copy; use HTML::Entities(); use Apache::Constants qw(:common :http :methods); use Apache::loncacc; -use Apache::Log (); use Apache::lonnet; use Apache::loncommon(); use Apache::lonlocal; +use lib '/home/httpd/lib/perl/'; +use LONCAPA; + my $DEBUG=0; my $r; # Needs to be global for some stuff RF. @@ -101,16 +103,9 @@ my $r; # Needs to be global for some =cut sub Debug { - - # Marshall the parameters. - - my $r = shift; - my $log = $r->log; - my $message = shift; - # Put out the indicated message butonly if DEBUG is true. - if ($DEBUG) { + my ($r,$message) = @_; $r->log_reason($message); } } @@ -195,20 +190,20 @@ sub obsolete_unpub { } # see if directory is empty -# ignores any .meta, .save and .log files created for a previously +# ignores any .meta, .save, .bak, and .log files created for a previously # published file, which has since been marked obsolete and deleted. sub empty_directory { my ($dirname,$phase) = @_; if (opendir DIR, $dirname) { my @files = grep(!/^\.\.?$/, readdir(DIR)); # ignore . and .. if (@files) { - my @orphans = grep(/\.(meta|save|log)$/,@files); + my @orphans = grep(/\.(meta|save|log|bak)$/,@files); if (scalar(@files) - scalar(@orphans) > 0) { return 0; } else { if (($phase eq 'Delete2') && (@orphans > 0)) { foreach my $file (@orphans) { - if ($file =~ /\.(meta|save|log)$/) { + if ($file =~ /\.(meta|save|log|bak)$/) { unlink($dirname.$file); } } @@ -321,9 +316,9 @@ sub cleanDest { $foundbad=1; $dest=~s/\.//g; } - if ($dest=~/[\#\?&%\"]/) { + if ($dest=~/[\#\?&%\":]/) { $foundbad=1; - $dest=~s/[\#\?&%\"]//g; + $dest=~s/[\#\?&%\":]//g; } if ($dest=~m|/|) { my ($newpath)=($dest=~m|(.*)/|); @@ -1025,7 +1020,7 @@ sub Delete2 { =back -Returns 0 failure, and 0 successs. +Returns 0 failure, and 1 successs. =cut @@ -1033,6 +1028,10 @@ sub Copy2 { my ($request, $username, $dir, $oldfile, $newfile) = @_; &Debug($request ,"Will try to copy $oldfile to $newfile"); if(-e $oldfile) { + if ($oldfile eq $newfile) { + $request->print(' '.&mt('Warning').': '.&mt('Name of new file is the same as name of old file').' - '.&mt('no action taken').'.'); + return 1; + } unless (copy($oldfile, $newfile)) { $request->print(' '.&mt('copy Error').': '.$!.''); return 0; @@ -1139,7 +1138,7 @@ sub phasetwo { &Debug($r, "loncfile - Entering phase 2 for $fn"); - # Break down the file into it's component pieces. + # Break down the file into its component pieces. my $dir; # Directory path my $main; # Filename. @@ -1180,7 +1179,7 @@ sub phasetwo { if(!&Rename2($r, $uname, $dir, $fn, $env{'form.newfilename'})) { return; } - $dest = $env{'form.newfilename'}; + $dest = $dir."/"; } } elsif ($env{'form.action'} eq 'delete') { if(!&Delete2($r, $uname, $env{'form.newfilename'})) { @@ -1233,12 +1232,12 @@ sub handler { if ($env{'form.filename'}) { &Debug($r, "test: $env{'form.filename'}"); - $fn=&Apache::lonnet::unescape($env{'form.filename'}); + $fn=&unescape($env{'form.filename'}); $fn=&URLToPath($fn); } elsif($ENV{'QUERY_STRING'} && $env{'form.phase'} ne 'two') { #Just hijack the script only the first time around to inject the #correct information for further processing - $fn=&Apache::lonnet::unescape($env{'form.decompress'}); + $fn=&unescape($env{'form.decompress'}); $fn=&URLToPath($fn); $env{'form.action'}="decompress"; } elsif ($env{'form.qualifiedfilename'}) { @@ -1277,10 +1276,12 @@ sub handler { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; + my (%loaditem,$js); + if ( ($env{'form.action'} eq 'newdir') && ($env{'form.phase'} eq 'two') && ( ($env{'form.callingmode'} eq 'testbank') || ($env{'form.callingmode'} eq 'imsimport') ) ) { my $newdirname = $env{'form.newfilename'}; - $r->print('LON-CAPA Construction Space - |); - my $loaditem = 'onLoad="writeDone()"'; - $r->print(&Apache::loncommon::bodytag('Construction Space File Operation','',$loaditem)); - } else { - $r->print('LON-CAPA Construction Space'); - $r->print(&Apache::loncommon::bodytag('Construction Space File Operation')); +|; + $loaditem{'onload'} = "writeDone()"; } - + + $r->print(&Apache::loncommon::start_page('Construction Space File Operation', + $js, + {'add_entries' => \%loaditem,})); $r->print('

'.&mt('Location').': '.&display($fn).'

'); @@ -1329,7 +1329,8 @@ function writeDone() { $env{'form.action'} eq 'Select Action' ) { $r->print('

'.&mt('New Resource').'

'); } else { - $r->print('

'.&mt('Unknown Action').' '.$env{'form.action'}.'

'); + $r->print('

'.&mt('Unknown Action').' '.$env{'form.action'}.'

'. + &Apache::loncommon::end_page()); return OK; } if ($env{'form.phase'} eq 'two') { @@ -1340,7 +1341,7 @@ function writeDone() { &phaseone($r,$fn,$uname,$udom); } - $r->print(''); + $r->print(&Apache::loncommon::end_page()); return OK; }