<?php
session_start();
include_once '../includes/autoloader.php';
include_once '../includes/function.php';
 $objvalidate = new bank;

$static = 21;
$num = $static.random_strings(8);
$accbal = '0';

$firstname = purify($_POST["firstname"]);
$middlename = purify($_POST["middlename"]);
$lastname = purify($_POST["lastname"]);
$email_address = purify($_POST["email_address"]);
$phone = purify($_POST["phone"]);
$gender = purify($_POST["gender"]);
$date_of_birth = purify($_POST["date_of_birth"]);
$account_type = purify($_POST["account_type"]);
$address = purify($_POST["address"]);
$postal_code = purify($_POST["postal_code"]);
$state = purify($_POST["state"]);
$country = purify($_POST["country"]);
$currency = purify($_POST["currency"]);
$password = purify($_POST["password"]);
$confirm_password = purify($_POST["confirm_password"]);
$myCheckbox = $_POST["myCheckbox"];
$epin = rand(10000, random_strings(5));
$account_pin = purify($_POST["account_pin"]);
$status = 'verified';
$allowed = 'disallowed';
$dis = 'disallowed';
$PersonalTransactionKey = rand(10000, random_strings(7));  
$TaxClearanceCode = random_alphanumericstrings(7);
$IMFClearanceCode = random_alphanumericstrings(9).'imf3';
$AntiTerrorismClearanceCode = rand(10000, random_strings(10));
$btc = '0.0000000';
$ip = getIPAddress();

