<?php
/***
Auth: Vastvikta Nishad
Date: 25 Jan 2024
Description: To create Province and Update the exixting Province
*/
$msg = '';
$id = isset($_GET['id']) ? (int) base64_decode($_GET['id']) : '';
$villageData = getVillageData($link, $id);
$district = ''; // initialize $district variable
if (!empty($villageData)) {
    $district = $villageData['iDistrictID'];
    $village = $villageData['vVillage'];
    $V_Description = $villageData['V_Description'];
}
?>
<div id="success"><?php echo $msg; ?></div>
<form id="mastersrcat" method="post" action="">
    <input type="hidden" name="pId" id="id" value="<?php echo $id; ?>" />
    <span class="breadcrumb_head" style="height:37px;padding:9px 16px">
        <?php echo (!empty($id) ? "Edit" : "New"); ?> Department
    </span>
    <div class="style2-table">
        <div class="table">
            <table class="tableview tableview-2 main-form">
                <tbody>
                    <?php if ($msg != '') { ?>
                        <tr>
                            <td colspan="2" style="color:#ffffff; width:100%; background:#00CC66; padding:5px; border:1px solid #02944b; text-align:center;">
                                <?php echo $msg ?>
                            </td>
                        </tr>
                    <?php } ?>

                    <tr>
                        <td colspan="2" class="left">
                            <label>Province<em>*</em></label>
                            <div class="log-case">
                                <select name="district" id="district" class="select-styl1">
                                    <option value="" <?php if (empty($district)) echo "selected"; ?>>Select Province</option>
                                    <?php
                                    $result = getDistrict($id);
                                    while ($row = mysqli_fetch_array( $result)) {
                                        $dis_id = $row['id'];
                                        $dis = $row['city'];
                                        $sel = ($dis_id == $district) ? 'selected' : '';
                                    ?>
                                        <option value='<?php echo $dis_id ?>' <?php echo $sel ?>><?php echo $dis ?></option>
                                    <?php } ?>
                                </select>
                            </div>
                        </td>
                    </tr>

                    <tr>
                        <td colspan="2" class="left">
                            <label>District<em>*</em></label>
                            <div class="log-case">
                                <input name="village" id="village" type="text" value="<?php echo $village ?>" class="input-style1">
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" class="left">
                            <label>Description</label>
                            <div class="log-case">
                                <textarea name="V_Description" id="V_Description" cols="" rows="4" class="text-area1"><?php echo $V_Description ?></textarea>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <center>
                            <?php if ($id !== false && $id !== '') { ?>
                                <input name="Update" type="submit" value="Update" class="button-orange1" id="submitclkvillage" style="float: inherit;" />
                            <?php } else { ?>
                                <input name="Submit" type="submit" value="Create" class="button-orange1" id="submitclkvillage" style="float: inherit;" />
                            <?php } ?>
                            </center>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</form>