<?php

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

/* Only Super Admin */
allowRoles([1]);

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

/* HIDE SIDEBAR */
echo "<style>
.sidebar{display:none !important;}
.topbar{margin-left:0 !important;}
.main{margin-left:0 !important;padding-bottom:80px;}
</style>";

if(isset($_POST['add']))
{

$district_name = mysqli_real_escape_string($conn, trim($_POST['district_name']));
$district_name_hi = mysqli_real_escape_string($conn, trim($_POST['district_name_hi']));
$state_id = 1;

/* CHECK DUPLICATE */

$check = mysqli_query($conn,"
SELECT id FROM districts
WHERE LOWER(district_name) = LOWER('$district_name')
");

if(mysqli_num_rows($check) > 0)
{
echo "<script>
alert('District already exists');
window.location='add_district.php';
</script>";
exit;
}
else
{
mysqli_query($conn,"
INSERT INTO districts
(state_id,district_name,district_name_hi)
VALUES
('$state_id','$district_name','$district_name_hi')
");

echo "<script>
alert('District Added Successfully');
window.location='add_district.php';
</script>";
exit;
}

}
?>

<div class="app-content">

<div class="card-box">
<h4>Add District</h4>
<p style="font-size:12px;color:#777;">Create new district</p>
</div>

<div class="card-box">

<form method="POST">

<label>District Name (English)</label>
<input type="text" name="district_name" class="form-control"
placeholder="Enter District Name" required>

<label>District Name (Hindi)</label>
<input type="text" name="district_name_hi" class="form-control"
placeholder="जिले का नाम हिंदी में">

<br>

<button type="submit" name="add" class="btn-mobile"
style="background:#27ae60;color:#fff;">
Add District
</button>

</form>

</div>

</div>

<div class="bottom-nav">
    <a href="../dashboard.php"><i class="fa fa-house"></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"; ?>