<?php

include('php/database.php');
include('php/security.php');
session_start();
if(logged_in())
{
	header('location:../login.php');
}
$id= $_SESSION['id'];
$results= mysqli_query($connection, "SELECT `date`, `id`, `name`, `email`, `number`, `password`, `phone`, `address`, `country`, `gender`, `image`, `vcode`, `verified`, `verify`, `balance`, `totalbalance`, `investbalance`, `profit`, `totaldeposit`, `totalwithdrawal`, `loanlimit`, `availableloan`, `ongoingloan`, `savings`, `idcard`, `idcardback`, `accountstatus`, `pina`, `pinb`, `pinc`, `pind` FROM users WHERE id ='$id'");
$retrive= mysqli_fetch_array($results);
$date = $retrive['date'];
$id = $retrive['id'];
$name = $retrive['name'];
$email = $retrive['email'];
$number = $retrive['number'];
$password = $retrive['password'];
$phone = $retrive['phone'];
$address = $retrive['address'];
$country = $retrive['country'];
$gender = $retrive['gender'];
$image = $retrive['image'];
$vcode = $retrive['vcode'];
$verified = $retrive['verified'];
$verify = $retrive['verify'];
$balance = $retrive['balance'];
$totalbalance = $retrive['totalbalance'];
$investbalance = $retrive['investbalance'];
$profit = $retrive['profit'];
$totaldeposit = $retrive['totaldeposit'];
$totalwithdrawal = $retrive['totalwithdrawal'];
$loanlimit = $retrive['loanlimit'];
$availableloan = $retrive['availableloan'];
$ongoingloan = $retrive['ongoingloan'];
$savings = $retrive['savings'];
$idcard = $retrive['idcard'];
$idcardback = $retrive['idcardback'];
$accountstatus = $retrive['accountstatus'];
$pina = $retrive['pina'];
$pinb = $retrive['pinb'];
$pinc = $retrive['pinc'];
$pind = $retrive['pind'];

$amount = mysqli_real_escape_string($connection, $_GET['amount']);
   
$repayment = $amount * 1.002;

?>


<!DOCTYPE html>
<html lang="en">


<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Mobile Specific Metas -->
  <meta name="viewport" content="width=device-width, initial-scale=0.7, viewport-fit=cover">
    <title>Complete Loan</title>
    <!-- Favicon and Touch Icons  -->
    <link rel="shortcut icon" href="images/logo.png" />
    <link rel="apple-touch-icon-precomposed" href="images/logo.png" />
    <!-- Font -->
    <link rel="stylesheet" href="fonts/fonts.css" />
    <!-- Icons -->
    <link rel="stylesheet" href="fonts/icons-alipay.css">
    <link rel="stylesheet" href="styles/bootstrap.css">

    <link rel="stylesheet" type="text/css" href="styles/styles.css" />
    <link rel="manifest" href="_manifest.json" data-pwa-version="set_in_manifest_and_pwa_js">
    <link rel="apple-touch-icon" sizes="192x192" href="app/icons/icon-192x192.png">
</head>

<body class="bg_surface_color">
     <!-- preloade -->
     <div class="preload preload-container">
        <div class="preload-logo">
          <div class="spinner"></div>
        </div>
      </div>
    <!-- /preload -->
    <div class="header is-fixed">
        <div class="tf-container">
            <div class="tf-statusbar d-flex justify-content-center align-items-center">
                <a href="#" class="back-btn"> <i class="icon-left"></i> </a>
                <h3>Complete Loan  </h3>&nbsp; &nbsp; <div  class="gtranslate_wrapper"></div>
