<?php

$json = file_get_contents('php://input');   
$obj = json_decode($json);
$id = $obj->flag;
// Returns a Json
header('Content-Type: application/json');
    
    switch($id){
        case '0': //keys Stripe
        
        $array;
        $conn = new mysqli("directoriofitness.com.mx","direct18","L4LL4v3M@3str@",'direct18_ProGymCloud');
        $conn -> set_charset("utf8");
        
        $bd = explode('_',$obj->bd);
        
        $query = "SELECT info_stripe.*, info_plataformaspago.activar_stripe 
                    FROM info_stripe 
                INNER JOIN gimnasios ON info_stripe.gimnasio_idGimnasio = gimnasios.idGimnasio 
                INNER JOIN info_plataformaspago ON info_plataformaspago.gimnasio_idGimnasio = gimnasios.idGimnasio 
                WHERE gimnasios.BaseDatos = '$bd[1]' AND info_stripe.sucursal_idSucursal = $obj->sucursal";
            $resul = $conn->query($query);
            //var_dump($resul);
            if(mysqli_num_rows($resul) > 0){
                $array[] = $resul->fetch_assoc();
            }else{
                $array[] = ['secret_id' => 'not', 'publishable_key' => 'not'];
                
            }
            echo json_encode($array);
            $conn->close();
        break;
        
        case '1': //keys Payu
            $bd = explode('_',$obj->bd);
            $array;
            $conn = new mysqli("directoriofitness.com.mx","direct18","L4LL4v3M@3str@",'direct18_ProGymCloud');
            $conn -> set_charset("utf8");
            $query = "SELECT info_payu.*, info_plataformaspago.activar_payu
                        FROM info_payu 
                    INNER JOIN gimnasios ON info_payu.id_gym = gimnasios.idGimnasio 
                    INNER JOIN info_plataformaspago ON info_plataformaspago.gimnasio_idGimnasio = gimnasios.idGimnasio 
                    WHERE gimnasios.BaseDatos = '$bd[1]' AND info_payu.sucursal_idSucursal = $obj->sucursal";
                $resul = $conn->query($query);
                //var_dump($resul);
                if($resul->num_rows > 0){
                    $row = $resul->fetch_assoc();
                    $array[] = $row;
                    echo json_encode($array);
                }else{
                    $array[] = ['api_login' => 'not', 'api_key' => 'not', 'merchant_id'=> '12345'];
                    echo json_encode($array);
                }
            $conn->close();
            break;
    }
    
    

?>