justifica.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <?php
  2. require_once("../include/constantes.php");
  3. require_once("../include/util.php");
  4. require_once("../include/bd_pdo.php");
  5. require_once("../classes/ValidaSesion.php");
  6. require_once("../classes/MainMenu.php");
  7. $menu = 8;
  8. $submenu = 83;
  9. //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
  10. $objSesion = new ValidaSesion($pdo, $submenu, APSA);
  11. if(!$objSesion->tieneAcceso()){
  12. $objSesion->terminaSesion();
  13. }
  14. $objSesion->validaPeriodoUsuario();//si no tiene periodo manda a main
  15. /*if(!$objSesion->puedeEditar()){
  16. $errorDesc = "No puedes generar nombramientos.";
  17. }*/
  18. //Obtiene grupos del periodo
  19. $stmt = $pdo->prepare('Select * from fs_grupo(NULL, :periodo)');
  20. $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
  21. if(!$stmt->execute()){
  22. header("Location: grupos.php?error=4");
  23. exit();
  24. }else{
  25. $grupos_rs = $stmt->fetchAll();
  26. }
  27. $stmt->closeCursor();
  28. if(!is_array($grupos_rs) || count($grupos_rs) == 0){
  29. header("Location: grupos.php?error=5");
  30. exit();
  31. }
  32. ?>
  33. <!DOCTYPE html>
  34. <html lang="es" prefix="og: http://ogp.me/ns#">
  35. <head>
  36. <title>APSA - Facultad de Ingeniería</title>
  37. <meta charset="utf-8">
  38. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  39. <link rel="icon" type="image/png" href="../img/favicon.png" />
  40. <link rel="stylesheet" href="../css/bootstrap-ulsa.min.css" type="text/css">
  41. <link rel="stylesheet" href="../css/indivisa.css" type="text/css">
  42. <link rel="stylesheet" href="../css/sgi.css?rand=<?php echo rand();?>" type="text/css">
  43. <link rel="stylesheet" href="../css/fa_all.css" type="text/css">
  44. <link rel="stylesheet" href="../css/jquery-ui.css" type="text/css">
  45. <link rel="stylesheet" href="../css/clockpicker.css" type="text/css">
  46. <link rel="stylesheet" href="../css/calendar.css" type="text/css">
  47. <script src="../js/util.js"></script>
  48. </head>
  49. <body>
  50. <div>
  51. <?php
  52. //--- Objeto que pinta menu
  53. $menuObj = new MainMenu($_SESSION["usuario_id"], $menu, $pdo, APSA, "Justificar faltas");//usr, menu, pdo, sist
  54. $menuObj->printMenu();
  55. //Obtiene fechas de periodo
  56. $stmt = $pdo->prepare('Select * from fs_periodo(:periodo, NULL, NULL, true)');
  57. $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
  58. if(!$stmt->execute()){
  59. $errorDesc = "Ocurrió un error al cargar las fechas del periodo";
  60. }else{
  61. $periodo_rs = $stmt->fetch();
  62. }
  63. $stmt->closeCursor();
  64. $stmt = null;
  65. if(isset($_POST["hora_inicial"]) && $_POST["hora_inicial"]!=""){
  66. $filter_hini = trim(filter_input(INPUT_POST, "hora_inicial", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  67. }else{
  68. $filter_hini = HORA_INICIO.':00';
  69. }
  70. if(isset($_POST["hora_final"]) && $_POST["hora_final"]!=""){
  71. $filter_hfin = trim(filter_input(INPUT_POST, "hora_final", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  72. }else{
  73. $filter_hfin = HORA_FINAL.':00';
  74. }
  75. if(isset($_POST["hora_final"]) && $_POST["hora_final"]!=""){
  76. $filter_nombre = trim(filter_input(INPUT_POST, "nombre", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  77. }else{
  78. $filter_nombre = "";
  79. }
  80. if(isset($_POST["fecha"])){
  81. $fecha = fechaGuion($_POST["fecha"]);
  82. $stmt = $pdo->prepare('Select * from fs_profesoresfecha(:nom, :periodo, :fecha, :h_ini, :h_fin)');
  83. $stmt->bindParam(":nom", $filter_nombre);
  84. $stmt->bindParam(":periodo", $_SESSION["periodo_id"]);
  85. $stmt->bindParam(":fecha", $fecha);
  86. $stmt->bindParam(":h_ini", $filter_hini);
  87. $stmt->bindParam(":h_fin", $filter_hfin);
  88. if(!$stmt->execute()){
  89. $errorDesc = "Ocurrió un error al cargar los profesores de la fecha";
  90. }else{
  91. $profesores_rs = $stmt->fetchAll();
  92. }
  93. $stmt->closeCursor();
  94. $stmt = null;
  95. }
  96. //--Manejo de errores y mensajes de exito
  97. if(isset($_GET["error"]) && is_numeric($_GET["error"])){
  98. switch ($_GET["error"]){
  99. case 0: $errorDesc = "No se reciberon los datos para justificar la falta."; break;
  100. case 1: $errorDesc = "Ocurrió un error al gruardar la justificación."; break;
  101. case 2: $errorDesc = "No tienes permisos para realizar esa acción."; break;
  102. }
  103. }
  104. if(isset($_GET["ok"]) && is_numeric($_GET["ok"])){
  105. switch ($_GET["ok"]){
  106. case 0: $successDesc = "Las justificaciones se guardaron correctamente."; break;
  107. }
  108. }
  109. ?>
  110. <main class="container-fluid content marco">
  111. <?php include_once("../include/errorMessage.php");?>
  112. <?php include("../include/periodoCambio.php");?>
  113. <?php if(isset($periodo_rs)){ ?>
  114. <p>Selecciona la fecha que deseas justificar.</p>
  115. <div class="row">
  116. <div class="col-12">
  117. <form action="" method="post" id="form_filter" onsubmit="return submitForm()">
  118. <div class="form-box form-box-info">
  119. <div class="form-group row">
  120. <label for="fecha" class="col-4 col-form-label">Fecha *</label>
  121. <div class="col-8 col-sm-4">
  122. <input id="fecha" name="fecha" type="text" class="form-control date-picker" placeholder="dd/mm/aaaa" maxlength="10" required="required" readonly="readonly" value="<?php if(isset($fecha)){echo fechaSlash($fecha);}else{echo date("d/m/Y");} ?>">
  123. <div class="invalid-feedback">Debes escribir una fecha.</div>
  124. </div>
  125. </div>
  126. <div class="form-group row">
  127. <label for="hora_inicial" class="col-4 col-form-label">Hora inicial *</label>
  128. <div class="col-8 col-sm-4">
  129. <input id="hora_inicial" name="hora_inicial" type="text" class="form-control clock" data-autoclose="true" placeholder="hh:mm" maxlength="5" required="required" readonly="readonly" value="<?php echo $filter_hini;?>">
  130. </div>
  131. </div>
  132. <div class="form-group row">
  133. <label for="hora_final" class="col-4 col-form-label">Hora final *</label>
  134. <div class="col-8 col-sm-4">
  135. <input id="hora_final" name="hora_final" type="text" class="form-control clock" data-autoclose="true" placeholder="hh:mm" maxlength="10" required="required" readonly="readonly" value="<?php echo $filter_hfin ?>">
  136. </div>
  137. </div>
  138. <div class="form-group row">
  139. <label for="hora_inicial" class="col-4 col-form-label">Nombre</label>
  140. <div class="col-8 col-sm-4">
  141. <input id="nombre" name="nombre" type="text" class="form-control" value="<?php echo $filter_nombre;?>">
  142. </div>
  143. </div>
  144. </div>
  145. <div class="form-group row">
  146. <div class="col-12 text-center">
  147. <button type="submit" class="btn btn-outline-primary"><?php echo $ICO["buscar"]; ?> Buscar profesores</button>
  148. </div>
  149. </div>
  150. </form>
  151. </div>
  152. </div>
  153. <div class="row">
  154. <div class="col-12 ">
  155. <?php if(isset($profesores_rs) && count($profesores_rs) > 0){ ?>
  156. <form action="./action/justifica_insert.php" method="post" onsubmit="return validaAsistencia()">
  157. <input type="hidden" name="fecha" value="<?php echo $fecha; ?>" >
  158. <div class="row">
  159. <div class="col-12">
  160. <p>Selecciona los horarios de los profesores en los que se justificará la falta.</p>
  161. </div>
  162. </div>
  163. <div class="row">
  164. <div class="col-12 table-responsive">
  165. <table class="table table-sm table-striped table-white">
  166. <thead class="thead-dark">
  167. <tr >
  168. <th style="width:30px;" class="">
  169. <div class="custom-control custom-checkbox">
  170. <input type="checkbox" class="custom-control-input" id="selectAll">
  171. <label class="custom-control-label" for="selectAll"></label>
  172. </div>
  173. </th>
  174. <th>Clave</th>
  175. <th>Profesor</th>
  176. <th>Hora</th>
  177. <th>Materia</th>
  178. <th>Grupo</th>
  179. </tr>
  180. </thead>
  181. <tbody id="profesor_list">
  182. <?php
  183. $i = 0;
  184. foreach($profesores_rs as $profesor){ ?>
  185. <tr class="">
  186. <td class="center">
  187. <div class="custom-control custom-checkbox">
  188. <?php $id_val = "";
  189. if(intval($profesor["Reposicion_id"]) == -1){
  190. $id_val = "0_".$profesor["HorarioGrupo_id"];
  191. }else{
  192. $id_val = "1_".$profesor["Reposicion_id"];
  193. }
  194. ?>
  195. <input type="checkbox" class="custom-control-input select_profesor" name="asistenciaArr[]" id="customCheck<?php echo $i;?>" value="<?php echo $profesor["Usuario_id"]."_".$profesor["Horario_hora"]."_".$id_val;?>">
  196. <label class="custom-control-label" for="customCheck<?php echo $i;?>"></label>
  197. </div>
  198. </td>
  199. <td class="text-center font-weight-bold"><?php echo $profesor["Usuario_claveULSA"];?></td>
  200. <td><?php echo $profesor["Usuario_apellidos"]." ".$profesor["Usuario_nombre"];?></td>
  201. <td class="text-center"><?php echo date('H:i', strtotime($profesor["Horario_hora"])); if($profesor["Reposicion_id"]!= -1){ echo " [REP]";}?></td>
  202. <td><?php echo $profesor["Materia_desc"];?></td>
  203. <td class="text-center text-nowrap"><?php
  204. //if($_SESSION["nivel_id"] == 1)
  205. echo $profesor["Grupo_desc"]." ".$profesor["Carrera_prefijo"];
  206. //else
  207. //echo $profesor["Grupo_desc"];
  208. ?></td>
  209. </tr>
  210. <?php
  211. $i++;
  212. } ?>
  213. </tbody>
  214. </table>
  215. </div>
  216. </div>
  217. <div class="row justify-content-md-center">
  218. <div class="col text-center">
  219. <button type="submit" class="btn btn-outline-primary" id="btn_justificar"><?php echo $ICO["aceptar"];?> Justificar faltas</button>
  220. </div>
  221. </div>
  222. </form>
  223. <?php } ?>
  224. </div>
  225. </div>
  226. <?php } ?>
  227. </main>
  228. <!--- FOOTER--->
  229. <?php require_once("../include/footer.php"); ?>
  230. </div>
  231. <script src="../js/jquery.min.js"></script>
  232. <script src="../js/jquery-ui.js"></script>
  233. <script src="../js/datepicker-es.js"></script>
  234. <script src="../js/bootstrap/popper.min.js"></script>
  235. <script src="../js/bootstrap/bootstrap.min.js"></script>
  236. <script src="../js/clockpicker.js"></script>
  237. <script src="../js/fechas.js"></script>
  238. <script src="../js/sidebarmenu.js"></script>
  239. <script src="../js/datalist.js"></script>
  240. <script>
  241. setDatalist("#periodo", <?php echo $_SESSION["periodo_id"]; ?>);
  242. $(document).on('click', '#dlPeriodo ul li' ,function(){
  243. $("#formaPeriodo").submit();
  244. });
  245. <?php
  246. if(strtotime(date("Y-m-d")) < strtotime($periodo_rs["Periodo_fecha_final"]))
  247. $limite = date("d/m/Y");
  248. else
  249. $limite = fechaSlash($periodo_rs["Periodo_fecha_final"]);
  250. ?>
  251. var _periodo_fecha_inicial = "<?php echo fechaSlash($periodo_rs["Periodo_fecha_inicial"]); ?>";
  252. var _periodo_fecha_final = "<?php echo $limite; ?>";
  253. var datepickerOptions = { dateFormat: "dd/mm/yy", minDate:_periodo_fecha_inicial, maxDate:_periodo_fecha_final };
  254. function submitForm(){
  255. if(!validaFecha($('#fecha').val()) ){
  256. $('#fecha').addClass("is-invalid");
  257. return false;
  258. }
  259. return true;
  260. }
  261. function validaAsistencia(){
  262. var numberOfChecked = $('#profesor_list input:checkbox:checked').length;
  263. //var totalCheckboxes = $('#profesores_block input:checkbox').length;
  264. //var numberNotChecked = totalCheckboxes - numberOfChecked;
  265. if(numberOfChecked == 0){
  266. $("#errorBox").collapse('show');
  267. $("#errorBox_text").html("Debes seleccionar al menos un horario para justificar");
  268. $('#messageBox')[0].scrollIntoView({ block: "end" });
  269. return false;
  270. }
  271. return true;
  272. }
  273. $(document).ready(function(){
  274. $(".date-picker" ).datepicker(datepickerOptions);
  275. $(".date-picker" ).datepicker( $.datepicker.regional[ "es" ] );
  276. $(".date-picker").blur(function(){
  277. var fechaObj = fechaObjeto($(this).val());
  278. if( fechaObj !== false ){
  279. if(Date.parse(fechaObj) < Date.parse(fechaObjeto(_periodo_fecha_inicial))){
  280. $(this).val(_periodo_fecha_inicial);
  281. }else if(Date.parse(fechaObj) > Date.parse(fechaObjeto(_periodo_fecha_final))){
  282. $(this).val(_periodo_fecha_final);
  283. }
  284. }
  285. });
  286. $('.clock').clockpicker();
  287. $("#btn-profesores").click(function(){
  288. $("#profesores_block").removeClass("d-none");
  289. });
  290. $("#btn_justificar").prop("disabled", true);
  291. $("#selectAll").change(function(){
  292. var check = $(this).prop("checked");
  293. $(".select_profesor").prop("checked", check);
  294. $("#btn_justificar").prop("disabled", !check);
  295. });
  296. $(".select_profesor").change(function(event){
  297. event.stopPropagation();
  298. //var check = $(this).prop("checked");
  299. var numberOfChecked = $('.select_profesor:checked').length;
  300. var totalCheckboxes = $('.select_profesor').length;
  301. if(numberOfChecked == totalCheckboxes){
  302. $("#selectAll").prop("checked", true);
  303. }else{
  304. $("#selectAll").prop("checked", false);
  305. }
  306. if(numberOfChecked > 0){
  307. $("#btn_justificar").prop("disabled", false);
  308. }else{
  309. $("#btn_justificar").prop("disabled", true);
  310. }
  311. });
  312. });
  313. </script>
  314. </body>
  315. </html>