<?php

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

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

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


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

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


/* 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)
VALUES
('$state_id','$district_name')
");

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

exit;

}

}

?>

<div class="main">

<h2>Add District</h2>

<form method="POST" class="form-box">

<label>District Name</label>

<input type="text" name="district_name" placeholder="Enter District Name" required>

<button type="submit" name="add" class="btn-save">
Add District
</button>

</form>

</div>

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