                                                                            

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

   include "c:/apache2/htdocs/RETRO-GLOBALS.php";

   include "$LIBRARYPATH/RETROVOX-CONSTANT-VARIABLES.php";
   include "$LIBRARYPATH/fnRetrovoxStartHtml.php";
   include "$LIBRARYPATH/fnRetrovoxDirectoryListing.php";


  $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);

  $bDebug = "";
  if ($bDebug == "true")
  {
    echo "
     <pre>
       sFilePath=$sFilePath
       sNewFilePath=$sNewFilePath
     </pre>";
  } //-- if debug mode
  
  $sWebNewFilePathEncoded = 
    htmlspecialchars(
      str_replace($WEBDOCUMENTROOT, "", $sNewFilePath));

  $bStripSlashes = $_GET['stripslash'];

  if ($sFilePath == '')
  {
    echo fnRetrovoxStartHtml("Rename File: no source file name specified");
    echo "
      <p>You did not specify any file to be renamed</p>
      <br>
        <ol>
          <li><a href = 'move-file-form.php'>
	   Try Again</a></li>
        </ol>
	  
      </body>
      </html>";
     exit; 
  } //-- if no old file specified
 
  if ($sNewFilePath == '')
  {
    echo fnRetrovoxStartHtml("Rename 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 new file name specified


  if (!file_exists($sFilePath))
  {
    if (file_exists($WEBDOCUMENTROOT.$sFilePath))
    {
      $sFilePath = $WEBDOCUMENTROOT.$sFilePath;
    }
    elseif (file_exists($WEBDOCUMENTROOT."/".$sFilePath))
    {
      $sFilePath = $WEBDOCUMENTROOT."/".$sFilePath;
    }
    else
    {

      echo fnRetrovoxStartHtml("Rename File: the source file doesn't exist");
      echo "
	  <p>
          The file-name [$sFilePathEncoded] which you just specified does
	  not exist and therefore cannot be renamed
          </p>
          <br>
          <ol>
           <li><a href = \"move-file-form.php?file=$sFilePathEncoded\">
	   Re-enter the file name</a></li>
          </ol>
           
      </body>
      </html>";
      exit; 
    } //-- if, else old file path is web-relative	  
  } //-- if the old file path doesn't exist

  if (is_dir($sFilePath))
  {
    if (substr($sFilePath, -1) != "/")
    {
      $sFilePath = "$sFilePath/";
    }
    
    echo fnRetrovoxStartHtml("Rename File: the source file is a directory");
    echo "
	  <p>
          The file-name [$sFilePathEncoded] which you just specified is a 
          directory (folder).
        </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 ($sFilePath == $sNewFilePath)
  { 
    echo fnRetrovoxStartHtml(
      "Rename File: the new name is the same as the old");
    echo "
       <p>The two file names which you specified in the rename form were
          the same.
       </p>
       <a  href = \"move-file-form.php?file=$sFilePathEncoded\">
       Please re-enter the file names</a>
       </body>
       </html>";
       exit;
  }

  rename($sFilePath, $sNewFilePath);

  $sWebFilePathEncoded = 
    htmlspecialchars(str_replace($WEBDOCUMENTROOT, "", $sFilePath));

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

<?=fnRetrovoxStartHtml("Retrovox rename file")?>

    <p>The file: <em><?=$sFilePathEncoded?></em>
    <br>was renamed to: <em><?=$sNewFilePathEncoded?></em>
    </p>
    <ol>
    <li><a href = '/manage/admin.php'>
    Go to the Retrovox Administration page</a></li>
    <li>
    <a href = "move-file-form.php?file=<?=urlencode($sFilePathEncoded)?>">
    Rename again</a></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>

                                