<?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'); 

$codigo = $_GET['codigo'];	

$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 id_avi = $id_avi";
$rs_ingreso2 = mysqli_query($odonto_connection,$query_rs_todos) or die(mysqli_error());
}

$query_rs_todos = "SELECT mesa FROM mesas WHERE codigo = '$codigo'";
$rs_ingreso = mysqli_query($odonto_connection,$query_rs_todos) or die(mysqli_error());
$row_rs_ingreso = mysqli_fetch_assoc($rs_ingreso);

$mesa=$row_rs_ingreso['mesa'];


	#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("Pedidos", "pedidos", "id_ped", "../");

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

    ## 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->defineRelationship("mesa","mesas","codigo","mesa");

$tabla1->defineRelationship("cod_pre","precios","id_pre","menu");

//$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("cod_pre", "Item");
	$tabla1->displayAs("recibido", "Cantidad");
	
	$tabla1->disallowEdit('cod_pre'); 

	//$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("negocio");
  $tabla1->omitField("sucursal");
  $tabla1->omitField("cant");
  $tabla1->omitField("nuevo");
  $tabla1->omitField("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 = "Nada para mostrar en el pedido";

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

//$tabla1->addButtonToRow("Limpiar", "auxi_limpiar.php" , "codigo");

// $tabla1->addOrderBy("ORDER BY id_pac DESC");

$allowableValues = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
$tabla1->defineAllowableValues("recibido", $allowableValues);

#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');


	

    #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->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" />

<?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="row" ><b>
<span style="border-image: initial; border: 2px solid white;">MESAS Y MOZOS</span>
</b><p>
		</div> -->

	<div class="container-fluid text-center">
<?php	

$q = "SELECT cod_pre,recibido FROM pedidos WHERE mesa = '$codigo'";
$rs = mysqli_query($odonto_connection,$q) or die(mysqli_error());
$row = mysqli_fetch_assoc($rs);
$num_rows = mysqli_num_rows($rs);

if($num_rows != 0)
	{
	do{
		$cod_pre = $row['cod_pre'];
		$q0 = "SELECT menu FROM precios WHERE id_pre = $cod_pre";
		$rs0 = mysqli_query($odonto_connection,$q0) or die(mysqli_error());
		$row0 = mysqli_fetch_assoc($rs0);

		$pedido_actual .= $row['recibido']." ".$row0['menu']."+";
	} while($row = mysqli_fetch_assoc($rs));
}

?>
		<div class="row">
			<div class="col">
				<h5>Pedido Actual:  <?php echo $pedido_actual;?></h5>
			</div>
		</div>
		
		<div class="row">
			<div class="col">
				<h3><?php
				if(!$_GET[modif]) echo "Modificación Pedido mesa".$mesa;
				else echo "Se modificó correctamente la mesa ".$mesa;
				?>
				</h3>
			</div>
		</div>
		<div class="row">
			<div class="col">
			<?php $tabla1->showTable();?>
			<a href="negocio_8_modif.php?codigo=<?php echo $codigo;?>" class="btn btn-primary">Ok <i class="fas fa-thumbs-up"></i></a>
			</div>
		</div>
	</div>
