<?php

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

/* Allow Super Admin + Village Admin + Operator */
allowRoles([1,5,6]);

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


$query = mysqli_query($conn,"
SELECT s.*, c.caste_name
FROM schemes s
LEFT JOIN caste_master c ON s.category_id = c.id
ORDER BY s.id DESC
");

?>

<div class="main">

<h2>Government Schemes</h2>

<br>

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

<a href="add_scheme.php"
style="background:#2c7be5;color:#fff;padding:8px 15px;border-radius:4px;text-decoration:none;">
+ Add Scheme
</a>

<?php } ?>

<br><br>

<table border="1" width="100%" cellpadding="8" style="border-collapse:collapse;">

<tr style="background:#2c3e50;color:white">

<th>ID</th>
<th>Scheme Title</th>
<th>Category</th>
<th>Department</th>
<th>Status</th>
<th>Action</th>

</tr>

<?php

if(mysqli_num_rows($query) > 0){

while($row=mysqli_fetch_assoc($query)){

?>

<tr>

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

<td><?php echo htmlspecialchars($row['scheme_name']); ?></td>

<td>
<?php
if($row['category_id']==0){
echo "All";
}else{
echo htmlspecialchars($row['caste_name']);
}
?>
</td>

<td><?php echo htmlspecialchars($row['department']); ?></td>

<td>

<?php
if($row['status']==1){
echo "<span style='color:green;'>Active</span>";
}else{
echo "<span style='color:red;'>Disabled</span>";
}
?>

</td>

<td>

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

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

|

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

|

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

<?php } ?>

</td>

</tr>

<?php

}

}else{

echo "<tr><td colspan='6' align='center'>No Schemes Found</td></tr>";

}

?>

</table>

</div>

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