<?php ob_start();
require_once('../setup.php'); ?>
<?php
if (isset($_GET['e']) and isset($_GET['r'])) {
  $email = base64_decode($_GET['e']);
  $random_number = base64_decode($_GET['r']);
} else {
  header("Location: register");
  exit();
}
?>
<!DOCTYPE html>
<html lang="en">

<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title><?= $main_capital_name; ?></title>
  <!-- plugins:css -->
  <link rel="stylesheet" href="vendors/feather/feather.css">
  <link rel="stylesheet" href="vendors/ti-icons/css/themify-icons.css">
  <link rel="stylesheet" href="vendors/css/vendor.bundle.base.css">
  <!-- endinject -->
  <!-- Plugin css for this page -->
  <!-- End plugin css for this page -->
  <!-- inject:css -->
  <link rel="stylesheet" href="css/vertical-layout-light/style.css">
  <!-- endinject -->
  <link rel="shortcut icon" href="../assets/images/logo.png" />
</head>

<body>
  <div class="container-scroller">
    <div class="container-fluid page-body-wrapper full-page-wrapper">
      <div class="content-wrapper d-flex align-items-center auth px-0">
        <div class="row w-100 mx-0">
          <div class="col-lg-4 mx-auto">
            <div class="auth-form-light text-left py-5 px-4 px-sm-5">
              <div class="brand-logo">
                <img src="../assets/images/logo.png" style="width: 50px; display: block; margin-left: auto; margin-right: auto;" alt="logo">
              </div>
              <h4 class="text-center"><?= $main_capital_name; ?></h4>
              <h5 class="font-weight-light text-center"><b>OTP VERIFICATION</b></h5>
              <hr>
              <div class="row">
                <div class="col-md-12">
                  <?php
                  if (isset($_POST['confirm'])) {
                    require_once("conn.php");
                    $verification_code = $_POST['verification_code'];
                    $random_number = $_POST['random_number'];
                    $email = $_POST['email'];
                    $roemail = base64_encode($email);

                    $account_number = rand(1111, 9999).date('ydh');

                    if($verification_code == $random_number){
                      $sql = "UPDATE accounts SET email_status='active', account_number='$account_number' WHERE email='$email'";
                      if ($dbconfig->query($sql) === TRUE) {
                        header("Refresh: 6; url=online-banking?e=$roemail");
                        echo '<div align="center" class=" alert alert-success"><b>Hurray!<br>Your application has been submitted.<br>Let\'s set up your Online Banking</b> <br><b>Hold - Redirecting...</b></div>';
                      }
                    } else {
                      echo '<div class="alert alert-danger text-center">Wrong Verification Code</div>';
                    }
                  }
                  ?>
                  <div class="alert alert-primary text-center">We've sent a verification code to your email address - <?= $email ?></div>
                </div>
              </div>
              <form class="pt-3" action="" method="POST">
                <div class="row">
                  <div class="col-md-12">
                    <div class="form-group">
                      <input type="hidden" name="email" value="<?= $email; ?>" required>
                      <input type="hidden" name="random_number" value="<?= $random_number; ?>" required>
                      <input type="text" class="form-control form-control-lg" id="exampleInputUsername1" placeholder="Enter Verification Code" name="verification_code" maxlength="6" value="<?php if (isset($_POST['verification_code'])) {
                                                                                                                                                                                                echo $_POST['verification_code'];
                                                                                                                                                                                              } ?>" required>
                    </div>
                  </div>
                </div>
                <div>
                  <button type="submit" name="confirm" class="btn btn-block btn-primary btn-lg font-weight-medium auth-form-btn">CONFIRM CODE</button>
                </div>
              </form>
            </div>
          </div>
        </div>
      </div>
      <!-- content-wrapper ends -->
    </div>
    <!-- page-body-wrapper ends -->
  </div>
  <!-- container-scroller -->
  <!-- plugins:js -->
  <script src="vendors/js/vendor.bundle.base.js"></script>
  <!-- endinject -->
  <!-- Plugin js for this page -->
  <!-- End plugin js for this page -->
  <!-- inject:js -->
  <script src="js/off-canvas.js"></script>
  <script src="js/hoverable-collapse.js"></script>
  <script src="js/template.js"></script>
  <script src="js/settings.js"></script>
  <script src="js/todolist.js"></script>
  <!-- endinject -->
  <?php include('../chat.php'); ?>
</body>

</html>
