Annotation of loncom/publisher/lonpubdir.pm, revision 1.7
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.6 www 13: # 03/31,04/03,05/09 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);
1.6 www 21: use Apache::loncacc;
1.1 www 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: }
1.6 www 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: }
1.1 www 50:
1.3 www 51: $fn=~s/\/$//;
1.1 www 52:
53: unless ($fn) {
54: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
1.2 www 55: ' trying to list empty directory', $r->filename);
1.1 www 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:
1.3 www 73: $r->print('<h1>Construction Space Directory <tt>'.$thisdisfn.'/</tt></h1>');
1.6 www 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:
1.1 www 80:
81: my $docroot=$r->dir_config('lonDocRoot');
82:
83: my $resdir=$docroot.'/res/'.$udom.'/'.$uname.$thisdisfn;
84: my $linkdir='/~'.$uname.$thisdisfn;
85:
1.2 www 86: $r->print('<table border=2>'.
87: '<tr><th>Filename</th><th>Modified</th><th>Status</th></tr>');
1.1 www 88:
1.2 www 89: my $filename;
90: my $dirptr=16384;
1.1 www 91:
1.2 www 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';
1.5 www 113: if
114: (&Apache::lonnet::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
1.7 ! www 115: $status.='<br><a href="/adm/diff?filename=/~'.$uname.
! 116: '/'.$filename.
1.5 www 117: '&versionone=priv" target=cat>Diffs</a>';
118: }
1.2 www 119: }
120: }
121: $r->print('<tr bgcolor='.$bgcol.
122: '><td><a href="'.$linkdir.'/'.$filename.'">'.$filename.
123: '</a></td><td>'.localtime($cmtime).'</td><td>'.$status.'</td></tr>');
124: } elsif ($cmode&$dirptr) {
1.3 www 125: my $disfilename=$filename;
126: if ($filename eq '..') {
127: $disfilename='<i>Parent Directory</i>';
128: }
129: unless ((($filename eq '..') && ($thisdisfn eq '')) ||
130: ($filename eq '.')) {
131: $r->print('<tr bgcolor=#BBBBFF'.
132: '><td><a href="'.$linkdir.'/'.$filename.'">'.$disfilename.
133: '</a></td><td>'.localtime($cmtime).'</td><td> </td></tr>');
134: }
1.2 www 135: }
136: }
137: closedir(DIR);
138:
139: $r->print('</table></body></html>');
1.1 www 140: return OK;
141: }
1.4 www 142:
143: 1;
144: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>