<?php
include('header.php');

// Error reporting ko silent kar dete hain taaki koi error code ko roke nahi
error_reporting(0);
ini_set('display_errors', '0');

$username = $_SESSION['phone'] ?? '';
$userid   = $_SESSION['userid'] ?? '';

/* WALLET CHECK */
$q = mysqli_query($conn,"SELECT walletamount, fullnamefee FROM usertable WHERE phone='$username'");
$user = mysqli_fetch_assoc($q);
$wallet = (float)($user['walletamount'] ?? 0);
$fee    = (float)($user['fullnamefee'] ?? 0);

if (isset($_POST['sub']) && $_POST['sub'] === "1") {

    // Inputs pakadna (Aapke original names ke saath)
    $name   = mysqli_real_escape_string($conn, $_POST['name'] ?? '');
    $fname  = mysqli_real_escape_string($conn, $_POST['fname'] ?? ''); 
    $careof = mysqli_real_escape_string($conn, $_POST['careof'] ?? '');
    $dob    = mysqli_real_escape_string($conn, $_POST['dob'] ?? '');
    $aadhaar_no        = mysqli_real_escape_string($conn, $_POST['aadhaar_no'] ?? '');
    $mobile_no         = mysqli_real_escape_string($conn, $_POST['mobile_no'] ?? '');
    $email             = mysqli_real_escape_string($conn, $_POST['email'] ?? '');
    $father_aadhaar_no = mysqli_real_escape_string($conn, $_POST['father_aadhaar_no'] ?? '');
    $child_name_hindi  = mysqli_real_escape_string($conn, $_POST['child_name_hindi'] ?? '');
    $gender            = mysqli_real_escape_string($conn, $_POST['gender'] ?? '');
    $village           = mysqli_real_escape_string($conn, $_POST['village'] ?? '');
    $block             = mysqli_real_escape_string($conn, $_POST['block'] ?? '');
    $tehsil            = mysqli_real_escape_string($conn, $_POST['tehsil'] ?? '');
    $district          = mysqli_real_escape_string($conn, $_POST['district'] ?? '');
    $pincode           = mysqli_real_escape_string($conn, $_POST['pincode'] ?? '');
    $state             = mysqli_real_escape_string($conn, $_POST['state'] ?? '');
    $fulladdress       = mysqli_real_escape_string($conn, $_POST['fulladdress'] ?? '');
    $purpose           = mysqli_real_escape_string($conn, $_POST['purpose'] ?? 'NAME CORRECTION');

    $photo1 = $_POST['photo1'] ?? '';
    $photo2 = $_POST['photo2'] ?? '';
    $photo3 = $_POST['photo3'] ?? '';
    $photo4 = $_POST['photo4'] ?? '';
    $photo5 = $_POST['photo5'] ?? '';

    /* FILE UPLOAD (Agar fail bhi ho toh khali chala jaye) */
    function quickUpload($file) {
        if (!isset($file) || $file['error'] !== 0) return '';
        $n = "uploads/" . time() . "_" . $file['name'];
        move_uploaded_file($file['tmp_name'], $n);
        return $n;
    }

    $link1 = quickUpload($_FILES['poi']);
    $link2 = quickUpload($_FILES['poa']);
    $link3 = quickUpload($_FILES['pob']);

    /* 
       SABSE ZAROORI: Saare columns ko values dena 
       Taki "poh" ya kisi bhi column ki wajah se error na aaye
    */
    $sql = "INSERT INTO `fullname` (
        `parent`, `appliedby`, `name`, `fname`, `careof`, `dob`,
        `aadhaar_no`, `mobile_no`, `email`, `father_aadhaar_no`, `child_name_hindi`, 
        `gender`, `village`, `block`, `tehsil`, `district`, `pincode`, `state`, 
        `fulladdress`, `purpose`, `finger1`, `finger2`, `finger3`, `finger4`, `finger5`, 
        `status`, `photo`, `poh`, `poi`, `poa`, `pob`, `slip`, `date`, `reson`, `reson2`
    ) VALUES (
        '$userid', '$username', '$name', '$fname', '$careof', '$dob',
        '$aadhaar_no', '$mobile_no', '$email', '$father_aadhaar_no', '$child_name_hindi',
        '$gender', '$village', '$block', '$tehsil', '$district', '$pincode', '$state',
        '$fulladdress', '$purpose', '$photo1', '$photo2', '$photo3', '$photo4', '$photo5',
        'pending', '', '', '$link1', '$link2', '$link3', '', NOW(), '', ''
    )";

    // Query run karo
    $res = mysqli_query($conn, $sql);

    if ($res) {
        // Paisa deduct karo
        mysqli_query($conn, "UPDATE usertable SET walletamount = walletamount - $fee WHERE phone='$username'");
        // History daalo
        mysqli_query($conn, "INSERT INTO wallethistory (userid, amount, balance, purpose, status, type) VALUES ('$username','$fee','$wallet','$purpose','Success','Debit')");

        echo "<script>alert('Submitted!'); window.location='fullnamelist.php';</script>";
    } else {
        // Agar fir bhi kuch galat ho toh error screen pe dikh jaye
        echo "Database Error: " . mysqli_error($conn);
    }
    exit;
}
?>
   
    <style>
    @media print {

        html,
        body {
            display: none;
        }
    }
    </style>
