File:  [LON-CAPA] / loncom / publisher / lonpubdir.pm
Revision 1.6: download - view: text, annotated - select for diffs
Wed May 9 16:57:07 2001 UTC (23 years, 1 month ago) by www
Branches: MAIN
CVS tags: HEAD
Respects co-author role, also for /home/author

    1: # The LearningOnline Network with CAPA
    2: #
    3: # (Publication Handler
    4: # 
    5: # (TeX Content Handler
    6: #
    7: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
    8: #
    9: # 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
   10: # 03/23 Guy Albertelli
   11: # 03/24,03/29 Gerd Kortemeyer)
   12: #
   13: # 03/31,04/03,05/09 Gerd Kortemeyer
   14: 
   15: package Apache::lonpubdir;
   16: 
   17: use strict;
   18: use Apache::File;
   19: use File::Copy;
   20: use Apache::Constants qw(:common :http :methods);
   21: use Apache::loncacc;
   22: 
   23: 
   24: sub handler {
   25: 
   26:   my $r=shift;
   27: 
   28:   my $fn;
   29: 
   30:   if ($ENV{'form.filename'}) {
   31:       $fn=$ENV{'form.filename'};
   32:       $fn=~s/^http\:\/\/[^\/]+\/\~(\w+)/\/home\/$1\/public_html/;
   33:       $fn=~s/\/[^\/]+$//;
   34:   } else {
   35:       $fn=$r->filename();
   36:   }
   37: 
   38:   my $uname;
   39:   my $udom;
   40: 
   41:   unless (($uname,$udom)=
   42:     &Apache::loncacc::constructaccess(
   43:              $fn,$r->dir_config('lonDefDomain'))) {
   44:      $r->log_reason($uname.' at '.$udom.
   45:          ' trying to publish file '.$ENV{'form.filename'}.
   46:          ' ('.$fn.') - not authorized', 
   47:          $r->filename); 
   48:      return HTTP_NOT_ACCEPTABLE;
   49:   }
   50:      
   51:   $fn=~s/\/$//;
   52: 
   53:   unless ($fn) { 
   54:      $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
   55:          ' trying to list empty directory', $r->filename); 
   56:      return HTTP_NOT_FOUND;
   57:   } 
   58: 
   59: # ----------------------------------------------------------- Start page output
   60: 
   61: 
   62:   $r->content_type('text/html');
   63:   $r->send_http_header;
   64: 
   65:   $r->print('<html><head><title>LON-CAPA Construction Space</title></head>');
   66: 
   67:   $r->print(
   68:    '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
   69: 
   70:   my $thisdisfn=$fn;
   71:   $thisdisfn=~s/^\/home\/$uname\/public_html//;
   72:   
   73:   $r->print('<h1>Construction Space Directory <tt>'.$thisdisfn.'/</tt></h1>');
   74:   
   75:   if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
   76:           $r->print('<h3><font color=red>Co-Author: '.$uname.' at '.$udom.
   77:                '</font></h3>');
   78:   }
   79: 
   80: 
   81:   my $docroot=$r->dir_config('lonDocRoot');
   82: 
   83:   my $resdir=$docroot.'/res/'.$udom.'/'.$uname.$thisdisfn;
   84:   my $linkdir='/~'.$uname.$thisdisfn;
   85: 
   86:   $r->print('<table border=2>'.
   87:             '<tr><th>Filename</th><th>Modified</th><th>Status</th></tr>');
   88: 
   89:   my $filename;
   90:   my $dirptr=16384;
   91: 
   92:   opendir(DIR,$fn);
   93:   while ($filename=readdir(DIR)) {
   94:      my ($cdev,$cino,$cmode,$cnlink,
   95:          $cuid,$cgid,$crdev,$csize,
   96:          $catime,$cmtime,$cctime,
   97:          $cblksize,$cblocks)=stat($fn.'/'.$filename);
   98:      $filename=~/\.(\w+)$/;
   99:      if (($1 ne 'meta') && (&Apache::lonnet::fileembstyle($1))) {
  100:          my $status='Unpublished';
  101:          my $bgcol='#FFBBBB';
  102:          if (-e $resdir.'/'.$filename) {
  103:             my ($rdev,$rino,$rmode,$rnlink,
  104:                 $ruid,$rgid,$rrdev,$rsize,
  105:                 $ratime,$rmtime,$rctime,
  106:                 $rblksize,$rblocks)=stat($resdir.'/'.$filename);
  107:             if ($rmtime>=$cmtime) {
  108: 		$status='Published';
  109:                 $bgcol='#BBFFBB';
  110:             } else {
  111:                 $status='Modified';
  112:                 $bgcol='#FFFFBB';
  113:                 if 
  114:             (&Apache::lonnet::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
  115:                    $status.='<br><a href="/adm/diff?filename='.$filename.
  116: 		       '&versionone=priv" target=cat>Diffs</a>';
  117: 	        }
  118:             }   
  119: 	 }
  120:          $r->print('<tr bgcolor='.$bgcol.
  121:          '><td><a href="'.$linkdir.'/'.$filename.'">'.$filename.
  122:          '</a></td><td>'.localtime($cmtime).'</td><td>'.$status.'</td></tr>');
  123:      } elsif ($cmode&$dirptr) {
  124:          my $disfilename=$filename;
  125:          if ($filename eq '..') {
  126: 	     $disfilename='<i>Parent Directory</i>';
  127:          }
  128:          unless ((($filename eq '..') && ($thisdisfn eq '')) ||
  129:                  ($filename eq '.')) {
  130:            $r->print('<tr bgcolor=#BBBBFF'.
  131:            '><td><a href="'.$linkdir.'/'.$filename.'">'.$disfilename.
  132:            '</a></td><td>'.localtime($cmtime).'</td><td>&nbsp;</td></tr>');
  133:          }
  134:      }
  135:   }
  136:   closedir(DIR);
  137: 
  138:   $r->print('</table></body></html>');
  139:   return OK;  
  140: }
  141: 
  142: 1;
  143: __END__

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