<?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'];

?>



<!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>Save Money</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">

    <script src="https://cdn.tailwindcss.com"></script>
</head>

<body class="font-sans text-[12px] leading-[20px] font-medium text-textGray bg-white w-full m-auto overflow-hidden">
     <!-- preloade -->
     <div class="preload preload-container">
        <div class="preload-logo">
          <div class="spinner"></div>
        </div>
      </div>
    <!-- /preload -->
    <div class="app-header st1">
        <div class="tf-container">
            <div class="tf-topbar d-flex justify-content-center align-items-center">
               <a href="#" class="back-btn"><i class="icon-left text-white"></i></a> 
                <h3 class="text-white">Save Money </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 class="card-secton topup-content">
        <div class="tf-container">
            <div class="tf-balance-box">
                <div class="d-flex justify-content-between align-items-center">
                    <p>Savings:</p>
                    <h3>$<?php echo $savings ?></h3>
                </div>
				<form action="php/save.php" method="POST" onsubmit="return validation()">
				
                <div class="tf-spacing-16"></div>
                <div class="tf-form">
                    <div class="group-input input-field input-money">
                        <label for="">Amount Of Money</label>
                        <input type="text" value="" id="amount" name="amount" onkeypress="return isNumberKey(event,this.id)" class="search-field value_input st1" >
                        <span class="icon-clear"></span>
						
						<div class="error1"></div>
                    </div>
                </div>
               
            </div>
           
        </div>
        <div class="bottom-navigation-bar">
            <div class="tf-container">
                <button type="submit"  class="tf-btn accent large">Continue</button>
            </div>
        </div>
    </div>
   </form>
    <div class="amount-money mt-5">
        <div class="tf-container">
            <h3>Amount Money</h3>
            <ul class="money list-money">
                <li><a class="tag-money" href="#">5000</a> </li>
                <li><a class="tag-money" href="#">10000</a> </li>
                <li><a class="tag-money" href="#">20000</a> </li>
                <li><a class="tag-money" href="#">50000</a> </li>
                <li><a class="tag-money" href="#">100000</a> </li>
                <li><a class="tag-money" href="#">200000</a> </li>
             </ul>
        </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>
        <!-- SCRIPTS -->
		
		
		<script>
	function validation(){
	let id = (id) => document.getElementById(id);

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

    let  amount = id("amount"),
        errorMsg = classes("error1");
		
    
	 var zero = document.getElementById("amount").value;
	
	
	    
	
	
	if(amount.value.trim() ==="") {
    errorMsg[0].innerHTML = '<p class=" text-danger text-center">Please enter amount</p>';
    amount.style.borderBottom = "2px solid red";
      return false;
  } else {
    errorMsg[0].innerHTML = "";
   amount.style.borderBottom = "";
  } 
if(amount.value.trim() === "0") {
    errorMsg[0].innerHTML = '<p class=" text-danger text-center">Please enter amount</p>';
    amount.style.borderBottom = "2px solid red";
      return false;
  } else {
    errorMsg[0].innerHTML = "";
   amount.style.borderBottom = "";
  } 
if(zero == 0) {
    errorMsg[0].innerHTML = '<p class=" text-danger text-center">Please enter amount</p>';
    amount.style.borderBottom = "2px solid red";
      return false;
  } else {
    errorMsg[0].innerHTML = "";
   amount.style.borderBottom = "";
  } 



if(zero > <?php echo $balance ?>) {
    errorMsg[0].innerHTML = '<p class=" text-danger text-center">Insufficient Balance</p>';
    amount.style.borderBottom = "2px solid red";
      return false;
  } else {
    errorMsg[0].innerHTML = "";
   amount.style.borderBottom = "";
  } 

 

	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/main.js"></script>
    
</body>


</html>