periodo_update.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /*
  3. * Actualiza los datos del periodo
  4. * Recibe:
  5. * id - ID del menú a editar
  6. * desc - Descripción
  7. * fecha_inicial date,
  8. * fecha_final date,
  9. * nivel integer,
  10. * estado integer,
  11. * fecha_jefes
  12. * Error:
  13. * 0 - No se recibieron los datos
  14. * 1 - Error de base de datos
  15. * Success:
  16. */
  17. require_once("../../include/constantes.php");
  18. require_once("../../include/bd_pdo.php");
  19. require_once("../../include/util.php");
  20. require_once("../../classes/ValidaSesion.php");
  21. require_once("../classes/LogActividad.php");//die on error
  22. $pag = "../periodos.php";
  23. //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
  24. $objSesion = new ValidaSesion($pdo, 44, APSA);
  25. if(!$objSesion->tieneAcceso()){
  26. $objSesion->terminaSesion();
  27. //print_r($objSesion->getError());
  28. }
  29. if(!$objSesion->puedeEditar()){
  30. header("Location: ".$pag);
  31. exit();
  32. }
  33. unset($objValida);
  34. if(!isset($_POST["id"]) || !isset($_POST["desc"])){
  35. header("Location: ".$pag."?error=0");
  36. exit();
  37. }
  38. $id = filter_input(INPUT_POST, "id", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  39. $desc = trim(filter_input(INPUT_POST, "desc", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  40. $fecha_inicial = fechaGuion(trim(filter_input(INPUT_POST, "fecha_inicial", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  41. $fecha_final = fechaGuion(trim(filter_input(INPUT_POST, "fecha_final", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  42. $nivel = filter_input(INPUT_POST, "nivel", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  43. $estado = filter_input(INPUT_POST, "estado", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  44. $fecha_jefes = fechaGuion(trim(filter_input(INPUT_POST, "fecha_jefes", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  45. $horario = filter_input(INPUT_POST, "horario", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  46. $inter = filter_input(INPUT_POST, "inter", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  47. $fecha_inicial_per = fechaGuion(trim(filter_input(INPUT_POST, "fecha_inicial_per", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  48. $fecha_final_per = fechaGuion(trim(filter_input(INPUT_POST, "fecha_final_per", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  49. $fecha_inicial_extras = fechaGuion(trim(filter_input(INPUT_POST, "fecha_inicial_extras", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  50. $fecha_final_extras = fechaGuion(trim(filter_input(INPUT_POST, "fecha_final_extras", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  51. $horario = ($horario == 1 ? 'true' : 'false');
  52. $inter_text = ($inter == 1 ? 'true' : 'false');
  53. try {
  54. $pdo->beginTransaction();
  55. if($fecha_jefes == "")
  56. $stmt = $pdo->prepare('Select * from fu_periodo(:id, :desc, :fini, :ffin, :edo, NULL, '.$horario.', '.$inter_text.')');
  57. else{
  58. $stmt = $pdo->prepare('Select * from fu_periodo(:id, :desc, :fini, :ffin, :edo, :fjefes, '.$horario.', '.$inter_text.')');
  59. $stmt->bindParam(":fjefes", $fecha_jefes);
  60. }
  61. $stmt->bindParam(":id", $id);
  62. $stmt->bindParam(":desc", $desc);
  63. $stmt->bindParam(":fini", $fecha_inicial);
  64. $stmt->bindParam(":ffin", $fecha_final);
  65. $stmt->bindParam(":edo", $estado);
  66. if(!$stmt->execute()){
  67. $pdo->rollBack();
  68. //print_r($stmt->errorInfo());
  69. header("Location:".$pag."?error=2");
  70. exit();
  71. }
  72. $stmt->closeCursor();
  73. $stmt = null;
  74. $stmt = $pdo->prepare('Select * from fi_fechaimportante(:periodo, 3, :fechai, :fechaf )');//fechas periodo
  75. $stmt->bindParam(":periodo", $id);
  76. $stmt->bindParam(":fechai", $fecha_inicial_per);
  77. $stmt->bindParam(":fechaf", $fecha_final_per);
  78. if(!$stmt->execute()){
  79. $pdo->rollBack();
  80. //echo "3";print_r($stmt->errorInfo());exit();
  81. header("Location:".$pag."?error=5");
  82. exit();
  83. }
  84. $stmt->closeCursor();
  85. if($nivel == 1 && $inter == 0){
  86. if($fecha_inicial_extras != "" && $fecha_final_extras != ""){
  87. $stmt = $pdo->prepare('Select * from fi_fechaimportante(:periodo, 2, :fechai, :fechaf )');//fehas extraordinarios
  88. $stmt->bindParam(":periodo", $id);
  89. $stmt->bindParam(":fechai", $fecha_inicial_extras);
  90. $stmt->bindParam(":fechaf", $fecha_final_extras);
  91. if(!$stmt->execute()){
  92. $pdo->rollBack();
  93. //echo "2";print_r($stmt->errorInfo());exit();
  94. header("Location:".$pag."?error=5");
  95. exit();
  96. }
  97. $stmt->closeCursor();
  98. }
  99. }else{
  100. $stmt = $pdo->prepare('Select * from fd_fechaimportante(:periodo, 2)');//fehas extraordinarios
  101. $stmt->bindParam(":periodo", $id);
  102. if(!$stmt->execute()){
  103. $pdo->rollBack();
  104. //echo "2 delete";print_r($stmt->errorInfo());exit();
  105. header("Location:".$pag."?error=5");
  106. exit();
  107. }
  108. $stmt->closeCursor();
  109. }
  110. if($id == $_SESSION["periodo_id"]){//Si se editó periodo en sesión, actualizar información
  111. if($estado != 2){//no es inactivo
  112. $_SESSION["periodo_desc"] = $desc;
  113. }else{//se desactiva
  114. unset($_SESSION["periodo_id"]);
  115. unset($_SESSION["periodo_desc"]);
  116. }
  117. }
  118. $pdo->commit();
  119. $log = new LogActividad();
  120. $desc_log = "Actualiza periodo nuevo ID[".$id."] Nombre[".$desc."] FechaInicial[".$fecha_inicial."] FechaFinal[".$fecha_final."] Nivel[".$nivel."] Estado[".$estado."] FechaJefes[".$fecha_jefes."]";
  121. $log->appendLog($_SESSION["usuario_id"], $_SESSION["usuario_nombre"]." ".$_SESSION["usuario_apellidos"], $desc_log);
  122. header("Location: ".$pag."?ok=1");
  123. exit();
  124. } catch(PDOException $e) {
  125. $pdo->rollBack();
  126. header("Location:".$pag."?error=2");
  127. //print_r($e);
  128. }
  129. ?>