areaacademica_insert.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /*
  3. * Inserta los datos de área administrativa
  4. * Recibe:
  5. * desc
  6. * Error:
  7. * 0 - No se recibieron los datos
  8. * 1 - Error de base de datos
  9. * Success:
  10. */
  11. require_once("../../include/constantes.php");
  12. require_once("../../include/bd_pdo.php");
  13. require_once("../../classes/ValidaSesion.php");
  14. require_once("../classes/LogActividad.php");//die on error
  15. $pag = "../areasacademicas.php";
  16. //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
  17. $objSesion = new ValidaSesion($pdo, 62, APSA);
  18. if(!$objSesion->tieneAcceso()){
  19. $objSesion->terminaSesion();
  20. //print_r($objSesion->getError());
  21. }
  22. if(!$objSesion->puedeEditar()){
  23. header("Location: ".$pag);
  24. exit();
  25. }
  26. unset($objValida);
  27. if(!isset($_POST["desc"]) || !isset($_POST["color"]) || !isset($_POST["nivel"])){
  28. header("Location: ".$pag."?error=0");
  29. exit();
  30. }
  31. $desc = trim(filter_input(INPUT_POST, "desc", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  32. $color = trim(filter_input(INPUT_POST, "color", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  33. $nivel = filter_input(INPUT_POST, "nivel", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  34. $alerta = filter_input(INPUT_POST, "alerta", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  35. $curricular = filter_input(INPUT_POST, "curricular", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  36. $sql = "";
  37. if($alerta == 1){ $sql.="true,";}else{$sql.="false,";}
  38. if($curricular == 1){ $sql.="true";}else{$sql.="false";}
  39. $stmt = $pdo->prepare('Select * from fi_areaacademica(:desc, :color, :nivel, '.$sql.')');
  40. $stmt->bindParam(":desc", $desc);
  41. $stmt->bindParam(":color", $color);
  42. $stmt->bindParam(":nivel", $nivel);
  43. if(!$stmt->execute()){
  44. print_r($stmt->errorInfo());
  45. //header("Location:".$pag."?error=1");
  46. exit();
  47. }
  48. $rs = $stmt->fetch();
  49. $stmt->closeCursor();
  50. $stmt = null;
  51. $log = new LogActividad();
  52. $desc_log = "Inserta área académica nueva ID[".$rs["fi_areaacademica"]."] Nombre[".$desc."] Color[".$color."] Nivel[".$nivel."]";
  53. $log->appendLog($_SESSION["usuario_id"], $_SESSION["usuario_nombre"]." ".$_SESSION["usuario_apellidos"], $desc_log);
  54. header("Location: ".$pag);
  55. exit();
  56. ?>