                <?php
//-->-->
//--Description:
//-- This function creates an Html select element which allows the
//-- user to choose from the files and directories in a particular 
//-- directory on the web-server. The function returns a string containing
//-- HTML which when displayed in a web page creates the 'select'.
//-- 
//--Notes: 
//--  This function is very similar to fnSwitchFileSelect but it does
//--  not create an HTML submit button nor a form container for the
//--  select (list box) element, so that it is more suitable for 
//--  more general situations where there is more than one form input 
//--  element.
//--
//--Parameters
//--  $sCurrentDirectory: This parameter is somewhat misnamed, it really
//--  should be called something like $sBaseDirectory or just $sDirectory
//--  it is the directory whose files and directories will be displayed. 
//-- 
//--  $sFormActionUrl: this is the URL which is the 'action' property
//--  for the form element which contains the HTML select element.
//--
//--Used By: document-configure-form.php
//--
  function fnHtmlFileSelect
    ($sCurrentDirectory,
     $sElementName = 'file', 
     $bDisplayDirectories = false)
  {

    $sReturn = "
    <select  name = '$sElementName'>
    <option value=''>-Choose A File-</option>";
    //$sCurrentDirectory = dirname($sFilePath);

      $aaFiles = '';
      $dh  = opendir($sCurrentDirectory);
      while (false !== ($sMemberFileName = readdir($dh)))
      {
        $sCurrentFilePath = "$sCurrentDirectory/$sMemberFileName";
        if (is_dir($sCurrentFilePath))
        {
           if ($sMemberFileName != '.')
           {
              $aaDirectories[] = $sMemberFileName;
           }
        }
        else
        {
           $aaFiles[] = $sMemberFileName;
        }
      } //-- while more files in the directory
       
      sort($aaFiles);
      sort($aaDirectories);
      reset($aaFiles);
      reset($aaDirectories);
      
      $sFileSeparator = '\\';
     
      if ($bDisplayDirectories)
      {
        foreach ($aaDirectories as $sMemberFileName)
        {
          if ($sMemberFileName == '..')
          {
            $sParentDirectory = 
              preg_replace('#[^/]+$#', '', $sCurrentDirectory);
            //$sParentDirectory = basename($sCurrentDirectory);
            $sReturn =  
             $sReturn."<option  value = '".
                htmlspecialchars($sParentDirectory)."'>
            [Parent Directory]</option> ";
          }
          else
          {
             $sMemberFilePathEncoded = 
               htmlspecialchars("$sCurrentDirectory/$sMemberFileName");
             $sReturn = $sReturn."<option  value = '$sMemberFilePathEncoded'>
                   $sMemberFileName/</option> ";
          } //-- 
        } //-- foreach directory
      } //-- if $bDisplayDirectories
      foreach ($aaFiles as $sMemberFileName)
      {
         $sMemberFilePathEncoded = 
             htmlspecialchars("$sCurrentDirectory/$sMemberFileName");
         $sReturn = $sReturn."<option  value = '$sMemberFilePathEncoded'>
            $sMemberFileName</option> ";
      } //-- foreach file

    $sReturn = $sReturn."
      </select>
      ";

     return $sReturn;

   } //-- function: fnHtmlFileSelect


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