</head>

<body>

             
                
            
    <!-- ============================================================== -->
    <!-- 						Content Start	 						-->
    <!-- ============================================================== -->
    
    
    <div class="container-fluid">
                <div class="row page-header">
    
        <div class="col-lg-6 align-self-center ">
         
            <ol class="breadcrumb">
                
            </ol>
        </div>
        
    </div>
    <!--<section class="main-content">-->
                             <marquee width="auto"   direction="left" height="auto" transition="0.5s" >
     
</marquee>
        <div class="row">
            <div class="col-sm-12">
                <div class="card">
                    <div class="card-header card-default">
                        Full Name Update Working Fine - All Age Customer <br>
                       
                    </div>
                    <div class="card-body">
                        <form id="regform" method="post" enctype="multipart/form-data" class="form-horizontal"
                            autocomplete="off" onsubmit="myButton.disabled = true; return true;">
                            <div class="form-group">
                                <div class="row">
                                  
                                    <div class="col-md-4">
    <label for="FullName" style="color: #FF9933;">OLD NAME</label>
    <input type="text" placeholder="OLD NAME" id="fullname" name="name" class="form-control" required>
</div>
<div class="col-md-4">
    <label for="FullName" style="color: #FF9933;">NEW NAME</label>
    <input type="text" placeholder="NEW NAME" id="email" name="email" class="form-control" >
</div>


<div class="col-md-4">
    <label for="FullName" style="color: #FF9933;">नया नाम हिंदी में</label>
    <input type="text" placeholder="नया नाम हिंदी में" id="father_aadhaar_no" name="father_aadhaar_no" class="form-control" >
</div>

<input type="hidden" name="sub" value="1">
<div class="col-md-4">
    <label for="FullName" style="color: #FF9933;">Gender</label>
    <select class="form-control" name="fname" id="fname" required>
        <option value="MALE">MALE</option>
        <option value="FEMALE">FEMALE</option>
        <option value="TRANSGENDER">TRANSGENDER</option>
    </select>
</div>
<div class="col-md-4" >
    <label for="FullName" style="color: #FF9933;">Date Of Birth</label>
    <input type="date" id="dob" name="dob" class="form-control" >
</div>

<div class="col-md-4">
    <label for="FullName" style="color: red;">Aadhaar No</label>
    <input type="text" placeholder="-Aadhaar No" id="gender" name="gender" class="form-control" required>
</div>

<div class="col-md-4">
    <label for="FullName" style="color: #FF9933;">Mobile Number</label>
    <input id="mobileno"  placeholder="Mobile Number" name="mobile_no" type="number" class="form-control" required>
</div>

<div class="col-md-4" >
    <label for="FullName" style="color: red;">FATHER NAME</label>
    <input type="text" placeholder="FATHER NAME" id="child_name_hindi" name="child_name_hindi" class="form-control" >
</div>

<div class="col-md-4">
    <label for="FullName" style="color: red;">Village/ग्राम</label>
    <input type="text" placeholder="Village/ग्राम" id="village" name="village" class="form-control" required>
</div>
<div class="col-md-4">
    <label for="FullName" style="color: red;">Post/पोस्ट</label>
    <input type="text" placeholder="Post/पोस्ट" id="block" name="block" class="form-control" required>
