<?php 
include_once("classes/database.class.php");
include_once("classes/oanda.php");

$myHttp = isset($_SERVER['HTTPS']) ? 'https://' : 'http://';
$myDomain = $_SERVER['HTTP_HOST'];

$url = "https://".$myDomain;

?>


<?php

$loggedIn = false;
if(isset($_COOKIE['id']) && isset($_COOKIE['uid'])){
  $userId = filter_input(INPUT_COOKIE, 'id');
  $userUId = filter_input(INPUT_COOKIE, 'uid');
  $db = new database();
  $stmt = $db->db->prepare("SELECT * FROM users WHERE id = :id and uid = :uid");
  $stmt->execute(array(':id' => $userId, ':uid' => $userUId));
  $userDetails = $stmt->fetch(PDO::FETCH_OBJ);
  $account = new oandaAPI();
  $account->retrieveAccount($userDetails->accountId);
  $loggedIn = true;
}

if ($loggedIn == true) {
	# code...
	?>
	<script type="text/javascript">
		location.href = "<?=$url; ?>/dashboard.php";
	</script>
	<?php 
}
?>
<!DOCTYPE HTML>
<html lang="zxx">
<meta http-equiv="content-type" content="text/html;charset=UTF-8" /><!-- /Added by HTTrack -->
<head>
	<title>Invata Trading Platform</title>
	<!-- Meta tag Keywords -->
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta charset="UTF-8" />
	<meta name="keywords" content="Latest Login Form Responsive Widget,Login form widgets, Sign up Web forms , Login signup Responsive web form,Flat Pricing table,Flat Drop downs,Registration Forms,News letter Forms,Elements" />
	<script>
		addEventListener("load", function () {
			setTimeout(hideURLbar, 0);
		}, false);

		function hideURLbar() {
			window.scrollTo(0, 1);
		}
	</script>
	<!-- Meta tag Keywords -->

	<!-- css files -->
	<link rel="stylesheet" href="css/style.css" type="text/css" media="all" />
	<!-- Style-CSS -->
	<link href="css/font-awesome.min.css" rel="stylesheet">
	<!-- Font-Awesome-Icons-CSS -->
	<!-- //css files -->

	<!-- web-fonts -->
	<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,200i,300,300i,400,400i,600,600i,700,700i,900,900i&amp;subset=cyrillic,cyrillic-ext,greek,greek-ext,latin-ext,vietnamese"
	 rel="stylesheet">
	<!-- //web-fonts -->



<style type="text/css">
	.top-content-style {
    		background:#000;
		}
	.alert-danger
	{
		background-color: red;
		color: #000;
		padding: 20px;

	}
	.alert-success{
		background-color: green;
    	color: #fff;
    	padding: 20px;
	}
	#loginRow
	{
		background: transparent !important;
	}
	.bg-content-w3pvt
	{
		background: rgba(255, 255, 255, 0.2);
	}
	.sub-main-w3 form
	{
		margin: 0px !important;
	}
	.paymentButton
	{
		width: 100%;
		color: #fff;
		font-weight: 700;
	}
</style>




<style type="text/css">
	.StripeElement {
  box-sizing: border-box;

  height: 40px;

  padding: 10px 12px;

  border: 1px solid transparent;
  border-radius: 4px;
  background-color: white;

  box-shadow: 0 1px 3px 0 #e6ebf1;
  -webkit-transition: box-shadow 150ms ease;
  transition: box-shadow 150ms ease;
}

.StripeElement--focus {
  box-shadow: 0 1px 3px 0 #cfd7df;
}

.StripeElement--invalid {
  border-color: #fa755a;
}

.StripeElement--webkit-autofill {
  background-color: #fefde5 !important;
}
</style>



</head>


<body>
	<div class="main-bg">
		<!-- title -->
		<h1></h1>
		<!-- //title -->
