<script type="text/javascript">
    $(document).ready(function(){
        $("#checkall").click(function(){
            if(this.checked){
                $(".check_class").attr("checked",true);					
                $(".check_class").parent().addClass("checked");					
            }else{
                $(".check_class").attr("checked",false);					
                $(".check_class").parent().removeClass("checked");					
            }
        });
    });

    function delete_entry(id){
        swal({
            title: 'Are you sure?',
            text: "You won't be able to revert this!",
            type: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#0CC27E',
            cancelButtonColor: '#FF586B',
            confirmButtonText: 'Yes, delete it!',
            cancelButtonText: 'No, cancel!',
            confirmButtonClass: 'btn btn-success mr-5',
            cancelButtonClass: 'btn btn-danger',
            buttonsStyling: false
        }).then(function () {
            location.href = 'userPermissionList.php?act=delete&id='+id;
        }, function (dismiss) {
            return false; 
        });
    }
</script>

<div class="breadcrumb">
    <h1>User Permissions</h1>
    <ul>
        <li><a href="<?php echo SITE_URL.ADMIN_DIR ?>">Dashboard</a></li>
        <li>User Permissions List</li>
    </ul>
</div>
<div class="separator-breadcrumb border-top"></div>

<div class="row mb-4">
    <div class="col-md-6">
        <select id="act" name="act" class="form-control maction">
            <option value="">Multiple action</option>              
            <option value="delete_all">Delete selected</option>
        </select>
        <button type="button" class="btn btn-primary m-1" onclick="return validate_all();">Apply</button>
    </div>
    <div class="col-md-6 pull-right">
        <div class="button-group">
            <a href="userPermissionAdd.php" class="btn btn-dark m-1"><i class="i-Add-User"></i> Add New</a>
        </div>    
    </div>  
</div>

<div class="widget-body">
    <div class="portlet-body">
        <?php echo (isset($successMsg) && $successMsg!='') ? "<div class='alert alert-success'><button data-dismiss='alert' class='close' type='button'>×</button>".base64_decode($successMsg)."</div>" : '' ; ?>
        <?php echo (isset($failedMsg) && $failedMsg!='') ? "<div class='alert alert-danger'><button data-dismiss='alert' class='close' type='button'>×</button>".base64_decode($failedMsg)."</div>" : '' ?>
    </div>
</div>

<div class="row mb-4">
    <div class="col-md-12 mb-4">
        <div class="card text-left">
            <div class="card-body">
                <div class="table-responsive">
                    <form id="listFrm" name="listFrm" action="" method="post">       
                        <input type="hidden" id="action" name="action" value="">
                        <table id="list" class="display table table-striped table-bordered" style="width:100%">
                            <thead>
                                <tr>
                                    <th class="center"><input type="checkbox" name="checkall" id="checkall"></th>
                                    <th>ID</th>
                                    <th>Title</th>
                                    <th>Created At</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                        </table>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="application/javascript">
    $(document).ready(function() {
        $('#list').DataTable({ 
            "ajax": "userPermissionList.php?act=load",
            "processing": true,
            "serverSide": true,
            "pageLength": 25,
            "bSort": false,
            language: {
                "processing": "<div class='loader-bubble loader-bubble-primary m-5'></div>",
                "sEmptyTable": "No records found."
            }
        });
    });
</script> 