123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- /*
- * Inserta los datos del nuevo sistema
- * Recibe:
- * desc - Descripción
- * nombre
- * pag
- */
- require_once("../include/constantes.php");
- require_once("../include/bd_pdo.php");
- session_start();
- if(!isset($_SESSION["usuario_id"])){
- session_destroy();
- $pag = "salir.php?expired=1";
- header("Location: ".$pag);
- exit();
- }
- $session_life = 1*60*60;//convertido a segundos
- if (isset($_SESSION["timeout"])) {
- // calculate the session's "time to live"
- $sessionTTL = time() - $_SESSION["timeout"];
- if ($sessionTTL > $session_life) {
- $_SESSION = array();
- session_destroy();
- $pag = $_SERVER['SERVER_NAME']."/salir.php?expired=1";
- header("Location: http://".$pag);
- exit();
- }
- }else{
- $_SESSION = array();
- session_destroy();
- $pag = $_SERVER['SERVER_NAME']."/salir.php?expired=1";
- header("Location: http://".$pag);
- exit();
- }
- $_SESSION["timeout"] = time();
- $pag="../apsa/main.php";
- if(isset($_POST["nombre"], $_POST["apellidos"], $_POST["cambio"]) && isset($_POST["contactos"], $_POST["curp"], $_POST["contactos"], $_POST["emergencia"])
- && trim($_POST["nombre"]) != "" && trim($_POST["apellidos"]) != ""){
- $nombre = trim(filter_input(INPUT_POST, "nombre", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
- $apellidos = trim(filter_input(INPUT_POST, "apellidos", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
- $grado = trim(filter_input(INPUT_POST, "grado", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
- $id = $_SESSION["usuario_id"];
- $cambio = filter_input(INPUT_POST, "cambio", FILTER_SANITIZE_NUMBER_INT);//limpia texto
- $curp = mb_strtoupper(trim(filter_input(INPUT_POST, "curp", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
- $rfc = mb_strtoupper(trim(filter_input(INPUT_POST, "rfc", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
- $dir = trim(filter_input(INPUT_POST, "direccion", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
-
- try{
- $pdo->beginTransaction();
- if($cambio == 1)
- $stmt = $pdo->prepare('Select * from fi_checkusuario(:id, true, :grado, :nom, :apell, :curp, :rfc, :dir)');
- else
- $stmt = $pdo->prepare('Select * from fi_checkusuario(:id, false, :grado, :nom, :apell, :curp, :rfc, :dir)');
- $stmt->bindParam(":id", $id);
- $stmt->bindParam(":grado", $grado);
- $stmt->bindParam(":nom", $nombre);
- $stmt->bindParam(":apell", $apellidos);
- $stmt->bindParam(":curp", $curp);
- $stmt->bindParam(":rfc", $rfc);
- $stmt->bindParam(":dir", $dir);
- if(!$stmt->execute()){
- $pdo->rollBack();
- header("Location: ".$pag."?error=1");
- exit();
- }
- $hasLasalle = false;
- $hasLasallistas = false;
- $error = false;
- $contactoObj = json_decode($_POST["contactos"], true);
- foreach($contactoObj as $contacto){
- $stmt = $pdo->prepare('Select * from fd_checkcontacto(:id, :num)');
- $stmt->bindParam(":id", $id);
- $stmt->bindParam(":num", $contacto["num"]);
- $stmt->execute();
- if(!empty($contacto["contacto_valor"])){
- $query = ":id, :num, ";
- if(!empty($contacto["contacto_id"])){
- $query .= ":contacto_id, ";
- }else{
- $query .= "NULL,";
- }
- $query .= ":contacto,";
- $query .= ":perfil, :tipo, ";
- if(!empty($contacto["subtipo"])){
- $query .= ":subtipo";
- }else{
- $query .= "NULL";
- }
- //echo $query."<br>";
- $stmt = $pdo->prepare('Select * from fi_checkcontacto('.$query.')');
- if(!empty($contacto["contacto_id"])){ $stmt->bindParam(":contacto_id", $contacto["contacto_id"]); }
- if(!empty($contacto["subtipo"])){ $stmt->bindParam(":subtipo", $contacto["subtipo"]); }
- $stmt->bindParam(":id", $id);
- $stmt->bindParam(":num", $contacto["num"]);
- $stmt->bindParam(":contacto", $contacto["contacto_valor"]);
- $stmt->bindParam(":perfil", $contacto["perfil"]);
- $stmt->bindParam(":tipo", $contacto["tipo"]);
- if(!$stmt->execute()){
- $error=true;
- }
- }
- }
- $emergenciaObj = json_decode($_POST["emergencia"], true);
- //echo $emergenciaObj;
- //echo "<p>".!$error." ".!empty($emergenciaObj["emergencia_nombre"])."</p>";
-
- if(!$error && !empty($emergenciaObj["emergencia_nombre"])){
- $stmt = $pdo->prepare('Select * from fi_checkemergencia(:id, :nom, :tel)');
- $stmt->bindParam(":id", $id);
- $stmt->bindParam(":nom", $emergenciaObj["emergencia_nombre"]);
- $stmt->bindParam(":tel", $emergenciaObj["emergencia_tel"]);
- if(!$stmt->execute()){
- $error=true;
- }
- }
-
- if(!$error){
- $pdo->commit();
- }else{
- $pdo->rollBack();
- //header("Location: ".$pag."?error=4");
- echo "else";
- print_r($e);
- exit();
- }
- } catch(PDOException $e) {
- $pdo->rollBack();
- //header("Location:".$pag."?error=4");
- print_r($e);
- exit();
- }
- }else{
-
- header("Location: ".$pag."?error=3");
- exit();
- }
- header("Location: ".$pag."?ok=1");
- ?>
|