<?php $__env->startSection('titulo', 'Gestion de Usuarios'); ?>
<?php $__env->startSection('css'); ?>
	<style type="text/css">
		.btn-desfasado{
			margin-top: -30px;
			margin-right: 86px;
		}
		.btn-desfasado-delete{
			margin-right: 15px;
    		margin-top: -30px;
		}
	</style>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('botonera'); ?>
	<?php if(strstr(Auth::user()->permisos['usuarios'], 'c') || Auth::user()->id == 1): ?>
		<li class="form-group">
			<a href="<?php echo URL::to('/usuario/create'); ?>" class="btn btn-primary">Crear Usuario</a>
		</li>
	<?php endif; ?>
	<?php echo $__env->make('componentes.boton-salir-sin-aviso', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
	<?php echo $__env->make('alerts.success', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

	<div class="row">
		<div class="col-xs-12">
			<h3>Listado de Usuarios<small><br>Presiona click sobre el usuario para conocer sus permisos.</small></h3>
		</div>
	</div>
	<div class="row">
		<div class="col-xs-12">

			<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
				<?php foreach($users as $user): ?>
					<div class="panel
						<?php if($user->deleted_at): ?>
							panel-danger
						<?php else: ?>
							panel-default
						<?php endif; ?>
					">
						<div class="panel-heading" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-<?php echo $user->id; ?>" aria-expanded="true" aria-controls="collapse-<?php echo $user->id; ?>" id="heading-<?php echo $user->id; ?>">
							<strong> <?php echo e($user->name); ?> </strong>
							<?php if($user->es_responsable): ?>
								(Usuario Responsable)
							<?php endif; ?>
						</div>
							<?php if(Auth::user()->id == 1 || strstr(Auth::user()->permisos['usuarios'], 'd')): ?>
								<?php echo Form::open(['route'=>['usuario.destroy', $user->id], 'method'=>'DELETE']); ?>

								<?php if($user->deleted_at): ?>
									<?php echo Form::submit('Habilitar', ['class'=>'btn btn-success btn-xs btn-right btn-desfasado-delete']); ?>

								<?php else: ?>
									<?php echo Form::submit('inhabilitar', ['class'=>'btn btn-danger btn-xs btn-right btn-desfasado-delete']); ?>

								<?php endif; ?>
								<?php echo Form::close(); ?>

							<?php endif; ?>
							<?php if(Auth::user()->id == 1 || strstr(Auth::user()->permisos['usuarios'], 'u')): ?>
								<?php if(!$user->deleted_at): ?>
									<?php echo link_to_route('usuario.edit', $title = 'Editar', $parameters = $user->id, $attributes = ['class'=>'btn btn-primary btn-xs btn-right btn-desfasado']); ?>

								<?php endif; ?>
							<?php endif; ?>
						<div id="collapse-<?php echo $user->id; ?>" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
							<table class="panel-body table table-striped table-bordered table-hover table-condensed">
								<tr class="info">
									<td colspan="2">
								<?php if(!isset($permisos["$user->id"])): ?>
									El usuario no tiene asociado permisos de Acceso.
								<?php else: ?>
									Permisos de Acceso:
										</td>
									</tr>
									<?php foreach($permisos["$user->id"] as $permiso): ?>
										<tr>
											<td><?php echo e($permiso->tabla); ?></td>
											<td><?php echo e($permiso->capacidad); ?></td>
										</tr>
									<?php endforeach; ?>
								<?php endif; ?>
								<tr class="info">
									<td colspan='2'>
								<?php if(isset($permitidosI["$user->id"]) && count($permitidosI["$user->id"]) != 0): ?>
									Tiene permiso para realizar <strong>Inscripción</strong> en los siguientes programas:
								<?php else: ?>
									No tiene permiso para realizar <strong>Inscripciones</strong>.
								<?php endif; ?>
									</td>
								</tr>
								<?php if(isset($permitidosI["$user->id"])): ?>
									<?php foreach($permitidosI["$user->id"] as $permitido): ?>
										<tr>
											<td colspan='2'><?php echo e($permitido->programa); ?></td>
										</tr>
									<?php endforeach; ?>
								<?php endif; ?>
								<tr class="info">
									<td colspan='2'>
								<?php if(isset($permitidosI["$user->id"]) && count($permitidosS["$user->id"]) != 0): ?>
									Tiene permiso para realizar <strong>Seguimiento</strong> en los siguientes programas:
								<?php else: ?>
									No tiene permiso para realizar <strong>Seguimientos</strong>.
								<?php endif; ?>
									</td>
								</tr>
								<?php if(isset($permitidosI["$user->id"])): ?>
									<?php foreach($permitidosS["$user->id"] as $permitido): ?>
										<tr>
											<td colspan='2'><?php echo e($permitido->programa); ?></td>
										</tr>
									<?php endforeach; ?>
								<?php endif; ?>
							</table>
						</div>
					</div>
				<?php endforeach; ?>
			</div>

		</div>
	</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.admin-bloqueo-vista', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>