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