<?php $__env->startSection('title', 'Manage User Account'); ?>


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

            $('#active-table').dataTable();
            $('#blocked-table').dataTable();
            $('#super-admin-table').dataTable();
            $('#search-user').select2();


            
            $('#submit-search').on('click', function () {
                let stamp = $('#search-user').val();
                if (stamp == "") {
                    alert('Please Select a User Account to Search');
                } else {
                    window.location = '/manage-user/' + stamp + '?type=modules';
                }
            });

            $('#modules-url').on('click', function (){
                window.history.pushState({}, null, '?type=modules');
            });
            $('#create-url').on('click', function (){
                window.history.pushState({}, null, '?type=create');
            });
            $('#read-url').on('click', function (){
                window.history.pushState({}, null, '?type=read');
            });
            $('#update-url').on('click', function (){
                window.history.pushState({}, null, '?type=update');
            });
            $('#delete-url').on('click', function (){
                window.history.pushState({}, null, '?type=delete');
            });
            $('#approve-url').on('click', function (){
                window.history.pushState({}, null, '?type=approve');
            });
        });

        
        function updateUserModules(id, stamp){
            var route_link = '/edit-user-modules/'+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>');
            $('#edit_dialog_content').load(encodeURI(route_link));
            $('#edit_dialog_content').dialog({
                modal: true,
                width: 500,
                title: "Update User Modules",

                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);
                                $("#my-button-1").text('Please Wait....');*/
                                var datas = $('#update-user-modules').serializeArray();

                                $.ajax({
                                    method: "POST",
                                    url: route_link,
                                    data: datas,
                                    success: function (res){
                                        if(res == 'success'){
                                            window.location = '/manage-user/'+stamp+'?type=modules&updateModules=true';
                                        }else if(res == 'error'){
                                            window.location = '/manage-user/'+stamp+'?type=modules&updateModules=false';
                                        }else{
                                            alert('System Encountered an Error. Please Contact System Admin');
                                            location.reload();
                                        }
                                    }
                                });
                            }
                            return false;
                        }
                    }
                ],
                open: function() {
                    $(this).parent().css({'top': 50});
                }
            });
        }

        
        function updateUserCreates(id,stamp){
            var route_link = '/edit-user-creates/'+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>');
            $('#edit_dialog_content').load(encodeURI(route_link));
            $('#edit_dialog_content').dialog({
                modal: true,
                width: 500,
                title: "Update what the User can Create in the System",

                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();
                                var datas = $('#update-user-creates').serializeArray();

                                $.ajax({
                                    method: "POST",
                                    url: route_link,
                                    data: datas,
                                    success: function (res){
                                        if(res == 'success'){
                                            window.location = '/manage-user/'+stamp+'?type=create&updateCreates=true';
                                        }else if(res == 'error'){
                                            window.location = '/manage-user/'+stamp+'?type=create&updateCreates=false';
                                        }else{
                                            alert('System Encountered an Error. Please Contact System Admin');
                                            location.reload();
                                        }
                                    }
                                });
                            }
                            return false;
                        }
                    }
                ],
                open: function() {
                    $(this).parent().css({'top': 50});
                }
            });
        }

        
        function updateUserViews(id,stamp){
            var route_link = '/edit-user-views/'+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: "Update what the User can View in the System",

                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();
                                var datas = $('#update-user-views').serializeArray();

                                $.ajax({
                                    method: "POST",
                                    url: route_link,
                                    data: datas,
                                    success: function (res){
                                        if(res == 'success'){
                                            window.location = '/manage-user/'+stamp+'?type=read&updateViews=true';
                                        }else if(res == 'error'){
                                            window.location = '/manage-user/'+stamp+'?type=read&updateViews=false';
                                        }else{
                                            alert('System Encountered an Error. Please Contact System Admin');
                                            location.reload();
                                        }
                                    }
                                });
                            }
                            return false;
                        }
                    }
                ],
                open: function() {
                    $(this).parent().css({'top': 50});
                }
            });
        }

        
        function updateUserEdits(id,stamp){
            var route_link = '/edit-user-edits/'+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: "Update what the User can Edit/Update in the System",

                    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();
                                    var datas = $('#update-user-edits').serializeArray();

                                    $.ajax({
                                        method: "POST",
                                        url: route_link,
                                        data: datas,
                                        success: function (res){
                                            if(res == 'success'){
                                                window.location = '/manage-user/'+stamp+'?type=update&updateEdits=true';
                                            }else if(res == 'error'){
                                                window.location = '/manage-user/'+stamp+'?type=update&updateEdits=false';
                                            }else{
                                                alert('System Encountered an Error. Please Contact System Admin');
                                                location.reload();
                                            }
                                        }
                                    });
                                }
                                return false;
                            }
                        }
                    ],
                    open: function() {
                        $(this).parent().css({'top': 50});
                    }
                });
        }
        
        function updateUserDeletes(id,stamp){
            var route_link = '/edit-user-deletes/'+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: "Update what the User can Delete in the System",

                    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();
                                    var datas = $('#update-user-deletes').serializeArray();

                                    $.ajax({
                                        method: "POST",
                                        url: route_link,
                                        data: datas,
                                        success: function (res){
                                            if(res == 'success'){
                                                window.location = '/manage-user/'+stamp+'?type=delete&updateDeletes=true';
                                            }else if(res == 'error'){
                                                window.location = '/manage-user/'+stamp+'?type=delete&updateDeletes=false';
                                            }else{
                                                alert('System Encountered an Error. Please Contact System Admin');
                                                location.reload();
                                            }
                                        }
                                    });
                                }
                                return false;
                            }
                        }
                    ],
                    open: function() {
                        $(this).parent().css({'top': 50});
                    }
                });
        }

        
        function backToUsers(){
            window.location = '/user-accounts?type=active';
        }
    </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;}

        #blocked-table th, td {
            text-align: left;
            padding: 4px;
        }
        #blocked-table tr:hover {background-color: #cbd1f8;}

        #super-admin-table th, td {
            text-align: left;
            padding: 4px;
        }
        #super-admin-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 Account for:
    <span class="error" ><?php echo $user->firstName." ".$user->lastName; ?>: </span>
    <span class="success"> <?php echo $user->accessType($user->access); ?></span> |
    <span class="error">
        <?php if($user->branchDetails != null): ?>
            <?php echo $user->branchDetails->name.' Branch'; ?>

        <?php endif; ?>
    </span>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('searches'); ?>
    <?php echo Form::open(['route'=>'search-client'],['method'=>'POST']); ?>

    <div style="float: right">
        <br>
        <div class="guestDetails_input">
            <div class="guestDetails_input" style="text-align: center">
                <select name="search-client" id="search-user" style="max-width: 180px" required>
                    <option value="">--Select User Account.--</option>
                    <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($row->stamp); ?>"><?php echo $row['firstName']." ".$row['lastName']; ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
        </div>
        <div class="guestDetails_input">
            <div class="guestDetails_input">
                <button type="button" id="submit-search" style="width: auto; height: 20px; cursor: pointer"
                        title="Search User"><i class="fa fa-search" aria-hidden="true"></i></button>
            </div>
        </div>
    </div>
    <?php echo Form::close(); ?>

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