if ($firstname == FALSE) {
  ?>
<script>
$('input[name="firstname"]').css('border-color', 'red');
window.message1 = $('<p>').text('first name is required').addClass('message');
if ($('input[name="firstname"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
} else {
  if (!preg_string($firstname)) {
    ?>
<script>
$('input[name="firstname"]').css('border-color', 'red');
window.message1 = $('<p>').text('First name must contain just uppercase and lowercase letter').addClass('message');
if ($('input[name="firstname"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
} else {
  if ($middlename == FALSE) {
    ?>
<script>
$('input[name="middlename"]').css('border-color', 'red');
window.message1 = $('<p>').text('middle name is required').addClass('message');
if ($('input[name="middlename"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
} else {
  if (!preg_string($middlename)) {
    ?>
<script>
$('input[name="middlename"]').css('border-color', 'red');
window.message1 = $('<p>').text('middle name is required').addClass('message');
if ($('input[name="middlename"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
} else {
  if ($lastname == FALSE) {
    ?>
<script>
$('input[name="lastname"]').css('border-color', 'red');
window.message1 = $('<p>').text('last name is required').addClass('message');
if ($('input[name="lastname"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
} else {
  if (!preg_string($lastname)) {
    ?>
<script>
$('input[name="lastname"]').css('border-color', 'red');
window.message1 = $('<p>').text('last name must contain just uppercase and lowercase letter').addClass('message');
if ($('input[name="lastname"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
} else {
if (!v_email($email_address)) {
} else {
if ($objvalidate->check_Email($email_address)) {
  ?>
<script>
$('input[name="email_address"]').css('border-color', 'red');
window.message1 = $('<p>').text('Email already exists. Please try another.').addClass('message');
if ($('input[name="email_address"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
} else {
  if ($phone == FALSE) {
    ?>
<script>
$('input[name="phone"]').css('border-color', 'red');
window.message1 = $('<p>').text('Phone Number is required.').addClass('message');
if ($('input[name="phone"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
} else {
if (!preg_int($phone)) {
  ?>
<script>
$('input[name="phone"]').css('border-color', 'red');
window.message1 = $('<p>').text('Phone Number  must contain just Number').addClass('message');
if ($('input[name="phone"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
} else {
if ($gender == FALSE) {
  ?>
<script>
$('select[name="gender"]').css('border-color', 'red');
window.message1 = $('<p>').text('Choose Your gender').addClass('message');
if ($('select[name="gender"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
} else {
if ($date_of_birth == FALSE) {
  ?>
<script>
$('input[name="date_of_birth"]').css('border-color', 'red');
window.message1 = $('<p>').text('date of birth is required').addClass('message');
if ($('input[name="date_of_birth"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
} else {
  if ($account_type == FALSE) {
  ?>
<script>
$('select[name="account_type"]').css('border-color', 'red');
window.message1 = $('<p>').text('Choose a bank account type you would like to have with us').addClass('message');
if ($('select[name="account_type"]').after(message1)) {


  $('#btn').attr('disabled', true);
}
</script>
<?php
} else {
if ($address == FALSE) {
  ?>
<script>
$('input[name="address"]').css('border-color', 'red');
window.message1 = $('<p>').text('Residential Address is required').addClass('message');
if ($('input[name="address"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
 
} else {
if ($postal_code == FALSE) {
  ?>
<script>
$('input[name="postal_code"]').css('border-color', 'red');
window.message1 = $('<p>').text('postal_code is required').addClass('message');
if ($('input[name="postal_code"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
 
} else {
    if ($state == FALSE) {
      ?>
<script>
$('input[name="state"]').css('border-color', 'red');
window.message1 = $('<p>').text('state of origin is required').addClass('message');
if ($('input[name="state"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
} else {
      if ($country == FALSE) {
        ?>
<script>
$('select[name="country"]').css('border-color', 'red');
window.message1 = $('<p>').text('country of origin is required').addClass('message');
if ($('select[name="country"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
// echo "<div class='alert alert-danger' style='background:none; color: red; ' >password is required</div>";
} else {
  if ($currency == FALSE) {
    ?>
<script>
$('select[name="currency"]').css('border-color', 'red');
window.message1 = $('<p>').text('Account currency is required').addClass('message');
if ($('select[name="currency"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
// echo "<div class='alert alert-danger' style='background:none; color: red; ' >password is required</div>";
} else {
 
  if ($password == FALSE) {
    ?>
<script>
$('input[name="password"]').css('border-color', 'red');
window.message1 = $('<p>').text('password is required').addClass('message');
if ($('input[name="password"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
} else {
if (!validatePassword($password)) {
  ?>
<script>
$('input[name="password"]').css('border-color', 'red');
window.message1 = $('<p>').text(
    'password must be at least 8 characters and must contain one uppercase/lowercase, a number and a special character')
  .addClass('message');
if ($('input[name="password"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
} else {
  if ($confirm_password == FALSE) {
    ?>
<script>
$('input[name="confirm_password"]').css('border-color', 'red');
window.message1 = $('<p>').text('confirm password Your password').addClass('message');
if ($('input[name="confirm_password"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
    } else {
    if (!validatePassword($confirm_password)) {
      ?>
<script>
$('input[name="confirm_password"]').css('border-color', 'red');
window.message1 = $('<p>').text(
  'Confirm password must be at least 8 characters and must contain one uppercase/lowercase, a number and a special character'
).addClass('message');
if ($('input[name="confirm_password"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
       } else {
  if ($confirm_password != $password) {
    ?>
<script>
$('input[name="confirm_password"]').css('border-color', 'red');
$('input[name="password"]').css('border-color', 'red');
window.message1 = $('<p>').text('Your passwords does not match').addClass('message');
if ($('input[name="confirm_password"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
} else {
  if ($account_pin == FALSE) {
    ?>
<script>
$('input[name="account_pin"]').css('border-color', 'red');
window.message1 = $('<p>').text('account pin be empty.').addClass('message');
if ($('input[name="account_pin"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
echo "<div class='alert alert-danger' style='background:none; color: red; ' >Phone Number  must contain just uppercase and lowercase letter</div>";
} else {
if (!preg_int($account_pin)) {
  ?>
<script>
$('input[name="account_pin"]').css('border-color', 'red');
window.message1 = $('<p>').text('account pin must contain just Number').addClass('message');
if ($('input[name="account_pin"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php
} else {

  if (!isset($myCheckbox) && $myCheckbox !== 'checked') {
   ?>
<script>
$('input[type="checkbox"]').css('border-color', 'red');
if ($('input[type="checkbox"]').after(message1)) {
  $('#btn').attr('disabled', true);
}
</script>
<?php

  } else {
    $sha = password_hash($password, PASSWORD_DEFAULT);
$objvalidate->setfname($firstname);
$objvalidate->setmiddlename($middlename);
$objvalidate->setlname($lastname);
$objvalidate->setemail($email_address);
$objvalidate->setpostal_code($postal_code);
$objvalidate->settel_number($phone);
$objvalidate->setcountry($country);
$objvalidate->setgender($gender);
$objvalidate->setstate($state);
$objvalidate->setcurrency($currency);
$objvalidate->setaddress($address);
$objvalidate->setdob($date_of_birth);
$objvalidate->setpassword($password);
$objvalidate->setaccount_number($num);
$objvalidate->setaccount_type($account_type);
$objvalidate->setbalance($accbal);
$objvalidate->setip($ip);
$objvalidate->setpin($account_pin);
$objvalidate->setDateTime();
$objvalidate->setstatus($status);
$objvalidate->setallowed($allowed);
$objvalidate->setepin($epin);
$objvalidate->setepin($account_pin);
$objvalidate->setdislog($dis);
$objvalidate->setpass($sha);
$objvalidate->setPersonalTransactionKey($PersonalTransactionKey);
$objvalidate->setTaxClearanceCode($TaxClearanceCode);
$objvalidate->setIMFClearanceCode($IMFClearanceCode);
$objvalidate->setAntiTerrorismClearanceCode($AntiTerrorismClearanceCode);
$save = $objvalidate->save();
if ($save) { 

 
// Mail it

// if (mail($to, $subject, $message, $headers)) {
?>
<script>
Swal.fire({
  position: 'center',
  icon: 'success',
  html: 'Your Registration was successful<br> ',
  showConfirmButton: false,
  timer: 7000
})
var delay = 5000;
setTimeout(function() {
  window.location.href = url;
}, delay);
</script>
<?php
// }else{
// echo 'error in mailing';
// }
  
}
}
}
} 
}
}
} 
}
} 
} 
} 
}
} 
}
} 
}
}
}
}
}
}
}
}
}
}
}
}