Annotation of loncom/publisher/loncfile.pm, revision 1.3
1.1 www 1: # The LearningOnline Network with CAPA
2: # Handler to rename files, etc, in construction space
3: #
4: # (Handler to retrieve an old version of a file
5: #
6: # (Publication Handler
7: #
8: # (TeX Content Handler
9: #
10: # 05/29/00,05/30,10/11 Gerd Kortemeyer)
11: #
12: # 11/28,11/29,11/30,12/01,12/02,12/04,12/23 Gerd Kortemeyer
13: # 03/23 Guy Albertelli
14: # 03/24,03/29 Gerd Kortemeyer)
15: #
16: # 03/31,04/03,05/02,05/09,06/23 Gerd Kortemeyer)
17: #
18: # 06/23 Gerd Kortemeyer
19:
20: package Apache::loncfile;
21:
22: use strict;
23: use Apache::File;
24: use File::Copy;
25: use Apache::Constants qw(:common :http :methods);
26: use Apache::loncacc;
27:
28: sub phaseone {
29: my ($r,$fn,$uname,$udom)=@_;
30:
1.3 ! www 31: $fn=~/(.*)\/([^\/]+)\.(\w+)$/;
! 32: my $dir=$1;
! 33: my $main=$2;
! 34: my $suffix=$3;
1.1 www 35:
1.3 ! www 36: my $conspace='/home/'.$uname.'/public_html'.$fn;
1.1 www 37:
1.3 ! www 38: $r->print('<form action=/adm/cfile method=post>'.
1.1 www 39: '<input type=hidden name=filename value="/~'.$uname.$fn.'">'.
40: '<input type=hidden name=phase value=two>'.
1.3 ! www 41: '<input type=hidden name=action value='.$ENV{'form.action'}.'>');
! 42: if ($ENV{'form.action'} eq 'rename') {
! 43: if (-e $conspace) {
! 44: if ($ENV{'form.newfilename'}) {
! 45: $ENV{'form.newfilename'}=~/(.*)\/([^\/]+)\.(\w+)$/;
! 46: if ($3 ne $suffix) {
! 47: $r->print(
! 48: '<p><font color=red>Warning: change of MIME type!</font>');
! 49: }
! 50: if (-e
! 51: '/home/httpd/'.$uname.'/'.$dir.'/'.$ENV{'form.newfilename'}) {
! 52: $r->print(
! 53: '<p><font color=red>Warning: target file exists!</font>');
! 54: }
! 55: $r->print('<p>Rename <tt>'.$fn.'</tt> to <tt>'.
! 56: $dir.'/'.$ENV{'form.newfilename'}.'</tt>?');
! 57: } else {
! 58: $r->print('<p>No new filename specified.</form>');
! 59: return;
! 60: }
! 61: } else {
! 62: $r->print('<p>No such file.</form>');
! 63: return;
! 64: }
! 65: } elsif ($ENV{'form.action'} eq 'delete') {
! 66: if (-e $conspace) {
! 67: $r->print('<p>Delete <tt>'.$fn.'</tt>?');
! 68: } else {
! 69: $r->print('<p>No such file.</form>');
! 70: return;
1.1 www 71: }
1.3 ! www 72: } elsif ($ENV{'form.action'} eq 'copy') {
! 73: if (-e $conspace) {
! 74: if ($ENV{'form.newfilename'}) {
! 75: $ENV{'form.newfilename'}=~/(.*)\/([^\/]+)\.(\w+)$/;
! 76: if ($3 ne $suffix) {
! 77: $r->print(
! 78: '<p><font color=red>Warning: change of MIME type!</font>');
! 79: }
! 80: if (-e
! 81: '/home/httpd/'.$uname.'/'.$dir.'/'.$ENV{'form.newfilename'}) {
! 82: $r->print(
! 83: '<p><font color=red>Warning: target file exists!</font>');
! 84: }
! 85: $r->print('<p>Copy <tt>'.$fn.'</tt> to <tt>'.
! 86: $dir.'/'.$ENV{'form.newfilename'}.'</tt>?');
! 87: } else {
! 88: $r->print('<p>No new filename specified.</form>');
! 89: return;
! 90: }
! 91: } else {
! 92: $r->print('<p>No such file.</form>');
! 93: return;
! 94: }
! 95: } elsif ($ENV{'form.action'} eq 'newdir') {
! 96: if (-e $conspace) {
! 97: $r->print('<p>Directory exists.</form>');
! 98: return;
! 99: }
! 100:
1.1 www 101: }
1.3 ! www 102: $r->print('<p><input type=submit value=Continue></form>');
1.1 www 103: }
104:
105: sub phasetwo {
106: my ($r,$fn,$uname,$udom)=@_;
1.3 ! www 107: if ($ENV{'form.action'} eq 'rename') {
! 108: } elsif ($ENV{'form.action'} eq 'delete') {
! 109: } elsif ($ENV{'form.action'} eq 'copy') {
! 110: } elsif ($ENV{'form.action'} eq 'newdir') {
! 111: }
1.1 www 112: }
113:
114: sub handler {
115:
116: my $r=shift;
117:
118: my $fn;
119:
120: if ($ENV{'form.filename'}) {
121: $fn=$ENV{'form.filename'};
122: $fn=~s/^http\:\/\/[^\/]+//;
123: } else {
124: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
125: ' unspecified filename for cfile', $r->filename);
126: return HTTP_NOT_FOUND;
127: }
128:
129: unless ($fn) {
130: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
131: ' trying to cfile non-existing file', $r->filename);
132: return HTTP_NOT_FOUND;
133: }
134:
135: # ----------------------------------------------------------- Start page output
136: my $uname;
137: my $udom;
138:
139: ($uname,$udom)=
140: &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain'));
141: unless (($uname) && ($udom)) {
142: $r->log_reason($uname.' at '.$udom.
143: ' trying to publish file '.$ENV{'form.filename'}.
144: ' ('.$fn.') - not authorized',
145: $r->filename);
146: return HTTP_NOT_ACCEPTABLE;
147: }
148:
149: $fn=~s/\/\~(\w+)//;
150:
151: $r->content_type('text/html');
152: $r->send_http_header;
153:
154: $r->print('<html><head><title>LON-CAPA Construction Space</title></head>');
155:
156: $r->print(
157: '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
158:
159:
160: $r->print('<h1>Construction Space <tt>'.$fn.'</tt></h1>');
161:
162: if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
163: $r->print('<h3><font color=red>Co-Author: '.$uname.' at '.$udom.
164: '</font></h3>');
165: }
166:
1.2 www 167: if ($ENV{'form.action'} eq 'delete') {
168: $r->print('<h3>Delete</h3>');
169: } elsif ($ENV{'form.action'} eq 'rename') {
170: $r->print('<h3>Rename</h3>');
171: } elsif ($ENV{'form.action'} eq 'newdir') {
172: $r->print('<h3>New Directory</h3>');
173: } elsif ($ENV{'form.action'} eq 'copy') {
174: $r->print('<h3>Copy</h3>');
175: } else {
176: $r->print('<p>Unknown Action</body></html>');
177: return OK;
178: }
1.1 www 179: if ($ENV{'form.phase'} eq 'two') {
180: # &phasetwo($r,$fn,$uname,$udom);
181: } else {
1.3 ! www 182: &phaseone($r,$fn,$uname,$udom);
1.1 www 183: }
184:
185: $r->print('</body></html>');
186: return OK;
187: }
188:
189: 1;
190: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>