<!---728x90--->

		<!-- content -->
		<div class="sub-main-w3">
			<div class="bg-content-w3pvt">
				<div class="top-content-style">
					<img src="https://trading.invata.io/images/invatalogo.png" width="220" style="border-radius:0px !important;" alt="" />
					<a href="javascript:void(0)" style="color: #015196;margin-top: 10px;" onclick="registerAccount()" id="forgotpasswordwords" class="bottom-text-w3ls">Register Your Account</a>
				</div>



				<form action="#" method="post" id="newPasswordRow" class="formRow" style="display: none;background: transparent !important;">
					<p class="legend" style="color: #1CC7D0">New Password Here<span class="fa fa-hand-o-down" style="color: #1CC7D0;"></span></p>

					<div class="alert alert-danger" id="newCheck" style="display: none;4">
					
					</div>
					<div class="input">
						<input type="password" id="newpass1" placeholder="New Password" name="email" required />
						<span class="fa fa-envelope"></span>
					</div>
					<div class="input">
						<input type="password" id="newpass2" placeholder="Enter Password Again" name="email" required />
						<span class="fa fa-envelope"></span>
					</div>
					<button onclick="newpasswordfunc()" type="button" class="btn submit">
						<span class="fa fa-sign-in"></span>
					</button>
				</form>






				<form action="#" method="post" class="formRow" id="forgotRow" style="display: none;background: transparent !important;">
					<p class="legend" style="color: #1CC7D0">Email Here<span class="fa fa-hand-o-down" style="color: #1CC7D0;"></span></p>

					<div class="alert alert-danger" id="codeCheck" style="display: none;4">
					
					</div>
					<div class="input">
						<input type="email" id="forgotEmail" placeholder="Email Address" name="email" required />
						<span class="fa fa-envelope"></span>
					</div>
					<button onclick="submitforgotpassword()" type="button" class="btn submit">
						<span class="fa fa-sign-in"></span>
					</button>
				</form>


				<form action="#" method="post" class="formRow" id="codeRow" style="display: none;background: transparent !important;">
					<p class="legend" style="color: #1CC7D0">Code Here<span class="fa fa-hand-o-down" style="color: #1CC7D0;"></span></p>

					<div class="alert alert-danger" id="codecheckError" style="display: none;4">
					
					</div>
					<div class="input">
						<input type="text" id="forgotCode" placeholder="Enter Code" name="email" required />
						<span class="fa fa-envelope"></span>
					</div>
					<button onclick="submitForgotCode()" type="button" class="btn submit">
						<span class="fa fa-sign-in"></span>
					</button>
				</form>


				<form action="#" method="post" id="loginRow" class="formRow">
					<p class="legend" style="color: #F15A24;padding-top: 20px;font-weight: 700;">Login Here<span class="fa fa-hand-o-down" style="color: #F15A24;"></span></p>
					<div class="alert alert-danger" id="loginInfo" style="display: none;">
						Wrong Credentials
					</div>
					<div class="input">
						<input type="email" id="loginEmail" placeholder="Email" name="email" required style="border-color: #F15A24;" />
						<span class="fa fa-envelope" style="color: #F15A24;"></span>
					</div>
					<div class="input">
						<input type="password" id="loginPassword" placeholder="Password" name="password" required style="border-color: #F15A24;" />
						<span class="fa fa-unlock" style="color: #F15A24;"></span>
					</div>
					<button onclick="submitform()" type="button" class="btn submit" style="background-color: #F15A24;">
						<span class="fa fa-sign-in"></span>
					</button>
				</form>



				<form action="#" method="post" id="payment-form" style="display: none;background: transparent !important;">
					<p class="legend" style="color: #F15A24;font-weight: 900">Pay To Register</p>
					
				
					  <div class="form-row">
					    <label for="card-element">
					     
					    </label>
					     <div id="card-errors" class="alert alert-danger" role="alert" style="margin-bottom: 20px;color: white;display: none;"></div>
					     <div id="card-success" class="alert alert-success" role="alert" style="margin-bottom: 20px;color: white;display: none;"></div>
					     <div class="input">
							<input type="text" id="emailPayment" placeholder="Enter Email" name="emailPayment" required style="border-color: #F15A24;" />
							<span class="fa fa-envelope" style="color: #F15A24;"></span>
						</div>
					    <div id="card-element">
					      <!-- A Stripe Element will be inserted here. -->
					    </div>

					    <!-- Used to display form errors. -->
					   
					  </div>

					  <button class="btn submit paymentButton" id="submitButtonPayment" style="background-color: #F15A24;">Submit Payment</button>
				</form>




				<a href="javascript:void(0)" style="color: #F15A24;font-weight: 900;" onclick="forgetpassword()" id="forgotpasswordwords" class="bottom-text-w3ls">Forgot Password?</a>





				<a href="javascript:void(0)" onclick="loginhere()" id="loginwords" style="display: none;color: #F15A24;" class="bottom-text-w3ls">Login Here</a>




			</div>
		</div>
		<!-- //content -->
