<?php
include('header.php');
$state_submitted = false;
if (isset($_POST['ahkweb']) && $_POST['ahkweb'] == "ahkwebsolutions") {
    $state_submitted = true;
    $state = mysqli_real_escape_string($conn, $_POST['state']);
    mysqli_set_charset($conn,"utf8");

    $sres = mysqli_query($conn, "SELECT * FROM `portal` WHERE state='$state' ");
}


if(isset($_POST['cert_var']) && $_POST['cert_var'] == "ahkweb"){
    $registration_no = "B2025095034700".rand(0000, 9999);
    $name = mysqli_real_escape_string($conn,$_POST['name']);
    $aadhar = mysqli_real_escape_string($conn,$_POST['aadhar']);
    $gender = mysqli_real_escape_string($conn,$_POST['gender']);
    $date_of_birth = mysqli_real_escape_string($conn,$_POST['date_of_birth']);
    $dod_word = mysqli_real_escape_string($conn,$_POST['dod_word']);
    $dod_word1 = mysqli_real_escape_string($conn,$_POST['dod_word1']);
    $dod_word2 = mysqli_real_escape_string($conn,$_POST['dod_word2']);
    $birth_place = mysqli_real_escape_string($conn,$_POST['birth_place']);
    $father_name = mysqli_real_escape_string($conn,$_POST['father_name']);
    $father_aadhar = mysqli_real_escape_string($conn,$_POST['father_aadhar']);
    $mother_name = mysqli_real_escape_string($conn,$_POST['mother_name']);
    $mother_aadhar = mysqli_real_escape_string($conn,$_POST['mother_aadhar']);
    $permanent_address = mysqli_real_escape_string($conn,$_POST['permanent_address']);
    $birth_address = mysqli_real_escape_string($conn,$_POST['birth_address']);
    $register_date = mysqli_real_escape_string($conn,$_POST['register_date']);
    $hospital_id = mysqli_real_escape_string($conn,$_POST['hospital_id']);
    $unitname = mysqli_real_escape_string($conn,$_POST['unitname']);
    $unitcode = mysqli_real_escape_string($conn,$_POST['unitcode']); 
    $state = mysqli_real_escape_string($conn,$_POST['state']);

    date_default_timezone_set("Asia/Kolkata");
    $dateof_issue = date('d-m-Y');
    $dateof_update = date('d-m-Y h:i:s');
    $username = $_SESSION['phone'];
    
    $fee = $ahkweb['birth_fee'];
    $debit_fee = $wallet_amount - $fee;
    if($wallet_amount > $fee){
        mysqli_set_charset($conn,"utf8");
        $ires = mysqli_query($conn,"INSERT INTO `birthmanual`(`name`, `name_local`, `aadharno`, `dob`, `birthTime`, `dodwords`,`dodwords1`,`dodwords2`, `placeofbirth`, `pob_local`, `mname`, `mname_local`, `maadhar`, `fname`, `fname_local`, `faadhar`, `birthaddress`, `tadd_local`, `permanentaddress`, `padd_local`, `regno`, `dateofregister`, `unitname`, `unitcode`, `dateofissue`, `updatedate`, `username`, `gender`, `gender_local`, `state`, `hospital`, `hospital1`, `block`, `block1`, `district`, `district1`) VALUES ('$name','','$aadhar','$date_of_birth','','$dod_word','$dod_word1','$dod_word2','$birth_place','','$mother_name','','$mother_aadhar','$father_name','','$father_aadhar','$birth_address','','$permanent_address','','$registration_no','$register_date','$unitname','$unitcode','$dateof_issue','$dateof_update','$username','$gender','','$state','$hospital_id','','','','','')");
        $debit = mysqli_query($conn,"UPDATE `usertable` SET walletamount='$debit_fee' WHERE phone='$username'");
    
        if($ires){
            ?>
            <script>
                $(function(){
                    Swal.fire('Success', 'Birth Application Submitted Successfully!', 'success')
                });
                window.setTimeout(function(){
                    window.location.href='birthlist.php';
                },1500);
            </script>
            <?php 
        }else{
            $error_msg = mysqli_error($conn);
            ?>
            <script>
                $(function(){
                    Swal.fire('Error', 'Database Error: <?php echo addslashes($error_msg); ?>', 'error')
                });
            </script>
            <?php
        }
    }else{
        ?>
        <script>
            $(function(){
                Swal.fire('Opps', 'Wallet Balance Insufficient ! Please Recharge ', 'error')
            });
            window.setTimeout(function(){
                window.location.href='wallet.php';
            },1500);
        </script>
        <?php
    }
}
?>

