<?php	require_once('../preheader1.php'); // <-- this include file MUST go first before any HTML/output
$user=$_SESSION['MM_Username'];
if(!isset($user)) header("Location:" . "../../index.php?deslogeo");
require_once('../../Connections/odonto_connection1.php'); 

$query_rs_todos = "SELECT negocio,categ FROM `ingreso` WHERE user LIKE '$user'";
$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'];

if(isset($_GET['id_avi'])){$id_avi=$_GET['id_avi'];
$query_rs_todos = "UPDATE `avisos` SET `avisado` = '1' WHERE `avisos`.`id_avi` = $id_avi";
$rs_ingreso2 = mysqli_query($odonto_connection,$query_rs_todos) or die(mysqli_error());
}

$codigo=$_GET['codigo'];

$query_rs_todos = "SELECT * FROM `clientes`";
$rs_ingreso = mysqli_query($odonto_connection,$query_rs_todos) or die(mysqli_error());
$row_rs_ingreso = mysqli_fetch_assoc($rs_ingreso);

$hora=$row_rs_ingreso['hora'];


	#the code for the class
	include ('../ajaxCRUD.class.php'); // <-- this include file MUST go first before any HTML/output

    #this one line of code is how you implement the class
    ########################################################
    ##

    $tabla1 = new ajaxCRUD("MESAS", "mesas", "id_mesa", "../");

    ##
    ########################################################

    ## all that follows is setup configuration for your fields....
    ## full API reference material for all functions can be found here - http://ajaxcrud.com/api/
    ## note: many functions below are commented out (with //). note which ones are and which are not

    #i can define a relationship to another table
    #the 1st field is the fk in the table, the 2nd is the second table, the 3rd is the pk in the second table, the 4th is field i want to retrieve as the dropdown value
    #http://ajaxcrud.com/api/index.php?id=defineRelationship
    //$tabla1->defineRelationship("fkID", "tabla1Relationship", "pkID", "fldName", "fldSort DESC"); //use your own table - this table (tabla1Relationship) not included in the installation script

//$tabla1->defineRelationship("usuario","ingreso","user","doc");

//$tabla1->addAjaxFilterBox('celular',11);

    #i don't want to visually show the primary key in the table
    
	//$tabla1->displayAddFormTop();
	
	//$tabla1->showCSVExportOption();
	
	$tabla1->omitPrimaryKey();

    #the table fields have prefixes; i want to give the heading titles something more meaningful

	$tabla1->displayAs("codigo", "CODIGO");
	$tabla1->displayAs("mesa", "MESA");
	$tabla1->displayAs("descripcion", "PEDIDOS");
	$tabla1->displayAs("mozo", "ZONA");
	$tabla1->displayAs("mensaje", "MENSAJE A MESA");
	$tabla1->displayAs("ver", "PUBLICAR");

	$tabla1->setTextboxWidth('mensaje', 80);


	#set the textarea height of the longer field (for editing/adding)
    #http://ajaxcrud.com/api/index.php?id=setTextareaHeight
    //$tabla1->setTextareaHeight('fldLongField', 150);

   $tabla1->omitField("hash");
   $tabla1->omitField("sucursal");
   $tabla1->omitField("negocio");
   $tabla1->omitField("nombre");
   $tabla1->omitField("ocup");
   $tabla1->disallowEdit('codigo'); 
   $tabla1->disallowEdit('descripcion'); 
   //$tabla1->disallowEdit('mensaje'); 
   //$tabla1->disallowEdit('ver'); 
   $tabla1->disallowEdit('mesa'); 
//    $tabla1->omitFieldCompletely("mat");
 	//$tabla1->omitFieldCompletely('notas');
    #i could omit a field from being on the add form if I wanted
   
//$tabla1->setTextboxWidth('paciente', 20);

$tabla1->emptyTableMessage = "";
																					//$tabla1->turnOffAjaxADD();

//$tabla1->orderFields("paciente,nombre,dni,telefono,celular,obra,email,ficha,usuario");



    #i could set a field to accept file uploads (the filename is stored) if wanted
    //$tabla1->setFileUpload("fldField2", "uploads/");

