                                                                                                                                                                                                                                                                                                                                                                                    

<?php
//-->-->-->-->-->-->-->-->-->-->-->-->-->-->
  $sLibraryPath = 'c:\apache2\htdocs\ideas\product-data\lib';
  include "$sLibraryPath\RETROVOX-CONSTANT-VARIABLES.php";
  include "$sLibraryPath\fnRetrovoxStartHtml.php";
  include "$sLibraryPath\fnSwitchFileSelect.php";
  include "$sLibraryPath\fnNumericHtmlSelect.php";
  include "$sLibraryPath\fnDebugArray.php";
  include "$sLibraryPath\fnRetrovoxDirectoryListing.php";


  $bNewFile = false;
  $sFilePath = '';
  $sFileContents = '';
  $aaTextLines = '';
  $sWebPathPrefix = '/ideas';

  $sConfigurationFilePath =
     "c:\\apache2\\htdocs\\ideas\\manage\\notepad\\retrovox-notepad.conf";

  if (file_exists($sConfigurationFilePath))
  {
    $aaEditorSettings = parse_ini_file($sConfigurationFilePath);
    $iEditorFontSize = $aaEditorSettings['editor-font-size'];
    $iEditorColumns = $aaEditorSettings['editor-columns'];
    $iEditorRows = $aaEditorSettings['editor-rows'];
    //fnDebugArray($aaEditorSettings);
  }

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

