<?php

/* ==========================
   VILLAGE SLIDERS
========================== */

$sliders = mysqli_query($conn,"
SELECT *
FROM village_sliders
WHERE village_id='$village_id'
ORDER BY display_order ASC
");


/* ==========================
   VILLAGE STATISTICS
========================== */

/* TOTAL FAMILIES */

$fam = mysqli_fetch_assoc(mysqli_query($conn,"
SELECT COUNT(*) as total FROM families
WHERE village_id='$village_id'
"));

$total_families = $fam['total'];


/* TOTAL MEMBERS */

$mem = mysqli_fetch_assoc(mysqli_query($conn,"
SELECT COUNT(*) as total FROM family_members fm
JOIN families f ON f.id = fm.family_id
WHERE f.village_id='$village_id'
"));

$total_members = $mem['total'];


/* POPULATION */

$population = $total_members + $total_families;


/* DEVELOPMENT WORKS */

$total_works = 0;


/* TOTAL SCHEMES */

$schemes = mysqli_fetch_assoc(mysqli_query($conn,"
SELECT COUNT(*) as total FROM schemes
"));

$total_schemes = $schemes['total'];

?>

<div class="container">

<!-- SLIDER + NEWS -->

<div class="top-section">

<div class="slider">

<button class="slider-btn prev" onclick="prevSlide()">&#10094;</button>
<button class="slider-btn next" onclick="nextSlide()">&#10095;</button>

<?php if(mysqli_num_rows($sliders) > 0){ ?>

<div class="slider-container">

<?php 
$first = true;
while($s = mysqli_fetch_assoc($sliders)){ 
?>

<div class="slide <?php echo $first ? 'active' : ''; ?>">

<img src="/digital_panchayat/uploads/sliders/<?php echo $s['image']; ?>" alt="slider">

<?php if($s['title'] || $s['description']){ ?>

<div class="slide-caption">
<h3><?php echo $s['title']; ?></h3>
<p><?php echo $s['description']; ?></p>
</div>

<?php } ?>

</div>

<?php 
$first = false;
} 
?>

</div>

<?php } else { ?>

<div style="padding:20px;text-align:center;">
No Slider Images
</div>

<?php } ?>

</div>


<!-- NEWS SECTION -->

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


</div>


<!-- VILLAGE STATISTICS -->

<!-- VILLAGE STATISTICS -->

<h2 class="section-title">Village Statistics</h2>

<div class="stats">

<div class="stat-box">
<h3><?php echo $total_families; ?></h3>
<p>Families</p>
</div>

<div class="stat-box">
<h3><?php echo $total_members; ?></h3>
<p>Members</p>
</div>

<div class="stat-box">
<h3><?php echo $population; ?></h3>
<p>Population</p>
</div>

<div class="stat-box">
<h3><?php echo $total_works; ?></h3>
<p>Development Works</p>
</div>

<div class="stat-box">
<h3><?php echo $total_schemes; ?></h3>
<p>Schemes</p>
</div>

</div>


<!-- ABOUT VILLAGE -->

<?php include "about_section.php"; ?>
<?php include "sarpanch_list_section.php"; ?>
<?php include "members_section.php"; ?>
<?php include "sarpanch_section.php"; ?>


</div>