--- loncom/publisher/loncfile.pm 2005/11/08 17:58:35 1.73 +++ loncom/publisher/loncfile.pm 2006/11/23 01:50:57 1.79 @@ -9,7 +9,7 @@ # and displays a page showing the results of the action. # # -# $Id: loncfile.pm,v 1.73 2005/11/08 17:58:35 albertel Exp $ +# $Id: loncfile.pm,v 1.79 2006/11/23 01:50:57 banghart Exp $ # # Copyright Michigan State University Board of Trustees # @@ -72,6 +72,9 @@ use Apache::loncacc; 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. @@ -187,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); } } @@ -1135,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. @@ -1148,8 +1151,10 @@ sub phasetwo { $suffix=$1; #This is the actually filename extension if it exists $main=~s/\.\w+$//; #strip the extension } - my $dest; # On success this is where we'll go. - + my $dest; # + my $dest_dir; # On success this is where we'll go. + my $disp_newname; # + my $dest_newname; # &Debug($r,"loncfile::phase2 dir = $dir main = $main suffix = $suffix"); &Debug($r," newfilename = ".$env{'form.newfilename'}); @@ -1176,7 +1181,11 @@ sub phasetwo { if(!&Rename2($r, $uname, $dir, $fn, $env{'form.newfilename'})) { return; } - $dest = $env{'form.newfilename'}; + $dest = $dir."/"; + $dest_newname = $env{'form.newfilename'}; + $env{'form.newfilename'} =~ /.+(\/.+$)/; + $disp_newname = $1; + $disp_newname =~ s/\///; } } elsif ($env{'form.action'} eq 'delete') { if(!&Delete2($r, $uname, $env{'form.newfilename'})) { @@ -1207,7 +1216,12 @@ sub phasetwo { if ( ($env{'form.action'} eq 'newdir') && ($env{'form.phase'} eq 'two') && ( ($env{'form.callingmode'} eq 'testbank') || ($env{'form.callingmode'} eq 'imsimport') ) ) { $r->print('

'.&mt('Done').'

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

'.&mt('Done').'

'); + if ($env{'form.action'} eq 'rename') { + $r->print('

'.&mt('Return to Directory').'

'); + $r->print('

'.$disp_newname.'

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

'.&mt('Done').'

'); + } } } @@ -1229,12 +1243,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'}) { @@ -1273,10 +1287,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).'

'); @@ -1325,7 +1340,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') { @@ -1336,7 +1352,7 @@ function writeDone() { &phaseone($r,$fn,$uname,$udom); } - $r->print(''); + $r->print(&Apache::loncommon::end_page()); return OK; }