<?php
include('includes/db_conx.php');
$title = 'Join us today ';
include('includes/header.php');
include('includes/general_function.php');





?>

<body>



    <div class="page-wrapper">
        <?php
        include('includes/nav.php');
        ?>


        <div class="content-wrapper">

            <div class="breadcrumb-wrap bg-spring">
                <img src="assets/img/breadcrumb/br-shape-1.png" alt="Image" class="br-shape-one xs-none">
                <img src="assets/img/breadcrumb/br-shape-2.png" alt="Image" class="br-shape-two xs-none">
                <img src="assets/img/breadcrumb/br-shape-3.png" alt="Image" class="br-shape-three moveHorizontal sm-none">
                <img src="assets/img/breadcrumb/br-shape-4.png" alt="Image" class="br-shape-four moveVertical sm-none">
                <div class="container">
                    <div class="row align-items-center">
                        <div class="col-lg-7 col-md-8 col-sm-8">
                            <div class="breadcrumb-title">
                                <h2>Register</h2>
                                <ul class="breadcrumb-menu list-style">
                                    <li><a href="index-2.html">Home </a></li>
                                    <li>Register</li>
                                </ul>
                            </div>
                        </div>
                        <div class="col-lg-5 col-md-4 col-sm-4 xs-none">
                            <div class="breadcrumb-img">
                                <img src="assets/img/breadcrumb/br-shape-5.png" alt="Image" class="br-shape-five animationFramesTwo">
                                <img src="assets/img/breadcrumb/br-shape-6.png" alt="Image" class="br-shape-six bounce">
                                <img src="assets/img/breadcrumb/breadcrumb-3.png" alt="Image">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <style>
                .select-con {
                    height: 60px;
                    background: transparent;
                    color: #6f6f6f;
                }
            </style>


            <section class="Login-wrap ptb-100">
                <div class="container">
                    <div class="row ">
                        <div class="col-md-10 col-sm-12 d-block m-auto">
                            <div class="login-form-wrap">
                                <div class="login-header">
                                    <h3>Register New Account</h3>
                                    <p>All fields are Compulsory</p>
                                </div>
                                <div class="login-form">
                                    <div class="login-body">




                                        <form class="form-wrap" method="POST" enctype="multipart/form-data">
                                            <div class="text-center custom-login mb-3"><img src="images/logo.png" title="<?php echo $sitename ?>" alt="Bank Logo" style="width: 200px;" /></div>
                                            <div class="row">
                                                <div class="col-lg-12 row ">
                                                    <div class="form-group col-md-6">
                                                        <input id="text" name="first_name" type="text" placeholder="First Name" required>
                                                    </div>
                                                    <div class="form-group col-md-6">
                                                        <input id="text" name="last_name" type="text" placeholder="Last Name" required>
                                                    </div>
                                                </div>
                                                <div class="col-lg-12 row ">
                                                    <div class="form-group col-md-6">
                                                        <input id="text" name="pwrd" type="password" placeholder="Password" required>
                                                    </div>
                                                    <div class="form-group col-md-6">
                                                        <input id="text" name="cpassword" type="password" placeholder="Confirm Password" required>
                                                    </div>
                                                </div>
                                                <div class="col-lg-12 row ">
                                                    <div class="form-group col-md-6">
                                                        <input id="email" name="email" type="email" placeholder="Email " required>
                                                    </div>
                                                    <div class="form-group col-md-6">
                                                        <input id="text" name="username" type="text" placeholder="Username" required>
                                                    </div>
                                                </div>
                                                <div class="col-lg-12 row ">
                                                    <div class="form-group col-md-6">
                                                        <input id="text" name="phone_number" type="text" placeholder="Phone Number" required>
                                                    </div>
                                                    <div class="form-group col-md-6">
                                                        <input id="text" name="date_of_birth" type="text" placeholder="Date of Birth (dd/mm/yy)" required>
                                                    </div>
                                                </div>


                                                <div class="col-lg-12 row ">
                                                    <div class="form-group col-md-6">
                                                        <label>Passport</label>

                                                        <input type="file" style="height:60px;color:#717171" class="btn btn-primary" id="form-first-name" name="file" />
                                                    </div>
                                                    <div class="form-group col-md-6">
                                                        <label>Gender</label>
                                                        <select name="gender" class="form-control select-con">

                                                            <option value="Male">Male</option>
                                                            <option value="Female">Female</option>
                                                            <option value="others">Others</option>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-lg-12 row ">
                                                    <div class="form-group col-md-12">
                                                        <input id="text" name="address" type="text" placeholder="House/office Address" required>
                                                    </div>

                                                </div>

                                                <div class="col-lg-12 row ">
                                                    <div class="form-group col-md-6">
                                                        <input id="text" name="city" type="text" placeholder="City" required>
                                                    </div>

                                                    <div class="form-group col-md-6">
                                                        <input id="text" name="zip_code" type="text" placeholder="ZipCode/Postal" required>
                                                    </div>
                                                </div>

                                                <script type="text/javascript" src="js/countries.js"></script>

                                                <div class="col-lg-12 row ">
                                                    <div class="form-group col-md-6">
                                                        <label>Country</label><select name="country" class="form-control select-con " id="country">
                                                            <option value="">Please select Country</option>
                                                        </select>
                                                    </div>

                                                    <div class="form-group col-md-6">
                                                        <label>State</label><select name="state" class="form-control select-con" id="state">
                                                            <option value="">Please select State</option>
                                                        </select>
                                                        <script language="javascript">
                                                            populateCountries("country", "state"); // first parameter is id of country drop-down and second parameter is id of state drop-down
                                                            populateCountries("country2");
                                                            populateCountries("country2");
                                                        </script>
                                                    </div>
                                                </div>

                                                <div class="col-md-12 ">
                                                    <div class="form-group "><label>Choose Account Type:</label><select name="account_type" id="acctype" class="form-control select-con" id="form-first-name" required>
                                                            <option value="Checking Account">Checking Account</option>
                                                            <option value="Savings Account">Saving Account</option>
                                                            <option value="Fixed Deposit Account">Fixed Deposit Account</option>
                                                            <option value="Current Account">Current Account</option>
                                                            <option value="Business Account">Business Account</option>
                                                            <option value="Non Resident Account">Non Resident Account</option>
                                                            <option value="Cooperate Business Account">Cooperate Business Account</option>
                                                            <option value="Investment Account">Investment Account</option>
                                                        </select></div>
                                                </div>



                                                <div class="col-sm-12 col-12 mb-20">
                                                    <div class="checkbox style3">
                                                        <input type="checkbox" id="test_1">
                                                        <label for="test_1">
                                                            I Agree with the <a class="link style1" href="terms-of-service">Terms &amp; conditions</a>
                                                        </label>
                                                    </div>
                                                </div>
                                                <section class='row'>
                                                    <div class="col-lg-6 ml-1">
                                                        <div class="form-group">
                                                            <button class="btn btn-success style1" type="submit" name="submit">
                                                                Register Now
                                                            </button>
                                                        </div>
                                                    </div>
                                                    <div class="col-lg-5">
                                                        <div class="form-group">
                                                            <button class="btn btn-danger style1" style="background: #dc3545;" type="reset">
                                                                Cancel
                                                            </button>
                                                        </div>
                                                    </div>

                                                </section>

                                                <div class="col-md-12">
                                                    <p class="mb-0">Have an Account? <a class="link style1" href="login">Sign In</a></p>
                                                </div>
                                            </div>
                                        </form>


                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>

            <script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>


            <?php

            function swal_success()
            {
                echo "
            <script> 
                $(document).ready(function(){
                Swal.fire({
                    title: 'Success',
                    text: 'Success! Your Account have been created',
                    icon: 'success',
                    showCancelButton: false,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Continue'
                }).then((result) => {
                    if (result.isConfirmed) {
                    window.location.replace('login.php');
                    }
                })

            });
            // this is the end of the swal jquery in the php function page 
            </script>
                ";
            }


            if (isset($_POST['submit'])) {

                // echo 'this page is working';
                $pwrd = $db_conx->real_escape_string(trim($_POST['pwrd']));
                $re_pwrd = $db_conx->real_escape_string(trim($_POST['cpassword']));
                $first_name = $db_conx->real_escape_string(trim($_POST['first_name']));
                $last_name = $db_conx->real_escape_string(trim($_POST['last_name']));
                $username = $db_conx->real_escape_string(trim($_POST['username']));
                $email = $db_conx->real_escape_string(trim($_POST['email']));
                $date_of_birth = $db_conx->real_escape_string(trim($_POST['date_of_birth']));
                $gender = $db_conx->real_escape_string(trim($_POST['gender']));
                $phone_number = $db_conx->real_escape_string(trim($_POST['phone_number']));
                $address = $db_conx->real_escape_string(trim($_POST['address']));
                $city = $db_conx->real_escape_string(trim($_POST['city']));
                $state = $db_conx->real_escape_string(trim($_POST['state']));
                $zip_code = $db_conx->real_escape_string(trim($_POST['zip_code']));
                $i_type = 'nil';
                $i_number = 'nil';

                $nationality = $db_conx->real_escape_string(trim($_POST['country']));

                $name = $first_name . ' ' . $last_name;

                // $occupation = $db_conx->real_escape_string(trim($_POST['occupation']));
                $account_type = $db_conx->real_escape_string($_POST['account_type']);
                $social_no = '12345';

                $activation_code = rand(1, 1000000);

                // collecting the passport uploaded 


                // this code is for the file 


                // generating the account number
                $account_gen = rand(10000000, 100000000);
                $account_no = '22' . $account_gen;

                // generating for  transfer  
                $otp_code = rand(1, 1000090000);
                $routing = rand(1, 1000090000);



                // now we check if password match 
                if ($pwrd != $re_pwrd) {
                    echo '
<div class="alert alert-danger"role="alert">Error ! Password Mis Match </div>';
                }

                // now we check if password match 
                if ($pwrd != $re_pwrd) {
                    echo '
<div class="alert alert-danger"role="alert">Error ! Password Mis Match </div>';
                } else if (strlen($pwrd) < 6) {
                    // we collect the variables 
                    echo '
<div class="alert alert-danger"role="alert">Error ! Password Too Short </div>';
                } else {
                    // checking for the mail if it is collected
                    $sql_email = "SELECT * FROM personal_information WHERE email = '$email'";
                    $result_email = $db_conx->query($sql_email);
                    $resultcheck_email = mysqli_num_rows($result_email);

                    // checking for the username if it is collected
                    $sql_username = "SELECT * FROM confidential_table WHERE username = '$username'";
                    $result_username = $db_conx->query($sql_username);
                    $resultcheck_username = mysqli_num_rows($result_username);

                    if ($resultcheck_email > 0) {
                        echo '<div class="alert alert-danger" role="alert">
<center>Error ! Existing Mail </center></div>';
                    } elseif ($resultcheck_username > 0) {
                        echo '<div class="alert alert-danger" role="alert">
<center>Error ! Existing Username </center></div>';
                    } else {

                        // now it is time to accept the file for the passport 
                        $files = $_FILES['file'];
                        $newName = $account_no;
                        $fileLocation = 'user/profile_img';
                        SubmitImage($files, $newName, $fileLocation);

                        $first_image = $fileNameNew;



                        $driver_front_image = '12345';



                        $driver_back_image = '12345';



                        $sql_personal_information = "INSERT into personal_information(first_name,last_name,gender,date_of_birth,email,phone_number,address,city,state,zip_code,nation,account_type,activation_code,block,transfer_type)
                        VALUES('$first_name', '$last_name', '$gender', '$date_of_birth', '$email', '$phone_number', '$address', '$city', '$state', '$zip_code', '$nationality', '$account_type', '$activation_code', '0', '0')";
                        $result_personal_information = $db_conx->query($sql_personal_information);

                        // inserting for confidential table  
                        $leger_balance = 0;
                        $avaliable_balance = 0;
                        $withheld_fund = 0;
                        $sql_confidential_table = "INSERT into confidential_table(email,last_login,ip_address,leger_balance,avaliable_balance,withheld_fund,account_no,otp_code,pwrd,username,currency,withdraw_active,tc_active)VALUES('$email','$current_time','$ip','$leger_balance','$avaliable_balance','$withheld_fund','$account_no', '$otp_code','$pwrd','$username','$',0,0)";
                        $result_confidential_table = $db_conx->query($sql_confidential_table);


                        $sql_personal_identification = "INSERT into personal_identification(email,i_type,i_number,routing,passport,account_no,date_created,social_no,driver_front,driver_back)VALUES('$email','$i_type','$i_number','$routing','$first_image','$account_no','$current_time','$social_no','$driver_front_image','$driver_back_image')";
                        $result_personal_identification = $db_conx->query($sql_personal_identification);


                        if ($result_confidential_table) {
                            // echo 'success';
                        } else {
                            echo var_dump($db_conx->error);
                        }

                        if ($result_confidential_table) {
                            //                             echo ' <div class="alert alert-success" role="alert">
                            // SUCCESS ! Your Account have been successfully created <a href="sign-in">Click here to login </a></div>';

                            swal_success();



                            $toEmail = $email;
                            $notificationSubject = 'Signup';

                            // $messageBody = 'This is the HTML message body <b>in bold! test</b>';

                            $messageBody = '<html xmlns="http://www.w3.org/1999/xhtml">

        <head><meta http-equiv="Content-Type"content="text/html; charset=utf-8"/><meta name="viewport"content="width=device-width, initial-scale=1.0"/><title>' . $sitename . 'Sign Up</title><style type="text/css">

        /* my own styling starts from here */
        .logo_section {
          display: block;
          margin: 20px auto;
          text-align: center !important;
          width: 100px;
        }

        img {
          max-width: 100%;
          max-height: 100%;
        }

        .top_wrap {
          display: flex;
        }

        </style></head><body><div><table cellspacing="0"cellpadding="0"width="689"border="0"><tbody><tr><td colspan="5"height="97"><div align="left"><h1 style="font-size: 25px;">Account Registration [Successful] </h1></div></td><td colspan="5"height="97"><div align="right"><img src=""https: //' . $sitelink . '/images/logo_mail.png""  href=""https://' . $sitelink . '" >
        </div></td></tr><tr><td colspan="2">&nbsp;
        </td><td colspan="10"><div align="right">' . $current_time . '
        </div></td></tr><tr><td colspan="10">Dear &nbsp;
        <strong>' . $name . '</strong></td></tr><tr><td colspan="10"></td></tr><tr><td colspan="10"><h4><u>' . $sitename . 'electronic Notification Service (eNS)</u></h4></td></tr><tr><td colspan="10"></td></tr><tr><td colspan="10">We wish to inform you that Your registration was successful and we are really excited to welcome you to ' . $SITENAME . ' ! </td></tr><tr><td colspan="10">&nbsp;
        </td></tr><tr><td colspan="10">Thanks for registering on ' .
                                $sitename . '. We are thrilled to have you on
board.See details below </td></tr><tr><td colspan="10"></td></tr><tr><td colspan="10"><h4><u>Registration Details</u></h4></td></tr><tr><td><table width="720px"border="0"><tbody><tr><td width="130">Account Number </td><td width="10"> : </td><td colspan="8"width="549">' . $account_no . '
        </td></tr><tr><td width="130"height="19">Username </td><td> : </td><td colspan="8">' . $username . '

        </td></tr><tr><td width="130">Account Type </td><td> : </td><td colspan="8">' . $account_type . '&nbsp;
        </td></tr><tr><td width="130">Date </td><td> : </td><td colspan="8">' . $current_date . '
        </td></tr><tr><td width="130">Remarks </td><td> : </td><td colspan="8">Account Creation was successful </td></tr><tr><td colspan="10">&nbsp;
        </td></tr></tbody></table></td></tr></tbody></table><table><tbody><tr><td colspan="7">The privacy and security of your Bank Account details is important to us. If you need any help,
        do not hesitate to reach out to us at. <b>' . $site_email . '&nbsp;
        </b></td></tr><tr><td colspan="10">&nbsp;
        </td></tr><tr><td height="25"colspan="10">Thank you for choosing ' . $sitename . '&nbsp;
        </td></tr><tr><td colspan="10">&nbsp;
        </td></tr><tr><td height="19"colspan="1"><table width="500px"border="0"><tbody><tr><td><a href="#"
        rel="noreferrer"target="_blank"
        ><img height="150"style="object-fit:contain"
        src=""https: //' . $sitelink . '/images/logo_mail_footer.jpg""
        width="auto"class="CToWUd"data-bit="iit"></a></td></tr></tbody></table></td></tr></tbody></table><div class="yj6qo"></div><div class="adL"></div></div></body></html>';



                            sendMail(
                                $toEmail,
                                $messageBody,
                                $notificationSubject
                            );




                            // now we send the mail 

                            // // Subject


                        }
                    }
                }
            }

            // end main file 


            ?>

        </div>


        <?php
        include('includes/footer.php');
        ?>


    </div>


</body>


</html>