<script>window.gtranslateSettings = {"default_language":"en","detect_browser_language":true,"wrapper_selector":".gtranslate_wrapper"}</script>
<script src="https://cdn.gtranslate.net/widgets/latest/dropdown.js" defer></script>
            </div>
        </div>
    </div>
    <div id="app-wrap">
        <div class="bill-payment-content">
            <div class="tf-container">
                
                 <div class="wrapper-bill">
                     <div class="archive-top">
                         <span class="circle-box lg bg-success">
                             <svg width="63" height="62" viewBox="0 0 63 62" fill="none" xmlns="http://www.w3.org/2000/svg">
                                 <path d="M31.5 11.2783L27.023 7.68753L22.5459 11.2824L18.069 7.68753V50.3189L22.5459 53.9139L27.023 50.3189L31.5 53.9139L31.6334 53.5819L32.3766 30.9701L31.6419 11.3564L31.5 11.2783Z" fill="white"/>
                                 <path d="M40.454 11.2824L35.977 7.68753L31.5 11.2783V53.9139L35.977 50.3189L40.454 53.9139L44.931 50.3189V7.68753L40.454 11.2824Z" fill="white"/>
                                 <path d="M21.681 17.808V21.364H31.642L31.9964 19.5859L31.642 17.808H21.681Z" fill="#C5C5C5"/>
                                 <path d="M31.5051 17.808H35.6749V21.364H31.5051V17.808Z" fill="#C5C5C5"/>
                                 <path d="M21.681 31.2109H29.7102V34.7669H21.681V31.2109Z" fill="#C5C5C5"/>
                                 <path d="M21.681 38.3227H29.7102V41.8786H21.681V38.3227Z" fill="#4A84F6"/>
                                 <path d="M21.6597 24.3728V27.9286H31.6419L31.9964 26.0385L31.6419 24.3728H21.6597Z" fill="#C5C5C5"/>
                                 <path d="M31.5051 24.3728H41.3404V27.9287H31.5051V24.3728Z" fill="#C5C5C5"/>
                                 <path d="M37.7163 40.5659C36.3815 40.4515 35.4027 39.943 34.7035 39.2438L35.6951 37.8327C36.1655 38.3285 36.8647 38.7734 37.7164 38.926V36.9555C36.407 36.6376 34.9832 36.1419 34.9832 34.413C34.9832 33.1291 36.0002 32.0358 37.7164 31.8578V30.6756H38.9114V31.8833C39.941 31.9977 40.8182 32.379 41.5047 33.0146L40.5005 34.3622C40.0429 33.9427 39.4835 33.6757 38.9114 33.5358V35.2901C40.2335 35.6206 41.7082 36.1292 41.7082 37.8707C41.7082 39.2819 40.7801 40.3751 38.9114 40.5658V41.7099H37.7164V40.5659H37.7163ZM37.7163 34.9979V33.4597C37.157 33.536 36.8391 33.841 36.8391 34.2733C36.8392 34.6419 37.1951 34.8326 37.7163 34.9979ZM38.9114 37.248V38.9514C39.5597 38.8242 39.8648 38.4556 39.8648 38.0488C39.8648 37.6294 39.4707 37.426 38.9114 37.248Z" fill="#F2C71C"/>
                             </svg>
                         </span>
                         <h1><a href="#" class="green">+ $ <?php echo $amount?></a></h1>
                         </div>
                     <div class="dashed-line"></div>
                     <div class="archive-bottom">
                         <h2 class="text-center">Loan Details</h2>
                         <ul>
                             <li class="list-info-bill">Loan Amount <span>$<?php echo $amount?></span> </li>
                             <li class="list-info-bill">Repayment Amount <span>$<?php echo $repayment?></span> </li>
                             <li class="list-info-bill">Duration <span class="text-end">1 month</span> </li>
                         </ul>
                     </div>
     
                 </div>
     
     
            </div>
          
         </div>
    </div>
    
    <div class="bottom-navigation-bar st1 bottom-btn-fixed">
        <div class="tf-container">
           <a href="#" id="btn-popup-down" class="tf-btn accent large">Confirm</a>
        </div>
    </div>
    




<div class="tf-panel down">
        <div class="panel_overlay"></div>
        <div class="panel-box panel-down">
            <div class="header">
                <div class="tf-container">
                    <div class="tf-statusbar br-none d-flex justify-content-center align-items-center">
                        <a href="#" class="clear-panel"> <i class="icon-close1"></i> </a>
                        <h3>Enter pin</h3>
                    </div>
                    
                </div>
            </div>
            
            <div class="mt-5">
                <div class="tf-container">
                    <form class="tf-form tf-form-verify" action="php/loan.php" method="POST" onsubmit="return validation()">
                        <div class="d-flex group-input-verify">
                                <input type="tel" maxlength="1" name="pina" id="pina" pattern="[0-9]" onkeypress="return isNumberKey(event,this.id)" class="input-verify" value="">
                                <input type="tel" maxlength="1" name="pinb" id="pinb" pattern="[0-9]" onkeypress="return isNumberKey(event,this.id)" class="input-verify" value="">
                                <input type="tel" maxlength="1" name="pinc" id="pinc" pattern="[0-9]" onkeypress="return isNumberKey(event,this.id)" class="input-verify" value="">
                                <input type="tel" maxlength="1" name="pind" id="pind" pattern="[0-9]" onkeypress="return isNumberKey(event,this.id)" class="input-verify" value="">
                        </div>
                      <div class="error1"></div>
					  
					   <input type="hidden" name="amount" value="<?php echo $amount?>">
					  <input type="hidden" name="repayment" value="<?php echo $repayment?>">
                        <div class="mt-7 mb-6">
                            <button type="submit" name="submit "class="tf-btn accent large">Continue</button>
                        </div>
                    </form>
                </div>
        
            </div>
        </div>
    </div>