//  if (substr($sFilePath, 0, 1) != "\\")
//  {
//    $sFilePath = "\\$sFilePath";  
//  }
  
  //if (!strstr($sFilePath, "c:\apache2\htdocs"))
  //{
  //  $sFilePath = "c:\apache2\htdocs".$sFilePath;
 // }
  
  $sFilePathEncoded = htmlspecialchars($sFilePath);
  $sFilePathUrlEncoded = htmlspecialchars(urlencode($sFilePath));
  $sWebFilePathEncoded = htmlspecialchars(str_replace("public_html", "", $sFilePath));

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

  $iEditorColumnsRequest = $_REQUEST['cols'];
  $iEditorRowsRequest = $_REQUEST['rows'];
  $bStripSlashes = $_REQUEST['stripslash'];
  $iEditorFontSizeRequest = $_REQUEST['fontsize'];
  $bSaveConfiguration = $_REQUEST['save'];

  if ($bSaveConfiguration == 'true')
    { $bSaveConfiguration = true; }
  else
    { $bSaveConfiguration = false; } 
  //-- if, else save config settings


  //-- Editor settings set through request variables have
  //-- precedence to those set through the configuration file
  if (!is_numeric($iEditorFontSize))
  { 
    if (is_numeric($iEditorFontSizeRequest))
    {
      $iEditorFontSize = $iEditorFontSizeRequest; 
    }
    else
    {
      $iEditorFontSize = "15"; 
    }
  }
  else
  { 
    if (is_numeric($iEditorFontSizeRequest))
    {
      $iEditorFontSize = $iEditorFontSizeRequest; 
    }
  } //-- if no font size in config file

  if (!is_numeric($iEditorColumns))
  { 
    if (is_numeric($iEditorColumnsRequest))
    {
      $iEditorColumns = $iEditorColumnsRequest; 
    }
    else
    {
      $iEditorColumns = "15"; 
    }
  }
  else
  { 
    if (is_numeric($iEditorColumnsRequest))
    {
      $iEditorColumns = $iEditorColumnsRequest; 
    }
  } //-- if no rows in config file

  if (!is_numeric($iEditorRows))
  { 
    if (is_numeric($iEditorRowsRequest))
    {
      $iEditorRows = $iEditorRowsRequest; 
    }
    else
    {
      $iEditorRows = "15"; 
    }
  }
  else
  { 
    if (is_numeric($iEditorRowsRequest))
    {
      $iEditorRows = $iEditorRowsRequest; 
    }
  } //-- if no rows number in config file



  if ($bSaveConfiguration)
  {
    $sConfigurationData = "\n".
      "editor-font-size=$iEditorFontSize\n".
      "editor-columns=$iEditorColumns\n".
      "editor-rows=$iEditorRows\n";

    $fileHandler = fopen($sConfigurationFilePath, "w");
    fwrite($fileHandler, $sConfigurationData);
    fclose($fileHandler);
  
  } //-- if save settings

  if ($sFilePath == '/usr50/home/retrovox')
  {
    echo fnRetrovoxStartHtml("Retrovox Notepad: no file name specified");
    echo "
	  <p>You did not specify any file to be edited</p>
          <br>
          <a href = 'retrovox-notepad-choose-file.html'>Try Again</a>
      </body>
      </html>";
     //-- is this possible 
     return; 
  } //-- if no file specified
 
  
  
  if (is_dir($sFilePath))
  {
    if (substr($sFilePath, -1) != "/")
    {
      $sFilePath = "$sFilePath/";
    }

    echo fnRetrovoxStartHtml("Retrovox Notepad: the path is a directory");    
    echo "
      <p>
       The file-name<br>
       &nbsp;&nbsp;<em>$sFilePathEncoded</em><br>
       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 = \"retrovox-notepad-choose-file.php?file=$sFilePathUrlEncoded\">
       Re-enter the file name</a></li>
       <li>
       <a href = '/manage/find-file-form.php?file=$sFileNameUrlEncoded'>
       Find a file on the server</a></li>
       <li>Select a file in the directory (<em>$sFilePathEncoded</em>):</li>";
         
       echo fnRetrovoxDirectoryListing($sFilePath);

     echo "    
        </ol>
        </body>
        </html>";
      
     exit;
  } //-- if file is a directory

  if (!file_exists($sFilePath))
  {

    echo fnRetrovoxStartHtml("Retrovox Notepad: the file doesn't exist");    
    echo "
      <p>
       The file-name<br>
       &nbsp;&nbsp;<em>$sFilePathEncoded</em><br>
       which you just specified doesn't exist (folder).
      </p>
       <ol>
        <li>
   <a href = \"retrovox-notepad-choose-file.php?file=$sFilePathUrlEncoded\">
       Re-enter the file name</a></li>
        <li>Select a file in the directory (folder):</li>
          
	  <ol type = '1'>";
      /*
      //-- Not supported in php 4
      //foreach (glob("$sFilePath*") as $sMemberFileName) 
      $aaFiles = '';
      $dh  = opendir($sFilePath);
      while (false !== ($sMemberFileName = readdir($dh)))
      {
         $aaFiles[] = $sMemberFileName;
      }
       
      sort($aaFiles);
      reset($aaFiles);
      
      foreach ($aaFiles as $sMemberFileName)
      {
        echo "<li><a href ='retrovox-notepad.php?file=".
	  htmlspecialchars(urlencode($sFilePath.$sMemberFileName))
	  ."'>$sFilePath$sMemberFileName</a></li> \n";
      }
      */

      echo "  
        </ol>
        </ol>
        </body>
        </html>";
      
     return;
  } //-- if file doesn't exist


  if (!is_writable($sFilePath))
  {
    echo fnRetrovoxStartHtml("Retrovox Notepad: the file is not writable");    
    echo "
	  <p>
          The file-name [$sFilePathEncoded] which you just specified has its permissions
          set so that is cannot be edited (updated or modified in any way).
          You can overcome this problem by typing 
          <pre>
            chmod a+w $sFilePath
          </pre>
          when you are logged into the retrovox server. This sometimes works.
          However, the web-server (Apache) runs as the user 'nobody' which
          seems to cause some permissions headaches. You can also try copying
          the old file to a new one.
          </p>
          <br>
          <ol  type = 'a'>
          <li>
   <a href = \"retrovox-notepad-choose-file.php?file=$sFilePathUrlEncoded\">
           Re-enter the file name</a></li>
          <li>
   <a href = \"/manage/move-file-form.php?file=$sFilePathUrlEncoded\">
           Copy the file</a></li>
          </ol>
           
      </body>
      </html>";
      return; 
  } //-- if file not writeable


   $aaTextLines = file($sFilePath);
   $sFileContents = implode('', $aaTextLines);
   $bNewFile = false;

  if ($bStripSlashes != '')
  {
    $sEditorContents = stripslashes(htmlspecialchars($sFileContents));
  }
  else
  {
    $sEditorContents = htmlspecialchars($sFileContents);
  }    
