                                                                                                                    

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

   include "$LIBRARYPATH/RETROVOX-CONSTANT-VARIABLES.php";
   include "$LIBRARYPATH/fnStartHtml.php";
   include "$LIBRARYPATH/fnRetrovoxStartHtml.php";
   include "$LIBRARYPATH/fnRetrovoxDirectoryListing.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);
  //echo $sErrorTemplateContents;
  //exit;


  //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)
  { 
    echo fnStartHtml("Copy File: the new name is the same as the old");
    echo "
       <p>The two file names which you specified in the copy form were
          the same.
       </p>
       <a  href = \"move-file-form.php?file=$sFilePathEncoded\">
       Please re-enter the file names</a>
       </body>
       </html>";
       exit;
  }

  copy($sFilePath, $sNewFilePath);

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

<?=fnStartHtml("copy server file")?>

    <p>The file: <em><?=$sFilePathEncoded?></em>
    <br>was copied to: <em><?=$sNewFilePathEncoded?></em>
    </p>
    <ol>
    <li>
    <a href = "move-file-form.php?file=<?=urlencode($sFilePathEncoded)?>">
    Copy or rename again</a></li>
    <li>
    <a href = "<?=$NOTEPADWEBFOLDER?>/retrovox-notepad.php?file=<?=urlencode($sFilePathEncoded)?>">
       Edit <em><?=$sFilePathEncoded?></em></a> (If its a text file)</li>
     <li>
     <a href = "<?=$NOTEPADWEBFOLDER?>/retrovox-notepad.php?file=<?=urlencode($sNewFilePathEncoded)?>">
      Edit <em><?=$sNewFilePathEncoded?></em></a> (If its a text file)</li>
    </ol>
    <br>
</body>
</html>

                                                                        