Annotation of loncom/publisher/loncfile.pm, revision 1.4
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: }
1.4 ! www 55: $r->print('<input type=hidden name=newfilename value="'.
! 56: $ENV{'form.newfilename'}.
! 57: '"><p>Rename <tt>'.$fn.'</tt> to <tt>'.
1.3 www 58: $dir.'/'.$ENV{'form.newfilename'}.'</tt>?');
59: } else {
60: $r->print('<p>No new filename specified.</form>');
61: return;
62: }
63: } else {
64: $r->print('<p>No such file.</form>');
65: return;
66: }
67: } elsif ($ENV{'form.action'} eq 'delete') {
68: if (-e $conspace) {
69: $r->print('<p>Delete <tt>'.$fn.'</tt>?');
70: } else {
71: $r->print('<p>No such file.</form>');
72: return;
1.1 www 73: }
1.3 www 74: } elsif ($ENV{'form.action'} eq 'copy') {
75: if (-e $conspace) {
76: if ($ENV{'form.newfilename'}) {
77: $ENV{'form.newfilename'}=~/(.*)\/([^\/]+)\.(\w+)$/;
78: if ($3 ne $suffix) {
79: $r->print(
80: '<p><font color=red>Warning: change of MIME type!</font>');
81: }
82: if (-e
83: '/home/httpd/'.$uname.'/'.$dir.'/'.$ENV{'form.newfilename'}) {
84: $r->print(
85: '<p><font color=red>Warning: target file exists!</font>');
86: }
1.4 ! www 87: $r->print('<input type=hidden name=newfilename value="'.
! 88: $ENV{'form.newfilename'}.
! 89: '"><p>Copy <tt>'.$fn.'</tt> to <tt>'.
1.3 www 90: $dir.'/'.$ENV{'form.newfilename'}.'</tt>?');
91: } else {
92: $r->print('<p>No new filename specified.</form>');
93: return;
94: }
95: } else {
96: $r->print('<p>No such file.</form>');
97: return;
98: }
99: } elsif ($ENV{'form.action'} eq 'newdir') {
1.4 ! www 100: my $newdir='/home/'.$uname.'/public_html/'.
! 101: $fn.$ENV{'form.newfilename'};
! 102: if (-e $newdir) {
1.3 www 103: $r->print('<p>Directory exists.</form>');
104: return;
105: }
1.4 ! www 106: $r->print('<input type=hidden name=newfilename value="'.
! 107: $ENV{'form.newfilename'}.
! 108: '"><p>Make new directory <tt>'.
! 109: $fn.$ENV{'form.newfilename'}.'</tt>?');
1.3 www 110:
1.1 www 111: }
1.3 www 112: $r->print('<p><input type=submit value=Continue></form>');
1.1 www 113: }
114:
115: sub phasetwo {
116: my ($r,$fn,$uname,$udom)=@_;
1.4 ! www 117: $r->print('Under Construction');
1.1 www 118: }
119:
120: sub handler {
121:
122: my $r=shift;
123:
124: my $fn;
125:
126: if ($ENV{'form.filename'}) {
127: $fn=$ENV{'form.filename'};
128: $fn=~s/^http\:\/\/[^\/]+//;
129: } else {
130: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
131: ' unspecified filename for cfile', $r->filename);
132: return HTTP_NOT_FOUND;
133: }
134:
135: unless ($fn) {
136: $r->log_reason($ENV{'user.name'}.' at '.$ENV{'user.domain'}.
137: ' trying to cfile non-existing file', $r->filename);
138: return HTTP_NOT_FOUND;
139: }
140:
141: # ----------------------------------------------------------- Start page output
142: my $uname;
143: my $udom;
144:
145: ($uname,$udom)=
146: &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain'));
147: unless (($uname) && ($udom)) {
148: $r->log_reason($uname.' at '.$udom.
1.4 ! www 149: ' trying to manipulate file '.$ENV{'form.filename'}.
1.1 www 150: ' ('.$fn.') - not authorized',
151: $r->filename);
152: return HTTP_NOT_ACCEPTABLE;
153: }
154:
155: $fn=~s/\/\~(\w+)//;
156:
157: $r->content_type('text/html');
158: $r->send_http_header;
159:
160: $r->print('<html><head><title>LON-CAPA Construction Space</title></head>');
161:
162: $r->print(
163: '<body bgcolor="#FFFFFF"><img align=right src=/adm/lonIcons/lonlogos.gif>');
164:
165:
166: $r->print('<h1>Construction Space <tt>'.$fn.'</tt></h1>');
167:
168: if (($uname ne $ENV{'user.name'}) || ($udom ne $ENV{'user.domain'})) {
169: $r->print('<h3><font color=red>Co-Author: '.$uname.' at '.$udom.
170: '</font></h3>');
171: }
172:
1.2 www 173: if ($ENV{'form.action'} eq 'delete') {
174: $r->print('<h3>Delete</h3>');
175: } elsif ($ENV{'form.action'} eq 'rename') {
176: $r->print('<h3>Rename</h3>');
177: } elsif ($ENV{'form.action'} eq 'newdir') {
178: $r->print('<h3>New Directory</h3>');
179: } elsif ($ENV{'form.action'} eq 'copy') {
180: $r->print('<h3>Copy</h3>');
181: } else {
182: $r->print('<p>Unknown Action</body></html>');
183: return OK;
184: }
1.1 www 185: if ($ENV{'form.phase'} eq 'two') {
1.4 ! www 186: &phasetwo($r,$fn,$uname,$udom);
1.1 www 187: } else {
1.3 www 188: &phaseone($r,$fn,$uname,$udom);
1.1 www 189: }
190:
191: $r->print('</body></html>');
192: return OK;
193: }
194:
195: 1;
196: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>