--- loncom/publisher/loncfile.pm 2003/11/08 10:48:33 1.43 +++ loncom/publisher/loncfile.pm 2003/12/15 20:44:06 1.47 @@ -9,7 +9,7 @@ # and displays a page showing the results of the action. # # -# $Id: loncfile.pm,v 1.43 2003/11/08 10:48:33 albertel Exp $ +# $Id: loncfile.pm,v 1.47 2003/12/15 20:44:06 sakharuk Exp $ # # Copyright Michigan State University Board of Trustees # @@ -72,6 +72,7 @@ use Apache::loncacc; use Apache::Log (); use Apache::lonnet; use Apache::loncommon(); +use Apache::lonlocal; my $DEBUG=0; my $r; # Needs to be global for some stuff RF. @@ -110,7 +111,7 @@ sub Debug { # Put out the indicated message butonly if DEBUG is true. if ($DEBUG) { - $log->debug($message); + $r->log_reason($message); } } @@ -211,12 +212,12 @@ sub exists { s/^\/home\/$user\/public\_html\//\/home\/httpd\/html\/res\/$domain\/$user\//; my $result=''; if ( -d $construct ) { - return 'Error: destination for operation is an existing directory.'; + return &mt('Error: destination for operation is an existing directory.'); } if ( -e $published) { - $result.='
Warning: target file exists, and has been published!
'; + $result.=''.&mt('Warning: target file exists, and has been published!').'
'; } elsif ( -e $construct) { - $result.='Warning: target file exists!
'; + $result.=''.&mt('Warning: target file exists!').'
'; } return $result; @@ -260,7 +261,7 @@ sub checksuffix { if ($old=~m:(.*)/+([^/]+)\.(\w+)$:) { $oldsuffix=$3; } if ($oldsuffix ne $newsuffix) { $result.= - 'Warning: change of MIME type!
'; + ''.&mt('Warning: change of MIME type!').'
'; } return $result; } @@ -269,7 +270,7 @@ sub cleanDest { my ($request,$dest)=@_; #remove bad characters if ($dest=~/[\#\?&]/) { - $request->print("Invalid characters in requested name have been removed.
"); + $request->print("".&mt('Invalid characters in requested name have been removed.')."
"); $dest=~s/[\#\?&]//g; } return $dest; @@ -312,9 +313,9 @@ Parameters: sub CloseForm1 { my ($request, $fn) = @_; - $request->print(''); + $request->print(''); $request->print(''); + '" method="POST">'); } @@ -344,7 +345,7 @@ Parameters: sub CloseForm2 { my ($request, $user, $fn) = @_; - $request->print('Rename '.&display($fn). + '" />
'.&mt('Rename').' '.&display($fn).
'
to '.&display($newfilename).'?
No new filename specified.
'); + $request->print(''.&mt('No new filename specified.').'
'); return; } } else { - $request->print('No such file: '.&display($fn).'
'); + $request->print(''.&mt('No such file').': '.&display($fn).'
'); return; } @@ -458,10 +459,10 @@ sub Delete1 { if( -e $fn) { $request->print(''); - $request->print('Delete '.&display($fn).'?
'); + $request->print(''.&mt('Delete').' '.&display($fn).'?
'); &CloseForm1($request, $fn); } else { - $request->print('No such file: '.&display($fn).'
'); + $request->print(''.&mt('No such file').': '.&display($fn).'
'); } } @@ -512,16 +513,16 @@ sub Copy1 { my $return=&exists($user, $domain, $newfilename); $request->print($return); if ($return =~/^Error:/) { - $request->print('Copy '.&display($fn).'
to '.
+ '" />
'.&mt('Copy').' '.&display($fn).'
to '.
&display($newfilename).'?
No such file: '.&display($fn).'
'); + $request->print(''.&mt('No such file').': '.&display($fn).'
'); } } @@ -573,12 +574,23 @@ sub NewDir1 $request->print(''.$result.''); } else { $request->print('Make new directory '. + $newfilename.'" />
'.&mt('Make new directory').' '. &display($newfilename).'?
'); &CloseForm1($request, $fn); } } + +sub Decompress1 { + my ($request, $user, $domain, $fn) = @_; + if( -e $fn) { + $request->print(''); + $request->print(''.&mt('Decompress').' '.&display($fn).'?
'); + &CloseForm1($request, $fn); + } else { + $request->print(''.&mt('No such file').': '.&display($fn).'
'); + } +} =pod =item NewFile1 @@ -629,8 +641,8 @@ sub NewFile1 { ##Informs User (name).(number).(extension) not allowed if($newfilename =~ /\.(\d+)\.(\w+)$/){ $r->print(''.$newfilename. - ' - Bad FilenameMake new file '.&display($newfilename).'?
'); + $request->print(''.&mt('Make new file').' '.&display($newfilename).'?
'); $request->print(''); $request->print(''); + '" method="POST">'); $request->print(''); + '" method="POST">'); } } @@ -687,7 +699,6 @@ sub phaseone { my $newfilename=&cleanDest($r,$ENV{'form.newfilename'}); $newfilename=&relativeDest($fn,$newfilename,$uname); - $r->print(''); + $r->print(''.&mt('No new filename specified.').'
'); } } elsif ($ENV{'form.action'} eq 'newdir') { &NewDir1($r, $uname, $udom, $fn, $newfilename); @@ -716,7 +729,7 @@ sub phaseone { if ($newfilename) { &NewFile1($r, $uname, $udom, $fn, $newfilename); } else { - $r->print('No new filename specified.
'); + $r->print(''.&mt('No new filename specified.').'
'); } } } @@ -768,7 +781,7 @@ sub Rename2 { my $oRN=$oldfile; my $nRN=$newfile; unless (rename($oldfile,$newfile)) { - $request->print('Error: '.$!.''); + $request->print(''.&mt('Error').': '.$!.''); return 0; } ## If old name.(extension) exits, move under new name. @@ -803,7 +816,7 @@ sub Rename2 { unlink $tmp2; } } else { - $request->print("No such file: ".&display($oldfile).'
'); + $request->print("".&mt('No such file').": ".&display($oldfile).'
'); return 0; } return 1; @@ -839,16 +852,40 @@ Returns: sub Delete2 { my ($request, $user, $filename) = @_; - - if(-e $filename) { - unless(unlink($filename)) { - $request->print('Error: '.$!.''); + if(opendir DIR, $filename) { + my @files=readdir(DIR); + shift @files; shift @files; # takes off . and .. + if(@files) { + $request->print(' '.&mt('Error: Directory Non Empty').''); return 0; } - } else { - $request->print('No such file.
print(''.&mt('Error').': '.$!.''); + return 0; + } + } + else { + $request->print(''.&mt('No such file').'.
print(''.&mt('Error').': '.$!.''); + return 0; + } + } + else { + $request->print(''.&mt('No such file').'.
print(' copy Error: '.$!.''); + $request->print(' '.&mt('copy Error').': '.$!.''); return 0; } else { unless (chmod(0660, $newfile)) { - $request->print(' chmod error: '.$!.''); + $request->print(' '.&mt('chmod error').': '.$!.''); return 0; } return 1; } } else { - $request->print('No such file
'); + $request->print(''.&mt('No such file').'
'); return 0; } return 1; @@ -926,16 +963,25 @@ sub NewDir2 { my ($request, $user, $newdirectory) = @_; unless(mkdir($newdirectory, 02770)) { - $request->print('Error: '.$!.''); + $request->print(''.&mt('Error').': '.$!.''); return 0; } unless(chmod(02770, ($newdirectory))) { - $request->print(' Error: '.$!.''); + $request->print(' '.&mt('Error').': '.$!.''); return 0; } return 1; } - +sub decompress2 { + my ($r, $user, $dir, $file) = @_; + &Apache::lonnet::appenv('cgi.file' => $file); + &Apache::lonnet::appenv('cgi.dir' => $dir); + my $result=&Apache::lonnet::ssi_body('/cgi-bin/decompress.pl'); + $r->print($result); + &Apache::lonnet::delenv('cgi.file'); + &Apache::lonnet::delenv('cgi.dir'); + return 1; +} =pod =item phasetwo($r, $fn, $uname, $udom) @@ -978,13 +1024,14 @@ sub phasetwo { my $dir; # Directory path my $main; # Filename. my $suffix; # Extension. - - if ($fn=~m:(.*)/([^/]+)\.(\w+)$:) { + if ($fn=~m:(.*)/([^/]+):) { $dir=$1; # Directory path $main=$2; # Filename. - $suffix=$3; # Extension. - } - + } + if($main=~m:\.(\w+)$:){ # Fixes problems with filenames with no extensions + $main=$`; + $suffix=$1; + } my $dest; # On success this is where we'll go. &Debug($r, @@ -1001,8 +1048,16 @@ sub phasetwo { "loncfie::phase2 action is $ENV{'form.action'}"); # Select the appropriate processing sub. - - if ($ENV{'form.action'} eq 'rename') { # Rename. + if ($ENV{'form.action'} eq 'decompress') { + $main .= '.'; + $main .= $suffix; + if(!&decompress2($r, $uname, $dir, $main)) { + return ; + } + $dest = $dir."/."; + + + } elsif ($ENV{'form.action'} eq 'rename') { # Rename. if($ENV{'form.newfilename'}) { if (!defined($dir)) { $fn=~m:^(.*)/:; @@ -1024,12 +1079,12 @@ sub phasetwo { } elsif ($ENV{'form.action'} eq 'copy') { if($ENV{'form.newfilename'}) { if(!&Copy2($r, $uname, $dir, $fn, $ENV{'form.newfilename'})) { - return + return ; } $dest = $ENV{'form.newfilename'}; } else { - $r->print('No New filename specified
'); + $r->print(''.&mt('No New filename specified').'
'); return; } @@ -1040,7 +1095,7 @@ sub phasetwo { } $dest = $newdir."/" } - $r->print('Unknown Action '.$ENV{'form.action'}.'