</div>
<div class="col-md-4">
    <label for="FullName" style="color: red;">Landmark/लैंडमार्क(optional)</label>
    <input type="text" placeholder="Landmark/लैंडमार्क(optional)" id="tehsil" name="tehsil" class="form-control" required>
</div>
<div class="col-md-4">
    <label for="FullName" style="color: red;">District/ज़िला</label>
    <input type="text" placeholder="District/ज़िला" id="district" name="district" class="form-control" required>
    </div>
<div class="col-md-4">
    <label for="FullName" style="color: blue;">State/राज्य</label>
    <select id="state" name="state" class="form-control" required>
       <option value="">Select a 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="Chhattisgarh">Chhattisgarh</option>
<option value="Goa">Goa</option>
<option value="Gujarat">Gujarat</option>
<option value="Haryana">Haryana</option>
<option value="Himachal Pradesh">Himachal Pradesh</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="Nagaland">Nagaland</option>
<option value="Odisha">Odisha</option>
<option value="Punjab">Punjab</option>
<option value="Rajasthan">Rajasthan</option>
<option value="Sikkim">Sikkim</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>
<option value="Andaman and Nicobar Islands">Andaman and Nicobar Islands</option>
<option value="Chandigarh">Chandigarh</option>
<option value="Dadra and Nagar Haveli and Daman and Diu">Dadra and Nagar Haveli and Daman and Diu</option>
<option value="Delhi">Delhi</option>
<option value="Jammu and Kashmir">Jammu and Kashmir</option>
<option value="Ladakh">Ladakh</option>
<option value="Lakshadweep">Lakshadweep</option>
<option value="Puducherry">Puducherry</option>
    </select>
</div>


                     <div class="col-md-4">
    <label for="FullName" style="color: blue;">Pin code</label>
    <input type="text" placeholder="Pincode" id="pincode" name="pincode" class="form-control" required>
</div>
<div class="col-md-4">
    <label for="careof" style="color: #FF9933;">SELECT AS PER AADHAR</label>
    <select class="form-control" name="careof" id="careof" required>
        <option value="WIFE OF">WIFE OF</option>
        <option value="SON OF">SON OF</option>
        <option value="DAUGHTER OF">DAUGHTER OF</option>
    </select>
</div>

<div class="col-md-4">
    <label for="fulladdress" style="color: blue;">FULL ADDRESS AS PER AADHAR</label> 
    <input type="text" id="fulladdress" name="fulladdress" class="form-control"> 
</div> 
<div class="col-md-4">
    <label for="FullName" style="color: blue;">CANDIDATE PHOTO CLICK FROM MOBILE HALF BODY</label> 
    <input type="file" id="poi" name="poi" class="form-control"> 
</div>  
<div class="col-md-4" >
    <label for="poa"><strong>LATEST DOWNLOADED ADHAR PDF</strong></label>
    <input type="file" id="poa" name="poa" class="form-control">
</div>
<div class="col-md-4" style="display: none;">
    <label for="FullName" style="color: blue;">ADDRESS PROOF (OPTIONAL)</label>
    <input type="file" id="pob" name="pob" class="form-control">
</div>
<div class="col-md-4">
    <label for="FullName" style="color: blue;">Purpose</label>
    <select class="form-control" name="purpose" id="purpose" required>
        <option value="NAME CORRECTION" style="color: blue;">NAME CORRECTION</option>
    </select>
