<?php

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

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

$id = intval($_GET['id']);

/* FETCH DATA */
$data = mysqli_query($conn,"SELECT * FROM villages WHERE id='$id'");
$row = mysqli_fetch_assoc($data);

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

/* UPDATE */
if(isset($_POST['update']))
{

$village_name     = mysqli_real_escape_string($conn, trim($_POST['village_name']));
$village_name_hi  = mysqli_real_escape_string($conn, trim($_POST['village_name_hi']));
$pincode          = mysqli_real_escape_string($conn, trim($_POST['pincode']));

mysqli_query($conn,"UPDATE villages SET
village_name='$village_name',
village_name_hi='$village_name_hi',
pincode='$pincode'
WHERE id='$id'");

echo "<script>alert('Village Updated Successfully');</script>";
echo "<script>window.location='village_data.php';</script>";

}
?>

<div class="main">

<h2>Edit Village</h2>

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

<label>Village Name (English)</label>
<input type="text" name="village_name"
value="<?php echo htmlspecialchars($row['village_name']); ?>" required>

<label>Village Name (Hindi)</label>
<input type="text" name="village_name_hi"
value="<?php echo htmlspecialchars($row['village_name_hi']); ?>">

<label>Pincode</label>
<input type="text" name="pincode"
value="<?php echo htmlspecialchars($row['pincode']); ?>">

<button name="update" class="btn-save">Update Village</button>

</form>

</div>

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