//--<--<--<--<--<--<--<--<--<--<--<--<--<--<
?>

<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 3.2//EN'>
<html>
 <META HTTP-EQUIV='Content-Type' CONTENT='text/html; CHARSET='iso-8859-1'>
 <META HTTP-EQUIV='Keywords'
          CONTENT='Retrovox, edit, file'>
 <META HTTP-EQUIV='Description'
          CONTENT='Retrovox notepad'>
        <LINK REV='made' HREF='mailto:matth3wbishop@yahoo.com'>

<head><title>Retrovox Notepad</title>
<style>
  TEXTAREA
  {
    background: black;
    font-size: <?=$iEditorFontSize?>pt;
    color: white;
    font-weight: normal;
  }
</style>
</head>
   <body bgcolor='lightgreen'>
<center><big>The Retrovox Notepad</big></center>
<?php
//-->-->-->-->-->-->-->-->-->-->-->-->-->-->
   if ($bSaveConfiguration)
   {
     echo "
        <small><font color ='red'>
        Configuration Settings Saved</font></small><br>
          ";
   }
//--<--<--<--<--<--<--<--<--<--<--<--<--<--<
?>
    
    <form action = 'retrovox-notepad-save-SAFE.php' 
          method = 'post'>
    <input   type = 'submit'  value = 's a v e   f i l e'>
    <a href = '/ideas/manage/move-file-form.php?file=<?=$sFilePath?>'>
    Copy or Rename the Current File</a> | 
    <a href = 'retrovox-notepad-choose-file.php?file=<?=$sFilePathUrlEncoded?>'>
    Select a Different File</a>
    <br>
    Editing file: <em><?= htmlspecialchars($sFilePath) ?></em>
    <br>
    <textarea name = 'fileContents' 
              cols = '<?=$iEditorColumns?>' 
              rows = '<?=$iEditorRows?>'>
    <?= $sEditorContents ?>
    </textarea>
    <br>
    <nobr>
    <input   type = 'submit'  value = 's a v e   f i l e'>
    <input   type = 'hidden'  name = 'saveFilePath'
            value = '<?=htmlspecialchars($sFilePath)?>'>
    <a href = '/ideas/manage/move-file-form.php?file=<?=$sFilePath?>'>
    Copy or Rename the Current File</a> | 
    <a href = 'retrovox-notepad-choose-file.php?file=<?=$sFilePathUrlEncoded?>'>
    Select a Different File</a> |
    <a href = '/ideas/manage/view-file-lines.php?file=<?=$sFilePathUrlEncoded?>'>
    View file with line numbers</a>

    </form>

<?php
//-->-->-->-->-->-->-->-->-->-->-->-->-->-->
  $sCurrentDirectory = dirname($sFilePath);
  echo fnSwitchFileSelect($sCurrentDirectory); 
//--<--<--<--<--<--<--<--<--<--<--<--<--<--<
?>
  <form action = '/ideas/manage/notepad/retrovox-notepad.php'
        method = 'get'>
  <input type = 'hidden'  name = 'file'
        value = '<?=$sFilePathEncoded?>'>
  <input type = 'hidden'  name = 'save'
        value = 'true'>
  <strong>Editor font size:</strong>
  <?= fnNumericHtmlSelect('30', 'fontsize', $iEditorFontSize, 1, 1, '') ?>
  <strong>Editor rows:</strong>
  <?= fnNumericHtmlSelect('45', 'rows', $iEditorRows, 5, 1, '') ?>
  <strong>Editor columns:</strong>
  <?= fnNumericHtmlSelect('100', 'cols', $iEditorColumns, 40, 1, '') ?>
  <input type = 'submit' value = 'Change Editor Settings'>
  </form>
  <a href = '/ideas/manage/add-registration-form.php?file=<?=$sFilePathUrlEncoded?>'>
    Register this file</a>
<?php
?>
    </nobr>
    <br>
</body>
</html>



                                                                                                                                                                                                                                                                                                                                                                        
        
    