 <?php

if (isset($_SERVER['HTTP_ORIGIN'])) {
    header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
    header('Access-Control-Allow-Credentials: true');
    header('Access-Control-Max-Age: 86400'); // cache for 1 day
}

error_reporting(E_ERROR | E_PARSE);

$_SESSION['database'] = $_GET['database'];
$_SESSION['sala'] = $_GET['sala'];
$_SESSION['suc_id'] = $_GET['suc_id'];

include 'conn.php';
include 'funciones.php';

$jsonData = array();
$jsonTempData = array();

$sql = "select * from " . $_GET['database'] . ".json_mesas where sala = " . $_SESSION['sala'] . " and suc_id =" . $_SESSION['suc_id'] . "";

$qur = $connection->query($sql);

if ($_SESSION['codigo'] == "99") {

    $json->datos = "false";

} else {
    $json->datos = "true";

    while ($r = mysqli_fetch_assoc($qur)) {

        $jsonTempData = array();
        $jsonTempData['json_mesa'] = $r['json_mesa'];
        $jsonTempData['imgfondo'] = utf8_encode($r['imgfondo']);
        $jsonData[] = $jsonTempData;
    }
}

$json->jsonMesas = $jsonData;

print_r(json_encode($json));

@mysqli_close($connection);
?>