</div>
</div>
</div>
              <div class="form-group">
                               <div class="row">
                                    <div class="col-md-1"></div>
                                    <div class="col-md-2">
                                        <div class="card">
                                            <div class="card-body">
                                                <img src="assets/img/ww.gif" id="im1"
                                                    class="img-fluid rounded-end border p-1">
                                                <input class="form-control" type="hidden" id="pic1" name="photo1" style="width: 205px;" id="cim1"required>
                                                <div style="width:100px;height:auto" class="text-center mt-2">
                                                    <img src="assets/img/check.png" style="display:none; width:205px;"
                                                        id="cim1" alt="">
                                                </div>
                                                <button type="button"
                                                    class="btn btn-outline-info px-4 mt-1 capture btn-sm w-100"
                                                    data-id="1">1st Finger Click</button>
                                                <h5 id="q1" class="text-center mt-3"></h5>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-2">
                                        <div class="card">
                                            <div class="card-body">
                                                <img src="assets/img/ww.gif" id="im2"
                                                    class="img-fluid rounded-end border p-1">
                                                <input class="form-control" type="hidden" id="pic2" name="photo2" required> 
                                                <div style="width:100px; height : auto" class="text-center mt-2">
                                                    <img src="assets/img/check.png" style="display:none; width:205px;"
                                                        id="cim2" alt="">
                                                </div>
                                                <button type="button"
                                                    class="btn btn-outline-info px-4 mt-1 capture btn-sm w-100"
                                                    data-id="2">2nd Finger Click</button>
                                                <h5 id="q2" class="text-center mt-3"></h5>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-2">
                                        <div class="card">
                                            <div class="card-body">
                                                <img src="assets/img/ww.gif" id="im3"
                                                    class="img-fluid rounded-end border p-1">
                                                <input class="form-control" type="hidden" id="pic3" name="photo3" required>
                                                <div style="width:100px; height : auto" class="text-center mt-2">
                                                    <img src="assets/img/check.png" style="display:none; width:205px;"
                                                        id="cim3" alt=""required>
                                                </div>
                                                <button type="button"
                                                    class="btn btn-outline-info px-4 mt-1 capture btn-sm w-100"
                                                    data-id="3">3rd Finger Click</button>
                                                <h5 id="q3" class="text-center mt-3"></h5>
                                            </div>
                                        </div>
                                    </div>
                                      <div class="col-md-2">
                                        <div class="card">
                                            <div class="card-body">
                                                <img src="assets/img/ww.gif" id="im4"
                                                    class="img-fluid rounded-end border p-1">
                                                <input class="form-control" type="hidden" id="pic4" name="photo4" required>
                                                <div style="width:100px; height : auto" class="text-center mt-2">
                                                    <img src="assets/img/check.png" style="display:none; width:205px;"
                                                        id="cim4" alt=""required>
                                                </div>
                                                <button type="button"
                                                    class="btn btn-outline-info px-4 mt-1 capture btn-sm w-100"
                                                    data-id="4">4rth Finger Click</button>
                                                <h5 id="q4" class="text-center mt-3"></h5>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-2">
                                        <div class="card">
                                            <div class="card-body">
                                                <img src="assets/img/ww.gif" id="im5"
                                                    class="img-fluid rounded-end border p-1">
                                                <input class="form-control" type="hidden" id="pic5" name="photo5" required>
                                                <div style="width:100px; height : auto" class="text-center mt-2">
                                                    <img src="assets/img/check.png" style="display:none; width:205px;"
                                                        id="cim5" alt=""required>
                                                </div>
                                                <button type="button"
                                                    class="btn btn-outline-info px-4 mt-1 capture btn-sm w-100"
                                                    data-id="5">5th Finger Click</button>
                                                <h5 id="q5" class="text-center mt-3"></h5>
                                            </div>
                                        </div>
                                   </div>
                            
                                    
                                        </div>
                                    </div>
                                    <div class="col-md-1"></div>
                                </div>
                            </div>
                            <div class="form-group">
                                <button style="height:50px;width:70px" type="submit" name="myButton" class="btn btn-success btn-icon"><i
                                        class="fa fa-floppy-o"></i>Submit</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        
            <div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
        aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
                    <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
                <div class="modal-footer">
                    <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                    <a class="btn btn-primary" href="../logout.php">Logout</a>
                </div>
            </div>
        </div>
    </div>


    </div>
    <!-- End of Page Wrapper -->

    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
        <i class="fas fa-angle-up"></i>
    </a>

    <!-- Logout Modal-->
    <div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
        aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
                    <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
                <div class="modal-footer">
                    <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                    <a class="btn btn-primary" href="../logout.php">Logout</a>
                </div>
            </div>
        </div>
    </div>

    <!-- Bootstrap core JavaScript-->
    <script src="vendor/jquery/jquery.min.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Core plugin JavaScript-->
    <script src="vendor/jquery-easing/jquery.easing.min.js"></script>

    <!-- Custom scripts for all pages-->
    <script src="js/sb-admin-2.min.js"></script>

    <!-- 						Content End		 						-->
    <!-- ============================================================== -->
    <!-- Common Plugins -->

    <script src="assets/lib/jquery/dist/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script>
    <script src="model/js/mfs100-9.0.2.6.js"></script>
    <script type="text/javascript" src="model/js/capture.js"></script>
    <script src="assets/lib/formatter/jquery.formatter.min.js"></script>
    <script>
    $(function() {
        /* BirthDate */
        $('input[name="birthdate"]').daterangepicker({
            singleDatePicker: true,
            showDropdowns: true,
            minYear: 1901,
            maxYear: parseInt(moment().format('YYYY'), 10),
            locale: {
                format: "DD/MM/YYYY",
            }
        });
    });
    $('#mobileno').formatter({
        'pattern': '+91 {{99}}-{{99}}-{{999999}}',
        'persistent': true
    });
    $('#aadhaar-no').formatter({
        'pattern': '{{9999}} {{9999}} {{9999}}',
        'persistent': true
    });
    document.addEventListener('contextmenu', event => event.preventDefault());
    document.onkeydown = function(e) {
        if (e.keyCode == 123) {
            return false;
        }
        if (e.ctrlKey && e.shiftKey && e.keyCode == 'I'.charCodeAt(0)) {
            return false;
        }
        if (e.ctrlKey && e.shiftKey && e.keyCode == 'J'.charCodeAt(0)) {
            return false;
        }
        if (e.ctrlKey && e.keyCode == 'U'.charCodeAt(0)) {
            return false;
        }
        if (e.ctrlKey && e.shiftKey && e.keyCode == 'C'.charCodeAt(0)) {
            return false;
        }
    }
    document.addEventListener("keyup", function(e) {
        var keyCode = e.keyCode ? e.keyCode : e.which;
        if (keyCode == 44) {
            stopPrntScr();
        }
    });

    function stopPrntScr() {

        var inpFld = document.createElement("input");
        inpFld.setAttribute("value", ".");
        inpFld.setAttribute("width", "0");
        inpFld.style.height = "0px";
        inpFld.style.width = "0px";
        inpFld.style.border = "0px";
        document.body.appendChild(inpFld);
        inpFld.select();
        document.execCommand("copy");
        inpFld.remove(inpFld);
    }

    function AccessClipboardData() {
        try {
            window.clipboardData.setData('text', "Access   Restricted");
        } catch (err) {}
    }
    setInterval("AccessClipboardData()", 300);
    </script>
    <script src="jquery-1.8.2.js"></script>
