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."]
";
//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."]
";
//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."]
";
//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);
}
}
?>