                                                                                    

<?php
//-->-->-->-->-->-->-->-->-->-->-->-->-->-->
//--Description:
//--  The purpose of this script is to return the 'source' of a file, and
//--  in particular, PHP files or any other file which would otherwise be
//--  pre-processed by the web-server. This current script is important
//--  because I am envisioning an 'across-the-web' or internet-oriented
//--  system installation proceedure. This proceedure would involve a set-up
//--  or installation script querying another installation for all the 
//--  required files to set up a new installation of this system.
//--
//--  This would involve first obtaining a list of files in each of the 
//--  main areas of the system, such as; library functions, management scripts,
//--  the notepad files, and the webpad files, and also system documentation
//--  and configuration files.
//--
//--  Once these lists were obtained then this 'get-source.php' script would
//--  be able to be employed to serve each of the required files, one at
//--  a time. This proceedure obviates the need to have unzipping software
//--  available on the server, even if this software is quite common.
//--
//--
//--
  include "/home/waggacwc/public_html/refurb/RETRO-GLOBALS.php";

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

  include "$LIBRARYPATH/fnFillWebTemplate.php";
  include "$LIBRARYPATH/fnMessageToHtml.php";
  include "$LIBRARYPATH/fnCodeBlockToHtml.php";
  include "$LIBRARYPATH/fnCodeBlockFromHtml.php";
  include "$LIBRARYPATH/fnListBlockToHtml.php";

  include "$LIBRARYPATH/fnHyperlinkPlainText.php";

  $sWebDocumentRoot = "$WEBROOT";
  $sFilePath = '';

  $sFilePath = stripslashes($_GET['file']);
  $sFilePathEncoded = htmlspecialchars($sFilePath);


  //if (substr($sFilePath, 0, 1) != "c")
  //{
  //  $sFilePath = "/$sFilePath";  
 // }
  
  if (!strstr($sFilePath, $sWebDocumentRoot))
  {
    $sFilePath = $sWebDocumentRoot.$sFilePath;
  }

  $sWebFilePathEncoded = 
    htmlspecialchars(
      str_replace("$sWebDocumentRoot", "", $sFilePath));
  
  if ($sFilePath == '$sWebDocumentRoot')
  {

    $sPageTitle = "no file name specified";
    $sPageContent = "
          = No File Name Specified

      You did not specify any files


      ";

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

    exit; 

  } //-- if no file specified
 
  
  
  if (is_dir($sFilePath))
  {
    if (substr($sFilePath, -1) != "/")
    {
      $sFilePath = "$sFilePath/";
    }
    
    $sPageTitle = "file is a directory";
    $sPageContent = "
          = file is a directory

       file is a directory

      ";

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

    exit; 

  } //-- if file is a directory


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


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

<?=fnRetrovoxStartHtml("View file")?>

    <ul>
    <li>
    <a href = "notepad/retrovox-notepad.php?file=<?=urlencode($sFilePathEncoded)?>">
       Edit <em><?=$sFilePathEncoded?></em></a> (If its a text file)</li>
    <li>
    <a href = "<?=$MANAGEMENTWEBFOLDER?>/admin.php">
    Go to the Retrovox Administration Page</a></li>
    <li>
    <a href = "<?=$MANAGEMENTWEBFOLDER?>/find-file-form.php">
    Find a file on the server</a></li>
    </ul>
    <br>

<?php
//-->-->-->-->-->-->-->-->-->-->-->-->-->-->
  $ii = 0;
  $aaFileLines = file($sFilePath);
  echo "<pre>";
  foreach ($aaFileLines as $sLine)
  {
    echo "$ii: ".htmlspecialchars($sLine);
    $ii++;
  }
  echo "</pre>";
//--<--<--<--<--<--<--<--<--<--<--<--<--<--<
?>

    <ol>
    <li>
    <a href = "<?=$NOTEPADWEBFOLDER?>/retrovox-notepad.php?file=<?=urlencode($sFilePathEncoded)?>">
       Edit <em><?=$sFilePathEncoded?></em></a> (If its a text file)</li>
    </ol>
    <br>
</body>
</html>



                                                                                    