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