<?php require_once('unibenkgh.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$colname_billings = "-1";
if (isset($_POST['customernum'])) {
  $colname_billings = $_POST['customernum'];
}
mysql_select_db($database_unibenkgh, $unibenkgh);
$query_billings = sprintf("SELECT * FROM bill WHERE customernum = %s", GetSQLValueString($colname_billings, "text"));
$billings = mysql_query($query_billings, $unibenkgh) or die(mysql_error());
$row_billings = mysql_fetch_assoc($billings);
$totalRows_billings = mysql_num_rows($billings);

$colname_customerbill = "-1";
if (isset($_POST['customernum'])) {
  $colname_customerbill = $_POST['customernum'];
}
mysql_select_db($database_unibenkgh, $unibenkgh);
$query_customerbill = sprintf("SELECT accholder FROM ibank WHERE customernum = %s", GetSQLValueString($colname_customerbill, "text"));
$customerbill = mysql_query($query_customerbill, $unibenkgh) or die(mysql_error());
$row_customerbill = mysql_fetch_assoc($customerbill);
$totalRows_customerbill = mysql_num_rows($customerbill);

$colname_billings = "-1";
if (isset($_POST['customernum'])) {
  $colname_billings = $_POST['customernum'];
}
mysql_select_db($database_unibenkgh, $unibenkgh);
$query_billings = sprintf("SELECT * FROM bill WHERE customernum = %s", GetSQLValueString($colname_billings, "text"));
$billings = mysql_query($query_billings, $unibenkgh) or die(mysql_error());
$row_billings = mysql_fetch_assoc($billings);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<h3>View Customer Bill History</h3>
<table width="40%" border="0">
  <tr>
    <td><form id="form1" name="form1" method="post" action="">
      <table width="100%" border="0">
        <tr>
          <td width="40%">Customer Acc Number</td>
          <td width="30%"><label for="customernum"></label>
            <input type="text" name="customernum" id="customernum" /></td>
          <td><input type="submit" name="button" id="button" value="View Bill History" /></td>
        </tr>
      </table>
    </form></td>
  </tr>
</table>
<p>**************************************************************************************************</p>
<table width="68%" border="0">
  <tr>
    <td><form id="form2" name="form2" method="post" action="">
      <table width="85%" border="0">
        <tr bgcolor="#999999">
          <th scope="col">Customer</th>
          <th scope="col">Authentication Code</th>
          <th scope="col">Insurance Code</th>
          <th scope="col">Taxation Code</th>
        </tr>
        <?php do { ?>
          <tr bgcolor="#CCCCCC">
            <td><?php echo $row_customerbill['accholder']; ?></td>
            <td><?php echo $row_billings['acode']; ?></td>
            <td><?php echo $row_billings['icode']; ?></td>
            <td><?php echo $row_billings['tcode']; ?></td>
          </tr>
          <?php } while ($row_billings = mysql_fetch_assoc($billings)); ?>
      </table>
    </form></td>
  </tr>
</table>
<p><strong><a href="index.php">Back to home page</a></strong> ~ <strong><a href="bill1.php">Billing Page</a></strong></p>
<p>**************************************************************************************************</p>
</body>
</html>
<?php
mysql_free_result($billings);

mysql_free_result($customerbill);
?>
