                                                                                                                            

<?php
//-->-->-->-->-->-->-->-->-->-->-->-->-->-->
   //test
   include "/home/waggacwc/public_html/refurb/RETRO-GLOBALS.php";

   include "$LIBRARYPATH/fnDirectoryListing.php";
   include "$LIBRARYPATH/fnFillWebTemplate.php";
   include "$LIBRARYPATH/fnMessageToHtml.php";
   include "$LIBRARYPATH/fnHyperlinkPlainText.php";

  $sErrorTemplateContents = "";
  $sFilePath = '';

  $sFilePath = $_GET['old-name'];
  $sFilePath = str_replace('\\', '/', $sFilePath);
  $sFilePath = preg_replace('#[/]+#', '/', $sFilePath);
  $sFilePathEncoded = htmlspecialchars($sFilePath);

  $sNewFilePath = $_GET['new-name'];
  $sNewFilePath = str_replace('\\', '/', $sNewFilePath);
  $sNewFilePath = preg_replace('#[/]+#', '/', $sNewFilePath);
  $sNewFilePathEncoded = htmlspecialchars($sNewFilePath);


  $sWebFilePathEncoded = 
    htmlspecialchars(
      str_replace("/usr50/home/retrovox/public_html", "", $sFilePath));
  
  
  $aaTextLines = file($ERRORTEMPLATE);
  $sErrorTemplateContents = implode('', $aaTextLines);

  $aaTextLines = file($ADMINTEMPLATE);
  $sAdminTemplateContents = implode('', $aaTextLines);

  //if (substr($sNewFilePath, 0, 1) != "/")
  //{
  //  $sNewFilePath = "/$sNewFilePath";  
  //}
  

  $sWebNewFilePathEncoded = 
    htmlspecialchars(
      str_replace($WEBDOCUMENTROOT, "", $sNewFilePath));

  $bStripSlashes = $_GET['stripslash'];

  if ($sFilePath == '')
  {
     
    $sPageTitle = "Copy File: no source file name specified";
    $sPageContent = "
          = No File Names Specified

      You did not specify any files to be copied

      'Try Again' link://move-file-form.php

      ";

    $sPageContent = fnMessageToHtml($sPageContent);
    $sErrorPage = fnFillWebTemplate(
      $sErrorTemplateContents, $sPageContent, $sPageTitle);   
    echo $sErrorPage;

    exit; 
  } //-- if no old file specified
  

  if ($sNewFilePath == '')
  {
    $sPageTitle = "Copy File: no target file name specified";
    $sPageContent = "
          = No Target File Name Specified

      You did not specify the target name of the file to be copied

      'Try Again' link://move-file-form.php?file=$sFilePathEncoded

      ";

    $sPageContent = fnMessageToHtml($sPageContent);
    $sErrorPage = fnFillWebTemplate(
      $sErrorTemplateContents, $sPageContent, $sPageTitle);   
    echo $sErrorPage;
    exit; 

  } //-- if no file specified


  if (!file_exists($sFilePath))
  {
    if (file_exists($WEBDOCUMENTROOT.$sFilePath))
    {
      $sFilePath = $WEBDOCUMENTROOT.$sFilePath;
    }
    elseif (file_exists($WEBDOCUMENTROOT."/".$sFilePath))
    {
      $sFilePath = $WEBDOCUMENTROOT."/".$sFilePath;
    }
    else
    {
      $sPageTitle = "Copy File: the source file doesn't exist";
      $sPageContent = "
            = The Source File Doesnt Exist

        The file-name [$sFilePathEncoded] which you just specified does
        not exist and therefore cannot be copied or renamed

        'Try Again' link://move-file-form.php?file=$sFilePathEncoded ";

      $sPageContent = fnMessageToHtml($sPageContent);
      $sErrorPage = fnFillWebTemplate(
        $sErrorTemplateContents, $sPageContent, $sPageTitle);   
      echo $sErrorPage;

      exit; 
    }	  
  }

  if (is_dir($sFilePath))
  {
    if (substr($sFilePath, -1) != "/")
    {
      $sFilePath = "$sFilePath/";
    }
    
    $sPageTitle = "Copy File: the source file is a directory";
    $sPageContent = "
           = Copy File: the source file is a directory

      The file-name [$sFilePathEncoded] which you just specified is a 
      directory (folder). The webpad system is for editing text files 
      located on the server. 

      'Reenter the file name' 
         link://move-file-form.php?file=$sFilePathEncoded 
       
       ";

    $sPageContent = 
      fnMessageToHtml($sPageContent).fnDirectoryListing($sFilePath, true);

    $sErrorPage = fnFillWebTemplate(
      $sErrorTemplateContents, $sPageContent, $sPageTitle);   
    echo $sErrorPage;
      
    exit;
  } //-- if file is a directory

  if ($sFilePath == $sNewFilePath)
  { 
    $sPageTitle = "Copy File: the new name is the same as the old";
    $sPageContent = "
          = Copy File: the new name is the same as the old

      The two file names which you specified in the copy form were
      the same.

      'Try Again' link://move-file-form.php?file=$sFilePathEncoded

      ";

    $sPageContent = fnMessageToHtml($sPageContent);
    $sErrorPage = fnFillWebTemplate(
      $sErrorTemplateContents, $sPageContent, $sPageTitle);   
    echo $sErrorPage;

    exit;
  } //-- if the two file names the same

  copy($sFilePath, $sNewFilePath);

  //-- Display a message indicating success.

  $sPageTitle = "Server File Copied";
  $sPageContent = "
        = Server File Copied

    The file: $sFilePathEncoded
    was copied to: $sNewFilePathEncoded

    'Copy or rename again' 
       link://move-file-form.php?file=".urlencode($sFilePathEncoded)."

    'Edit $sFilePathEncoded'
      link://$NOTEPADWEBFOLDER/retrovox-notepad.php?file=".
      urlencode($sFilePathEncoded)." (If its a text file)
     
    'Edit $sNewFilePathEncoded'
      link://$NOTEPADWEBFOLDER/retrovox-notepad.php?file=".
      urlencode($sNewFilePathEncoded)." (If its a text file)

      ";

    $sPageContent = fnMessageToHtml($sPageContent);
    $sResultPage = fnFillWebTemplate(
      $sErrorTemplateContents, $sPageContent, $sPageTitle);   
    echo $sResultPage;

//--<--<--<--<--<--<--<--<--<--<--<--<--<--<
?>


                                                                                