avisos.php 11 KB

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