<?php

    // session_start();

    include "../../db.php";

    require '../../auth.php';

    restrictAccess(['master_admin']);

    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();

    }



    if ( $_SESSION['utype'] != 'master_admin' && $_SESSION['uref'] != 'fssdf4543frts' ) {

        header("Location: logout.php");

        exit();

    }

?>



<!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'] = "";

    </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">Agent's Work Details</h5>

                    </div>

                    <div class="card-body">

                        <!--  Count  -->

                        <?php  

                        $count_sql = "SELECT * FROM student_details WHERE ( st_name !='' && st_name IS NOT NULL ) AND ( st_by='' || st_by IS NULL ) AND `flag_status` ='A' ";

                        $count_res = mysqli_query($con,$count_sql);

                        $count_total_rows=mysqli_num_rows($count_res) ;

                            echo "<div class='col-md-12 text-center'>

                                        <b><i class='fa fa-check-square' aria-hidden='true' style='color:green;'></i> Total Data : $count_total_rows &nbsp; 

                                        </b>

                                        <hr>

                                    </div>";

                        ?>

                        <br>

                        <div class="row filter">

                            <ul class="search-details">

                                <li>

                                    <div class="form-group">

                                        <font>Agent Name:</font>

                                        <input type="text" list="Third" class="form-control form-control-sm"

                                            placeholder="Search By Candidate Name" id="ThirdFilterValue">

                                        <datalist id="Third">

                                            <?php 

                                            $sql = "SELECT uname FROM users WHERE utype='Associate'AND  `uadmin`= '$_SESSION[uref]' ORDER BY uid DESC";

                                            $res = mysqli_query($con,$sql);

                                            while ($row = mysqli_fetch_assoc($res)) {

                                            ?>

                                            <option value="<?php echo $row['uname']; ?>"><?php echo $row['uname']; ?>

                                            </option>

                                            <?php } ?>

                                        </datalist>

                                    </div>

                                </li>

                                <li>

                                    <div class="form-group">

                                        <font>Status:</font>

                                        <select class="form-control form-control-sm SecondFilterValue">

                                            <option></option>

                                            <?php 

                                            $sql = "SELECT * FROM status WHERE s_by='$_SESSION[uref]' ORDER BY s_pos ASC";

                                            $res = mysqli_query($con,$sql);

                                            while ($row = mysqli_fetch_assoc($res)) {

                                            ?>

                                            <option value="<?php echo $row['s_id']; ?>"><?php echo $row['s_name']; ?>

                                            </option>

                                            <?php } ?>

                                        </select>

                                    </div>

                                </li>

                                <li>

                                    <div class="form-group">

                                        <font>Date</font>

                                        <input type="date" class="form-control form-control-sm" id="First1FilterValue">

                                    </div>

                                </li>

                                <li class="d-flex align-items-end">

                                    <div class="filter-btn">

                                        <button type="button" id="filter" class="btn btn-primary btn-sm"><i

                                                class="fa fa-search"></i></button>

                                    </div>

                                </li>

                            </ul>

                        </div>



                        <hr>



                        <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++) {

                          

                                    echo '<li>

                                    <div class="ph-item">

                                    <div cl ass="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>';

                                }

                              ?>

                                </ul>

                            </div>

                            <!-- loader -->

                            <div class="col-12" id="full-table">

                                <ul class="timeline" id="full-table-data" style="list-style: none; padding-left: 0;">

                                    </>

                                </ul>

                            </div>

                            <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>

                        <ul class="pager">

                            <li class="previous" id="first-page" style="cursor: -webkit-grab; cursor: grab;"><a>First

                                    Page</a></li>

                            <li class="next" id="next-page" style="cursor: -webkit-grab; cursor: grab;"><a>Next Page</a>

                            </li>

                        </ul>



                    </div>

                </div>

            </div>

        </div>



        <!--=============Modals Start================= -->

        <div class="modal fade" id="remarkModal" tabindex="-1" aria-labelledby="modalName" aria-hidden="true">

            <div class="modal-dialog">

                <div class="modal-content">

                    <div class="modal-header">

                        <h5 class="modal-name badge bg-primary text-light" id="modalName"></h5>

                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>

                    </div>

                    <div class="modal-body">

                        <span id="remarkShow"></span>

                    </div>

                    <div class="modal-footer">

                        <button type="button" class="btn btn-warning text-dark" data-bs-dismiss="modal">Close</button>

                    </div>

                </div>

            </div>

        </div>



        <!--==============Modals End================ -->

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

    </section>



    <!-- JavaScript Libraries -->



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

    <script>

    //dropdown TWO filter Start//

    $(document).ready(function() {



        var load_filter_flag = '';

        var First1FilterValue = '';

        var First2FilterValue = '';

        var SecondFilterValue = '';

        var ThirdFilterValue = '';



        var aFilterValue = '';

        var bFilterValue = '';



        $("#filter").click(function() {

            First1FilterValue = $('#First1FilterValue').val();

            First2FilterValue = $('#First2FilterValue').val();

            SecondFilterValue = $('.SecondFilterValue').val();

            ThirdFilterValue = $('#ThirdFilterValue').val();



            aFilterValue = $('#aFilterValue').val();

            bFilterValue = $('#bFilterValue').val();



            load_filter_flag = 0;

            if (First1FilterValue != '' || First2FilterValue != '' || SecondFilterValue != '' ||

                ThirdFilterValue != '' || aFilterValue != '' || bFilterValue != '') {

                //alert(name);

                $.ajax({

                    url: 'agents-Ajax.php',

                    type: 'post',

                    data: {

                        First1FilterValue: First1FilterValue,

                        First2FilterValue: First2FilterValue,

                        SecondFilterValue: SecondFilterValue,

                        ThirdFilterValue: ThirdFilterValue,



                        aFilterValue: aFilterValue,

                        bFilterValue: bFilterValue,



                        uid: SESS['uid'],

                        uref: SESS['uref'],

                        uadmin: SESS['uadmin'],



                        start: load_filter_flag

                    },

                    success: function(result) {

                        $('#full-table').hide();

                        $('#filter-table').show();

                        $('#filter-table-data').html(result);

                        load_filter_flag += 25;

                    },

                    complete: function(data) {

                        /* Hide loader container */

                        $("#loader").hide();

                    }

                });

            } else {

                alert('Plz Select an Option');

                $('#full-table').show();

                $('#filter-table').hide();

            }

        });





        function loadMoreFilter(start) {

            console.log('Filter' + start);

            if (load_filter_flag > 0) {

                //alert(name);

                $.ajax({

                    url: 'agents-Ajax.php',

                    type: 'post',

                    data: {

                        First1FilterValue: First1FilterValue,

                        First2FilterValue: First2FilterValue,

                        SecondFilterValue: SecondFilterValue,

                        ThirdFilterValue: ThirdFilterValue,



                        aFilterValue: aFilterValue,

                        bFilterValue: bFilterValue,



                        uid: SESS['uid'],

                        uref: SESS['uref'],

                        uadmin: SESS['uadmin'],



                        start: start

                    },

                    success: function(result) {

                        $('#filter-table-data').html(result);

                        load_filter_flag += 25;

                    }

                });



            }

        }

        // Scroll Loading of Full Data //

        var load_flag = 0;

        loadMore(load_flag);



        function loadMore(start) {

            //console.log('total'+start);

            $.ajax({

                url: 'agents-Ajax.php',

                type: 'post',

                data: {

                    uid: SESS['uid'],

                    uref: SESS['uref'],

                    uadmin: SESS['uadmin'],

                    start: start

                },

                success: function(result) {

                    $('#full-table-data').html(result);

                    load_flag += 25;

                },

                complete: function(data) {

                    /* Hide loader container */

                    $("#loader").hide();

                }

            });

        }





        $('#next-page').click(function() {

            console.log('next-page');

            if (load_filter_flag > 0) {

                loadMoreFilter(load_filter_flag);

            } else {

                loadMore(load_flag);

            }

        });



        $('#first-page').click(function() {

            console.log('first-page');

            if (load_filter_flag > 0) {

                //console.log('first-filter-page');

                $("#filter").trigger("click");

            } else {

                // console.log('first-real-page');

                load_flag = 0;

                loadMore(load_flag);

            }

        });



    });

    </script>



</body>



</html>