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