1: # The LearningOnline Network with CAPA
2: # Handler to rename files, etc, in construction space
3: #
4: # This file responds to the various buttons and events
5: # in the top frame of the construction space directory.
6: # Each event is processed in two phases. The first phase
7: # presents a page that describes the proposed action to the user
8: # and requests confirmation. The second phase commits the action
9: # and displays a page showing the results of the action.
10: #
11: #
12: # $Id: loncfile.pm,v 1.100.2.2 2009/08/28 14:32:26 raeburn Exp $
13: #
14: # Copyright Michigan State University Board of Trustees
15: #
16: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
17: #
18: # LON-CAPA is free software; you can redistribute it and/or modify
19: # it under the terms of the GNU General Public License as published by
20: # the Free Software Foundation; either version 2 of the License, or
21: # (at your option) any later version.
22: #
23: # LON-CAPA is distributed in the hope that it will be useful,
24: # but WITHOUT ANY WARRANTY; without even the implied warranty of
25: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26: # GNU General Public License for more details.
27: #
28: # You should have received a copy of the GNU General Public License
29: # along with LON-CAPA; if not, write to the Free Software
30: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31: #
32: # /home/httpd/html/adm/gpl.txt
33: #
34: # http://www.lon-capa.org/
35: #
36: =pod
37:
38: =head1 NAME
39:
40: Apache::loncfile - Construction space file management.
41:
42: =head1 SYNOPSIS
43:
44: Content handler for buttons on the top frame of the construction space
45: directory.
46:
47: =head1 INTRODUCTION
48:
49: loncfile is invoked when buttons in the top frame of the construction
50: space directory listing are clicked. All operations proceed in two phases.
51: The first phase describes to the user exactly what will be done. If the user
52: confirms the operation, the second phase commits the operation and indicates
53: completion. When the user dismisses the output of phase2, they are returned to
54: an "appropriate" directory listing in general.
55:
56: This is part of the LearningOnline Network with CAPA project
57: described at http://www.lon-capa.org.
58:
59: =head2 Subroutines
60:
61: =cut
62:
63: package Apache::loncfile;
64:
65: use strict;
66: use Apache::File;
67: use File::Basename;
68: use File::Copy;
69: use HTML::Entities();
70: use Apache::Constants qw(:common :http :methods);
71: use Apache::loncacc;
72: use Apache::lonnet;
73: use Apache::loncommon();
74: use Apache::lonlocal;
75: use LONCAPA qw(:DEFAULT :match);
76:
77:
78: my $DEBUG=0;
79: my $r; # Needs to be global for some stuff RF.
80:
81: =pod
82:
83: =item Debug($request, $message)
84:
85: If debugging is enabled puts out a debugging message determined by the
86: caller. The debug message goes to the Apache error log file. Debugging
87: is enabled by setting the module global DEBUG variable to nonzero (TRUE).
88:
89: Parameters:
90:
91: =over 4
92:
93: =item $request - The current request operation.
94:
95: =item $message - The message to put in the log file.
96:
97: =back
98:
99: Returns:
100: nothing.
101:
102: =cut
103:
104: sub Debug {
105: # Put out the indicated message butonly if DEBUG is true.
106: if ($DEBUG) {
107: my ($r,$message) = @_;
108: $r->log_reason($message);
109: }
110: }
111:
112: sub done {
113: my ($url)=@_;
114: my $done=&mt("Done");
115: return(<<ENDDONE);
116: <a href="$url">$done</a>
117: <script type="text/javascript">
118: location.href="$url";
119: </script>
120: ENDDONE
121: }
122:
123: =pod
124:
125: =item URLToPath($url)
126:
127: Convert a URL to a file system path.
128:
129: In order to manipulate the construction space objects, it is necessary
130: to access url identified objects a filespace objects. This function
131: translates a construction space URL to a file system path.
132: Parameters:
133:
134: =over 4
135:
136: =item Url - string [in] The url to convert.
137:
138: =back
139:
140: Returns:
141:
142: =over 4
143:
144: =item The corresponding file system path.
145:
146: =back
147:
148: Global References
149:
150: =over 4
151:
152: =item $r - Request object [in] Referenced in the &Debug calls.
153:
154: =back
155:
156: =cut
157:
158: sub URLToPath {
159: my $Url = shift;
160: &Debug($r, "UrlToPath got: $Url");
161: $Url=~ s/\/+/\//g;
162: $Url=~ s/^https?\:\/\/[^\/]+//;
163: $Url=~ s/^\///;
164: $Url=~ s/(\~|priv\/)($match_username)\//\/home\/$2\/public_html\//;
165: &Debug($r, "Returning $Url \n");
166: return $Url;
167: }
168:
169: sub url {
170: my $fn=shift;
171: $fn=~s/^\/home\/($match_username)\/public\_html/\/priv\/$1/;
172: $fn=&HTML::Entities::encode($fn,'<>"&');
173: return $fn;
174: }
175:
176: sub display {
177: my $fn=shift;
178: $fn=~s-^/home/($match_username)/public_html-/priv/$1-;
179: return '<span class="LC_filename">'.$fn.'</span>';
180: }
181:
182:
183: # see if the file is
184: # a) published (return 0 if not)
185: # b) if, so obsolete (return 0 if not)
186:
187: sub obsolete_unpub {
188: my ($user,$domain,$construct)=@_;
189: my $published=$construct;
190: $published=~
191: s/^\/home\/$user\/public\_html\//\/home\/httpd\/html\/res\/$domain\/$user\//;
192: if (-e $published) {
193: if (&Apache::lonnet::metadata($published,'obsolete')) {
194: return 1;
195: }
196: return 0;
197: } else {
198: return 1;
199: }
200: }
201:
202: # see if directory is empty
203: # ignores any .meta, .save, .bak, and .log files created for a previously
204: # published file, which has since been marked obsolete and deleted.
205: sub empty_directory {
206: my ($dirname,$phase) = @_;
207: if (opendir DIR, $dirname) {
208: my @files = grep(!/^\.\.?$/, readdir(DIR)); # ignore . and ..
209: if (@files) {
210: my @orphans = grep(/\.(meta|save|log|bak)$/,@files);
211: if (scalar(@files) - scalar(@orphans) > 0) {
212: return 0;
213: } else {
214: if (($phase eq 'Delete2') && (@orphans > 0)) {
215: foreach my $file (@orphans) {
216: if ($file =~ /\.(meta|save|log|bak)$/) {
217: unlink($dirname.$file);
218: }
219: }
220: }
221: }
222: }
223: closedir(DIR);
224: return 1;
225: }
226: return 0;
227: }
228:
229: =pod
230:
231: =item exists($user, $domain, $file)
232:
233: Determine if a resource file name has been published or exists
234: in the construction space.
235:
236: Parameters:
237:
238: =over 4
239:
240: =item $user - string [in] - Name of the user for which to check.
241:
242: =item $domain - string [in] - Name of the domain in which the resource
243: might have been published.
244:
245: =item $file - string [in] - Name of the file.
246:
247: =item $creating - string [in] - optional, type of object being created,
248: either 'directory' or 'file'. Defaults to
249: 'file' if unspecified.
250:
251: =back
252:
253: Returns:
254:
255: =over 4
256:
257: =item string - Either undef, 'warning' or 'error' depending on the
258: type of problem
259:
260: =item string - Either where the resource exists as an html string that can
261: be embedded in a dialog or an empty string if the resource
262: does not exist.
263:
264: =back
265:
266: =cut
267:
268: sub exists {
269: my ($user, $domain, $construct, $creating) = @_;
270: $creating ||= 'file';
271:
272: my $published=$construct;
273: $published=~
274: s{^/home/$user/public_html/}{/home/httpd/html/res/$domain/$user/};
275: my ($type,$result);
276: if ( -d $construct ) {
277: return ('error','<p><span class="LC_error">'.&mt('Error: destination for operation is an existing directory.').'</span></p>');
278:
279: }
280:
281: if ( -e $published) {
282: if ( -e $construct ) {
283: $type = 'warning';
284: $result.='<p><span class="LC_warning">'.&mt('Warning: target file exists, and has been published!').'</span></p>';
285: } else {
286: my $published_type = (-d $published) ? 'directory' : 'file';
287:
288: if ($published_type eq $creating) {
289: $type = 'warning';
290: $result.='<p><span class="LC_warning">'.&mt("Warning: a published $published_type of this name exists.").'</span></p>';
291: } else {
292: $type = 'error';
293: $result.='<p><span class="LC_error">'.&mt("Error: a published $published_type of this name exists.").'</span></p>';
294: }
295: }
296: } elsif ( -e $construct) {
297: $type = 'warning';
298: $result.='<p><span class="LC_warning">'.&mt('Warning: target file exists!').'</span></p>';
299: }
300:
301: return ($type,$result);
302: }
303:
304: =pod
305:
306: =item checksuffix($old, $new)
307:
308: Determine if a resource filename suffix (the stuff after the .) would change
309: as a result of this operation.
310:
311: Parameters:
312:
313: =over 4
314:
315: =item $old = string [in] Previous filename.
316:
317: =item $new = string [in] Resultant filename.
318:
319: =back
320:
321: Returns:
322:
323: =over 4
324:
325: =item Empty string if everything worked.
326:
327: =item String containing an error message if there was a problem.
328:
329: =back
330:
331: =cut
332:
333: sub checksuffix {
334: my ($old,$new) = @_;
335: my $result;
336: my $oldsuffix;
337: my $newsuffix;
338: if ($new=~m:(.*/*)([^/]+)\.(\w+)$:) { $newsuffix=$3; }
339: if ($old=~m:(.*)/+([^/]+)\.(\w+)$:) { $oldsuffix=$3; }
340: if (lc($oldsuffix) ne lc($newsuffix)) {
341: $result.=
342: '<p><span class="LC_warning">'.&mt('Warning: change of MIME type!').'</span></p>';
343: }
344: return $result;
345: }
346:
347: sub cleanDest {
348: my ($request,$dest,$subdir,$fn,$uname)=@_;
349: #remove bad characters
350: my $foundbad=0;
351: if ($subdir && $dest =~/\./) {
352: $foundbad=1;
353: $dest=~s/\.//g;
354: }
355: $dest =~ s/(\s+$|^\s+)//g;
356: if ($dest=~/[\#\?&%\":]/) {
357: $foundbad=1;
358: $dest=~s/[\#\?&%\":]//g;
359: }
360: if ($dest=~m|/|) {
361: my ($newpath)=($dest=~m|(.*)/|);
362: $newpath=&relativeDest($fn,$newpath,$uname);
363: if (! -d "$newpath") {
364: $request->print('<p><span class="LC_warning">'
365: .&mt("You have requested to create file in directory [_1] which doesn't exist. The requested directory path has been removed from the requested file name."
366: ,'<span class="LC_filename">'.&display($newpath).'</span>')
367: .'</span></p>');
368: $dest=~s|.*/||;
369: }
370: }
371: if ($dest =~ /\.(\d+)\.(\w+)$/){
372: $request->print('<p><span class="LC_warning">'
373: .&mt('Bad filename [_1]','<span class="LC_filename">'.&display($dest).'</span>')
374: .'<br />'
375: .&mt('[_1](name).(number).(extension)[_2] not allowed.','<tt>','</tt>')
376: .'<br />'
377: .&mt('Removing the [_1].number.[_2] from requested filename.','<tt>','</tt>')
378: .'</span></p>');
379: $dest =~ s/\.(\d+)(\.\w+)$/$2/;
380: }
381: if ($foundbad) {
382: $request->print('<p><span class="LC_warning">'
383: .&mt('Invalid characters in requested name have been removed.')
384: .'</span></p>'
385: );
386: }
387: return $dest;
388: }
389:
390: sub relativeDest {
391: my ($fn,$newfilename,$uname)=@_;
392: if ($newfilename=~/^\//) {
393: # absolute, simply add path
394: $newfilename='/home/'.$uname.'/public_html/';
395: } else {
396: my $dir=$fn;
397: $dir=~s/\/[^\/]+$//;
398: $newfilename=$dir.'/'.$newfilename;
399: }
400: $newfilename=~s://+:/:g; # remove duplicate /
401: while ($newfilename=~m:/\.\./:) {
402: $newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/..
403: }
404: return $newfilename;
405: }
406:
407: =pod
408:
409: =item CloseForm1($request, $user, $file)
410:
411: Close of a form on the successful completion of phase 1 processing
412:
413: Parameters:
414:
415: =over 4
416:
417: =item $request - Apache Request Object [in] - Apache server request object.
418:
419: =item $cancelurl - the url to go to on cancel.
420:
421: =back
422:
423: =cut
424:
425: sub CloseForm1 {
426: my ($request, $fn) = @_;
427: $request->print('<p><input type="submit" value="'.&mt('Continue').'" /></p></form>');
428: $request->print('<form action="'.&url($fn).
429: '" method="post"><p><input type="submit" value="'.&mt('Cancel').'" /></p></form>');
430: }
431:
432:
433: =pod
434:
435: =item CloseForm2($request, $user, $directory)
436:
437: Successfully close off the phase 2 form.
438:
439: Parameters:
440:
441: =over 4
442:
443: =item $request - Apache Request object [in] - The request that is being
444: executed.
445:
446: =item $user - string [in] - Name of the user that is initiating the
447: request.
448:
449: =item $directory - string [in] - Directory in which the operation is
450: being done relative to the top level construction space
451: directory.
452:
453: =back
454:
455: =cut
456:
457: sub CloseForm2 {
458: my ($request, $user, $fn) = @_;
459: $request->print(&done(&url($fn)));
460: }
461:
462: =pod
463:
464: =item Rename1($request, $filename, $user, $domain, $dir)
465:
466: Perform phase 1 processing of the file rename operation.
467:
468: Parameters:
469:
470: =over 4
471:
472: =item $request - Apache Request Object [in] The request object for the
473: current request.
474:
475: =item $filename - The filename relative to construction space.
476:
477: =item $user - Name of the user making the request.
478:
479: =item $domain - User login domain.
480:
481: =item $dir - Directory specification of the path to the file.
482:
483: =back
484:
485: Side effects:
486:
487: =over 4
488:
489: =item A new form is displayed prompting for confirmation. The newfilename
490: hidden field of this form is loaded with
491: new filename relative to the current directory ($dir).
492:
493: =back
494:
495: =cut
496:
497: sub Rename1 {
498: my ($request, $user, $domain, $fn, $newfilename, $style) = @_;
499:
500: if(-e $fn) {
501: if($newfilename) {
502: # is dest a dir
503: if ($style eq 'move') {
504: if (-d $newfilename) {
505: if ($fn =~ m|/([^/]*)$|) { $newfilename .= '/'.$1; }
506: }
507: }
508: if ($newfilename =~ m|/[^\.]+$|) {
509: #no extension add on original extension
510: if ($fn =~ m|/[^\.]*\.([^\.]+)$|) {
511: $newfilename.='.'.$1;
512: }
513: }
514: $request->print(&checksuffix($fn, $newfilename));
515: #renaming a dir, delete the trailing /
516: #remove second to last element for current dir
517: if (-d $fn) {
518: $newfilename=~/\.(\w+)$/;
519: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
520: $request->print('<p><span class="LC_error">'.
521: &mt('Cannot change MIME type of a directory.').
522: '</span>'.
523: '<br /><a href="'.&url($fn).'">'.&mt('Cancel').'</a></p>');
524: return;
525: }
526: $newfilename=~s/\/[^\/]+\/([^\/]+)$/\/$1/;
527: }
528: $newfilename=~s://+:/:g; # remove duplicate /
529: while ($newfilename=~m:/\.\./:) {
530: $newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/..
531: }
532: my ($type, $return)=&exists($user, $domain, $newfilename);
533: $request->print($return);
534: if ($type eq 'error') {
535: $request->print('<br /><a href="'.&url($fn).'">'.&mt('Cancel').'</a>');
536: return;
537: }
538: unless (&obsolete_unpub($user,$domain,$fn)) {
539: $request->print('<p><span class="LC_error">'
540: .&mt('Cannot rename or move non-obsolete published file.')
541: .'</span><br />'
542: .'<a href="'.&url($fn).'">'.&mt('Cancel').'</a></p>'
543: );
544: return;
545: }
546: my $action;
547: if ($style eq 'rename') {
548: $action='Rename';
549: } else {
550: $action='Move';
551: }
552: $request->print('<input type="hidden" name="newfilename" value="'
553: .$newfilename.'" />'
554: .'<p>'
555: .&mt($action.' [_1] to [_2]?'
556: ,&display($fn),&display($newfilename))
557: .'</p>'
558: );
559: &CloseForm1($request, $fn);
560: } else {
561: $request->print('<p class="LC_error">'.&mt('No new filename specified.').'</p></form>');
562: return;
563: }
564: } else {
565: $request->print('<p class="LC_error">'
566: .&mt('No such file: [_1]'
567: ,'<span class="LC_filename">'.&display($fn).'</span>')
568: .'</p></form>'
569: );
570: return;
571: }
572:
573: }
574:
575: =pod
576:
577: =item Delete1
578:
579: Performs phase 1 processing of the delete operation. In phase one
580: we just check to be sure the file exists.
581:
582: Parameters:
583:
584: =over 4
585:
586: =item $request - Apache Request Object [in] request object for the current
587: request.
588:
589: =item $user - string [in] Name of the user initiating the request.
590:
591: =item $domain - string [in] Domain the initiating user is logged in as
592:
593: =item $filename - string [in] Source filename.
594:
595: =back
596:
597: =cut
598:
599: sub Delete1 {
600: my ($request, $user, $domain, $fn) = @_;
601:
602: if( -e $fn) {
603: $request->print('<input type="hidden" name="newfilename" value="'.
604: $fn.'" />');
605: if (-d $fn) {
606: unless (&empty_directory($fn,'Delete1')) {
607: $request->print('<p>'
608: .'<span class="LC_error">'
609: .&mt('Only empty directories may be deleted.')
610: .'</span><br />'
611: .&mt('You must delete the contents of the directory first.')
612: .'</p>'
613: .'<p><a href="'.&url($fn).'">'.&mt('Cancel').'</a></p>'
614: );
615: return;
616: }
617: } else {
618: unless (&obsolete_unpub($user,$domain,$fn)) {
619: $request->print('<p><span class="LC_error">'
620: .&mt('Cannot delete non-obsolete published file.')
621: .'</span><br />'
622: .'<a href="'.&url($fn).'">'.&mt('Cancel').'</a></p>'
623: );
624: return;
625: }
626: }
627: $request->print('<p>'
628: .&mt('Delete [_1]?'
629: ,'<span class="LC_filename">'.&display($fn).'</span>')
630: .'</p>'
631: );
632: &CloseForm1($request, $fn);
633: } else {
634: $request->print('<p class="LC_error">'
635: .&mt('No such file: [_1]'
636: ,'<span class="LC_filename">'.&display($fn).'</span>')
637: .'</p></form>'
638: );
639: }
640: }
641:
642: =pod
643:
644: =item Copy1($request, $user, $domain, $filename, $newfilename)
645:
646: Performs phase 1 processing of the construction space copy command.
647: Ensure that the source file exists. Ensure that a destination exists,
648: also warn if the destination already exists.
649:
650: Parameters:
651:
652: =over 4
653:
654: =item $request - Apache Request Object [in] request object for the current
655: request.
656:
657: =item $user - string [in] Name of the user initiating the request.
658:
659: =item $domain - string [in] Domain the initiating user is logged in as
660:
661: =item $fn - string [in] Source filename.
662:
663: =item $newfilename-string [in] Destination filename.
664:
665: =back
666:
667: =cut
668:
669: sub Copy1 {
670: my ($request, $user, $domain, $fn, $newfilename) = @_;
671:
672: if(-e $fn) {
673: # is dest a dir
674: if (-d $newfilename) {
675: if ($fn =~ m|/([^/]*)$|) { $newfilename .= '/'.$1; }
676: }
677: if ($newfilename =~ m|/[^\.]+$|) {
678: #no extension add on original extension
679: if ($fn =~ m|/[^\.]*\.([^\.]+)$|) { $newfilename.='.'.$1; }
680: }
681: $newfilename=~s://+:/:g; # remove duplicate /
682: while ($newfilename=~m:/\.\./:) {
683: $newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/..
684: }
685: $request->print(&checksuffix($fn,$newfilename));
686: my ($type,$return)=&exists($user, $domain, $newfilename);
687: $request->print($return);
688: if ($type eq 'error') {
689: $request->print('<br /><a href="'.&url($fn).'">'.&mt('Cancel').'</a>');
690: return;
691: }
692: $request->print('<input type="hidden" name="newfilename" value="'
693: .$newfilename.'" />'
694: .'<p>'
695: .&mt('Copy [_1] to [_2]?'
696: ,'<span class="LC_filename">'.&display($fn).'</span>'
697: ,'<span class="LC_filename">'.&display($newfilename).'</span>')
698: .'</p>'
699: );
700: &CloseForm1($request, $fn);
701: } else {
702: $request->print('<p class="LC_error">'
703: .&mt('No such file: [_1]'
704: ,'<span class="LC_filename">'.&display($fn).'</span>')
705: .'</p></form>'
706: );
707: }
708: }
709:
710: =pod
711:
712: =item NewDir1
713:
714: Does all phase 1 processing of directory creation:
715: Ensures that the user provides a new directory name,
716: and that the directory does not already exist.
717:
718: Parameters:
719:
720: =over 4
721:
722: =item $request - Apache Request Object [in] - Server request object for the
723: current url.
724:
725: =item $username - Name of the user that is requesting the directory creation.
726:
727: =item $domain - Domain user is in
728:
729: =item $fn - source file.
730:
731: =item $newdir - Name of the directory to be created; path relative to the
732: top level of construction space.
733: =back
734:
735: Side Effects:
736:
737: =over 4
738:
739: =item A new form is displayed. Clicking on the confirmation button
740: causes the newdir operation to transition into phase 2. The hidden field
741: "newfilename" is set with the construction space path to the new directory.
742:
743:
744: =back
745:
746: =cut
747:
748:
749: sub NewDir1 {
750: my ($request, $username, $domain, $fn, $newfilename, $mode) = @_;
751:
752: my ($type, $result)=&exists($username,$domain,$newfilename,'directory');
753: $request->print($result);
754: if ($type eq 'error') {
755: $request->print('</form>');
756: } else {
757: if ($mode eq 'testbank') {
758: $request->print('<input type="hidden" name="callingmode" value="testbank" />');
759: } elsif ($mode eq 'imsimport') {
760: $request->print('<input type="hidden" name="callingmode" value="imsimport" />');
761: }
762: $request->print('<input type="hidden" name="newfilename" value="'
763: .$newfilename.'" />'
764: .'<p>'
765: .&mt('Make new directory [_1]?'
766: ,'<span class="LC_filename">'.&display($newfilename).'</span>')
767: .'</p>'
768: );
769: &CloseForm1($request, $fn);
770: }
771: }
772:
773:
774: sub Decompress1 {
775: my ($request, $user, $domain, $fn) = @_;
776: if( -e $fn) {
777: $request->print('<input type="hidden" name="newfilename" value="'.$fn.'" />');
778: $request->print('<p>'
779: .&mt('Decompress [_1]?'
780: ,'<span class="LC_filename">'.&display($fn).'</span>')
781: .'</p>'
782: );
783: &CloseForm1($request, $fn);
784: } else {
785: $request->print('<p class="LC_error">'
786: .&mt('No such file: [_1]'
787: ,'<span class="LC_filename">'.&display($fn).'</span>')
788: .'</p></form>'
789: );
790: }
791: }
792:
793: =pod
794:
795: =item NewFile1
796:
797: Does all phase 1 processing of file creation:
798: Ensures that the user provides a new filename, adds proper extension
799: if needed and that the file does not already exist, if it is a html,
800: problem, page, or sequence, it then creates a form link to hand the
801: actual creation off to the proper handler.
802:
803: Parameters:
804:
805: =over 4
806:
807: =item $request - Apache Request Object [in] - Server request object for the
808: current url.
809:
810: =item $username - Name of the user that is requesting the directory creation.
811:
812: =item $domain - Name of the domain of the user
813:
814: =item $fn - Source file name
815:
816: =item $newfilename
817: - Name of the file to be created; no path information
818: =back
819:
820: Side Effects:
821:
822: =over 4
823:
824: =item 2 new forms are displayed. Clicking on the confirmation button
825: causes the browser to attempt to load the specfied URL, allowing the
826: proper handler to take care of file creation. There is also a Cancel
827: button which returns you to the driectory listing you came from
828:
829: =back
830:
831: =cut
832:
833: sub NewFile1 {
834: my ($request, $user, $domain, $fn, $newfilename) = @_;
835: return if (&filename_check($newfilename) ne 'ok');
836:
837: if ($env{'form.action'} =~ /new(.+)file/) {
838: my $extension=$1;
839: if ($newfilename !~ /\Q.$extension\E$/) {
840: if ($newfilename =~ m|/[^/.]*\.(?:[^/.]+)$|) {
841: #already has an extension strip it and add in expected one
842: $newfilename =~ s|(/[^./])\.(?:[^.]+)$|$1|;
843: }
844: $newfilename.=".$extension";
845: }
846: }
847: my ($type, $result)=&exists($user,$domain,$newfilename);
848: $request->print($result);
849: if ($type eq 'error') {
850: $request->print('</form>');
851: } else {
852: my $extension;
853:
854: if ($newfilename =~ m{[^/.]+\.([^/.]+)$}) {
855: $extension = $1;
856: }
857:
858: my @okexts = qw(xml html xhtml htm xhtm problem page sequence rights sty task library js css txt);
859:
860: if (($extension eq '') || (!grep(/^\Q$extension\E/,@okexts))) {
861: my $validexts = '.'.join(', .',@okexts);
862: $request->print('<p class="LC_warning">'.
863: &mt('Invalid filename: ').&display($newfilename).'</p><p>'.
864: &mt('The name of the new file needs to end with an appropriate file extension to indicate the type of file to create.').'<br />'.
865: &mt('The following are valid extensions: [_1].',$validexts).
866: '</p></form><p>'.
867: '<form name="fileaction" action="/adm/cfile" method="post">'.
868: '<input type="hidden" name="qualifiedfilename" value="'.$fn.'" />'.
869: '<input type="hidden" name="action" value="newfile" />'.
870: '<span class ="LC_nobreak">'.&mt('Enter a file name: ').'<input type="text" name="newfilename" value="Type Name Here" onfocus="if (this.value == '."'Type Name Here') this.value=''".'" /> <input type="submit" value="Go" />'.
871: '</span></form></p>'.
872: '<p><form action="'.&url($fn).
873: '" method="post"><p><input type="submit" value="'.&mt('Cancel').'" /></form></p>');
874: return;
875: }
876:
877: $request->print('<p>'.&mt('Make new file').' '.&display($newfilename).'?</p>');
878: $request->print('</form>');
879:
880: $request->print('<form action="'.&url($newfilename).
881: '" method="post"><p><input type="submit" value="'.&mt('Continue').'" /></p></form>');
882: $request->print('<form action="'.&url($fn).
883: '" method="post"><p><input type="submit" value="'.&mt('Cancel').'" /></p></form>');
884: }
885: return;
886: }
887:
888: sub filename_check {
889: my ($newfilename) = @_;
890: ##Informs User (name).(number).(extension) not allowed
891: if($newfilename =~ /\.(\d+)\.(\w+)$/){
892: $r->print('<span class="LC_error">'.$newfilename.
893: ' - '.&mt('Bad Filename').'<br />('.&mt('name').').('.&mt('number').').('.&mt('extension').') '.
894: ' '.&mt('Not Allowed').'</span>');
895: return;
896: }
897: if($newfilename =~ /(\:\:\:|\&\&\&|\_\_\_)/){
898: $r->print('<span class="LC_error">'.$newfilename.
899: ' - '.&mt('Bad Filename').'<br />('.&mt('Must not include').' '.$1.') '.
900: ' '.&mt('Not Allowed').'</span>');
901: return;
902: }
903: return 'ok';
904: }
905:
906: =pod
907:
908: =item phaseone($r, $fn, $uname, $udom)
909:
910: Peforms phase one processing of the request. In phase one, error messages
911: are returned if the request cannot be performed (e.g. attempts to manipulate
912: files that are nonexistent). If the operation can be performed, what is
913: about to be done will be presented to the user for confirmation. If the
914: user confirms the request, then phase two is executed, the action
915: performed and reported to the user.
916:
917: Parameters:
918:
919: =over 4
920:
921: =item $r - request object [in] - The Apache request being executed.
922:
923: =item $fn = string [in] - The filename being manipulated by the
924: request.
925:
926: =item $uname - string [in] Name of user logged in and doing this action.
927:
928: =item $udom - string [in] Domain name under which the user logged in.
929:
930: =back
931:
932: =cut
933:
934: sub phaseone {
935: my ($r,$fn,$uname,$udom)=@_;
936:
937: my $doingdir=0;
938: if ($env{'form.action'} eq 'newdir') { $doingdir=1; }
939: my $newfilename=&cleanDest($r,$env{'form.newfilename'},$doingdir,$fn,$uname);
940: $newfilename=&relativeDest($fn,$newfilename,$uname);
941: $r->print('<form action="/adm/cfile" method="post">'.
942: '<input type="hidden" name="qualifiedfilename" value="'.$fn.'" />'.
943: '<input type="hidden" name="phase" value="two" />'.
944: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />');
945:
946: if ($env{'form.action'} eq 'rename') {
947: &Rename1($r, $uname, $udom, $fn, $newfilename, 'rename');
948: } elsif ($env{'form.action'} eq 'move') {
949: &Rename1($r, $uname, $udom, $fn, $newfilename, 'move');
950: } elsif ($env{'form.action'} eq 'delete') {
951: &Delete1($r, $uname, $udom, $fn);
952: } elsif ($env{'form.action'} eq 'decompress') {
953: &Decompress1($r, $uname, $udom, $fn);
954: } elsif ($env{'form.action'} eq 'copy') {
955: if($newfilename) {
956: &Copy1($r, $uname, $udom, $fn, $newfilename);
957: } else {
958: $r->print('<p class="LC_error">'
959: .&mt('No new filename specified.')
960: .'</p></form>'
961: );
962: }
963: } elsif ($env{'form.action'} eq 'newdir') {
964: my $mode = '';
965: if (exists($env{'form.callingmode'}) ) {
966: $mode = $env{'form.callingmode'};
967: }
968: &NewDir1($r, $uname, $udom, $fn, $newfilename, $mode);
969: } elsif ($env{'form.action'} eq 'newfile' ||
970: $env{'form.action'} eq 'newhtmlfile' ||
971: $env{'form.action'} eq 'newproblemfile' ||
972: $env{'form.action'} eq 'newpagefile' ||
973: $env{'form.action'} eq 'newsequencefile' ||
974: $env{'form.action'} eq 'newrightsfile' ||
975: $env{'form.action'} eq 'newstyfile' ||
976: $env{'form.action'} eq 'newtaskfile' ||
977: $env{'form.action'} eq 'newlibraryfile' ||
978: $env{'form.action'} eq 'Select Action') {
979: my $empty=&mt('Type Name Here');
980: if (($newfilename!~/\/$/) && ($newfilename!~/$empty$/)) {
981: &NewFile1($r, $uname, $udom, $fn, $newfilename);
982: } else {
983: $r->print('<p class="LC_error">'
984: .&mt('No new filename specified.')
985: .'</p></form>'
986: );
987: }
988: }
989: }
990:
991: =pod
992:
993: =item Rename2($request, $user, $directory, $oldfile, $newfile)
994:
995: Performs phase 2 processing of a rename reequest. This is where the
996: actual rename is performed.
997:
998: Parameters
999:
1000: =over 4
1001:
1002: =item $request - Apache request object [in] The request being processed.
1003:
1004: =item $user - string [in] The name of the user initiating the request.
1005:
1006: =item $directory - string [in] The name of the directory relative to the
1007: construction space top level of the renamed file.
1008:
1009: =item $oldfile - Name of the file.
1010:
1011: =item $newfile - Name of the new file.
1012:
1013: =back
1014:
1015: Returns:
1016:
1017: =over 4
1018:
1019: =item 1 Success.
1020:
1021: =item 0 Failure.
1022:
1023: =cut
1024:
1025: sub Rename2 {
1026:
1027: my ($request, $user, $directory, $oldfile, $newfile) = @_;
1028:
1029: &Debug($request, "Rename2 directory: ".$directory." old file: ".$oldfile.
1030: " new file ".$newfile."\n");
1031: &Debug($request, "Target is: ".$directory.'/'.
1032: $newfile);
1033: if (-e $oldfile) {
1034:
1035: my $oRN=$oldfile;
1036: my $nRN=$newfile;
1037: unless (rename($oldfile,$newfile)) {
1038: $request->print('<span class="LC_error">'.&mt('Error').': '.$!.'</span>');
1039: return 0;
1040: }
1041: ## If old name.(extension) exits, move under new name.
1042: ## If it doesn't exist and a new.(extension) exists
1043: ## delete it (only concern when renaming over files)
1044: my $tmp1=$oRN.'.meta';
1045: my $tmp2=$nRN.'.meta';
1046: if(-e $tmp1){
1047: unless(rename($tmp1,$tmp2)){ }
1048: } elsif(-e $tmp2){
1049: unlink $tmp2;
1050: }
1051: $tmp1=$oRN.'.save';
1052: $tmp2=$nRN.'.save';
1053: if(-e $tmp1){
1054: unless(rename($tmp1,$tmp2)){ }
1055: } elsif(-e $tmp2){
1056: unlink $tmp2;
1057: }
1058: $tmp1=$oRN.'.log';
1059: $tmp2=$nRN.'.log';
1060: if(-e $tmp1){
1061: unless(rename($tmp1,$tmp2)){ }
1062: } elsif(-e $tmp2){
1063: unlink $tmp2;
1064: }
1065: $tmp1=$oRN.'.bak';
1066: $tmp2=$nRN.'.bak';
1067: if(-e $tmp1){
1068: unless(rename($tmp1,$tmp2)){ }
1069: } elsif(-e $tmp2){
1070: unlink $tmp2;
1071: }
1072: } else {
1073: $request->print('<p>'
1074: .&mt('No such file: [_1]'
1075: ,'<span class="LC_filename">'.&display($oldfile).'</span>')
1076: .'</p></form>'
1077: );
1078: return 0;
1079: }
1080: return 1;
1081: }
1082:
1083: =pod
1084:
1085: =item Delete2($request, $user, $filename)
1086:
1087: Performs phase two of a delete. The user has confirmed that they want
1088: to delete the selected file. The file is deleted and the results of the
1089: delete attempt are indicated.
1090:
1091: Parameters:
1092:
1093: =over 4
1094:
1095: =item $request - Apache Request object [in] the request object for the current
1096: delete operation.
1097:
1098: =item $user - string [in] The name of the user initiating the delete
1099: request.
1100:
1101: =item $filename - string [in] The name of the file, relative to construction
1102: space, to delete.
1103:
1104: =back
1105:
1106: Returns:
1107: 1 - success.
1108: 0 - Failure.
1109:
1110: =cut
1111:
1112: sub Delete2 {
1113: my ($request, $user, $filename) = @_;
1114: if (-d $filename) {
1115: unless (&empty_directory($filename,'Delete2')) {
1116: $request->print('<span class="LC_error">'.&mt('Error: Directory Non Empty').'</span>');
1117: return 0;
1118: } else {
1119: if(-e $filename) {
1120: unless(rmdir($filename)) {
1121: $request->print('<span class="LC_error">'.&mt('Error').': '.$!.'</span>');
1122: return 0;
1123: }
1124: } else {
1125: $request->print('<p class="LC_error">'.&mt('No such file').'</p></form>');
1126: return 0;
1127: }
1128: }
1129: } else {
1130: if(-e $filename) {
1131: unless(unlink($filename)) {
1132: $request->print('<span class="LC_error">'.&mt('Error').': '.$!.'</span>');
1133: return 0;
1134: }
1135: } else {
1136: $request->print('<p class="LC_error">'.&mt('No such file').'</p></form>');
1137: return 0;
1138: }
1139: }
1140: return 1;
1141: }
1142:
1143: =pod
1144:
1145: =item Copy2($request, $username, $dir, $oldfile, $newfile)
1146:
1147: Performs phase 2 of a copy. The file is copied and the status
1148: of that copy is reported back to the user.
1149:
1150: =over 4
1151:
1152: =item $request - Apache request object [in]; the apache request currently
1153: being executed.
1154:
1155: =item $username - string [in] Name of the user who is requesting the copy.
1156:
1157: =item $dir - string [in] Directory path relative to the construction space
1158: of the destination file.
1159:
1160: =item $oldfile - string [in] Name of the source file.
1161:
1162: =item $newfile - string [in] Name of the destination file.
1163:
1164:
1165: =back
1166:
1167: Returns 0 failure, and 1 successs.
1168:
1169: =cut
1170:
1171: sub Copy2 {
1172: my ($request, $username, $dir, $oldfile, $newfile) = @_;
1173: &Debug($request ,"Will try to copy $oldfile to $newfile");
1174: if(-e $oldfile) {
1175: if ($oldfile eq $newfile) {
1176: $request->print('<span class="LC_error">'.&mt('Warning').': '.&mt('Name of new file is the same as name of old file').' - '.&mt('no action taken').'.</span>');
1177: return 1;
1178: }
1179: unless (copy($oldfile, $newfile)) {
1180: $request->print('<span class="LC_error">'.&mt('copy Error').': '.$!.'</span>');
1181: return 0;
1182: } elsif (!chmod(0660, $newfile)) {
1183: $request->print('<span class="LC_error">'.&mt('chmod error').': '.$!.'</span>');
1184: return 0;
1185: } elsif (-e $oldfile.'.meta' &&
1186: !copy($oldfile.'.meta', $newfile.'.meta') &&
1187: !chmod(0660, $newfile.'.meta')) {
1188: $request->print('<span class="LC_error">'.&mt('copy metadata error').
1189: ': '.$!.'</span>');
1190: return 0;
1191: } else {
1192: return 1;
1193: }
1194: } else {
1195: $request->print('<p class="LC_error">'.&mt('No such file').'</p>');
1196: return 0;
1197: }
1198: return 1;
1199: }
1200:
1201: =pod
1202:
1203: =item NewDir2($request, $user, $newdirectory)
1204:
1205: Performs phase 2 processing of directory creation. This involves creating the directory and
1206: reporting the results of that creation to the user.
1207:
1208: Parameters:
1209: =over 4
1210:
1211: =item $request - Apache request object [in]. Object representing the current HTTP request.
1212:
1213: =item $user - string [in] The name of the user that is initiating the request.
1214:
1215: =item $newdirectory - string [in] The full path of the directory being created.
1216:
1217: =back
1218:
1219: Returns 0 - failure 1 - success.
1220:
1221: =cut
1222:
1223: sub NewDir2 {
1224: my ($request, $user, $newdirectory) = @_;
1225:
1226: unless(mkdir($newdirectory, 02770)) {
1227: $request->print('<span class="LC_error">'.&mt('Error').': '.$!.'</span>');
1228: return 0;
1229: }
1230: unless(chmod(02770, ($newdirectory))) {
1231: $request->print('<span class="LC_error">'.&mt('Error').': '.$!.'</span>');
1232: return 0;
1233: }
1234: return 1;
1235: }
1236:
1237: sub decompress2 {
1238: my ($r, $user, $dir, $file) = @_;
1239: &Apache::lonnet::appenv({'cgi.file' => $file});
1240: &Apache::lonnet::appenv({'cgi.dir' => $dir});
1241: my $result=&Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
1242: $r->print($result);
1243: &Apache::lonnet::delenv('cgi.file');
1244: &Apache::lonnet::delenv('cgi.dir');
1245: return 1;
1246: }
1247:
1248: =pod
1249:
1250: =item phasetwo($r, $fn, $uname, $udom)
1251:
1252: Controls the phase 2 processing of file management
1253: requests for construction space. In phase one, the user
1254: was asked to confirm the operation. In phase 2, the operation
1255: is performed and the result is shown.
1256:
1257: The strategy is to break out the processing into specific action processors
1258: named action2 where action is the requested action and the 2 denotes
1259: phase 2 processing.
1260:
1261: Parameters:
1262:
1263: =over 4
1264:
1265: =item $r - Apache Request object [in] The request object for this httpd
1266: transaction.
1267:
1268: =item $fn - string [in] A filename indicating the object that is being
1269: manipulated.
1270:
1271: =item $uname - string [in] The name of the user initiating the file management
1272: request.
1273:
1274: =item $udom - string [in] The login domain of the user initiating the
1275: file management request.
1276: =back
1277:
1278: =cut
1279:
1280: sub phasetwo {
1281: my ($r,$fn,$uname,$udom)=@_;
1282:
1283: &Debug($r, "loncfile - Entering phase 2 for $fn");
1284:
1285: # Break down the file into its component pieces.
1286:
1287: my $dir; # Directory path
1288: my $main; # Filename.
1289: my $suffix; # Extension.
1290: if ($fn=~m:(.*)/([^/]+):) {
1291: $dir=$1; # Directory path
1292: $main=$2; # Filename.
1293: }
1294: if($main=~m:\.(\w+)$:){ # Fixes problems with filenames with no extensions
1295: $suffix=$1; #This is the actually filename extension if it exists
1296: $main=~s/\.\w+$//; #strip the extension
1297: }
1298: my $dest; #
1299: my $dest_dir; # On success this is where we'll go.
1300: my $disp_newname; #
1301: my $dest_newname; #
1302: &Debug($r,"loncfile::phase2 dir = $dir main = $main suffix = $suffix");
1303: &Debug($r," newfilename = ".$env{'form.newfilename'});
1304:
1305: my $conspace=$fn;
1306:
1307: &Debug($r,"loncfile::phase2 Full construction space name: $conspace");
1308:
1309: &Debug($r,"loncfie::phase2 action is $env{'form.action'}");
1310:
1311: # Select the appropriate processing sub.
1312: if ($env{'form.action'} eq 'decompress') {
1313: $main .= '.'.$suffix;
1314: if(!&decompress2($r, $uname, $dir, $main)) {
1315: return ;
1316: }
1317: $dest = $dir."/.";
1318: } elsif ($env{'form.action'} eq 'rename' ||
1319: $env{'form.action'} eq 'move') {
1320: if($env{'form.newfilename'}) {
1321: if (!defined($dir)) {
1322: $fn=~m:^(.*)/:;
1323: $dir=$1;
1324: }
1325: if(!&Rename2($r, $uname, $dir, $fn, $env{'form.newfilename'})) {
1326: return;
1327: }
1328: $dest = $dir."/";
1329: $dest_newname = $env{'form.newfilename'};
1330: $env{'form.newfilename'} =~ /.+(\/.+$)/;
1331: $disp_newname = $1;
1332: $disp_newname =~ s/\///;
1333: }
1334: } elsif ($env{'form.action'} eq 'delete') {
1335: if(!&Delete2($r, $uname, $env{'form.newfilename'})) {
1336: return ;
1337: }
1338: # Once a resource is deleted, we just list the directory that
1339: # previously held it.
1340: #
1341: $dest = $dir."/."; # Parent dir.
1342: } elsif ($env{'form.action'} eq 'copy') {
1343: if($env{'form.newfilename'}) {
1344: if(!&Copy2($r, $uname, $dir, $fn, $env{'form.newfilename'})) {
1345: return ;
1346: }
1347: $dest = $env{'form.newfilename'};
1348: } else {
1349: $r->print('<p class="LC_error">'.&mt('No New filename specified').'</p></form>');
1350: return;
1351: }
1352:
1353: } elsif ($env{'form.action'} eq 'newdir') {
1354: my $newdir= $env{'form.newfilename'};
1355: if(!&NewDir2($r, $uname, $newdir)) {
1356: return;
1357: }
1358: $dest = $newdir."/";
1359: }
1360: if ( ($env{'form.action'} eq 'newdir') && ($env{'form.phase'} eq 'two') && ( ($env{'form.callingmode'} eq 'testbank') || ($env{'form.callingmode'} eq 'imsimport') ) ) {
1361: $r->print('<h3><a href="javascript:self.close()">'.&mt('Done').'</a></h3>');
1362: } else {
1363: if ($env{'form.action'} eq 'rename') {
1364: $r->print('<h3><a href="'.&url($dest).'">'.&mt('Return to Directory').'</a></h3>');
1365: $r->print('<h3><a href="'.&url($dest_newname).'">'.$disp_newname.'</a></h3>');
1366: } else {
1367: $r->print(&done(&url($dest)));
1368: }
1369: }
1370: }
1371:
1372: sub handler {
1373:
1374: $r=shift;
1375:
1376: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['decompress','action','filename','newfilename']);
1377:
1378: &Debug($r, "loncfile.pm - handler entered");
1379: &Debug($r, " filename: ".$env{'form.filename'});
1380: &Debug($r, " newfilename: ".$env{'form.newfilename'});
1381: #
1382: # Determine the root filename
1383: # This could come in as "filename", which actually is a URL, or
1384: # as "qualifiedfilename", which is indeed a real filename in filesystem
1385: #
1386: my $fn;
1387:
1388: if ($env{'form.filename'}) {
1389: &Debug($r, "test: $env{'form.filename'}");
1390: $fn=&unescape($env{'form.filename'});
1391: $fn=&URLToPath($fn);
1392: } elsif($ENV{'QUERY_STRING'} && $env{'form.phase'} ne 'two') {
1393: #Just hijack the script only the first time around to inject the
1394: #correct information for further processing
1395: $fn=&unescape($env{'form.decompress'});
1396: $fn=&URLToPath($fn);
1397: $env{'form.action'}="decompress";
1398: } elsif ($env{'form.qualifiedfilename'}) {
1399: $fn=$env{'form.qualifiedfilename'};
1400: } else {
1401: &Debug($r, "loncfile::handler - no form.filename");
1402: $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
1403: ' unspecified filename for cfile', $r->filename);
1404: return HTTP_NOT_FOUND;
1405: }
1406:
1407: unless ($fn) {
1408: &Debug($r, "loncfile::handler - doctored url is empty");
1409: $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
1410: ' trying to cfile non-existing file', $r->filename);
1411: return HTTP_NOT_FOUND;
1412: }
1413:
1414: # ----------------------------------------------------------- Start page output
1415: my $uname;
1416: my $udom;
1417:
1418: ($uname,$udom)=
1419: &Apache::loncacc::constructaccess($fn,$r->dir_config('lonDefDomain'));
1420: &Debug($r,
1421: "loncfile::handler constructaccess uname = $uname domain = $udom");
1422: unless (($uname) && ($udom)) {
1423: $r->log_reason($uname.' at '.$udom.
1424: ' trying to manipulate file '.$env{'form.filename'}.
1425: ' ('.$fn.') - not authorized',
1426: $r->filename);
1427: return HTTP_NOT_ACCEPTABLE;
1428: }
1429:
1430:
1431: &Apache::loncommon::content_type($r,'text/html');
1432: $r->send_http_header;
1433:
1434: my (%loaditem,$js);
1435:
1436: if ( ($env{'form.action'} eq 'newdir') && ($env{'form.phase'} eq 'two') && ( ($env{'form.callingmode'} eq 'testbank') || ($env{'form.callingmode'} eq 'imsimport') ) ) {
1437: my $newdirname = $env{'form.newfilename'};
1438: $js = qq|
1439: <script type="text/javascript">
1440: function writeDone() {
1441: window.focus();
1442: opener.document.info.newdir.value = "$newdirname";
1443: setTimeout("self.close()",10000);
1444: }
1445: </script>
1446: |;
1447: $loaditem{'onload'} = "writeDone()";
1448: }
1449:
1450: $r->print(&Apache::loncommon::start_page('Construction Space File Operation',
1451: $js,
1452: {'add_entries' => \%loaditem,}));
1453:
1454: $r->print('<h3>'.&mt('Location').': '.&display($fn).'</h3>');
1455:
1456: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1457: $r->print('<p class="LC_warning">'
1458: .&mt('Co-Author [_1]',$uname.':'.$udom)
1459: .'</p>'
1460: );
1461: }
1462:
1463:
1464: &Debug($r, "loncfile::handler Form action is $env{'form.action'} ");
1465: if ($env{'form.action'} eq 'delete') {
1466: $r->print('<h3>'.&mt('Delete').'</h3>');
1467: } elsif ($env{'form.action'} eq 'rename') {
1468: $r->print('<h3>'.&mt('Rename').'</h3>');
1469: } elsif ($env{'form.action'} eq 'move') {
1470: $r->print('<h3>'.&mt('Move').'</h3>');
1471: } elsif ($env{'form.action'} eq 'newdir') {
1472: $r->print('<h3>'.&mt('New Directory').'</h3>');
1473: } elsif ($env{'form.action'} eq 'decompress') {
1474: $r->print('<h3>'.&mt('Decompress').'</h3>');
1475: } elsif ($env{'form.action'} eq 'copy') {
1476: $r->print('<h3>'.&mt('Copy').'</h3>');
1477: } elsif ($env{'form.action'} eq 'newfile' ||
1478: $env{'form.action'} eq 'newhtmlfile' ||
1479: $env{'form.action'} eq 'newproblemfile' ||
1480: $env{'form.action'} eq 'newpagefile' ||
1481: $env{'form.action'} eq 'newsequencefile' ||
1482: $env{'form.action'} eq 'newrightsfile' ||
1483: $env{'form.action'} eq 'newstyfile' ||
1484: $env{'form.action'} eq 'newtaskfile' ||
1485: $env{'form.action'} eq 'newlibraryfile' ||
1486: $env{'form.action'} eq 'Select Action' ) {
1487: $r->print('<h3>'.&mt('New Resource').'</h3>');
1488: } else {
1489: $r->print('<p class="LC_error">'
1490: .&mt('Unknown Action').' '.$env{'form.action'}
1491: .'</p>'
1492: .&Apache::loncommon::end_page()
1493: );
1494: return OK;
1495: }
1496: if ($env{'form.phase'} eq 'two') {
1497: &Debug($r, "loncfile::handler entering phase2");
1498: &phasetwo($r,$fn,$uname,$udom);
1499: } else {
1500: &Debug($r, "loncfile::handler entering phase1");
1501: &phaseone($r,$fn,$uname,$udom);
1502: }
1503:
1504: $r->print(&Apache::loncommon::end_page());
1505: return OK;
1506: }
1507:
1508: 1;
1509: __END__
1510:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>