<!---728x90--->

		<!-- copyright -->
		<div class="copyright">
			<h2>&copy; 2019 - Invata Trading Platform . Designed By 
				<a href="https://invata.io" target="_blank">Invata</a>
			</h2>
		</div>
		<!-- //copyright -->
<!---728x90--->

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>



	<script type="text/javascript">
		function registerAccount()
		{
			$("#payment-form").show();
			$(".formRow").hide();
			$("#forgotpasswordwords").hide();
			$("#loginwords").hide();
		}
	</script>



	<script type="text/javascript">
		function submitform()
		{
			var email = $('#loginEmail').val();
			var password = $('#loginPassword').val();

			 $.ajax({
			  type: 'POST',
			  url: '<?=$url;?>/controller/user.controller.php', 
			  data: {action:'login',email:email, password:password},
			  success: function(res){
			  	
			    if (res == "valid") {
			          location.href = "<?=$url; ?>/dashboard.php";
			    }else{
			        $("#loginInfo").show();
			    }
			  }
			});
			

		}
	</script>

	<script type="text/javascript">
		function newpasswordfunc()
		{
			var pass1 = $("#newpass1").val();
			var pass2 = $("#newpass2").val();
			 var email = $("#forgotEmail").val();

			  if (pass1 != pass2) {

                                    $("#newCheck").show();
                                    $("#newCheck").html('Both password doesnt match');
                                }else{

                                    $("#newCheck").hide();


                                    $.ajax({
                                        type: 'POST',
                                        url: '<?=$url; ?>/controller/forgot.controller.php', 
                                        data: {action:'changepassword',email:email, pass:pass1},
                                        success: function(res){
                                            if (res == 'done') {
                                                location.reload();
                                            }
                                        }
                                    });



                                }

		}
	</script>

	<script type="text/javascript">
		function forgetpassword()
		{
			$("#loginRow").hide();
			$("#forgotpasswordwords").hide();
			$("#loginwords").show();
			$("#forgotRow").show();
			$("#payment-form").hide();
		}
	</script>

	<script type="text/javascript">
		function loginhere()
		{
			$("#loginRow").show();
			$("#forgotpasswordwords").show();
			$("#loginwords").hide();
			$("#forgotRow").hide();
			$("#payment-form").hide();
		}
	</script>
	<script type="text/javascript">
		function  submitForgotCode()
		{
			var code = $("#forgotCode").val();
			var email = $("#forgotEmail").val();
			$.ajax({
			    type: 'POST',
			    url: '<?=$url; ?>/controller/forgot.controller.php', 
			    data: {action:'checkcode',email:email, code:code},
			    success: function(res){
						
						 if (res == 'found') {

		                    $("#forgotRow").hide();
		                    $("#newPasswordRow").show();
		                    $("#codecheckError").hide();
		                    $("#codeRow").hide();
			            }else{
			            	$("#codecheckError").show();
			            	$("#codecheckError").html('Incorrect Code');
			            }


			    }
			});
		}
	</script>

	<script type="text/javascript">
		function submitforgotpassword()
		{
			var email = $("#forgotEmail").val();
			$.ajax({
			  type: 'POST',
			  url: '<?=$url; ?>/controller/forgot.controller.php', 
			  data: {action:'forgot',email:email},
			  success: function(res){

			  	$("#codeError").show();

			        if (res == 'sent') {

			        	$("#codeRow").show();
			        	$("#forgotRow").hide();
			        }else if (res == 'notsent') {
			        	$("#codeError").html('Some error Occured');
			        }else{
			        	$("#codeError").html('Email Not Found');

			        }

			  }
			});
		}
	</script>


	<script src="https://js.stripe.com/v3/"></script>


	<script type="text/javascript">
		// Create a Stripe client.
