avisos.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <?php
  2. require_once 'class/c_login.php';
  3. require_once 'include/bd_pdo.php';
  4. include 'include/constantes.php';
  5. if(!isset($_SESSION['user'])){
  6. header('Location: index.php');
  7. exit;
  8. }
  9. else
  10. $user = unserialize($_SESSION['user']);
  11. $user->access();
  12. if(!$user->admin && $user->acceso == 'n'){
  13. header('Location: main.php?error=1');
  14. }else{
  15. $user->print_to_log('Avisos');
  16. }
  17. $fac = $user->facultad['facultad_id'];
  18. if($user->admin){
  19. $fac = null;
  20. }
  21. $limit = 20;
  22. if(isset($_POST['filter_fecha']) && $_POST['filter_fecha'] != ""){
  23. $filter_fecha = $_POST['filter_fecha'];
  24. }
  25. else{
  26. $filter_fecha = null;
  27. }
  28. if(isset($_GET['pag'])){
  29. $pag = $_GET['pag'] - 1;
  30. }else{
  31. $pag = 0;
  32. }
  33. if($user->admin){
  34. $count = query("SELECT count(1) FROM fs_aviso(null, :fecha, :facultad_id, null, 0, null)", [':fecha' => $filter_fecha, ':facultad_id' => $fac], true);
  35. $fs_avisos = query("SELECT * FROM fs_aviso(null, :fecha, :facultad_id, :limite, :offset, null)", [':fecha' => $filter_fecha, ':facultad_id' => $fac, ':limite' => $limit, ':offset' => $pag * $limit], false);
  36. }else{
  37. $count = query("SELECT count(1) FROM fs_aviso(null, :fecha, :facultad_id, null, 0, true)", [':fecha' => $filter_fecha, ':facultad_id' => $fac], true);
  38. $fs_avisos = query("SELECT * FROM fs_aviso(null, :fecha, :facultad_id, :limite, :offset, true)", [':fecha' => $filter_fecha, ':facultad_id' => $fac, ':limite' => $limit, ':offset' => $pag * $limit], false);
  39. }
  40. $paginas = ceil($count['count'] / $limit);
  41. ?>
  42. <!DOCTYPE html>
  43. <html lang="en">
  44. <head>
  45. <meta charset="UTF-8">
  46. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  47. <title>Avisos</title>
  48. <link rel="stylesheet" href="css/jquery-ui.css">
  49. <link rel="stylesheet" href="css/calendar.css">
  50. <?php
  51. include 'import/html_css_files.php';
  52. ?>
  53. </head>
  54. <body>
  55. <?php
  56. include "import/html_header.php";
  57. html_header(
  58. "Avisos",
  59. "Gestión de Checador "
  60. );
  61. $user->access();
  62. ?>
  63. <main class="content marco">
  64. <?php if($user->acceso == 'w') {?>
  65. <div class="row">
  66. <div class="col-12 text-right">
  67. <a href="avisos_crear.php">
  68. <button type="button" class="btn btn-outline-secondary"><span class="ing-mas ing-fw"></span>Crear Aviso</button>
  69. </a>
  70. </div>
  71. </div>
  72. <?php } ?>
  73. <!-- Filtro -->
  74. <div class="row">
  75. <div class="col-12">
  76. <form action="avisos.php" method="post">
  77. <div class="form-box">
  78. <div class="form-group row">
  79. <label for="filter_fecha" class="col-4 con-form-label">Fecha</label>
  80. <div class="col-8 col-sm-4">
  81. <input id="filter_fecha" name="filter_fecha" type="text" class="form-control date-picker" placeholder="dd/mm/aaaa" maxlength="10" required="required" readonly="" value="<?php if(isset($filter_fecha)){ echo $filter_fecha; } ?>">
  82. </div>
  83. </div>
  84. <p class="offset-4">Se muestran los avisos posteriores a la fecha</p>
  85. </div>
  86. <div class="form-group">
  87. <div class="col-12 text-center">
  88. <button type="submit" class="btn btn-outline-primary">
  89. <span class="ing-buscar ing-fw"></span>
  90. Filtrar
  91. </button>
  92. <button type="button" class="btn btn-outline-danger btn-reset">
  93. <span class="ing-borrar ing-fw"></span>
  94. Limpiar
  95. </button>
  96. </div>
  97. </div>
  98. </form>
  99. </div>
  100. </div>
  101. <div id="message"></div>
  102. <!-- Tabla -->
  103. <div class="row">
  104. <div class="col-12 table-responsive">
  105. <table class="table table-sm table-striped table-white">
  106. <thead class="thead-dark">
  107. <tr>
  108. <th>Estado</th>
  109. <?php if($user->acceso == 'w') {?>
  110. <th>Facultad</th>
  111. <?php }?>
  112. <th>Fechas</th>
  113. <th>Mensaje</th>
  114. <?php if($user->acceso == 'w') {?>
  115. <th>Acciones</th>
  116. <?php }?>
  117. </tr>
  118. </thead>
  119. <tbody>
  120. <?php $today = date('Y-m-j');
  121. foreach($fs_avisos as $aviso){
  122. $color2 = 'danger';
  123. $title2 = 'Inactivo';
  124. $color = 'danger';
  125. $title = 'Fuera de tiempo';
  126. $icono = 'retardo';
  127. if($today >= $aviso['aviso_fecha_inicial'] && $today <= $aviso['aviso_fecha_final']){
  128. $color = 'success';
  129. $title = 'En tiempo';
  130. $icono = 'reloj';
  131. }else if($today < $aviso['aviso_fecha_inicial']){
  132. $color = 'warning';
  133. $title = 'Antes de tiempo';
  134. }
  135. if($aviso['aviso_estado'] == true){
  136. $color2 = 'success';
  137. $title2 = 'Activo';
  138. }
  139. $day = explode("-", $aviso['aviso_fecha_inicial']);
  140. $dia_inicial = $day['2'].'/'.$day['1'].'/'.$day[0];
  141. $day = explode("-", $aviso['aviso_fecha_final']);
  142. $dia_final = $day['2'].'/'.$day['1'].'/'.$day[0];
  143. ?>
  144. <tr data-id="<?= $aviso['aviso_id'] ?>" id="<?= $aviso['aviso_id'] ?>">
  145. <td class="text-center"><?php if($user->admin){ ?> <span class="ing-bullet text-<?= $color2 ?>" title="<?= $title2 ?>"></span> <?php } ?> <span class="ing-<?= $icono ?> text-<?= $color ?>" title="<?= $title ?>"></span></td>
  146. <?php if($user->acceso == 'w') {?>
  147. <td><?= $aviso['facultad_nombre'] ?></td>
  148. <?php }?>
  149. <td><?= $dia_inicial ?> - <?= $dia_final ?></td>
  150. <td><?= $aviso['aviso_texto'] ?></td>
  151. <?php if($user->acceso == 'w') {?>
  152. <td class="text-center">
  153. <a href="avisos_editar.php?id=<?= $aviso['aviso_id'] ?>" title="Editar"><span class="ing-editar"></span></a>
  154. <?php if($aviso['aviso_estado'] == true){ ?>
  155. <a href="#" data-toggle="modal" data-target="#modal_confirm" title="Borrar"><span class="ing-basura"></span></a>
  156. <?php } ?>
  157. </td>
  158. <?php }?>
  159. </tr>
  160. <?php } ?>
  161. </tbody>
  162. </table>
  163. </div>
  164. </div>
  165. <nav aria-label="paginas">
  166. <ul class="pagination justify-content-end">
  167. <?php if($pag != 0){ ?>
  168. <li class="page-item">
  169. <a class="page-link" href="avisos.php?pag=<?= $pag ?>" aria-label="Previous">
  170. <span aria-hidden="true">&laquo;</span>
  171. </a>
  172. </li>
  173. <?php } ?>
  174. <?php for($i = 0; $i < $paginas; $i++){ ?>
  175. <li class="page-item <?php if($i == $pag){ echo"active"; } ?>" <?php if($i == $pag){ echo 'aria-current="page"'; } ?>><a class="page-link" href="avisos.php?pag=<?= $i+1 ?>"><?= $i+1 ?></a></li>
  176. <?php }
  177. if(($pag + 1) < $paginas){ ?>
  178. <li class="page-item">
  179. <a class="page-link" href="avisos.php?pag=<?= $pag + 2 ?>" aria-label="Next">
  180. <span aria-hidden="true">&raquo;</span>
  181. </a>
  182. </li>
  183. <?php } ?>
  184. </ul>
  185. </nav>
  186. </main>
  187. <?php
  188. include "import/html_footer.php";
  189. ?>
  190. <?php if($user->acceso == 'w') {?>
  191. <div class="modal fade" id="modal_confirm" tabindex="-1" role="dialog" aria-labelledby="modal" aria-hidden="true">
  192. <div class="modal-dialog modal-dialog-centered" role="document">
  193. <div class="modal-content">
  194. <div class="modal-body">
  195. <div class="row">
  196. <div class="col">
  197. <p class="font-weight-bold">¿Estás seguro de que quieres borrar el aviso?</p>
  198. <p>Esta acción no se puede deshacer.</p>
  199. </div>
  200. </div>
  201. </div>
  202. <div class="modal-footer">
  203. <input type="hidden" id="id_borrar" value="">
  204. <button type="button" class="btn btn-outline-primary btn-borrar"><?php echo $ICO["aceptar"];?> Borrar</button>
  205. <button type="button" class="btn btn-outline-danger" data-dismiss="modal" aria-label="Close"><?php echo $ICO["cancelar"];?> Cancelar</button>
  206. </div>
  207. </div>
  208. </div>
  209. </div>
  210. <?php } ?>
  211. <script src="js/jquery.min.js"></script>
  212. <script src="js/jquery-ui.js"></script>
  213. <script src="js/bootstrap/bootstrap.min.js"></script>
  214. <script src="js/datalist.js"></script>
  215. <script src="js/datepicker-es.js"></script>
  216. <?php
  217. require_once 'js/messages.php';
  218. ?>
  219. <script>
  220. var today = new Date();
  221. $(".date-picker").datepicker($.datepicker.regional["es"]);
  222. $(".date-picker").datepicker({
  223. dateFormat: "dd/mm/yyyy",
  224. changeMonth: true,
  225. });
  226. $(document).on( "click", ".btn-reset", function(event){
  227. var forma = $(this).parents("form");
  228. forma.find("input[type=text]").val("");
  229. forma.find("select").prop("selectedIndex",0);
  230. forma.submit();
  231. });
  232. $('#modal_confirm').on('show.bs.modal', function (event) {
  233. var button = $(event.relatedTarget); // Button that triggered the modal
  234. var id = button.parents("tr").data("id");
  235. $("#id_borrar").val(id);
  236. });
  237. $('.btn-borrar').click(function(){
  238. var cid = $('#id_borrar').val();
  239. $.ajax({
  240. url: './action/action_avisos_delete.php',
  241. type: 'POST',
  242. dataType: 'json',
  243. data: {id: cid},
  244. success: function(result){
  245. console.log("bien");
  246. },
  247. error: function(){
  248. console.log(cid);
  249. }
  250. });
  251. $('#modal_confirm').modal("hide");
  252. location.reload();
  253. });
  254. </script>
  255. </body>
  256. </html>