<?php
include('../includes/session.php');
include('../includes/config.php');
include('../template/tngweb/header.php');
$fee    = $udata['aadhar_manual'];
checkServiceStatus($udata, 'aadhar_manual_status');
 $wallet_amount = $udata['balance'];

// ------------ AUTO SAVE DATA -----------------
if (isset($_POST['savedataauto'])) {
    $q = "SELECT * FROM users where phone='".$_SESSION['phone']."'";
    $r = mysqli_query($tng_conn,$q);
    $rw = mysqli_fetch_assoc($r);
    if($wallet_amount < $fee) {
    echo "<script src='https://cdn.jsdelivr.net/npm/sweetalert2@11'></script>";
    echo "
    <script>
        Swal.fire({
            title: 'Low Wallet Balance!',
            text: 'Your wallet has ₹$wallet_amount. Fee is ₹$fee. Please recharge.',
            icon: 'warning',
            confirmButtonText: 'OK'
        }).then((result) => {
            if (result.isConfirmed) {
                window.location.href = 'wallet.php';
            }
        });
    </script>
    ";
    exit;
    }
    $aadharno = trim($_POST['aadharno']);
    $name = trim($_POST['name']);
    $fathername = trim($_POST['fathername']);
    $dobadhar = trim($_POST['dobadhar']);
    $birthtithilocal = trim($_POST['birthtithilocal']);
    $gender = strtoupper(trim($_POST['gender']));
    $genderlocal = trim($_POST['genderlocal']);
    $address = trim($_POST['address']);
    $language = trim($_POST['language']);
    $namelocal = trim($_POST['namelocal']);
    $localaddress = trim($_POST['addresslocal']);
    $patalocal = trim($_POST['patalocal']);
    $houseno = trim($_POST['houseno']);
    $street = trim($_POST['street']);
    $pincode = trim($_POST['pincode']);
    $vtcandpost = trim($_POST['vtcandpost']);
    $dist = trim($_POST['dist']);
    $statename = trim($_POST['statename']);
    
    // Process image as base64
    $image_base64 = '';
    if(isset($_FILES["imagefile"]) && $_FILES["imagefile"]["error"] == 0) {
        $image_info = getimagesize($_FILES["imagefile"]["tmp_name"]);
        $image_type = $image_info["mime"];
        $image_data = file_get_contents($_FILES["imagefile"]["tmp_name"]);
        $image_base64 = 'data:' . $image_type . ';base64,' . base64_encode($image_data);
    }
    
    if ($aadharno == "") {
        $msgno = 'Please Enter Aadhar Card No .... ';
    } else if ($rw['aadharpoint'] > $rw['balance']) {
        $msgno = "Sorry, Your Balance is Low .... Please Recharge Soon";
        ?>
        <script>
        setTimeout(function () {
            window.location.href = 'Adhar_manual.php';
        }, 2000);
        </script>
        <?php	
    } elseif ($name == "") {
        $msgno = 'Please Enter Name  .... ';
    } elseif ($fathername == "") {
        $msgno = 'Please Enter Father Name  .... ';
    } elseif ($dobadhar == "") {
        $msgno = 'Please Enter Date of Birth  .... ';
    } elseif ($gender == "") {
        $msgno = 'Please Enter Gender  .... ';
    } elseif ($address == "") {
        $msgno = 'Please Enter Address  .... ';
    } elseif ($language == "") {
        $msgno = 'Please Enter Local Language  .... ';
    } elseif ($namelocal == "") {
        $msgno = 'Please Enter Name in Local Language  .... ';
    } elseif ($localaddress == "") {
        $msgno = 'Please Enter Address in Local Language  .... ';
    } else { 
        $a = mysqli_query($tng_conn, "SELECT aadharno FROM aadharauto WHERE aadharno='".$aadharno."'");
        $b = mysqli_fetch_array($a);
        
        if($b && $b['aadharno'] == $aadharno) {
            $msgno = 'This Aadhar Card No Already Exist .... ';
        } else {
            $st = substr($aadharno, 0, 4);
            $nd = substr($aadharno, 4, 4);
            $rd = substr($aadharno, 8, 4);
            $adhrno = $st.' '.$nd.' '.$rd;
            
            $sex = ($gender == 'Male') ? 'M' : 'F';
            
            // Get next serial number
            $resultm = mysqli_query($tng_conn, "SELECT srno FROM aadharauto ORDER BY srno DESC LIMIT 1");
            $num_rows = mysqli_fetch_array($resultm);
            $srno = $num_rows['srno'] + 1;
            
            // Insert Query
            $query = "INSERT INTO `aadharauto`
                (`aadharno`, `originalaadharno`, `aadharname`, `fathername`, `dob`, `gender`, `sexinlocal`, `fulladdress`,
                `locallanguage`, `localname`, `localaddress`, `imagepathoriginal`, `dobinlocal`, `pata`, `houseno`, `street`, `vtcandpost`, 
                `dist`, `statename`, `pincode`, `srno`, `userid`, `createdatetime`) 
                VALUES (
                '" . mysqli_real_escape_string($tng_conn, $aadharno) . "',
                '" . mysqli_real_escape_string($tng_conn, $adhrno) . "',
                '" . mysqli_real_escape_string($tng_conn, $name) . "',
                '" . mysqli_real_escape_string($tng_conn, $fathername) . "',
                '" . mysqli_real_escape_string($tng_conn, $dobadhar) . "',
                '" . mysqli_real_escape_string($tng_conn, $gender) . "',
                N'" . mysqli_real_escape_string($tng_conn, $genderlocal) . "',
                '" . mysqli_real_escape_string($tng_conn, $address) . "',
                '" . mysqli_real_escape_string($tng_conn, $language) . "',
                N'" . mysqli_real_escape_string($tng_conn, $namelocal) . "',
                N'" . mysqli_real_escape_string($tng_conn, $localaddress) . "',
                '" . mysqli_real_escape_string($tng_conn, $image_base64) . "',
                N'" . mysqli_real_escape_string($tng_conn, $birthtithilocal) . "',
                N'" . mysqli_real_escape_string($tng_conn, $patalocal) . "',
                '" . mysqli_real_escape_string($tng_conn, $houseno) . "',
                '" . mysqli_real_escape_string($tng_conn, $street) . "',
                '" . mysqli_real_escape_string($tng_conn, $vtcandpost) . "',
                '" . mysqli_real_escape_string($tng_conn, $dist) . "',
                '" . mysqli_real_escape_string($tng_conn, $statename) . "',
                '" . mysqli_real_escape_string($tng_conn, $pincode) . "',
                '$srno',
                '" . mysqli_real_escape_string($tng_conn, $_SESSION['phone']) . "',
                NOW()
                )";
            
            $result = mysqli_query($tng_conn, $query);
            
            if ($result) {
                $debit_fee = $udata['balance'] - $fee;
                $parentPhone = $udata['parent'] ?? null;
                $appliedby = $udata['phone'] ?? null;
        addCommission($tng_conn, $appliedby, $fee, $parentPhone, "Aadhar Manual Verification");
                $debit = mysqli_query($tng_conn, "UPDATE users SET balance=balance-$fee WHERE phone='{$_SESSION['phone']}'");
                $updatehistory = mysqli_query($tng_conn, "INSERT INTO `wallethistory`(`userid`, `amount`, `balance`, `purpose`, `status`, `type`) VALUES ('{$_SESSION['phone']}','$fee','$debit_fee','Aadhar Manual  print','1','Debit')");
       
                $msg = "Please Wait Aadhar Preview just a second...";
                $_SESSION["IMGPATH"] = '';
                $_SESSION["AADHAARNO"] = trim($aadharno);
                
               
                
                ?>
                <script>
                    $(function(){
                        Swal.fire(
                            'Application Submitted Success',
                            '',
                            'success'
                        )
                    })
                    setTimeout(() => {
                        window.location='aadhar_advance_list.php';
                    }, 1500);
                </script>
                <?php
            } else {
                $msgno = "Error saving data: " . mysqli_error($tng_conn);
            }
        }
    }
}
?>
     	<!--start page wrapper -->
		<div class="page-wrapper">
			<div class="page-content">

				<div class="row">
					<div class="col-xl-10 mx-auto">
					    <div class="mb-4">
        <a href="javascript:history.back()" class="back-btn">
            <i class="bi bi-arrow-left-circle"></i> Go Back
        </a>
    </div>
						<h6 class="mb-0 text-uppercase">Aadhar Manaual Print</h6>
						<hr/>
						<div class="card border-top border-0 border-4 border-primary">
							<div class="card-body p-5">
								<div class="card-title d-flex align-items-center">
									<div><i class="bx bxs-id-card me-1 font-22 text-primary"></i>
									</div>
									  <strong><i class="fa fa-warning"></i></strong> <marquee><p style="font-family: Impact; font-size: 18pt">कृपया ध्यान दें -: ✔  ADHAR MANUAL PRINT सिर्फ आपको EMERGENCY काम में ही यूज करे ।  कोई गलत काम में यूज न करें</p></marquee>
