429 lines
18 KiB
PHP
429 lines
18 KiB
PHP
<?php
|
|
# print_r($_POST); exit;
|
|
|
|
require_once 'class/c_login.php';
|
|
|
|
if (!isset($_SESSION['user']))
|
|
die(header('Location: index.php'));
|
|
|
|
$user = unserialize($_SESSION['user']);
|
|
|
|
$user->access('reporte_de_asistencias');
|
|
if ( $user->acceso == null )
|
|
die(header('Location: main.php?error=1'));
|
|
|
|
$user->print_to_log('Consultar: Reporte de asistencias de profesor');
|
|
|
|
|
|
#$required_post = ['id', 'fecha_inicial', 'fecha_final', 'periodo'];
|
|
#if (array_diff($required_post, array_keys($_POST)))
|
|
#header('Location: s.php');
|
|
|
|
extract($_POST);
|
|
$post_keys = array_keys($_POST);
|
|
|
|
if (
|
|
!in_array('fecha_inicial', $post_keys) ||
|
|
!in_array('fecha_final', $post_keys)
|
|
) {
|
|
header('Location: reporte_de_asistencias.php');
|
|
exit;
|
|
}
|
|
|
|
|
|
|
|
# date validation
|
|
$fecha_inicial = date_create_from_format("d/m/Y", $fecha_inicial);
|
|
$fecha_final = date_create_from_format("d/m/Y", $fecha_final);
|
|
|
|
|
|
// Nombre del profesor es opcional
|
|
$reporte = queryAll("SELECT * FROM fs_asistencia_profesorreporte(:carrera, :periodo, :id, :initial_date, :final_date)
|
|
WHERE materia_id = COALESCE(:materia, materia_id)",
|
|
array(
|
|
":carrera" => empty($carrera) ? null : $carrera,
|
|
":periodo" => $user->periodo_id,
|
|
":id" => $id,
|
|
":initial_date" => $fecha_inicial->format("Y-m-d"),
|
|
":final_date" => $fecha_final->format("Y-m-d"),
|
|
":materia" => empty($materia) ? null : $materia
|
|
)
|
|
);
|
|
|
|
$profesor = query(
|
|
"SELECT * FROM FS_PROFESOR WHERE id = :id",
|
|
array(":id" => $id)
|
|
);
|
|
|
|
$asistencias = query("SELECT total, asistencias, retardos, justificaciones FROM fs_asistencia_reporte(:carrera, :periodo, :clave, :nombre, :facultad, :initial_date, :final_date)",
|
|
array(
|
|
":carrera" => empty($carrera) ? null : $carrera,
|
|
":periodo" => $user->periodo_id,
|
|
":clave" => $profesor['clave'],
|
|
":nombre" => $profesor['profesor'],
|
|
":facultad" => $user->facultad['facultad_id'],
|
|
":initial_date" => $fecha_inicial->format("Y-m-d"),
|
|
":final_date" => $fecha_final->format("Y-m-d"),
|
|
),
|
|
);
|
|
|
|
// die(var_dump($asistencias));
|
|
|
|
$retardos = query("SELECT FS_HAS_RETARDO(:facultad) AS retardo", array(":facultad" => $user->facultad['facultad_id']))['retardo']; ?>
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<head>
|
|
<title>Reporte asistencias</title>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
|
<?php
|
|
include_once "import/html_css_files.php";
|
|
?>
|
|
|
|
</head>
|
|
|
|
<body style="display: block;">
|
|
<?php
|
|
include("import/html_header.php");
|
|
html_header("Reporte de asistencias", "Sistema de gestión de checador");
|
|
?>
|
|
<main class="container content marco content-margin">
|
|
<div class="container ml-4">
|
|
|
|
<div class="row my-3">
|
|
<h3 class="ml-4 text-left"><?= $profesor['profesor'] ?></h3>
|
|
</div>
|
|
<div class="row my-3">
|
|
<h4 class="ml-4 text-left text-danger"><b>Clave:</b> <?= $profesor['clave'] ?></h4>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-12 text-right">
|
|
<button type="button" class="btn btn-outline-secondary" onclick="submit('reporte_de_asistencias.php', {clave: <?= $profesor['clave'] ?>, periodo: <?= $user->periodo_id ?>, nombre: '<?= $profesor['profesor'] ?>', fecha_inicial: '<?= $fecha_inicial->format('Y-m-d') ?>', fecha_final: '<?= $fecha_final->format('Y-m-d') ?>'})">
|
|
<span class="ing-regresar ing-fw"></span>
|
|
Regresar
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<?php
|
|
require_once "import/html_forms_vista.php";
|
|
?>
|
|
|
|
<section id="message"></section>
|
|
<!-- Space -->
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<hr>
|
|
</div>
|
|
</div>
|
|
<div id="barra-profesor"></div>
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<hr>
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<?php
|
|
if (!empty($reporte)) {
|
|
?>
|
|
<!-- legend check (Asistencia) x | (sin registro) | * (Justificada) -->
|
|
<div class="row text-right">
|
|
<div class="col-12">
|
|
<i class='ing-aceptar' style='color:green'></i><span class="text-success"> Asistencia</span> |
|
|
<?php if ($retardos) { ?>
|
|
<i class='ing-retardo' style='color:orange'></i><span style="color:orange"> Retardo</span> |
|
|
<?php } ?>
|
|
<i class='ing-cancelar text-danger'></i><span class="text-danger"> Sin registro</span> | <i class='ing-justificar azul'></i><span class="azul"> Justificada</span>
|
|
</div>
|
|
</div>
|
|
|
|
<table class="table table-striped table-hover table-white mt-4 table-sm">
|
|
<thead class="thead-dark">
|
|
<tr>
|
|
<th>Grupo</th>
|
|
<th>Salón</th>
|
|
<th>Materia</th>
|
|
<th>Fecha</th>
|
|
<th>Hora de clase</th>
|
|
<th>Checado</th> <!-- 3 -->
|
|
<th></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php
|
|
$días = array("Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado");
|
|
//red icon cross
|
|
$cross_icon = "<i class='ing-cancelar text-danger'></i>";
|
|
$check_icon = "<i class='ing-aceptar text-success'></i>";
|
|
$retardo_icon = "<i class='ing-retardo' style='color:orange'></i>";
|
|
$justificado_icon = "<i class='ing-justificar azul'></i>";
|
|
|
|
# print_r($reporte);
|
|
foreach ($reporte as $row) {
|
|
# print_r($row);
|
|
$justificable = false;
|
|
if ($row["checado"] == 1)
|
|
if ($row["justificada"] == 1)
|
|
$checado = $justificado_icon;
|
|
else if ($row["retardo"] == 1)
|
|
$checado = $retardo_icon;
|
|
else
|
|
$checado = $check_icon;
|
|
else {
|
|
$checado = $cross_icon;
|
|
$justificable = true;
|
|
}
|
|
|
|
$fecha = date("d/m/Y", strtotime($row["fecha"]));
|
|
$hora = date("H:i", strtotime($row['hora']));
|
|
$hora_checado = is_null($row["hora_checado"]) ? '-' : date("H:i:s", strtotime($row["hora_checado"]));
|
|
$horario = $db->getOne("fget_horario({$row['id']})");
|
|
?>
|
|
<tr class="text-nowrap" id="<?= $row["id"] ?>">
|
|
<!-- <td class="complete"><pre><?= print_r($row, true) ?></pre></td> -->
|
|
<td class="text-center"><?= $row["grupo"] ?></td>
|
|
<td class="text-center"><?= $horario["salon"] ?></td>
|
|
<td id="<?= $row["materia_id"] ?>"><?= $row["materia"] ?></td>
|
|
<td class="text-center text-nowrap"><?= $fecha ?> | <?= $días[date("w", strtotime($row["fecha"]))] ?></td>
|
|
<!-- "hh:mm:ss" -> "hh:mm" -->
|
|
<td class="text-center text-nowrap"><?= $hora ?> - <?= join(":", array_slice(explode(":", $horario["hora_final"]), 0, 2)) ?></td>
|
|
<td class="text-center"><?= $checado ?></td>
|
|
<td class="text-center">
|
|
<?php if ($justificable) { ?>
|
|
<button class='btn btn-sm btn-outline-primary' onclick="justificar(<?= $row['id'] ?>, '<?= $fecha ?>', ' <?= $hora ?>')">Justificar</button>
|
|
<?php } else { ?>
|
|
<?= !$row["justificada"] ? $hora_checado : "<b>Justificada</b>" ?>
|
|
<?php } ?>
|
|
</td>
|
|
</tr>
|
|
<?php
|
|
}
|
|
|
|
?>
|
|
</tbody>
|
|
</table>
|
|
<?php
|
|
} else { ?>
|
|
<div class='alert alert-warning'>No hay registros para mostrar</div>
|
|
<?php
|
|
}
|
|
?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php
|
|
include_once "import/html_scroll.php";
|
|
?>
|
|
</main>
|
|
<?php
|
|
include("import/html_footer.php");
|
|
?>
|
|
|
|
<template id="messages_tmp">
|
|
<div class="alert alert-{{type}} alert-dismissible fade show" role="alert">
|
|
{{message}}
|
|
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
</div>
|
|
</template>
|
|
|
|
<div class="modal fade" id="modal_confirm" tabindez="-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-body">
|
|
<div class="row">
|
|
<div class="col">
|
|
<p class="font-weight-bold">
|
|
¿Estás seguro de justificar esta falta?
|
|
<hr>
|
|
<section>
|
|
<b>Fecha:</b> <span class="modal-fecha"></span> <br>
|
|
<b>Hora:</b> <span class="modal-hora"></span>
|
|
</section>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
<div class="modal-footer">
|
|
<input type="hidden" id="id_borrar" value="">
|
|
<input type="hidden" id="facultad_borrar" value="">
|
|
<button type="button" class="btn btn-outline-primary btn-aceptar"><span class="ing-aceptar ing-fw"></span> Justificar</button>
|
|
<button type="button" class="btn btn-outline-danger" data-dismiss="modal" aria-label="Close"><span class="ing-cancelar ing-fw"></span> Cancelar</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script src="js/bootstrap/popper.min.js"></script>
|
|
<script src="js/bootstrap/bootstrap.min.js"></script>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/3.0.0/mustache.min.js"></script>
|
|
<script src="js/fetchlib.js"></script>
|
|
<script src="js/barra.js"></script>
|
|
<script>
|
|
var profesor = <?= json_encode($asistencias) ?>;
|
|
|
|
// modal_confirm -> bool
|
|
function modal_confirm(fecha, hora) {
|
|
return new Promise((resolve, reject) => {
|
|
$("#modal_confirm").modal("show");
|
|
|
|
$(".modal-fecha").html(fecha);
|
|
$(".modal-hora").html(hora);
|
|
|
|
$(".btn-aceptar").click(() => {
|
|
$("#modal_confirm").modal("hide");
|
|
resolve(true);
|
|
});
|
|
|
|
$("#modal_confirm").on("hidden.bs.modal", () => {
|
|
resolve(false);
|
|
});
|
|
});
|
|
}
|
|
|
|
function show_message(message, type) {
|
|
var template = $("#messages_tmp").html();
|
|
var html = Mustache.render(template, {
|
|
message: message,
|
|
type: type
|
|
});
|
|
var clone = $(html);
|
|
// append html to message section
|
|
clone.appendTo("#message");
|
|
|
|
// remove after 4 seconds
|
|
setTimeout(function() {
|
|
clone.alert("close");
|
|
}, 4000);
|
|
}
|
|
$(document).ready(function() {
|
|
|
|
$("#reporte").hide();
|
|
|
|
$("#reporte").click(function(e) {
|
|
$("#form_reporte").submit();
|
|
});
|
|
var periodo_inicio = '<?= $periodo["inicio"] ?>';
|
|
var periodo_fin = '<?= $periodo["fin"] ?>';
|
|
|
|
var previous_date;
|
|
$('#initial_date_src').focus(function() {
|
|
previous_date = $(this).val();
|
|
}).change(function() {
|
|
// console.log("Periodo inicio: ", periodo_inicio);
|
|
// console.log("this < Periodo inicio: ", $(this).val() < periodo_inicio);
|
|
if ($(this).val() > $('#final_date_src').val()) {
|
|
show_message("La fecha inicial no puede ser mayor a la fecha final", "danger");
|
|
$(this).val(previous_date);
|
|
} else if ($(this).val() < periodo_inicio) {
|
|
show_message("La fecha inicial no puede ser menor a la fecha inicial del período", "danger");
|
|
$(this).val(previous_date);
|
|
} else {
|
|
$("#reporte").show();
|
|
|
|
var initial_date = $("#initial_date_src").val();
|
|
$("#initial_date_dst").val(initial_date);
|
|
}
|
|
});
|
|
|
|
$('#final_date_src').focus(function() {
|
|
previous_date = $(this).val();
|
|
}).change(function() {
|
|
console.log("Periodo fin: ", periodo_fin);
|
|
console.log("this > Periodo fin: ", $(this).val() > periodo_fin);
|
|
if ($(this).val() < $('#initial_date_src').val()) {
|
|
show_message("La fecha final no puede ser menor a la fecha inicial", "danger");
|
|
$(this).val(previous_date);
|
|
} else if ($(this).val() > periodo_fin) {
|
|
show_message("La fecha final no puede ser mayor a la fecha final del período", "danger");
|
|
$(this).val(previous_date);
|
|
} else {
|
|
$("#reporte").show();
|
|
var final_date = $("#final_date_src").val();
|
|
$("#final_date_dst").val(final_date);
|
|
}
|
|
});
|
|
/*
|
|
$("#submit-form").click(function(e) {
|
|
var form = $("#form_reporte");
|
|
// change action of form
|
|
form.attr("action", "consultar_asistencias.php");
|
|
form.submit();
|
|
});
|
|
*/
|
|
|
|
|
|
$("#barra-profesor").html(barra(profesor, <?= $retardos ? "true" : "false" ?>));
|
|
});
|
|
|
|
function justificar(id, fecha, hora) {
|
|
modal_confirm(fecha, hora).then(async (result) => {
|
|
if (result) {
|
|
|
|
var resultado = await fetchPHP("action/action_justificar.php", {
|
|
clave: "<?= $id ?>",
|
|
fecha: fecha,
|
|
hora: hora,
|
|
id: id
|
|
});
|
|
|
|
if (resultado.success) {
|
|
show_message("Asistencia justificada", "success");
|
|
// Change button to justificada and the icon
|
|
// to only javascript
|
|
const cell = document.querySelector(`button[onclick="justificar(${id}, '${fecha}', '${hora}')"]`).parentElement;
|
|
// the previous td
|
|
cell.innerHTML = "<b>Justificada</b>";
|
|
profesor.justificaciones++;
|
|
profesor.faltas--;
|
|
document.getElementById("barra-profesor").innerHTML = barra(profesor, <?= $retardos ? "true" : "false" ?>);
|
|
|
|
// previous cell, change icon
|
|
cell.previousElementSibling.innerHTML = `<?= $justificado_icon ?>`;
|
|
} else {
|
|
show_message("Error al justificar asistencia", "danger");
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
async function carreras(id_carrera) {
|
|
// enable datalist carreras
|
|
disableDatalist("#filter_materia", false);
|
|
var materias = await fetchPHP("action/action_materias.php", {
|
|
carrera: id_carrera,
|
|
profesor_id: <?= $id ?>
|
|
});
|
|
|
|
if (materias.error) {
|
|
show_message("Error al obtener las materias", "danger");
|
|
return
|
|
}
|
|
// clear datalist
|
|
$("#dlmateria ul").html("<li data-id=''>Todas las materias</li>");
|
|
// add options to datalist
|
|
|
|
materias.forEach(materia => {
|
|
$("#dlmateria ul").append(`<li data-id="${materia.id}">${materia.nombre}</option>`);
|
|
});
|
|
setDatalistFirst("#filter_materia");
|
|
}
|
|
|
|
function validateForm() {
|
|
var initial_date = $("#initial_date_src").val();
|
|
var final_date = $("#final_date_src").val();
|
|
if (initial_date == "" || final_date == "") {
|
|
show_message("Debe seleccionar un rango de fechas", "Error al generar reporte");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
</script>
|
|
</body>
|
|
|
|
</html>
|