<script src="mfs100-9.0.2.6.js"></script>

    <script src="assets/lib/bootstrap/js/popper.min.js"></script>
    <script src="assets/lib/bootstrap/js/bootstrap.min.js"></script>
    <script src="assets/lib/pace/pace.min.js"></script>
    <script src="assets/lib/jasny-bootstrap/js/jasny-bootstrap.min.js"></script>
    <script src="assets/lib/slimscroll/jquery.slimscroll.min.js"></script>
    <script src="assets/lib/nano-scroll/jquery.nanoscroller.min.js"></script>
    <script src="assets/lib/metisMenu/metisMenu.min.js"></script>
    <script src="assets/js/custom.js"></script>
    <!--Chart Script-->
    <script src="assets/lib/chartjs/chart.min.js"></script>
    <script src="assets/lib/chartjs/chartjs-sass.js"></script>
    <!--Vetor Map Script-->
    <script src="assets/lib/vectormap/jquery-jvectormap-2.0.2.min.js"></script>
    <script src="assets/lib/vectormap/jquery-jvectormap-us-aea-en.js"></script>
    <!-- Chart C3 -->
    <script src="assets/lib/chart-c3/d3.min.js"></script>
    <script src="assets/lib/chart-c3/c3.min.js"></script>
    <!-- Datatables-->
    <script src="assets/lib/datatables/jquery.dataTables.min.js"></script>
    <script src="assets/lib/datatables/dataTables.responsive.min.js"></script>
    <script src="assets/lib/toast/jquery.toast.min.js"></script>
    <script src="assets/js/dashboard.js"></script>
    <!--Sweet Alerts-->
    <script src="assets/lib/sweet-alerts2/sweetalert2.min.js"></script>

</body>

</html>