</h5>
								</div>
								<hr>

            
            
							
				
								<?php if($msg !='') { ?>
									<div style="width=100%"  class="row cvmsgok"><?php echo $msg; ?></div>
								<?php } elseif($msgno !='') { ?>
									<div style="width=100%"  class="row cvmsgno"><?php echo $msgno; ?></div>
								<?php  } ?>
						
								<form method="post" autocomplete="off"  onSubmit="return validation();"   enctype="multipart/form-data" action="" style="width:100%">
									<div class="row dgnform">
                                        <div class="col-sm-9">
                                                <div class="row">
                                                    <div class="col-sm-4">
                                                        <label>Aadhar Card No.</label>
                                                        <div class="form-group">
                                                            <input class="form-control " value=""  id="aadharno" placeholder="Aadharcard No..." autocomplete="off" name="aadharno" type="text" maxlength="12" required value="<?php echo $aadharno; ?>">
                                                            <span id="erroraadharno" class="error"></span>
                                                        </div>
                                                    </div>
                                                    <div class="col-sm-4">
                                                        <label>Name</label>
                                                        <div class="form-group">
                                                            <input class="form-control " value="" id="name" placeholder="Example : Raju Kumar" name="name" type="text" required value="<?php echo $txtnm; ?>">
														</div>
                                                    </div>
                                                    <div class="col-sm-4">
                                                        <label>Father Name </label>
                                                        <div class="form-group">

                                                            <input class="form-control" name="fathername" id="fathername" placeholder="Example : Shyam Singh" Value="" type="text" value="<?php echo $txtfnm; ?>" oninput="setaddress()">
                                                        </div>
                                                    </div>
													

													
                                                </div>
												<div class="row">
												<div class="col-md-4">
												 <label>House No</label>
												 <input class="form-control" name="houseno" id="houseno" type="text" oninput="setaddress()" required="" placeholder="House No">
												</div>
												<div class="col-md-4">
												<label>Gali,Locality</label>
												<input class="form-control" name="streetlocality" id="streetlocality" oninput="setaddress()" type="text" required="" placeholder="Gali, Locality, Panchayat">
												</div>
												<div class="col-md-4">
												<label>Post Office</label>
												<input class="form-control" name="vtcandpost" id="vtcandpost" type="text" oninput="setaddress()" required="" placeholder="Post Office">
												</div>
												<div class="col-md-4">
												<label>State</label>
												<input class="form-control" name="state" id="state" type="text" oninput="setaddress()" required="" placeholder="State">
												</div>
												<div class="col-md-4">
												<label>City</label>
												<input class="form-control" name="city" id="city" type="text" oninput="setaddress()" required="" placeholder="City">
												</div>
												<div class="col-md-4">
												<label>Pin code</label>
												<input class="form-control" name="pincode" id="pincode" type="text" maxlength="7"oninput="setaddress()" required="" placeholder="pincode">
												</div>
												</div>
												
                                                <div class="row">
                                                    <div class="col-sm-4">
                                                        <label>Date Of Birth</label>
                                                        <div class="form-group">
                                                            <input class="form-control " name="dobadhar"  type="text" value="26/07/1992" required placeholder="D.O.B.(dd/MM/yyyy)" value="<?php echo $txtdob; ?>">
                                                            <input class="form-control " name="houseno"  type="hidden" value="<?php echo $txtbuld; ?>">
                                                            <input class="form-control " name="street"  type="hidden" value="<?php echo $txtlocality; ?>">
                                                            <input class="form-control " name="pincode"  type="hidden" value="<?php echo $txtpincode; ?>">
                                                            <input class="form-control " name="vtcandpost"  type="hidden" value="<?php echo $txtpost; ?>">
                                                            <input class="form-control " name="dist"  type="hidden" value="<?php echo $txtdistrict; ?>">
                                                            <input class="form-control " name="statename"  type="hidden" value="<?php echo $txtstate; ?>">
															<input class="form-control " id="birthtithi" name="birthtithi"  type="hidden" value="Birth Tithi">
                                                            
                                                           
                                                        </div>
                                                    </div>
													<div class="col-sm-4">
													<label>Date Of Birth Local</label>
													<input class="form-control " id="birthtithilocal" name="birthtithilocal" placeholder="Auto Fill"  type="text" value="">
                                                    </div></br>
													
                                                    <div class="col-md-4 col-sm-4 col-xs-6">
                                                    <label>Select Gender</label>
                                                    <div class="form-group">
                                                        <select class="form-control" name="gender" id="gender" required>
                                                            <option value="">GENDER</option>
                                                            <option value="Male" name="gender" id="gender" >Male</option>
                                                            <option value="Female" name="gender" id="gender" >Female</option>
                                                        </select>   
                                                    </div>
                                                    </div>
													<div class="col-sm-4">
													<label>Gender Local</label>
													<input class="form-control " id="genderlocal" name="genderlocal"  type="text" value="">
													</div>
													

                                                    <input class="form-control " id="pata" name="pata" readonly="readonly" type="hidden" value="address">
                                                    <input class="form-control " id="patalocal" name="patalocal" readonly="readonly" type="hidden" value="">
                                                        </div>
                                                    </div>
													
                                                    <div class="col-sm-7">
                                                        <label>Address  </label>
                                                        <div class="form-group">
                                                            <textarea class="form-control"  placeholder="S/O : Mo Rahim,  khurdaha, Jakhauli, Faizabad, Uttar Pradesh, 878987"  style="height:55px" id="txtSource" name="address" rows="10" type="text"  ><?php echo $txtadd; ?></textarea> 
                                                            <span id="errortxtSource" class="error"></span>
                                                        </div>
                                                  </div>
                                        <div class="col-sm-3">
                                            <label>Select Image  </label>
                                            <div class="form-group">
											  <input type="file" name="imagefile" class="form-control" id="imgInp" accept="image/x-png,image/jpg,image/jpeg" required />
                                                 <img src="" id="blah" width="100px" height="100px" style="display: none;">
                                            </div>
                                        </div>
                                        <div class="col-sm-12">
                                            <div class="row">
                                                <div class="col-sm-3">
                                                    <label>Select Local Language</label>
                                                    <div class="form-group">
                                                        <select class="form-control"  onchange="changelang()" name="language" id="language" required>
                                                            <option value="">SELECT  </option>
                                                             <option value="HI">Hindi   </option>
                                                             <option value="PA">Punjabi </option>
                                                             <option value="GU">Gujarati</option>
                                                             <option value="MR">Marathi </option>
                                                             <option value="TA">Tamil   </option>
                                                             <option value="KN">Kannada </option>
                                                             <option value="BN">Bengali </option>
                                                             <option value="TE">Telugu  </option>
                                                             <option value="OR">Oriya   </option>
                                                             <option value="SD">Sindhi  </option>
                                                        </select>  
                                                        <span id="errorlanguage" class="error"></span>
                                                    </div>
                                                </div>
                                                <div class="col-sm-3">
                                                    <label>Name (Local Language) </label>
                                                    <div class="form-group">
                                                        <input class="form-control" id="name_regional"  name="namelocal" type="text" value="">
                                                        <span id="errorname_regional" class="error"></span>
                                                    </div>
                                                </div>
                                                <div class="col-sm-6">
                                                    <label>Address (Local Language)  </label>
                                                    <div class="form-group">
                                                        <textarea class="form-control" id="txtTarget"   style="height:55px" name="addresslocal" rows="10" type="text" ></textarea>
                                                        <span id="errortxtTarget" class="error"></span>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="col-12 ml-2">
								          	<h5 class="text-warning ">Application Fee: <?php  
								          		echo "₹" .$fee;
								          		?></h5>
								          		
								          	</div>
                                            <div class="col-sm-3">
                                                <label>&nbsp;</label>
                                                <div class="form-group">              
                                                <button type="submit" name="savedataauto" class="btn btn-success btn-block">Submit</button>  
                                                </div> 
												
												
													  
                                            </div>
                                            <div class="col-sm-3">
                                                <label>&nbsp;</label>
                                                <div class="form-group">              
                                                <a href="https://www.google.com/intl/sa/inputtools/try/" target="_blank" type="button" name="button" class="btn btn-primary btn-block">Open Google Input Tools</a> 
                                                </div>
												
												
                                            </div>
                                        </div>
									</div>

                                    
								</form>
					
							</div>
							<!-- /# row -->
						</section>
					</div>
				</div>
            </div>
        </div>


        <script type="text/javascript">
			function validation() {
				
			/*	var aadharno = document.getElementById('aadharno').value;
				if ( aadharno.length < 12 ) {
					 document.getElementById('erroraadharno').innerHTML = " **Please Enter 12 Digit Aadhaar Card Number !!!";
					 document.getElementById('aadharno').style.border = "1px solid red";
					 document.getElementById('aadharno').focus();
					 return false;
				}*/

                var txtSource = document.getElementById('txtSource').value;
				if ( txtSource.trim() =="" ) {
					 document.getElementById('errortxtSource').innerHTML = " **Please Enter Address !!!";
					 document.getElementById('txtSource').style.border = "1px solid red";
					 document.getElementById('txtSource').focus();
					 return false;
                }
                
                var name_regional = document.getElementById('name_regional').value;
				if ( name_regional.trim() =="" ) {
					 document.getElementById('errorname_regional').innerHTML = " **Please Enter Name in Local Language !!!";
					 document.getElementById('name_regional').style.border = "1px solid red";
					 document.getElementById('name_regional').focus();
					 return false;
				}

                var txtTarget = document.getElementById('txtTarget').value;
				if ( txtTarget.trim() =="" ) {
					 document.getElementById('errortxtTarget').innerHTML = " **Please Enter Local Language Address !!!";
					 document.getElementById('txtTarget').style.border = "1px solid red";
					 document.getElementById('txtTarget').focus();
					 return false;
				}
				
			}
			
			function setaddress(){
	var fathername = document.getElementById('fathername').value;
    var houseno = document.getElementById('houseno').value;
    var streetlocality = document.getElementById('streetlocality').value;
    var vtcandpost = document.getElementById('vtcandpost').value;
    var state = document.getElementById('state').value;
    var city = document.getElementById('city').value;
    var pincode = document.getElementById('pincode').value;

	document.getElementById('txtSource').innerHTML ="S/O : " + fathername + ", " + houseno + ", " + streetlocality + ", " + vtcandpost + ", " + city + ", " + state + ", " + pincode;
}

        </script>
	         