<script>
function isNumberKey(evt,id)
{
	try{
        var charCode = (evt.which) ? evt.which : event.keyCode;
  
        if(charCode==46){
            var txt=document.getElementById(id).value;
            if(!(txt.indexOf(".") > -1)){
	
                return true;
            }
        }
        if (charCode > 31 && (charCode < 48 || charCode > 57) )
            return false;

        return true;
	}catch(w){
		alert(w);
	}
}

</script>

<script>
	function validation(){
	let id = (id) => document.getElementById(id);

    let classes = (classes) => document.getElementsByClassName(classes);

    let  pina = id("pina"),
	   pinb = id("pinb"),
	    pinc = id("pinc"),
		 pind = id("pind"),
        errorMsg = classes("error1");
		
    var codea = document.getElementById("pina").value;
	var codeb = document.getElementById("pinb").value;	
	  var codec = document.getElementById("pinc").value;
	var coded = document.getElementById("pind").value;  
	
	if(pina.value.trim() ==="") {
    errorMsg[0].innerHTML = '<p style="font-size:12px;" class="  text-danger text-center">Enter Pin</p>';
    pina.style.borderBottom = "2px solid red";
      return false;
  } else {
    errorMsg[0].innerHTML = "";
   pina.style.borderBottom = "";
  }

if(pinb.value.trim() ==="") {
    errorMsg[0].innerHTML = '<p style="font-size:12px;" class="  text-danger text-center">Enter Pin</p>';
    pinb.style.borderBottom = "2px solid red";
      return false;
  } else {
    errorMsg[0].innerHTML = "";
   pinb.style.borderBottom = "";
  } 
 
  
if(pinc.value.trim() ==="") {
    errorMsg[0].innerHTML = '<p style="font-size:12px;" class="  text-danger text-center">Enter Pin</p>';
    pinc.style.borderBottom = "2px solid red";
      return false;
  } else {
    errorMsg[0].innerHTML = "";
   pinc.style.borderBottom = "";
  } 
 
if(pind.value.trim() ==="") {
    errorMsg[0].innerHTML = '<p style="font-size:12px;" class="  text-danger text-center">Enter Pin</p>';
    pind.style.borderBottom = "2px solid red";
      return false;
  } else {
    errorMsg[0].innerHTML = "";
   pind.style.borderBottom = "";
  } 
  
  if(codea > <?php echo $pina ?>) {
    errorMsg[0].innerHTML = '<p style="font-size:12px;" class="  text-danger text-center">Wrong Pin</p>';
       return false;
  } else {
    errorMsg[0].innerHTML = "";
    } 
 if(codeb > <?php echo $pinb ?>) {
    errorMsg[0].innerHTML = '<p style="font-size:12px;" class="  text-danger text-center">Wrong Pin</p>';
       return false;
  } else {
    errorMsg[0].innerHTML = "";
    } 
  
   if(codec > <?php echo $pinc ?>) {
    errorMsg[0].innerHTML = '<p style="font-size:12px;" class="  text-danger text-center">Wrong Pin</p>';
       return false;
  } else {
    errorMsg[0].innerHTML = "";
    } 
  
  
if(coded > <?php echo $pind ?>) {
    errorMsg[0].innerHTML = '<p style="font-size:12px;" class="  text-danger text-center">Wrong Pin</p>';
       return false;
  } else {
    errorMsg[0].innerHTML = "";
    } 
 

	return true;
	};
	
  
	</script>





 <script type="text/javascript" src="javascript/jquery.min.js"></script>
    <script type="text/javascript" src="javascript/bootstrap.min.js"></script>
    <script type="text/javascript" src="javascript/count-down.js"></script>
    <script type="text/javascript" src="javascript/verify-input.js"></script>
    



    <script type="text/javascript" src="javascript/jquery.min.js"></script>
    <script type="text/javascript" src="javascript/bootstrap.min.js"></script>
    <script type="text/javascript" src="javascript/count-down.js"></script>
    <script type="text/javascript" src="javascript/main.js"></script>

</body>


</html>