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

if ($udata['balance'] < $fee) {
    ?>
    <script>
        alert("Dear user your Wallet Balance is Low Please Recharge Now");
        window.location.href = "wallet.php";
    </script>
    <?php 
} elseif (isset($_POST['savedata'])) {	

    $q = "SELECT * FROM users WHERE phone='" . $_SESSION['phone'] . "'";
    $r = mysqli_query($tng_conn, $q);
    $rw = mysqli_fetch_assoc($r);

    $aadharno   = trim($_POST['pannumber']);
    $name       = trim($_POST['name']);
    $fathername = trim($_POST['fathername']);
    $dobadhar   = trim($_POST['dobadhar']);
    $gender   = trim($_POST['gender']);

    // File types
    $sign_image_type  = $_FILES["signfile"]["type"];
    $image_type       = $_FILES["imagefile"]["type"];
    $word = "image";

    if ($aadharno == "") {
        $msgno = 'Please Enter Pan Card No .... ';
    } elseif ($rw['aadharpoint'] > $rw['balance']) {
        $msgno = "Sorry, Your Balance is Low .... Please Recharge Soon";
        ?>
        <script>
            setTimeout(function () {
                window.location.href= 'panmanual.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 .... ';
    } else {
        $a = mysqli_query($tng_conn, "SELECT panno FROM panauto WHERE panno='" . $aadharno . "'");
        $b = mysqli_fetch_array($a);

        if ($b['panno'] == $aadharno) {
            $msgno = 'This Pan Card No Already Exist .... ';
        } else {
            if ((strpos($sign_image_type, $word) !== false) && (strpos($image_type, $word) !== false)) {

                // Base64 conversion with prefix
                $image_base64 = "data:" . $image_type . ";base64," . base64_encode(file_get_contents($_FILES['imagefile']['tmp_name']));
                $sign_base64  = "data:" . $sign_image_type . ";base64," . base64_encode(file_get_contents($_FILES['signfile']['tmp_name']));

                date_default_timezone_set('Asia/Kolkata');
                $timestamp = date("Y-m-d H:i:s");

                $query = "INSERT INTO panauto(`userid`,`panno`,`name`,`fathername`,`dob`,`gender`,`image`,`signimage`,`create_time`) 
                          VALUES('" . $_SESSION['phone'] . "','" . $aadharno . "','" . $name . "','" . $fathername . "','" . $dobadhar . "','" . $gender . "','" . $image_base64 . "','" . $sign_base64 . "','" . $timestamp . "')";

                $result = mysqli_query($tng_conn, $query);

                if ($result) {
                    $appliedby = $udata['phone'];
                    $parentPhone = $udata['parent'];
                    $debit_fee = $udata['balance'] - $fee;
                    addCommission($tng_conn, $appliedby, $fee, $parentPhone, "Pan Manual Verification");

                    mysqli_query($tng_conn,"UPDATE users SET balance=balance-$fee WHERE phone='$appliedby'");
                    mysqli_query($tng_conn, "INSERT INTO wallethistory(userid, amount, balance, purpose, status, type) VALUES ('$appliedby', '$fee', '$debit_fee', 'Pan Manual Print', '1', 'Debit')");

                    $msg = "Please Wait Pan Preview just a second...";
                    $_SESSION["Panno"]=trim($aadharno);

                    echo '<script>
                        $(function(){
                            Swal.fire(
                                "' . $msg . '",
                                "",
                                "success"
                            );
                        });
                        setTimeout(function () {
                            window.location = "Pan_manual_list.php";
                        }, 1200);
                    </script>';
                }
            } else {
                $msgno = "Please select PNG and JPEG image only.";
            }
        }
    }
}

if (!empty($msgno)) {
    echo '<script>
        document.addEventListener("DOMContentLoaded", function() {
            alert("' . $msgno . '");
        });
    </script>';
}
?>

	<!--start page wrapper -->
		<div class="page-wrapper">
			<div class="page-content">
				<div class="row">
					<div class="col-xl-10 mx-auto">
						
						<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>
									<div class="mb-4">
        <a href="javascript:history.back()" class="back-btn">
            <i class="bi bi-arrow-left-circle"></i> Go Back
        </a>
    </div>
									<h5 class="mb-0 text-primary">Enter Pan Card Manual</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-12">
                                                         <label>Select Pan Card Type</label>
                                                        <div class="form-group ">
                                                           <select name="ptype" autofocus id="ptype" class="form-control stylec" required>
                                                               <option value="UTI-NONMINOR"> (18 साल  या उस  से ज्यादा  उम्र के लिए )  </option>
															   <option value="NSDL-NONMINOR">NSDL NONMINOR (18 साल  या उस  से ज्यादा  उम्र के लिए ) </option
                                                           <option value="UTI-MINOR">UTI MINOR (18 साल से कम उम्र के लिए )</option>
                                                         <option value="NSDL-MINOR">NSDL MINOR (18 साल से कम उम्र के लिए )</option>
                                                           </select>
                                                            
                                                        </div>
                                                    </div>
                                                    <div class="col-sm-12">
                                                        <label>Pan Card No.</label>
                                                        <div class="form-group">
                                                            <input class="form-control stylec" value="<?php echo $panNumber;?>"  id="pannumber" placeholder=""  autocomplete="off" name="pannumber" type="text" maxlength="10" required onkeyup="this.value = this.value.toUpperCase();" onblur='ValidatePAN(this)'>
                                                            <span id="erroraadharno" class="error"></span>
                                                        </div>
                                                    </div></br>
                                                    <div class="col-sm-12">
                                                        <label>Name</label>
                                                        <div class="form-group">
                                                            <input class="form-control stylec" id="name" placeholder="" name="name"  value="<?php echo $json['fullname'];?>"  type="text" required onkeyup="this.value = this.value.toUpperCase();" >
															
															
															
                                                        </div>
                                                    </div>
                                                    <div class="col-sm-12">
                                                        <label>Father Name </label>
                                                        <div class="form-group">

                                                            <input class="form-control stylec" name="fathername" id="fathername" placeholder="" Value="<?php echo $json['fathername'];?>" type="text" onkeyup="this.value = this.value.toUpperCase();"  >
                                                        </div>
                                                    </div>
													

													
                                              
												
                                                
                                                    <div class="col-sm-6">
                                                        <label>Date Of Birth</label>
                                                        <div class="form-group">
                                                            <input class="form-control stylec" name="dobadhar" data-field="date" type="text" value="<?php echo $formatted_dob;?>" required placeholder="D.O.B.(dd/MM/yyyy)">
                                                            
                                                        </div>
                                                    </div>
                                                    
                                                    <div class="col-sm-6">
                                                        <label>Gender </label>
                                                        <div class="form-group ">

                                                            <select name="gender" class="form-control stylec" required>
                                                            <option value="<?php echo $json['gender'];?>"><?php echo $json['gender'];?></option>
                                                            <option value="Male">Male</option>
                                                            <option value="Female">Female</option>
                                                            <option value="Other">Other</option>
                                                            </select>   
                                                            </div>
                                                    </div>
													

													
                                              
												
                                        <div class="col-sm-6">
                                            <label id="stype">Select Image   </label>
                                            <div class="form-group">
											  <input type="file" name="imagefile" class="form-control stylec" id="imgInp" required />
                                              <img src=""   id="blah" width="100px" height="100px" style="margin-top: 12px;
    box-shadow: 4px 4px 2px 1px;
    border-radius: 10px;"/>
                                              <input type="hidden" name="blahin" id="blahin" value="" class="form-control"/>
                                            </div>
                                        </div>
										
                                                
                                                   
                                                    
													<div class="col-sm-6">
                                            <label id="simgs">Select  Sign Image  </label>
                                            <div class="form-group">
											  <input type="file" name="signfile" class="form-control stylec" id="signInp" required />
                                              <img src=""   id="blahs" width="100px" height="100px" style="margin-top: 12px;
    box-shadow: 4px 4px 2px 1px;
    border-radius: 10px;" />
                                               <input type="hidden" name="blahsin" id="blahsin" value="" class="form-control"/>
                                            </div>
                                        </div>
	<br><br>
										   <div class="row" style=" margin-top:25px;">
                                            <div class="col-12 ml-4">
								          	<h5 class="text-warning ">Application Fee: <?php  
								          		echo "₹" .$fee;
								          		?></h5>		
                                          <div class="col-sm-12">
                                           <div class="col-sm-3">
                                                <label>&nbsp;</label>
                                                <div class="form-group">              
                                                <button type="submit" name="savedata" class="btn btn-success btn-block" style="box-shadow: 0 0 0 3px rgba(40,167,69,.5);">Submit</button> 
                                                </div> 
                                            </div>
                                        </div>
									</div>
								</form>
							</div>
							<!-- /# row -->
						</section>
							<style>
								.stylec
								{
								    box-shadow: 2px 3px #000 !important;
    border-radius: 50px !important;
								}
								</style>
					</div>
				</div>
            </div>
        </div>

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

               
                
                
				
			}
			
		
        </script>
	         
<script type="text/javascript">
//English to hindi translate code
    
//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);
            $('#blahin').val(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);
            $('#blahsin').val(e.target.result);
        }

        reader.readAsDataURL(input.files[0]);
    }
}
$("#blahs").hide();
$("#signInp").change(function(){
    readURLs(this);
	$("#blahs").show();
});	
									
