<?php 
include ('database.php');
session_start();


if(isset($_POST['submit']));
{
    $firstname = mysqli_real_escape_string($connection, $_POST['firstname']);
    $lastname = mysqli_real_escape_string($connection, $_POST['lastname']);
    $email = mysqli_real_escape_string($connection, $_POST['email']);
    $password = mysqli_real_escape_string($connection, $_POST['password']);
	 $phone = mysqli_real_escape_string($connection, $_POST['phone']);
	  $country = mysqli_real_escape_string($connection, $_POST['country']);
      $gender = mysqli_real_escape_string($connection, $_POST['gender']);
      $dob = mysqli_real_escape_string($connection, $_POST['dob']);
      $profile = mysqli_real_escape_string($connection, $_FILES["idcard"]['name']);
    $idcard= time().'_'.$profile;
	
	  $profile2 = mysqli_real_escape_string($connection, $_FILES["idcardback"]['name']);
    $idcardback= time().'_'.$profile2;
	$profile = "profile.png";
    $vcode = rand(100000,999999);
	$number = rand(1000000000,9999999999);
    $name = "$firstname $lastname";
    $vat = strtoupper(substr(str_shuffle('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 6));
    $imt = rand(100000,999999);
    //check email
  $check_email_query = "SELECT email FROM users WHERE email='$email' LIMIT 1";
  $check_email_query_run = mysqli_query($connection, $check_email_query);
 
 if(mysqli_num_rows($check_email_query_run)> 0)
  {
 	 $_SESSION['status'] = "<h5 style='padding:8px; background: #fe8b8e; border-radius: 10px; color: #fff; text-align: center;'>Acoount E-mail already exists</h5>";
 	 header("location: ../../register.php");
  }
 else
 {
	 //register users data
	 $query = "INSERT INTO `users` (`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`, `dob`, `imt`, `vat`) VALUES (current_timestamp(), NULL, '$name', '$email', '$number', '$password', '$phone', '$address', '$country', '$gender', 'profile.png', '$vcode', '0', '0', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '0.00', '$idcard', '$idcardback', '1', '0', '0', '0', '0', '$dob', '$imt', '$vat')";
     $query_run = mysqli_query($connection, $query);
 }
 if($query_run)
 {
    move_uploaded_file($_FILES["idcard"]["tmp_name"], "../images/user/".$idcard);
		
    move_uploaded_file($_FILES["idcardback"]["tmp_name"], "../images/user/".$idcardback);
	 header("location:email.php?email=$email&vcode=$vcode"); 
 }
 else
 {
$_SESSION['status'] = "<h5 style='padding:8px; background: #fe8b8e; border-radius: 10px; color: #fff; text-align: center;'>Acoount E-mail already exists</h5>";
 	 header("location: ../../register.php");	 
 }
}
?>