

<?php $__env->startSection('title', __('backend.user-management')); ?>

<?php $__env->startSection('content'); ?>

<?php 
    $page = 'users';
 ?>
<?php if(Auth::user()->level != '1'): ?>
    <script type="text/javascript">
        window.location.href="<?php echo e(route('backendHome')); ?>";
    </script>
<?php endif; ?>
    <!-- MAIN CONTENT -->
    <div class="container-fluid">
    	<div class="row">
		    <div class="col-xs-12">
			    <div class="panel panel-primary">
			    	<div class="panel-heading">
			    		<a class="btn btn-success" href="<?php echo e(route('register')); ?>"><?php echo app('translator')->getFromJson('backend.register-new-user'); ?></a>
			    	</div>
			    	<div class="panel-body">
				    	<?php if(Session::has('message')): ?>
							<div class="alert <?php echo e(Session::get('alert-class')); ?> alert-dismissible" role="alert">
								<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
							 	<p><?php echo e(Session::get('message')); ?></p>
							</div>
						<?php endif; ?>
				    	<div class="table-responsive">
				    		<table id="usersTable" class="table table-hover">
							    <thead>
								    <tr>
								    	<th class="text-center">#</th>
								        <th><?php echo app('translator')->getFromJson('backend.name'); ?></th>
								        <th><?php echo app('translator')->getFromJson('backend.email'); ?></th>
								        <th><?php echo app('translator')->getFromJson('backend.level'); ?></th>
								        <th class="text-center"><?php echo app('translator')->getFromJson('backend.options'); ?></th>
								    </tr>
							    </thead>
							    <tbody>
								    <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
									    <tr>
									    	<td class="text-center"><?php echo e($key+1); ?></td>
									        <td><?php echo e($val->name); ?></td>
									        <td><?php echo e($val->email); ?></td>
									        <td><?php echo e(($val->level=='1')?'Administrator':'Operator'); ?></td>
									        <td class="text-center">
									        	<a class="btn btn-warning" href="<?php echo e(route('userUpdate',['id'=>$val->id])); ?>" title="Update data">
									        		<i class="fa fa-pencil" aria-hidden="true"></i>
									        	</a>

												
									        	<?php 
									        		if($val->level != 1){
									        	 ?>
												<button title="Make <?php echo e(($val->level == '1')?'Operator':'Admin'); ?>" class="btn btn-success" data-toggle="modal" data-target="#level<?php echo e($val->id); ?>"><i class="fa fa-angle-double-up" aria-hidden="true"></i></button>
												<div id="level<?php echo e($val->id); ?>" class="modal fade" role="dialog">
													<div class="modal-dialog modal-sm">

													<form class="" method="post" action="<?php echo e(route('levelUser')); ?>">
														<?php echo e(csrf_field()); ?>

														<input name="id" value="<?php echo e($val->id); ?>" type="hidden">
														<input name="level" value="<?php echo e($val->level); ?>" type="hidden">
														<div class="modal-content text-center">
															<div class="modal-body">
																<h3>Make <strong>'<?php echo e($val->name); ?>'</strong> as <?php echo e(($val->level == '1')?'Operator':'Admin'); ?>?</h3>

																<button type="submit" class="btn btn-primary"><?php echo app('translator')->getFromJson('backend.make-admin'); ?></button>
															<button class="btn btn-default" data-dismiss="modal"><?php echo app('translator')->getFromJson('backend.cancel'); ?></button>
															</div>
														</div>
													</form>

													</div>
												</div>
												<?php 
													}
												 ?>

									        	
									        	<?php 
									        		if(count($users) > 1 && $val->id != Auth::user()->id){
									        	 ?>
												<button title="Delete user" class="btn btn-danger" data-toggle="modal" data-target="#delete<?php echo e($val->id); ?>"><i class="fa fa-trash" aria-hidden="true"></i></button>
												<div id="delete<?php echo e($val->id); ?>" class="modal fade" role="dialog">
													<div class="modal-dialog modal-sm">

													<form class="" method="post" action="<?php echo e(route('deleteUser',['id'=>$val->id])); ?>">
														<?php echo e(method_field('DELETE')); ?>

														<?php echo e(csrf_field()); ?>

														<input name="id" value="<?php echo e($val->id); ?>" type="hidden">
														<div class="modal-content text-center">
															<div class="modal-body">
																<h3><?php echo app('translator')->getFromJson('backend.ask-delete-user'); ?></h3>

																<button type="submit" class="btn btn-primary"><?php echo app('translator')->getFromJson('backend.delete'); ?></button>
															<button class="btn btn-default" data-dismiss="modal"><?php echo app('translator')->getFromJson('backend.cancel'); ?></button>
															</div>
														</div>
													</form>

													</div>
												</div>
												<?php 
													}
												 ?>
									        </td>
									    </tr>
									<?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
							    </tbody>
							</table>
				    	</div>
			    	</div>
			    </div>
		    </div>
		</div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('script'); ?>
<script type="text/javascript">
	$("#usersTable").DataTable();
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.masterBackend', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>