<?php $__env->startSection('title', 'Manage Users Roles and Permissions'); ?>


<?php $__env->startSection('internal-js'); ?>
    <script>
        $(document).ready(function () {
            $('#active-table').dataTable();
        });

        
        function assignRoles(id){
            var route_link = '/assign-roles-to-user/'+id;

            $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>')
            .load(encodeURI(route_link))
            .dialog({
                modal: true,
                width: 500,
                title: "Assign Roles to a User",

                buttons: [
                    {
                        text: "Save Details",
                        icon: "ui-icon-check",
                        id: "my-button-1",
                        click: function(e) {
                            if(confirm('Are you sure to Save Entered Details?')){
                                e.preventDefault();
                                $("#my-button-1").attr('disabled', true).text('Please Wait....');
                                var datas = $('#assign-roles-to-user').serializeArray();

                                $.ajax({
                                    method: "POST",
                                    url: route_link,
                                    data: datas,
                                    success: function (res){
                                        if(res == 'success'){
                                            location.reload();
                                        }else if(res == 'empty list'){
                                            alert('Please Select at least one Permission from the Provided List');
                                            $("#my-button-1").attr('disabled', false).text('Save Details');
                                        }else{
                                            alert('System Encountered an Error. Please Contact System Admin');
                                        }
                                    }
                                });
                            }
                            return false;
                        }
                    }
                ],
                open: function() {
                    $(this).parent().css({'top': 50});
                }
            });
        }


        
        function assignPermissions(id){
            var route_link = '/assign-permissions-to-user/'+id;

            $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>')
            .load(encodeURI(route_link))
            .dialog({
                modal: true,
                width: 500,
                title: "Assign Permissions to a User",

                buttons: [
                    {
                        text: "Save Details",
                        icon: "ui-icon-check",
                        id: "my-button-1",
                        click: function(e) {
                            if(confirm('Are you sure to Save Entered Details?')){
                                e.preventDefault();
                                $("#my-button-1").attr('disabled', true).text('Please Wait....');
                                var datas = $('#assign-permissions-to-user').serializeArray();

                                $.ajax({
                                    method: "POST",
                                    url: route_link,
                                    data: datas,
                                    success: function (res){
                                        if(res == 'success'){
                                            location.reload();
                                        }else if(res == 'empty list'){
                                            alert('Please Select at least one Permission from the Provided List');
                                            $("#my-button-1").attr('disabled', false).text('Save Details');
                                        }else{
                                            alert('System Encountered an Error. Please Contact System Admin');
                                        }
                                    }
                                });
                            }
                            return false;
                        }
                    }
                ],
                open: function() {
                    $(this).parent().css({'top': 50});
                }
            });
        }

        
        function viewRoles(id){
            var route_link = '/view-assigned-roles-to-a-user/'+id;

            $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>')
                .load(encodeURI(route_link)).dialog({
                modal: true,
                width: 500,
                title: "View Assigned Roles to a User",
                open: function() {
                    $(this).parent().css({'top': 50});
                }
            });
        }

        
        function viewPermissionsViaRoles(id){
            var route_link = '/view-assigned-permissions-via-roles-to-a-user/'+id;

            $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>')
                .load(encodeURI(route_link)).dialog({
                modal: true,
                width: 500,
                title: "View Assigned Permissions Via Roles to a User",
                open: function() {
                    $(this).parent().css({'top': 50});
                }
            });
        }

        
        function viewAssignedDirectPermissions(id){
            var route_link = '/view-assigned-direct-permissions-to-a-user/'+id;

            $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>')
                .load(encodeURI(route_link)).dialog({
                modal: true,
                width: 500,
                title: "View Assigned Direct Permissions to a User",
                open: function() {
                    $(this).parent().css({'top': 50});
                }
            });
        }
    </script>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('internal-css'); ?>
    <style>
        #active-table th, td {
            text-align: left;
            padding: 4px;
        }
        #active-table tr:hover {background-color: #cbd1f8;}

    </style>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('headers'); ?>
    <?php echo $__env->make('headers.settings-header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php $__env->stopSection(); ?>


<?php $__env->startSection('heading', 'Manage User Roles & Permissions'); ?>


<?php $__env->startSection('content'); ?>
    <div class="tab">
        <button class="tablinks" onclick="openCity(event, 'users')" id="defaultOpen">Active Users</button>
    </div>

    <div id="users" class="tabcontent">
        <h3 class="error">
            Company's Active Users Listing with their Roles
        </h3>
        <table id="active-table" class="display" style="width: 100%; border-collapse: collapse; ">
            <thead>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Full Names</th>
                <th>Assigned Roles</th>
                <th>Assign Role</th>
                <th>Assigned Permissions Via Roles</th>
                <th>Assigned Direct Permissions</th>
                <th>Assign Direct Permission</th>
                <th>Created At</th>
            </tr>
            </thead>
            <tbody>
            <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr>
                    <td class="ar"></td>
                    <td><b class="error"><?php echo $row->firstName." ".$row->lastName; ?></b></td>
                    <td>
                        <b>
                            <?php echo count($row->roles); ?>

                            <?php if(count($row->roles) > 0): ?>
                                <i onclick="viewRoles('<?php echo e($row->id); ?>')" class="fa fa-eye error" style="margin-left: 5px;font-size: 16px; cursor: pointer"></i>
                            <?php endif; ?>
                        </b>
                    </td>
                    <td><i onclick="assignRoles('<?php echo e($row->id); ?>')" class="fa fa-pencil error" style="font-size: 16px; cursor: pointer"></i></td>
                    <td>
                        <b>
                            <?php echo count($row->getPermissionsViaRoles()); ?>

                            <?php if(count($row->getPermissionsViaRoles()) > 0): ?>
                                <i onclick="viewPermissionsViaRoles('<?php echo e($row->id); ?>')" class="fa fa-eye error" style="margin-left: 5px;font-size: 16px; cursor: pointer"></i>
                            <?php endif; ?>
                        </b>
                    </td>
                    <td>
                        <b>
                            <?php echo count($row->permissions); ?>

                            <?php if(count($row->permissions) > 0): ?>
                                <i onclick="viewAssignedDirectPermissions('<?php echo e($row->id); ?>')" class="fa fa-eye error" style="margin-left: 5px;font-size: 16px; cursor: pointer"></i>
                            <?php endif; ?>
                        </b>
                    </td>
                    <td><i onclick="assignPermissions('<?php echo e($row->id); ?>')" class="fa fa-pencil error" style="font-size: 16px; cursor: pointer"></i></td>
                    <td><?php echo date('d/m/Y',strtotime($row->created_at)); ?></td>
                </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
            <tfoot>
            <tr style="background-color: #a1b5d3">
                <th>No</th>
                <th>Full Names</th>
                <th>Assigned Roles</th>
                <th>Assign Role</th>
                <th>Assigned Permissions Via Roles</th>
                <th>Assigned Direct Permissions</th>
                <th>Assign Direct Permission</th>
                <th>Created At</th>
            </tr>
            </tfoot>
        </table>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('modal_heading'); ?>
    <h1>Manage Users Roles & Permissions</h1>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('modal_title'); ?>
    <h3><u>Dashboard Functionalities</u></h3>
    <b>
        <ol>
            <li>View All Users and their Roles and Permissions in the System </li>
            <li>Add New/Revoke Roles to a User </li>
            <li>Add New/Revoke Permissions to a User </li>
        </ol>
    </b>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\finewood\resources\views/user/manage-user-roles-and-permissions.blade.php ENDPATH**/ ?>