<?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());
}

$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("PRECIOS", "precios", "id_pre", "../");

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

    ## 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("anteced3", "MEDICACION HABITUAL:");


	#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("sucursal");
   $tabla1->omitField("negocio");
   $tabla1->omitField("nombre");
   $tabla1->disallowEdit('cod_pre'); 

//    $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')");
//	$tabla1->turnOffAjaxEditing();
	

//$tabla1->addButtonToRow("SMS", "../../../../dental/ajax/examples/salutaciones_celu_negocio_0.php" , "celular");


	
    #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("Allowable Value1", "Allowable Value2", "Dropdown Value", "CRUD");
    //$tabla1->defineAllowableValues("fldCertainFields", $allowableValues);

    //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->setLimit(20);

//$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('fldField1', '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('cuscosky.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){
		return "<span style='color: blue;'>$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" />
	
<?php require_once('../../inc/bootstrap.php');?>

</head>
<body style="background-color:#0D1749"/>
	
	<?php	 require_once('menu.php');?>
	<br>
	<?php	 require_once('botones.php');?>
	
		<div class="container-fluid text-center" style="color:white">
		<div class="row">
			<div class="col">
				<h2>AppMoviles (sólo para el Staff):</h2><p>
			</div>
		</div>
		
		<div class="row" >
			<div class="col md-6" >
				<b>App Mozo:</b><p>
				<b>Leer Codigo QR o Acceder al siguiente link: <a href='http://ponderzone.com/appmozo/<?php echo $negocio;?>/pondermozo.apk'>http://ponderzone.com/appmozo/<?php echo $negocio;?>/pondermozo.apk</a></b><p>
				<img src="../../../appmozo/<?php echo $negocio?>/frame_mozo.png"><p>
		</div>
		<br><br><br><br><br><br><br>
		<div class="col md-6" >
				<b>App Cocina:</b><p>
				<b>Leer Codigo QR o Acceder al siguiente link: <a href='http://ponderzone.com/appcocina/<?php echo $negocio;?>/pondercocina.apk'>http://ponderzone.com/appcocina/<?php echo $negocio;?>/pondercocina.apk</a></b><p>
				<img src="../../../appcocina/<?php echo $negocio?>/frame_cocina.png"><p>
		</div>
		<br><br><br><br><br><br><br>
		<div class='col md-6' >
				<?php 
				if($categ=='cat1'){
				echo "<b>AppBar (Encargado o Dueño):</b><p>";
				echo "<b>Leer Codigo QR o Acceder al siguiente link: <a href='http://ponderzone.com/appmozo/$negocio/ponderbar.apk'>http://ponderzone.com/appbar/$negocio/ponderbar.apk</a></b><p>";
				echo "<img src='../../../appbar/$negocio/frame.png'><p>";
				}?>
				
		</div>
		<br><br><br><br><br><br><br>
		</div>
		</div>
		
</div>


</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){startFlashTitle('nuevo PEDIDO');}
		}
        };
        //xmlhttp.open("GET","getuser.php?q="+str,true);
        xmlhttp.open("GET","./getuser.php?q="+negocio+"&r="+orig,true);
        xmlhttp.send();

		
    }
}


  (function () {
   var titleOriginal = document.title;   
   var intervalBlinkTitle = 0;
 
   // Inicia el parpadeo del título la página
   window.startFlashTitle = function (newTitle) {       
       if(intervalBlinkTitle == 0){
        document.title = 
         (document.title == titleOriginal) ? newTitle : titleOriginal;           
 
        intervalBlinkTitle = setInterval(function (){
         document.title = 
          (document.title == titleOriginal) ? newTitle : titleOriginal;           
        }, 800);
    } 
   };
 
   // Para el parpadeo del título de la página   
   // Restablece el título
   window.stopFlashTitle = function () {       
       clearInterval(intervalBlinkTitle);
       intervalBlinkTitle = 0;
       document.title = titleOriginal;
   };
  }());
 </script>
 