<?php echo $__env->make('admin/partial/header', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.1/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.3.3/css/select.dataTables.min.css">
<style>
    .dataTables_scrollHeadInner {
        width: auto !important;
    }

    .btn-icon {
        background: #fff;
    }

    .btn-icon .bx {
        font-size: 20px;
    }

    .btn .bx {
        vertical-align: middle;
        font-size: 20px;
    }

    .dropdown-menu {
        padding: 0.25rem 0;
    }

    .dropdown-item {
        padding: 0.5rem 1rem;
    }

    .throwout {
        position: absolute !important;
        right: 2000px !important;
    }

    .wide {
        width: 8.1% !important;
    }

</style>
<!-- start page container -->
<div class="page-container">
    <div class="loading" style="display:none;">Loading&#8230;</div>
    <!-- start sidebar menu -->
    <?php echo $__env->make('admin/partial/nav', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
    <!-- end sidebar menu -->
    <!-- start page content -->
    <div class="page-content-wrapper">
        <div class="page-content">
            <div class="page-bar">
                <div class="page-title-breadcrumb">
                    <div class=" pull-left">
                        <div class="page-title">Drivers List</div>
                    </div>
                    <?php echo $__env->make('admin/partial/sub', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
                    <!-- <ol class="breadcrumb page-breadcrumb pull-right">
                        <li><i class="fa fa-home"></i>&nbsp;<a class="parent-item"
                                href="index.html">Home</a>&nbsp;<i class="fa fa-angle-right"></i>
                        </li>
                        <li class="active">All Drivers</li>
                    </ol> -->
                </div>
            </div>


            <center><img id="gif" src="https://createwebsite.net/wp-content/uploads/2015/09/Display-Loading.gif"
                    width="25%" class="gif"></center>




            <div class="row">
                <div class="col-md-12">
                    <div class="card card-topline-purple throwout" id="cardwrappers">
                        <div class="card-body ">


                            <div id="example3_wrapper" class="dataTables_wrapper container-fluid dt-bootstrap4">

                                <div class="row">
                                    <div class="col-sm-12">
                                        <div class="dataTables_scroll">


                                            <div class="dataTables_scrollBody" id="dtc"
                                                style="position: relative; overflow: auto; width: 100%;">

                                                <table id="driver_multitable" class="display full-width dataTable"
                                                    role="grid" aria-describedby="example3_info"
                                                    style="width: 909px; height: 230px;">
                                                    <thead>
                                                        <tr role="row" style="height: 0px;">
                                                            <th class="sorting_asc" id="thisth"
                                                                aria-controls="example3" rowspan="1" colspan="1"
                                                                style="width: 136.458px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;"
                                                                aria-label="Column 1: activate to sort column descending"
                                                                aria-sort="ascending">
                                                                Driver Code
                                                            </th>
                                                            <th class="sorting_asc" id="thisth"
                                                                aria-controls="example3" rowspan="1" colspan="1"
                                                                style="width: 136.458px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;"
                                                                aria-label="Column 1: activate to sort column descending"
                                                                aria-sort="ascending">
                                                                ID
                                                            </th>
                                                            <th class="sorting_asc" aria-controls="example3"
                                                                rowspan="1" colspan="1"
                                                                style="width: 136.458px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;"
                                                                aria-label="Column 1: activate to sort column descending"
                                                                aria-sort="ascending">
                                                                First Name
                                                            </th>
                                                            <th class="sorting" aria-controls="example3"
                                                                rowspan="1" colspan="1"
                                                                style="width: 142.014px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;"
                                                                aria-label="Column 2: activate to sort column ascending">
                                                                Last Name
                                                            </th>
                                                            <th class="sorting" aria-controls="example3"
                                                                rowspan="1" colspan="1"
                                                                style="width: 144.236px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;"
                                                                aria-label="Column 3: activate to sort column ascending">
                                                                CEST
                                                            </th>
                                                            <th class="sorting" aria-controls="example3"
                                                                rowspan="1" colspan="1"
                                                                style="width: 146.458px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;"
                                                                aria-label="Column 4: activate to sort column ascending">
                                                                PSC Engagement
                                                            </th>
                                                            <th class="sorting" aria-controls="example3"
                                                                rowspan="1" colspan="1"
                                                                style="width: 146.458px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;"
                                                                aria-label="Column 5: activate to sort column ascending">
                                                                PL Ins.
                                                            </th>
                                                            <th class="sorting" aria-controls="example3"
                                                                rowspan="1" colspan="1"
                                                                style="width: 146.458px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;"
                                                                aria-label="Column 5: activate to sort column ascending">
                                                                Accept Substitution
                                                            </th>
                                                            <th class="sorting" aria-controls="example3"
                                                                rowspan="1" colspan="1"
                                                                style="width: 146.458px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;"
                                                                aria-label="Column 5: activate to sort column ascending">
                                                                CPC
                                                            </th>
                                                            <th class="sorting" aria-controls="example3"
                                                                rowspan="1" colspan="1"
                                                                style="width: 146.458px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;"
                                                                aria-label="Column 5: activate to sort column ascending">
                                                                Email
                                                            </th>
                                                            <th class="sorting" aria-controls="example3"
                                                                rowspan="1" colspan="1"
                                                                style="width: 146.458px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;"
                                                                aria-label="Column 5: activate to sort column ascending">
                                                                Account Verification
                                                            </th>
                                                            <th class="sorting" aria-controls="example3"
                                                                rowspan="1" colspan="1"
                                                                style="width: 146.458px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;"
                                                                aria-label="Column 5: activate to sort column ascending">
                                                                Last Login
                                                            </th>
                                                            <th class="sorting" aria-controls="example3"
                                                                rowspan="1" colspan="1"
                                                                style="width: 146.458px; padding-top: 0px; padding-bottom: 0px; border-top-width: 0px; border-bottom-width: 0px; height: 0px;"
                                                                aria-label="Column 5: activate to sort column ascending">
                                                                Status
                                                            </th>


                                                        </tr>
                                                    </thead>
                                                    <tbody id="tbody" class="">

                                                    </tbody>


                                                </table>
                                            </div>

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

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





        </div>









    </div>
    <!-- end page content -->





</div>
<!-- end page container -->
<?php echo $__env->make('admin/partial/footer', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>




<script type="text/javascript" src="https://cdn.datatables.net/select/1.3.3/js/dataTables.select.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/select/1.3.3/js/dataTables.select.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/select/1.3.3/js/dataTables.select.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        var myTable = $('#driver_multitable').DataTable({
            "serverSide": true,
            "ajax": {
                "url": "<?php echo e(url('datatable_alldrivers')); ?>",
                "dataType": "json",
                "type": "POST",
                "data": {
                    _token: "<?php echo e(csrf_token()); ?>"
                }
            },
            "columns": [{
                    "data": "driver_code"
                },
                {
                    "data": "id"
                },
                {
                    "data": "first_name"
                },
                {
                    "data": "last_name"
                },
                {
                    "data": "CEST"
                },
                {
                    "data": "PSC"
                },
                {
                    "data": "PL"
                },
                {
                    "data": "Accept"
                },
                {
                    "data": "CPC"
                },
                {
                    "data": "e-Davis"
                },
                {
                    "data": "account_verification"
                },
                {
                    "data": "last_accessed"
                },
                {
                    "data": "status"
                },
            ],
            processing: true,
            language: {
                processing: '<i class="fa fa-spinner fa-spin fa-3x fa-fw"></i>Processing...'
            },
            select: {
                style: 'multi'
            }
        });

        // ch Details
        $('#customSubNavBtn').append(
            `<div><a id="chDetails" href="#"><i class="fa fa-home" style="font-size:20px"></i> CompH</a></div>`
        );
        $('#customSubNavSeperator').append(`<div>|</div>`);


        // chDetails button
        $('#chDetails').click(function() {
            if (myTable.rows({
                    selected: true
                }).count() == 0) {
                return swal({
                    title: "Attention",
                    text: "Please first select an item to see its details!",
                    icon: "warning",
                    buttons: false,
                    dangerMode: false,
                });
            }
            if (myTable.rows({
                    selected: true
                }).count() > 1) {
                return swal("Please only select one item to see its details!");
            }
            if (myTable.rows({
                    selected: true
                }).count() == 1) {
                var id = myTable.rows({
                    selected: true
                }).data()[0].id;

                var route = "<?php echo e(url('CHDetails/Driver')); ?>" + `/${id}`;

                window.location.href = route;
            }

        });


        // add button
        $('#add').click(function() {
            window.location.href = '<?php echo route('adddrivers'); ?>';
        });

        // edit button
        $('#edit').click(function() {
            if (myTable.rows({
                    selected: true
                }).count() == 0) {
                return swal({
                    title: "Attention",
                    text: "Please first select an item to edit it!",
                    icon: "warning",
                    buttons: false,
                    dangerMode: false,
                });
            }
            if (myTable.rows({
                    selected: true
                }).count() > 1) {
                return swal("Please only select one item to edit!");
            }
            if (myTable.rows({
                    selected: true
                }).count() == 1) {
                var id = myTable.rows({
                    selected: true
                }).data()[0].id;

                $.ajax({
                    type: "GET",
                    url: 'CryptedHash/' + id,
                    success: function(hash) {
                        window.location.href = 'editdriver/' + hash;
                    },
                    error: function(err) {
                        window.location.reload();
                    }
                });
            }

        });


        // delete button
        $('#delete').click(function() {
            if (myTable.rows({
                    selected: true
                }).count() == 0) {
                return swal({
                    title: "Attention!",
                    text: "Please first select an item to delete",
                    icon: "warning",
                    buttons: false,
                    dangerMode: false,
                });
            }
            swal({
                    title: "Are you sure?",
                    text: "Once deleted, you will not be able to recover this record!",
                    icon: "warning",
                    buttons: true,
                    dangerMode: true,
                })
                .then((willDelete) => {
                    if (willDelete) {
                        $('.loading').show();
                        const ID = [];
                        const selectedRows = myTable.rows({
                            selected: true
                        }).data().toArray();
                        for (var i = 0; i < selectedRows.length; i++) {
                            ID.push(Number(selectedRows[i].id));
                        }
                        $.ajax({
                            type: "POST",
                            url: 'deletedriverbulk',
                            data: {
                                ids: ID,
                                _token: "<?php echo e(csrf_token()); ?>"
                            },
                            success: function(data) {
                                if (data.status == 200) {
                                    $('.loading').show();
                                    window.location.reload();
                                }
                            },
                            error: function(err) {
                                window.location.reload();
                            }
                        });
                    } else {
                        swal("Your Data is safe!");
                    }
                });
        });
        // delete button
        $('#activate').click(function() {
            if (myTable.rows({
                    selected: true
                }).count() == 0) {
                return swal({
                    title: "Attention!",
                    text: "Please first select an record to activate",
                    icon: "warning",
                    buttons: false,
                    dangerMode: false,
                });
            }
            swal({
                    title: "Attention!",
                    text: "Are you sure to activate selected item(s)",
                    icon: "warning",
                    buttons: true,
                    dangerMode: true,
                })
                .then((willDelete) => {
                    if (willDelete) {
                        $('.loading').show();
                        const ID = [];
                        const selectedRows = myTable.rows({
                            selected: true
                        }).data().toArray();
                        for (var i = 0; i < selectedRows.length; i++) {
                            ID.push(Number(selectedRows[i].id));
                        }
                        $.ajax({
                            type: "POST",
                            url: 'activatedriverbulk',
                            data: {
                                ids: ID,
                                _token: "<?php echo e(csrf_token()); ?>"
                            },
                            success: function(data) {
                                // if (data.status == 200) {
                                $('.loading').hide();
                                window.location.reload();
                                // }
                            },
                            error: function(err) {
                                window.location.reload();
                            }
                        });
                    } else {
                        swal("Your Data is safe!");
                    }
                });
        });
        // delete button
        $('#suspend').click(function() {
            if (myTable.rows({
                    selected: true
                }).count() == 0) {
                return swal({
                    title: "Attention!",
                    text: "Please first select an item to suspend",
                    icon: "warning",
                    buttons: false,
                    dangerMode: false,
                });
            }
            swal({
                    title: "Attention!",
                    text: "Are you sure to suspend selected item(s)",
                    icon: "warning",
                    buttons: true,
                    dangerMode: true,
                })
                .then((willDelete) => {
                    if (willDelete) {
                        $('.loading').show();
                        const ID = [];
                        const selectedRows = myTable.rows({
                            selected: true
                        }).data().toArray();
                        for (var i = 0; i < selectedRows.length; i++) {
                            ID.push(Number(selectedRows[i].id));
                        }
                        $.ajax({
                            type: "POST",
                            url: 'deactivatedriverbulk',
                            data: {
                                ids: ID,
                                _token: "<?php echo e(csrf_token()); ?>"
                            },
                            success: function(data) {
                                if (data.status == 200) {
                                    $('.loading').show();
                                    window.location.reload();
                                }
                            },
                            error: function(err) {
                                window.location.reload();
                            }
                        });
                    } else {
                        swal("Your Data is safe!");
                    }
                });
        });

        // select all button
        $('#selectAll').click(function() {
            if (myTable.rows({
                    selected: true
                }).count() > 0) {
                return;
            }

            myTable.rows().select();
        });

        // deselect all button
        $('#deselectAll').click(function() {
            if (myTable.rows({
                    selected: true
                }).count() == 0) {
                return;
            }

            myTable.rows().deselect();
        });



    });

    function Delete(ID) {
        swal({
                title: "Are you sure?",
                text: "Once deleted, you will not be able to recover this record!",
                icon: "warning",
                buttons: true,
                dangerMode: true,
            })
            .then((willDelete) => {
                if (willDelete) {
                    window.location.href = '<?php echo url('deletedriver'); ?>/' + ID;
                } else {
                    swal("Your Data is safe!");
                }
            });

    }
</script>

<script>
    // $('#tbody').toggleClass('hide');
    $("#cardwrappers").ready(() => {
        $('#gif').toggle();
        $('#cardwrappers').toggleClass('throwout');
        $('#thisth').toggleClass('wide');

    })

    $(document).ready(function() {
        $('#example31').dataTable({
            "stateSave": true
        });
    });
</script>
