Annotation of loncom/publisher/lonpubdir.pm, revision 1.4
1.1 www 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: #
1.2 www 13: # 03/31,04/03 Gerd Kortemeyer
1.1 www 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:
22:
23: sub handler {
24:
25: my $r=shift;
26:
27: my $fn;
28:
29: if ($ENV{'form.filename'}) {
30: $fn=$ENV{'form.filename'};
31: $fn=~s/^http\:\/\/[^\/]+\/\~(\w+)/\/home\/$1\/public_html/;
32: $fn=~s/\/[^\/]+$//;
33: } else {
34: $fn=$r->filename();
35: }
36:
1.3 www 37: $fn=~s/\/$//;
1.1 www 38:
39: unless ($fn) {
40: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
1.2 www 41: ' trying to list empty directory', $r->filename);
1.1 www 42: return HTTP_NOT_FOUND;
43: }
44:
45: # ----------------------------------------------------------- Start page output
46:
47: my $uname=$ENV{'user.name'};
48: my $udom=$ENV{'user.domain'};
49:
50: $r->content_type('text/html');
51: $r->send_http_header;
52:
53: $r->print('<html><head><title>LON-CAPA Construction Space</title></head>');
54:
55: $r->print(
56: '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
57:
58: my $thisdisfn=$fn;
59: $thisdisfn=~s/^\/home\/$uname\/public_html//;
60:
1.3 www 61: $r->print('<h1>Construction Space Directory <tt>'.$thisdisfn.'/</tt></h1>');
1.1 www 62:
63: my $docroot=$r->dir_config('lonDocRoot');
64:
65: my $resdir=$docroot.'/res/'.$udom.'/'.$uname.$thisdisfn;
66: my $linkdir='/~'.$uname.$thisdisfn;
67:
1.2 www 68: $r->print('<table border=2>'.
69: '<tr><th>Filename</th><th>Modified</th><th>Status</th></tr>');
1.1 www 70:
1.2 www 71: my $filename;
72: my $dirptr=16384;
1.1 www 73:
1.2 www 74: opendir(DIR,$fn);
75: while ($filename=readdir(DIR)) {
76: my ($cdev,$cino,$cmode,$cnlink,
77: $cuid,$cgid,$crdev,$csize,
78: $catime,$cmtime,$cctime,
79: $cblksize,$cblocks)=stat($fn.'/'.$filename);
80: $filename=~/\.(\w+)$/;
81: if (($1 ne 'meta') && (&Apache::lonnet::fileembstyle($1))) {
82: my $status='Unpublished';
83: my $bgcol='#FFBBBB';
84: if (-e $resdir.'/'.$filename) {
85: my ($rdev,$rino,$rmode,$rnlink,
86: $ruid,$rgid,$rrdev,$rsize,
87: $ratime,$rmtime,$rctime,
88: $rblksize,$rblocks)=stat($resdir.'/'.$filename);
89: if ($rmtime>=$cmtime) {
90: $status='Published';
91: $bgcol='#BBFFBB';
92: } else {
93: $status='Modified';
94: $bgcol='#FFFFBB';
95: }
96: }
97: $r->print('<tr bgcolor='.$bgcol.
98: '><td><a href="'.$linkdir.'/'.$filename.'">'.$filename.
99: '</a></td><td>'.localtime($cmtime).'</td><td>'.$status.'</td></tr>');
100: } elsif ($cmode&$dirptr) {
1.3 www 101: my $disfilename=$filename;
102: if ($filename eq '..') {
103: $disfilename='<i>Parent Directory</i>';
104: }
105: unless ((($filename eq '..') && ($thisdisfn eq '')) ||
106: ($filename eq '.')) {
107: $r->print('<tr bgcolor=#BBBBFF'.
108: '><td><a href="'.$linkdir.'/'.$filename.'">'.$disfilename.
109: '</a></td><td>'.localtime($cmtime).'</td><td> </td></tr>');
110: }
1.2 www 111: }
112: }
113: closedir(DIR);
114:
115: $r->print('</table></body></html>');
1.1 www 116: return OK;
117: }
1.4 ! www 118:
! 119: 1;
! 120: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>