<?php
/**
 * pending-verifications.php -- Pending Verifications
 */

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['admin']) || $_SESSION["loggedin"] !== true || trim($_SESSION['admin']) == '' ){
	//header('Location: ' . $BASE_URL . 'wp-admin/');
    header('Location: ' . $BASE_URL . 'signin');
	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>Pending Verifications - Alert Signals Nation</title>
    <!-- Favicon -->
    <link rel="shortcut icon" href="../img/Signals-Alert-3.png" />
    <!-- Bootstrap CSS -->
    <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">

    <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>
    <!-- loader Start -->
    <div id="loading">
        <div id="loading-center">
        </div>
    </div>
    <!-- loader END -->
    <!-- Wrapper Start -->
    <div class="wrapper">
        <!-- Sidebar  -->
        <?php include 'navbar.php' ?>
        <!-- TOP Nav Bar END -->
        <!-- Page Content  -->
        <div id="content-page" class="content-page">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-sm-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;">Pending Verifications</h4>
                                </div>
                            </div>
                            <div class="iq-card-body">
                                <div class="table-responsive">
                                    <div class="row justify-content-between">
                                        <div class="col-sm-12 col-md-6">
                                            <div id="user_list_datatable_info" class="dataTables_filter">
                                                <form class="mr-3 position-relative">
                                                    <div class="form-group mb-0">
                                                        <input type="search" class="form-control" id="exampleInputSearch" placeholder="Search" aria-controls="user-list-table">
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                        <div class="col-sm-12 col-md-6">
                                            <div class="user-list-files d-flex float-right">
                                                <a class="iq-bg-primary" href="javascript:void();">
                                                    Print
                                                </a>
                                                <a class="iq-bg-primary" href="javascript:void();">
                                                    Excel
                                                </a>
                                                <a class="iq-bg-primary" href="javascript:void();">
                                                    Pdf
                                                </a>
                                            </div>
                                        </div>
                                    </div>
                                    <table id="user-list-table" class="table table-striped table-bordered mt-4" role="grid" aria-describedby="user-list-page-info">
                                        <thead>
                                            <tr>
                                                <th>Username</th>
                                                <th>Name</th>
                                                <th>Profile</th>
                                                <th>Join Date</th>
                                                <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                        <?php
                                        // Users
                                        $users = $db_con->prepare("SELECT * FROM users WHERE status='Pending Verification' AND submitted='Yes' ORDER BY created DESC");

                                        if ( $users->execute() ){
                                            $i = 0;
                                            while ( $user = $users->fetch(PDO::FETCH_ASSOC) ){
                                                $i++;
                                        ?>
                                                <tr id="tr-<?= $user['id']; ?>">
                                                    <!--<td class="text-center">
                                                        <?php
                                                        if ( empty($user['picture']) ){
                                                            echo '<img class="rounded img-fluid avatar-40" src="../wp-user/images/user/11.png" alt="profile">';
                                                        } else {
                                                            echo '<img class="rounded img-fluid avatar-40" src="../wp-user/uploads/'.$user['picture'].'" alt="profile">';
                                                        }
                                                        ?>
                                                    </td>-->
                                                    <td><?= $user['username']; ?></td>
                                                    <td><?= $user['fullname']; ?></td>
                                                    <td>
                                                        <a href="userProfile?id=<?= $user['id']; ?>" target="_blank">View Document</a>
                                                    </td>
                                                    <td><?= date('Y/m/d', strtotime($user['created'])); ?></td>
                                                    <td>
                                                        <!--<div class="d-flex align-items-center list-user-action">
                                                            <a class="iq-bg-primary" data-toggle="tooltip" data-placement="top" title="" data-original-title="View" href="userProfile?id=<?= $user['id']; ?>"><i class="ri-user-line"></i></a>
                                                            <a class="iq-bg-primary" data-toggle="tooltip" data-placement="top" title="" data-original-title="Edit" href="userEdit?id=<?= $user['id']; ?>"><i class="ri-pencil-line"></i></a>

                                                            <a class="iq-bg-primary" data-toggle="tooltip" data-placement="top" title="" data-original-title="Delete" href="users?delete&id=<?= $user['id']; ?>"><i class="ri-delete-bin-line"></i></a>
                                                            <?php
                                                            if ( isset($_GET['delete'], $_GET['id']) ){
                                                                $user_id = intval($_GET['id']);
                                                                $getUser = $db_con->prepare("SELECT * FROM users WHERE id='$user_id'");
                                                                $getUser->execute();
                                                                $userRow = $getUser->fetch(PDO::FETCH_ASSOC);

                                                                $delete = $db_con->prepare("DELETE FROM users WHERE id='$user_id';
                                                                	DELETE FROM user_active_deposit WHERE id='$user_id'; 
                                                                	DELETE FROM user_last_deposit WHERE id='$user_id'; 
                                                                	DELETE FROM user_last_withdrawal WHERE id='$user_id'; 
                                                                	DELETE FROM user_pending_withdraw WHERE id='$user_id'; 
                                                                	DELETE FROM user_total_balance WHERE id='$user_id'; 
                                                                	DELETE FROM user_total_deposit WHERE id='$user_id'; 
                                                                	DELETE FROM user_total_earning WHERE id='$user_id'; 
                                                                	DELETE FROM user_total_withdrawal WHERE id='$user_id'; 
                                                                	DELETE FROM user_trade_session WHERE id='$user_id'; 
                                                                	DELETE FROM user_transactions WHERE id='$user_id'");
                                                                	
                                                                if ( $delete->execute() ){
                                                            ?>
                                                                    <script>
                                                                        setTimeout(function(){
                                                                            noticePop('<?= $userRow['fullname']; ?>\'s Account Has Been Deleted.', 'success');
                                                                        }, 2000);
                                                                    </script>
                                                            <?php
                                                                } else {
                                                            ?>
                                                                    <script>
                                                                        setTimeout(function(){
                                                                            noticePop('Something Went Wrong.', 'error');
                                                                        }, 2000);
                                                                    </script>
                                                            <?php
                                                                }
                                                            }
                                                            ?>
                                                        </div>-->
                                                        <button class="btn btn-sm btn-primary" type="button" onclick="AppDec('approve', <?= $user['id']; ?>, '<?= $user['username']; ?>')">Approve</button>
                                                        &nbsp;
                                                        <button class="btn btn-sm btn-primary" type="button" onclick="AppDec('decline')">Decline</button>
                                                    </td>
                                                </tr>
                                        <?php
                                            }
                                        }
                                        ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Wrapper END -->
    <!-- Footer -->
    <?php include 'footer.php' ?>
    <!-- color-customizer 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>
        // BASE URL and API Inclusion
        const BASE_URL = '<?= $BASE_URL; ?>';
        const API = `${BASE_URL}api/admin.php`;

        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 = 'pending-verifications';
            });
        }

        function AppDec( action, uid, uname ){
            $.ajax({
                url: API,
                type: 'POST',
                //dataType: 'JSON',
                data: {
                    verifications: 'verifications',
                    action_type: action,
                    user_id: uid,
                    user_name: uname
                },
                cache: false
            }).done( function( result ){
                if ( result.error == false && result.notice == 'approved' ){
                    document.getElementById('tr-'+uid).style.display = 'none'; // hide table row (tr)
                    noticePop( result.message, 'success' );
                }
                else if ( result.error == false && result.notice == 'declined' ){
                    document.getElementById('tr-'+uid).style.display = 'none'; // hide table row (tr)
                    noticePop( result.message, 'success' );
                }
                else if ( result.error == true && result.notice == 'failed' ){
                    noticePop( result.message, 'error' );
                }
            });
        }
    </script>

</body>
</html>