<?php

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

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


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

if($role_id == 1)
{

$famous=mysqli_query($conn,"
SELECT fp.*,v.village_name
FROM village_famous_people fp
LEFT JOIN villages v ON fp.village_id=v.id
ORDER BY fp.id DESC
");

}
else
{

$village_id=$_SESSION['village_id'];

$famous=mysqli_query($conn,"
SELECT fp.*,v.village_name
FROM village_famous_people fp
LEFT JOIN villages v ON fp.village_id=v.id
WHERE fp.village_id='$village_id'
ORDER BY fp.id DESC
");

}

?>

<div class="main">

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

<h2>Famous People</h2>

<a href="add_famous_person.php" class="btn-success">Add Famous Person</a>

</div>

<table>

<thead>

<tr>
<th>#</th>
<th>Village</th>
<th>Image</th>
<th>Name</th>
<th>Profession</th>
</tr>

</thead>

<tbody>

<?php

$i=1;

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

<tr>

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

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

<td>
<?php if($row['image']){ ?>
<img src="../../uploads/famous/<?php echo $row['image']; ?>" width="50">
<?php } ?>
</td>

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

</tr>

<?php } ?>

</tbody>

</table>

</div>

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