Diff for /loncom/publisher/loncfile.pm between versions 1.70 and 1.76

version 1.70, 2005/07/14 22:49:26 version 1.76, 2006/04/13 18:30:30
Line 69  use File::Copy; Line 69  use File::Copy;
 use HTML::Entities();  use HTML::Entities();
 use Apache::Constants qw(:common :http :methods);  use Apache::Constants qw(:common :http :methods);
 use Apache::loncacc;  use Apache::loncacc;
 use Apache::Log ();  
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::loncommon();  use Apache::loncommon();
 use Apache::lonlocal;  use Apache::lonlocal;
Line 101  my $r;    # Needs to be global for some Line 100  my $r;    # Needs to be global for some
 =cut  =cut
   
 sub Debug {  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.      # Put out the indicated message butonly if DEBUG is true.
     
     if ($DEBUG) {      if ($DEBUG) {
    my ($r,$message) = @_;
  $r->log_reason($message);   $r->log_reason($message);
     }      }
 }  }
Line 195  sub obsolete_unpub { Line 187  sub obsolete_unpub {
 }  }
   
 # see if directory is empty  # 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.  # published file, which has since been marked obsolete and deleted.
 sub empty_directory {  sub empty_directory {
     my ($dirname,$phase) = @_;      my ($dirname,$phase) = @_;
     if (opendir DIR, $dirname) {      if (opendir DIR, $dirname) {
         my @files = grep(!/^\.\.?$/, readdir(DIR)); # ignore . and ..          my @files = grep(!/^\.\.?$/, readdir(DIR)); # ignore . and ..
         if (@files) {           if (@files) { 
             my @orphans = grep(/\.(meta|save|log)$/,@files);              my @orphans = grep(/\.(meta|save|log|bak)$/,@files);
             if (scalar(@files) - scalar(@orphans) > 0) {               if (scalar(@files) - scalar(@orphans) > 0) { 
                 return 0;                  return 0;
             } else {              } else {
                 if (($phase eq 'Delete2') && (@orphans > 0)) {                  if (($phase eq 'Delete2') && (@orphans > 0)) {
                     foreach my $file (@orphans) {                      foreach my $file (@orphans) {
                         if ($file =~ /\.(meta|save|log)$/) {                          if ($file =~ /\.(meta|save|log|bak)$/) {
                             unlink($dirname.$file);                              unlink($dirname.$file);
                         }                          }
                     }                      }
Line 321  sub cleanDest { Line 313  sub cleanDest {
  $foundbad=1;   $foundbad=1;
  $dest=~s/\.//g;   $dest=~s/\.//g;
     }      }
     if  ($dest=~/[\#\?&%\"]/) {      if  ($dest=~/[\#\?&%\":]/) {
  $foundbad=1;   $foundbad=1;
  $dest=~s/[\#\?&%\"]//g;   $dest=~s/[\#\?&%\":]//g;
     }      }
     if ($dest=~m|/|) {      if ($dest=~m|/|) {
  my ($newpath)=($dest=~m|(.*)/|);   my ($newpath)=($dest=~m|(.*)/|);
Line 1025  sub Delete2 { Line 1017  sub Delete2 {
   
 =back  =back
   
 Returns 0 failure, and 0 successs.  Returns 0 failure, and 1 successs.
   
 =cut  =cut
   
Line 1033  sub Copy2 { Line 1025  sub Copy2 {
     my ($request, $username, $dir, $oldfile, $newfile) = @_;      my ($request, $username, $dir, $oldfile, $newfile) = @_;
     &Debug($request ,"Will try to copy $oldfile to $newfile");      &Debug($request ,"Will try to copy $oldfile to $newfile");
     if(-e $oldfile) {      if(-e $oldfile) {
           if ($oldfile eq $newfile) {
               $request->print('<font color="red"> '.&mt('Warning').': '.&mt('Name of new file is the same as name of old file').' - '.&mt('no action taken').'.</font>');
               return 1;
           }
  unless (copy($oldfile, $newfile)) {   unless (copy($oldfile, $newfile)) {
     $request->print('<font color="red"> '.&mt('copy Error').': '.$!.'</font>');      $request->print('<font color="red"> '.&mt('copy Error').': '.$!.'</font>');
     return 0;      return 0;
Line 1277  sub handler { Line 1273  sub handler {
     &Apache::loncommon::content_type($r,'text/html');      &Apache::loncommon::content_type($r,'text/html');
     $r->send_http_header;      $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') ) ) {      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'};   my $newdirname = $env{'form.newfilename'};
  $r->print('<html><head><title>LON-CAPA Construction Space</title><script language="Javascript">');   $js = qq|
  $r->print(qq|  <script type="text/javascript">
 function writeDone() {  function writeDone() {
     var winName = window.opener      var winName = window.opener
     window.focus();      window.focus();
Line 1288  function writeDone() { Line 1286  function writeDone() {
     setTimeout("self.close()",10000)      setTimeout("self.close()",10000)
 }  }
   </script>    </script>
   </head>|);  |;
  my $loaditem = 'onLoad="writeDone()"';   $loaditem{'onload'} = "writeDone()";
  $r->print(&Apache::loncommon::bodytag('Construction Space File Operation','',$loaditem));  
     } else {  
  $r->print('<html><head><title>LON-CAPA Construction Space</title></head>');  
  $r->print(&Apache::loncommon::bodytag('Construction Space File Operation'));  
     }      }
       
       $r->print(&Apache::loncommon::start_page('Construction Space File Operation',
        $js,
        {'add_entries' => \%loaditem,}));
       
     $r->print('<h3>'.&mt('Location').': '.&display($fn).'</h3>');      $r->print('<h3>'.&mt('Location').': '.&display($fn).'</h3>');
       
Line 1329  function writeDone() { Line 1326  function writeDone() {
      $env{'form.action'} eq 'Select Action' ) {       $env{'form.action'} eq 'Select Action' ) {
  $r->print('<h3>'.&mt('New Resource').'</h3>');   $r->print('<h3>'.&mt('New Resource').'</h3>');
     } else {      } else {
  $r->print('<p>'.&mt('Unknown Action').' '.$env{'form.action'}.' </p></body></html>');   $r->print('<p>'.&mt('Unknown Action').' '.$env{'form.action'}.' </p>'.
     &Apache::loncommon::end_page());
  return OK;     return OK;  
     }      }
     if ($env{'form.phase'} eq 'two') {      if ($env{'form.phase'} eq 'two') {
Line 1340  function writeDone() { Line 1338  function writeDone() {
  &phaseone($r,$fn,$uname,$udom);   &phaseone($r,$fn,$uname,$udom);
     }      }
   
     $r->print('</body></html>');      $r->print(&Apache::loncommon::end_page());
     return OK;        return OK;  
 }  }
   

Removed from v.1.70  
changed lines
  Added in v.1.76


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>