//$tabla1->addValueOnInsert("hora", "NOW()");
//$tabla1->addValueOnInsert("negocio", $negocio);

//$tabla1->setInitialAddFieldValue ("nacionalidad", "Argentina");

    #i can have a field automatically populate with a certain value (eg the current timestamp)
    //$tabla1->addValueOnInsert("fldField1", "NOW()");
	$tabla1-> addWhereClause("WHERE (negocio = '$negocio' AND codigo = '$codigo')");
//	$tabla1->turnOffAjaxEditing();
	

$tabla1->addButtonToRow("Volver", "negocio_2.php" , "codigo");
	
    #i can use a where field to better-filter my table
    //$tabla1->addWhereClause("WHERE (fldField1 = 'test')");
    #i can order my table by whatever i want
 
// $tabla1->addOrderBy("ORDER BY id_pac DESC");
 
    #i can set certain fields to only allow certain values
    #http://ajaxcrud.com/api/index.php?id=defineAllowableValues
    //$allowableValues = array("si", "no");
    //$tabla1->defineAllowableValues("ver", $allowableValues);
	$tabla1->defineCheckbox("ver", "si", "no");
    //set field fldCheckbox to be a checkbox
    //$tabla1->defineCheckbox("fldCheckbox");

    #i can disallow deleting of rows from the table
    #http://ajaxcrud.com/api/index.php?id=disallowDelete
    $tabla1->disallowDelete();
    
$tabla1->hover_color = "#E9E8DC";
    $tabla1->setLimit(100);

//$tabla1->addMessage = "Paciente agregado correctamente";

$numRows = $tabla1->getNumRows();
$tabla1->disallowAdd();
//$tabla1->displayAddFormTop();

    #i can disallow adding rows to the table
    #http://ajaxcrud.com/api/index.php?id=disallowAdd
    //if($clinica=='clinica_28'){echo $tabla1->disallowAdd();}

    #i can add a button that performs some action deleting of rows for the entire table
    #http://ajaxcrud.com/api/index.php?id=addButtonToRow
  //  $tabla1->addButtonToRow("OK", "negocio_0.php", "$id_avi");

//$tabla1->formatFieldWithFunctionAdvanced('hora', 'formatfecha_fin');
//$tabla1->formatFieldWithFunctionAdvanced('aviso', 'formatfecha_fin');
//$tabla1->formatFieldWithFunctionAdvanced('descrip', 'formatfecha_fin');


function formatfecha_fin($data,$id)	
								{
$trozos = explode ("-", $data);
									$vemos=array();
									$vemos['0']=$trozos['2'];
									$vemos['1']=$trozos['1'];
									$vemos['2']=$trozos['0'];
									$data_c = implode('-', $vemos);

$carInfo = qr("SELECT * FROM avisos WHERE id_avi = $id");

$avisado = $carInfo['avisado'];
$hora = $carInfo['hora'];
$timer=date("Y-m-d H:i:s");

$horaInicio = new DateTime($hora);
$horaTermino = new DateTime($timer);
$interval = $horaInicio->diff($horaTermino);
//echo $interval->format('%i %s');
if($interval->format('%i') < '1' && $interval->format('%h') == '0' && $interval->format('%d') == '0' && $avisado != '1') {
	
//if($data < $fecha_estipulada2 && $status=="<font style='color:red'>PENDIENTE</font>")

	return "<span style='color:#75b257ff' class='parpadea text2'>$data</span>";
}

if($interval->format('%i') >= '1' && $interval->format('%i') < '2' && $interval->format('%h') == '0' && $interval->format('%d') == '0' && $avisado != '1') {
	
//if($data < $fecha_estipulada2 && $status=="<font style='color:red'>PENDIENTE</font>")

	return "<span style='color:#dbb326ff' class='parpadea text2'>$data</span>";
}

if($interval->format('%i') > '2'  && $interval->format('%h') == '0' && $interval->format('%d') == '0' && $avisado != '1' ) {
	
//if($data < $fecha_estipulada2 && $status=="<font style='color:red'>PENDIENTE</font>")

	return "<span style='color:#d84a2cff' class='parpadea text2'>$data</span>";
}

}



    #set the number of rows to display (per page)

	#set a filter box at the top of the table
    //$tabla1->addAjaxFilterBox('fldField1');

    #if really desired, a filter box can be used for all fields

    #i can set the size of the filter box
    #i can set the size of the filter box
    //$tabla1->setAjaxFilterBoxSize('fldField1', 3);

	#i can format the data in cells however I want with formatFieldWithFunction
	#this is arguably one of the most important (visual) functions
