Annotation of loncom/publisher/lonpubdir.pm, revision 1.16
1.1 www 1: # The LearningOnline Network with CAPA
1.16 ! albertel 2: # (Publication Handler
! 3: #
! 4: # $Id: gplheader.pl,v 1.1 2001/11/29 18:19:27 www Exp $
! 5: #
! 6: # Copyright Michigan State University Board of Trustees
! 7: #
! 8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
! 9: #
! 10: # LON-CAPA is free software; you can redistribute it and/or modify
! 11: # it under the terms of the GNU General Public License as published by
! 12: # the Free Software Foundation; either version 2 of the License, or
! 13: # (at your option) any later version.
! 14: #
! 15: # LON-CAPA is distributed in the hope that it will be useful,
! 16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
! 17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! 18: # GNU General Public License for more details.
! 19: #
! 20: # You should have received a copy of the GNU General Public License
! 21: # along with LON-CAPA; if not, write to the Free Software
! 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
! 23: #
! 24: # /home/httpd/html/adm/gpl.txt
! 25: #
! 26: # http://www.lon-capa.org/
1.1 www 27: #
28: #
29: # (TeX Content Handler
30: #
31: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
32: #
33: # 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
34: # 03/23 Guy Albertelli
35: # 03/24,03/29 Gerd Kortemeyer)
36: #
1.13 www 37: # 03/31,04/03,05/09,06/23,08/18,08/20 Gerd Kortemeyer
1.1 www 38:
39: package Apache::lonpubdir;
40:
41: use strict;
42: use Apache::File;
43: use File::Copy;
44: use Apache::Constants qw(:common :http :methods);
1.6 www 45: use Apache::loncacc;
1.8 www 46: use Apache::lonnet;
1.1 www 47:
48:
49: sub handler {
50:
51: my $r=shift;
52:
53: my $fn;
54:
55: if ($ENV{'form.filename'}) {
56: $fn=$ENV{'form.filename'};
57: $fn=~s/^http\:\/\/[^\/]+\/\~(\w+)/\/home\/$1\/public_html/;
58: $fn=~s/\/[^\/]+$//;
59: } else {
60: $fn=$r->filename();
61: }
1.6 www 62:
63: my $uname;
64: my $udom;
65:
1.9 www 66: ($uname,$udom)=
1.6 www 67: &Apache::loncacc::constructaccess(
1.9 www 68: $fn,$r->dir_config('lonDefDomain'));
69: unless (($uname) && ($udom)) {
1.6 www 70: $r->log_reason($uname.' at '.$udom.
71: ' trying to publish file '.$ENV{'form.filename'}.
72: ' ('.$fn.') - not authorized',
73: $r->filename);
74: return HTTP_NOT_ACCEPTABLE;
75: }
1.1 www 76:
1.3 www 77: $fn=~s/\/$//;
1.1 www 78:
79: unless ($fn) {
80: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
1.2 www 81: ' trying to list empty directory', $r->filename);
1.1 www 82: return HTTP_NOT_FOUND;
83: }
84:
85: # ----------------------------------------------------------- Start page output
86:
87:
88: $r->content_type('text/html');
89: $r->send_http_header;
90:
91: $r->print('<html><head><title>LON-CAPA Construction Space</title></head>');
92:
93: $r->print(
94: '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
95:
96: my $thisdisfn=$fn;
97: $thisdisfn=~s/^\/home\/$uname\/public_html//;
98:
1.3 www 99: $r->print('<h1>Construction Space Directory <tt>'.$thisdisfn.'/</tt></h1>');
1.6 www 100:
101: if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
102: $r->print('<h3><font color=red>Co-Author: '.$uname.' at '.$udom.
103: '</font></h3>');
104: }
105:
1.1 www 106:
107: my $docroot=$r->dir_config('lonDocRoot');
108:
109: my $resdir=$docroot.'/res/'.$udom.'/'.$uname.$thisdisfn;
110: my $linkdir='/~'.$uname.$thisdisfn;
111:
1.2 www 112: $r->print('<table border=2>'.
1.12 www 113: '<tr><th>Filename</th><th>Modified</th><th>Status</th><th> </th></tr>');
1.1 www 114:
1.2 www 115: my $filename;
116: my $dirptr=16384;
1.1 www 117:
1.2 www 118: opendir(DIR,$fn);
1.10 albertel 119: my @files=sort(readdir(DIR));
1.11 albertel 120: foreach my $filename (@files) {
1.2 www 121: my ($cdev,$cino,$cmode,$cnlink,
122: $cuid,$cgid,$crdev,$csize,
123: $catime,$cmtime,$cctime,
124: $cblksize,$cblocks)=stat($fn.'/'.$filename);
1.12 www 125:
1.10 albertel 126: my $extension='';
127: if ($filename=~/\.(\w+)$/) { $extension=$1; }
1.15 matthew 128: if ($cmode&$dirptr) {
129: my $disfilename=$filename;
130: if ($filename eq '..') {
131: $disfilename='<i>Parent Directory</i>';
132: }
133: unless ((($filename eq '..') && ($thisdisfn eq '')) ||
134: ($filename eq '.')) {
135: $r->print('<tr bgcolor=#BBBBFF'.
136: '><td><a href="'.$linkdir.'/'.$filename.'">'.$disfilename.
137: '</a></td><td>'.localtime($cmtime).'</td><td> </td><td> </td></tr>'
138: );
139: }
140: } elsif (&Apache::lonnet::fileembstyle($extension) ne 'hdn') {
1.2 www 141: my $status='Unpublished';
142: my $bgcol='#FFBBBB';
143: if (-e $resdir.'/'.$filename) {
144: my ($rdev,$rino,$rmode,$rnlink,
145: $ruid,$rgid,$rrdev,$rsize,
146: $ratime,$rmtime,$rctime,
147: $rblksize,$rblocks)=stat($resdir.'/'.$filename);
148: if ($rmtime>=$cmtime) {
149: $status='Published';
150: $bgcol='#BBFFBB';
151: } else {
152: $status='Modified';
153: $bgcol='#FFFFBB';
1.5 www 154: if
155: (&Apache::lonnet::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
1.7 www 156: $status.='<br><a href="/adm/diff?filename=/~'.$uname.
1.12 www 157: $thisdisfn.'/'.$filename.
1.5 www 158: '&versionone=priv" target=cat>Diffs</a>';
159: }
1.2 www 160: }
1.13 www 161: $status.='<br><a href="/adm/retrieve?filename=/~'.$uname.
162: $thisdisfn.'/'.$filename.'" target=cat>Retrieve</a>';
1.2 www 163: }
164: $r->print('<tr bgcolor='.$bgcol.
165: '><td><a href="'.$linkdir.'/'.$filename.'">'.$filename.
1.12 www 166: '</a></td><td>'.localtime($cmtime).'</td><td>'.$status.'</td>'.
167: '<td><a target="_parent" href="/adm/publish?filename=/~'.$uname.
168: $thisdisfn.'/'.$filename.'">'.
169: 'Publish</a></td></tr>');
1.14 albertel 170: } else {
1.15 matthew 171: # "hidden" extension and not a directory, so hide it away.
1.2 www 172: }
173: }
174: closedir(DIR);
175:
176: $r->print('</table></body></html>');
1.1 www 177: return OK;
178: }
1.4 www 179:
180: 1;
181: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>