Annotation of loncom/publisher/loncfile.pm, revision 1.44

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

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