<?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,sucursal 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];
$sucursal=$row_rs_ingreso0[sucursal];

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 hora 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("Item", "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("id_categ", "categorias", "id_categ", "categoria", "id_categ ASC", 0, "WHERE negocio LIKE '$negocio'"); //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


$aux1="../../../imagenes_productos/".$negocio."/";
$aux2="../../../imagenes_productos/".$negocio."/";
$allowedExts = array("png", "jpg", "jpeg", "gif", "bmp", "tif", "tiff","txt");
$tabla1->setFileUpload("imagen", $aux1, $aux2,$allowedExts);
$tabla1->appendUploadFilename("id_pre");
$tabla1->formatFieldWithFunction('imagen', 'makeImg');

function makeImg($val)
{
	global $negocio;
	if($val) return "<img src=\"../../../imagenes_productos/".$negocio."/$val\" width=\"100\" height=\"100\" />";
	else return "<img src=\"../../../imagenes_productos/sin_imagen.png\" width=\"100\" height=\"100\" />";
}


	$tabla1->displayAs("id_categ", "Categoria");
	$tabla1->displayAs("menu", "Descripcion");
	$tabla1->displayAs("observa", "Nota");
	$tabla1->displayAs("precio", "Precio");
	$tabla1->displayAs("publicar", "Local");
	$tabla1->displayAs("delivery", "Delivery");


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

   //$tabla1->omitFieldCompletely("id_categ");
   $tabla1->omitFieldCompletely("categoria");
   $tabla1->omitFieldCompletely("sucursal");
   $tabla1->omitFieldCompletely("negocio");
   //$tabla1->omitField("observa");
   
//    $tabla1->omitFieldCompletely("mat");
 	//$tabla1->omitFieldCompletely('notas');
    #i could omit a field from being on the add form if I wanted
   
$tabla1->setTextboxWidth('menu', 50);
//$tabla1->setTextboxWidth('nota', 100);

$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("negocio", "$negocio");
$tabla1->addValueOnInsert("sucursal", "$sucursal");
//$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_categ ASC");
 
    #i can set certain fields to only allow certain values
    #http://ajaxcrud.com/api/index.php?id=defineAllowableValues
    
$query_rs_todos = "SELECT id_categ,categoria FROM `categorias` WHERE negocio LIKE '$negocio'";
$rs_ingreso55 = mysqli_query($odonto_connection,$query_rs_todos) or die(mysqli_error());
$row_rs_ingreso55 = mysqli_fetch_assoc($rs_ingreso55);
$allowableValues = array();

do{   
	$id_categ = $row_rs_ingreso55['id_categ'];
	$categoria = $row_rs_ingreso55['categoria'];
	
	$allowableValues[] = array(0 => "$id_categ", 1 => "$categoria");

	} while($row_rs_ingreso55 = mysqli_fetch_assoc($rs_ingreso55));

	$tabla1->defineAllowableValues("id_categ", $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(700);

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

$numRows = $tabla1->getNumRows();
//$tabla1->disallowAdd();
//$tabla1->displayAddFormTop();
/*
$allowableValues = array("si", "no");
$tabla1->defineAllowableValues("publicar", $allowableValues);
*/
$tabla1->defineCheckbox("publicar", "si", "no");
$tabla1->defineCheckbox("delivery", "si", "no");
//$tabla1->showCheckboxAll('publicar',"si", "no"); 

    #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->displayAddFormTop();

	$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){
		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">

<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">
	<div class="row">
		<div class="col">
			<a href="negocio_3_categorias.php" class="btn btn-outline-light btn-sm" role="button" style="width:15rem"><b><span class='glyphicon glyphicon-th-large'></span> Ver Categorias</b></a></p>
		</div>
	</div>
	<div class="row">
		<div class="col">
				<?php $tabla1->showTable();?>
		</div>
	</div>
</div>

</body>
</html>

