<?php

// connect to the mlm database
  function db_connect()
  {
     $ibdir      = $_SESSION['dbpath']; //"c:/local databases/Specworld New/";
     $ibname     = $_SESSION['dbname']; //"H2K.gdb";
     $ibfullname = $ibdir . $ibname;

     $result= ibase_pconnect($ibfullname,'SYSDBA','masterkey');

     if (!$result)
        return false;
     return $result;
  }

  function statementdb_connect()
  {
     $ibdir      = "127.0.0.1:C:/data/Isoleso/statements/";
     $ibname     = "statements.gdb";
     $ibfullname = $ibdir . $ibname;
  
     $result= ibase_pconnect($ibfullname, 'SYSDBA', 'masterkey');//$_SESSION['admin_user'],$_SESSION['password']);

     if (!$result)
        return false;
     return $result;
  }

  function ExecuteQuery($query)
  {
    $list = array();
    
    if($conn=db_connect())
    {
      $result = ibase_query($conn,$query);

      if(!$result)
      {
        echo '<p>Unable to get data from database.</p>';
        echo $query;
        return false;
      }
      else
      {
          $numcol = ibase_num_fields($result);
          $i = 0;
         
          while ($row=ibase_fetch_row ($result))
          {
                        
            for($j=0; $j <$numcol; $j++)
               $list[$i][$j] = $row[$j]; 

            $i++;
          } 
      }
      $result= ibase_close($conn);
    }    
 
    return $list;
  }  


  function fillcombo($query, $compare, $length, $blank = 'F')
  {
    if ($blank == 'T')
     echo '<option value="-1">';
    
    if($conn=db_connect())
    {
      $result = ibase_query($conn,$query);
 
      while ($row=ibase_fetch_row ($result))
      {
       if ($row[0] == $compare)
         echo '<option selected value="'.$row[0].'">'.substr($row[1],0,$length);
       else
         echo '<option value="'.$row[0].'">'.substr($row[1],0,$length);

       echo '</option>';
      }
      $result= ibase_close($conn);
    }             
  }
  
  
  function ibtimeformat($time)
  {
    $newtime = '1899-12-30 '.$time.':00.000';
    
    return $newtime;  
  }
  
?>
