                                                        

<?php
//-->-->-->-->-->-->-->-->-->-->-->-->-->-->
   $sLibraryPath = '/usr50/home/retrovox/public_html/manage/php-lib';
   include "$sLibraryPath/RETROVOX-CONSTANT-VARIABLES.php";
   include "$sLibraryPath/fnRetrovoxStartHtml.php";
   include "$sLibraryPath/fnRetrovoxDirectoryListing.php";

  $sFilePath = '';

  $sFilePath = $_GET['old-name'];
  $sFilePathEncoded = htmlspecialchars($sFilePath);

  $sNewFilePath = $_GET['new-name'];
  $sNewFilePathEncoded = htmlspecialchars($sNewFilePath);


  if (substr($sFilePath, 0, 1) != "/")
  {
    $sFilePath = "/$sFilePath";  
  }
  
  if (!strstr($sFilePath, "/usr50/home/retrovox"))
  {
    $sFilePath = "/usr50/home/retrovox".$sFilePath;
  }

  $sWebFilePathEncoded = 
    htmlspecialchars(
      str_replace("/usr50/home/retrovox/public_html", "", $sFilePath));
  
  if (substr($sNewFilePath, 0, 1) != "/")
  {
    $sNewFilePath = "/$sNewFilePath";  
  }
  
  if (!strstr($sNewFilePath, "/usr50/home/retrovox"))
  {
    $sNewFilePath = "/usr50/home/retrovox".$sNewFilePath;
  }

  $sWebNewFilePathEncoded = 
    htmlspecialchars(
      str_replace("/usr50/home/retrovox/public_html", "", $sNewFilePath));

  $bStripSlashes = $_GET['stripslash'];

  if ($sFilePath == '/usr50/home/retrovox/')
  {
    echo fnRetrovoxStartHtml("Copy File: no source file name specified");
    echo "
      <p>You did not specify any file to be edited</p>
      <br>
        <ol>
          <li><a href = 'move-file-form.php'>
	   Try Again</a></li>
        </ol>
	  
      </body>
      </html>";
     exit; 
  } //-- if no file specified
 
  
  
  if (is_dir($sFilePath))
  {
    if (substr($sFilePath, -1) != "/")
    {
      $sFilePath = "$sFilePath/";
    }
    
    echo fnRetrovoxStartHtml("Copy File: the source file is a directory");
    echo "
	  <p>
          The file-name [$sFilePathEncoded] which you just specified is a directory (folder).
          The Retrovox Notepad system is for editing text files located on the
          server. 
          </p>
          <br>
          <ol type = 'a'>
           <li><a href = \"move-file-form.php?file=$sFilePathEncoded\">
	   Re-enter the file name</a></li>
          <li>";

     echo fnRetrovoxDirectoryListing($sFilePath, true);
     echo "</li>
        </ol>
        </body>
        </html>";
      
     exit;
  } //-- if file is a directory

  if ($sNewFilePath == '/usr50/home/retrovox/')
  {
    echo fnRetrovoxStartHtml("Copy File: no target name specified");
    echo "
	  <p>You did not specify the target name of the file to be copied</p>
          <br>
          <ol>
           <li><a href = \"move-file-form.php?file=$sFilePathEncoded\">
	   Try Again</a></li>
          </ol>
	  
      </body>
      </html>";
     exit; 
  } //-- if no file specified

  if ($sFilePath == $sNewFilePath)
  { 
    echo fnRetrovoxStartHtml("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;
  }

  if (!file_exists($sFilePath))
  {
    echo fnRetrovoxStartHtml("Copy File: the source file doesn't exist");
    echo "
	  <p>
          The file-name [$sFilePathEncoded] which you just specified does
	  not exist and therefore cannot be copied or renamed
          </p>
          <br>
          <ol>
           <li><a href = \"move-file-form.php?file=$sFilePathEncoded\">
	   Re-enter the file name</a></li>
          </ol>
           
      </body>
      </html>";
      exit; 
	  
  }
  else
  {
     copy($sFilePath, $sNewFilePath);
  } 

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

<?=fnRetrovoxStartHtml("Retrovox copy 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 again</a></li>
    <li>
    <a href = "notepad/retrovox-notepad.php?file=<?=urlencode($sFilePathEncoded)?>">
       Edit <em><?=$sFilePathEncoded?></em></a> (If its a text file)</li>
     <li>
     <a href = "notepad/retrovox-notepad.php?file=<?=urlencode($sNewFilePathEncoded)?>">
      Edit <em><?=$sNewFilePathEncoded?></em></a> (If its a text file)</li>
    </ol>
    <br>
</body>
</html>

            