 <?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['mesa'] = $_GET['mesa'];
$_SESSION['suc_id'] = $_GET['suc_id'];

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

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

$sql = "select m.puesto, o.po_id from " . $_GET['database'] . ".mesasPuesto m left outer join " . $_GET['database'] . ".tmp_producto_op o on m.sala = o.sala and m.mesa = o.mesa and m.puesto = o.ubicacion and m.suc_id = o.suc_id where m.suc_id = "
    . $_SESSION['suc_id'] . " and m.mesa = " . $_SESSION['mesa'] . " and m.sala = " . $_SESSION['sala'] . " group by m.puesto";

//echo "aqui".$sql;
$qur = $connection->query($sql);

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

    $json->datos = "false";

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

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

        $jsonTempData = array();
        $jsonTempData['puesto'] = $r['puesto'];
        $jsonTempData['autoinc'] = $r['po_id'];
        $jsonData[] = $jsonTempData;
    }

}

$json->jsonpuestos = $jsonData;
print_r(json_encode($json));

$qur = null;
@mysqli_close($connection);
?>