tieneAcceso() || !$objSesion->puedeEditar()){ header("Location: ".$pag."?error=2"); exit(); } unset($objValida); if(!isset($_POST["fecha_inicial"]) || !isset($_POST["fecha_final"]) || !isset($_POST["texto"]) || (!isset($_POST["tipo"]) && !isset($_POST["usuario"])) ){ header("Location: ".$pag."?error=0"); exit(); } $fecha_inicial = trim(filter_input(INPUT_POST, "fecha_inicial", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto $fecha_inicial = fechaGuion($fecha_inicial); $fecha_final = trim(filter_input(INPUT_POST, "fecha_final", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto $fecha_final = fechaGuion($fecha_final); $texto = $_POST["texto"]; $usuarioArr = array(); if(isset($_POST["tipo"])){ $tipoArr = $_POST["tipo"]; foreach($tipoArr as $tipo){ switch ($tipo){ case 1://profesores $stmt = $pdo->prepare('Select * from fs_profesores()'); if(!$stmt->execute()){ $pdo->rollBack(); //echo "fs_profesores "; //print_r($stmt->errorInfo()); header("Location:".$pag."?error=1"); exit(); } $rs = $stmt->fetchAll(); $stmt->closeCursor(); break; case 2://jefes de carrera $stmt = $pdo->prepare('Select * from fs_jefescarrera()'); if(!$stmt->execute()){ $pdo->rollBack(); //echo "fs_jefescarrera() "; //print_r($stmt->errorInfo()); header("Location:".$pag."?error=1"); exit(); } $rs = $stmt->fetchAll(); $stmt->closeCursor(); break; } if(isset($rs) && count($rs) > 0){ foreach($rs as $usr){ $usuarioArr[] = $usr["Usuario_id"]; } unset($rs); } } } if(isset($_POST["usuario"])){ foreach($_POST["usuario"] as $usr){ if(!in_array($usr, $usuarioArr)){ $usuarioArr[] = $usr; } } } try { $pdo->beginTransaction(); $stmt = $pdo->prepare('Select * from fi_aviso(:fini, :ffin, :texto, :usr)'); $stmt->bindParam(":fini", $fecha_inicial); $stmt->bindParam(":ffin", $fecha_final); $stmt->bindParam(":texto", $texto); $stmt->bindParam(":usr", $_SESSION["usuario_id"]); if(!$stmt->execute()){ $pdo->rollBack(); //echo "fi_materia "; //print_r($stmt->errorInfo()); header("Location:".$pag."?error=1"); exit(); } $rs = $stmt->fetch(); $aviso_id = $rs["fi_aviso"]; $stmt->closeCursor(); unset($rs); //Inserta usuarios if(isset($usuarioArr)){ foreach($usuarioArr as $usuario){ $stmt = $pdo->prepare('Select * from fi_avisousuario(:aviso, :usr)'); $stmt->bindParam(":aviso", $aviso_id); $stmt->bindParam(":usr", $usuario); if(!$stmt->execute()){ $pdo->rollBack(); //echo "fi_avisousuario"; //print_r($stmt->errorInfo()); header("Location:".$pag."?error=4"); exit(); } } $stmt->closeCursor(); } $stmt = null; $log = new LogActividad(); $desc_log = "Inserta aviso nuevo ID[".$aviso_id."] Fecha inicial[".$fecha_inicial."] Fecha final[".$fecha_final."] Usuarios[".count($usuarioArr)."]"; $log->appendLog($_SESSION["usuario_id"], $_SESSION["usuario_nombre"]." ".$_SESSION["usuario_apellidos"], $desc_log); $pdo->commit(); header("Location: ../avisos.php?ok=0"); }catch(PDOException $e) { $pdo->rollBack(); header("Location:".$pag."?error=1"); } ?>