<?php

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

  function GetProvider($practiceno, $providerno)
  {
    $login = login('', '', 0);
   
    if ($login)
    {
          $query = "SELECT UNIQUENO, PRACNUM, PRACNAME, TELEPHONE1, FAX, EMAIL, ADD1, ADD2, ADD3, PCODE,  PHYSADD1, PHYSADD2, PHYSADD3, PHYSPCODE,
                    CHIASMA, CONTRACTED, JOINDATE
                    FROM PROVIDER";

          if ($practiceno <> '')          
           $query .= " WHERE PRACNUM = '$practiceno'";
          else
          if ($providerno <> '')          
           $query .= " WHERE UNIQUENO = '$providerno'";

          if($conn = db_connect())
          {  
            $result = ibase_query($conn, $query); 

            if (ibase_errmsg()) 
            {
              $iberror = ibase_errmsg();
              return 'RSP|1|Could not retrieve provider ERROR:'.$iberror.'|E|-1'."\r\n".$query;
            }
            else
            if (!$result) 
            {
              return 'RSP|1|Could not retrieve provider|E|-1';
            }
            
            else
            {
              $row = ibase_fetch_row ($result);

              if (!$row) 
              {
                return 'RSP|2|Provider not found|E|-1';
              }  
              else
              { 	

                $output = "HDR|PROVIDER NO|PRACTICE NO|PRACTICENAME|PHONE1|PHONE2|EMAIL|POSTADDR1|POST_ADDR2|POST_ADDR3|POST_PCODE|PHYS_ADDR1|PHYS_ADDR2|PHYS_ADDR3|PHYS_PCODE|
                           CHIASMA|CONTRACTED|CONTRACT_JOINDATE"."\r\n"; 

             
                $PROVIDERNO   = $row[0];
                $PRACTICENO   = $row[1];
                $PRACNAME     = $row[2];
                $TELEPHONE1   = $row[3];
                $FAX          = $row[4];
                $EMAIL		  = $row[5]; 
                $ADD1		  = $row[6]; 
                $ADD2		  = $row[7]; 
                $ADD3		  = $row[8]; 
                $PCODE 		  = $row[9];  
                $PHYSADD1	  = $row[10]; 
                $PHYSADD2 	  = $row[11]; 
                $PHYSADD3 	  = $row[12]; 
                $PHYSPCODE 	  = $row[13];
                $CHIASMA 	  = $row[14]; 
                $CONTRACTED   = $row[15]; 
                $JOINDATE	  = $row[16];
            
                $output .= 'OUT|'.$PROVIDERNO.'|'.$PRACTICENO.'|'.$PRACNAME.'|'.$TELEPHONE1.'|'.$FAX.'|'.$EMAIL.'|'.$ADD1.'|'.$ADD2.'|'.$ADD3.'|'.$PCODE.'|'.$PHYSADD1.'|'.
                           $PHYSADD2.'|'.$PHYSADD3.'|'.$PHYSPCODE.'|'.$CHIASMA.'|'.$CONTRACTED.'|'.$JOINDATE."\r\n";
              
                return $output;
             }
            }          
          }
    }
  }

  $practiceno =  $_GET['practiceno'];
  $providerno =  $_GET['providerno'];

  $result = GetProvider($practiceno, $providerno);
  echo $result;

 ?>