<?php
session_start();
error_reporting(0);
include('../../includes/config.php');
require_once("../../includes/dbcontroller.php");
$db_handle = new DBController();

$role= $_SESSION['role'];
if($role!='Admin'){
	header("location:$website_url/");
	exit();
}
$uid=$_GET['id'];
if((!isset($_GET['id']))){
	header("location:$website_url$listusers_url");
	exit();
}
$user_query="SELECT * FROM users where userid='$uid'";
$user_data = current($db_handle->runQuery($user_query));

if(isset($_POST['delete'])){
	$del_id=$_POST['id'];
	$exist_user_sql="select * from users where userid='$del_id'";
	$count   = $db_handle->numRows($exist_user_sql);
	if($count>0){
		$sql = "DELETE FROM users WHERE userid='$del_id'";
		$result = $db_handle->executeQuery($sql);
		if ($result) {
			echo "<script>alert('User Deleted Succesfully')</script>";
			echo "<script>location.href = '$website_url$listusers_url';</script>";
		}
	}
	else{
		echo "<script>alert('User does Not Exist.')</script>";
		echo "<script>location.href = '$website_url$listusers_url';</script>";
	}
}
include('../../includes/menu.php');
?>


<div class="container main-cont single-delete-user">
	<div class="delete-container">
		<fieldset>
			<div class="page-title">
				<h3> Are you sure you would like to delete the user record(s) below?</h3>
			</div>
			<div class="table-responsive">
				<table class="table table-striped table-hover table-reflow">
					<thead>
						<tr>
							<th>#</th><th>User Email</th><th>Admin</th><th>Active</th><th></th>
						</tr>
					</thead>
					<tbody>
						<tr>
							<td><?php echo $user_data['userid']; ?></td>
							<td><?php echo $user_data['Useremail']; ?></td>
							<td><?php echo ($user_data['Admin'] == 1)? "Yes":"No";?></td>
							<td><?php echo ($user_data['Active'] == 1)? "Yes":"No";?></td>
						</tr>
					</tbody>
				</table>
			</div>
			<form  enctype="multipart/form-data" method="post" accept-charset="utf-8">
				<input type="hidden" name="id" value="<?php echo $user_data['userid']; ?>">
				<a class="btn btn-primary" href="<?php echo $website_url.$listusers_url ?>">Cancel</a>
				<input type="submit" value="Yes" name="delete" class="btn btn-danger">
			</form>    
		</fieldset>
	</div>
</div>



<?php
include('../includes/footer.php');
include('../includes/webfooter.php');
?>