Initial Commit
This commit is contained in:
487
usuarios.php
Normal file
487
usuarios.php
Normal file
@@ -0,0 +1,487 @@
|
||||
<?php
|
||||
require_once 'class/c_login.php';
|
||||
require_once 'include/bd_pdo.php';
|
||||
$user = Login::get_user();
|
||||
|
||||
$user->access();
|
||||
|
||||
if ($user->acceso == null) {
|
||||
header('Location: main.php?error=1');
|
||||
} else {
|
||||
$user->print_to_log('Usuarios');
|
||||
}
|
||||
$fac = isset($_POST['facultad']) ? $_POST['facultad'] ?: null : null;
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Usuarios</title>
|
||||
<?php
|
||||
include 'import/html_css_files.php';
|
||||
?>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<?php
|
||||
include "import/html_header.php";
|
||||
html_header(
|
||||
"USUARIOS",
|
||||
"Gestión de Checador "
|
||||
);
|
||||
$user->access();
|
||||
|
||||
if (isset($_POST["desc"])) {
|
||||
$desc = $_POST["desc"];
|
||||
$filter_desc = htmlspecialchars($desc, ENT_QUOTES, 'UTF-8');
|
||||
} else {
|
||||
$desc = NULL;
|
||||
}
|
||||
|
||||
if (isset($_POST["clave"])) {
|
||||
$clave = $_POST["clave"];
|
||||
$filter_clave = htmlspecialchars($clave, ENT_QUOTES, 'UTF-8');
|
||||
} else {
|
||||
$clave = NULL;
|
||||
}
|
||||
|
||||
if (isset($_POST["rol"])) {
|
||||
if ($_POST['rol'] != "") {
|
||||
$rol = $_POST["rol"];
|
||||
$filter_rol = htmlspecialchars($rol, ENT_QUOTES, 'UTF-8');
|
||||
} else {
|
||||
$rol = NULL;
|
||||
}
|
||||
} else {
|
||||
$rol = NULL;
|
||||
}
|
||||
|
||||
if (isset($_POST["mnombre"])) {
|
||||
$desc = $_POST["mnombre"];
|
||||
$filter_desc = htmlspecialchars($desc, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
if (isset($_POST["mclave"])) {
|
||||
$clave = $_POST["mclave"];
|
||||
$filter_clave = htmlspecialchars($clave, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
$fs_usuarios = query(
|
||||
"SELECT * FROM fs_usuarios(:facultad, :nombre, :clave, :rol)",
|
||||
array(
|
||||
":facultad" => $fac,
|
||||
":nombre" => $desc,
|
||||
":clave" => $clave,
|
||||
":rol" => $rol
|
||||
),
|
||||
false
|
||||
);
|
||||
$fs_roles = $db
|
||||
->orderBy('rol_titulo', 'asc')
|
||||
->get("rol");
|
||||
if (!$user->facultad['facultad_id']) {
|
||||
$fs_facultades = $db
|
||||
->orderBy('facultad_nombre', 'asc')
|
||||
->get('facultad');
|
||||
}
|
||||
|
||||
$facultades = $db
|
||||
->orderBy('facultad_nombre', 'asc')
|
||||
->get('facultad');
|
||||
?>
|
||||
<main class="content marco">
|
||||
<?php if (($_GET['error'] ?? null) == 2) { ?>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
<h4 class="alert-heading">Error: Al insertar usuario. Verifica los datos.</h4>
|
||||
<p>Clave duplicada, o clave formato (ad123456)</p>
|
||||
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($user->acceso == 'w') { ?>
|
||||
<div class="row">
|
||||
<div class="col-12 text-right">
|
||||
<button type="button" class="btn btn-outline-secondary" data-toggle="modal" data-target="#modal"
|
||||
data-tipo="1"><span class="ing-mas ing-fw"></span> Crear Usuario</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<?php } ?>
|
||||
<!-- Filtro -->
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<form action="usuarios.php" method="post" onsubmit="return valida_filtro()">
|
||||
<div class="form-box">
|
||||
<div class="form-group row">
|
||||
<label for="filter_desc" class="col-4 col-form-label">Nombre</label>
|
||||
<div class="col-8">
|
||||
<input id="filter_desc" name="desc" type="text" class="form-control" <?php if (isset($filter_desc)) {
|
||||
echo 'value="' . $filter_desc . '"';
|
||||
} ?>>
|
||||
<div class="invalid-feedback" id="desc-error">
|
||||
Debe ser un numero
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="filter_clave" class="col-4 col-form-label">Clave</label>
|
||||
<div class="col-8">
|
||||
|
||||
<input id="filter_clave" name="clave" type="text" class="form-control" <?php if (isset($filter_desc)) {
|
||||
echo 'value="' . $filter_clave . '"';
|
||||
} ?>>
|
||||
<div class="invalid-feedback" id="clave-error">
|
||||
Debe ser un numero
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="filter_facultad" class="col-4 col-form-label">Facultad</label>
|
||||
<div class="col-8">
|
||||
<select id="filter_facultad" name="facultad" class="form-control" <?php if ($user->facultad['facultad_id']) { ?> disabled <?php } ?>>
|
||||
<option value="">Mostrar todas</option>
|
||||
<?php foreach ($facultades as $facultad) { ?>
|
||||
<option value="<?php echo $facultad['facultad_id']; ?>" <?php if (isset($_POST['facultad']) && $_POST['facultad'] == $facultad['facultad_id']) {
|
||||
echo 'selected';
|
||||
} ?>>
|
||||
<?php echo $facultad['facultad_nombre']; ?>
|
||||
</option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group row">
|
||||
<lab el for="filter_rol" class="col-4 col-form-label">Rol</label>
|
||||
<div class="col-8">
|
||||
<div class="datalist datalist-select mb-1 w-100">
|
||||
<div class="datalist-input">Mostrar todas</div>
|
||||
<span class="ing-buscar icono"></span>
|
||||
<ul style="display:none">
|
||||
|
||||
|
||||
<li data-id="" class="pl-4">Mostrar todas</li>
|
||||
<?php foreach ($fs_roles as $rol) { ?>
|
||||
<li data-id="<?php echo $rol['rol_id']; ?>" class="pl-4 <?php if (isset($filter_rol) && $rol["rol_id"] == $filter_rol) {
|
||||
echo 'selected';
|
||||
} ?>">
|
||||
<?php echo $rol['rol_titulo']; ?>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
<input type="hidden" id="filter_rol" name="rol" value="">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="col-12 text-center">
|
||||
<button type="submit" class="btn btn-outline-primary">
|
||||
<span class="ing-buscar ing-fw"></span>
|
||||
Filtrar
|
||||
</button>
|
||||
<button type="button" class="btn btn-outline-danger btn-reset">
|
||||
<span class="ing-borrar ing-fw"></span>
|
||||
Limpiar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div id="message"></div>
|
||||
<!-- Tabla -->
|
||||
<div class="row">
|
||||
<div class="col-12 table-responsive">
|
||||
<table class="table table-sm table-striped table-white">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
<th>Nombre</th>
|
||||
<th>Correo</th>
|
||||
<th>Clave</th>
|
||||
<th>Rol</th>
|
||||
<? if (!$user->facultad['facultad_id']) { ?>
|
||||
<th>Facultad</th>
|
||||
<? } ?>
|
||||
<? if ($user->acceso == 'w') { ?>
|
||||
<th>Acciones</th>
|
||||
<? } ?>
|
||||
</tr>
|
||||
|
||||
|
||||
</thead>
|
||||
|
||||
|
||||
<tbody>
|
||||
<?php foreach ($fs_usuarios as $usuario) { ?>
|
||||
<tr data-id="<?= $usuario['id'] ?>" data-facultad="<?= $fac ?>" id="<?= $usuario['id'] ?>">
|
||||
<td class="text-primary">
|
||||
<?= $usuario['username'] ?>
|
||||
</td>
|
||||
|
||||
<td class="text-primary">
|
||||
<?= $usuario['email'] ?>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<?= $usuario['clave'] ?>
|
||||
</td>
|
||||
<td class="text-primary">
|
||||
<?= $usuario['titulo'] ?>
|
||||
</td>
|
||||
<? if (!$user->facultad['facultad_id']) { ?>
|
||||
<td class="text-primary">
|
||||
<?= $usuario['facultad_nombre'] ?>
|
||||
</td>
|
||||
<? } ?>
|
||||
<? if ($user->acceso == 'w') { ?>
|
||||
<td class="text-center icono-acciones">
|
||||
<a href="#" data-toggle="modal" data-target="#modal" data-tipo="2" title="Editar"><span
|
||||
class="ing-editar ing-fw"></span></a>
|
||||
<a href="action/action_usuarios_delete.php?id=<?= $usuario['id'] ?>" title="Eliminar"
|
||||
onclick="return confirm('¿Estás seguro de que deseas eliminar este usuario?')"><span
|
||||
class="ing-borrar ing-fw"></span></a>
|
||||
</td>
|
||||
<? } ?>
|
||||
</tr>
|
||||
<? } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<!-- Footer -->
|
||||
<?php
|
||||
include "import/html_footer.php";
|
||||
?>
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="modal" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="col-12 modal-title text-center">
|
||||
<span id="modalLabel">
|
||||
Editar datos de Usuario
|
||||
</span>
|
||||
<button type="button" class="close text-white" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form action="" method="post" id="formaModal" onsubmit="return valida_campos()">
|
||||
<input type="hidden" name="id" id="id">
|
||||
<input type="hidden" name="mfacultad" id="mfacultad">
|
||||
<div class="form-box">
|
||||
<div class="form-group row">
|
||||
<label for="clave" class="col-4 col-form-label">Clave *</label>
|
||||
<div class="col-8">
|
||||
<input type="text" id="mclave" name="mclave" class="form-control" maxlength="8">
|
||||
<div class="invalid-feedback" id="mclave-error">
|
||||
Debe ser un numero
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="mnombre" class="col-4 col-form-label">Nombre *</label>
|
||||
<div class="col-8">
|
||||
<input type="text" id="mnombre" name="mnombre" class="form-control" maxlength="100">
|
||||
<div class="invalid-feedback" id="mnombre-error">
|
||||
Campo obligatorio
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label for="correo" class="col-4 col-form-label">Correo</label>
|
||||
<div class="col-8">
|
||||
<input type="text" id="mcorreo" name="mcorreo" class="form-control" maxlength="100">
|
||||
<div class="invalid-feedback" id="mcorreo-error">
|
||||
No puede tener espacios al inicio
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="mrol" class="col-4 col-form-label">Rol</label>
|
||||
<div class="col-8">
|
||||
<div class="datalist datalist-select mb-1 w-100">
|
||||
<div class="datalist-input">Mostrar todas</div>
|
||||
<span class="ing-buscar icono"></span>
|
||||
<ul style="display:none">
|
||||
<?php foreach ($fs_roles as $rol) { ?>
|
||||
<li data-id="<?= $rol['rol_id'] ?>" class="pl-4">
|
||||
<?= $rol['rol_titulo'] ?>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
<input type="hidden" id="mrol" name="mrol" value="">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<? if (!$user->facultad['facultad_id']) { ?>
|
||||
<div class="form-group row" id="mdatalist">
|
||||
<label for="dlfacultad" class="col-4 col-form-label">Facultad *</label>
|
||||
<div class="col-8">
|
||||
<div class="datalist datalist-select mb-1 w-100">
|
||||
<div class="datalist-input">Mostrar todas</div>
|
||||
<span class="ing-buscar icono"></span>
|
||||
<ul style="display:none">
|
||||
<li data-id="" class="pl-4">General</li>
|
||||
<?php foreach ($fs_facultades as $facultad) { ?>
|
||||
<li data-id="<?= $facultad['facultad_id'] ?>" class="pl-4">
|
||||
<?= $facultad['facultad_nombre'] ?>
|
||||
</li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
<input type="hidden" id="dlfacultad" name="dlfacultad" value="">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="offset-4 col-8">
|
||||
<button type="submit" class="btn btn-outline-primary" id="submitBtn" data-tipo="1">
|
||||
<span class="ing-aceptar ing-fw"></span> Guardar
|
||||
</button>
|
||||
<button type="reset" class="btn btn-outline-danger" data-dismiss="modal">
|
||||
<span class="ing-cancelar ing-fw"></span> Cancelar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</ div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="js/jquery.min.js"></script>
|
||||
<script src="js/bootstrap/bootstrap.min.js"></script>
|
||||
<script src="js/datalist.js"></script>
|
||||
<?php
|
||||
require_once 'js/messages.php';
|
||||
?>
|
||||
<script>
|
||||
<?php if (isset($_GET['error'])) {
|
||||
if ($_GET['error'] == 1) { ?>
|
||||
triggerMessage("Es ta cl ave ya está en uso", "Error");
|
||||
<?php }
|
||||
}
|
||||
?>
|
||||
|
||||
function valida_campos() {
|
||||
var error = false;
|
||||
if ($("#mclave").val() == "") {
|
||||
$("#mclave").addClass("is-invalid");
|
||||
$("#mclave-error").html("Campo obligatorio");
|
||||
error = true;
|
||||
} else {
|
||||
$("#mclave").removeClass("i s-invalid");
|
||||
}
|
||||
if ($("#mclave").val()[0] == "") {
|
||||
$("#mclave").addClass("is-invalid");
|
||||
$("#mclave-error").html("No puede tener espacios al inicio");
|
||||
error = true;
|
||||
}
|
||||
if ($("#mnombre").val() == "") {
|
||||
$("#mnombre").addClass("is-invalid");
|
||||
$("#mnombre-error").html("Campo obligatorio");
|
||||
error = true;
|
||||
} else {
|
||||
$("#mnombre").removeClass("is-invalid");
|
||||
}
|
||||
if ($("#mnombre").val()[0] == "") {
|
||||
$("#mnombre").addClass("is-invalid");
|
||||
$("#mnombre-error").html("No puede tener espacios al inicio");
|
||||
error = true;
|
||||
}
|
||||
if ($("#mcorreo").val()[0] == "") {
|
||||
$("#mcorreo").addClass("is-invalid");
|
||||
$("#mcorreo-error")
|
||||
error = true;
|
||||
}
|
||||
if (error == true) {
|
||||
return false;
|
||||
} else {
|
||||
var btn = $('#submitBtn');
|
||||
if (btn.data('tipo') == 2)//update
|
||||
$('#formaModal').prop("action", "./action/action_usuarios_update.php");
|
||||
else//insert
|
||||
$('#formaModal').prop('action', './action/action_usuarios_insert.php');
|
||||
}
|
||||
}
|
||||
$('#modal').on('show.bs.modal', function (event) {
|
||||
var button = $(event.relatedTarget);
|
||||
var tipo = button.data('tipo');
|
||||
var modal = $(this);
|
||||
// setDatalistFirst('#mrol');
|
||||
<?php if ($user->admin) { ?>
|
||||
// setDatalistFirst("#dlfacultad");
|
||||
<?php } ?>
|
||||
$("#mnombre").removeClass("is-invalid");
|
||||
$("#mclave").removeClass("is-invalid");
|
||||
$("#mcorreo").removeClass("is-invalid");
|
||||
if (tipo == 1) {//crear
|
||||
$('#modalLabe l').html("Crear Usuario");
|
||||
$('#mclave').val("");
|
||||
|
||||
$('#mnombre').val("");
|
||||
$('#mcorreo').val("");
|
||||
$('#id').val("");
|
||||
<?php if (!$user->facultad['facultad_id']) { ?>
|
||||
$('#mfacultad').val(<?= $fac ?>);
|
||||
<?php } ?>
|
||||
}
|
||||
else {//editar
|
||||
var id = $(event.relatedTarget).parents('tr').data('id');
|
||||
var fac = $(event.relatedTarget).parents('tr').data('facultad');
|
||||
$('#modalLabel').html("Editar Usuario");
|
||||
$('#id').val(id);
|
||||
$('#mfacultad').val(fac);
|
||||
$('#submitBtn').data('tipo', 2);
|
||||
$.ajax({
|
||||
url: "action/action_usuarios_select.php",
|
||||
type: "post",
|
||||
dataType: "json",
|
||||
data: { usuario: id },
|
||||
success: function (result) {
|
||||
console.log(result);
|
||||
$('#id').val(result['us uario_id']);
|
||||
$('#mfacultad').val(result['facultad_id']);
|
||||
$('#mnombre').val(result['usuario_nombre']);
|
||||
$('#mclave').val(result['usuario_clave']);
|
||||
$('#mcorreo').val(result['usuario_correo']);
|
||||
setDatalist('#mrol', result['rol_id']);
|
||||
<? if (!$user->facultad['facultad_id']) { ?>
|
||||
setDatalist('#dlfacultad', result['facultad_id']);
|
||||
<? } ?>
|
||||
},
|
||||
error: function () {
|
||||
console.log("Error")
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function valida_filtro() {
|
||||
var error = false;
|
||||
if ($('#filter_desc').val()[0] == "") {
|
||||
|
||||
$('#filter_desc').addClass("is-invalid");
|
||||
$('#desc-error').html("No puede tener espacios al inicio");
|
||||
error = true;
|
||||
}
|
||||
return !error;
|
||||
}
|
||||
|
||||
$(document).on("click", ".btn-reset", function (event) {
|
||||
var forma = $(this).parents("form");
|
||||
forma.find("input[type=text]").val("");
|
||||
// setDatalistFirst("#filter_rol");
|
||||
forma.submit();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user