<?php $__env->startSection('content'); ?>
    <?php if(isset($_GET['userCreated'])): ?>
        <div class="error-section">
            <span onclick="this.parentElement.style.display='none'" class="topright" style="color: white ;margin-top: -4px;font-weight: bold; margin-right: 5px">&times</span>
            <?php if($_GET['userCreated'] == 'success'): ?>
                <div class="yesFound">User Account Created Successfully</div><br>
            <?php elseif($_GET['userCreated'] == 'error'): ?>
                <div class="notFound">There was an error while trying to create New User Account</div><br>
            <?php endif; ?>
        </div>
    <?php endif; ?>
    <?php if(isset($_GET['updateUser'])): ?>
        <div class="error-section">
            <span onclick="this.parentElement.style.display='none'" class="topright" style="color: white ;margin-top: -4px;font-weight: bold; margin-right: 5px">&times</span>
            <?php if($_GET['updateUser'] == 'true'): ?>
                <div class="yesFound">User Account Details updated Successfully</div><br>
            <?php elseif($_GET['updateUser'] == 'false'): ?>
                <div class="notFound">There was an error while trying to update User Account Details</div><br>
            <?php endif; ?>
        </div>
    <?php endif; ?>
    <?php if(isset($_GET['updateModules'])): ?>
        <div class="error-section">
            <span onclick="this.parentElement.style.display='none'" class="topright" style="color: white ;margin-top: -4px;font-weight: bold; margin-right: 5px">&times</span>
            <?php if($_GET['updateModules'] == 'true'): ?>
                <div class="yesFound">Accessible User Modules updated Successfully</div><br>
            <?php elseif($_GET['updateModules'] == 'false'): ?>
                <div class="notFound">There was an error while trying to update Accessible User Modules</div><br>
            <?php endif; ?>
        </div>
    <?php endif; ?>
    <?php if(isset($_GET['updateCreates'])): ?>
        <div class="error-section">
            <span onclick="this.parentElement.style.display='none'" class="topright" style="color: white ;margin-top: -4px;font-weight: bold; margin-right: 5px">&times</span>
            <?php if($_GET['updateCreates'] == 'true'): ?>
                <div class="yesFound">Items to be created by User have been updated Successfully</div><br>
            <?php elseif($_GET['updateCreates'] == 'false'): ?>
                <div class="notFound">There was an error while trying to update Items to be created by specified User</div><br>
            <?php endif; ?>
        </div>
    <?php endif; ?>
    <?php if(isset($_GET['updateViews'])): ?>
        <div class="error-section">
            <span onclick="this.parentElement.style.display='none'" class="topright" style="color: white ;margin-top: -4px;font-weight: bold; margin-right: 5px">&times</span>
            <?php if($_GET['updateViews'] == 'true'): ?>
                <div class="yesFound">Items to be viewed by User have been updated Successfully</div><br>
            <?php elseif($_GET['updateViews'] == 'false'): ?>
                <div class="notFound">There was an error while trying to update Items to be viewed by specified User</div><br>
            <?php endif; ?>
        </div>
    <?php endif; ?>

    <button onclick="backToUsers()" type="button" class="navButtons" style="; margin-left: 0; background: grey; margin-bottom: 0">&#9756; BACK TO USER ACCOUNTS</button>
    <div class="guestDetails_inputDivider"></div>
    <div class="tab">
        <button class="tablinks" onclick="openCity(event, 'modules')" <?php if(isset($_GET['type']) && $_GET['type'] == 'modules'): ?>id="defaultOpen" <?php else: ?> id="modules-url"<?php endif; ?>>User's Modules</button>
        
        <button class="tablinks" onclick="openCity(event, 'read')" <?php if(isset($_GET['type']) && $_GET['type'] == 'read'): ?>id="defaultOpen" <?php else: ?> id="read-url"<?php endif; ?>>User's Reads/Views</button>
        <button class="tablinks" onclick="openCity(event, 'update')" <?php if(isset($_GET['type']) && $_GET['type'] == 'update'): ?>id="defaultOpen" <?php else: ?> id="update-url"<?php endif; ?>>User's Edits/Updates</button>
        <button class="tablinks" onclick="openCity(event, 'delete')" <?php if(isset($_GET['type']) && $_GET['type'] == 'delete'): ?>id="defaultOpen" <?php else: ?> id="delete-url"<?php endif; ?>>User's Deletions</button>
        <button class="tablinks" onclick="openCity(event, 'approve')" <?php if(isset($_GET['type']) && $_GET['type'] == 'approve'): ?>id="defaultOpen" <?php else: ?> id="approve-url"<?php endif; ?>>User's Approvals</button>
    </div>

    <div id="modules" class="tabcontent">
        <span onclick="this.parentElement.style.display='none'" class="topright" style="margin-left: 20px">&times</span>
        <h3 class="error">
            User's Modules
            <button onclick="updateUserModules('<?php echo e($user->id); ?>', '<?php echo e($user->stamp); ?>')" class="section-button"> Click to Update User's Modules</button>
        </h3>
        <?php echo $__env->make('user.user-modules', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    </div>
    <div id="create" class="tabcontent">
        <span onclick="this.parentElement.style.display='none'" class="topright" style="margin-left: 20px">&times</span>
        <h3 class="error">
            What the User Can Create
            <?php if($userCreates != null): ?>
            <?php endif; ?>
            <button onclick="updateUserCreates('<?php echo e($user->id); ?>', '<?php echo e($user->stamp); ?>')" class="section-button"> Click to Update what the User can Create</button>
        </h3>
        <?php echo $__env->make('user.user-creates', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    </div>
    <div id="read" class="tabcontent">
        <span onclick="this.parentElement.style.display='none'" class="topright" style="margin-left: 20px">&times</span>
        <h3 class="error">
            What the User Can View
            <?php if($userViews != null): ?>
                <button onclick="updateUserViews('<?php echo e($user->id); ?>', '<?php echo e($user->stamp); ?>')" class="section-button">  Click to Update what the User can View</button>
            <?php endif; ?>
        </h3>
        <?php echo $__env->make('user.user-views', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    </div>
    <div id="update" class="tabcontent">
        <span onclick="this.parentElement.style.display='none'" class="topright" style="margin-left: 20px">&times</span>
        <h3 class="error">
            What the User Can Edit
            <?php if($userEdits != null): ?>
                <button onclick="updateUserEdits('<?php echo e($user->id); ?>', '<?php echo e($user->stamp); ?>')" class="section-button"> Click to Update what the User can Edit</button>
            <?php endif; ?>
        </h3>
        <?php echo $__env->make('user.user-edits', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    </div>
    <div id="delete" class="tabcontent">
        <span onclick="this.parentElement.style.display='none'" class="topright" style="margin-left: 20px">&times</span>
        <h3 class="error">
            What the User Can Delete
            <?php if($userDeletes != null): ?>
                <button onclick="updateUserDeletes('<?php echo e($user->id); ?>', '<?php echo e($user->stamp); ?>')" class="section-button"> Click to Update what the User can Delete</button>
            <?php endif; ?>
        </h3>
        <?php echo $__env->make('user.user-deletes', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
    </div>
    <div id="approve" class="tabcontent">
        <span onclick="this.parentElement.style.display='none'" class="topright" style="margin-left: 20px">&times</span>
        <h3 class="error">
            What the User Can Approve
            <button onclick="updateUserApprovals('<?php echo e($user->id); ?>', '<?php echo e($user->stamp); ?>')" class="section-button"> Click to Update what the User can Approve</button>
        </h3>
    </div>
<?php $__env->stopSection(); ?>



<?php $__env->startSection('modal_heading'); ?>
    <h1>Manage User Account</h1>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('modal_title'); ?>
    <h3><u>Dashboard Functionalities</u></h3>
    <b>
        <ol>
            <li>View and Manage Modules accessible by this User </li>
            <li>View and Manage what this User can create in the system</li>
            <li>View and Manage what this user can View/Read in the System</li>
            <li>View and Manage what this user can delete in the system</li>
            <li>View and Manage what this user can approve in the system</li>
        </ol>
    </b>
<?php $__env->stopSection(); ?>








<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/zedarroot/public_html/edwulp/resources/views/manage-user.blade.php ENDPATH**/ ?>