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