</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['pafile'];?>" 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>

<div id="myModals" class="modal fade" role="dialog" data-backdrop="static" data-keyboard="false" style="background-color: rgba(0, 0, 0, 0.7);">
  <div class="modal-dialog">

    <!-- Modal content-->
    <div class="modal-content" style="     height: 352px;
    width: 727px;
    margin-left: 165px;
">
      
      <div class="modal-body" style="height: 243px;">
	 <img src="abs.jpg" height="200px" width="100%">
	<form method="post" action="paytmv/index.php">
									<div class="">
									
									 <p style="    font-size: 18px;
    text-align: center;
    margin-top:20px;
    ">You Not Authorized For using This Pan Services Please Buy Services.</p>
									    <div class="row col-md-12 col-sm-12 col-xs-12">
											<div class="col-md-3 col-sm-3 col-xs-6">
											<?php
												error_reporting(0);
												include("config.php");

												
												//$slct = mysqli_fetch_assoc($r);
												//$slct['aadharpoint'];
                                       $c = "select * from user_data where phone=".$_SESSION['phone']."";
									   $updts = mysqli_query($tng_conn,$c) ;
												$slcts = mysqli_fetch_array($updts);
												?>
												
												
												
                                    
													
												
												</div> 
											</div>
											
											<div class="col-md-12 col-sm-4 col-xs-6">
												
												<div class="form-group"> 
									
