<?php

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

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

$role_id = $_SESSION['role_id'] ?? 0;

if($role_id == 1)
{

$sliders=mysqli_query($conn,"
SELECT s.*,v.village_name
FROM village_sliders s
LEFT JOIN villages v ON s.village_id=v.id
ORDER BY s.display_order ASC
");

}
else
{

$village_id=$_SESSION['village_id'];

$sliders=mysqli_query($conn,"
SELECT s.*,v.village_name
FROM village_sliders s
LEFT JOIN villages v ON s.village_id=v.id
WHERE s.village_id='$village_id'
ORDER BY s.display_order ASC
");

}

?>

<div class="main">

<div style="display:flex;justify-content:space-between;margin-bottom:20px;">

<h2>Village Sliders</h2>

<a href="add_slider.php" class="btn-success">Add Slider</a>

</div>

<table>

<thead>

<tr>
<th>#</th>
<th>Village</th>
<th>Image</th>
<th>Title</th>
<th>Order</th>
</tr>

</thead>

<tbody>

<?php

$i=1;

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

<tr>

<td><?php echo $i++; ?></td>

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

<td>

<?php if($row['image']){ ?>

<img src="../../uploads/sliders/<?php echo $row['image']; ?>" width="120">

<?php } ?>

</td>

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

</tr>

<?php } ?>

</tbody>

</table>

</div>

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