123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- <?php
- /* AJAX
- * Selecciona los datos de la carrera
- * Recibe:
- * id - ID de la carrera
- * Return:
- * resultado o cadena de error
- */
- require_once("../../include/constantes.php");
- require_once("../../include/nocache.php");
- require_once("../../include/util.php");
- require_once("../../include/bd_pdo.php");
- require_once("../../classes/ValidaSesion.php");
- require "../../include/phpSpreadsheet/autoload.php";
- use PhpOffice\PhpSpreadsheet\IOFactory;
- $pag = "../alumnos_subir.php";
- //--- Objeto para validar usuario. El id de usuario lo lee desde sesión
- $objSesion = new ValidaSesion($pdo, 101, GEMA);
- if(!$objSesion->tieneAcceso()){
- header("Location: ".$pag."?error=2");
- exit();
- }else if(!isset($_FILES['archivo']['name']) || $_FILES['archivo']['name'] == null || !isset($_POST["ingreso"], $_POST["plan"])){
- header("Location: ".$pag."?error=0");
- exit();
- }else{
- //$inputFileName =__DIR__. '/tmp/alumnos_tmp.xlsx';
- $archivo = $_FILES['archivo']['name'];
-
- // Check file size
- if ($_FILES["archivo"]["size"] > 10 * 1024 * 1024) {//en bytes
- header("Location: ".$pag."?error=3");
- exit();
- }
- $exts_arr = array("xls","xlsx");
- $dot_arr = explode('.', $archivo);
- $ext = end($dot_arr);
- if(!in_array($ext, $exts_arr)){
- header("Location: ".$pag."?error=4");
- exit();
- }
- //$newfilename = "tmp_al_".$_SESSION["gpo_id"].".".$ext;
- $inputFileName = $_FILES["archivo"]["tmp_name"];
-
- $inputFileType = IOFactory::identify($inputFileName);
- $reader = IOFactory::createReader($inputFileType);
- $spreadsheet = $reader->load($inputFileName);
- $sheetData = $spreadsheet->getActiveSheet()->toArray();
-
- try {
- $pdo->beginTransaction();
- $alumnoArr = array();
- $al = 0;
- $row = 1;
- $repetido = 0;
-
- $fechaingreso = trim(filter_input(INPUT_POST, "ingreso"));//limpia texto
- $fechaingreso = fechaGuion($fechaingreso);
- $plan = filter_input(INPUT_POST, "plan", FILTER_SANITIZE_NUMBER_INT);//limpia texto
-
- foreach($sheetData as $data){
- if($row > 1){
- if($data[0] != "" && $data[1] != "" && $data[2] != "" && $data[3] != ""){
- $apellidos = mb_strtoupper(trim($data[0]));
- $nombre = mb_strtoupper(trim($data[1]));
- $clave = intval($data[2]);
- $curp = mb_strtoupper(trim($data[3]));
- $correo = $data[4];
- $telcasa = $data[5];
- $telcel = $data[6];
- $stmt = $pdo->prepare('Select * from fi_alumno(:nombre, :apellidos, :curp)');//no administrador, devuelve: Usuario_id
- $stmt->bindParam(":nombre", $nombre);
- $stmt->bindParam(":apellidos", $apellidos);
- $stmt->bindParam(":curp", $curp);
- if(!$stmt->execute()){
- $pdo->rollBack();
- header("Location:".$pag."?error=1");
- exit();
- }
- $usr_rs = $stmt->fetch();
- $usr_id = $usr_rs["Usuario_id"];
- $usr_existe = $usr_rs["Usuario_existe"];
- $stmt->closeCursor(); // cierra conexion de resultado
- $usr_rs = null;
- unset($usr_rs);
-
- if(!$usr_existe){
- $stmt = $pdo->prepare('Select * from fi_alumno_planestudio(:id, :plan, :claveulsa, :fechai)');
- $stmt->bindParam(":id", $usr_id);
- $stmt->bindParam(":plan", $plan);
- $stmt->bindParam(":claveulsa", $clave);
- $stmt->bindParam(":fechai", $fechaingreso);
- if(!$stmt->execute()){
- $stmt->closeCursor();
- $pdo->rollBack();
- header("Location:".$pag."?error=7");
- exit();
- }
- $stmt->closeCursor();
-
- //Inserta datos de contacto
- if($telcasa != ""){
- $stmt = $pdo->prepare('Select * from fi_contacto(:valor, 1, :usr, 1, NULL)');//inserta tel casa
- $stmt->bindParam(":usr", $usr_id);
- $stmt->bindParam(":valor", $telcasa);
- if(!$stmt->execute()){
- $pdo->rollBack();
- //echo "Error fi_contacto [".$valorArr[$i]."] [".$tipoArr[$i]."] [".$usr_id."]<br>";
- //print_r($stmt->errorInfo());
- header("Location:".$pag."?error=6");
- exit();
- }
- }
- if($telcel != ""){
- $stmt = $pdo->prepare('Select * from fi_contacto(:valor, 3, :usr, 1, NULL)');//inserta tel cel
- $stmt->bindParam(":usr", $usr_id);
- $stmt->bindParam(":valor", $telcel);
- if(!$stmt->execute()){
- $pdo->rollBack();
- //echo "Error fi_contacto [".$valorArr[$i]."] [".$tipoArr[$i]."] [".$usr_id."]<br>";
- //print_r($stmt->errorInfo());
- header("Location:".$pag."?error=6");
- exit();
- }
- }
- if($correo != ""){
- $stmt = $pdo->prepare('Select * from fi_contacto(:valor, 4, :usr, 1, NULL)');//inserta correo
- $stmt->bindParam(":usr", $usr_id);
- $stmt->bindParam(":valor", $correo);
- if(!$stmt->execute()){
- $pdo->rollBack();
- //echo "Error fi_contacto [".$valorArr[$i]."] [".$tipoArr[$i]."] [".$usr_id."]<br>";
- //print_r($stmt->errorInfo());
- header("Location:".$pag."?error=6");
- exit();
- }
- }
- $stmt->closeCursor(); // cierra conexion de resultado
- }else{
- $repetido++;
- }
- }
- }
- $row++;
- }
- $pdo->commit();
- $stmt = null; // cierra conexion
- if($repetido > 0){
- header("Location: ../alumnos.php?ok=4&rep=".$repetido);
- }else
- header("Location: ../alumnos.php?ok=3");
- //$alumnoArr;
- } catch(PDOException $e) {
- $pdo->rollBack();
- header("Location:".$pag."?error=1");
- //print_r($e);
- }
- }
- ?>
|