datos_update.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /*
  3. * Inserta los datos del nuevo sistema
  4. * Recibe:
  5. * desc - Descripción
  6. * nombre
  7. * pag
  8. */
  9. require_once("../include/constantes.php");
  10. require_once("../include/bd_pdo.php");
  11. session_start();
  12. if(!isset($_SESSION["usuario_id"])){
  13. session_destroy();
  14. $pag = "salir.php?expired=1";
  15. header("Location: ".$pag);
  16. exit();
  17. }
  18. $session_life = 1*60*60;//convertido a segundos
  19. if (isset($_SESSION["timeout"])) {
  20. // calculate the session's "time to live"
  21. $sessionTTL = time() - $_SESSION["timeout"];
  22. if ($sessionTTL > $session_life) {
  23. $_SESSION = array();
  24. session_destroy();
  25. $pag = $_SERVER['SERVER_NAME']."/salir.php?expired=1";
  26. header("Location: http://".$pag);
  27. exit();
  28. }
  29. }else{
  30. $_SESSION = array();
  31. session_destroy();
  32. $pag = $_SERVER['SERVER_NAME']."/salir.php?expired=1";
  33. header("Location: http://".$pag);
  34. exit();
  35. }
  36. $_SESSION["timeout"] = time();
  37. $pag="../apsa/main.php";
  38. if(isset($_POST["nombre"], $_POST["apellidos"], $_POST["cambio"]) && isset($_POST["contactos"], $_POST["curp"], $_POST["contactos"], $_POST["emergencia"])
  39. && trim($_POST["nombre"]) != "" && trim($_POST["apellidos"]) != ""){
  40. $nombre = trim(filter_input(INPUT_POST, "nombre", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  41. $apellidos = trim(filter_input(INPUT_POST, "apellidos", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  42. $grado = trim(filter_input(INPUT_POST, "grado", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  43. $id = $_SESSION["usuario_id"];
  44. $cambio = filter_input(INPUT_POST, "cambio", FILTER_SANITIZE_NUMBER_INT);//limpia texto
  45. $curp = mb_strtoupper(trim(filter_input(INPUT_POST, "curp", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  46. $rfc = mb_strtoupper(trim(filter_input(INPUT_POST, "rfc", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto
  47. $dir = trim(filter_input(INPUT_POST, "direccion", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW)));//limpia texto
  48. try{
  49. $pdo->beginTransaction();
  50. if($cambio == 1)
  51. $stmt = $pdo->prepare('Select * from fi_checkusuario(:id, true, :grado, :nom, :apell, :curp, :rfc, :dir)');
  52. else
  53. $stmt = $pdo->prepare('Select * from fi_checkusuario(:id, false, :grado, :nom, :apell, :curp, :rfc, :dir)');
  54. $stmt->bindParam(":id", $id);
  55. $stmt->bindParam(":grado", $grado);
  56. $stmt->bindParam(":nom", $nombre);
  57. $stmt->bindParam(":apell", $apellidos);
  58. $stmt->bindParam(":curp", $curp);
  59. $stmt->bindParam(":rfc", $rfc);
  60. $stmt->bindParam(":dir", $dir);
  61. if(!$stmt->execute()){
  62. $pdo->rollBack();
  63. header("Location: ".$pag."?error=1");
  64. exit();
  65. }
  66. $hasLasalle = false;
  67. $hasLasallistas = false;
  68. $error = false;
  69. $contactoObj = json_decode($_POST["contactos"], true);
  70. foreach($contactoObj as $contacto){
  71. $stmt = $pdo->prepare('Select * from fd_checkcontacto(:id, :num)');
  72. $stmt->bindParam(":id", $id);
  73. $stmt->bindParam(":num", $contacto["num"]);
  74. $stmt->execute();
  75. if(!empty($contacto["contacto_valor"])){
  76. $query = ":id, :num, ";
  77. if(!empty($contacto["contacto_id"])){
  78. $query .= ":contacto_id, ";
  79. }else{
  80. $query .= "NULL,";
  81. }
  82. $query .= ":contacto,";
  83. $query .= ":perfil, :tipo, ";
  84. if(!empty($contacto["subtipo"])){
  85. $query .= ":subtipo";
  86. }else{
  87. $query .= "NULL";
  88. }
  89. //echo $query."<br>";
  90. $stmt = $pdo->prepare('Select * from fi_checkcontacto('.$query.')');
  91. if(!empty($contacto["contacto_id"])){ $stmt->bindParam(":contacto_id", $contacto["contacto_id"]); }
  92. if(!empty($contacto["subtipo"])){ $stmt->bindParam(":subtipo", $contacto["subtipo"]); }
  93. $stmt->bindParam(":id", $id);
  94. $stmt->bindParam(":num", $contacto["num"]);
  95. $stmt->bindParam(":contacto", $contacto["contacto_valor"]);
  96. $stmt->bindParam(":perfil", $contacto["perfil"]);
  97. $stmt->bindParam(":tipo", $contacto["tipo"]);
  98. if(!$stmt->execute()){
  99. $error=true;
  100. }
  101. }
  102. }
  103. $emergenciaObj = json_decode($_POST["emergencia"], true);
  104. //echo $emergenciaObj;
  105. //echo "<p>".!$error." ".!empty($emergenciaObj["emergencia_nombre"])."</p>";
  106. if(!$error && !empty($emergenciaObj["emergencia_nombre"])){
  107. $stmt = $pdo->prepare('Select * from fi_checkemergencia(:id, :nom, :tel)');
  108. $stmt->bindParam(":id", $id);
  109. $stmt->bindParam(":nom", $emergenciaObj["emergencia_nombre"]);
  110. $stmt->bindParam(":tel", $emergenciaObj["emergencia_tel"]);
  111. if(!$stmt->execute()){
  112. $error=true;
  113. }
  114. }
  115. if(!$error){
  116. $pdo->commit();
  117. }else{
  118. $pdo->rollBack();
  119. //header("Location: ".$pag."?error=4");
  120. echo "else";
  121. print_r($e);
  122. exit();
  123. }
  124. } catch(PDOException $e) {
  125. $pdo->rollBack();
  126. //header("Location:".$pag."?error=4");
  127. print_r($e);
  128. exit();
  129. }
  130. }else{
  131. header("Location: ".$pag."?error=3");
  132. exit();
  133. }
  134. header("Location: ".$pag."?ok=1");
  135. ?>