                                                                                                                                                                                                                                    <?php
//-->-->-->-->-->-->-->-->-->-->-->-->-->-->
  include "/home/waggacwc/public_html/refurb/RETRO-GLOBALS.php";
  //test1
  include "$LIBRARYPATH/RETROVOX-CONSTANT-VARIABLES.php";
  include "$LIBRARYPATH/fnRetrovoxStartHtml.php";
  include "$LIBRARYPATH/fnStartHtml.php";
  include "$LIBRARYPATH/fnSwitchFileSelect.php";
  include "$LIBRARYPATH/fnNumericHtmlSelect.php";
  include "$LIBRARYPATH/fnDebugArray.php";
  include "$LIBRARYPATH/fnDirectoryListing.php";
  include "$LIBRARYPATH/fnDirectoryTreeHtmlLinkList.php";


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


  //echo realpath('/apache2/ideas/product-data/lib');
  //echo "The realpath of / is ".realpath('/');
  $bNewFile = false;
  $sFilePath = '';
  $sFileContents = '';
  $aaTextLines = '';
  $sWebPathPrefix = '/ideas';
  $bChmodSucceeded = false;  //-- if php can make the file writeable

  $aaTextLines = file($ERRORTEMPLATE);
  $sErrorTemplateContents = implode('', $aaTextLines);

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



  //-- Convert all file path indicators to forward slashes since this is the
  //-- easiest format for PHP to deal with. Otherwise it is necessary to 'escape'
  //-- all the MS Windows backslashes.
  $sFilePath = $_GET['folder'];

  if ($sFilePath == "")
  {
    $sFilePath = $WEBROOT;
  }

  $sFilePath = str_replace('\\', '/', $sFilePath);
  $sFilePath = preg_replace('#[/]+#', '/', $sFilePath);
  
//  if (substr($sFilePath, 0, 1) != "/")
//  {
//    $sFilePath = "/$sFilePath";  
//  }
  
  
  $sFilePathEncoded = htmlspecialchars($sFilePath);
  $sFilePathUrlEncoded = htmlspecialchars(urlencode($sFilePath));
  $sWebFilePathEncoded = htmlspecialchars(str_replace($WEBDOCUMENTROOT, "", $sFilePath));

  $sFileName = basename($sFilePath);
  $sFileNameEncoded = htmlspecialchars($sFileName);
  $sFileNameUrlEncoded = htmlspecialchars(urlencode($sFileName));

  $debug = "";
  if ($debug == "true")
  {
    echo "
      <pre>
      sFilePath=$sFilePath
      sFileName=$sFileName
      sCurrentDirectory=$sCurrentDirectory
      sCurrrentWebDirectory=$sCurrentWebDirectory
      sWebFilePathEncoded=$sWebFilePathEncoded
      </pre>";
    //exit;
  } //--if

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

      $sPageTitle = "Select folder: the root folder doesn't exist";
      $sPageContent = "
          = Select folder: the root folder doesnt exist

       The folder-name $sFilePathEncoded which was specified as the 
       root folder under which to display directories does not exist.

       This probably indicates an error in the page from which 
       you have just come.
       ";

      $sPageContent = fnMessageToHtml($sPageContent);
      $sOutputPage = fnFillWebTemplate(
        $sAdminTemplateContents, $sPageContent, $sPageTitle);   
      echo $sOutputPage;
      exit;
    } //-- if, else web-relative path
  } //-- if file doesn't exist

  if (!is_dir($sFilePath))
  {
    if (substr($sFilePath, -1) != "/")
    {
      $sFilePath = "$sFilePath/";
    }

    $sPageTitle = "choose folder: the path is not a directory";
    $sPageContent = "
          = choose folder: the path is not a directory

       The file-name $sFilePathEncoded which was just specified is not a 
       'directory' or 'folder' on the web-server.

       ";

      $sPageContent = fnMessageToHtml($sPageContent);

      $sOutputPage = fnFillWebTemplate(
        $sAdminTemplateContents, $sPageContent, $sPageTitle);   
      echo $sOutputPage;
      exit;

  } //-- if file is not a directory



  $sPageTitle = "Choose a Folder";
  $sPageContent = "
          = Choose a folder

      You can use this page to choose a folder on the server.

 
       ";

  $sPageContent = fnMessageToHtml($sPageContent);
  $sPageContent = $sPageContent.
    fnDirectoryTreeHtmlLinkList(
       "$WEBROOT",
       "/refurb/manage/notepad/retrovox-notepad.php?file=");

  $sOutputPage = fnFillWebTemplate(
     $sAdminTemplateContents, $sPageContent, $sPageTitle);   
  echo $sOutputPage;
  exit;


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

    