<? ob_start(); ?>
<?php
  //login_success.php  
 session_start();

	require_once 'dbconfig.php';
	
	if(isset($_GET['delete_id']))
	{
		// select image from db to delete
		$stmt_select = $DB_con->prepare('SELECT userPic FROM tbl_users WHERE id =:uid');
		$stmt_select->execute(array(':uid'=>$_GET['delete_id']));
		$imgRow=$stmt_select->fetch(PDO::FETCH_ASSOC);
		unlink("user_images/".$imgRow['userPic']);
		
		// it will delete an actual record from db
		$stmt_delete = $DB_con->prepare('DELETE FROM tbl_users WHERE id =:uid');
		$stmt_delete->bindParam(':uid',$_GET['delete_id']);
		$stmt_delete->execute();
		
		header("Location: view.php");
	}

?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>View Records</title>
<style>
table.table-bordered.dataTable tbody th, table.table-bordered.dataTable tbody td {
  border-bottom-width: 0;
}
table.table-bordered.dataTable th, table.table-bordered.dataTable td {
  border-left-width: 0;
}
table.dataTable td, table.dataTable th {
  -webkit-box-sizing: content-box;
  box-sizing: content-box;
}
.table-bordered td, .table-bordered th {
  border: 1px solid #dee2e6;
    border-bottom-width: 1px;
    border-left-width: 1px;
}
.table td, .table th {
  padding: .75rem;
  vertical-align: top;
  border-top: 1px solid #dee2e6;
}
table td {
  vertical-align: middle !important;
}
*, ::after, ::before {
  box-sizing: border-box;
}
.table:not(.table-dark) {
  color: inherit;
}
table.dataTable {
  border-collapse: separate !important;
  border-spacing: 0;
}
.table {
  color: #212529;
}
table {
  border-collapse: collapse;
}
.card {
  word-wrap: break-word;
}</style>
<script src='https://kit.fontawesome.com/a076d05399.js' crossorigin='anonymous'></script>
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>

</head>
<body>
<div class="viewsup">
<br><br>
 <?php  
  
 if(isset($_SESSION["username"]))  
 {  
      echo '<h3>Login Success, Welcome - '.$_SESSION["username"].'</h3>';    
 }  
 else  
 {  
      header("location:panel.php");  
 }  
 ?>
	
<div class="topit" style="font-size:22px;" align="center"><a href="dashboard.php">Home</a> | <a href="addnew.php">Add New Account</a>  | <a href="logout.php">Logout</a></div>
<h2 align="center">Account Created</h2>
<div class="card-body">
			<div id="list_wrapper" class="dataTables_wrapper dt-bootstrap4 no-footer">
            <div class="row">
            <div class="col-sm-12">
  <table width="100%" class="table tabe-hover table-bordered" id="list" border="1" style="border-collapse:collapse;">
				<!-- <colgroup>
					<col width="5%">
					<col width="15%">
					<col width="25%">
					<col width="25%">
					<col width="15%">
				</colgroup> -->
				<thead>
					<tr>
                        <th class="text-center">#</th>
						<th>Full Name</th>
						<th>Address</th>
						<th>Account Nos</th>
						<th>Username</th>
                        <th>Password</th>
                        <th>Balance</th>
                        <th>Currency Type</th>
                        <th>Account Type</th>
                        <th>Opening Date</th>
                        <th>Depositor</th>
						<th>Action</th>
</tr>
</thead>
<tbody>


<?php
	$count=1;
	$stmt = $DB_con->prepare('SELECT id, fullname, address, acref, username, password, balance, currencytype, actype, opendate, deposit, userPic FROM tbl_users ORDER BY id DESC');
	$stmt->execute();
	
	if($stmt->rowCount() > 0)
	{
		while($row=$stmt->fetch(PDO::FETCH_ASSOC))
		{
			extract($row);
			?>
             <tr><td align="center"><b> <?php echo $count."</td>
                        <td><b> ".$fullname."</b></td>
						<td><b> ".$address." </b></td>
						<td><b> ".$acref." </b></td>
                        <td><b> ".$username." </b></td>
						<td><b> ".$password."  </b></td>
						<td><b> ".$balance." </b></td>
                        <td><b> ".$currencytype." </b></td>
						<td><b> ".$actype."  </b></td>
						<td><b> ".$opendate." </b></td>
                        <td>".$deposit." </b></td>
          
              
				<td class='text-center'>
		                    <div class='btn-group'>
		                    	<a href='view_acct.php?id= ".$id."' class='btn btn-info btn-flat view_parcel' title='View This Account'>
		                          <i class='fas fa-eye'></i>
		                        </a>
		                       <a href='editform.php?edit_id= ".$id."' class='btn btn-primary btn-flat' title='Edit This Account' onclick='return confirm('sure to edit ?')'><span class='glyphicon glyphicon-edit'></span>
		                          <i class='fas fa-edit'></i>
		                        </a>
		                       <a href='?delete_id=".$id; ?> ' class='btn btn-danger btn-flat delete_parcel' title='Delete This Account'onclick="return confirm('sure to delete ?')"><span class="glyphicon glyphicon-remove-circle"></span>
		                          <i class='fas fa-trash'></i>
		                 </a>
	                      </div>
						</td>
			</tr>
<?php $count++; } ?>
</tbody>
</table>

<br /><br /><br /><br />
</div>
<script>
	$(document).ready(function(){
		$('#list').dataTable()
		$('.view_parcel').click(function(){
			uni_modal("Parcel's Details","view_parcel.php?id="+$(this).attr('data-id'),"large")
		})
	$('.delete_parcel').click(function(){
	_conf("Are you sure to delete this parcel?","delete_parcel",[$(this).attr('data-id')])
	})
	})
	function delete_parcel($id){
		start_load()
		$.ajax({
			url:'ajax.php?action=delete_parcel',
			method:'POST',
			data:{id:$id},
			success:function(resp){
				if(resp==1){
					alert_toast("Data successfully deleted",'success')
					setTimeout(function(){
						location.reload()
					},1500)

				}
			}
		})
	}
</script>      
				<?php
		}
	
	else
	{
		?>
        <div class="col-xs-12">
        	<div class="alert alert-warning">
            	<span class="glyphicon glyphicon-info-sign"></span> &nbsp; No Data Found ...
            </div>
        </div>
        <?php
	}
	
?>
</div>	



<div class="alert alert-info">
    
</div>

</div>


<!-- Latest compiled and minified JavaScript -->
<script src="bootstrap/js/bootstrap.min.js"></script>


</body>
</html>
<? ob_flush(); ?>