--- loncom/publisher/loncfile.pm 2003/11/08 10:48:33 1.43 +++ loncom/publisher/loncfile.pm 2003/11/19 14:57:32 1.44 @@ -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.44 2003/11/19 14:57:32 taceyjo1 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -73,7 +73,7 @@ use Apache::Log (); use Apache::lonnet; use Apache::loncommon(); -my $DEBUG=0; +my $DEBUG=2; my $r; # Needs to be global for some stuff RF. =pod @@ -110,12 +110,31 @@ sub Debug { # Put out the indicated message butonly if DEBUG is true. if ($DEBUG) { - $log->debug($message); + $r->log_reason($message); } } =pod +=item checksuffix($old, $new) + + Determine if a resource filename suffix (the stuff after the .) would change +as a result of this operation. + + Parameters: + +=over 4 + +=item $old = string [in] Previous filename. + +=item $new = string [in] Resultant filename. + +=back + +=cut + +=pod + =item URLToPath($url) Convert a URL to a file system path. @@ -579,6 +598,17 @@ sub NewDir1 } } + +sub Decompress1 { + my ($request, $user, $domain, $fn) = @_; + if( -e $fn) { + $request->print(''); + $request->print('

Decompress '.&display($fn).'?

'); + &CloseForm1($request, $fn); + } else { + $request->print('

No such file: '.&display($fn).'

'); + } +} =pod =item NewFile1 @@ -687,7 +717,7 @@ sub phaseone { my $newfilename=&cleanDest($r,$ENV{'form.newfilename'}); $newfilename=&relativeDest($fn,$newfilename,$uname); - + &Debug($r, "Newfile: $newfilename"); $r->print('
'. ''. ''. @@ -697,6 +727,9 @@ sub phaseone { &Rename1($r, $uname, $udom, $fn, $newfilename); } elsif ($ENV{'form.action'} eq 'delete') { &Delete1($r, $uname, $udom, $fn); + } elsif ($ENV{'form.action'} eq 'decompress') { + &Apache::lonnet::appenv('cgi.path' => $newfilename); + &Decompress1($r, $uname, $udom, $fn); } elsif ($ENV{'form.action'} eq 'copy') { if($newfilename) { &Copy1($r, $uname, $udom, $fn, $newfilename); @@ -935,7 +968,16 @@ sub NewDir2 { } 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) @@ -1001,8 +1043,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,7 +1074,7 @@ 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'}; @@ -1059,9 +1109,19 @@ sub handler { my $fn; if ($ENV{'form.filename'}) { + + &Debug($r, "test: $ENV{'form.filename'}"); $fn=&Apache::lonnet::unescape($ENV{'form.filename'}); $fn=&URLToPath($fn); - } elsif ($ENV{'form.qualifiedfilename'}) { + } + elsif($ENV{'QUERY_STRING'} && $ENV{'form.phase'} ne 'two') { + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['decompress']); + $fn=&Apache::lonnet::unescape($ENV{'form.decompress'}); + $fn=&URLToPath($fn); + $ENV{'form.action'}="decompress"; + } + + elsif ($ENV{'form.qualifiedfilename'}) { $fn=$ENV{'form.qualifiedfilename'}; } else { &Debug($r, "loncfile::handler - no form.filename"); @@ -1118,6 +1178,8 @@ sub handler { $r->print('

Rename

'); } elsif ($ENV{'form.action'} eq 'newdir') { $r->print('

New Directory

'); + } elsif ($ENV{'form.action'} eq 'decompress') { + $r->print('

Decompress

'); } elsif ($ENV{'form.action'} eq 'copy') { $r->print('

Copy

'); } elsif ($ENV{'form.action'} eq 'newfile' ||