Annotation of loncom/publisher/lonpubdir.pm, revision 1.12
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.12 ! www 13: # 03/31,04/03,05/09,06/23,08/18 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>'.
1.12 ! www 89: '<tr><th>Filename</th><th>Modified</th><th>Status</th><th> </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.12 ! www 101:
1.10 albertel 102: my $extension='';
103: if ($filename=~/\.(\w+)$/) { $extension=$1; }
1.12 ! www 104: if (($extension ne 'meta') &&
! 105: (&Apache::lonnet::fileembstyle($extension))) {
1.2 www 106: my $status='Unpublished';
107: my $bgcol='#FFBBBB';
108: if (-e $resdir.'/'.$filename) {
109: my ($rdev,$rino,$rmode,$rnlink,
110: $ruid,$rgid,$rrdev,$rsize,
111: $ratime,$rmtime,$rctime,
112: $rblksize,$rblocks)=stat($resdir.'/'.$filename);
113: if ($rmtime>=$cmtime) {
114: $status='Published';
115: $bgcol='#BBFFBB';
116: } else {
117: $status='Modified';
118: $bgcol='#FFFFBB';
1.5 www 119: if
120: (&Apache::lonnet::fileembstyle(($filename=~/\.(\w+)$/)) eq 'ssi') {
1.7 www 121: $status.='<br><a href="/adm/diff?filename=/~'.$uname.
1.12 ! www 122: $thisdisfn.'/'.$filename.
1.5 www 123: '&versionone=priv" target=cat>Diffs</a>';
124: }
1.2 www 125: }
126: }
127: $r->print('<tr bgcolor='.$bgcol.
128: '><td><a href="'.$linkdir.'/'.$filename.'">'.$filename.
1.12 ! www 129: '</a></td><td>'.localtime($cmtime).'</td><td>'.$status.'</td>'.
! 130: '<td><a target="_parent" href="/adm/publish?filename=/~'.$uname.
! 131: $thisdisfn.'/'.$filename.'">'.
! 132: 'Publish</a></td></tr>');
1.2 www 133: } elsif ($cmode&$dirptr) {
1.3 www 134: my $disfilename=$filename;
135: if ($filename eq '..') {
136: $disfilename='<i>Parent Directory</i>';
137: }
138: unless ((($filename eq '..') && ($thisdisfn eq '')) ||
139: ($filename eq '.')) {
140: $r->print('<tr bgcolor=#BBBBFF'.
141: '><td><a href="'.$linkdir.'/'.$filename.'">'.$disfilename.
1.12 ! www 142: '</a></td><td>'.localtime($cmtime).'</td><td> </td><td> </td></tr>'
! 143: );
1.3 www 144: }
1.2 www 145: }
146: }
147: closedir(DIR);
148:
149: $r->print('</table></body></html>');
1.1 www 150: return OK;
151: }
1.4 www 152:
153: 1;
154: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>