<?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: #fff;
		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://invata.io/new_assets/img/logofinal1.png" width="220" style="border-radius:0px !important;" alt="" />
				</div>



				

				<form action="#" method="post" id="loginRow" class="formRow">
					<p class="legend" style="color: #1CC7D0;padding-top: 20px;">Register Your Account<span class="fa fa-hand-o-down" style="color: #1CC7D0;"></span></p>
					<div class="alert alert-danger" id="paymentError" style="display: none;">
					</div>
					<div class="alert alert-success" id="paymentStatus" style="display: none;">
					</div>
					<div class="input">
						<input type="text" id="fn" placeholder="First Name" name="fn" required />
						<span class="fa fa-user"></span>
					</div>
					<div class="input">
						<input type="text" id="ln" placeholder="Last Name" name="ln" required />
						<span class="fa fa-user"></span>
					</div>
					<div class="input">
						<input type="email" id="email" placeholder="Email Address" name="email" required />
						<span class="fa fa-envelope"></span>
					</div>
					<div class="input">
						<input type="tel" id="phone" placeholder="Phone" name="phone" required />
						<span class="fa fa-phone"></span>
					</div>
					<div class="input">
						<select class="form-control" style="width: 100%;height: 45px;" id="pcar" name="pcar">
							<option value="0">Select Your Phone Carrier</option>
							<option value="@txt.att.net">AT&T</option>
							<option value="@tmomail.net">T-Mobile</option>
							<option value="@vtext.com">Verizon</option>
							<option value="@messaging.sprintpcs.com">number@messaging.sprintpcs.com</option>
							<option value="@vtext.com">XFinity Mobile</option>
							<option value="@vmobl.com">Virgin Mobile</option>
							<option value="@mmst5.tracfone.com">Tracfone</option>
							<option value="@mymetropcs.com">Metro PCS</option>
							<option value="@sms.myboostmobile.com">Boost Mobile</option>
							<option value="@sms.cricketwireless.net">Cricket</option>
							<option value="@text.republicwireless.com">Republic Wireless</option>
							<option value="@msg.fi.google.com">Google Fi</option>
							<option value="@email.uscc.net">U.S. Cellular</option>
							<option value="@message.ting.com">Ting</option>
							<option value="@mailmymobile.net">Consumer Cellular</option>
							<option value="@cspire1.com">C-Spire</option>
							<option value="@vtext.com">Page Plus</option>
						</select>
					</div>

					<div class="input">
						<input type="password" id="pw" placeholder="Password" name="pw" required />
						<span class="fa fa-unlock"></span>
					</div>
					<div class="input">
						<input type="password" id="pw2" placeholder="Confirm Password" name="pw2" required />
						<span class="fa fa-unlock"></span>
					</div>

					<?php 
						$token = "";
						if (isset($_GET['token'])) {
							# code...
							$token = $_GET['token'];
						}

					?>

					<div class="input">
						<input type="text" id="pt" placeholder="Payment Code" name="pt" value="<?=$token; ?>" required />
						<span class="fa fa-credit-card"></span>
					</div>
					<button id="signupp" onclick="submitform()" type="button" class="btn submit paymentButton">
						Sign Up
					</button>
				</form>


			</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 submitform()
	{
		var pt = $("#pt").val();
		var fn = $("#fn").val();
		var ln = $("#ln").val();
		var email = $("#email").val();
		var pw = $("#pw").val();
		var pw2 = $("#pw2").val();
		var ph = $("#phone").val();
		var pcar = $("#pcar").val();

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

		$.ajax({
		  type: 'POST',
		  url: '<?=$url; ?>/controller/forgot.controller.php', 
		  data: {action:'checkpt',pt:pt},
		  success: function(res){

		  		var result = JSON.parse(res);

		  		var resu = result.result;

		  		if (resu == 'notfound') {


		  			$("#paymentSuccess").hide();
		  			$("#paymentError").show();
		  			$("#paymentError").html('Please check your payment code');
		  			$("#signupp").html('Sign up');


		  		}else{

		  			var paymentStatus = result.status;

		  			if (paymentStatus == '1') {

		  				$("#paymentError").show();
		  				$("#paymentStatus").hide();
		  				$("#paymentError").html('Your payment code has already been used');
		  				$("#signupp").html('Sign up');

		  			}else{



		  				if (pw != pw2) {

			  				$("#paymentError").show();
			  				$("#paymentStatus").hide();
			  				$("#paymentError").html('Your password doesn\'t match');
			  				$("#signupp").html('Sign up');

		  				}else{


							$.ajax({
							  type: 'POST',
							  url: '<?=$url; ?>/controller/forgot.controller.php', 
							  data: {action:'checkemail',email:email},
							  success: function(res){

							  		var json = JSON.parse(res);
							  		var jsonRes = json.result;

							  		if (jsonRes == 'found') {

										$("#paymentError").show();
										$("#paymentStatus").hide();
										$("#paymentError").html('Email already exsist');
							  			$("#signupp").html('Sign up');

							  		}else{

										$.ajax({
										  type: 'POST',
										  url: '<?=$url; ?>/controller/forgot.controller.php', 
										  data: {action:'register',fn:fn, ln:ln, email:email,pw:pw, pt:pt, ph:ph, pcar:pcar},
										  success: function(res){

										  	var result = JSON.parse(res);
										  	var resu = result.result;
										  	if (resu == 'success') {

												$("#paymentError").hide();
												$("#paymentStatus").show();
												$("#paymentStatus").html('Registration Successfull');
												$("#signupp").html('Sign up');

										  	}else{

												$("#paymentError").show();
												$("#paymentStatus").hide();
												$("#paymentError").html('Some error occured');
										  		$("#signupp").html('Sign up');
										  	}

										  }
										});



							  		}

							  }
							});




		  				}



		  			}

		  		}


		  }
		});


	}

</script>









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