Annotation of loncom/publisher/loncfile.pm, revision 1.128
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.128 ! raeburn 12: # $Id: loncfile.pm,v 1.127 2023/07/14 23:20:15 raeburn 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:
1.119 raeburn 40: Apache::loncfile - Authoring space file management.
1.12 foxr 41:
42: =head1 SYNOPSIS
1.127 raeburn 43:
44: Content handler for buttons on the top frame of the construction space
1.12 foxr 45: directory.
46:
47: =head1 INTRODUCTION
48:
1.127 raeburn 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);
1.15 foxr 71: use Apache::lonnet;
1.33 www 72: use Apache::loncommon();
1.128 ! raeburn 73: use Apache::lonhtmlcommon;
1.47 sakharuk 74: use Apache::lonlocal;
1.80 albertel 75: use LONCAPA qw(:DEFAULT :match);
76:
1.45 taceyjo1 77: my $DEBUG=0;
1.10 foxr 78: my $r; # Needs to be global for some stuff RF.
1.12 foxr 79:
80: =pod
81:
82: =item Debug($request, $message)
83:
1.17 harris41 84: If debugging is enabled puts out a debugging message determined by the
1.12 foxr 85: caller. The debug message goes to the Apache error log file. Debugging
1.17 harris41 86: is enabled by setting the module global DEBUG variable to nonzero (TRUE).
1.12 foxr 87:
88: Parameters:
89:
90: =over 4
1.127 raeburn 91:
1.17 harris41 92: =item $request - The current request operation.
1.12 foxr 93:
1.17 harris41 94: =item $message - The message to put in the log file.
1.12 foxr 95:
96: =back
1.127 raeburn 97:
1.12 foxr 98: Returns:
99: nothing.
100:
101: =cut
102:
1.9 foxr 103: sub Debug {
1.117 bisitz 104: # Put out the indicated message but only if DEBUG is true.
1.55 albertel 105: if ($DEBUG) {
1.73 albertel 106: my ($r,$message) = @_;
1.55 albertel 107: $r->log_reason($message);
108: }
1.12 foxr 109: }
110:
1.89 www 111: sub done {
1.125 raeburn 112: my ($destfn) = @_;
1.117 bisitz 113: return
114: '<p>'
115: .&Apache::lonhtmlcommon::confirm_success(&mt("Done"))
1.125 raeburn 116: .'<br /><a href="'.&url($destfn).'">'.&mt("Continue").'</a>'
1.117 bisitz 117: .'<script type="text/javascript">'
1.125 raeburn 118: .'location.href="'.&url($destfn,'js').'";'
1.117 bisitz 119: .'</script>'
120: .'</p>';
1.89 www 121: }
122:
1.12 foxr 123: =pod
124:
125: =item URLToPath($url)
126:
127: Convert a URL to a file system path.
1.127 raeburn 128:
1.12 foxr 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.
1.127 raeburn 137:
1.12 foxr 138: =back
1.127 raeburn 139:
1.12 foxr 140: Returns:
141:
142: =over 4
143:
1.127 raeburn 144: =item The corresponding file system path.
1.12 foxr 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 {
1.55 albertel 159: my $Url = shift;
160: &Debug($r, "UrlToPath got: $Url");
1.113 raeburn 161: $Url=~ s{^https?\://[^/]+}{};
162: $Url=~ s{//+}{/}g;
163: $Url=~ s{^/}{};
164: $Url=$Apache::lonnet::perlvar{'lonDocRoot'}."/$Url";
1.55 albertel 165: &Debug($r, "Returning $Url \n");
166: return $Url;
1.12 foxr 167: }
168:
1.36 www 169: sub url {
1.125 raeburn 170: my ($fn,$context) = @_;
1.113 raeburn 171: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
172: $fn=~ s/^\Q$londocroot\E//;
173: $fn=~s{/\./}{/}g;
1.125 raeburn 174: if ($context eq 'js') {
175: &js_escape(\$fn);
176: } else {
177: $fn=&HTML::Entities::encode($fn,'\'<>"&');
178: }
1.36 www 179: return $fn;
180: }
181:
182: sub display {
183: my $fn=shift;
1.113 raeburn 184: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
185: $fn=~s/^\Q$londocroot\E//;
186: $fn=~s{/\./}{/}g;
1.87 albertel 187: return '<span class="LC_filename">'.$fn.'</span>';
1.36 www 188: }
189:
1.50 www 190:
191: # see if the file is
192: # a) published (return 0 if not)
193: # b) if, so obsolete (return 0 if not)
194:
195: sub obsolete_unpub {
196: my ($user,$domain,$construct)=@_;
1.112 raeburn 197: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.50 www 198: my $published=$construct;
1.112 raeburn 199: $published=~s{^\Q$londocroot/priv/\E}{$londocroot/res/};
1.50 www 200: if (-e $published) {
201: if (&Apache::lonnet::metadata($published,'obsolete')) {
202: return 1;
203: }
204: return 0;
205: } else {
206: return 1;
207: }
208: }
209:
1.70 raeburn 210: # see if directory is empty
1.74 www 211: # ignores any .meta, .save, .bak, and .log files created for a previously
1.70 raeburn 212: # published file, which has since been marked obsolete and deleted.
1.127 raeburn 213: # ignores a .DS_Store file put there when viewing directory via webDAV on MacOS.
1.70 raeburn 214: sub empty_directory {
215: my ($dirname,$phase) = @_;
216: if (opendir DIR, $dirname) {
217: my @files = grep(!/^\.\.?$/, readdir(DIR)); # ignore . and ..
1.127 raeburn 218: if (@files) {
1.115 raeburn 219: my @orphans = grep(/\.(meta|save|log|bak|DS_Store)$/,@files);
1.127 raeburn 220: if (scalar(@files) - scalar(@orphans) > 0) {
1.70 raeburn 221: return 0;
222: } else {
223: if (($phase eq 'Delete2') && (@orphans > 0)) {
224: foreach my $file (@orphans) {
1.74 www 225: if ($file =~ /\.(meta|save|log|bak)$/) {
1.70 raeburn 226: unlink($dirname.$file);
227: }
228: }
229: }
230: }
231: }
232: closedir(DIR);
233: return 1;
234: }
235: return 0;
236: }
1.50 www 237:
1.12 foxr 238: =pod
239:
1.39 www 240: =item exists($user, $domain, $file)
1.12 foxr 241:
1.118 bisitz 242: Determine if a resource filename has been published or exists
1.12 foxr 243: in the construction space.
244:
245: Parameters:
246:
247: =over 4
248:
1.85 albertel 249: =item $user - string [in] - Name of the user for which to check.
1.12 foxr 250:
1.85 albertel 251: =item $domain - string [in] - Name of the domain in which the resource
1.12 foxr 252: might have been published.
253:
1.85 albertel 254: =item $file - string [in] - Name of the file.
255:
256: =item $creating - string [in] - optional, type of object being created,
257: either 'directory' or 'file'. Defaults to
258: 'file' if unspecified.
1.12 foxr 259:
260: =back
261:
262: Returns:
263:
264: =over 4
265:
1.83 albertel 266: =item string - Either undef, 'warning' or 'error' depending on the
267: type of problem
268:
1.12 foxr 269: =item string - Either where the resource exists as an html string that can
270: be embedded in a dialog or an empty string if the resource
271: does not exist.
1.127 raeburn 272:
1.12 foxr 273: =back
274:
275: =cut
276:
1.8 albertel 277: sub exists {
1.85 albertel 278: my ($user, $domain, $construct, $creating) = @_;
279: $creating ||= 'file';
280:
1.112 raeburn 281: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.55 albertel 282: my $published=$construct;
1.112 raeburn 283: $published=~s{^\Q$londocroot/priv/\E}{$londocroot/res/};
1.83 albertel 284: my ($type,$result);
1.55 albertel 285: if ( -d $construct ) {
1.124 raeburn 286: return ('error','<p class="LC_error">'.&mt('Error: destination for operation is an existing directory.').'</p>');
1.83 albertel 287:
1.55 albertel 288: }
1.83 albertel 289:
1.55 albertel 290: if ( -e $published) {
1.83 albertel 291: if ( -e $construct ) {
292: $type = 'warning';
1.124 raeburn 293: $result.='<p class="LC_warning">'.&mt('Warning: target file exists, and has been published!').'</p>';
1.83 albertel 294: } else {
1.85 albertel 295: my $published_type = (-d $published) ? 'directory' : 'file';
296:
297: if ($published_type eq $creating) {
298: $type = 'warning';
1.124 raeburn 299: $result.='<p class="LC_warning">'.&mt("Warning: a published $published_type of this name exists.").'</p>';
1.85 albertel 300: } else {
301: $type = 'error';
1.124 raeburn 302: $result.='<p class="LC_error">'.&mt("Error: a published $published_type of this name exists.").'</p>';
1.85 albertel 303: }
1.83 albertel 304: }
1.55 albertel 305: } elsif ( -e $construct) {
1.83 albertel 306: $type = 'warning';
1.124 raeburn 307: $result.='<p class="LC_warning">'.&mt('Warning: target file exists!').'</p>';
1.55 albertel 308: }
1.83 albertel 309:
310: return ($type,$result);
1.8 albertel 311: }
312:
1.12 foxr 313: =pod
314:
315: =item checksuffix($old, $new)
1.127 raeburn 316:
1.12 foxr 317: Determine if a resource filename suffix (the stuff after the .) would change
318: as a result of this operation.
319:
320: Parameters:
321:
322: =over 4
323:
324: =item $old = string [in] Previous filename.
325:
326: =item $new = string [in] Resultant filename.
327:
328: =back
329:
330: Returns:
331:
332: =over 4
333:
1.17 harris41 334: =item Empty string if everything worked.
1.12 foxr 335:
336: =item String containing an error message if there was a problem.
337:
338: =back
339:
340: =cut
341:
1.8 albertel 342: sub checksuffix {
343: my ($old,$new) = @_;
344: my $result;
345: my $oldsuffix;
346: my $newsuffix;
347: if ($new=~m:(.*/*)([^/]+)\.(\w+)$:) { $newsuffix=$3; }
348: if ($old=~m:(.*)/+([^/]+)\.(\w+)$:) { $oldsuffix=$3; }
1.82 albertel 349: if (lc($oldsuffix) ne lc($newsuffix)) {
1.12 foxr 350: $result.=
1.124 raeburn 351: '<p class="LC_warning">'.&mt('Warning: change of MIME type!').'></p>';
1.8 albertel 352: }
353: return $result;
354: }
1.32 albertel 355:
356: sub cleanDest {
1.125 raeburn 357: my ($dest,$subdir,$fn,$uname,$udom)=@_;
1.32 albertel 358: #remove bad characters
1.58 albertel 359: my $foundbad=0;
1.125 raeburn 360: my $warnings;
1.106 raeburn 361: my $error='';
1.58 albertel 362: if ($subdir && $dest =~/\./) {
363: $foundbad=1;
364: $dest=~s/\.//g;
365: }
1.87 albertel 366: $dest =~ s/(\s+$|^\s+)//g;
1.72 albertel 367: if ($dest=~/[\#\?&%\":]/) {
1.58 albertel 368: $foundbad=1;
1.72 albertel 369: $dest=~s/[\#\?&%\":]//g;
1.58 albertel 370: }
1.63 albertel 371: if ($dest=~m|/|) {
372: my ($newpath)=($dest=~m|(.*)/|);
1.109 www 373: ($newpath,$error)=&relativeDest($fn,$newpath,$uname,$udom);
1.64 albertel 374: if (! -d "$newpath") {
1.125 raeburn 375: $warnings = '<p class="LC_warning">'
376: .&mt("You have requested to create file in directory [_1] which doesn't exist. The requested directory path has been removed from the requested filename."
377: ,&display($newpath))
378: .'</p>';
1.63 albertel 379: $dest=~s|.*/||;
380: }
381: }
1.125 raeburn 382: if ($dest =~ /\.(\d+)\.(\w+)$/) {
383: $warnings .= '<p class="LC_warning">'
384: .&mt('Bad filename [_1]',&display($dest))
385: .'<br />'
386: .&mt('[_1](name).(number).(extension)[_2] not allowed.','<tt>','</tt>')
387: .'<br />'
388: .&mt('Removing the [_1].number.[_2] from requested filename.','<tt>','</tt>')
389: .'</p>';
1.84 albertel 390: $dest =~ s/\.(\d+)(\.\w+)$/$2/;
391: }
1.58 albertel 392: if ($foundbad) {
1.125 raeburn 393: $warnings .= '<p class="LC_warning">'
394: .&mt('Invalid characters in requested name have been removed.')
395: .'</p>';
1.32 albertel 396: }
1.125 raeburn 397: return ($dest,$error,$warnings);
1.32 albertel 398: }
399:
1.36 www 400: sub relativeDest {
1.109 www 401: my ($fn,$newfilename,$uname,$udom)=@_;
1.106 raeburn 402: my $error = '';
1.36 www 403: if ($newfilename=~/^\//) {
404: # absolute, simply add path
1.113 raeburn 405: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
406: $newfilename="$londocroot/res/$udom/$uname/";
1.36 www 407: } else {
408: my $dir=$fn;
1.113 raeburn 409: $dir=~s{/[^/]+$}{};
1.36 www 410: $newfilename=$dir.'/'.$newfilename;
411: }
1.113 raeburn 412: $newfilename=~s{//+}{/}g; # remove duplicate /
413: while ($newfilename=~m{/\.\./}) {
414: $newfilename=~ s{/[^/]+/\.\./}{/}g; #remove dir/..
1.36 www 415: }
1.116 raeburn 416: my ($authorname,$authordom)=&Apache::lonnet::constructaccess($newfilename);
1.111 www 417: unless (($authorname) && ($authordom)) {
418: my $otherdir = &display($newfilename);
419: $error = &mt('Access denied to [_1]',$otherdir);
1.106 raeburn 420: }
421: return ($newfilename,$error);
1.36 www 422: }
423:
1.12 foxr 424: =pod
425:
426: =item CloseForm1($request, $user, $file)
427:
428: Close of a form on the successful completion of phase 1 processing
429:
430: Parameters:
431:
432: =over 4
433:
434: =item $request - Apache Request Object [in] - Apache server request object.
435:
1.13 foxr 436: =item $cancelurl - the url to go to on cancel.
1.12 foxr 437:
438: =back
439:
440: =cut
441:
442: sub CloseForm1 {
1.55 albertel 443: my ($request, $fn) = @_;
1.117 bisitz 444: $request->print('<input type="submit" value="'.&mt('Continue').'" /></form>');
445: $request->print(' <form action="'.&url($fn).'" method="post">'.
446: '<input type="submit" value="'.&mt('Cancel').'" /></form>');
1.12 foxr 447: }
448:
449:
450: =pod
451:
452: =item CloseForm2($request, $user, $directory)
453:
454: Successfully close off the phase 2 form.
455:
456: Parameters:
457:
458: =over 4
459:
460: =item $request - Apache Request object [in] - The request that is being
461: executed.
462:
463: =item $user - string [in] - Name of the user that is initiating the
464: request.
465:
1.127 raeburn 466: =item $directory - string [in] - Directory in which the operation is
1.12 foxr 467: being done relative to the top level construction space
468: directory.
469:
470: =back
471:
472: =cut
473:
474: sub CloseForm2 {
1.55 albertel 475: my ($request, $user, $fn) = @_;
1.125 raeburn 476: $request->print(&done($fn));
1.12 foxr 477: }
478:
479: =pod
480:
481: =item Rename1($request, $filename, $user, $domain, $dir)
1.127 raeburn 482:
1.12 foxr 483: Perform phase 1 processing of the file rename operation.
484:
485: Parameters:
486:
487: =over 4
488:
1.127 raeburn 489: =item $request - Apache Request Object [in] The request object for the
1.12 foxr 490: current request.
491:
492: =item $filename - The filename relative to construction space.
493:
494: =item $user - Name of the user making the request.
495:
496: =item $domain - User login domain.
497:
498: =item $dir - Directory specification of the path to the file.
499:
500: =back
501:
502: Side effects:
503:
504: =over 4
505:
506: =item A new form is displayed prompting for confirmation. The newfilename
507: hidden field of this form is loaded with
508: new filename relative to the current directory ($dir).
509:
510: =back
511:
1.127 raeburn 512: =cut
1.12 foxr 513:
514: sub Rename1 {
1.52 albertel 515: my ($request, $user, $domain, $fn, $newfilename, $style) = @_;
1.36 www 516:
517: if(-e $fn) {
518: if($newfilename) {
1.42 albertel 519: # is dest a dir
1.52 albertel 520: if ($style eq 'move') {
521: if (-d $newfilename) {
522: if ($fn =~ m|/([^/]*)$|) { $newfilename .= '/'.$1; }
523: }
1.42 albertel 524: }
1.29 albertel 525: if ($newfilename =~ m|/[^\.]+$|) {
1.36 www 526: #no extension add on original extension
527: if ($fn =~ m|/[^\.]*\.([^\.]+)$|) {
1.24 albertel 528: $newfilename.='.'.$1;
529: }
530: }
1.36 www 531: $request->print(&checksuffix($fn, $newfilename));
1.27 albertel 532: #renaming a dir, delete the trailing /
1.39 www 533: #remove second to last element for current dir
534: if (-d $fn) {
1.53 www 535: $newfilename=~/\.(\w+)$/;
536: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
1.100 bisitz 537: $request->print('<p><span class="LC_error">'.
538: &mt('Cannot change MIME type of a directory.').
1.82 albertel 539: '</span>'.
1.100 bisitz 540: '<br /><a href="'.&url($fn).'">'.&mt('Cancel').'</a></p>');
1.53 www 541: return;
542: }
1.39 www 543: $newfilename=~s/\/[^\/]+\/([^\/]+)$/\/$1/;
1.27 albertel 544: }
1.42 albertel 545: $newfilename=~s://+:/:g; # remove duplicate /
546: while ($newfilename=~m:/\.\./:) {
547: $newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/..
548: }
1.83 albertel 549: my ($type, $return)=&exists($user, $domain, $newfilename);
1.21 albertel 550: $request->print($return);
1.83 albertel 551: if ($type eq 'error') {
1.47 sakharuk 552: $request->print('<br /><a href="'.&url($fn).'">'.&mt('Cancel').'</a>');
1.21 albertel 553: return;
554: }
1.50 www 555: unless (&obsolete_unpub($user,$domain,$fn)) {
1.100 bisitz 556: $request->print('<p><span class="LC_error">'
557: .&mt('Cannot rename or move non-obsolete published file.')
558: .'</span><br />'
559: .'<a href="'.&url($fn).'">'.&mt('Cancel').'</a></p>'
560: );
1.50 www 561: return;
562: }
1.52 albertel 563: my $action;
564: if ($style eq 'rename') {
1.100 bisitz 565: $action='Rename';
1.52 albertel 566: } else {
1.100 bisitz 567: $action='Move';
1.52 albertel 568: }
1.100 bisitz 569: $request->print('<input type="hidden" name="newfilename" value="'
570: .$newfilename.'" />'
571: .'<p>'
1.103 bisitz 572: .&mt($action.' [_1] to [_2]?',
573: &display($fn),
574: &display($newfilename))
1.100 bisitz 575: .'</p>'
576: );
1.36 www 577: &CloseForm1($request, $fn);
1.12 foxr 578: } else {
1.100 bisitz 579: $request->print('<p class="LC_error">'.&mt('No new filename specified.').'</p></form>');
1.12 foxr 580: return;
581: }
582: } else {
1.100 bisitz 583: $request->print('<p class="LC_error">'
1.103 bisitz 584: .&mt('No such file: [_1]',
585: &display($fn))
1.100 bisitz 586: .'</p></form>'
587: );
1.12 foxr 588: return;
589: }
1.127 raeburn 590:
1.12 foxr 591: }
1.55 albertel 592:
1.12 foxr 593: =pod
594:
595: =item Delete1
596:
597: Performs phase 1 processing of the delete operation. In phase one
598: we just check to be sure the file exists.
599:
600: Parameters:
601:
602: =over 4
603:
1.127 raeburn 604: =item $request - Apache Request Object [in] request object for the current
1.12 foxr 605: request.
606:
1.36 www 607: =item $user - string [in] Name of the user initiating the request.
1.12 foxr 608:
1.36 www 609: =item $domain - string [in] Domain the initiating user is logged in as
1.13 foxr 610:
1.36 www 611: =item $filename - string [in] Source filename.
1.12 foxr 612:
613: =back
614:
615: =cut
616:
617: sub Delete1 {
1.55 albertel 618: my ($request, $user, $domain, $fn) = @_;
1.12 foxr 619:
1.55 albertel 620: if( -e $fn) {
621: $request->print('<input type="hidden" name="newfilename" value="'.
1.95 bisitz 622: $fn.'" />');
1.70 raeburn 623: if (-d $fn) {
624: unless (&empty_directory($fn,'Delete1')) {
1.100 bisitz 625: $request->print('<p>'
626: .'<span class="LC_error">'
627: .&mt('Only empty directories may be deleted.')
628: .'</span><br />'
629: .&mt('You must delete the contents of the directory first.')
630: .'</p>'
631: .'<p><a href="'.&url($fn).'">'.&mt('Cancel').'</a></p>'
632: );
1.70 raeburn 633: return;
634: }
1.127 raeburn 635: } else {
1.70 raeburn 636: unless (&obsolete_unpub($user,$domain,$fn)) {
1.100 bisitz 637: $request->print('<p><span class="LC_error">'
638: .&mt('Cannot delete non-obsolete published file.')
639: .'</span><br />'
640: .'<a href="'.&url($fn).'">'.&mt('Cancel').'</a></p>'
641: );
1.70 raeburn 642: return;
643: }
644: }
1.100 bisitz 645: $request->print('<p>'
1.103 bisitz 646: .&mt('Delete [_1]?',
647: &display($fn))
1.100 bisitz 648: .'</p>'
649: );
1.55 albertel 650: &CloseForm1($request, $fn);
651: } else {
1.100 bisitz 652: $request->print('<p class="LC_error">'
1.103 bisitz 653: .&mt('No such file: [_1]',
654: &display($fn))
1.100 bisitz 655: .'</p></form>'
656: );
1.50 www 657: }
1.12 foxr 658: }
659:
660: =pod
661:
662: =item Copy1($request, $user, $domain, $filename, $newfilename)
663:
664: Performs phase 1 processing of the construction space copy command.
1.17 harris41 665: Ensure that the source file exists. Ensure that a destination exists,
666: also warn if the destination already exists.
1.12 foxr 667:
668: Parameters:
669:
670: =over 4
671:
1.127 raeburn 672: =item $request - Apache Request Object [in] request object for the current
1.12 foxr 673: request.
674:
675: =item $user - string [in] Name of the user initiating the request.
676:
677: =item $domain - string [in] Domain the initiating user is logged in as
678:
1.36 www 679: =item $fn - string [in] Source filename.
1.12 foxr 680:
681: =item $newfilename-string [in] Destination filename.
682:
683: =back
684:
685: =cut
686:
687: sub Copy1 {
1.42 albertel 688: my ($request, $user, $domain, $fn, $newfilename) = @_;
1.12 foxr 689:
1.42 albertel 690: if(-e $fn) {
691: # is dest a dir
692: if (-d $newfilename) {
693: if ($fn =~ m|/([^/]*)$|) { $newfilename .= '/'.$1; }
694: }
695: if ($newfilename =~ m|/[^\.]+$|) {
696: #no extension add on original extension
697: if ($fn =~ m|/[^\.]*\.([^\.]+)$|) { $newfilename.='.'.$1; }
1.127 raeburn 698: }
1.42 albertel 699: $newfilename=~s://+:/:g; # remove duplicate /
700: while ($newfilename=~m:/\.\./:) {
701: $newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/..
702: }
703: $request->print(&checksuffix($fn,$newfilename));
1.83 albertel 704: my ($type,$return)=&exists($user, $domain, $newfilename);
1.42 albertel 705: $request->print($return);
1.83 albertel 706: if ($type eq 'error') {
1.120 raeburn 707: $request->print('<br /><a href="'.&url($fn).'">'.&mt('Cancel').'</a></form>');
1.42 albertel 708: return;
709: }
1.120 raeburn 710: # Check if there is enough space.
711: my @fileinfo = stat($fn);
712: my ($dir,$fname) = ($fn =~ m{^(.+/)([^/]+)$});
713: my $filesize = $fileinfo[7];
714: $filesize = int($filesize/1000); #expressed in kb
1.122 raeburn 715: my $output = &Apache::loncommon::excess_filesize_warning($user,$domain,'author',
1.121 bisitz 716: $fname,$filesize,'copy');
1.120 raeburn 717: if ($output) {
718: $request->print($output.'<br /><a href="'.&url($dir).'">'.&mt('Cancel').'</a></form>');
719: return;
720: }
1.103 bisitz 721: $request->print(
722: '<input type="hidden" name="newfilename"'
723: .' value="'.$newfilename.'" />'
724: .'<p>'
725: .&mt('Copy [_1] to [_2]?',
726: &display($fn),
727: &display($newfilename))
728: .'</p>'
1.100 bisitz 729: );
1.42 albertel 730: &CloseForm1($request, $fn);
731: } else {
1.100 bisitz 732: $request->print('<p class="LC_error">'
1.103 bisitz 733: .&mt('No such file: [_1]',
734: &display($fn))
1.100 bisitz 735: .'</p></form>'
736: );
1.21 albertel 737: }
1.19 albertel 738: }
739:
740: =pod
741:
1.12 foxr 742: =item NewDir1
1.127 raeburn 743:
1.12 foxr 744: Does all phase 1 processing of directory creation:
745: Ensures that the user provides a new directory name,
746: and that the directory does not already exist.
747:
748: Parameters:
749:
750: =over 4
751:
752: =item $request - Apache Request Object [in] - Server request object for the
1.17 harris41 753: current url.
1.12 foxr 754:
755: =item $username - Name of the user that is requesting the directory creation.
756:
1.36 www 757: =item $domain - Domain user is in
758:
759: =item $fn - source file.
1.12 foxr 760:
1.127 raeburn 761: =item $newdir - Name of the directory to be created; path relative to the
1.12 foxr 762: top level of construction space.
763: =back
764:
765: Side Effects:
766:
767: =over 4
768:
769: =item A new form is displayed. Clicking on the confirmation button
770: causes the newdir operation to transition into phase 2. The hidden field
771: "newfilename" is set with the construction space path to the new directory.
772:
773:
774: =back
775:
776: =cut
777:
778:
1.55 albertel 779: sub NewDir1 {
780: my ($request, $username, $domain, $fn, $newfilename, $mode) = @_;
781:
1.85 albertel 782: my ($type, $result)=&exists($username,$domain,$newfilename,'directory');
1.83 albertel 783: $request->print($result);
1.85 albertel 784: if ($type eq 'error') {
1.83 albertel 785: $request->print('</form>');
1.55 albertel 786: } else {
1.104 raeburn 787: if (($mode eq 'testbank') || ($mode eq 'imsimport')) {
788: $request->print('<input type="hidden" name="callingmode" value="'.$mode.'" />'."\n".
789: '<input type="hidden" name="inhibitmenu" value="yes" />');
1.55 albertel 790: }
1.100 bisitz 791: $request->print('<input type="hidden" name="newfilename" value="'
792: .$newfilename.'" />'
793: .'<p>'
1.103 bisitz 794: .&mt('Make new directory [_1]?',
795: &display($newfilename))
1.100 bisitz 796: .'</p>'
797: );
1.55 albertel 798: &CloseForm1($request, $fn);
799: }
1.12 foxr 800: }
801:
1.44 taceyjo1 802:
803: sub Decompress1 {
1.55 albertel 804: my ($request, $user, $domain, $fn) = @_;
805: if( -e $fn) {
1.95 bisitz 806: $request->print('<input type="hidden" name="newfilename" value="'.$fn.'" />');
1.100 bisitz 807: $request->print('<p>'
1.103 bisitz 808: .&mt('Decompress [_1]?',
809: &display($fn))
1.100 bisitz 810: .'</p>'
811: );
1.44 taceyjo1 812: &CloseForm1($request, $fn);
1.55 albertel 813: } else {
1.100 bisitz 814: $request->print('<p class="LC_error">'
1.103 bisitz 815: .&mt('No such file: [_1]',
816: &display($fn))
1.100 bisitz 817: .'</p></form>'
818: );
1.55 albertel 819: }
1.44 taceyjo1 820: }
1.55 albertel 821:
1.128 ! raeburn 822: sub Archive1 {
! 823: my ($request,$fn) = @_;
! 824: my @posstypes = qw(problem library sty sequence page task rights meta xml html xhtml htm xhtm css js tex txt gif jpg jpeg png svg other);
! 825: my (%location_of,%default,$compstyle);
! 826: foreach my $program ('tar','gzip','bzip2','xz','zip') {
! 827: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
! 828: '/usr/sbin/') {
! 829: if (-x $dir.$program) {
! 830: $location_of{$program} = $dir.$program;
! 831: last;
! 832: }
! 833: }
! 834: }
! 835: my (%defaults,$cancompress,$canarchive);
! 836: if (exists($location_of{'tar'})) {
! 837: $default{'tar'} = ' checked="checked"';
! 838: $canarchive = 1;
! 839: $compstyle = 'block';
! 840: } elsif (exists($location_of{'zip'})) {
! 841: $default{'zip'} = ' checked="checked"';
! 842: $canarchive = 1;
! 843: $compstyle = 'none';
! 844: }
! 845: foreach my $compress ('gzip','bzip2','xz') {
! 846: if (exists($location_of{$compress})) {
! 847: $default{$compress} = ' checked="checked"';
! 848: $cancompress = 1;
! 849: last;
! 850: }
! 851: }
! 852: if (!$canarchive) {
! 853: $request->print('<p class="LC_error">'.
! 854: &mt('This LON-CAPA instance does not seem to have either tar or zip installed.').'</p>'.
! 855: '<span class="LC_warning">'.
! 856: &mt('At least one of the two is needed in order to be able to create an archive file for: [_1].',
! 857: &display($fn)).
! 858: '</span></form>');
! 859: } elsif (-e $fn) {
! 860: $request->print(&Apache::lonhtmlcommon::start_pick_box().
! 861: &Apache::lonhtmlcommon::row_title(&mt('Directory')).
! 862: &display($fn).
! 863: &Apache::lonhtmlcommon::row_closure().
! 864: &Apache::lonhtmlcommon::row_title(&mt('Options').
! 865: &Apache::loncommon::help_open_topic('Archiving_Directory_Options')).
! 866: '<fieldset><legend>'.&mt('Recurse').'</legend>'.
! 867: '<span class="LC_nobreak"><label><input type="checkbox" name="recurse" /> '.
! 868: &mt('include subdirectories').'</label></span>'.
! 869: '</fieldset>'.
! 870: '<fieldset><legend>'.&mt('File types (extensions) to include').(' 'x2).
! 871: '<span style="text-decoration:line-through">'.(' 'x5).'</span>'.(' 'x2).
! 872: '<input type="button" name="checkall" value="'.&mt('check all').
! 873: '" style="height:20px;" onclick="checkAll(document.phaseone.filetype);" />'.
! 874: (' 'x2).
! 875: '<input type="button" name="uncheckall" value="'.&mt('uncheck all').
! 876: '" style="height:20px;" onclick="uncheckAll(document.phaseone.filetype);" /></legend>'.
! 877: '<table>');
! 878: my $rem;
! 879: my $numinrow = 6;
! 880: for (my $i=0; $i<@posstypes; $i++) {
! 881: my $rem = $i%($numinrow);
! 882: if ($rem == 0) {
! 883: if ($i > 0) {
! 884: $request->print('</tr>'."\n");
! 885: }
! 886: $request->print('<tr>'."\n");
! 887: }
! 888: $request->print('<td class="LC_left_item">'.
! 889: '<span class="LC_nobreak"><label>'.
! 890: '<input type="checkbox" name="filetype" '.
! 891: 'value="'.$posstypes[$i].'" /> '.
! 892: $posstypes[$i].'</label></span></td>'."\n");
! 893: }
! 894: $rem = scalar(@posstypes)%($numinrow);
! 895: my $colsleft;
! 896: if ($rem) {
! 897: $colsleft = $numinrow - $rem;
! 898: }
! 899: if ($colsleft > 1 ) {
! 900: $request->print('<td colspan="'.$colsleft.'" class="LC_left_item">'.
! 901: ' </td>'."\n");
! 902: } elsif ($colsleft == 1) {
! 903: $request->print('<td class="LC_left_item"> </td>'."\n");
! 904: }
! 905: $request->print('</tr></table>'."\n".
! 906: '</fieldset>'.
! 907: '<fieldset><legend>'.&mt('Archive file format').'</legend>');
! 908: foreach my $possfmt ('tar','zip') {
! 909: if (exists($location_of{$possfmt})) {
! 910: $request->print('<span class="LC_nobreak">'.
! 911: '<label><input type="radio" name="format" value="'.$possfmt.'"'.
! 912: $default{$possfmt}.' onclick="toggleCompression(this.form);" /> '.
! 913: $possfmt.'</label></span> ');
! 914: }
! 915: }
! 916: $request->print('</fieldset>'."\n".
! 917: '<fieldset style="display:'.$compstyle.'" id="tar_compression">'.
! 918: '<legend>'.&mt('Compression to apply to tar file').'</legend>'.
! 919: '<span class="LC_nobreak">');
! 920: if ($cancompress) {
! 921: foreach my $compress ('gzip','bzip2','xz') {
! 922: if (exists($location_of{$compress})) {
! 923: $request->print('<label><input type="radio" name="compress" value="'.$compress.'"'.
! 924: $default{$compress}.' />'.$compress.'</label> ');
! 925: }
! 926: }
! 927: } else {
! 928: $request->print('<span class="LC_warning">'.
! 929: &mt('This LON-CAPA instance does not seem to have gzip, bzip2 or xz installed.').
! 930: '<br />'.&mt('No compression will be used.').'</span>');
! 931: }
! 932: $request->print('</fieldset>'.
! 933: &Apache::lonhtmlcommon::row_closure(1).
! 934: &Apache::lonhtmlcommon::end_pick_box()
! 935: );
! 936: &CloseForm1($request, $fn);
! 937: } else {
! 938: $request->print('<p class="LC_error">'
! 939: .&mt('No such directory: [_1]',
! 940: &display($fn))
! 941: .'</p></form>'
! 942: );
! 943: }
! 944: }
! 945:
1.12 foxr 946: =pod
947:
1.22 albertel 948: =item NewFile1
1.127 raeburn 949:
1.22 albertel 950: Does all phase 1 processing of file creation:
951: Ensures that the user provides a new filename, adds proper extension
952: if needed and that the file does not already exist, if it is a html,
953: problem, page, or sequence, it then creates a form link to hand the
954: actual creation off to the proper handler.
955:
956: Parameters:
957:
958: =over 4
959:
960: =item $request - Apache Request Object [in] - Server request object for the
961: current url.
962:
963: =item $username - Name of the user that is requesting the directory creation.
964:
965: =item $domain - Name of the domain of the user
966:
1.118 bisitz 967: =item $fn - Source filename
1.22 albertel 968:
969: =item $newfilename
970: - Name of the file to be created; no path information
1.125 raeburn 971:
972: =item $warnings - Information about changes to filename made by cleanDest().
973:
1.22 albertel 974: =back
975:
976: Side Effects:
977:
978: =over 4
979:
980: =item 2 new forms are displayed. Clicking on the confirmation button
981: causes the browser to attempt to load the specfied URL, allowing the
1.36 www 982: proper handler to take care of file creation. There is also a Cancel
1.117 bisitz 983: button which returns you to the directory listing you came from
1.22 albertel 984:
985: =back
986:
987: =cut
988:
989: sub NewFile1 {
1.125 raeburn 990: my ($request, $user, $domain, $fn, $newfilename, $warnings) = @_;
991: return if (&filename_check($newfilename,$warnings) ne 'ok');
1.22 albertel 992:
1.67 albertel 993: if ($env{'form.action'} =~ /new(.+)file/) {
1.22 albertel 994: my $extension=$1;
995: if ($newfilename !~ /\Q.$extension\E$/) {
1.81 albertel 996: if ($newfilename =~ m|/[^/.]*\.(?:[^/.]+)$|) {
1.26 albertel 997: #already has an extension strip it and add in expected one
1.81 albertel 998: $newfilename =~ s|(/[^./])\.(?:[^.]+)$|$1|;
1.26 albertel 999: }
1.22 albertel 1000: $newfilename.=".$extension";
1001: }
1.31 albertel 1002: }
1.83 albertel 1003: my ($type, $result)=&exists($user,$domain,$newfilename);
1004: if ($type eq 'error') {
1.125 raeburn 1005: $request->print($warnings.$result);
1.83 albertel 1006: $request->print('</form>');
1.39 www 1007: } else {
1.96 raeburn 1008: my $extension;
1009:
1010: if ($newfilename =~ m{[^/.]+\.([^/.]+)$}) {
1011: $extension = $1;
1012: }
1013:
1.102 raeburn 1014: my @okexts = qw(xml html xhtml htm xhtm problem page sequence rights sty task library js css txt);
1.96 raeburn 1015: if (($extension eq '') || (!grep(/^\Q$extension\E/,@okexts))) {
1016: my $validexts = '.'.join(', .',@okexts);
1.125 raeburn 1017: $request->print($warnings.$result);
1.96 raeburn 1018: $request->print('<p class="LC_warning">'.
1019: &mt('Invalid filename: ').&display($newfilename).'</p><p>'.
1020: &mt('The name of the new file needs to end with an appropriate file extension to indicate the type of file to create.').'<br />'.
1021: &mt('The following are valid extensions: [_1].',$validexts).
1022: '</p></form><p>'.
1023: '<form name="fileaction" action="/adm/cfile" method="post">'.
1024: '<input type="hidden" name="qualifiedfilename" value="'.$fn.'" />'.
1025: '<input type="hidden" name="action" value="newfile" />'.
1.118 bisitz 1026: '<span class ="LC_nobreak">'.&mt('Enter a filename: ').'<input type="text" name="newfilename" value="Type Name Here" onfocus="if (this.value == '."'Type Name Here') this.value=''".'" /> <input type="submit" value="Go" />'.
1.96 raeburn 1027: '</span></form></p>'.
1028: '<p><form action="'.&url($fn).
1.97 bisitz 1029: '" method="post"><p><input type="submit" value="'.&mt('Cancel').'" /></form></p>');
1.125 raeburn 1030: } elsif (($type ne 'warning') && ($warnings eq '') && ($result eq '')) {
1.123 golterma 1031: my $query = "";
1032: $query .= "?mode=" . $env{'form.mode'} unless (!exists($env{'form.mode'}) || !length($env{'form.mode'}));
1033: $request->print('
1034: <script type="text/javascript">
1.125 raeburn 1035: window.location = "'.&url($newfilename,'js'). $query .'";
1.123 golterma 1036: </script>');
1037: } else {
1.125 raeburn 1038: $request->print($warnings.$result);
1.123 golterma 1039: $request->print('<p>'.&mt('Make new file').' '.&display($newfilename).'?</p>');
1040: $request->print('</form>');
1041: $request->print('<form action="'.&url($newfilename).
1042: '" method="post"><p><input type="submit" value="'.&mt('Continue').'" /></p></form>');
1043: $request->print('<form action="'.&url($fn).
1044: '" method="post"><p><input type="submit" value="'.&mt('Cancel').'" /></p></form>');
1.96 raeburn 1045: }
1.22 albertel 1046: }
1.96 raeburn 1047: return;
1048: }
1049:
1050: sub filename_check {
1051: my ($newfilename) = @_;
1052: ##Informs User (name).(number).(extension) not allowed
1053: if($newfilename =~ /\.(\d+)\.(\w+)$/){
1054: $r->print('<span class="LC_error">'.$newfilename.
1055: ' - '.&mt('Bad Filename').'<br />('.&mt('name').').('.&mt('number').').('.&mt('extension').') '.
1056: ' '.&mt('Not Allowed').'</span>');
1057: return;
1058: }
1059: if($newfilename =~ /(\:\:\:|\&\&\&|\_\_\_)/){
1060: $r->print('<span class="LC_error">'.$newfilename.
1061: ' - '.&mt('Bad Filename').'<br />('.&mt('Must not include').' '.$1.') '.
1062: ' '.&mt('Not Allowed').'</span>');
1063: return;
1064: }
1.127 raeburn 1065: return 'ok';
1.22 albertel 1066: }
1067:
1068: =pod
1069:
1.12 foxr 1070: =item phaseone($r, $fn, $uname, $udom)
1071:
1072: Peforms phase one processing of the request. In phase one, error messages
1073: are returned if the request cannot be performed (e.g. attempts to manipulate
1074: files that are nonexistent). If the operation can be performed, what is
1075: about to be done will be presented to the user for confirmation. If the
1.127 raeburn 1076: user confirms the request, then phase two is executed, the action
1.12 foxr 1077: performed and reported to the user.
1078:
1079: Parameters:
1080:
1081: =over 4
1082:
1083: =item $r - request object [in] - The Apache request being executed.
1084:
1.127 raeburn 1085: =item $fn = string [in] - The filename being manipulated by the
1.12 foxr 1086: request.
1087:
1088: =item $uname - string [in] Name of user logged in and doing this action.
1089:
1.127 raeburn 1090: =item $udom - string [in] Domain name under which the user logged in.
1.12 foxr 1091:
1092: =back
1093:
1094: =cut
1.8 albertel 1095:
1.1 www 1096: sub phaseone {
1.55 albertel 1097: my ($r,$fn,$uname,$udom)=@_;
1.127 raeburn 1098:
1.58 albertel 1099: my $doingdir=0;
1.67 albertel 1100: if ($env{'form.action'} eq 'newdir') { $doingdir=1; }
1.127 raeburn 1101: my ($newfilename,$error,$warnings) =
1.125 raeburn 1102: &cleanDest($env{'form.newfilename'},$doingdir,$fn,$uname,$udom);
1.106 raeburn 1103: unless ($error) {
1.109 www 1104: ($newfilename,$error)=&relativeDest($fn,$newfilename,$uname,$udom);
1.106 raeburn 1105: }
1106: if ($error) {
1107: my $dirlist;
1108: if ($fn=~m{^(.*/)[^/]+$}) {
1109: $dirlist=$1;
1110: } else {
1.127 raeburn 1111: $dirlist=$fn;
1.106 raeburn 1112: }
1.125 raeburn 1113: if ($warnings) {
1114: $r->print($warnings);
1115: }
1.106 raeburn 1116: $r->print('<div class="LC_error">'.$error.'</div>'.
1.117 bisitz 1117: '<p><a href="'.&url($dirlist).'">'.&mt('Return to Directory').
1118: '</a></p>');
1.106 raeburn 1119: return;
1120: }
1.128 ! raeburn 1121: $r->print('<form action="/adm/cfile" method="post" name="phaseone">'.
1.55 albertel 1122: '<input type="hidden" name="qualifiedfilename" value="'.$fn.'" />'.
1123: '<input type="hidden" name="phase" value="two" />'.
1.67 albertel 1124: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />');
1.125 raeburn 1125:
1126: if ($env{'form.action'} eq 'newfile' ||
1127: $env{'form.action'} eq 'newhtmlfile' ||
1128: $env{'form.action'} eq 'newproblemfile' ||
1129: $env{'form.action'} eq 'newpagefile' ||
1130: $env{'form.action'} eq 'newsequencefile' ||
1131: $env{'form.action'} eq 'newrightsfile' ||
1132: $env{'form.action'} eq 'newstyfile' ||
1133: $env{'form.action'} eq 'newtaskfile' ||
1134: $env{'form.action'} eq 'newlibraryfile' ||
1135: $env{'form.action'} eq 'Select Action') {
1.65 www 1136: my $empty=&mt('Type Name Here');
1.125 raeburn 1137: if (($newfilename!~/\/$/) && ($newfilename!~/$empty$/)) {
1138: &NewFile1($r, $uname, $udom, $fn, $newfilename, $warnings);
1139: } else {
1140: if ($warnings) {
1141: $r->print($warnings);
1142: }
1.100 bisitz 1143: $r->print('<p class="LC_error">'
1144: .&mt('No new filename specified.')
1145: .'</p></form>'
1146: );
1.125 raeburn 1147: }
1148: } else {
1149: if ($warnings) {
1150: $r->print($warnings);
1151: }
1152: if ($env{'form.action'} eq 'rename') {
1153: &Rename1($r, $uname, $udom, $fn, $newfilename, 'rename');
1154: } elsif ($env{'form.action'} eq 'move') {
1155: &Rename1($r, $uname, $udom, $fn, $newfilename, 'move');
1.127 raeburn 1156: } elsif ($env{'form.action'} eq 'delete') {
1.125 raeburn 1157: &Delete1($r, $uname, $udom, $fn);
1158: } elsif ($env{'form.action'} eq 'decompress') {
1159: &Decompress1($r, $uname, $udom, $fn);
1.128 ! raeburn 1160: } elsif ($env{'form.action'} eq 'archive') {
! 1161: &Archive1($r,$fn);
1.127 raeburn 1162: } elsif ($env{'form.action'} eq 'copy') {
1.125 raeburn 1163: if ($newfilename) {
1164: &Copy1($r, $uname, $udom, $fn, $newfilename);
1165: } else {
1166: $r->print('<p class="LC_error">'
1167: .&mt('No new filename specified.')
1168: .'</p></form>'
1169: );
1170: }
1171: } elsif ($env{'form.action'} eq 'newdir') {
1172: my $mode = '';
1173: if (exists($env{'form.callingmode'}) ) {
1174: $mode = $env{'form.callingmode'};
1175: }
1176: &NewDir1($r, $uname, $udom, $fn, $newfilename, $mode);
1177: }
1.55 albertel 1178: }
1.12 foxr 1179: }
1180:
1181: =pod
1182:
1183: =item Rename2($request, $user, $directory, $oldfile, $newfile)
1184:
1.17 harris41 1185: Performs phase 2 processing of a rename reequest. This is where the
1.12 foxr 1186: actual rename is performed.
1187:
1188: Parameters
1189:
1190: =over 4
1191:
1192: =item $request - Apache request object [in] The request being processed.
1193:
1194: =item $user - string [in] The name of the user initiating the request.
1195:
1196: =item $directory - string [in] The name of the directory relative to the
1197: construction space top level of the renamed file.
1198:
1199: =item $oldfile - Name of the file.
1200:
1201: =item $newfile - Name of the new file.
1202:
1203: =back
1204:
1205: Returns:
1206:
1207: =over 4
1208:
1209: =item 1 Success.
1210:
1211: =item 0 Failure.
1212:
1213: =cut
1214:
1215: sub Rename2 {
1216:
1.55 albertel 1217: my ($request, $user, $directory, $oldfile, $newfile) = @_;
1.12 foxr 1218:
1.55 albertel 1219: &Debug($request, "Rename2 directory: ".$directory." old file: ".$oldfile.
1220: " new file ".$newfile."\n");
1221: &Debug($request, "Target is: ".$directory.'/'.
1222: $newfile);
1223: if (-e $oldfile) {
1224:
1225: my $oRN=$oldfile;
1226: my $nRN=$newfile;
1227: unless (rename($oldfile,$newfile)) {
1.83 albertel 1228: $request->print('<span class="LC_error">'.&mt('Error').': '.$!.'</span>');
1.55 albertel 1229: return 0;
1230: }
1231: ## If old name.(extension) exits, move under new name.
1.127 raeburn 1232: ## If it doesn't exist and a new.(extension) exists
1.55 albertel 1233: ## delete it (only concern when renaming over files)
1234: my $tmp1=$oRN.'.meta';
1235: my $tmp2=$nRN.'.meta';
1236: if(-e $tmp1){
1237: unless(rename($tmp1,$tmp2)){ }
1238: } elsif(-e $tmp2){
1239: unlink $tmp2;
1240: }
1241: $tmp1=$oRN.'.save';
1242: $tmp2=$nRN.'.save';
1243: if(-e $tmp1){
1244: unless(rename($tmp1,$tmp2)){ }
1245: } elsif(-e $tmp2){
1246: unlink $tmp2;
1247: }
1248: $tmp1=$oRN.'.log';
1249: $tmp2=$nRN.'.log';
1250: if(-e $tmp1){
1251: unless(rename($tmp1,$tmp2)){ }
1252: } elsif(-e $tmp2){
1253: unlink $tmp2;
1254: }
1255: $tmp1=$oRN.'.bak';
1256: $tmp2=$nRN.'.bak';
1257: if(-e $tmp1){
1258: unless(rename($tmp1,$tmp2)){ }
1259: } elsif(-e $tmp2){
1260: unlink $tmp2;
1261: }
1262: } else {
1.103 bisitz 1263: $request->print(
1.117 bisitz 1264: '<p class="LC_error">'
1.103 bisitz 1265: .&mt('No such file: [_1]',
1266: &display($oldfile))
1267: .'</p></form>'
1.100 bisitz 1268: );
1.55 albertel 1269: return 0;
1270: }
1271: return 1;
1.12 foxr 1272: }
1.55 albertel 1273:
1.12 foxr 1274: =pod
1275:
1276: =item Delete2($request, $user, $filename)
1277:
1.127 raeburn 1278: Performs phase two of a delete. The user has confirmed that they want
1.12 foxr 1279: to delete the selected file. The file is deleted and the results of the
1280: delete attempt are indicated.
1281:
1282: Parameters:
1283:
1284: =over 4
1285:
1286: =item $request - Apache Request object [in] the request object for the current
1287: delete operation.
1288:
1289: =item $user - string [in] The name of the user initiating the delete
1290: request.
1291:
1.17 harris41 1292: =item $filename - string [in] The name of the file, relative to construction
1293: space, to delete.
1.12 foxr 1294:
1295: =back
1296:
1297: Returns:
1298: 1 - success.
1299: 0 - Failure.
1300:
1301: =cut
1302:
1303: sub Delete2 {
1.55 albertel 1304: my ($request, $user, $filename) = @_;
1.127 raeburn 1305: if (-d $filename) {
1306: unless (&empty_directory($filename,'Delete2')) {
1307: $request->print('<span class="LC_error">'.&mt('Error: Directory Non Empty').'</span>');
1.55 albertel 1308: return 0;
1.127 raeburn 1309: } else {
1.55 albertel 1310: if(-e $filename) {
1311: unless(rmdir($filename)) {
1.83 albertel 1312: $request->print('<span class="LC_error">'.&mt('Error').': '.$!.'</span>');
1.55 albertel 1313: return 0;
1314: }
1315: } else {
1.100 bisitz 1316: $request->print('<p class="LC_error">'.&mt('No such file').'</p></form>');
1.55 albertel 1317: return 0;
1318: }
1319: }
1.48 taceyjo1 1320: } else {
1.55 albertel 1321: if(-e $filename) {
1322: unless(unlink($filename)) {
1.83 albertel 1323: $request->print('<span class="LC_error">'.&mt('Error').': '.$!.'</span>');
1.55 albertel 1324: return 0;
1325: }
1326: } else {
1.100 bisitz 1327: $request->print('<p class="LC_error">'.&mt('No such file').'</p></form>');
1.55 albertel 1328: return 0;
1.46 taceyjo1 1329: }
1.55 albertel 1330: }
1331: return 1;
1.12 foxr 1332: }
1333:
1334: =pod
1335:
1336: =item Copy2($request, $username, $dir, $oldfile, $newfile)
1337:
1.127 raeburn 1338: Performs phase 2 of a copy. The file is copied and the status
1.12 foxr 1339: of that copy is reported back to the user.
1340:
1341: =over 4
1342:
1343: =item $request - Apache request object [in]; the apache request currently
1344: being executed.
1345:
1346: =item $username - string [in] Name of the user who is requesting the copy.
1347:
1348: =item $dir - string [in] Directory path relative to the construction space
1349: of the destination file.
1350:
1351: =item $oldfile - string [in] Name of the source file.
1352:
1353: =item $newfile - string [in] Name of the destination file.
1354:
1355:
1356: =back
1357:
1.71 raeburn 1358: Returns 0 failure, and 1 successs.
1.12 foxr 1359:
1360: =cut
1.1 www 1361:
1.12 foxr 1362: sub Copy2 {
1363: my ($request, $username, $dir, $oldfile, $newfile) = @_;
1364: &Debug($request ,"Will try to copy $oldfile to $newfile");
1365: if(-e $oldfile) {
1.71 raeburn 1366: if ($oldfile eq $newfile) {
1.83 albertel 1367: $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>');
1.71 raeburn 1368: return 1;
1369: }
1.12 foxr 1370: unless (copy($oldfile, $newfile)) {
1.83 albertel 1371: $request->print('<span class="LC_error">'.&mt('copy Error').': '.$!.'</span>');
1.12 foxr 1372: return 0;
1.61 albertel 1373: } elsif (!chmod(0660, $newfile)) {
1.83 albertel 1374: $request->print('<span class="LC_error">'.&mt('chmod error').': '.$!.'</span>');
1.61 albertel 1375: return 0;
1.127 raeburn 1376: } elsif (-e $oldfile.'.meta' &&
1.61 albertel 1377: !copy($oldfile.'.meta', $newfile.'.meta') &&
1378: !chmod(0660, $newfile.'.meta')) {
1.83 albertel 1379: $request->print('<span class="LC_error">'.&mt('copy metadata error').
1380: ': '.$!.'</span>');
1.61 albertel 1381: return 0;
1.12 foxr 1382: } else {
1383: return 1;
1384: }
1.11 albertel 1385: } else {
1.100 bisitz 1386: $request->print('<p class="LC_error">'.&mt('No such file').'</p>');
1.12 foxr 1387: return 0;
1.11 albertel 1388: }
1.12 foxr 1389: return 1;
1390: }
1.55 albertel 1391:
1.12 foxr 1392: =pod
1393:
1394: =item NewDir2($request, $user, $newdirectory)
1.1 www 1395:
1.12 foxr 1396: Performs phase 2 processing of directory creation. This involves creating the directory and
1397: reporting the results of that creation to the user.
1398:
1399: Parameters:
1400: =over 4
1401:
1402: =item $request - Apache request object [in]. Object representing the current HTTP request.
1403:
1404: =item $user - string [in] The name of the user that is initiating the request.
1405:
1406: =item $newdirectory - string [in] The full path of the directory being created.
1407:
1408: =back
1409:
1410: Returns 0 - failure 1 - success.
1411:
1412: =cut
1.8 albertel 1413:
1.12 foxr 1414: sub NewDir2 {
1.55 albertel 1415: my ($request, $user, $newdirectory) = @_;
1.127 raeburn 1416:
1.55 albertel 1417: unless(mkdir($newdirectory, 02770)) {
1.83 albertel 1418: $request->print('<span class="LC_error">'.&mt('Error').': '.$!.'</span>');
1.55 albertel 1419: return 0;
1420: }
1421: unless(chmod(02770, ($newdirectory))) {
1.83 albertel 1422: $request->print('<span class="LC_error">'.&mt('Error').': '.$!.'</span>');
1.55 albertel 1423: return 0;
1424: }
1425: return 1;
1.1 www 1426: }
1.55 albertel 1427:
1.44 taceyjo1 1428: sub decompress2 {
1.55 albertel 1429: my ($r, $user, $dir, $file) = @_;
1.88 raeburn 1430: &Apache::lonnet::appenv({'cgi.file' => $file});
1431: &Apache::lonnet::appenv({'cgi.dir' => $dir});
1.55 albertel 1432: my $result=&Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
1433: $r->print($result);
1434: &Apache::lonnet::delenv('cgi.file');
1435: &Apache::lonnet::delenv('cgi.dir');
1436: return 1;
1.44 taceyjo1 1437: }
1.55 albertel 1438:
1.128 ! raeburn 1439: sub Archive2 {
! 1440: my ($r,$name,$udom,$fn,$identifier) = @_;
! 1441: my %options = (
! 1442: dir => $fn,
! 1443: );
! 1444: my @filetypes = qw(problem library sty sequence page task rights meta xml html xhtml htm xhtm css js tex txt gif jpg jpeg png svg other);
! 1445: my (@include,%oktypes);
! 1446: map { $oktypes{$_} = 1; } @filetypes;
! 1447: my @posstypes = &Apache::loncommon::get_env_multiple('form.filetype');
! 1448: foreach my $type (@posstypes) {
! 1449: if ($oktypes{$type}) {
! 1450: push(@include,$type);
! 1451: }
! 1452: }
! 1453: if (scalar(@include) == scalar(@filetypes)) {
! 1454: $options{'types'} = 'all';
! 1455: } else {
! 1456: $options{'types'} = join(',',@include);
! 1457: }
! 1458: if (exists($env{'form.recurse'})) {
! 1459: $options{'recurse'} = 1;
! 1460: }
! 1461: if (exists($env{'form.encrypt'})) {
! 1462: if ($env{'form.enckey'} ne '') {
! 1463: $options{'encrypt'} = $env{'form.enckey'};
! 1464: }
! 1465: }
! 1466: $options{'format'} = 'tar';
! 1467: $options{'compress'} = 'gzip';
! 1468: if ((exists($env{'form.format'})) && $env{'form.format'} =~ /^zip$/i) {
! 1469: $options{'format'} = 'zip';
! 1470: delete($options{'compress'});
! 1471: } elsif ((exists($env{'form.compress'})) && ($env{'form.compress'} =~ /^(xz|bzip2)$/i)) {
! 1472: $options{'compress'} = lc($env{'form.compress'});
! 1473: }
! 1474: my $key = 'cgi.'.$identifier.'.archive';
! 1475: my $storestring = &Apache::lonnet::freeze_escape(\%options);
! 1476: &Apache::lonnet::appenv({$key => $storestring});
! 1477: return 1;
! 1478: }
! 1479:
1.12 foxr 1480: =pod
1481:
1.128 ! raeburn 1482: =item phasetwo($r, $fn, $uname, $udom,$identifier)
1.12 foxr 1483:
1484: Controls the phase 2 processing of file management
1485: requests for construction space. In phase one, the user
1486: was asked to confirm the operation. In phase 2, the operation
1487: is performed and the result is shown.
1488:
1489: The strategy is to break out the processing into specific action processors
1.127 raeburn 1490: named action2 where action is the requested action and the 2 denotes
1.12 foxr 1491: phase 2 processing.
1492:
1493: Parameters:
1494:
1495: =over 4
1496:
1497: =item $r - Apache Request object [in] The request object for this httpd
1498: transaction.
1499:
1500: =item $fn - string [in] A filename indicating the object that is being
1501: manipulated.
1502:
1503: =item $uname - string [in] The name of the user initiating the file management
1504: request.
1505:
1506: =item $udom - string [in] The login domain of the user initiating the
1507: file management request.
1508: =back
1509:
1510: =cut
1511:
1.1 www 1512: sub phasetwo {
1.128 ! raeburn 1513: my ($r,$fn,$uname,$udom,$identifier)=@_;
1.127 raeburn 1514:
1.9 foxr 1515: &Debug($r, "loncfile - Entering phase 2 for $fn");
1.127 raeburn 1516:
1.78 banghart 1517: # Break down the file into its component pieces.
1.127 raeburn 1518:
1.27 albertel 1519: my $dir; # Directory path
1520: my $main; # Filename.
1521: my $suffix; # Extension.
1.46 taceyjo1 1522: if ($fn=~m:(.*)/([^/]+):) {
1.27 albertel 1523: $dir=$1; # Directory path
1524: $main=$2; # Filename.
1.54 albertel 1525: }
1526: if($main=~m:\.(\w+)$:){ # Fixes problems with filenames with no extensions
1.68 albertel 1527: $suffix=$1; #This is the actually filename extension if it exists
1.66 albertel 1528: $main=~s/\.\w+$//; #strip the extension
1.54 albertel 1529: }
1.79 banghart 1530: my $dest; #
1531: my $dest_dir; # On success this is where we'll go.
1532: my $disp_newname; #
1533: my $dest_newname; #
1.55 albertel 1534: &Debug($r,"loncfile::phase2 dir = $dir main = $main suffix = $suffix");
1.67 albertel 1535: &Debug($r," newfilename = ".$env{'form.newfilename'});
1.9 foxr 1536:
1537: my $conspace=$fn;
1.127 raeburn 1538:
1.55 albertel 1539: &Debug($r,"loncfile::phase2 Full construction space name: $conspace");
1.127 raeburn 1540:
1.67 albertel 1541: &Debug($r,"loncfie::phase2 action is $env{'form.action'}");
1.127 raeburn 1542:
1.12 foxr 1543: # Select the appropriate processing sub.
1.127 raeburn 1544: if ($env{'form.action'} eq 'decompress') {
1.66 albertel 1545: $main .= '.'.$suffix;
1.55 albertel 1546: if(!&decompress2($r, $uname, $dir, $main)) {
1547: return ;
1548: }
1549: $dest = $dir."/.";
1.128 ! raeburn 1550: } elsif ($env{'form.action'} eq 'archive') {
! 1551: &Archive2($r,$uname,$udom,$fn,$identifier);
! 1552: return;
1.67 albertel 1553: } elsif ($env{'form.action'} eq 'rename' ||
1554: $env{'form.action'} eq 'move') {
1555: if($env{'form.newfilename'}) {
1.27 albertel 1556: if (!defined($dir)) {
1557: $fn=~m:^(.*)/:;
1.127 raeburn 1558: $dir=$1;
1.27 albertel 1559: }
1.67 albertel 1560: if(!&Rename2($r, $uname, $dir, $fn, $env{'form.newfilename'})) {
1.12 foxr 1561: return;
1562: }
1.78 banghart 1563: $dest = $dir."/";
1.79 banghart 1564: $dest_newname = $env{'form.newfilename'};
1565: $env{'form.newfilename'} =~ /.+(\/.+$)/;
1566: $disp_newname = $1;
1567: $disp_newname =~ s/\///;
1.12 foxr 1568: }
1.127 raeburn 1569: } elsif ($env{'form.action'} eq 'delete') {
1.67 albertel 1570: if(!&Delete2($r, $uname, $env{'form.newfilename'})) {
1.12 foxr 1571: return ;
1572: }
1573: # Once a resource is deleted, we just list the directory that
1574: # previously held it.
1575: #
1.20 albertel 1576: $dest = $dir."/."; # Parent dir.
1.127 raeburn 1577: } elsif ($env{'form.action'} eq 'copy') {
1.67 albertel 1578: if($env{'form.newfilename'}) {
1579: if(!&Copy2($r, $uname, $dir, $fn, $env{'form.newfilename'})) {
1.44 taceyjo1 1580: return ;
1.55 albertel 1581: }
1.67 albertel 1582: $dest = $env{'form.newfilename'};
1.55 albertel 1583: } else {
1.100 bisitz 1584: $r->print('<p class="LC_error">'.&mt('No New filename specified').'</p></form>');
1.12 foxr 1585: return;
1586: }
1587:
1.67 albertel 1588: } elsif ($env{'form.action'} eq 'newdir') {
1589: my $newdir= $env{'form.newfilename'};
1.12 foxr 1590: if(!&NewDir2($r, $uname, $newdir)) {
1591: return;
1592: }
1.55 albertel 1593: $dest = $newdir."/";
1.12 foxr 1594: }
1.67 albertel 1595: if ( ($env{'form.action'} eq 'newdir') && ($env{'form.phase'} eq 'two') && ( ($env{'form.callingmode'} eq 'testbank') || ($env{'form.callingmode'} eq 'imsimport') ) ) {
1.117 bisitz 1596: $r->print(
1597: '<p>'
1598: .&Apache::lonhtmlcommon::confirm_success(&mt('Done'))
1599: .'<br /><a href="javascript:self.close()">'.&mt('Continue').'</a>'
1600: .'</p>'
1601: );
1.51 raeburn 1602: } else {
1.79 banghart 1603: if ($env{'form.action'} eq 'rename') {
1.117 bisitz 1604: $r->print(
1605: '<p>'.&Apache::lonhtmlcommon::confirm_success(&mt('Done')).'</p>'
1606: .&Apache::lonhtmlcommon::actionbox(
1607: ['<a href="'.&url($dest).'">'.&mt('Return to Directory').'</a>',
1608: '<a href="'.&url($dest_newname).'">'.$disp_newname.'</a>']));
1.79 banghart 1609: } else {
1.125 raeburn 1610: $r->print(&done($dest));
1.79 banghart 1611: }
1.51 raeburn 1612: }
1.1 www 1613: }
1614:
1615: sub handler {
1616:
1.55 albertel 1617: $r=shift;
1.1 www 1618:
1.123 golterma 1619: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['decompress','action','filename','newfilename','mode']);
1.9 foxr 1620:
1.55 albertel 1621: &Debug($r, "loncfile.pm - handler entered");
1.67 albertel 1622: &Debug($r, " filename: ".$env{'form.filename'});
1623: &Debug($r, " newfilename: ".$env{'form.newfilename'});
1.36 www 1624: #
1625: # Determine the root filename
1626: # This could come in as "filename", which actually is a URL, or
1627: # as "qualifiedfilename", which is indeed a real filename in filesystem
1628: #
1.55 albertel 1629: my $fn;
1.1 www 1630:
1.67 albertel 1631: if ($env{'form.filename'}) {
1632: &Debug($r, "test: $env{'form.filename'}");
1.77 www 1633: $fn=&unescape($env{'form.filename'});
1.55 albertel 1634: $fn=&URLToPath($fn);
1.128 ! raeburn 1635: } elsif($ENV{'QUERY_STRING'} && $env{'form.phase'} ne 'two') {
1.55 albertel 1636: #Just hijack the script only the first time around to inject the
1637: #correct information for further processing
1.77 www 1638: $fn=&unescape($env{'form.decompress'});
1.44 taceyjo1 1639: $fn=&URLToPath($fn);
1.67 albertel 1640: $env{'form.action'}="decompress";
1641: } elsif ($env{'form.qualifiedfilename'}) {
1642: $fn=$env{'form.qualifiedfilename'};
1.55 albertel 1643: } else {
1644: &Debug($r, "loncfile::handler - no form.filename");
1.67 albertel 1645: $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
1.127 raeburn 1646: ' unspecified filename for cfile', $r->filename);
1.55 albertel 1647: return HTTP_NOT_FOUND;
1648: }
1.44 taceyjo1 1649:
1.126 raeburn 1650: unless ($fn) {
1.55 albertel 1651: &Debug($r, "loncfile::handler - doctored url is empty");
1.67 albertel 1652: $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
1.127 raeburn 1653: ' trying to cfile non-existing file', $r->filename);
1.55 albertel 1654: return HTTP_NOT_FOUND;
1.127 raeburn 1655: }
1.1 www 1656:
1657: # ----------------------------------------------------------- Start page output
1.55 albertel 1658:
1.116 raeburn 1659: my ($uname,$udom) = &Apache::lonnet::constructaccess($fn);
1.127 raeburn 1660: &Debug($r,
1.55 albertel 1661: "loncfile::handler constructaccess uname = $uname domain = $udom");
1.113 raeburn 1662: if (($uname eq '') || ($udom eq '')) {
1.55 albertel 1663: $r->log_reason($uname.' at '.$udom.
1.67 albertel 1664: ' trying to manipulate file '.$env{'form.filename'}.
1.127 raeburn 1665: ' ('.$fn.') - not authorized',
1666: $r->filename);
1.55 albertel 1667: return HTTP_NOT_ACCEPTABLE;
1668: }
1669:
1.1 www 1670:
1.55 albertel 1671: &Apache::loncommon::content_type($r,'text/html');
1672: $r->send_http_header;
1673:
1.128 ! raeburn 1674: my ($js,$identifier);
! 1675: my $args = {};
1.75 albertel 1676:
1.128 ! raeburn 1677: if (($env{'form.action'} eq 'newdir') && ($env{'form.phase'} eq 'two') &&
! 1678: (($env{'form.callingmode'} eq 'testbank') || ($env{'form.callingmode'} eq 'imsimport'))) {
1.67 albertel 1679: my $newdirname = $env{'form.newfilename'};
1.128 ! raeburn 1680: &js_escape(\$newdirname);
! 1681: $js = <<"ENDJS";
1.75 albertel 1682: <script type="text/javascript">
1.128 ! raeburn 1683: // <![CDATA[
1.51 raeburn 1684: function writeDone() {
1685: window.focus();
1.90 raeburn 1686: opener.document.info.newdir.value = "$newdirname";
1687: setTimeout("self.close()",10000);
1.51 raeburn 1688: }
1.128 ! raeburn 1689: // ]]>
! 1690: </script>
! 1691: ENDJS
! 1692: $args->{'add_entries'} = { onload => "writeDone()" };
! 1693: } elsif (($env{'form.action'} eq 'archive') &&
! 1694: ($env{'environment.authorarchive'})) {
! 1695: if ($env{'form.phase'} eq 'two') {
! 1696: $identifier = &Apache::loncommon::get_cgi_id();
! 1697: $args->{'redirect'} = [0,"/cgi-bin/archive.pl?$identifier"];
! 1698: } else {
! 1699: my $check_uncheck_js = &Apache::loncommon::check_uncheck_jscript();
! 1700: $js = <<"ENDJS";
! 1701: <script type="text/javascript">
! 1702: // <![CDATA[
! 1703: function toggleCompression(form) {
! 1704: if (document.getElementById('tar_compression')) {
! 1705: if (form.format.length > 1) {
! 1706: for (var i=0; i<form.format.length; i++) {
! 1707: if (form.format[i].checked) {
! 1708: if (form.format[i].value == 'zip') {
! 1709: document.getElementById('tar_compression').style.display = 'none';
! 1710: } else if (form.format[i].value == 'tar') {
! 1711: document.getElementById('tar_compression').style.display = 'block';
! 1712: }
! 1713: break;
! 1714: }
! 1715: }
! 1716: }
! 1717: }
! 1718: return;
! 1719: }
! 1720:
! 1721: function resetForm() {
! 1722: if (document.phaseone.filetype.length) {
! 1723: for (var i=0; i<document.phaseone.filetype.length; i++) {
! 1724: document.phaseone.filetype[i].checked = false;
! 1725: }
1.55 albertel 1726: }
1.128 ! raeburn 1727: if (document.getElementById('tar_compression')) {
! 1728: if (document.phaseone.format.length) {
! 1729: document.getElementById('tar_compression').style.display = 'block';
! 1730: for (var i=0; i<document.phaseone.format.length; i++) {
! 1731: if (document.phaseone.format[i].value == 'tar') {
! 1732: document.phaseone.format[i].checked = true;
! 1733: } else {
! 1734: document.phaseone.format[i].checked = false;
! 1735: }
! 1736: }
! 1737: }
! 1738: if (document.phaseone.compress.length) {
! 1739: for (var i=0; i<document.phaseone.compress.length; i++) {
! 1740: if (document.phaseone.compress[i].value == 'gzip') {
! 1741: document.phaseone.compress[i].checked = true;
! 1742: } else {
! 1743: document.phaseone.compress[i].checked = false;
! 1744: }
! 1745: }
! 1746: }
! 1747: }
! 1748: document.phaseone.recurse.checked = false;
! 1749: }
1.113 raeburn 1750:
1.128 ! raeburn 1751: $check_uncheck_js
! 1752:
! 1753: // ]]>
! 1754: </script>
! 1755:
! 1756: ENDJS
! 1757: $args->{'add_entries'} = { onload => "resetForm()" };
! 1758: }
! 1759: }
1.113 raeburn 1760: my $londocroot = $r->dir_config('lonDocRoot');
1761: my $trailfile = $fn;
1762: $trailfile =~ s{^/(priv/)}{$londocroot/$1};
1.126 raeburn 1763:
1.99 bisitz 1764: # Breadcrumbs
1.126 raeburn 1765: my $crsauthor;
1766: my $text = 'Authoring Space';
1767: my $title = 'Authoring Space File Operation',
1768: my $href = &Apache::loncommon::authorspace(&url($fn));
1769: if ($env{'request.course.id'}) {
1770: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1771: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1772: if ($href eq "/priv/$cdom/$cnum/") {
1773: $text = 'Course Authoring Space';
1774: $title = 'Course Authoring Space File Operation',
1775: $crsauthor = 1;
1776: }
1777: }
1.99 bisitz 1778: &Apache::lonhtmlcommon::clear_breadcrumbs();
1779: &Apache::lonhtmlcommon::add_breadcrumb({
1.126 raeburn 1780: 'text' => $text,
1781: 'href' => $href,
1.99 bisitz 1782: });
1783: &Apache::lonhtmlcommon::add_breadcrumb({
1784: 'text' => 'File Operation',
1.126 raeburn 1785: 'title' => $title,
1.99 bisitz 1786: 'href' => '',
1787: });
1788:
1.128 ! raeburn 1789: $r->print(&Apache::loncommon::start_page($title,$js,$args)
1.99 bisitz 1790: .&Apache::lonhtmlcommon::breadcrumbs()
1791: .&Apache::loncommon::head_subbox(
1.113 raeburn 1792: &Apache::loncommon::CSTR_pageheader($trailfile))
1.99 bisitz 1793: );
1.127 raeburn 1794:
1.128 ! raeburn 1795: unless ($env{'form.action'} eq 'archive') {
! 1796: $r->print('<p>'.&mt('Location').': '.&display($fn).'</p>');
! 1797: }
1.127 raeburn 1798:
1.67 albertel 1799: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.127 raeburn 1800: unless ($crsauthor) {
1.126 raeburn 1801: $r->print('<p class="LC_info">'
1802: .&mt('Co-Author [_1]',$uname.':'.$udom)
1803: .'</p>'
1804: );
1805: }
1.55 albertel 1806: }
1807:
1808:
1.67 albertel 1809: &Debug($r, "loncfile::handler Form action is $env{'form.action'} ");
1.117 bisitz 1810: my %action = &Apache::lonlocal::texthash(
1811: 'delete' => 'Delete',
1812: 'rename' => 'Rename',
1813: 'move' => 'Move',
1814: 'newdir' => 'New Directory',
1815: 'decompress' => 'Decompress',
1.128 ! raeburn 1816: 'archive' => 'Export directory to archive file',
1.117 bisitz 1817: 'copy' => 'Copy',
1818: 'newfile' => 'New Resource',
1819: 'newhtmlfile' => 'New Resource',
1820: 'newproblemfile' => 'New Resource',
1821: 'newpagefile' => 'New Resource',
1822: 'newsequencefile' => 'New Resource',
1823: 'newrightsfile' => 'New Resource',
1824: 'newstyfile' => 'New Resource',
1825: 'newtaskfile' => 'New Resource',
1826: 'newlibraryfile' => 'New Resource',
1827: 'Select Action' => 'New Resource',
1828: );
1829: if ($action{$env{'form.action'}}) {
1.126 raeburn 1830: if ($crsauthor) {
1831: my @disallowed = qw(page sequence rights library);
1832: my $newtype;
1833: if ($env{'form.action'} =~ /^new(\w+)file$/) {
1834: $newtype = $1;
1835: } elsif ($env{'form.action'} eq 'newfile') {
1836: ($newtype) = ($env{'form.newfilename'} =~ m{\.([^/.]+)$});
1837: $newtype = lc($newtype);
1838: }
1839: if (($newtype ne '') &&
1840: (grep(/^\Q$newtype\E$/,@disallowed))) {
1841: $r->print('<p class="LC_error">'
1842: .&mt('Creation of a new file of type: [_1] is not permitted in Course Authoring Space',$newtype)
1843: .'</p>'
1844: .&Apache::loncommon::end_page()
1845: );
1846: return OK;
1847: }
1.128 ! raeburn 1848: if ($env{'form.action'} eq 'archive') {
! 1849: $r->print('<p>'.&mt('Location').': '.&display($fn).'</p>'."\n".
! 1850: '<p class="LC_error">'.
! 1851: &mt('Export to an archive file is not permitted in Course Authoring Space').
! 1852: '</p>'."\n".
! 1853: &Apache::loncommon::end_page());
! 1854: return OK;
! 1855: }
! 1856: } elsif ($env{'form.action'} eq 'archive') {
! 1857: unless ($env{'environment.authorarchive'}) {
! 1858: $r->print('<p>'.&mt('Location').': '.&display($fn).'</p>'."\n".
! 1859: '<p class="LC_error">'.
! 1860: &mt('You do not have permission to export to an archive file in this Authoring Space').
! 1861: '</p>'."\n".
! 1862: &Apache::loncommon::end_page());
! 1863: return OK;
! 1864: }
1.126 raeburn 1865: }
1.117 bisitz 1866: $r->print('<h2>'.$action{$env{'form.action'}}.'</h2>');
1.55 albertel 1867: } else {
1.100 bisitz 1868: $r->print('<p class="LC_error">'
1.117 bisitz 1869: .&mt('Unknown Action: [_1]',$env{'form.action'})
1.100 bisitz 1870: .'</p>'
1871: .&Apache::loncommon::end_page()
1872: );
1.117 bisitz 1873: return OK;
1.55 albertel 1874: }
1.117 bisitz 1875:
1.67 albertel 1876: if ($env{'form.phase'} eq 'two') {
1.55 albertel 1877: &Debug($r, "loncfile::handler entering phase2");
1.128 ! raeburn 1878: &phasetwo($r,$fn,$uname,$udom,$identifier);
1.55 albertel 1879: } else {
1880: &Debug($r, "loncfile::handler entering phase1");
1881: &phaseone($r,$fn,$uname,$udom);
1882: }
1.1 www 1883:
1.75 albertel 1884: $r->print(&Apache::loncommon::end_page());
1.127 raeburn 1885: return OK;
1.1 www 1886: }
1887:
1888: 1;
1889: __END__
1.9 foxr 1890:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>