//	$tabla1->formatFieldWithFunction('codigo', 'makeBlue');

	$tabla1->formatFieldWithFunctionAdvanced('codigo', 'makeBlue');
	$tabla1->formatFieldWithFunctionAdvanced('mesa', 'makeBlue');
	$tabla1->formatFieldWithFunctionAdvanced('descripcion', 'makeBlue');
	$tabla1->formatFieldWithFunctionAdvanced('mozo', 'makeBlue');
	$tabla1->formatFieldWithFunctionAdvanced('mensaje', 'makeBlue');

//	$tabla1->formatFieldWithFunction('nombre', 'makeBold');
//	$tabla1->formatFieldWithFunction('celular', 'makeBold');
	//$tabla1->formatFieldWithFunction('paciente', 'makeBold');

	//$tabla1->modifyFieldWithClass("fldField1", "zip required"); 	//for testing masked input functionality
	//$tabla1->modifyFieldWithClass("fldField2", "phone");			//for testing masked input functionality

	//$tabla1->onAddExecuteCallBackFunction("mycallbackfunction"); //uncomment this to try out an ADD ROW callback function

	$tabla1->deleteText = "Borrar";
	$tabla1->addText= "AGREGAR";
	$tabla1->setCSSFile('greysuit.css');

	//$tabla1->addButtonText = "Register Me for this Event";

	#my self-defined functions used for formatFieldWithFunction
	function makeBold($val){
		if ($val == "") return "-----";
		return "<font style='font-size:10px'><b>$val</b></font>";
	}

	function makeBlue($val,$id){
		$carInfo = qr("SELECT ocup FROM mesas WHERE id_mesa = $id");
		$ocup = $carInfo['ocup'];
		if($ocup == 1)	return "<span style='color:#D8DE19;'>$val</span>";
		else return "<span style='color:#fff;'>$val</span>";
	}

	function myCallBackFunction($array){
		echo "THE ADD ROW CALLBACK FUNCTION WAS implemented";
		print_r($array);
	}
?>
<!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">

	<link rel="stylesheet" href="../../alertify/themes/alertify.core.css" />
	<link rel="stylesheet" href="../../alertify/themes/alertify.default.css" id="toggleCSS" />

<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0" />
<link rel="stylesheet" href="../../css_b/bootstrap.min.css" />

    <link rel="stylesheet" href="responsive/font-awesome/css/font-awesome.css" >

<script src="../../js_b/jquery-1.11.3.min.js"></script>
<script src="../../js_b/bootstrap.min.js"></script>
<script language="JavaScript" type="text/javascript">
/*Script del Reloj */
function actualizaReloj() {
/* Capturamos la Hora, los minutos y los segundos */
marcacion = new Date()
/* Capturamos la Hora */
Hora = marcacion.getHours()
/* Capturamos los Minutos */
Minutos = marcacion.getMinutes()
/* Capturamos los Segundos */
Segundos = marcacion.getSeconds()
/*variable para el apóstrofe de am o pm*/
dn = "a.m"
if (Hora > 12) {
dn = "p.m"
Hora = Hora - 12
}
if (Hora == 0)
Hora = 12
/* Si la Hora, los Minutos o los Segundos son Menores o igual a 9, le añadimos un 0 */
if (Hora <= 9) Hora = "0" + Hora
if (Minutos <= 9) Minutos = "0" + Minutos
if (Segundos <= 9) Segundos = "0" + Segundos
/* Termina el Script del Reloj */

/*Script de la Fecha */

var Dia = new Array("Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sabado", "Domingo");
var Mes = new Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", 
"Octubre", "Noviembre", "Diciembre");
var Hoy = new Date();
var Anio = Hoy.getFullYear();
var Fecha = Dia[Hoy.getDay()] + ", " + Hoy.getDate() + " de " + Mes[Hoy.getMonth()] + " de " + Anio + ". ";

