<?php
/**
 * verify.php -- Verify page - Complete Profile
 */

include '../inc/config.inc.php'; // Configuration

ob_start();
session_start();

//date_default_timezone_set('Africa/Lagos');

error_reporting(E_ALL);
ini_set('display_errors', 1);

if ( !isset($_SESSION['user']) || $_SESSION["loggedin"] !== true || trim($_SESSION['user']) == '' ){
	header('Location: ' . $BASE_URL . 'signin');
	exit;
}

// User Details
$stmt = $db_con->prepare("SELECT * FROM users WHERE id=:user_id");
$stmt->execute(array(":user_id"=>$_SESSION['user']));
$userRow = $stmt->fetch(PDO::FETCH_ASSOC);

?>

<!doctype html>
<html lang="en-uk">
<head>
    <!-- Required meta tags -->
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta charset="utf-8">
    <meta name="description" content="">
    <meta name="keywords" content="investment, Forex, Trading, Bitcoin, Cryptocurrency, Global investment, Live Trade, Trading class, indics">
    <meta name="author" content="Paul HubWeb & Tech">
    <meta name="theme-color" content="#313131" />
    <!-- Site Properties -->
    <title>Verifications </title>
    <link rel="shortcut icon" href="../img/Signals-Alert-3.png" type="image/x-icon">
    <link rel="apple-touch-icon-precomposed" href="../img/Signals-Alert-3.png">
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <!-- Typography CSS -->
    <link rel="stylesheet" href="css/typography.css">
    <!-- Style CSS -->
    <link rel="stylesheet" href="css/style.css">
    <!-- Responsive CSS -->
    <link rel="stylesheet" href="css/responsive.css">
    <style>
        * {
            box-sizing: border-box;
        }

        body {
            margin: 0;
            font-family: Arial, Helvetica, sans-serif;
        }

        .header {
            overflow: none;
            background-color: none;
            padding: 20px 10px;
            padding-left: 5px;
            position: fixed;
        }

                /*.header a {
        float: center;
        width:30px;
        color: #fff;
        text-align: center;
        padding: 12px;
        text-decoration: none;
        font-size: 18px; 
        line-height: 25px;
        border-radius: 4px;
        background-color:rgb(196, 0, 0);
        border-color: rgb(196, 0, 0);
        }*/

        .header a.logo {
            font-size: 25px;
            font-weight: bold;
        }

                /*.header a:hover {
        background-color:  #010847;
        color: #fff;
        }*/

                /*.header a.active {
        background-color: dodgerblue;
        color: white;
        }*/

        .header-center {
            float: left;
        }

        @media screen and (max-width: 500px) {
            .header a {
                float: none;
                display: block;
                text-align: left;
            }

            .header-right {
                float: none;
            }
        }
    </style>

    <script src="../plugins/sweetalerts/promise-polyfill.js"></script>
    <link href="../plugins/sweetalerts/sweetalert.css" rel="stylesheet" type="text/css" />

    <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,600,700" rel="stylesheet" />
    <style>
        /*------ Google Font Style ------ */
        body {font-family:'Roboto'!important;}
    </style>

