<?php
    // session_start();
    include "../../db.php";
    require '../../auth.php';
    restrictAccess(['Associate']);
    date_default_timezone_set('Asia/Kolkata');
    $currentTime = date('M j, Y g:i a');

    if ( !isset($_SESSION['uid']) && !isset($_SESSION['uref']) && !isset($_SESSION['utype']) ) {
        header("Location: logout.php");
        exit();
    }

    $adm_sql = mysqli_query($con, "SELECT * FROM users WHERE uid = '$_SESSION[uid]' ");
    if($adm_row = mysqli_fetch_assoc($adm_sql)){
        $uadmin = $adm_row["uadmin"];
        $admin_ref = $adm_row["admin_ref"];
    }
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <?php include "include/meta.php"; ?>
    <?php include "include/css.php"; ?>
    <?php include "include/php-functions.php"; ?>
    <script>
    let SESS = [];
    SESS['uid'] = "<?php echo $_SESSION['uid']; ?>";
    SESS['uref'] = "<?php echo $_SESSION['uref']; ?>";
    SESS['uadmin'] = "<?php echo $uadmin;?>";
    </script>
</head>

<body>
    <!--  Header -->
    <?php 
    include "include/header.php"; 
    ?>
    <!-- #header -->

    <section id="inner-body">
        <div class="body-content">
            <div class="container-fluid">
                <div class="card mt-3">
                    <div class="card-header">
                        <h5 class="text-dark text-center font-weight-bold">Duplicate Candidates</h5>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <!-- Loader -->
                            <div class="col-12" id="loader">
                                <ul style="list-style: none; padding-left: 0;">
                                    <?php for ($count = 0; $count < 4; $count++) { ?>
                                    <li>
                                        <div class="ph-item">
                                            <div class="ph-test">
                                                <div class="ph-row">
                                                    <div class="ph-col-12 big"></div>
                                                    <div class="ph-col-12"></div>
                                                    <div class="ph-col-12"></div>
                                                    <div class="ph-col-12"></div>
                                                    <div class="ph-col-12"></div>
                                                    <div class="ph-col-12"></div>
                                                </div>
                                            </div>
                                        </div>
                                    </li>
                                    <?php } ?>
                                </ul>
                            </div>
                            <!-- Full Data Table -->
                            <div class="col-12" id="full-table">
                                <ul class="timeline" id="full-table-data" style="list-style: none; padding-left: 0;">
                                </ul>
                            </div>
                            <!-- Filtered Data Table -->
                            <div class="col-12" id="filter-table" style="display: none;">
                                <ul class="timeline" id="filter-table-data" style="list-style: none; padding-left: 0;">
                                </ul>
                            </div>
                        </div>

                        <!-- Pagination -->
                        <ul class="pager">
                            <li class="previous" id="first-page" style="cursor: grab;"><a>First Page</a></li>
                            <li class="next" id="next-page" style="cursor: grab;"><a>Next Page</a></li>
                        </ul>

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

    </section>

    <!-- JavaScript Libraries -->

    <?php include "include/js.php"; ?>

    <script>
    $(document).ready(function() {
        var load_flag = 0;
        loadMore(load_flag);

        function loadMore(start) {
            $.ajax({
                url: 'duplicate-Ajax.php',
                type: 'POST',
                data: {
                    uadmin: SESS['uadmin'],
                    start: start
                },
                beforeSend: function() {
                    $("#loader").show();
                },
                success: function(result) {
                    if (start === 0) {
                        $('#full-table-data').html(result);
                    } else {
                        $('#full-table-data').append(result);
                    }
                    load_flag += 100;
                },
                complete: function() {
                    $("#loader").hide();
                }
            });
        }

        $('#next-page').click(function() {
            loadMore(load_flag);
        });

        $('#first-page').click(function() {
            load_flag = 0;
            loadMore(load_flag);
        });
    });
    </script>

</body>

</html>