var stripe = Stripe('pk_test_9qxDTxk50XPjrLElngKJ42Gp');

// Create an instance of Elements.
var elements = stripe.elements();

// Custom styling can be passed to options when creating an Element.
// (Note that this demo uses a wider set of styles than the guide below.)
var style = {
  base: {
    color: '#32325d',
    fontFamily: '"Helvetica Neue", Helvetica, sans-serif',
    fontSmoothing: 'antialiased',
    fontSize: '16px',
    '::placeholder': {
      color: '#aab7c4'
    }
  },
  invalid: {
    color: '#fa755a',
    iconColor: '#fa755a'
  }
};

// Create an instance of the card Element.
var card = elements.create('card', {style: style});

// Add an instance of the card Element into the `card-element` <div>.
card.mount('#card-element');

// Handle real-time validation errors from the card Element.
card.addEventListener('change', function(event) {
  var displayError = document.getElementById('card-errors');
  if (event.error) {
    displayError.textContent = event.error.message;
    $("#card-errors").show();
  } else {
    displayError.textContent = '';
    $("#card-errors").hide();
  }
});

// Handle form submission.
var form = document.getElementById('payment-form');
form.addEventListener('submit', function(event) {
  event.preventDefault();

  stripe.createToken(card).then(function(result) {
    if (result.error) {
      // Inform the user if there was an error.
      var errorElement = document.getElementById('card-errors');
      errorElement.textContent = result.error.message;
    } else {
      // Send the token to your server.


      var email = $("#emailPayment").val();

      if (email == '') {

      	$("#card-errors").show();
      	$("#card-errors").html('Enter Your Correct Email Address');

      }else{

      	stripeTokenHandler(result.token);	
      }

      
    }
  });
});

// Submit the form with the token ID.
function stripeTokenHandler(token) {
 	
	
	var email = $("#emailPayment").val();
	var tokenid = token.id;
	var createdDate = token.created;
	var paymentType = token.type;
	var cardObject = token['card'];
	var country = cardObject.country;
	var brand = cardObject.brand;
	var amount = '25.00';

	$("#submitButtonPayment").html('Please wait');

	$.ajax({
	  type: 'POST',
	  url: '<?=$url; ?>/controller/payment.controller.php', 
	  data: {action:'payment',email:email, token:tokenid, created:createdDate, type:paymentType, country:country, brand:brand, amount:amount},
	  success: function(res){


	  		$("#submitButtonPayment").html('Submit Payment');

	  		var result = JSON.parse(res);
	  		var resu = result.result;

	  		if (resu == 'success') {


	  			$("#card-errors").hide();
	  			$("#card-success").show();
	  			$("#card-success").html('Payment Successful. Please Check Your Email');

	  		}else{

	  			var error = result.err;
	  			$("#card-errors").show();
	  			$("#card-errors").html(error)
	  			$("#card-success").hide();
	  		}



	  }
	});



}
	</script>



	</div>
</body>
</html>