<!-- Flatpickr CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/themes/material_blue.css">

<style>
    .content-wrapper {
        display: flex !important;
        justify-content: center !important;
        align-items: flex-start !important;
        padding: 20px !important;
    }
    .payment-form {
        width: 100%;
        max-width: 900px;
        margin: 0 auto;
        background: #fff;
        padding: 30px;
        border-radius: 10px;
        box-shadow: 0 4px 15px rgb(0 0 0 / 15%);
        box-sizing: border-box;
        overflow: hidden;
    }
    .payment-form h2 {
        color: #333;
        margin-bottom: 25px;
        padding-bottom: 15px;
        border-bottom: 2px solid #007bff;
    }
    .payment-form .form-group {
        margin-bottom: 15px;
        display: block !important;
    }
    .payment-form .form-group label {
        font-weight: 600;
        color: #444;
        margin-bottom: 8px;
        display: block !important;
        width: 100% !important;
        float: none !important;
    }
    .payment-form .form-control {
        border-radius: 5px;
        border: 1px solid #ddd;
        padding: 10px 12px;
        width: 100% !important;
        display: block !important;
        float: none !important;
    }
    .payment-form .form-control:focus {
        border-color: #007bff;
        box-shadow: 0 0 5px rgba(0,123,255,0.3);
    }
    .section-title {
        background: linear-gradient(135deg, #007bff, #0056b3);
        color: #fff;
        padding: 10px 15px;
        border-radius: 5px;
        margin: 20px 0 15px 0;
        font-weight: 600;
        clear: both;
    }
    .payment-form .row {
        display: flex !important;
        flex-wrap: wrap !important;
        margin-left: -15px;
        margin-right: -15px;
    }
    .payment-form .col-md-4,
    .payment-form .col-md-6,
    .payment-form .col-md-12 {
        padding-left: 15px;
        padding-right: 15px;
        float: none !important;
    }
    .payment-form .col-md-4 {
        flex: 0 0 33.333333%;
        max-width: 33.333333%;
    }
    .payment-form .col-md-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }
    .payment-form .col-md-12 {
        flex: 0 0 100%;
        max-width: 100%;
    }
    .payment-form .btn-success {
        padding: 12px 30px;
        font-size: 16px;
        font-weight: 600;
    }
    .payment-form .btn-secondary {
        padding: 12px 30px;
        font-size: 16px;
    }
    .payment-form .input-group {
        display: flex !important;
        width: 100%;
        flex-wrap: nowrap !important;
    }
    .payment-form .input-group .form-control {
        flex: 1;
        width: auto !important;
        border-top-right-radius: 0 !important;
        border-bottom-right-radius: 0 !important;
    }
    .payment-form .input-group-append {
        display: flex !important;
        margin-left: -1px;
    }
    .payment-form .input-group-append .input-group-text {
        background-color: #007bff;
        border: 1px solid #007bff;
        color: #fff;
        cursor: pointer;
        padding: 10px 15px;
        border-top-left-radius: 0;
        border-bottom-left-radius: 0;
        border-top-right-radius: 5px;
        border-bottom-right-radius: 5px;
    }
    .payment-form .input-group-append .input-group-text:hover {
        background-color: #0056b3;
        border-color: #0056b3;
    }
    .payment-form .input-group-append .input-group-text i {
        font-size: 16px;
    }
    /* Flatpickr Custom Styling */
    .flatpickr-input {
        background-color: #fff !important;
    }
    .flatpickr-calendar {
        box-shadow: 0 4px 15px rgba(0,0,0,0.2) !important;
        border-radius: 8px !important;
    }
    .date-picker-wrapper {
        position: relative;
        display: flex;
        width: 100%;
    }
    .date-picker-wrapper input {
        flex: 1;
        border-top-right-radius: 0 !important;
        border-bottom-right-radius: 0 !important;
    }
    .date-picker-wrapper .calendar-btn {
        background-color: #007bff;
        border: 1px solid #007bff;
        color: #fff;
        padding: 10px 15px;
        border-top-right-radius: 5px;
        border-bottom-right-radius: 5px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .date-picker-wrapper .calendar-btn:hover {
        background-color: #0056b3;
        border-color: #0056b3;
    }
    .button-group {
        text-align: center;
        margin-top: 30px;
        padding: 20px 0;
        clear: both;
    }
    .button-group .btn {
        display: inline-block;
        margin: 5px 10px;
        min-width: 150px;
        vertical-align: middle;
    }
    @media (max-width: 768px) {
        .payment-form .col-md-4,
        .payment-form .col-md-6 {
            flex: 0 0 100%;
            max-width: 100%;
        }
        .button-group .btn {
            display: block;
            width: 100%;
            margin: 10px 0;
        }
    }
</style>

<div class="payment-form">
    <h2 align="center"><i class="fa fa-baby"></i> Birth Certificate Application (English Only)</h2>
    
    <?php if ($state_submitted == false) { ?>
    <!-- State Selection Form -->
    <form method="post" action="" autocomplete="off" enctype="multipart/form-data">
        <div class="row justify-content-center">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="state">State / राज्य <span class="text-danger">*</span></label>
                    <input type="hidden" name="ahkweb" value="ahkwebsolutions">
                    <select onchange='if(this.value != 0) { this.form.submit(); }' class="form-control" id="state" name="state" required="">
                        <option value="">-- Select State --</option>
                        <option value="Andhra Pradesh">Andhra Pradesh</option>
                        <option value="Arunachal Pradesh">Arunachal Pradesh</option>
                        <option value="Assam">Assam</option>
                        <option value="Bihar">Bihar</option>
                        <option value="Chandigarh">Chandigarh</option>
                        <option value="Chhattisgarh">Chhattisgarh</option>
                        <option value="Delhi">Delhi</option>
                        <option value="Gujarat">Gujarat</option>
                        <option value="Haryana">Haryana</option>
                        <option value="Himachal Pradesh">Himachal Pradesh</option>
                        <option value="Jammu and Kashmir">Jammu and Kashmir</option>
                        <option value="Jharkhand">Jharkhand</option>
                        <option value="Karnataka">Karnataka</option>
                        <option value="Kerala">Kerala</option>
                        <option value="Madhya Pradesh">Madhya Pradesh</option>
                        <option value="Maharashtra">Maharashtra</option>
                        <option value="Manipur">Manipur</option>
                        <option value="Meghalaya">Meghalaya</option>
                        <option value="Mizoram">Mizoram</option>
                        <option value="Sikkim">Sikkim</option>
                        <option value="Nagaland">Nagaland</option>
                        <option value="Odisha">Odisha</option>
                        <option value="Puducherry">Puducherry</option>
                        <option value="Punjab">Punjab</option>
                        <option value="Rajasthan">Rajasthan</option>
                        <option value="Tamil Nadu">Tamil Nadu</option>
                        <option value="Telangana">Telangana</option>
                        <option value="Tripura">Tripura</option>
                        <option value="Uttar Pradesh">Uttar Pradesh</option>
                        <option value="Uttarakhand">Uttarakhand</option>
                        <option value="West Bengal">West Bengal</option>
                    </select>
                </div>
            </div>
        </div>
    </form>
    <?php } ?>

    <?php if ($state_submitted != false) { 
        $unitcode = str_pad(rand(0, 99999), 5, '0', STR_PAD_LEFT); 
    ?>
    <!-- Main Application Form -->
    <form method="post" action="" autocomplete="off" enctype="multipart/form-data">
        <input type="hidden" name="cert_var" value="ahkweb">
        <input type="hidden" name="state" value="<?php echo $state; ?>">
        
        <!-- Personal Details Section -->
        <div class="section-title"><i class="fa fa-user"></i> Personal Details / व्यक्तिगत विवरण</div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="name">नाम / Full Name <span class="text-danger">*</span></label>
                    <input type="text" class="form-control" id="name" name="name" placeholder="FULL NAME" required="" style="text-transform:uppercase">
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label for="aadhar">आधार नंबर / Aadhar Number</label>
                    <input type="text" class="form-control" id="aadhar" name="aadhar" placeholder="AADHAR NUMBER" maxlength="12">
                </div>
            </div>
        </div>
        
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="gender">लिंग / Gender <span class="text-danger">*</span></label>
                    <select class="form-control" id="gender" name="gender" required="">
                        <option value="">-- Select Gender --</option>
                        <option value="Male">MALE</option>
                        <option value="Female">FEMALE</option>
                        <option value="Other">Transgender</option>
                    </select>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label for="date_of_birth">जन्म तिथि / Date of Birth <span class="text-danger">*</span></label>
                    <div class="date-picker-wrapper">
                        <input type="text" class="form-control" id="date_of_birth" name="date_of_birth" placeholder="DD-MM-YYYY" required="" readonly>
                        <span class="calendar-btn" onclick="document.getElementById('date_of_birth')._flatpickr.open()">
                            <i class="fa fa-calendar"></i>
                        </span>
                    </div>
                </div>
            </div>
        </div>

        <!-- DOB Confirmation Section -->
        <div class="section-title"><i class="fa fa-calendar-check"></i> Confirm Date of Birth / जन्म तिथि की पुष्टि करें</div>
        <div class="row">
            <div class="col-md-4">
                <div class="form-group">
                    <label>Day (DD)</label>
                    <select class="form-control" id="dod_word" name="dod_word" required="">
                        <option value="">DD</option>
                        <option value="FIRST">01</option>
                        <option value="SECOND">02</option>
                        <option value="THIRD">03</option>
                        <option value="FOURTH">04</option>
                        <option value="FIFTH">05</option>
                        <option value="SIXTH">06</option>
                        <option value="SEVENTH">07</option>
                        <option value="EIGHTH">08</option>
                        <option value="NINTH">09</option>
                        <option value="TENTH">10</option>
                        <option value="ELEVENTH">11</option>
                        <option value="TWELFTH">12</option>
                        <option value="THIRTEENTH">13</option>
                        <option value="FOURTEENTH">14</option>
                        <option value="FIFTEENTH">15</option>
                        <option value="SIXTEENTH">16</option>
                        <option value="SEVENTEENTH">17</option>
                        <option value="EIGHTEENTH">18</option>
                        <option value="NINETEENTH">19</option>
                        <option value="TWENTIETH">20</option>
                        <option value="TWENTY-FIRST">21</option>
                        <option value="TWENTY-SECOND">22</option>
                        <option value="TWENTY-THIRD">23</option>
                        <option value="TWENTY-FOURTH">24</option>
                        <option value="TWENTY-FIFTH">25</option>
                        <option value="TWENTY-SIXTH">26</option>
                        <option value="TWENTY-SEVENTH">27</option>
                        <option value="TWENTY-EIGHTH">28</option>
                        <option value="TWENTY-NINTH">29</option>
                        <option value="THIRTIETH">30</option>
                        <option value="THIRTY-FIRST">31</option>
                    </select>
                </div>
            </div>
            <div class="col-md-4">
                <div class="form-group">
                    <label>Month (MM)</label>
                    <select class="form-control" id="dod_word1" name="dod_word1" required="">
                        <option value="">MM</option>
                        <option value="JANUARY">01 - JANUARY</option>
                        <option value="FEBRUARY">02 - FEBRUARY</option>
                        <option value="MARCH">03 - MARCH</option>
                        <option value="APRIL">04 - APRIL</option>
                        <option value="MAY">05 - MAY</option>
                        <option value="JUNE">06 - JUNE</option>
                        <option value="JULY">07 - JULY</option>
                        <option value="AUGUST">08 - AUGUST</option>
                        <option value="SEPTEMBER">09 - SEPTEMBER</option>
                        <option value="OCTOBER">10 - OCTOBER</option>
                        <option value="NOVEMBER">11 - NOVEMBER</option>
                        <option value="DECEMBER">12 - DECEMBER</option>
                    </select>
                </div>
            </div>
            <div class="col-md-4">
                <div class="form-group">
                    <label>Year (YYYY)</label>
                    <select class="form-control" id="dod_word2" name="dod_word2" required="">
                        <option value="">YYYY</option>
                        <option value="TWO THOUSAND TWENTY SIX">2026</option>
                        <option value="TWO THOUSAND TWENTY FIVE">2025</option>
                        <option value="TWO THOUSAND TWENTY FOUR">2024</option>
                        <option value="TWO THOUSAND TWENTY THREE">2023</option>
                        <option value="TWO THOUSAND TWENTY TWO">2022</option>
                        <option value="TWO THOUSAND TWENTY ONE">2021</option>
                        <option value="TWO THOUSAND TWENTY">2020</option>
                        <option value="TWO THOUSAND NINETEEN">2019</option>
                        <option value="TWO THOUSAND EIGHTEEN">2018</option>
                        <option value="TWO THOUSAND SEVENTEEN">2017</option>
                        <option value="TWO THOUSAND SIXTEEN">2016</option>
                        <option value="TWO THOUSAND FIFTEEN">2015</option>
                        <option value="TWO THOUSAND FOURTEEN">2014</option>
                        <option value="TWO THOUSAND THIRTEEN">2013</option>
                        <option value="TWO THOUSAND TWELVE">2012</option>
                        <option value="TWO THOUSAND ELEVEN">2011</option>
                        <option value="TWO THOUSAND TEN">2010</option>
                        <option value="TWO THOUSAND NINE">2009</option>
                        <option value="TWO THOUSAND EIGHT">2008</option>
                        <option value="TWO THOUSAND SEVEN">2007</option>
                        <option value="TWO THOUSAND SIX">2006</option>
                        <option value="TWO THOUSAND FIVE">2005</option>
                        <option value="TWO THOUSAND FOUR">2004</option>
                        <option value="TWO THOUSAND THREE">2003</option>
                        <option value="TWO THOUSAND TWO">2002</option>
                        <option value="TWO THOUSAND ONE">2001</option>
                        <option value="TWO THOUSAND">2000</option>
                        <option value="NINETEEN NINETY NINE">1999</option>
                        <option value="NINETEEN NINETY EIGHT">1998</option>
                        <option value="NINETEEN NINETY SEVEN">1997</option>
                        <option value="NINETEEN NINETY SIX">1996</option>
                        <option value="NINETEEN NINETY FIVE">1995</option>
                        <option value="NINETEEN NINETY FOUR">1994</option>
                        <option value="NINETEEN NINETY THREE">1993</option>
                        <option value="NINETEEN NINETY TWO">1992</option>
                        <option value="NINETEEN NINETY ONE">1991</option>
                        <option value="NINETEEN NINETY">1990</option>
                        <option value="NINETEEN EIGHTY NINE">1989</option>
                        <option value="NINETEEN EIGHTY EIGHT">1988</option>
                        <option value="NINETEEN EIGHTY SEVEN">1987</option>
                        <option value="NINETEEN EIGHTY SIX">1986</option>
                        <option value="NINETEEN EIGHTY FIVE">1985</option>
                        <option value="NINETEEN EIGHTY FOUR">1984</option>
                        <option value="NINETEEN EIGHTY THREE">1983</option>
                        <option value="NINETEEN EIGHTY TWO">1982</option>
                        <option value="NINETEEN EIGHTY ONE">1981</option>
                        <option value="NINETEEN EIGHTY">1980</option>
                        <option value="NINETEEN SEVENTY NINE">1979</option>
                        <option value="NINETEEN SEVENTY EIGHT">1978</option>
                        <option value="NINETEEN SEVENTY SEVEN">1977</option>
                        <option value="NINETEEN SEVENTY SIX">1976</option>
                        <option value="NINETEEN SEVENTY FIVE">1975</option>
                        <option value="NINETEEN SEVENTY FOUR">1974</option>
                        <option value="NINETEEN SEVENTY THREE">1973</option>
                        <option value="NINETEEN SEVENTY TWO">1972</option>
                        <option value="NINETEEN SEVENTY ONE">1971</option>
                        <option value="NINETEEN SEVENTY">1970</option>
                        <option value="NINETEEN SIXTY NINE">1969</option>
                        <option value="NINETEEN SIXTY EIGHT">1968</option>
                        <option value="NINETEEN SIXTY SEVEN">1967</option>
                        <option value="NINETEEN SIXTY SIX">1966</option>
                        <option value="NINETEEN SIXTY FIVE">1965</option>
                        <option value="NINETEEN SIXTY FOUR">1964</option>
                        <option value="NINETEEN SIXTY THREE">1963</option>
                        <option value="NINETEEN SIXTY TWO">1962</option>
                        <option value="NINETEEN SIXTY ONE">1961</option>
                        <option value="NINETEEN SIXTY">1960</option>
                        <option value="NINETEEN FIFTY NINE">1959</option>
                        <option value="NINETEEN FIFTY EIGHT">1958</option>
                        <option value="NINETEEN FIFTY SEVEN">1957</option>
                        <option value="NINETEEN FIFTY SIX">1956</option>
                        <option value="NINETEEN FIFTY FIVE">1955</option>
                        <option value="NINETEEN FIFTY FOUR">1954</option>
                        <option value="NINETEEN FIFTY THREE">1953</option>
                        <option value="NINETEEN FIFTY TWO">1952</option>
                        <option value="NINETEEN FIFTY ONE">1951</option>
                        <option value="NINETEEN FIFTY">1950</option>
                        <option value="NINETEEN FORTY NINE">1949</option>
                        <option value="NINETEEN FORTY EIGHT">1948</option>
                        <option value="NINETEEN FORTY SEVEN">1947</option>
                        <option value="NINETEEN FORTY SIX">1946</option>
                        <option value="NINETEEN FORTY FIVE">1945</option>
                        <option value="NINETEEN FORTY FOUR">1944</option>
                        <option value="NINETEEN FORTY THREE">1943</option>
                        <option value="NINETEEN FORTY TWO">1942</option>
                        <option value="NINETEEN FORTY ONE">1941</option>
                        <option value="NINETEEN FORTY">1940</option>
                        <option value="NINETEEN THIRTY NINE">1939</option>
                        <option value="NINETEEN THIRTY EIGHT">1938</option>
                        <option value="NINETEEN THIRTY SEVEN">1937</option>
                        <option value="NINETEEN THIRTY SIX">1936</option>
                        <option value="NINETEEN THIRTY FIVE">1935</option>
                        <option value="NINETEEN THIRTY FOUR">1934</option>
                        <option value="NINETEEN THIRTY THREE">1933</option>
                        <option value="NINETEEN THIRTY TWO">1932</option>
                        <option value="NINETEEN THIRTY ONE">1931</option>
                        <option value="NINETEEN THIRTY">1930</option>
                    </select>
                </div>
            </div>
        </div>

        <!-- Family Details Section -->
        <div class="section-title"><i class="fa fa-users"></i> Family Details / परिवार विवरण</div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="father_name">पिता का नाम / Father Name <span class="text-danger">*</span></label>
                    <input type="text" class="form-control" id="father_name" name="father_name" placeholder="FATHER NAME" required="" style="text-transform:uppercase">
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label for="father_aadhar">पिता आधार नंबर / Father Aadhar</label>
                    <input type="text" class="form-control" id="father_aadhar" name="father_aadhar" placeholder="FATHER AADHAR NUMBER" maxlength="12">
                </div>
            </div>
        </div>
        
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="mother_name">माता का नाम / Mother Name <span class="text-danger">*</span></label>
                    <input type="text" class="form-control" id="mother_name" name="mother_name" placeholder="MOTHER NAME" required="" style="text-transform:uppercase">
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label for="mother_aadhar">माता आधार नंबर / Mother Aadhar</label>
                    <input type="text" class="form-control" id="mother_aadhar" name="mother_aadhar" placeholder="MOTHER AADHAR NUMBER" maxlength="12">
                </div>
            </div>
        </div>

        <!-- Address Section -->
        <div class="section-title"><i class="fa fa-map-marker-alt"></i> Address Details / पता विवरण</div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="birth_place">जन्म स्थान / Place of Birth <span class="text-danger">*</span></label>
                    <input type="text" class="form-control" id="birth_place" name="birth_place" placeholder="PLACE OF BIRTH" required="" style="text-transform:uppercase">
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label for="birth_address">जन्म के समय पता / Address at time of birth <span class="text-danger">*</span></label>
                    <input type="text" class="form-control" id="birth_address" name="birth_address" placeholder="ADDRESS AT TIME OF BIRTH" required="" style="text-transform:uppercase">
                </div>
            </div>
        </div>
        
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="permanent_address">स्थायी पता / Permanent Address <span class="text-danger">*</span></label>
                    <textarea class="form-control" id="permanent_address" name="permanent_address" placeholder="PERMANENT ADDRESS" required="" style="text-transform:uppercase" rows="2"></textarea>
                </div>
            </div>
        </div>

        <!-- Registration Details Section -->
        <div class="section-title"><i class="fa fa-file-alt"></i> Registration Details / पंजीकरण विवरण</div>
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="register_date">पंजीकरण की तिथि / Date of Registration <span class="text-danger">*</span></label>
                    <div class="date-picker-wrapper">
                        <input type="text" class="form-control" id="register_date" name="register_date" placeholder="DD-MM-YYYY" required="" readonly>
                        <span class="calendar-btn" onclick="document.getElementById('register_date')._flatpickr.open()">
                            <i class="fa fa-calendar"></i>
                        </span>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label for="unitname">इकाई का नाम / Unit Name of Registration</label>
                    <input type="text" class="form-control" name="unitname" placeholder="Gram Panchayat" style="text-transform:uppercase">
                </div>
            </div>
        </div>
        
        <div class="row">
            <div class="col-md-6">
                <div class="form-group">
                    <label for="unitcode">इकाई कोड / Unit Code of Registration</label>
                    <input type="text" class="form-control" name="unitcode" placeholder="56983" style="text-transform:uppercase" value="<?php echo $unitcode; ?>">
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label for="hospital_id">Hospital / अस्पताल <span class="text-danger">*</span></label>
                    <select class="form-control" id="hospital_id" name="hospital_id" required="">
                        <option value="">-- Select Hospital --</option>
                        <?php
                        if (mysqli_num_rows($sres) > 0) {
                            while ($sdata = mysqli_fetch_assoc($sres)) {
                        ?>
                            <option value="<?php echo $sdata['hospital']; ?>"><?php echo $sdata['hospital']; ?> - <?php echo $sdata['hospitalnamelocal']; ?></option>
                        <?php
                            }
                        }
                        ?>
                    </select>
                </div>
            </div>
        </div>

        <!-- Submit Buttons -->
        <div class="button-group">
            <button type="submit" name="submit" class="btn btn-success"><i class="fa fa-save"></i> Save Application</button>
            <button type="button" class="btn btn-danger" onclick="window.location.href='birthlist.php';"><i class="fa fa-times"></i> Cancel</button>
        </div>
    </form>
    <?php } ?>
</div>

<!-- Scripts -->
<script src="plugins/jquery/jquery.min.js"></script>
<script src="plugins/jquery-ui/jquery-ui.min.js"></script>
<script>$.widget.bridge('uibutton', $.ui.button)</script>
<script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="plugins/select2/js/select2.full.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/8.11.8/sweetalert2.all.min.js"></script>
<script src="plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>
<script src="dist/js/adminlte.js"></script>

<!-- Flatpickr JS -->
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>

<script>
// Day, Month, Year word mappings
var dayWords = ['', 'FIRST', 'SECOND', 'THIRD', 'FOURTH', 'FIFTH', 'SIXTH', 'SEVENTH', 'EIGHTH', 'NINTH', 'TENTH', 'ELEVENTH', 'TWELFTH', 'THIRTEENTH', 'FOURTEENTH', 'FIFTEENTH', 'SIXTEENTH', 'SEVENTEENTH', 'EIGHTEENTH', 'NINETEENTH', 'TWENTIETH', 'TWENTY-FIRST', 'TWENTY-SECOND', 'TWENTY-THIRD', 'TWENTY-FOURTH', 'TWENTY-FIFTH', 'TWENTY-SIXTH', 'TWENTY-SEVENTH', 'TWENTY-EIGHTH', 'TWENTY-NINTH', 'THIRTIETH', 'THIRTY-FIRST'];
var monthWords = ['', 'JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE', 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER'];
var yearWords = {
    2026: 'TWO THOUSAND TWENTY SIX', 2025: 'TWO THOUSAND TWENTY FIVE', 2024: 'TWO THOUSAND TWENTY FOUR',
    2023: 'TWO THOUSAND TWENTY THREE', 2022: 'TWO THOUSAND TWENTY TWO', 2021: 'TWO THOUSAND TWENTY ONE',
    2020: 'TWO THOUSAND TWENTY', 2019: 'TWO THOUSAND NINETEEN', 2018: 'TWO THOUSAND EIGHTEEN',
    2017: 'TWO THOUSAND SEVENTEEN', 2016: 'TWO THOUSAND SIXTEEN', 2015: 'TWO THOUSAND FIFTEEN',
    2014: 'TWO THOUSAND FOURTEEN', 2013: 'TWO THOUSAND THIRTEEN', 2012: 'TWO THOUSAND TWELVE',
    2011: 'TWO THOUSAND ELEVEN', 2010: 'TWO THOUSAND TEN', 2009: 'TWO THOUSAND NINE',
    2008: 'TWO THOUSAND EIGHT', 2007: 'TWO THOUSAND SEVEN', 2006: 'TWO THOUSAND SIX',
    2005: 'TWO THOUSAND FIVE', 2004: 'TWO THOUSAND FOUR', 2003: 'TWO THOUSAND THREE',
    2002: 'TWO THOUSAND TWO', 2001: 'TWO THOUSAND ONE', 2000: 'TWO THOUSAND',
    1999: 'NINETEEN NINETY NINE', 1998: 'NINETEEN NINETY EIGHT', 1997: 'NINETEEN NINETY SEVEN',
    1996: 'NINETEEN NINETY SIX', 1995: 'NINETEEN NINETY FIVE', 1994: 'NINETEEN NINETY FOUR',
    1993: 'NINETEEN NINETY THREE', 1992: 'NINETEEN NINETY TWO', 1991: 'NINETEEN NINETY ONE',
    1990: 'NINETEEN NINETY', 1989: 'NINETEEN EIGHTY NINE', 1988: 'NINETEEN EIGHTY EIGHT',
    1987: 'NINETEEN EIGHTY SEVEN', 1986: 'NINETEEN EIGHTY SIX', 1985: 'NINETEEN EIGHTY FIVE',
    1984: 'NINETEEN EIGHTY FOUR', 1983: 'NINETEEN EIGHTY THREE', 1982: 'NINETEEN EIGHTY TWO',
    1981: 'NINETEEN EIGHTY ONE', 1980: 'NINETEEN EIGHTY', 1979: 'NINETEEN SEVENTY NINE',
    1978: 'NINETEEN SEVENTY EIGHT', 1977: 'NINETEEN SEVENTY SEVEN', 1976: 'NINETEEN SEVENTY SIX',
    1975: 'NINETEEN SEVENTY FIVE', 1974: 'NINETEEN SEVENTY FOUR', 1973: 'NINETEEN SEVENTY THREE',
    1972: 'NINETEEN SEVENTY TWO', 1971: 'NINETEEN SEVENTY ONE', 1970: 'NINETEEN SEVENTY',
    1969: 'NINETEEN SIXTY NINE', 1968: 'NINETEEN SIXTY EIGHT', 1967: 'NINETEEN SIXTY SEVEN',
    1966: 'NINETEEN SIXTY SIX', 1965: 'NINETEEN SIXTY FIVE', 1964: 'NINETEEN SIXTY FOUR',
    1963: 'NINETEEN SIXTY THREE', 1962: 'NINETEEN SIXTY TWO', 1961: 'NINETEEN SIXTY ONE',
    1960: 'NINETEEN SIXTY', 1959: 'NINETEEN FIFTY NINE', 1958: 'NINETEEN FIFTY EIGHT',
    1957: 'NINETEEN FIFTY SEVEN', 1956: 'NINETEEN FIFTY SIX', 1955: 'NINETEEN FIFTY FIVE',
    1954: 'NINETEEN FIFTY FOUR', 1953: 'NINETEEN FIFTY THREE', 1952: 'NINETEEN FIFTY TWO',
    1951: 'NINETEEN FIFTY ONE', 1950: 'NINETEEN FIFTY'
};

// Initialize Date of Birth picker with Flatpickr
flatpickr('#date_of_birth', {
    dateFormat: 'd-m-Y',
    maxDate: 'today',
    allowInput: false,
    disableMobile: true,
    onChange: function(selectedDates, dateStr, instance) {
        if(selectedDates.length > 0) {
            var date = selectedDates[0];
            var day = date.getDate();
            var month = date.getMonth() + 1;
            var year = date.getFullYear();
            
            $('#dod_word').val(dayWords[day]);
            $('#dod_word1').val(monthWords[month]);
            if(yearWords[year]) {
                $('#dod_word2').val(yearWords[year]);
            }
        }
    }
});

// Initialize Registration Date picker with Flatpickr - Auto select today
flatpickr('#register_date', {
    dateFormat: 'd-m-Y',
    defaultDate: 'today',
    maxDate: 'today',
    allowInput: false,
    disableMobile: true
});
</script>

</body>
</html>
