<?php
  include ('db_fns.php');

  session_start();

  $statementkey = $_GET['statementkey'];

  $conn = statementdb_connect();

  if ($conn)
  {
    $result = ibase_query($conn, "SELECT COUNT(*) FROM STATEMENT WHERE STATEMENT_KEY = $statementkey");
    $row    = ibase_fetch_row ($result);
   
    if ($row[0] == 0)
    {
     echo "<b>Remittance could not be found for key ".$statementkey."</b>";      
    }
    else
    {
      header("Content-Type: application/pdf");

      $result = ibase_query($conn, "SELECT PDF FROM STATEMENT WHERE STATEMENT_KEY = $statementkey");


      $numcol = ibase_num_fields($result);
      $i = 0;
  
      while ($row=ibase_fetch_row ($result))
      {
        $blobby = ibase_blob_open($row[0]);

         while ($blob_stuff = ibase_blob_get($blobby, 100))
           $pdf .= $blob_stuff;

         ibase_blob_close($blobby);
      }

      echo $pdf;

    }
    ibase_close($conn);
  }

?>