<script type="text/javascript">
//English to hindi translate code
    function changelang() {
            var lang = document.getElementById("language").value;
            //alert(lang);
            var url = 
			"https://translate.googleapis.com/translate_a/single?client=gtx";
            url += "&sl=" + 'EN';
            url += "&tl=" + lang;
            url += "&dt=t&q=" + escape($("#txtSource").val());
		    
		   $.get(url, function (data, status) {
			 var result= '';
			  for(var i=0; i<=500; i++)
			    {
			      result += data[0][i][0];
                  //alert(result);
				  $("#txtTarget").val(result);
					
			    }
            });	

            url = 
			"https://translate.googleapis.com/translate_a/single?client=gtx";
            url += "&sl=" + 'EN';
            url += "&tl=" + lang;
            url += "&dt=t&q=" + escape($("#name").val());
		    //alert(url);
		   $.get(url, function (data, status) {
			 var result= '';
			  for(var i=0; i<=500; i++)
			    {
			      result += data[0][i][0];
                 // alert(result);
				  $("#name_regional").val(result);
					
			    }
            });	

            
            url = 
			"https://translate.googleapis.com/translate_a/single?client=gtx";
            url += "&sl=" + 'EN';
            url += "&tl=" + lang;
            url += "&dt=t&q=" + escape($("#gender").val());
		    //alert(url);
		   $.get(url, function (data, status) {
			 var result= '';
			  for(var i=0; i<=500; i++)
			    {
			      result += data[0][i][0];
                  // alert(result);
            if(result=="नर")
            result="पुरुष";
            $("#genderlocal").val(result);
					
			    }
            });
            
            url = 
			"https://translate.googleapis.com/translate_a/single?client=gtx";
            url += "&sl=" + 'EN';
            url += "&tl=" + lang;
            url += "&dt=t&q=" + escape($("#gender").val());
		    //alert(url);
		   $.get(url, function (data, status) {
			 var result= '';
			  for(var i=0; i<=500; i++)
			    {
			      result += data[0][i][0];
                  // alert(result);
            if(result=="ਨਰ")
            result="ਮਰਦ";
            $("#genderlocal").val(result);
					
			    }
            });

            url = 
			"https://translate.googleapis.com/translate_a/single?client=gtx";
            url += "&sl=" + 'EN';
            url += "&tl=" + lang;
            url += "&dt=t&q=" + escape($("#birthtithi").val());
		    //alert(url);
		   $.get(url, function (data, status) {
			 var result= '';
			  for(var i=0; i<=500; i++)
			    {
			      result += data[0][i][0];
                 //alert(result);
				  $("#birthtithilocal").val(result);
					
			    }
            });


            url = 
			"https://translate.googleapis.com/translate_a/single?client=gtx";
            url += "&sl=" + 'EN';
            url += "&tl=" + lang;
            url += "&dt=t&q=" + escape($("#pata").val());
		    //alert(url);
		   $.get(url, function (data, status) {
			 var result= '';
			  for(var i=0; i<=500; i++)
			    {
			      result += data[0][i][0];
                 // alert(result);
				  $("#patalocal").val(result);
					
			    }
            });

		};	
