<?php

include "../../config/master.php";
allowRoles([1]);

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

$query = mysqli_query($conn,"
SELECT departments.*, districts.district_name
FROM departments
JOIN districts ON departments.district_id = districts.id
");

?>

<div class="main">

<h2>Departments</h2>

<a href="add_department.php" class="btn-success">Add Department</a>

<table>

<tr>
<th>ID</th>
<th>District</th>
<th>Department</th>
<th>Action</th>
</tr>

<?php while($row=mysqli_fetch_assoc($query)){ ?>

<tr>

<td><?php echo $row['id']; ?></td>

<td><?php echo $row['district_name']; ?></td>

<td><?php echo $row['department_name']; ?></td>

<td>

<a href="edit_department.php?id=<?php echo $row['id']; ?>">Edit</a>

|

<a href="delete_department.php?id=<?php echo $row['id']; ?>"
onclick="return confirm('Delete this department?')">
Delete
</a>

</td>

</tr>

<?php } ?>

</table>

</div>

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