                                                                                        

<?php
//-->-->-->-->-->-->-->-->-->-->-->-->-->-->
//--Description:
//--  The purpose of this script is to display a text file with
//--  line numbers and possibly all 'whitespace' converted into some
//--  kind of visible form. The original motivation for showing line
//--  numbers was to track down php errors which are usually referenced
//--  with a line number. The ability to display visible whitespace
//--  becomes important in the context of debugging problems with 
//--  regular expressions. Often these problems have to do with
//--  what is actually considered to be an end of line character.
//--
//--  

   include_once "/home/waggacwc/public_html/refurb/RETRO-GLOBALS.php";

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

  $sWebDocumentRoot = "/home/waggacwc/public_html";
  $sFilePath = '';

  $sFilePath = stripslashes($_REQUEST['file']);
  $sFilePath = str_replace('\\', '/', $sFilePath);
  $sFilePath = preg_replace('#[/]+#', '/', $sFilePath);

  $sShowWhiteSpace = stripslashes($_REQUEST['space']);

  if ($sShowWhiteSpace == "true")
    { $bShowWhiteSpace = true; }
  else
    { $bShowWhiteSpace = false; }



  $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')
  {
    echo fnRetrovoxStartHtml("View File: no source file name specified");
    echo "
      <p>You did not specify any file to be viewed</p>
      <br>
        <ol>
        <li><a href = '$MANAGEMENTWEBFOLDER/admin.php'>
	   Go to the administration page</a></li>
        <li><a href = '$MANAGEMENTWEBFOLDER/find-file-form.php'>
	   Find a file on the server</a></li>
        </ol>
	  
      </body>
      </html>";
     exit; 
  } //-- if no file specified
 
  
  
  if (is_dir($sFilePath))
  {
    if (substr($sFilePath, -1) != "/")
    {
      $sFilePath = "$sFilePath/";
    }
    
    echo fnRetrovoxStartHtml("View File: the source file is a directory");
    echo "
	  <p>
          The file-name [$sFilePathEncoded] which you just specified is a directory (folder).
          </p>
          <br>
        <ol>
        <li><a href = '$MANAGEMENTWEBFOLDER/admin.php'>
	   Go to the administration page</a></li>
        <li><a href = '$MANAGEMENTWEBFOLDER/find-file-form.php'>
	   Find a file on the server</a></li>
        </ol>
	  <ol>";
	  
      $dh  = opendir($sFilePath);
      while (false !== ($sMemberFileName = readdir($dh)))
      {
        echo "<li><a href ='view-file-lines.php?file=".
	  htmlspecialchars(urlencode($sFilePath.$sMemberFileName))
	  ."'>$sFilePath$sMemberFileName</a></li> \n";
      }
      echo "  
        </ol>
        </body>
        </html>";
      
     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; 
	  
  }


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

<html><body>

    <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)
  {
    $sLine = htmlspecialchars($sLine);

    if ($bShowWhiteSpace)
    {
      //-- replace with a plus/minus sign
      $sLine = str_replace(" ", "&#177;", $sLine);
      //-- replace \n with the paragraph marker
      $sLine = str_replace("\n", "&#182;\n", $sLine);
      //-- replace \r with registered trademark symbol
      $sLine = str_replace("\r", "&#174;\r", $sLine);
    }

    echo "$ii: $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>



                                                                                        