<?php


$json = file_get_contents('php://input');   
$obj = json_decode($json);
$id = $obj->flag;

// Returns a Json
header('Content-Type: application/json');
//header("Access-Control-Allow-Origin: *");
//echo "flag: ".$id;
switch($id){
    case '0':
        $conn = new mysqli("progymcloud.com", "direct18", "L4LL4v3M@3str@","direct18_ProGymCloud");
        $conn->set_charset("utf8");
        $msg = "ok";
        $baseD = "entre";
        $nombreGym;
        $query = "SELECT * FROM gimnasios WHERE clave_clientes = '$obj->centro'";
        $resultado = $conn->query($query);
        $bandera = 'false';
        //var_dump($resultado);
        if($resultado->num_rows == 1){

            $bandera = 'true';
            while($row = $resultado->fetch_assoc()) 
            {
                $baseD = $row["BaseDatos"];
                $nombreGym = $row['NombreGimnasio'];
            }               
            
        }else{
            $msg = "Verifica tus datos!";
        }

        //$array = ["centro"=>$msg, "usuario"=>"direct18_".$baseD,"passwd" => $query];direct18_PG
        $array[] = ["centro"=>$msg, "usuario"=>"direct18_".$baseD ,"passwd" => $query,"nombreGym" => $nombreGym]; 
        echo json_encode($array);
        $conn->close();
        break;

    case '1':
        $msg;

        $conn = new mysqli("progymcloud.com", "direct18", "L4LL4v3M@3str@",$obj->centro);
        $conn->set_charset("utf8");
        //$conn = new mysqli("directoriofitness.com.mx","direct18","L4LL4v3M@3str@",$obj->centro);
        
        $query = "SELECT * FROM socios WHERE idSocio = '$obj->usuario'";
        
        $resultado = $conn->query($query);
        $foto;
        $nombre;
        if($resultado->num_rows == 1){
            while($row = $resultado->fetch_assoc()) 
            {
               $passwd = $row["Contrasena"];
               $nombre = $row["Nombre"]." ".$row["Apellidos"];
               $foto = $row["Foto"];
            }
            
            if(password_verify($obj->passwd, $passwd)){
                $msg = "login";
            }else{
                $msg = "Verifica Tus Datos!";
            }
        }

        $array = ["centro"=>$msg, "usuario"=>$nombre, "passwd" => $obj->passwd];
        echo json_encode($array);
        $conn->close();
        break;
    case '2':
        $msg;

        $conn = new mysqli("progymcloud.com","direct18","L4LL4v3M@3str@",$obj->centro);
        $conn->set_charset("utf8");
        //$conn = new mysqli("directoriofitness.com.mx","direct18","L4LL4v3M@3str@",$obj->centro);
        
        $query = "SELECT * FROM socios WHERE idSocio = '$obj->usuario'";
       
        $resultado = $conn->query($query);
        $foto;
        $nombre;
        $activo;
        $sucursal;
        if($resultado->num_rows == 1){
            while($row = $resultado->fetch_assoc()) 
            {
               $passwd = $row["Contrasena"];
               $nombre = $row["Nombre"]." ".$row["Apellidos"];
               $foto = $row["Foto"];
               $activo = $row["Activo"];
               $sucursal = $row["sucursal_idSucursal"];
            }
            
            if(password_verify($obj->passwd, $passwd)){
                $msg = "login";
            }else{
                $msg = "Verifica Tus Datos!";
            }
        }
        if($foto == null){
            $foto = 'sin foto';
        }

        $array[] = ["centro"=>$msg, "usuario"=>$nombre, "passwd" => $obj->passwd, "foto" => $foto, "activo" => $activo, "sucursal"=> $sucursal];
        echo json_encode($array);
        $conn->close();
        break;
}



?>