123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php
- /*
- * Actualiza los datos del periodo
- * Recibe:
- * id - ID del menú a editar
- * desc - Descripción
- * fecha_inicial date,
- * fecha_final date,
- * nivel integer,
- * estado integer,
- * fecha_jefes
- * Error:
- * 0 - No se recibieron los datos
- * 1 - Error de base de datos
- * Success:
- */
- require_once("../../include/constantes.php");
- require_once("../../include/bd_pdo.php");
- require_once("../../include/util.php");
- require_once("../../classes/ValidaSesion.php");
- require_once("../classes/LogActividad.php");//die on error
- $pag = "../periodos.php";
- //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
- $objSesion = new ValidaSesion($pdo, 44, APSA);
- if(!$objSesion->tieneAcceso()){
- $objSesion->terminaSesion();
- //print_r($objSesion->getError());
- }
- if(!$objSesion->puedeEditar()){
- header("Location: ".$pag);
- exit();
- }
- unset($objValida);
- if(!isset($_POST["id"]) || !isset($_POST["desc"])){
- header("Location: ".$pag."?error=0");
- exit();
- }
- $id = filter_input(INPUT_POST, "id", FILTER_SANITIZE_NUMBER_INT);//limpia texto
- $desc = trim(filter_input(INPUT_POST, "desc", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
- $fecha_inicial = fechaGuion(trim(filter_input(INPUT_POST, "fecha_inicial", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
- $fecha_final = fechaGuion(trim(filter_input(INPUT_POST, "fecha_final", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
- $nivel = filter_input(INPUT_POST, "nivel", FILTER_SANITIZE_NUMBER_INT);//limpia texto
- $estado = filter_input(INPUT_POST, "estado", FILTER_SANITIZE_NUMBER_INT);//limpia texto
- $fecha_jefes = fechaGuion(trim(filter_input(INPUT_POST, "fecha_jefes", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
- $horario = filter_input(INPUT_POST, "horario", FILTER_SANITIZE_NUMBER_INT);//limpia texto
- $inter = filter_input(INPUT_POST, "inter", FILTER_SANITIZE_NUMBER_INT);//limpia texto
- $fecha_inicial_per = fechaGuion(trim(filter_input(INPUT_POST, "fecha_inicial_per", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
- $fecha_final_per = fechaGuion(trim(filter_input(INPUT_POST, "fecha_final_per", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
- $fecha_inicial_extras = fechaGuion(trim(filter_input(INPUT_POST, "fecha_inicial_extras", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
- $fecha_final_extras = fechaGuion(trim(filter_input(INPUT_POST, "fecha_final_extras", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
- $horario = ($horario == 1 ? 'true' : 'false');
- $inter_text = ($inter == 1 ? 'true' : 'false');
- try {
- $pdo->beginTransaction();
- if($fecha_jefes == "")
- $stmt = $pdo->prepare('Select * from fu_periodo(:id, :desc, :fini, :ffin, :edo, NULL, '.$horario.', '.$inter_text.')');
- else{
- $stmt = $pdo->prepare('Select * from fu_periodo(:id, :desc, :fini, :ffin, :edo, :fjefes, '.$horario.', '.$inter_text.')');
- $stmt->bindParam(":fjefes", $fecha_jefes);
- }
- $stmt->bindParam(":id", $id);
- $stmt->bindParam(":desc", $desc);
- $stmt->bindParam(":fini", $fecha_inicial);
- $stmt->bindParam(":ffin", $fecha_final);
- $stmt->bindParam(":edo", $estado);
- if(!$stmt->execute()){
- $pdo->rollBack();
- //print_r($stmt->errorInfo());
- header("Location:".$pag."?error=2");
- exit();
- }
- $stmt->closeCursor();
- $stmt = null;
- $stmt = $pdo->prepare('Select * from fi_fechaimportante(:periodo, 3, :fechai, :fechaf )');//fechas periodo
- $stmt->bindParam(":periodo", $id);
- $stmt->bindParam(":fechai", $fecha_inicial_per);
- $stmt->bindParam(":fechaf", $fecha_final_per);
- if(!$stmt->execute()){
- $pdo->rollBack();
- //echo "3";print_r($stmt->errorInfo());exit();
- header("Location:".$pag."?error=5");
- exit();
- }
- $stmt->closeCursor();
- if($nivel == 1 && $inter == 0){
- if($fecha_inicial_extras != "" && $fecha_final_extras != ""){
- $stmt = $pdo->prepare('Select * from fi_fechaimportante(:periodo, 2, :fechai, :fechaf )');//fehas extraordinarios
- $stmt->bindParam(":periodo", $id);
- $stmt->bindParam(":fechai", $fecha_inicial_extras);
- $stmt->bindParam(":fechaf", $fecha_final_extras);
- if(!$stmt->execute()){
- $pdo->rollBack();
- //echo "2";print_r($stmt->errorInfo());exit();
- header("Location:".$pag."?error=5");
- exit();
- }
- $stmt->closeCursor();
- }
- }else{
- $stmt = $pdo->prepare('Select * from fd_fechaimportante(:periodo, 2)');//fehas extraordinarios
- $stmt->bindParam(":periodo", $id);
- if(!$stmt->execute()){
- $pdo->rollBack();
- //echo "2 delete";print_r($stmt->errorInfo());exit();
- header("Location:".$pag."?error=5");
- exit();
- }
- $stmt->closeCursor();
- }
- if($id == $_SESSION["periodo_id"]){//Si se editó periodo en sesión, actualizar información
- if($estado != 2){//no es inactivo
- $_SESSION["periodo_desc"] = $desc;
- }else{//se desactiva
- unset($_SESSION["periodo_id"]);
- unset($_SESSION["periodo_desc"]);
- }
- }
- $pdo->commit();
- $log = new LogActividad();
- $desc_log = "Actualiza periodo nuevo ID[".$id."] Nombre[".$desc."] FechaInicial[".$fecha_inicial."] FechaFinal[".$fecha_final."] Nivel[".$nivel."] Estado[".$estado."] FechaJefes[".$fecha_jefes."]";
- $log->appendLog($_SESSION["usuario_id"], $_SESSION["usuario_nombre"]." ".$_SESSION["usuario_apellidos"], $desc_log);
- header("Location: ".$pag."?ok=1");
- exit();
- } catch(PDOException $e) {
- $pdo->rollBack();
- header("Location:".$pag."?error=2");
- //print_r($e);
- }
- ?>
|