File:  [LON-CAPA] / loncom / publisher / loncfile.pm
Revision 1.69: download - view: text, annotated - select for diffs
Mon May 30 16:56:46 2005 UTC (18 years, 11 months ago) by www
Branches: MAIN
CVS tags: version_1_99_2, version_1_99_1, version_1_99_0, HEAD
Bug 3392 - don't allow ':::', etc
Bug 4113 - require extensions

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>