//Words and Characters Count
function readURL(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
            $('#blah').attr('src', e.target.result);
        }

        reader.readAsDataURL(input.files[0]);
    }
}
$("#blah").hide();
$("#imgInp").change(function(){
    readURL(this);
	$("#blah").show();
});	


function readURLs(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
            $('#blahs').attr('src', e.target.result);
        }

        reader.readAsDataURL(input.files[0]);
    }
}
$("#blahs").hide();
$("#signInp").change(function(){
    readURLs(this);
	$("#blahs").show();
});
</script>


  </script>
<div id="myModal" class="modal fade" role="dialog">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content">
      
      <div class="modal-body">
        <img src="<?php echo $slct['aafile'];?>" width="<?php echo $slct['iwidth'];?>" height="<?php echo $slct['iheight'];?>"/>
      </div>
      
    </div>
<button type="button" class="btn btn-default" data-dismiss="modal" style="    position: absolute;
    top: -20px;
    right: -422px;
    border-radius: 50%;
    background: red;
	border-color:red;
    color: white;">X</button>
  </div>
</div>
<style>
.modal-body
{
	flex:inherit !important;
	padding:inherit !important;
}
.modal-footer
{
	border:none !important;
}
.modal-dialog {
	margin: 30px 248px auto !important;
    max-width: auto !important;
	width : 100% !important;
}
</style>
	<!--end page wrapper -->
		<?php 
		include('../template/tngweb/footer.php');
		?>
	<!-- Bootstrap JS -->
	

	<script src="../template/tngweb/assets/js/bootstrap.bundle.min.js"></script>
	<!--plugins-->
	<!-- <script src="../template/tngweb/assets/js/jquery.min.js"></script> -->
	<script src="../template/tngweb/assets/plugins/simplebar/js/simplebar.min.js"></script>
	<script src="../template/tngweb/assets/plugins/metismenu/js/metisMenu.min.js"></script>
	<script src="../template/tngweb/assets/plugins/perfect-scrollbar/js/perfect-scrollbar.js"></script>
	<!--app JS-->
	<script src="../template/tngweb/assets/js/app.js"></script>
</body>

<script>
	$(document).ready(function() {
	
	$('#eid').inputmask();
	$('#date').inputmask();
	$('#pan_no').inputmask();
	$('#timea').inputmask("hh:mm:ss", {
        placeholder: "00:00:00", 
        insertMode: false, 
        showMaskOnHover: false,
        hourFormat: 12
      });
	});
</script>
</html>