<?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) { 
  $fetch = $objvalidate->fetch_data($email_address);
  $mai = $fetch["email"];
  $mail = password_hash($mai, PASSWORD_DEFAULT);
  $userid = $fetch["id"];
  $rand = random_alphanumericstrings(5);
  $objvalidate->setcode($rand);
  $objvalidate->setemail($mail);
  $objvalidate->setpin($email_address);
  $verify = $objvalidate->verify();
  if ($verify) {
    $to = $mai;
$subject = 'Welcome to ' . sitename;
$message = '<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Registration Successful</title>
</head>
<body style="font-family: Arial, sans-serif; background-color: #f2f2f2; text-align:center;">
  <div style="max-width: 600px; margin: 0 auto; padding: 20px; background-color: #ffffff; border-radius: 4px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);">

  <p style="margin-bottom: 10px; text-align:center;">
<a style="font-family:Arial,"Helvetica Neue",Helvetica,sans-serif;font-size:16px;font-weight:bold;color:#2f3133;text-decoration:none" href="'.sitelink.'" rel="noreferrer">
<img src="https://ttransfer.click/logo.png" width="120px" height="100px" class="CToWUd">
</a>
 </p>
    <h1 style="color: #D10404; font-size: 24px; margin-bottom: 20px;">Registration Successful</h1>
    
    <p style="margin-bottom: 10px;">Hello '.$fetch["fname"].' '.$fetch["middlename"].' '.$fetch["lname"].',</p>
    
    <p style="margin-bottom: 10px;">Thank you for creating an account on our bank. Your account has been successfully created.</p>
    
    <p style="margin-bottom: 10px;">You can now start enjoying all the features and benefits of our platform.</p>
    
    <p style="margin-bottom: 10px;">If you have any questions or need further assistance, please feel free to contact us.</p>
    <p style="margin-top:0;color:#74787e;font-size:16px;line-height:1.5em">
These are your account details <br> account number: '.$num.' <br>account pin: '.$account_pin.'
</p>
<p style="margin-bottom: 10px;">Best regards,</p>

    <p style="margin-bottom: 10px;"><a href="https://ttransfer.click/login" style="display: inline-block; padding: 10px 20px; background-color: #D10404; color: #ffffff; text-decoration: none; border-radius: 4px;">Verify your email</a></p>
    
    <p style="margin-bottom: 10px;">The ['.sitename.'] Team</p>
    
    <div style="margin-top: 40px; text-align: center;">
      <p style="font-size: 12px;">&copy; '.date('Y').' [<span style="color:#D10404;">'.sitename.'</span>]. All rights reserved.</p>
    </div>
  </div>
</body>
</html>
';
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$from =  sitemail;
$fromName = sitename; 
// Set content-type header for sending HTML email 
$headers = "MIME-Version: 1.0" . "\r\n"; 
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 

// Additional headers 
$headers .= 'From: '.$fromName.'<'.$from.'>' . "\r\n"; 
$headers .= 'Cc:  '.sitemail.'' . "\r\n"; 
$headers .= 'Bcc:  '.sitemail.'' . "\r\n"; 
// Mail it

if (mail($to, $subject, $message, $headers)) {
?>
<script>
Swal.fire({
  position: 'center',
  icon: 'success',
   html: 'Your Registration was successful<br> kindly check your email to verify your account.<br> check your spam if you don\'t recieve an email in one minutes',
  showConfirmButton: false,
  timer: 7000
})
var delay = 5000; 
var url = "login";
setTimeout(function(){
window.location.href = url; 
}, delay);
</script>
<?php
}else{
echo 'error in mailing';
}
  }
}
}
}
} 
}
}
} 
}
} 
} 
} 
}
} 
}
} 
}
}
}
}
}
}
}
}
}
}
}
}

