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

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

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