<?php
	session_start();
	include('../../includes/config.php');
	require_once("../../includes/dbcontroller.php");
	if(!isset($_SESSION['uid']) && empty($_SESSION['uid'])){
		header("location:$website_url/");
		exit();
	}
	$role= $_SESSION['role'];
	if($role!='Admin'){
		header("location:$website_url/");
		exit();
	}

	$db_handle = new DBController();
	$users_query="SELECT * FROM users";
	$users_data = $db_handle->runQuery($users_query);

	include('../../includes/header.php');
	include('../../includes/menu.php');
?>

<div class="container main-cont"><h2 class="page-title">Users</h2>
     <div class="container">
        <ul class="nav navbar-nav navbar-right">
           <li><a href="<?php echo $website_url.$addusers_url; ?>"><i class="fa fa-plus"></i> Add User</a></li>
        </ul>
    </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>
			<?php foreach ($users_data as $user){ ?>
				<tr>
					<td><?php echo $user['userid']; ?></td>
					<td><?php echo $user['Useremail']; ?></td>
					<td><?php echo ($user['Admin'] == 1)? "Yes":"No";?></td>
					<td><?php echo ($user['Active'] == 1)? "Yes":"No";?></td>
					<td><span class="admin-links"><a href="<?php echo $website_url.$edit_user_url; ?>?id=<?php echo $user['userid']; ?>"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>edit</a> <a href="<?php echo $website_url.$delete_user_url; ?>?id=<?php echo $user['userid']; ?>" class="link delete-link"><i class="fa fa-trash" aria-hidden="true"></i>delete</a> <a href="<?php echo $website_url.$changepassword_url; ?>?id=<?php echo $user['userid']; ?>" class="link password-link"><i class="fa fa-key" aria-hidden="true"></i>Change Password</a></span></td>
				</tr>
			<?php } ?>
			</tbody>
		</table>
	</div> 
</div>
<?php
	include('../../includes/webfooter.php');
	include('../../includes/footer.php');
?>