123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- /*
- * Inserta los datos de una nueva carrera
- * Recibe:
- * fecha_inicial
- * fecha_final
- * texto
- * tipo[]
- * usuario[]
- */
- 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 = "../avisos_crear.php";
- //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
- $objSesion = new ValidaSesion($pdo, 80, APSA);
- if(!$objSesion->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");
- }
- ?>
|