<input type="hidden" name="service[]" value="1"/> 


	
												<span id="erroruserid" class="error"></span>  
												</div> 
											</div>										
											
											<div class="col-md-12 col-sm-4 col-xs-6">
												
												<div class="form-group">              
												<input autocomplete="off" type="hidden" class="form-control"  id="Pay_Amt" value="500" name="Pay_Amt" placeholder="Website URL/ Link" readonly >
												<input type="hidden" value="<?php echo $_SESSION['phone'];?>" name="pay_uid"/>
												<span id="erroruserid" class="error"></span>  
												</div> 
											</div>										
											
															
													
																						
												
												
										
										
												
												
												
												
												
												
										</div> 
											</table>											
										</div>										
										<div class="col-md-12 col-sm-4 col-xs-6">
											<label>&nbsp;</label>
											<div class="form-group"> 
                                                   											
											   
											   <div class="col-md-6"><button type="submit" id="submit" name="submit" style="padding:17px;background:orange;border:1px solid orange;" class="btn btn-success btn-block"> &nbsp;&nbsp;&nbsp; Buy Now &nbsp;&nbsp;&nbsp;</button> </div><div class="col-md-6"><a href="panel.php" style="padding:17px;background:orange;border:1px solid orange;    margin-top: -65px;
    margin-left: 343px;" class="btn btn-success btn-block"> &nbsp;&nbsp;&nbsp; Dashboard &nbsp;&nbsp;&nbsp;</a></div>
											</div> 
										</div>
									</div>
								</form>
      </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>

  
 

<?php include('userFooter.php'); ?>

		<!--[if lt IE 9]>
			<link rel="stylesheet" type="text/css" href="DateTimePicker-ltie9.css" />
			<script type="text/javascript" src="DateTimePicker-ltie9.js"></script>
		<![endif]-->
<div id="dtBox"></div>
		<script>
					    $("#ptype").on('change',function()
					    {
					       if($(this).val() == 'UTI-MINOR' || $(this).val() == 'NSDL-MINOR') 
					       {
					           $("#signInp").hide();
					           
					           $("#simgs").hide();
					       }
					       else 
					       {
					           $("#signInp").show();
					           $("#imgInp").show();
					           $("#stype").show();
					           $("#simgs").show();
					       }
					    });
					</script>
					
					<script type="text/javascript">
function ValidatePAN()
{
	 var pan_no = document.getElementById("pannumber");
	
 if (pan_no.value != "") {
            PanNo = pan_no.value;
            var panPattern = /^([a-zA-Z]{5})(\d{4})([a-zA-Z]{1})$/;
            if (PanNo.search(panPattern) == -1) {
                alert("Invalid Pan No");
                pan_no.focus();
                pan_no.value='';
                return false;
                
            }
           
          
        }
}

</script>
								
								
								
								
		
		<!--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();
	$('#timea').inputmask("hh:mm:ss", {
        placeholder: "00:00:00", 
        insertMode: false, 
        showMaskOnHover: false,
        // hourFormat: 24
      });
	});
</script>
</html>