<?php

include "../config/db.php";

$slug = $_GET['village'] ?? '';

$village = mysqli_fetch_assoc(mysqli_query($conn,"
SELECT * FROM villages WHERE slug='$slug'
"));

include "header.php";

?>

<div class="container">

<h2 class="section-title">Government Schemes</h2>

<div class="scheme-list">

<?php

$query = mysqli_query($conn,"
SELECT * FROM schemes
WHERE status=1
ORDER BY id DESC
");

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

?>

<div class="scheme-card">

<div class="scheme-image">

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

<img src="/digital_panchayat/uploads/schemes/<?php echo htmlspecialchars($row['image']); ?>" 
onerror="this.src='/digital_panchayat/assets/no-image.png';">

<?php } else { ?>

<img src="/digital_panchayat/assets/no-image.png">

<?php } ?>

</div>

<div class="scheme-details">

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

<p>
<?php
$desc = strip_tags($row['description']);
$words = explode(" ", $desc);
echo implode(" ", array_slice($words,0,25));
?>...
</p>

<a class="scheme-read"
href="scheme_detail.php?id=<?php echo $row['id']; ?>&village=<?php echo $slug; ?>">
Read More →
</a>

</div>

</div>

<?php } ?>

</div>

</div>

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