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

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

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

if ($_SESSION['opcion'] == "0") {
    $sql = "delete from " . $_GET['database'] . ".mesasPuesto where sala = " . $_SESSION['sala'] . " and mesa = " . $_SESSION['mesa'] . " and puesto = " . $_SESSION['puesto'] . " and suc_id = " . $_SESSION['suc_id'] . "";
}

if ($_SESSION['opcion'] == "1") {
    $sql = "delete from " . $_GET['database'] . ".mesasPuesto where sala = " . $_SESSION['sala'] . " and mesa = " . $_SESSION['mesa'] . " and suc_id = " . $_SESSION['suc_id'] . "";
}

if ($_SESSION['opcion'] == "2") {
    $sql = "delete from " . $_GET['database'] . ".mesasPuesto where sala = " . $_SESSION['sala'] . "";
}

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

if ($_SESSION['codigo'] == "99") {
    $json->datos = "false";
} else {
    $json->datos = "true";
}

print_r(json_encode($json));

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