<?php
/***
Auth: Vastvikta Nishad
Date: 26 Jan 2024
Description: To create District and Update the exixting District
*/
?><div class="style2-table">
    <div class="style-title">
        <h3>District</h3>
        <div class="row">
            <?php $new_village = base64_encode('new_village');?>
            <div class="col-sm-2" style="text-align: end">
                <a href="admin_index.php?token=<?php echo $new_village;?>" class="button-orange1">New District</a>
            </div>
        </div>
    </div>
    <div id="success"><?php echo $msg; ?></div>
    <form name="frmService" action="" method="post">
        <div class="table" id="SRallview">
            <div class="">
                <div class="div2">
                    <table class="tableview tableview-2" id="admin_table">
                        <thead>
                            <tr class="background">
                                <td align="left" width="5%">S.No.</td>
                                <td align="left">Village Name</td>
                                <td align="left">District Name</td>
                                <td align="left">Created On</td>
                                <td align="left" width="5%">Action</td>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            $result = view_village(); // Call the view_village function

                            if (mysqli_num_rows($result) == 0) {
                                echo '<tr><td colspan="5" align="center" class="contentred">No records found!</td></tr>';
                            } else {
                                $no = 1;
                                while ($res = mysqli_fetch_assoc($result)) {
                                    $new_village = base64_encode('new_village');
                                    $id = base64_encode($res['id']);
                              
                                    ?>
                                    <tr>
                                        <td align="left"><?php echo  $no++ ?></td>
                                        <td align="left"><?php echo  $res['vVillage'] ?></td>
                                        <td align="left">
                                            <?php
                                            $sql = "SELECT city FROM $db.web_city WHERE id='" . $res['iDistrictID'] . "'";
                                            $query = mysqli_query($link, $sql);
                                            $row = mysqli_fetch_assoc($query);
                                            echo $district_name = $row['city'];
                                            ?>
                                        </td>
                                        <td align="left"><?php echo $res['createdon'] ?></td>
                                        <td>
                                        <a href='javascript:void(0)' onclick="window.location.href='admin_index.php?token=<?php echo $new_village ;?>&id=<?= $id ?>';">
                                                <img src="<?=$SiteURL?>public/images/edit-icon.png" border="0" alt="Edit" />
                                            </a>
                                            <a href='javascript:void(0);' data-id="<?php echo $res['id'] ?>" class="village_delete">
                                                <img src="<?php echo$SiteURL?>public/images/delete-icon.png" border="0" alt="delete">
                                            </a>
                                        </td>
                                    </tr>
                                    <?php
                                }
                            }
                            ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <input type="hidden" name="Action" />
        <input type="hidden" name="I_ServiceID" />
    </form>
</div>
