<?php
  include ('include_fns.php');
  
  session_start();


  function PerformBenefitCheck($benefitcheckvalues)
  {
       
       
        $list     = $benefitcheckvalues;
         
        $username = $_SESSION['admin_user'];
        $password = $_SESSION['password'];

       
        try
        {
          if($conn=db_connect())
          {
         
              
            if ($list[0])
            {
             $query = "SELECT NUMBER, SURNAME, DEPNUM, INITIALS, FIRSTNAMES, PHONE1, PHONE2, IDNUMBER, MEDAID, MEDAIDCODE, BIRTHDAY, SEX, JOINDATE
                       FROM PATIENT
                       WHERE SURNAME = '$list[0]' AND IDNUMBER = '$list[2]'  ";
            }

             $result = ibase_query($conn, $query); 
 
            if (!$result) 
            {
              echo ibase_errmsg();
              echo "Could not retrieve Member Information"; 
              echo $query;
              exit; 
            }
            else
            {
               
              $row=ibase_fetch_row ($result);
              if (!$row)
              {
                echo ibase_errmsg();
              }
              else
              {
                return trim($row[0]).','.trim($row[1]).','.trim($row[2]).','.trim($row[3]).','.trim($row[4]).','.trim($row[5]).','.trim($row[6]).','.trim($row[7]).','.trim($row[8]).','.
                  trim($row[9]).','.trim($row[10]).','.trim($row[11]).','.trim($row[12]);
                
              }
            }  
          
           ibase_close($conn);
          }  
        }   
        catch (Exception $e) 
        {
          echo 'Caught exception: ',  $e->getMessage(), "\n";
        }
 
  }
  
    

    if(!check_admin_user())
    {
     echo "You do not seem to be logged in.";
     exit;
    }

    $benefitcheckvalues = array();

    $benefitcheckvalues[0] = $_POST['surname'];
    $benefitcheckvalues[1] = $_POST['membershipno'];
    $benefitcheckvalues[2] = $_POST['idno'];
    
    $memberdetails = PerformBenefitCheck($benefitcheckvalues);
    
    echo $memberdetails;

    exit;

?>
