{% extends "layout.html" %}
{% block title %}Mantenimiento usuarios{% endblock %}

{% set nav_active = 'acceso' %}
{% block content %}

{% if message_error %}
<div class="alert alert-danger alert-dismissible" role="alert">
	{{message_error}}
	<button type="button" class="close" data-dismiss="alert" aria-label="Close">
		<span aria-hidden="true">&times;</span>
	</button>
</div>
{% endif %}
{% if message_success %}
<div class="alert alert-success alert-dismissible" role="alert">
	{{message_success}}
	<button type="button" class="close" data-dismiss="alert" aria-label="Close">
		<span aria-hidden="true">&times;</span>
	</button>
</div>
{% endif %}

<div class="box">
	<div class="box-header with-border">
		<h3 class="box-title">Usuarios</h3>
		<div class="box-tools pull-right">
			<button class="btn btn-box-tool" data-widget="collapse">
				<i class="fa fa-minus"></i>
			</button>

			<button class="btn btn-box-tool" data-widget="remove">
				<i class="fa fa-times"></i>
			</button>
		</div>
	</div>
	<div class="box-body">
		<div class="row">
			<div class="col-md-12">

				<form action="accion_usuario.php" method="POST">
					<div class="row">
						<div class="form-group col-md-4">
							<label for="usuario">Nombre</label>
							<input class="form-control" type="text" name="nombre" id="usuario">
						</div>
						<div class="form-group col-md-4">
							<label for="password">Cargo</label>
							<input class="form-control" type="text" name="cargo" id="password">
						</div>
					</div>
					<div class="row">
						<div class="form-group col-md-4">
							<label for="usuario">Usuario</label>
							<input class="form-control" type="text" name="usuario" id="usuario">
						</div>
						<div class="form-group col-md-4">
							<label for="password">Password</label>
							<input class="form-control" type="password" name="password" id="password">
						</div>
						<div class="form-group col-md-2">
							<label for="nivel">Acceso</label>
							<select class="form-control" name="nivel" id="nivel">
								{% for nivel in niveles %}
								<option value="{{nivel.id}}">{{nivel.nombre}}</option>
								{% endfor %}
							</select>
						</div>
					</div>
					<input type="hidden" name="crear_usuario" value="true">
					<button class="btn btn-verdedark mt-4" type="submit">Crear</button>
				</form>

				<div class="table-responsive" style="margin-top: 30px;">
					<table class="table table-bordered table-striped">
						<thead class="text-uppercase">
							<tr>
								<th>Nombre</th>
								<th>Cargo</th>
								<th>Usuario</th>
								<th>Nivel</th>
								<th>Resetear</th>
								<th>Accion</th>
							</tr>
						</thead>
						<tbody>
							{% for usuario in usuarios %}
							{% if usuario.nick != "MARTERMUNI" or user.nick == "MARTERMUNI" %}
							<tr>
								<td>{{usuario.nombre}}</td>
								<td>{{usuario.cargo}}</td>
								<td>{{usuario.nick}}</td>
								<td>{{usuario.nivel}}</td>
								<td>
									<a class="btn btn-light"
										href="accion_usuario.php?usuario={{usuario.id}}&accion=reset">Resetear
										contrase&ntilde;a</a>
								</td>
								<td>
										
									<button type="button" class="btn btn-warning" data-toggle="modal"
										data-target="#myModal{{usuario.id}}">
										Eliminar
									</button>

									<!-- Modal -->
									<div class="modal fade" id="myModal{{usuario.id}}" tabindex="-1" role="dialog"
										aria-labelledby="myModalLabel{{usuario.id}}">
										<div class="modal-dialog" role="document" style="max-width: 350px;">
											<div class="modal-content">
												<div class="modal-header" style="padding: 5px 15px">
													<button type="button" class="close" data-dismiss="modal"
														aria-label="Close"><span
															aria-hidden="true">&times;</span></button>
													<h4 class="modal-title" id="myModalLabel{{usuario.id}}">Confirmaci&oacute;n</h4>
												</div>
												<div class="modal-body" style="font-size: 1.5rem;">
													¿Estas seguro que deseas eliminar al usuario <br> <b>{{usuario.nombre}} - {{usuario.nick}}?</b>
													<br><br>
													<small class="text-danger">* Esta acci&aacute;n no es reversible</small>
												</div>
												<div class="modal-footer" style="padding: 5px 15px">
													<button type="button" class="btn btn-default"
														data-dismiss="modal">No</button>
													<a class="btn btn-warning" href="accion_usuario.php?usuario={{usuario.id}}&accion=delete">Eliminar</a>
												</div>
											</div>
										</div>
									</div>
									<!--/. Modal -->
								</td>
							</tr>
							{% endif %}
							{% endfor %}
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
</div>




{% endblock %}