<?php

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

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

/* SEARCH */
$search = $_GET['search'] ?? '';

$where = "WHERE 1";

if($search != ''){
$where .= " AND (
district_name LIKE '%$search%' 
OR district_name_hi LIKE '%$search%'
)";
}

/* DATA */
$query = mysqli_query($conn,"
SELECT * FROM districts
$where
ORDER BY district_name
");

?>

<div class="card-box">
<h4>District List</h4>
</div>

<!-- SEARCH -->
<div class="card-box">

<form method="GET" class="filter-form">

<input type="text" name="search" placeholder="Search District"
value="<?php echo $search; ?>">

<button type="submit" class="btn-mobile btn-save">Search</button>
<a href="district_list.php" class="btn-mobile btn-reset">Reset</a>

</form>

</div>

<!-- LIST -->
<?php while($row=mysqli_fetch_assoc($query)){ ?>

<div class="card-box">

<h5>
<?php 
echo ($row['district_name_hi'] != '') 
? $row['district_name_hi'] 
: $row['district_name']; 
?>
</h5>

<p style="font-size:12px;color:#666;">
(<?php echo $row['district_name']; ?>)
</p>

<div class="action-icons">

<a href="edit_district.php?id=<?php echo $row['id']; ?>" class="icon-btn edit">
<i class="fa fa-pen"></i>
</a>

</div>

</div>

<?php } ?>

<!-- NAV -->
<div class="bottom-nav">
    <a href="../dashboard.php"><i class="fa fa-home"></i>Home</a>
    <a href="../villages/village_data.php"><i class="fa fa-map"></i>Villages</a>
    <a href="../families/view_families.php"><i class="fa fa-users"></i>Families</a>
    <a href="../schemes/view_schemes.php"><i class="fa fa-list"></i>Schemes</a>
</div>

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