<?php
require_once('../../Connections/odonto_connection1.php');
require_once('../../inc/utils.php');

//$q = intval($_GET['q']);
$q = $_GET['negocio'];
$s = $_GET['sucursal'];
$mozo = $_GET['mozo'];

$hostname_odonto_connection = "localhost";
$database_odonto_connection = "elindelc_mozo";
$username_odonto_connection = "elindelc_mozo0";
$password_odonto_connection = "Mozo-001";

$sql="SELECT id_avi,hora,mensaje,aviso,coment,sugerencias,puntaje,avisado,descrip,id_delivery,codigo,limpiado FROM avisos WHERE negocio = '".$q."' AND mozo = '".$mozo."' AND sucursal = '".$s."' AND limpiado = 0 ORDER BY id_avi DESC LIMIT 30";
$result0 = mysqli_query($odonto_connection,$sql);
$row_rs_ingreso0 = mysqli_fetch_assoc($result0);
$row_cnt = mysqli_num_rows($result0);

do{
	//echo "sonido";
	$hora1=explode(' ',$row_rs_ingreso0['hora']);
	$hora1=$hora1[1];
	$avisos .= $hora1.": ".$row_rs_ingreso0['aviso'].":\n";
	if(strlen($row_rs_ingreso0['mensaje']) > 2) $avisos .= eliminar_tildes($row_rs_ingreso0['mensaje'])."\n";
	$avisos .= eliminar_tildes($row_rs_ingreso0['descrip']);
	$avisos .= "\n";
	
}
while ($row_rs_ingreso0 = mysqli_fetch_assoc($result0));

$myObj->avisos = $avisos;

$sql1="SELECT hora FROM avisos WHERE negocio = '".$q."' AND mozo = '".$mozo."' AND sucursal = '".$s."' ORDER BY id_avi DESC LIMIT 1";
$result1 = mysqli_query($odonto_connection,$sql1);
$row_rs_ingreso1 = mysqli_fetch_assoc($result1);

$timer=date("Y-m-d H:i:s");
$time=explode(' ',$timer);
$time=$time[1];
	
$myObj->time = $time;
	
//$date = new DateTime();
//$date->modify('-2 hours');
//$date->modify('+10 minute');
//$date->modify('-30 second');
//echo $date->format('Y-m-d H:i:s');

$horaInicio = new DateTime($row_rs_ingreso1['hora']);
$horaTermino = new DateTime($timer);
$interval = $horaInicio->diff($horaTermino);
//echo $interval->format('%i %s');

if($interval->format('%s') < 10 && $interval->format('%i') == 0 && $interval->format('%h') == 3 && $row_cnt > 0) $myObj->sonido = "si";
else $myObj->sonido = 'no';

	echo json_encode($myObj);

mysqli_close($odonto_connection);

?>