</head>
<body class="sidebar-main-active right-column-fixed">
    <!-- loader Start -->
    <!-- loader END -->
    <!-- Wrapper Start -->
    <div class="wrapper">
        <?php include 'navbar2.php' ?>
        <!-- Page Content  -->
        <div id="content-page" class="content-page" style="margin-top:90px;">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-sm-12 col-lg-12">
                        <div class="iq-card">
                            <div class="iq-card-header d-flex justify-content-between">
                                <div class="iq-header-title">
                                    <h4 class="card-title" style="font-family: 'Roboto'!important;">Account Verifications</h4>
                                </div>
                            </div>
                            <div class="iq-card-body">
                                <form id="form-wizard1" class="text-center mt-4" method="post" action="" enctype="multipart/form-data">
                                    <ul id="top-tab-list" class="p-0">
                                        <li class="active" id="account">
                                            <a href="javascript:void();">
                                                <i class="ri-lock-unlock-line"></i><span>Account</span>
                                            </a>
                                        </li>
                                        <li id="personal">
                                            <a href="javascript:void();">
                                                <i class="ri-user-fill"></i><span>Personal</span>
                                            </a>
                                        </li>
                                        <li id="payment">
                                            <a href="javascript:void();">
                                                <i class="ri-camera-fill"></i><span>Image</span>
                                            </a>
                                        </li>
                                        <li id="confirm">
                                            <a href="javascript:void();">
                                                <i class="ri-check-fill"></i><span>Finish</span>
                                            </a>
                                        </li>
                                    </ul>
                                    <!-- fieldsets -->
                                    <fieldset>
                                        <div class="form-card text-left">
                                            <div class="row">
                                                <div class="col-7">
                                                    <h3 class="mb-4">Account Information:</h3>
                                                </div>
                                                <div class="col-5">
                                                    <h2 class="steps">Step 1 - 4</h2>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label>Email: *</label>
                                                        <input type="email" class="form-control" required="required" name="email" value="<?= $userRow['email']; ?>" />
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label>Username: *</label>
                                                        <input type="text" class="form-control" required="required" name="username" value="<?= $userRow['username']; ?>" disabled>
                                                    </div>
                                                </div>
                                                <!--<div class="col-md-6">
                                                    <div class="form-group">
                                                        <label>Password: *</label>
                                                        <input type="password" required="required" class="form-control" name="pwd" placeholder="Password" maxlength="16" ng-minlength="8" required pattern=".{8,}" title="8 characters minimum" />
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <label>Confirm Password: *</label>
                                                        <input type="password" class="form-control" required="required" name="cpwd" placeholder="Confirm Password" maxlength="16" ng-minlength="8" pattern=".{6,}" title="8 characters minimum" />
                                                    </div>
                                                </div>-->
                                            </div>
                                        </div>
                                        <button type="button" name="next" class="btn btn-primary next action-button float-right" value="Next">Next</button>
                                    </fieldset>
                                    <fieldset>
                                        <div class="form-card text-left">
                                            <div class="row">
                                                <div class="col-7">
                                                    <h3 class="mb-4">Personal Information:</h3>
                                                </div>
                                                <div class="col-5">
                                                    <h2 class="steps">Step 2 - 4</h2>
                                                </div>
                                            </div>
                                            <div class="row align-items-center">
                                                <div class="form-group col-sm-6">
                                                    <label for="fname">Full Name:</label>
                                                    <input type="text" class="form-control" name="fullname" value="<?= $userRow['fullname']; ?>">
                                                </div>
                                                <!--<div class="form-group col-sm-6">
                                                    <label for="fname">First Name:</label>
                                                    <input type="text" class="form-control" id="fname" value="Barry">
                                                </div>
                                                <div class="form-group col-sm-6">
                                                    <label for="lname">Last Name:</label>
                                                    <input type="text" class="form-control" id="lname" value="Tech">
                                                </div>
                                                <div class="form-group col-sm-6">
                                                    <label for="uname">User Name:</label>
                                                    <input type="text" class="form-control" id="uname" value="Barry@01">
                                                </div>-->
                                                <div class="form-group col-sm-6">
                                                    <label for="cname">City:</label>
                                                    <input type="text" class="form-control" name="city" value="<?= $userRow['city']; ?>">
                                                </div>
                                                <div class="form-group col-sm-6">
                                                    <label class="d-block">Gender:</label>
                                                    <div class="custom-control custom-radio custom-control-inline">
                                                        <input type="radio" id="customRadio6" name="gender" class="custom-control-input" <? if ($userRow['gender']=='Male') echo 'checked'; ?> value="Male">
                                                        <label class="custom-control-label" for="customRadio6">Male</label>
                                                    </div>
                                                    <div class="custom-control custom-radio custom-control-inline">
                                                        <input type="radio" id="customRadio7" name="gender" class="custom-control-input" <? if ($userRow['gender']=='Female') echo 'checked'; ?> value="Female">
                                                        <label class="custom-control-label" for="customRadio7">Female</label>
                                                    </div>
                                                </div>
                                                <div class="form-group col-sm-6">
                                                    <label for="dob">Date Of Birth:</label>
                                                    <input class="form-control" name="dob" value="<?= $userRow['dob']; ?>" placeholder="YYYY-MM-DD">
                                                </div>
                                                <div class="form-group col-sm-6">
                                                    <label>Marital Status:</label>
                                                    <select class="form-control" name="marital_status">
                                                        <option value="Single" <? if ($userRow['marital_status']=='Single') echo 'selected'; ?>>Single</option>
                                                        <option value="Married" <? if ($userRow['marital_status']=='Married') echo 'selected'; ?>>Married</option>
                                                        <option value="Widowed" <? if ($userRow['marital_status']=='Widowed') echo 'selected'; ?>>Widowed</option>
                                                        <option value="Divorced" <? if ($userRow['marital_status']=='Divorced') echo 'selected'; ?>>Divorced</option>
                                                        <option value="Separated" <? if ($userRow['marital_status']=='Separated') echo 'selected'; ?>>Separated</option>
                                                    </select>
                                                </div>
                                                <div class="form-group col-sm-6">
                                                    <label>Age:</label>
                                                    <select class="form-control" name="age">
                                                        <option value="12 - 18" <? if ($userRow['age']=='12 - 18') echo 'selected'; ?>>12 - 18</option>
                                                        <option value="19 - 32" <? if ($userRow['age']=='19 - 32') echo 'selected'; ?>>19 - 32</option>
                                                        <option value="33 - 45" <? if ($userRow['age']=='33 - 45') echo 'selected'; ?>>33 - 45</option>
                                                        <option value="46 - 62" <? if ($userRow['age']=='46 - 62') echo 'selected'; ?>>46 - 62</option>
                                                        <option value="63 >" <? if ($userRow['age']=='63 >') echo 'selected'; ?>>63 > </option>
                                                    </select>
                                                </div>
                                                <div class="form-group">
                                                    <label for="facebook">Facebook: Input if you have any existing Social media account of the mentioned</label>
                                                    <input type="text" class="form-control" name="facebook" value="<?= $userRow['facebook']; ?>">
                                                </div>
                                                <div class="form-group">
                                                    <label for="twitter">Twitter: Input if you have any existing Social media account of the mentioned</label>
                                                    <input type="text" class="form-control" name="twitter" value="<?= $userRow['twitter']; ?>">
                                                </div>
                                                <div class="form-group">
                                                    <label for="google">Google +: Input if you have any existing Social media account of the mentioned</label>
                                                    <input type="text" class="form-control" name="googleplus" value="<?= $userRow['googleplus']; ?>">
                                                </div>
                                                <div class="form-group">
                                                    <label for="instagram">Instagram: Input if you have any existing Social media account of the mentioned</label>
                                                    <input type="text" class="form-control" name="instagram" value="<?= $userRow['instagram']; ?>">
                                                </div>
                                                <div class="form-group">
                                                    <label for="youtube">You Tube: Input if you have any existing Social media account of the mentioned</label>
                                                    <input type="text" class="form-control" name="youtube" value="<?= $userRow['youtube']; ?>">
                                                </div>
                                                <div class="form-group">
                                                    <label for="youtube"> Whatsapp: Input if you have any existing Social media account of the mentioned</label>
                                                    <input type="text" class="form-control" name="whatsapp" value="<?= $userRow['whatsapp']; ?>">
                                                </div>
                                                <div class="form-group col-sm-12">
                                                    <label>Address:</label>
                                                    <textarea class="form-control" name="home_address" rows="5" style="line-height: 22px;"><?= $userRow['home_address']; ?></textarea>
                                                </div>
                                            </div>
                                        </div>
                                        <button type="button" name="next" class="btn btn-primary next action-button float-right" value="Next">Next</button>
                                        <button type="button" name="previous" class="btn btn-dark previous action-button-previous float-right mr-3" value="Previous">Previous</button>
                                    </fieldset>
                                    <fieldset>
                                        <div class="form-card text-left">
                                            <div class="row">
                                                <div class="col-7">
                                                    <h3 class="mb-4">Photo Confirmation Upload:</h3>
                                                </div>
                                                <div class="col-5">
                                                    <h2 class="steps">Step 3 - 4</h2>
                                                </div>
                                            </div>
                                            <!--<div class="form-group">
                                                <label>Upload Your Photo (Passport Format):</label>
                                                <input type="file" class="form-control" name="pic" accept="image/*">
                                            </div>-->
                                            <div class="form-group">
                                                <label>Front Of Valid Id card:</label>
                                                <input type="file" class="form-control" name="idcardFront" accept="image/*">
                                            </div>
                                            <div class="form-group">
                                                <label>Back Of The Mentioned above:</label>
                                                <input type="file" class="form-control" name="idcardBack" accept="image/*">
                                            </div>
                                        </div>
                                        <button type="submit" name="verify_account" class="btn btn-primary float-right" value="Submit">Submit</button>
                                        <button type="button" name="previous" class="btn btn-dark previous action-button-previous float-right mr-3" value="Previous">Previous</button>
                                    </fieldset>
                                    <fieldset>
                                        <div class="form-card">
                                            <div class="row">
                                                <div class="col-7">
                                                    <h3 class="mb-4 text-left">Finish:</h3>
                                                </div>
                                                <div class="col-5">
                                                    <h2 class="steps">Step 4 - 4</h2>
                                                </div>
                                            </div>
                                            <br><br>
                                            <h2 class="text-success text-center"><strong>SUCCESS !</strong></h2>
                                            <br>
                                            <div class="row justify-content-center">
                                                <div class="col-3"> <img src="images/page-img/img-success.png" class="fit-image" alt="fit-image"> </div>
                                            </div>
                                            <br><br>
                                            <div class="row justify-content-center">
                                                <div class="col-7 text-center">
                                                    <h5 class="purple-text text-center">You Have Successfully Verified your Account</h5>
                                                </div>
                                            </div>
                                        </div>
                                    </fieldset>
                                </form>
                                <?php
                                if ( isset($_POST['verify_account']) ){
                                    error_reporting(E_ALL);

                                    $email = $_POST['email'];
                                    $fullname = $_POST['fullname'];
                                    $city = $_POST['city'];
                                    $gender = $_POST['gender'];
                                    $dob = $_POST['dob'];
                                    $marital_status = $_POST['marital_status'];
                                    $age = $_POST['age'];
                                    $facebook = $_POST['facebook'];
                                    $twitter = $_POST['twitter'];
                                    $googleplus = $_POST['googleplus'];
                                    $instagram = $_POST['instagram'];
                                    $youtube = $_POST['youtube'];
                                    $whatsapp = $_POST['whatsapp'];
                                    $home_address = $_POST['home_address'];

                                    $targetDir = "uploads/"; // Directory to save in uploads
                                    $allowedExts = array('jpg', 'jpeg', 'png'); // Allowed File Types

                                    $update = $db_con->prepare("UPDATE users SET email='$email', fullname='$fullname', city='$city', status='Pending Verification', submitted='Yes', gender='$gender', dob='$dob', marital_status='$marital_status', age='$age', facebook='$facebook', twitter='$twitter', googleplus='$googleplus', instagram='$instagram', youtube='$youtube', whatsapp='$whatsapp', home_address='$home_address' WHERE id='".$userRow['id']."' AND username='".$userRow['username']."'");

                                    if ( !empty($_FILES['idcardFront']['name']) && !empty($_FILES['idcardBack']['name']) ){
                                        $uploads = $db_con->prepare("SELECT idcard_front, idcard_back FROM users WHERE id='".$userRow['id']."' AND username='".$userRow['username']."'");
                                        $uploads->execute();
                                        $get = $uploads->fetch(PDO::FETCH_ASSOC);

                                        $extIDFront = pathinfo(basename($_FILES['idcardFront']['name']), PATHINFO_EXTENSION); // Get the extension
                                        $extIDBack = pathinfo(basename($_FILES['idcardBack']['name']), PATHINFO_EXTENSION); // Get the extension
                                        if ( !in_array(strtolower($extIDFront), $allowedExts) || !in_array(strtolower($extIDBack), $allowedExts) ){
                                ?>
                                            <script>
                                                setTimeout(function(){
                                                    noticePop('Invalid File Type. Upload an Image.', 'error');
                                                }, 2000);
                                            </script>
                                <?php
                                        } else {
                                            $newIDFront = 'idFront_' . randDoc($extIDFront); // Randomization
                                            $newIDBack = 'idBack_' . randDoc($extIDBack); // Randomization
                                            if ( (file_exists($targetDir . $get['idcard_front']) AND !empty($get['idcard_front'])) && file_exists($targetDir . $get['idcard_back']) AND !empty($get['idcard_back']) ){
                                                unlink($targetDir . $get['idcard_front']); // Delete Old File
                                                unlink($targetDir . $get['idcard_back']); // Delete Old File
                                            }
                                            $query = $db_con->prepare("UPDATE users SET idcard_front='$newIDFront', idcard_back='$newIDBack' WHERE id='".$userRow['id']."' AND username='".$userRow['username']."'");
                                            $query->execute(); // Update DB
                                            /*if ( file_exists($target_dir) ){
                                                echo 'Dir Exists<br>';
                                            } else { echo 'Does not exits<br>'; }
                                            if ( is_writable($target_dir) ){
                                                echo 'Dir is writable<br>';
                                            } else { echo 'Dir not writable<br>'; }*/
                                            if ( move_uploaded_file($_FILES['idcardFront']['tmp_name'], $targetDir . $newIDFront) && move_uploaded_file($_FILES['idcardBack']['tmp_name'], $targetDir . $newIDBack) ){
                                                $update->execute();
                                ?>
                                                <script>
                                                    setTimeout(function(){
                                                        noticePop('You Have Successfully Submitted Your Documents. Hold on for Approval.', 'success');
                                                    }, 2000);
                                                </script>
                                <?php
                                            } else {
                                ?>
                                                <script>
                                                    setTimeout(function(){
                                                        noticePop('Something Went Wrong. Try again.', 'error');
                                                    }, 2000);
                                                </script>
                                <?php
                                            }
                                        }
                                        unset($uploads);
                                    } else {
                                ?>
                                        <script>
                                            setTimeout(function(){
                                                noticePop('ID Card Front & Back Must Be Selected for Upload.', 'error');
                                            }, 2000);
                                        </script>
                                <?php
                                    }
                                }
                                ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Wrapper END -->
    <?php include 'footer.php' ?>
    <!-- Footer END -->
    <!-- Optional JavaScript -->
    <script src="../plugins/jquery-3.1.1.min.js"></script>
    <script src="../plugins/sweetalerts/sweetalert2.min.js"></script>
    <script src="https://unpkg.com/@popperjs/core@2/dist/umd/popper.js"></script>

    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <!--<script src="js/jquery.min.js"></script>
    <script src="js/popper.min.js"></script>-->
    <script src="js/bootstrap.min.js"></script>
    <!-- Appear JavaScript -->
    <script src="js/jquery.appear.js"></script>
    <!-- Countdown JavaScript -->
    <script src="js/countdown.min.js"></script>
    <!-- Counterup JavaScript -->
    <script src="js/waypoints.min.js"></script>
    <script src="js/jquery.counterup.min.js"></script>
    <!-- Wow JavaScript -->
    <script src="js/wow.min.js"></script>
    <!-- Apexcharts JavaScript -->
    <script src="js/apexcharts.js"></script>
    <!-- Slick JavaScript -->
    <script src="js/slick.min.js"></script>
    <!-- Select2 JavaScript -->
    <script src="js/select2.min.js"></script>
    <!-- Owl Carousel JavaScript -->
    <script src="js/owl.carousel.min.js"></script>
    <!-- Magnific Popup JavaScript -->
    <script src="js/jquery.magnific-popup.min.js"></script>
    <!-- Smooth Scrollbar JavaScript -->
    <script src="js/smooth-scrollbar.js"></script>
    <!-- lottie JavaScript -->
    <script src="js/lottie.js"></script>
    <!-- am core JavaScript -->
    <script src="js/core.js"></script>
    <!-- am charts JavaScript -->
    <script src="js/charts.js"></script>
    <!-- am animated JavaScript -->
    <script src="js/animated.js"></script>
    <!-- am kelly JavaScript -->
    <script src="js/kelly.js"></script>
    <!-- am maps JavaScript -->
    <script src="js/maps.js"></script>
    <!-- am worldLow JavaScript -->
    <script src="js/worldLow.js"></script>
    <!-- Style Customizer -->
    <script src="js/style-customizer.js"></script>
    <!-- Chart Custom JavaScript -->
    <script src="js/chart-custom.js"></script>
    <!-- Custom JavaScript -->
    <script src="js/custom.js"></script>

    <script>
        function noticePop( value, type ){
            swal({
                html: '<span style="font-size:18px!important;">'+ `${value}` +'</span>',
                type: `${type}`,
                timer: 4000,
                showConfirmButton: false,
                allowOutsideClick: false,
                allowEscapeKey: false,
            }).then(function(){
                window.location.href = 'verify';
            });
        }
    </script>

</body>
</html>