<?php

include "../../config/master.php";

/* Only Super Admin can access */

allowRoles([1]);

include "../layout/header.php";
include "../layout/sidebar.php";
?>

<div class="main">

<h2>All Users</h2>

<table border="1" width="100%">

<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Role</th>
<th>District</th>
<th>Block</th>
<th>Village</th>
<th>Action</th>
</tr>

<?php

$q=mysqli_query($conn,"
SELECT users.*,roles.role_name,
districts.district_name,
blocks.block_name,
villages.village_name

FROM users

LEFT JOIN roles ON users.role_id=roles.id
LEFT JOIN districts ON users.district_id=districts.id
LEFT JOIN blocks ON users.block_id=blocks.id
LEFT JOIN villages ON users.village_id=villages.id
");

while($row=mysqli_fetch_assoc($q))
{
?>

<tr>

<td><?php echo $row['id']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['role_name']; ?></td>
<td><?php echo $row['district_name']; ?></td>
<td><?php echo $row['block_name']; ?></td>
<td><?php echo $row['village_name']; ?></td>

<td>

<a href="edit_user.php?id=<?php echo $row['id']; ?>" 
style="padding:6px 10px;background:#3498db;color:#fff;text-decoration:none;border-radius:4px;">
Edit
</a>

<?php if($row['role_id']!=1){ ?>

<a href="delete_user.php?id=<?php echo $row['id']; ?>" 
onclick="return confirm('Are you sure you want to delete this user?')" 
style="padding:6px 10px;background:#e74c3c;color:#fff;text-decoration:none;border-radius:4px;">
Delete
</a>

<?php } ?>

</td>

</tr>

<?php
}
?>

</table>

</div>

<?php include "../layout/footer.php"; ?>