<?php




$pageName  = "Create Profile";
include($_SERVER['DOCUMENT_ROOT'] . "/admin/layout/header.php");

// Ofofonobs Developer WhatsAPP +2348114313795


// Bank Script Developer - Use For Educational Purpose Only

// Other scripts Available


if (isset($_POST['register'])) {
     $userid = "1202" . (substr(number_format(time() * rand(), 0, '', ''), 0, 6));
    $acct_type = $_POST['acct_type'];
    $acct_fullname = $_POST['acct_fullname'];
    $acct_status = "active";
    $acct_country = $_POST['acct_country'];
    $acct_email = $_POST['acct_email'];
    $acct_phone = $_POST['acct_phone'];
    $acct_password = inputValidation($_POST['acct_password']);
    $confirm_password = inputValidation($_POST['confirm_password']);
    $acct_dob = $_POST['acct_dob'];

    if ($acct_password !== $confirm_password) {
        toast_alert('error', 'Password not matched');
    } else {
        //checking exiting email

        $usersVerified = "SELECT * FROM users WHERE acct_email=:acct_email or acct_phone=:acct_phone";
        $stmt = $conn->prepare($usersVerified);
        $stmt->execute([
            'acct_email' => $acct_email,
            'acct_phone' => $acct_phone
        ]);



        if ($stmt->rowCount() > 0) {

            toast_alert('error', 'Email or Phone Number Already Exit');
        } else {
        
            //INSERT INTO DATABASE
            $registered = "INSERT INTO users (acct_fullname,acct_email,acct_password,userid,acct_status,acct_phone,acct_type,acct_gender,acct_country,acct_dob) VALUES(:acct_fullname,:acct_email,:acct_password,:userid,:acct_status,:acct_phone,:acct_type,:acct_country,:acct_dob)";
            $reg = $conn->prepare($registered);
            $reg->execute([
                'acct_fullname' => $acct_fullname,
                'lastname' => $lastname,
                'acct_email' => $acct_email,
                'acct_password' => password_hash((string)$acct_password, PASSWORD_BCRYPT),
                'userid' => $userid,
                'acct_status' => $acct_status,
                'acct_phone' => $acct_phone,
                'acct_type' => $acct_type,
                'acct_country' => $acct_country,
                'acct_dob' => $acct_dob
            ]);

            if (true) {


                // $full_name = $firstname . " " . $lastname;
                // $APP_NAME = WEB_TITLE;
                // $APP_URL = WEB_URL;
                // $SITE_ADDRESS = $page['url_address'];
                // $message = $sendMail->AdminRegisterMsg($full_name, $acct_no, $acct_status, $APP_NAME, $APP_URL, $SITE_ADDRESS);
                // // User Email
                // $subject = "Welcome to " . "-" . $APP_NAME;
                // $email_message->send_mail($acct_email, $message, $subject);

                $msg1 = "
                <div class='alert alert-warning'>
                
                <script type='text/javascript'>
                     
                        function Redirect() {
                        window.location='./users.php';
                        }
                        document.write ('');
                        setTimeout('Redirect()', 3000);
                     
                        </script>
                        
                <center><img src='../assets/images/loading.gif' width='180px'  /></center>
                 
                <center>	<strong style='color:black;'>Registered, Welcome Email Sent...
                       </strong></center>
                <center>	<strong style='color:black;'>Please Wait while we redirect to login...
                       </strong></center>
                  </div>
                ";
            } else {
                toast_alert('error', 'Sorry something went wrong');
            }
        }
    }
}



 
?>

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            Create New User
        </h1>
        <ol class="breadcrumb">
            <li><a href="./dashboard.php"><i class="fa fa-dashboard"></i> Dashboard</a></li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">

        <!-- SELECT2 EXAMPLE -->
        <form method="POST" enctype="multipart/form-data" action="">
            <div class="box box-default">
                <div class="box-header with-border">
                    <div class="box-tools pull-right">
                        <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
                    </div>
                </div>
                <!-- /.box-header -->
                <div class="box-body">
                    <div class="row">

                        <?php if (isset($msg1)) echo $msg1; ?>

                        <div class="col-md-6">

                            <div class="form-group">
                                <label for="exampleInputEmail1">Full Name</label>
                                <input type="text" name="acct_fullname" required class="form-control" placeholder="Full Name">

                            </div>
                           
                            <!-- /.form-group -->
                            
                            <div class="form-group">
                                <label for="exampleInputEmail1">Email address</label>
                                <input type="email" class="form-control" required placeholder="Enter Email" name="acct_email">
                            </div>
                            
                             <div class="form-group">
                                <label for="exampleInputEmail1">Phone Number</label>
                                <input type="text"  required  minlength="8"  autocomplete="off" placeholder="+1 440 941 4254" class="form-control wizard-required" name="acct_phone">
                            </div>
                            
                            
                             <div class="form-group">
                                    <label class="form-label">Account Type</label>
                                    <select name="acct_type" required class="form-control" data-width='100%'>
                                        <option value="">Select Account Type</option>
                                        <option value="Regular User">Regular User</option>
                                        <option value="Vip User">Vip User</option>
                                    </select>
                                </div>



                           

                            <!-- /.form-group -->
                        </div>
                        <!-- /.col -->
                        <div class="col-md-6">
                           
                           
                            <div class="form-group">
                                <label for="exampleInputEmail1">Date of Birth</label>
                                <input type="date" required class="form-control" name="acct_dob" placeholder="Date of birth">
                            </div>
                            <div class="form-group">
                                <label for="exampleInputEmail1">Balance</label>
                                <input type="number" required inputmode="numeric" required pattern="[0-9]+" maxlength="15" autocomplete="off" name="acct_balance" class="form-control" placeholder="Account Balance">
                            </div>
                           

                          

                           

                            <div class="form-group">
                                <label for="exampleInputEmail1">Password</label>
                                <input type="password" required class="form-control" name="acct_password" placeholder="Password">
                            </div>
                            <div class="form-group">
                                <label for="exampleInputEmail1">Confirm Password</label>
                                <input type="password" required class="form-control" name="confirm_password" placeholder="Confirm Password">
                            </div>
                           

                        </div>

                        <!-- /.col -->
                    </div>
                    <!-- /.row -->
                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                    <button type="submit" name="register" class="btn btn-primary">Create New Profile</button>
                </div>
            </div>
        </form>
        <!-- /.box -->



    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->


<?php
include($_SERVER['DOCUMENT_ROOT'] . "/admin/layout/footer.php");

?>