File:  [LON-CAPA] / loncom / publisher / loncfile.pm
Revision 1.4: download - view: text, annotated - select for diffs
Sun Jun 24 01:40:14 2001 UTC (22 years, 10 months ago) by www
Branches: MAIN
CVS tags: HEAD
Some more functionality - still not there.

# The LearningOnline Network with CAPA
# Handler to rename files, etc, in construction space
#
# (Handler to retrieve an old version of a file
#
# (Publication Handler
# 
# (TeX Content Handler
#
# 05/29/00,05/30,10/11 Gerd Kortemeyer)
#
# 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
# 03/23 Guy Albertelli
# 03/24,03/29 Gerd Kortemeyer)
#
# 03/31,04/03,05/02,05/09,06/23 Gerd Kortemeyer)
#
# 06/23 Gerd Kortemeyer

package Apache::loncfile;

use strict;
use Apache::File;
use File::Copy;
use Apache::Constants qw(:common :http :methods);
use Apache::loncacc;

sub phaseone {
    my ($r,$fn,$uname,$udom)=@_;

    $fn=~/(.*)\/([^\/]+)\.(\w+)$/;
    my $dir=$1;
    my $main=$2;
    my $suffix=$3;

    my $conspace='/home/'.$uname.'/public_html'.$fn;

    $r->print('<form action=/adm/cfile method=post>'.
	      '<input type=hidden name=filename value="/~'.$uname.$fn.'">'.
              '<input type=hidden name=phase value=two>'.
              '<input type=hidden name=action value='.$ENV{'form.action'}.'>');
    if ($ENV{'form.action'} eq 'rename') {
	if (-e $conspace) {
	    if ($ENV{'form.newfilename'}) {
               $ENV{'form.newfilename'}=~/(.*)\/([^\/]+)\.(\w+)$/;
               if ($3 ne $suffix) {
		   $r->print(
                    '<p><font color=red>Warning: change of MIME type!</font>');
               }
               if (-e 
       	         '/home/httpd/'.$uname.'/'.$dir.'/'.$ENV{'form.newfilename'}) {
		   $r->print(
                    '<p><font color=red>Warning: target file exists!</font>');
               }
	       $r->print('<input type=hidden name=newfilename value="'.
                         $ENV{'form.newfilename'}.
                         '"><p>Rename <tt>'.$fn.'</tt> to <tt>'.
                         $dir.'/'.$ENV{'form.newfilename'}.'</tt>?');
	    } else {
	       $r->print('<p>No new filename specified.</form>');
               return;
	    }
        } else {
	    $r->print('<p>No such file.</form>');
            return;
        }
    } elsif ($ENV{'form.action'} eq 'delete') { 
	if (-e $conspace) {
            $r->print('<p>Delete <tt>'.$fn.'</tt>?');
        } else {
	    $r->print('<p>No such file.</form>');
            return;
        }
    } elsif ($ENV{'form.action'} eq 'copy') { 
	if (-e $conspace) {
	    if ($ENV{'form.newfilename'}) {
               $ENV{'form.newfilename'}=~/(.*)\/([^\/]+)\.(\w+)$/;
               if ($3 ne $suffix) {
		   $r->print(
                    '<p><font color=red>Warning: change of MIME type!</font>');
               }
               if (-e 
       	         '/home/httpd/'.$uname.'/'.$dir.'/'.$ENV{'form.newfilename'}) {
		   $r->print(
                    '<p><font color=red>Warning: target file exists!</font>');
               }
	       $r->print('<input type=hidden name=newfilename value="'.
                         $ENV{'form.newfilename'}.
                         '"><p>Copy <tt>'.$fn.'</tt> to <tt>'.
                         $dir.'/'.$ENV{'form.newfilename'}.'</tt>?');
	    } else {
	       $r->print('<p>No new filename specified.</form>');
               return;
	    }
        } else {
	    $r->print('<p>No such file.</form>');
            return;
        }
    } elsif ($ENV{'form.action'} eq 'newdir') {
        my $newdir='/home/'.$uname.'/public_html/'.
                   $fn.$ENV{'form.newfilename'};
	if (-e $newdir) {
            $r->print('<p>Directory exists.</form>');
            return;
        }
	$r->print('<input type=hidden name=newfilename value="'.
                  $ENV{'form.newfilename'}.
                  '"><p>Make new directory <tt>'.
                  $fn.$ENV{'form.newfilename'}.'</tt>?');
       
    }
    $r->print('<p><input type=submit value=Continue></form>'); 
}

sub phasetwo {
    my ($r,$fn,$uname,$udom)=@_;
    $r->print('Under Construction');
}

sub handler {

  my $r=shift;

  my $fn;

  if ($ENV{'form.filename'}) {
      $fn=$ENV{'form.filename'};
      $fn=~s/^http\:\/\/[^\/]+//;
  } else {
     $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
         ' unspecified filename for cfile', $r->filename); 
     return HTTP_NOT_FOUND;
  }

  unless ($fn) { 
     $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
         ' trying to cfile non-existing file', $r->filename); 
     return HTTP_NOT_FOUND;
  } 

# ----------------------------------------------------------- Start page output
  my $uname;
  my $udom;

  ($uname,$udom)=
    &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain'));
  unless (($uname) && ($udom)) {
     $r->log_reason($uname.' at '.$udom.
         ' trying to manipulate file '.$ENV{'form.filename'}.
         ' ('.$fn.') - not authorized', 
         $r->filename); 
     return HTTP_NOT_ACCEPTABLE;
  }

  $fn=~s/\/\~(\w+)//;

  $r->content_type('text/html');
  $r->send_http_header;

  $r->print('<html><head><title>LON-CAPA Construction Space</title></head>');

  $r->print(
   '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');

  
  $r->print('<h1>Construction Space <tt>'.$fn.'</tt></h1>');
  
  if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
          $r->print('<h3><font color=red>Co-Author: '.$uname.' at '.$udom.
               '</font></h3>');
  }

  if ($ENV{'form.action'} eq 'delete') {
      $r->print('<h3>Delete</h3>');
  } elsif ($ENV{'form.action'} eq 'rename') {
      $r->print('<h3>Rename</h3>');
  } elsif ($ENV{'form.action'} eq 'newdir') {
      $r->print('<h3>New Directory</h3>');
  } elsif ($ENV{'form.action'} eq 'copy') {
      $r->print('<h3>Copy</h3>');
  } else {
     $r->print('<p>Unknown Action</body></html>');
     return OK;  
  }
  if ($ENV{'form.phase'} eq 'two') {
      &phasetwo($r,$fn,$uname,$udom);
  } else {
      &phaseone($r,$fn,$uname,$udom);
  }

  $r->print('</body></html>');
  return OK;  
}

1;
__END__

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