vista_profesor.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <?php
  2. # print_r($_POST); exit;
  3. require_once 'class/c_login.php';
  4. if (!isset($_SESSION['user']))
  5. die(header('Location: index.php'));
  6. $user = unserialize($_SESSION['user']);
  7. $user->access('reporte_de_asistencias');
  8. if ( !$user->admin && $user->acceso == 'n' )
  9. die(header('Location: main.php?error=1'));
  10. $user->print_to_log('Consultar: Reporte de asistencias de profesor');
  11. #$required_post = ['id', 'fecha_inicial', 'fecha_final', 'periodo'];
  12. #if (array_diff($required_post, array_keys($_POST)))
  13. #header('Location: s.php');
  14. extract($_POST);
  15. $post_keys = array_keys($_POST);
  16. if (
  17. !in_array('fecha_inicial', $post_keys) ||
  18. !in_array('fecha_final', $post_keys)
  19. ) {
  20. header('Location: reporte_de_asistencias.php');
  21. exit;
  22. }
  23. # date validation
  24. $fecha_inicial = date_create_from_format("d/m/Y", $fecha_inicial);
  25. $fecha_final = date_create_from_format("d/m/Y", $fecha_final);
  26. // Nombre del profesor es opcional
  27. $reporte = queryAll("SELECT * FROM fs_asistencia_profesorreporte(:carrera, :periodo, :id, :initial_date, :final_date)
  28. WHERE materia_id = COALESCE(:materia, materia_id)",
  29. array(
  30. ":carrera" => empty($carrera) ? null : $carrera,
  31. ":periodo" => $user->periodo,
  32. ":id" => $id,
  33. ":initial_date" => $fecha_inicial->format("Y-m-d"),
  34. ":final_date" => $fecha_final->format("Y-m-d"),
  35. ":materia" => empty($materia) ? null : $materia
  36. )
  37. );
  38. $profesor = query(
  39. "SELECT * FROM FS_PROFESOR WHERE id = :id",
  40. array(":id" => $id)
  41. );
  42. $asistencias = query("SELECT total, asistencias, retardos, justificaciones FROM fs_asistencia_reporte(:carrera, :periodo, :clave, :nombre, :facultad, :initial_date, :final_date)",
  43. array(
  44. ":carrera" => empty($carrera) ? null : $carrera,
  45. ":periodo" => $user->periodo,
  46. ":clave" => $profesor['clave'],
  47. ":nombre" => $profesor['profesor'],
  48. ":facultad" => $user->facultad['facultad_id'],
  49. ":initial_date" => $fecha_inicial->format("Y-m-d"),
  50. ":final_date" => $fecha_final->format("Y-m-d"),
  51. ),
  52. );
  53. // die(var_dump($asistencias));
  54. $retardos = query("SELECT FS_HAS_RETARDO(:facultad) AS retardo", array(":facultad" => $user->facultad['facultad_id']))['retardo']; ?>
  55. <!DOCTYPE html>
  56. <head>
  57. <title>Reporte asistencias</title>
  58. <meta charset="utf-8">
  59. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  60. <?php
  61. include_once "import/html_css_files.php";
  62. ?>
  63. </head>
  64. <body style="display: block;">
  65. <?php
  66. include("import/html_header.php");
  67. html_header("Reporte de asistencias", "Sistema de gestión de checador");
  68. ?>
  69. <main class="container content marco content-margin">
  70. <div class="container ml-4">
  71. <div class="row my-3">
  72. <h3 class="ml-4 text-left"><?= $profesor['profesor'] ?></h3>
  73. </div>
  74. <div class="row my-3">
  75. <h4 class="ml-4 text-left text-danger"><b>Clave:</b> <?= $profesor['clave'] ?></h4>
  76. </div>
  77. </div>
  78. <div class="row">
  79. <div class="col-12 text-right">
  80. <button type="button" class="btn btn-outline-secondary" onclick="submit('reporte_de_asistencias.php', {clave: <?= $profesor['clave'] ?>, periodo: <?= $user->periodo ?>, nombre: '<?= $profesor['profesor'] ?>', fecha_inicial: '<?= $fecha_inicial->format('Y-m-d') ?>', fecha_final: '<?= $fecha_final->format('Y-m-d') ?>'})">
  81. <span class="ing-regresar ing-fw"></span>
  82. Regresar
  83. </button>
  84. </div>
  85. </div>
  86. <?php
  87. require_once "import/html_forms_vista.php";
  88. ?>
  89. <section id="message"></section>
  90. <!-- Space -->
  91. <div class="row">
  92. <div class="col-12">
  93. <hr>
  94. </div>
  95. </div>
  96. <div id="barra-profesor"></div>
  97. <div class="row">
  98. <div class="col-12">
  99. <hr>
  100. </div>
  101. </div>
  102. <div class="row">
  103. <div class="col-12">
  104. <?php
  105. if (!empty($reporte)) {
  106. ?>
  107. <!-- legend check (Asistencia) x | (sin registro) | * (Justificada) -->
  108. <div class="row text-right">
  109. <div class="col-12">
  110. <i class='ing-aceptar' style='color:green'></i><span class="text-success"> Asistencia</span> |
  111. <?php if ($retardos) { ?>
  112. <i class='ing-retardo' style='color:orange'></i><span style="color:orange"> Retardo</span> |
  113. <?php } ?>
  114. <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>
  115. </div>
  116. </div>
  117. <table class="table table-striped table-hover table-white mt-4 table-sm">
  118. <thead class="thead-dark">
  119. <tr>
  120. <th>Grupo</th>
  121. <th>Salón</th>
  122. <th>Materia</th>
  123. <th>Fecha</th>
  124. <th>Hora de clase</th>
  125. <th>Checado</th> <!-- 3 -->
  126. <th></th>
  127. </tr>
  128. </thead>
  129. <tbody>
  130. <?php
  131. $días = array("Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado");
  132. //red icon cross
  133. $cross_icon = "<i class='ing-cancelar text-danger'></i>";
  134. $check_icon = "<i class='ing-aceptar text-success'></i>";
  135. $retardo_icon = "<i class='ing-retardo' style='color:orange'></i>";
  136. $justificado_icon = "<i class='ing-justificar azul'></i>";
  137. # print_r($reporte);
  138. foreach ($reporte as $row) {
  139. # print_r($row);
  140. $justificable = false;
  141. if ($row["checado"] == 1)
  142. if ($row["justificada"] == 1)
  143. $checado = $justificado_icon;
  144. else if ($row["retardo"] == 1)
  145. $checado = $retardo_icon;
  146. else
  147. $checado = $check_icon;
  148. else {
  149. $checado = $cross_icon;
  150. $justificable = true;
  151. }
  152. $fecha = date("d/m/Y", strtotime($row["fecha"]));
  153. $hora = date("H:i", strtotime($row['hora']));
  154. $hora_checado = is_null($row["hora_checado"]) ? '-' : date("H:i:s", strtotime($row["hora_checado"]));
  155. $horario = $db->getOne("fget_horario({$row['id']})");
  156. ?>
  157. <tr class="text-nowrap" id="<?= $row["id"] ?>">
  158. <!-- <td class="complete"><pre><?= print_r($row, true) ?></pre></td> -->
  159. <td class="text-center"><?= $row["grupo"] ?></td>
  160. <td class="text-center"><?= $horario["salon"] ?></td>
  161. <td id="<?= $row["materia_id"] ?>"><?= $row["materia"] ?></td>
  162. <td class="text-center text-nowrap"><?= $fecha ?> | <?= $días[date("w", strtotime($row["fecha"]))] ?></td>
  163. <!-- "hh:mm:ss" -> "hh:mm" -->
  164. <td class="text-center text-nowrap"><?= $hora ?> - <?= join(":", array_slice(explode(":", $horario["hora_final"]), 0, 2)) ?></td>
  165. <td class="text-center"><?= $checado ?></td>
  166. <td class="text-center">
  167. <?php if ($justificable) { ?>
  168. <button class='btn btn-sm btn-outline-primary' onclick="justificar(<?= $row['id'] ?>, '<?= $fecha ?>', ' <?= $hora ?>')">Justificar</button>
  169. <?php } else { ?>
  170. <?= !$row["justificada"] ? $hora_checado : "<b>Justificada</b>" ?>
  171. <?php } ?>
  172. </td>
  173. </tr>
  174. <?php
  175. }
  176. ?>
  177. </tbody>
  178. </table>
  179. <?php
  180. } else { ?>
  181. <div class='alert alert-warning'>No hay registros para mostrar</div>
  182. <?php
  183. }
  184. ?>
  185. </div>
  186. </div>
  187. <?php
  188. include_once "import/html_scroll.php";
  189. ?>
  190. </main>
  191. <?php
  192. include("import/html_footer.php");
  193. ?>
  194. <template id="messages_tmp">
  195. <div class="alert alert-{{type}} alert-dismissible fade show" role="alert">
  196. {{message}}
  197. <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  198. <span aria-hidden="true">&times;</span>
  199. </button>
  200. </div>
  201. </template>
  202. <div class="modal fade" id="modal_confirm" tabindez="-1" role="dialog" aria-labelledby="modal" aria-hidden="true">
  203. <div class="modal-dialog modal-dialog-centered" role="document">
  204. <div class="modal-content">
  205. <div class="modal-body">
  206. <div class="row">
  207. <div class="col">
  208. <p class="font-weight-bold">
  209. ¿Estás seguro de justificar esta falta?
  210. <hr>
  211. <section>
  212. <b>Fecha:</b> <span class="modal-fecha"></span> <br>
  213. <b>Hora:</b> <span class="modal-hora"></span>
  214. </section>
  215. </p>
  216. </div>
  217. </div>
  218. </div>
  219. <div class="modal-footer">
  220. <input type="hidden" id="id_borrar" value="">
  221. <input type="hidden" id="facultad_borrar" value="">
  222. <button type="button" class="btn btn-outline-primary btn-aceptar"><span class="ing-aceptar ing-fw"></span> Justificar</button>
  223. <button type="button" class="btn btn-outline-danger" data-dismiss="modal" aria-label="Close"><span class="ing-cancelar ing-fw"></span> Cancelar</button>
  224. </div>
  225. </div>
  226. </div>
  227. </div>
  228. <script src="js/bootstrap/popper.min.js"></script>
  229. <script src="js/bootstrap/bootstrap.min.js"></script>
  230. <script src="https://cdnjs.cloudflare.com/ajax/libs/mustache.js/3.0.0/mustache.min.js"></script>
  231. <script src="js/fetchlib.js"></script>
  232. <script src="js/barra.js"></script>
  233. <script>
  234. var profesor = <?= json_encode($asistencias) ?>;
  235. // modal_confirm -> bool
  236. function modal_confirm(fecha, hora) {
  237. return new Promise((resolve, reject) => {
  238. $("#modal_confirm").modal("show");
  239. $(".modal-fecha").html(fecha);
  240. $(".modal-hora").html(hora);
  241. $(".btn-aceptar").click(() => {
  242. $("#modal_confirm").modal("hide");
  243. resolve(true);
  244. });
  245. $("#modal_confirm").on("hidden.bs.modal", () => {
  246. resolve(false);
  247. });
  248. });
  249. }
  250. function show_message(message, type) {
  251. var template = $("#messages_tmp").html();
  252. var html = Mustache.render(template, {
  253. message: message,
  254. type: type
  255. });
  256. var clone = $(html);
  257. // append html to message section
  258. clone.appendTo("#message");
  259. // remove after 4 seconds
  260. setTimeout(function() {
  261. clone.alert("close");
  262. }, 4000);
  263. }
  264. $(document).ready(function() {
  265. $("#reporte").hide();
  266. $("#reporte").click(function(e) {
  267. $("#form_reporte").submit();
  268. });
  269. var periodo_inicio = '<?= $periodo["inicio"] ?>';
  270. var periodo_fin = '<?= $periodo["fin"] ?>';
  271. var previous_date;
  272. $('#initial_date_src').focus(function() {
  273. previous_date = $(this).val();
  274. }).change(function() {
  275. // console.log("Periodo inicio: ", periodo_inicio);
  276. // console.log("this < Periodo inicio: ", $(this).val() < periodo_inicio);
  277. if ($(this).val() > $('#final_date_src').val()) {
  278. show_message("La fecha inicial no puede ser mayor a la fecha final", "danger");
  279. $(this).val(previous_date);
  280. } else if ($(this).val() < periodo_inicio) {
  281. show_message("La fecha inicial no puede ser menor a la fecha inicial del período", "danger");
  282. $(this).val(previous_date);
  283. } else {
  284. $("#reporte").show();
  285. var initial_date = $("#initial_date_src").val();
  286. $("#initial_date_dst").val(initial_date);
  287. }
  288. });
  289. $('#final_date_src').focus(function() {
  290. previous_date = $(this).val();
  291. }).change(function() {
  292. console.log("Periodo fin: ", periodo_fin);
  293. console.log("this > Periodo fin: ", $(this).val() > periodo_fin);
  294. if ($(this).val() < $('#initial_date_src').val()) {
  295. show_message("La fecha final no puede ser menor a la fecha inicial", "danger");
  296. $(this).val(previous_date);
  297. } else if ($(this).val() > periodo_fin) {
  298. show_message("La fecha final no puede ser mayor a la fecha final del período", "danger");
  299. $(this).val(previous_date);
  300. } else {
  301. $("#reporte").show();
  302. var final_date = $("#final_date_src").val();
  303. $("#final_date_dst").val(final_date);
  304. }
  305. });
  306. /*
  307. $("#submit-form").click(function(e) {
  308. var form = $("#form_reporte");
  309. // change action of form
  310. form.attr("action", "consultar_asistencias.php");
  311. form.submit();
  312. });
  313. */
  314. $("#barra-profesor").html(barra(profesor, <?= $retardos ? "true" : "false" ?>));
  315. });
  316. function justificar(id, fecha, hora) {
  317. modal_confirm(fecha, hora).then(async (result) => {
  318. if (result) {
  319. var resultado = await fetchPHP("action/action_justificar.php", {
  320. clave: "<?= $id ?>",
  321. fecha: fecha,
  322. hora: hora,
  323. id: id
  324. });
  325. if (resultado.success) {
  326. show_message("Asistencia justificada", "success");
  327. // Change button to justificada and the icon
  328. // to only javascript
  329. const cell = document.querySelector(`button[onclick="justificar(${id}, '${fecha}', '${hora}')"]`).parentElement;
  330. // the previous td
  331. cell.innerHTML = "<b>Justificada</b>";
  332. profesor.justificaciones++;
  333. profesor.faltas--;
  334. document.getElementById("barra-profesor").innerHTML = barra(profesor, <?= $retardos ? "true" : "false" ?>);
  335. // previous cell, change icon
  336. cell.previousElementSibling.innerHTML = `<?= $justificado_icon ?>`;
  337. } else {
  338. show_message("Error al justificar asistencia", "danger");
  339. }
  340. }
  341. });
  342. }
  343. async function carreras(id_carrera) {
  344. // enable datalist carreras
  345. disableDatalist("#filter_materia", false);
  346. var materias = await fetchPHP("action/action_materias.php", {
  347. carrera: id_carrera,
  348. profesor_id: <?= $id ?>
  349. });
  350. if (materias.error) {
  351. show_message("Error al obtener las materias", "danger");
  352. return
  353. }
  354. // clear datalist
  355. $("#dlmateria ul").html("<li data-id=''>Todas las materias</li>");
  356. // add options to datalist
  357. materias.forEach(materia => {
  358. $("#dlmateria ul").append(`<li data-id="${materia.id}">${materia.nombre}</option>`);
  359. });
  360. setDatalistFirst("#filter_materia");
  361. }
  362. function validateForm() {
  363. var initial_date = $("#initial_date_src").val();
  364. var final_date = $("#final_date_src").val();
  365. if (initial_date == "" || final_date == "") {
  366. show_message("Debe seleccionar un rango de fechas", "Error al generar reporte");
  367. return false;
  368. }
  369. return true;
  370. }
  371. </script>
  372. </body>
  373. </html>