/* Termina el script de la Fecha */

/* Creamos 2 variables para darle formato a nuestro Script */
var Script, Total

/* En Reloj le indicamos la Hora, los Minutos y los Segundos */
Script = Fecha + Hora + ":" + Minutos + ":" + Segundos + " " + dn

/* En total Finalizamos el Reloj uniendo las variables */
Total = Script

/* Capturamos una celda para mostrar el Reloj */
document.getElementById('Fecha_Reloj').innerHTML = Total

/* Indicamos que nos refresque el Reloj cada 1 segundo */
setTimeout("actualizaReloj()", 1000)
} </script>

	<style>
		.alertify-log-custom {
			background: blue;
		}
	</style>
	
</head>
<body onload="actualizaReloj()" style="background-color:#0D1749"
<?php /*
$query_rs_todos = "SELECT * FROM `tabla1` WHERE `clinica` like '$clinica' AND `usuario` like '$doctor1'";
$rs_ingreso72 = mysqli_query($odonto_connection,$query_rs_todos) or die(mysql_error());
$row_rs_ingreso72 = mysqli_fetch_assoc($rs_ingreso72);

	$totalRows_rs_ingreso72 = mysqli_num_rows($rs_ingreso72);
	
	if($totalRows_rs_ingreso72==0){
		echo "onload=\"miaverde('Bienvenido $doctor1'),mia('Agrega tu primer paciente')\"";
		} */
		?>
		/>
	
	<?php	 require_once('menu.php');?>
	<div class="row">
		<div class="col">
			<HR>
		</div>
	</div>
	<div class="container-fluid" style="color:white">
		<div class="row justify-content-center">
			<div class="col-sm-4">
				<a href="negocio_2.php" class="btn btn-success" role="button" style="width:20rem"><b><span class='glyphicon glyphicon-arrow-left'></span> Volver</b></a></p>
			</div>
		</div>
		<div class="row text-center" >
			<div class="col"><b>
				<span style="border-image: initial; border: 2px solid white;">Mensaje a Mesa</span>
			</b>
			</div>
		</div>
		
	<?php	 $tabla1->showTable();?>
			</div>
</div>

<style>
.text {
  font-size:18px;
  font-family:helvetica;
  font-weight:bold;
  color:#71d90b;
  text-transform:uppercase;
}
.parpadea {
  
  animation-name: parpadeo;
  animation-duration: 1s;
  animation-timing-function: linear;
  animation-iteration-count: infinite;

  -webkit-animation-name:parpadeo;
  -webkit-animation-duration: 1s;
  -webkit-animation-timing-function: linear;
  -webkit-animation-iteration-count: infinite;
}

@-moz-keyframes parpadeo{  
  0% { opacity: 1.0; }
  50% { opacity: 0.0; }
  100% { opacity: 1.0; }
}

@-webkit-keyframes parpadeo {  
  0% { opacity: 1.0; }
  50% { opacity: 0.0; }
   100% { opacity: 1.0; }
}

@keyframes parpadeo {  
  0% { opacity: 1.0; }
   50% { opacity: 0.0; }
  100% { opacity: 1.0; }
}
</style>

