Diff for /loncom/publisher/loncfile.pm between versions 1.9 and 1.11

version 1.9, 2002/05/24 05:11:40 version 1.11, 2002/06/07 01:35:48
Line 63  use Apache::Constants qw(:common :http : Line 63  use Apache::Constants qw(:common :http :
 use Apache::loncacc;  use Apache::loncacc;
 use Apache::Log ();  use Apache::Log ();
   
 my $DEBUG=1;  my $DEBUG=0;
   my $r; # Needs to be global for some stuff RF.
 #  #
 #  Debug  #  Debug
 #    If debugging is enabled puts out a debuggin message determined by the  #    If debugging is enabled puts out a debuggin message determined by the
Line 83  sub Debug { Line 83  sub Debug {
  $log->debug($message);       $log->debug($message);    
     }      }
 }  }
   #
   #   URLToPath
   #     Convert a URL to a file system path.
   #
   #   In order to manipulate the construction space objects, it's necessary
   #   to access url identified objects a filespace objects.  This function
   #   translates a construction space URL to a file system path.
   # Parameters:
   #    Url    - string [in] The url to convert.
   # Returns:
   #    The corresponing file system path.
   sub URLToPath
   {
       my $Url = shift;
       &Debug($r, "UrlToPath got: $Url");
       $Url=~ s/^http\:\/\/[^\/]+\/\~(\w+)/\/home\/$1\/public_html/;
       $Url=~ s/^http\:\/\/[^\/]+//;
       &Debug($r, "Returning $Url \n");
       return $Url;
   }
 sub exists {  sub exists {
     my ($uname,$udom,$dir,$newfile)=@_;      my ($uname,$udom,$dir,$newfile)=@_;
     my $published='/home/httpd/html/res/'.$udom.'/'.$uname.'/'.$dir.'/'.      my $published='/home/httpd/html/res/'.$udom.'/'.$uname.'/'.$dir.'/'.
Line 120  sub phaseone { Line 139  sub phaseone {
     my $main=$2;      my $main=$2;
     my $suffix=$3;      my $suffix=$3;
   
     my $conspace='/home/'.$uname.'/public_html'.$fn;      my $conspace;
       if ($fn =~ m-^/home/-) {
           $conspace=$fn;
       } else {
           $conspace='/home/'.$uname.'/public_html'.$fn;
       }
   
     $r->print('<form action=/adm/cfile method=post>'.      $r->print('<form action=/adm/cfile method=post>'.
       '<input type=hidden name=filename value="/~'.$uname.$fn.'">'.        '<input type=hidden name=filename value="/~'.$uname.$fn.'">'.
Line 196  sub phasetwo { Line 220  sub phasetwo {
     my $dir=$1;      my $dir=$1;
     my $main=$2;      my $main=$2;
     my $suffix=$3;      my $suffix=$3;
       $dir =~ s-^/[^/]*/[^/]*/[^/]*--;
           
           
     &Debug($r, "loncfile::phase2 dir = $dir main = $main suffix = $suffix");      &Debug($r, "loncfile::phase2 dir = $dir main = $main suffix = $suffix");
Line 209  sub phasetwo { Line 234  sub phasetwo {
     if ($ENV{'form.action'} eq 'rename') {      if ($ENV{'form.action'} eq 'rename') {
  if (-e $conspace) {   if (-e $conspace) {
     if ($ENV{'form.newfilename'}) {      if ($ENV{'form.newfilename'}) {
                unless (rename('/home/'.$uname.'/public_html'.$fn,                 unless (rename($fn,
           '/home/'.$uname.'/public_html'.$dir.'/'.$ENV{'form.newfilename'})) {            '/home/'.$uname.'/public_html'.$dir.'/'.$ENV{'form.newfilename'})) {
     $r->print('<font color=red>Error: '.$!.'</font>');      $r->print('<font color=red>Error: '.$!.'</font>');
                }                 }
Line 220  sub phasetwo { Line 245  sub phasetwo {
         }          }
     } elsif ($ENV{'form.action'} eq 'delete') {       } elsif ($ENV{'form.action'} eq 'delete') { 
  if (-e $conspace) {   if (-e $conspace) {
             unless (unlink('/home/'.$uname.'/public_html'.$fn)) {              unless (unlink($fn)) {
        $r->print('<font color=red>Error: '.$!.'</font>');         $r->print('<font color=red>Error: '.$!.'</font>');
             }              }
         } else {          } else {
Line 230  sub phasetwo { Line 255  sub phasetwo {
     } elsif ($ENV{'form.action'} eq 'copy') {       } elsif ($ENV{'form.action'} eq 'copy') { 
  if (-e $conspace) {   if (-e $conspace) {
     if ($ENV{'form.newfilename'}) {      if ($ENV{'form.newfilename'}) {
                unless (copy('/home/'.$uname.'/public_html'.$fn,                 unless (copy($fn,
            '/home/'.$uname.'/public_html'.$dir.'/'.$ENV{'form.newfilename'})) {             '/home/'.$uname.'/public_html'.$dir.'/'.$ENV{'form.newfilename'})) {
           $r->print('<font color=red>Error: '.$!.'</font>');            $r->print('<font color=red>Error: '.$!.'</font>');
                }                 }
Line 265  sub phasetwo { Line 290  sub phasetwo {
   
 sub handler {  sub handler {
   
   my $r=shift;    $r=shift;
   
   
   &Debug($r, "loncfile.pm - handler entered");    &Debug($r, "loncfile.pm - handler entered");
Line 275  sub handler { Line 300  sub handler {
   if ($ENV{'form.filename'}) {    if ($ENV{'form.filename'}) {
       $fn=$ENV{'form.filename'};        $fn=$ENV{'form.filename'};
       &Debug($r, "loncfile::handler - raw url: $fn");        &Debug($r, "loncfile::handler - raw url: $fn");
       $fn=~s/^http\:\/\/[^\/]+\/\~(\w+)/\/home\/$1\/public_html/;  #      $fn=~s/^http\:\/\/[^\/]+\/\~(\w+)/\/home\/$1\/public_html/;
       $fn=~s/^http\:\/\/[^\/]+//;  #      $fn=~s/^http\:\/\/[^\/]+//;
         $fn=URLToPath($fn);
       &Debug($r, "loncfile::handler - doctored url: $fn");        &Debug($r, "loncfile::handler - doctored url: $fn");
   
   } else {    } else {

Removed from v.1.9  
changed lines
  Added in v.1.11


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