<?php	
	if(isset($_GET[negocio])){
		$sacar_menu = 1;
		$negocio = $_GET[negocio];
		require_once('../../Connections/odonto_connection1.php'); 
		$query_rs_todos = "SELECT user FROM ingreso WHERE negocio LIKE '$negocio' LIMIT 1";
		$rs_ingreso0 = mysqli_query($odonto_connection,$query_rs_todos) or die(mysqli_error());
		$row_rs_ingreso0 = mysqli_fetch_assoc($rs_ingreso0);
		$user=$row_rs_ingreso0[user];
	}

require_once('../../Connections/odonto_connection1.php'); 

$query_rs_todos = "SELECT categ,negocio FROM ingreso WHERE user LIKE '$user' LIMIT 1";
$rs_ingreso0 = mysqli_query($odonto_connection,$query_rs_todos) or die(mysqli_error());
$row_rs_ingreso0 = mysqli_fetch_assoc($rs_ingreso0);
$categ=$row_rs_ingreso0['categ'];
$negocio=$row_rs_ingreso0['negocio'];

$q = "SELECT id_datos FROM datos WHERE negocio LIKE '$negocio' LIMIT 1";
$rs = mysqli_query($odonto_connection,$q) or die(mysqli_error());
$row = mysqli_fetch_assoc($rs);
$id_datos = $row['id_datos'];

if(isset($_GET['confirmated']))
{
	$existe = 0;
	$id_delivery = $_GET['confirmated'];//es el id_delivery
	
	$q = "SELECT confiable FROM delivery WHERE id_delivery LIKE '$id_delivery' LIMIT 1";
	$rs = mysqli_query($odonto_connection,$q) or die(mysqli_error());
	$row = mysqli_fetch_assoc($rs);
	$confiable = $row['confiable'];
	if($confiable) {
		$confiable_decod = json_decode($confiable);
		foreach($confiable_decod as $clave => $valor){
			if($valor == $id_datos) $existe = 1;			
		}
	}
	else $confiable_decod = array();
	
	if(!$existe){
		
		$confiable_decod[] = $id_datos;
		$json=json_encode($confiable_decod);
	
		$sql = "UPDATE delivery SET confiable = '$json' WHERE id_delivery = '$id_delivery'";
		$rs = mysqli_query($odonto_connection, $sql) or die(mysqli_error());
	}
}

if(isset($_GET['no_confiable']))
{
	$existe = 0;
	$id_delivery = $_GET['confirmated'];//es el id_delivery
	
	$q = "SELECT confiable FROM delivery WHERE id_delivery LIKE '$id_delivery' LIMIT 1";
	$rs = mysqli_query($odonto_connection,$q) or die(mysqli_error());
	$row = mysqli_fetch_assoc($rs);
	$confiable = $row['confiable'];
		$confiable_decod = json_decode($confiable);
		foreach($confiable_decod as $clave => $valor){
			if($valor == $id_datos) unset($confiable_decod[$clave]);
		}

		$json=json_encode($confiable_decod);
		$sql = "UPDATE delivery SET confiable = '$json' WHERE id_delivery = '$id_delivery'";
		$rs = mysqli_query($odonto_connection, $sql) or die(mysqli_error());

}

if(isset($_GET['id_avi']))
{
	$id_avi=$_GET['id_avi'];
	$codigo=$_GET['codigo'];

	$q = "UPDATE avisos SET avisado = 1,hora_avisado = CURRENT_TIMESTAMP WHERE id_avi = $id_avi";
	$rs = mysqli_query($odonto_connection,$q) or die(mysqli_error());
	
	$query_rs_todos = "DELETE FROM pedidos WHERE mesa = '$codigo' ";
	$rs_ingreso0 = mysqli_query($odonto_connection,$query_rs_todos) or die(mysqli_error());
		
	$q = "UPDATE mesas SET ocup = '0',descripcion = '' WHERE codigo LIKE '$codigo'";
	$rs= mysqli_query($odonto_connection,$q) or die("Error en $q");
	
}


?>
<!DOCTYPE HTML>
<html>
<head>
<!--<meta http-equiv="refresh" content="7" charset="UTF-8"> -->
<meta charset="UTF-8">
<title>PonderZone</title>
<link rel="icon" href="../../pondercode.jpg">

<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0" />

<?php require_once('../../inc/bootstrap.php');?>

<link href='https://fonts.googleapis.com/css?family=Handlee' rel='stylesheet'>

<style>
body{
	background-color:#0D1749;
	background-image:none;
	color:white;
	font-size:2rem;
}

</style>

</head>
<body>

<?php if(!$sacar_menu) require_once('menu.php');?>
<div class="row">
	<div class="col text-center">
		<hr style="background-color:white">
		<h2>Elige tu zona:</h2>
		<form action="negocio_0.php?negocio=<?php echo $negocio;?>" method="post">
		<div class="form-group">
		  <select class="form-control" style="font-size:2rem" id="mozo" name="mozo">
			<option>1</option>
			<option>2</option>
			<option>3</option>
			<option>4</option>
			<option>5</option>
			<option>6</option>
			<option>7</option>
			<option>8</option>
			<option>9</option>
			<option>10</option>
			<option>11</option>
			<option>12</option>
			<option>13</option>
			<option>14</option>
			<option>15</option>
		  </select>
		</div>
		<input type="submit" id="mozo_submit" name="mozo_submit" value="OK">
		</form>
	<hr>	
	<a href="index_precios_mozos.php?negocio=<?php echo $negocio;?>" target="_blank" class="btn btn-outline-light">Carta</a>
	</div>
</div>

</body>
</html>


