--- loncom/publisher/loncfile.pm 2005/11/08 17:58:35 1.73 +++ loncom/publisher/loncfile.pm 2007/04/20 20:55:01 1.82 @@ -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.82 2007/04/20 20:55:01 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -72,6 +72,8 @@ use Apache::loncacc; use Apache::lonnet; use Apache::loncommon(); use Apache::lonlocal; +use LONCAPA qw(:DEFAULT :match); + my $DEBUG=0; my $r; # Needs to be global for some stuff RF. @@ -148,21 +150,21 @@ sub URLToPath { $Url=~ s/\/+/\//g; $Url=~ s/^http\:\/\/[^\/]+//; $Url=~ s/^\///; - $Url=~ s/(\~|priv\/)(\w+)\//\/home\/$2\/public_html\//; + $Url=~ s/(\~|priv\/)($match_username)\//\/home\/$2\/public_html\//; &Debug($r, "Returning $Url \n"); return $Url; } sub url { my $fn=shift; - $fn=~s/^\/home\/(\w+)\/public\_html/\/priv\/$1/; + $fn=~s/^\/home\/($match_username)\/public\_html/\/priv\/$1/; $fn=&HTML::Entities::encode($fn,'<>"&'); return $fn; } sub display { my $fn=shift; - $fn=~s-^/home/(\w+)/public_html-/priv/$1-; + $fn=~s-^/home/($match_username)/public_html-/priv/$1-; return ''.$fn.''; } @@ -187,20 +189,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); } } @@ -298,9 +300,9 @@ sub checksuffix { my $newsuffix; if ($new=~m:(.*/*)([^/]+)\.(\w+)$:) { $newsuffix=$3; } if ($old=~m:(.*)/+([^/]+)\.(\w+)$:) { $oldsuffix=$3; } - if ($oldsuffix ne $newsuffix) { + if (lc($oldsuffix) ne lc($newsuffix)) { $result.= - '

'.&mt('Warning: change of MIME type!').'

'; + '

'.&mt('Warning: change of MIME type!').'

'; } return $result; } @@ -461,9 +463,9 @@ sub Rename1 { if (-d $fn) { $newfilename=~/\.(\w+)$/; if (&Apache::loncommon::fileembstyle($1) eq 'ssi') { - $request->print('
'. + $request->print('
'. &mt('Cannot change MIME type of a directory'). - '
'. + ''. '
'.&mt('Cancel').''); return; } @@ -747,16 +749,16 @@ sub NewFile1 { return; } if ($newfilename !~ /\Q.$extension\E$/) { - if ($newfilename =~ m|^[^\.]*\.([^\.]+)$|) { + if ($newfilename =~ m|/[^/.]*\.(?:[^/.]+)$|) { #already has an extension strip it and add in expected one - $newfilename =~ s|.([^\.]+)$||; + $newfilename =~ s|(/[^./])\.(?:[^.]+)$|$1|; } $newfilename.=".$extension"; } } my $result=&exists($user,$domain,$newfilename); if($result) { - $request->print(''.$result.''); + $request->print(''.$result.''); } else { $request->print('

'.&mt('Make new file').' '.&display($newfilename).'?

'); $request->print(''); @@ -1135,7 +1137,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 +1150,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 +1180,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 +1215,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 +1242,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 +1286,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 +1339,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 +1351,7 @@ function writeDone() { &phaseone($r,$fn,$uname,$udom); } - $r->print(''); + $r->print(&Apache::loncommon::end_page()); return OK; }