<?php

$json = file_get_contents('php://input');   
    $obj = json_decode($json);
    $id = $obj->flag;
    // Returns a Json
    header('Content-Type: application/json');
    date_default_timezone_set('America/Mexico_City');
switch($id){
    
    case '0':
        $conn = new mysqli("directoriofitness.com.mx", "direct18", "L4LL4v3M@3str@",$obj->bd);
        $conn -> set_charset("utf8");
        $dayFilter;
        $array;
        switch($obj->filter){
            case '1':
                $dayFilter = 15;
                break;
            case '2':
                $dayFilter = 30;
                break;

            case '3':
                $dayFilter = 60;
                break;
            case '4':
                $dayFilter = 180;
                break;


        }
        
        $query = "SELECT a.idSocio, concat(s.Nombre, ' ', s.Apellidos) AS nombre, DATE_FORMAT(a.FechaHora, '%d/%m/%Y %H:%i:%s') AS fecha, 
        su.NombreSucursal, a.Puerta FROM sucursal su JOIN asistenciaservicio2 a ON su.idSucursal = a.idSucursal JOIN socios s 
        ON a.idSocio = s.idSocio WHERE a.idSocio = '$obj->id_cliente' AND (a.FechaHora >= DATE_SUB(NOW(), INTERVAL $dayFilter DAY) AND a.FechaHora <= NOW()) 
        ORDER BY a.FechaHora DESC";
        $resultado = $conn->query($query);
        
        if($resultado->num_rows > 0){
            while($row = $resultado->fetch_assoc()){
                $array[] = $row;
            }
            echo json_encode($array);
        }else{
            echo 'vacio';
        }
        
        $conn->close();
        break;
}

?>