tieneAcceso() || !$objSesion->puedeEditar()){ header("Location: ".$pag."?error=2"); exit(); } unset($objValida); try { $pdo->beginTransaction(); if(!isset($_POST["nombre"]) || !isset($_POST["apellidos"]) || !isset($_POST["clave"]) || !isset($_POST["ingreso"])){ header("Location:".$pag."?error=0"); exit(); } $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 $curp = mb_strtoupper(trim(filter_input(INPUT_POST, "curp", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto $fechaingreso = fechaGuion(trim(filter_input(INPUT_POST, "ingreso")));//limpia texto //$clave = mb_strtoupper(trim(filter_input(INPUT_POST, "clave", FILTER_SANITIZE_STRING,array('flags' => FILTER_FLAG_STRIP_LOW))));//limpia texto $clave = filter_input(INPUT_POST, "clave", FILTER_SANITIZE_NUMBER_INT);//limpia texto $sub = 3; if(empty($_POST["sub"])) $sub = filter_input(INPUT_POST, "sub", FILTER_SANITIZE_NUMBER_INT);//limpia texto if(isset($_POST["revalida"]) && intval($_POST["revalida"]) == 1){ $procedencia = filter_input(INPUT_POST, "procedencia", FILTER_SANITIZE_NUMBER_INT);//limpia texto $gen = fechaGuion(trim(filter_input(INPUT_POST, "generacion")));//limpia texto }else{ $gen = $fechaingreso; } //Valida que no esté solo en mayúsculas if($nombre == mb_strtoupper($nombre, "UTF-8")){ $nombre = mb_convert_case(mb_strtolower($nombre), MB_CASE_TITLE, "UTF-8"); } if($apellidos == mb_strtoupper($apellidos, "UTF-8")){ $apellidos = mb_convert_case(mb_strtolower($apellidos), MB_CASE_TITLE, "UTF-8"); } $plan = filter_input(INPUT_POST, "plan", FILTER_SANITIZE_NUMBER_INT);//limpia texto //Inserta usuario $stmt = $pdo->prepare('Select * from fi_usuario(:nom, :ape, :curp)');//devuelve: Usuario_id $stmt->bindParam(":nom", $nombre); $stmt->bindParam(":ape", $apellidos); $stmt->bindParam(":curp", $curp); if(!$stmt->execute()){ $pdo->rollBack(); //echo "Error fi_usuario [".$nombre."] [".$apellidos."][".$clave."] [".$user."]"; //print_r($stmt->errorInfo()); header("Location:".$pag."?error=1"); exit(); } $usr_rs = $stmt->fetch(); $usr_id = $usr_rs["Usuario_id"]; $stmt->closeCursor(); // cierra conexion de resultado $usr_rs = null; //unset($usr_rs); if(!empty($procedencia) ){ $stmt = $pdo->prepare('Select * from fi_alumno_planestudio(:id, :plan, :claveulsa, :fechai, :sub, :procedencia, :gen)'); $stmt->bindParam(":procedencia", $procedencia); }else{ $stmt = $pdo->prepare('Select * from fi_alumno_planestudio(:id, :plan, :claveulsa, :fechai, :sub, NULL, :gen)'); } $stmt->bindParam(":id", $usr_id); $stmt->bindParam(":plan", $plan); $stmt->bindParam(":claveulsa", $clave); $stmt->bindParam(":fechai", $fechaingreso); $stmt->bindParam(":sub", $sub); $stmt->bindParam(":gen", $gen); if(!$stmt->execute()){ $stmt->closeCursor(); $pdo->rollBack(); header("Location:".$pag."?error=7"); exit(); } $usr_rs = $stmt->fetch(); $usr_insertado = $usr_rs["fi_alumno_planestudio"]; $stmt->closeCursor(); $usr_rs = null; unset($usr_rs); if($usr_insertado == 1){ //Inserta datos de contacto if(!empty($_POST["contacto_tipo"]) ){ $tipoArr = $_POST["contacto_tipo"]; $valorArr = $_POST["contacto_valor"]; $perfilArr = $_POST["contacto_perfil"]; $subtipoArr = $_POST["contacto_subtipo"]; for($i=0; $i< count($tipoArr); $i++){ if(trim($valorArr[$i]) != ""){ if($subtipoArr[$i] != 0){ $stmt = $pdo->prepare('Select * from fi_contacto(:valor, :tipo, :usr, :perf, :subt)');//inserta contactos $stmt->bindParam(":subt", $subtipoArr[$i]); }else{ $stmt = $pdo->prepare('Select * from fi_contacto(:valor, :tipo, :usr, :perf, NULL)');//inserta contactos } $stmt->bindParam(":usr", $usr_id); $stmt->bindParam(":valor", $valorArr[$i]); $stmt->bindParam(":tipo", $tipoArr[$i]); $stmt->bindParam(":perf", $perfilArr[$i]); if(!$stmt->execute()){ $pdo->rollBack(); //echo "Error fi_contacto [".$valorArr[$i]."] [".$tipoArr[$i]."] [".$usr_id."]
"; //print_r($stmt->errorInfo()); header("Location:".$pag."?error=6"); exit(); } } } $stmt->closeCursor(); // cierra conexion de resultado } $log = new LogActividad(); $desc_log = "Inserta alumno nuevo ID[".$usr_id."] Nombre[".($nombre." ".$paterno." ".$materno)."] ClaveULSA[".$clave."] CURP[".$curp."]"; $log->appendLog($_SESSION["usuario_id"], $_SESSION["usuario_nombre"]." ".$_SESSION["usuario_apellidos"], $desc_log); $pdo->commit(); }else{ $pdo->rollBack(); //echo "no insertado"; header("Location:".$pag."?error=1&insertado=false"); exit(); } $stmt = null; // cierra conexion header("Location: ../alumnos.php?ok=0"); } catch(PDOException $e) { $pdo->rollBack(); header("Location:".$pag."?error=1"); //print_r($e); } ?>