getError(); if ($error) { return false; } $result = $client->call("valida_user_addo", array($user, $pass)); if ($client->fault) { return false; } else { $error = $client->getError(); if ($error) { return false; } else { if($result) return 1; else return 0; } } } if(!isset($_POST["username"]) || !isset($_POST["passwd"])){ header("Location: ../index.php?error=0"); //echo "No hay POST"; exit; } $usr = trim(filter_input(INPUT_POST, "username"));//limpia texto $usr_db = limpiaClave($usr); $pass = $_POST["passwd"]; //trim(filter_input(INPUT_POST, "passwd"));//limpia texto $stmt = $pdo->prepare('Select * from fs_validaclaveulsa(:usr) AS "Usuario_id"'); $stmt->bindParam(":usr", $usr_db); if(!$stmt->execute()){ //print_r($stmt->errorInfo()); header("Location: ../index.php?error=2"); exit(); } $usr_rs = $stmt->fetch();//Devuelve sólo 1 resultado $stmt->closeCursor(); // cierra conexion de resultado $stmt = null; // cierra conexion if($usr_rs["Usuario_id"] != ""){//Si existe el usuario $valido = validaUsuario($usr, $pass);//false = error, 0 = sin permiso, 1 = con permiso if($valido === false){ header("Location: ../index.php?error=1&sgu=false"); exit(); }else if($valido == 1){ $stmt = $pdo->prepare('Select * from fs_usuario(:id)'); $stmt->bindParam(":id", $usr_rs["Usuario_id"]); if(!$stmt->execute()){ //print_r($stmt->errorInfo()); header("Location: ../index.php?error=2"); exit(); } $rs = $stmt->fetch();//Devuelve sólo 1 resultado $stmt->closeCursor(); // cierra conexion de resultado $stmt = null; // cierra conexion //Guarda resultado de autenticación en sesión $_SESSION["n_timeout"] = time(); $_SESSION["n_usuario_id"] = $rs["Usuario_id"]; $_SESSION["n_usuario_nombre"] = $rs["Usuario_nombre"]; $_SESSION["n_usuario_apellidos"] = $rs["Usuario_apellidos"]; $_SESSION["n_sgi_administrador"] = $rs["SGI_administrador"]; $_SESSION["n_navidad"] = NAVIDAD; $stmt = $pdo->prepare('Select * from fs_navidadusuario(:id, '.NAVIDAD.', NULL)'); $stmt->bindParam(":id", $_SESSION["n_usuario_id"]); if(!$stmt->execute()){ //print_r($stmt->errorInfo()); header("Location: ../index.php?error=2"); exit(); } $usr_rs = $stmt->fetch();//Devuelve sólo 1 resultado $stmt->closeCursor(); // cierra conexion de resultado $stmt = null; // cierra conexion if($usr_rs["NavidadUsuario_existe"]){ if(!$usr_rs["NavidadUsuario_activo"]){ $stmt = $pdo->prepare('Select * from fu_navidadusuario(:id, '.NAVIDAD.', true)'); $stmt->bindParam(":id", $_SESSION["n_usuario_id"]); if(!$stmt->execute()){ //print_r($stmt->errorInfo()); header("Location: ../index.php?error=4"); exit(); } } }else{//no existe, darlo de alta $stmt = $pdo->prepare('Select * from fi_navidadusuario(:id, '.NAVIDAD.', true)'); $stmt->bindParam(":id", $_SESSION["n_usuario_id"]); if(!$stmt->execute()){ //print_r($stmt->errorInfo()); header("Location: ../index.php?error=4"); exit(); } } header("Location: ../main.php");//todo OK manda a sellección del sistema exit(); }else{//error de autenticación //echo "fallo autenticación"; header("Location: ../index.php?error=1"); exit(); } }else{//no existe en la BD //echo "no existe en BD"; header("Location: ../index.php?error=2"); exit(); } //Si no entró a ninguna, no tiene permisos //echo "No existe usuario"; exit(); header("Location: ../index.php?error=3"); $pdo = null; ?>