<script src="../../alertify/lib/alertify.min.js"></script>
	<script>
		function reset () {
			$("#toggleCSS").attr("href", "../../alertify/themes/alertify.default.css");
			alertify.set({
				labels : {
					ok     : "OK",
					cancel : "Cancel"
				},
				delay : 5000,
				buttonReverse : false,
				buttonFocus   : "ok"
			});
		}
		
									function mia(data){
									var mensa= data;
									alertify.success(mensa);}
									
									function miaverde(data){
									var mensa= data;
									alertify.error(mensa);}

		// ==============================
		// Standard Dialogs
		$("#alert").on( 'click', function () {
			reset();
			alertify.alert("This is an alert dialog");
			return false;
		});

		$("#confirm").on( 'click', function () {
			reset();
			alertify.confirm("This is a confirm dialog", function (e) {
				if (e) {
					alertify.success("You've clicked OK");
				} else {
					alertify.error("You've clicked Cancel");
				}
			});
			return false;
		});

		$("#prompt").on( 'click', function () {
			reset();
			alertify.prompt("This is a prompt dialog", function (e, str) {
				if (e) {
					alertify.success("You've clicked OK and typed: " + str);
				} else {
					alertify.error("You've clicked Cancel");
				}
			}, "Default Value");
			return false;
		});

		// ==============================
		// Ajax
		$("#ajax").on("click", function () {
			reset();
			alertify.confirm("Confirm?", function (e) {
				if (e) {
					alertify.alert("Successful AJAX after OK");
				} else {
					alertify.alert("Successful AJAX after Cancel");
				}
			});
		});

		// ==============================
		// Standard Dialogs
		$("#notification").on( 'click', function () {
			reset();
			alertify.log("Standard log message");
			return false;
		});

		$("#success").on( 'click', function () {
			reset();
			alertify.success("Success log message");
			return false;
		});

		$("#error").on( 'click', function () {
			reset();
			alertify.error("REVISAR MATERIALES");
			return false;
		});

		// ==============================
		// Custom Properties
		$("#delay").on( 'click', function () {
			reset();
			alertify.set({ delay: 10000 });
			alertify.log("Revisar Materiales");
			return false;
		});

		$("#forever").on( 'click', function () {
			reset();
			alertify.log("Will stay until clicked", "", 0);
			return false;
		});

		$("#labels").on( 'click', function () {
			reset();
			alertify.set({ labels: { ok: "Accept", cancel: "Deny" } });
			alertify.confirm("Confirm dialog with custom button labels", function (e) {
				if (e) {
					alertify.success("You've clicked OK");
				} else {
					alertify.error("You've clicked Cancel");
				}
			});
			return false;
		});

		$("#focus").on( 'click', function () {
			reset();
			alertify.set({ buttonFocus: "cancel" });
			alertify.confirm("Confirm dialog with cancel button focused", function (e) {
				if (e) {
					alertify.success("You've clicked OK");
				} else {
					alertify.error("You've clicked Cancel");
				}
			});
			return false;
		});

		$("#order").on( 'click', function () {
			reset();
			alertify.set({ buttonReverse: true });
			alertify.confirm("Confirm dialog with reversed button order", function (e) {
				if (e) {
					alertify.success("You've clicked OK");
				} else {
					alertify.error("You've clicked Cancel");
				}
			});
			return false;
		});

		// ==============================
		// Custom Log
		$("#custom").on( 'click', function () {
			reset();
			alertify.custom = alertify.extend("custom");
			alertify.custom("I'm a custom log message");
			return false;
		});

		// ==============================
		// Custom Themes
		$("#bootstrap").on( 'click', function () {
			reset();
			$("#toggleCSS").attr("href", "../themes/alertify.bootstrap.css");
			alertify.prompt("Prompt dialog with bootstrap theme", function (e) {
				if (e) {
					alertify.success("You've clicked OK");
				} else {
					alertify.error("You've clicked Cancel");
				}
			}, "Default Value");
			return false;
		});
	</script>

</body>
</html>


<script type="text/javascript">

function showUser(str) {
<?php 
require_once('../../Connections/odonto_connection1.php'); 

$query_rs_todos = "SELECT id_avi FROM `avisos` WHERE `negocio` like '$negocio'";
$rs_ingreso = mysqli_query($odonto_connection,$query_rs_todos) or die(mysqli_error());
$row_rs_ingreso = mysqli_fetch_assoc($rs_ingreso);
$row_cnt_orig = mysqli_num_rows($rs_ingreso);

?>	
	var negocio = "<?php echo $negocio;?>";
	var orig = "<?php echo $row_cnt_orig;?>";

	if (str == "") {
        document.getElementById("txtHint").innerHTML = "";
        return;
    } else { 
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("txtHint").innerHTML = this.responseText;
				var vemos = this.responseText;
if(vemos.indexOf("aqui") > -1){myFunction();}
		}
        };
        //xmlhttp.open("GET","getuser.php?q="+str,true);
        xmlhttp.open("GET","./getuser_mesas.php?q="+negocio+"&r="+orig,true);
        xmlhttp.send();

		
    }
}

function myFunction() {
  window.open("negocio_2.php" , '_parent');
}

 </script>
 