<?php include("session_controller.php"); ?>
<?php
mysqli_select_db($conn, $database_conn);
$query_accounts = NULL;
if(isset($_GET['search2']) && ($_GET['search2'] != "")){
$query_accounts = "SELECT * FROM accounts WHERE surname LIKE '%".$_GET['search2']. "%' OR firstname LIKE '%".$_GET['search2']. "%' OR middlename LIKE '%".$_GET['search2']. "%'";	
}
else{
$query_accounts = "SELECT * FROM accounts ORDER BY s_no DESC";
}
$accounts = mysqli_query($conn, $query_accounts) or die(mysqli_error($conn));
$row_accounts = mysqli_fetch_assoc($accounts);
$totalRows_accounts = mysqli_num_rows($accounts);

?>
<?php if($totalRows_accounts  > 0){ ?>
<div class="table-responsive">
<table width="100%" class="table table-striped table-bordered"> 
<thead>
    <tr>
      <th width="44">S/N </th><th width="205"> Customer Name </th><th width="150"> Account Nos</th><th width="150">Phone </th> <th width="255"> <i class="glyphicon glyphicon-map-marker"></i> Address</th> <th width="150">Opening Date </th><th width="150">Balance (NGN) </th>
       <?php if(isset($_SESSION['MM_UserGroup']) && ($_SESSION['MM_UserGroup'] == "admin")){?>
      <th width="255"> Add Tranx</th> <th width="200"> History </th>
      <th width="107"><i class="glyphicon glyphicon-pencil"></i> Edit</th><th width="107"><i class="glyphicon glyphicon-remove"></i> Delete</th>
      <?php } ?>
    </tr>
    </thead>
    <tbody>
<?php 
$counter = 0;
$d="active";
do { ?>
    <tr>
      <td><?php echo ++$counter; ?></td>  <td><a href="tranx.php?account_no=<?php echo $row_accounts['account_no']; ?>" title="View Account History"><?php echo $row_accounts['surname']; ?><?php echo " "; ?> <?php echo $row_accounts['firstname']; ?><?php echo " "; ?><?php echo $row_accounts['middlename']; ?></a></td><td><a href="tranx.php?account_no=<?php echo $row_accounts['account_no']; ?>" title="View Account History"> <?php echo $row_accounts['account_no']; ?></a></td><td> <?php echo $row_accounts['phone']; ?></td> 
     
<td><?php echo $row_accounts['address']; ?> </td><td><?php echo date('d/m/Y', strtotime($row_accounts['opening_date'])); ?>   </td>
 <td> <?php echo number_format($row_accounts['balance']); ?></td>
 <?php if(isset($_SESSION['MM_UserGroup']) && ($_SESSION['MM_UserGroup'] == "admin")){?>
 
   <td width="107"><form action="add_tranx.php" method="get"><input name="s_no" value="<?php echo $row_accounts['s_no']; ?>" type="hidden" /> <input name="account_no" value="<?php echo $row_accounts['account_no']; ?>"  type="hidden" /><button type="submit" name="up" class="btn btn-primary" style="width:100%; height:auto;padding-left:10px;padding-left:10px;padding-top:8px;padding-bottom:11px; background-color:#f2f1f3; display:block; border-radius:5px; color:#333"><i class="glyphicon glyphicon-plus"></i></button></form> </td>
   
  <td width="107"><form action="tranx.php" method="get"> <input name="id" value="<?php echo $row_accounts['account_no']; ?>"  type="hidden" /><button type="submit" name="up" class="btn btn-primary" style="width:100%; height:auto;padding-left:10px;padding-left:10px; background-color:#f2f1f3; display:block; border-radius:5px; color:#333">History</button></form> </td>
  
 
	 <td width="107"><form action="edit_account.php" method="get"><input name="s_no" value="<?php echo $row_accounts['s_no']; ?>" type="hidden" /> <input name="account_no" value="<?php echo $row_accounts['account_no']; ?>"  type="hidden" /><button type="submit" name="up" class="btn btn-primary">Update</button></form> </td>
      <td width="107"><form action="delete_account.php" method="get"><input name="account_no" value="<?php echo $row_accounts['account_no']; ?>" type="hidden" /><button type="submit" name="up" class="btn btn-primary" onClick="return check_confirmation();">Delete</button></form> </td>
     <?php } ?>
    </tr>
    <?php 
	if($d == "active"){
    $d = "success";
    }
    else{
    $d ="active";
    }
	?>
  <?php } while ($row_accounts = mysqli_fetch_assoc($accounts)); ?>
  <!-- close query div -->
  </tbody>
 </table>
</div>
<?php } 
else{
?>
<h3> No Matches Found !!! </h3>
<?php } ?>
