<?php
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DMMYSQLG.php");
include('JQUERY.inc');
//incluímos la clase ajax
require ('xajax/xajax_core/xajax.inc.php');
//instanciamos el objeto de la clase xajax
$xajax = new xajax();

function agrega($form_entrada) {
    $ssql = "insert into fcomhues  (no_pers,no_hab,folio,nombre,comentarios,cvmesa,cvpunto,cvarea,cvmesero,usuario) values ('" . $form_entrada["txtpersona"] . "','" . $form_entrada["txthabit"] . "','" . $form_entrada["txtfolio"] . "','" . $form_entrada["txtnombre"] . "','" . $form_entrada["txtcomen"] . "','" . $_GET['ms'] . "','" . $_GET['pt'] . "','" . $_GET['ar'] . "','" . $form_entrada["txtmesero"] . "','" . $_SESSION['num_usu'] . "' )";
    if (mysqli_query($con ,$ssql)) {
        $salida = "Insertado correctamente";
    } else {
        $salida = "No se ha insertado. Este es el error: " . mysqli_error($con);
    }
}

//registramos la función creada anteriormente al objeto xajax
$xajax->registerFunction("agrega");
//El objeto xajax tiene que procesar cualquier petición
$xajax->processRequest();
include("DFJSISCI.inc");
?>
<html>
    <script type="text/javascript" src="ajax.js"></script>
    <script type="text/javascript" src="ajax2.js"></script>
    <script type='text/javascript'>
    </script>
    <? $xajax->printJavascript("xajax/"); ?>
    <head>
        <script type="text/javascript" language="javascript" src="DSSCRIPT.js"></script>
        <link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
        <?php
        require_once("DFJQUERY.inc");
        ?>

        <script type='text/javascript'>
            function abrir(URL) {
                window.open(URL, "ventana1", "width=230,height=260,scrollbars=NO,minimize=0")
            }
        </script>
        <script type='text/javascript'>
            function valida(url) {

                window.open(url, "ventana1", "width=230,height=260,scrollbars=NO,minimize=0")

            }
            $(document).keydown(function (tecla) {
                num = String.fromCharCode(tecla.keyCode)
                $('#u-' + num).trigger("click");

            });
        </script> 
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
    <body>
        <form name="form1" action="" method="post">
            <input name="txtmesero" type="hidden" value="<?php echo $msr['nparte1']; ?>">

            <div align="center">
                <table width="463" height="22" border='0'>
                    <tr>
                        <th colspan="8"> 
                    <div align="center">POSICION DE LA MESA: <?php
        $busm = mysqli_fetch_array(mysqli_query($con ,"SELECT np_desc1 FROM ctmesas WHERE nparte1='" . $_GET['ms'] . "'"));
        echo $busm['np_desc1'];
        ?></div>
                    </th></tr>
                </table>


                <table border="0" align="center">
                    <tr class="condes" style="border:double">
<?php
$_GET['ms'];
$res = mysqli_fetch_array(mysqli_query($con ,"select status from ctmesas where nparte1='" . $_GET['ms'] . "'"));
if ($res['status'] == 1) {
    $bcon = mysqli_fetch_array(mysqli_query($con ,"select count(*)  as valor from fpos where mesa='" . $_GET['ms'] . "' and status=1"));
    if ($bcon['valor'] != 0) { // si la consulta es uno okupado 
//		echo "ocupado";
    } else if ($bcon['valor'] == 0) { // si la consulta es 0 desocupado 
        $mod = mysqli_query($con ,"update ctmesas set status=0, fol_ven=0 where nparte1='" . $_GET['ms'] . "'");
        echo "<script type='text/javascript'>
				alert('MESA DESOCUPADA');
				envia2('PBR10000_PR.php','_self','form1');
				</script> ";
    } //								
//		echo $bcon['valor'];		
}
$txthabit=isset($_POST['txthabit'])?$_POST['txthabit']:"";
$_GET['mesero'];
$cuenta = $_GET['pos'];
$div = $cuenta / 2;
For ($i = 1; $i <= $cuenta; $i++) {
    ?>
                            <td class="condes" style="border:double"><div align="center">
                                    <input type='button' name='aceptar'  value='<?php echo $i; ?>' id='u-<?php echo $i; ?>' onClick="valida('CAL10000.php?mesero=<?php echo $_GET['mesero']; ?>&pt=<?php echo $_GET['pt']; ?>&ar=<?php echo $_GET['ar']; ?>&ms=<?php echo $_GET['ms']; ?>&hb=<?php echo $txthabit ?>&pos=<?php echo $i; ?>&cont=<?php echo $cuenta; ?>&tpo=4')">
                                </div></td> 			
    <?php
    if (($i % $div) == 0) {
        if ($i == $cuenta) {
            
        } else {
            ?> 
                                <tr style="border:none"> 
                                    <td class="condes" style="border:double" colspan="<?php echo $div ?>" align="center">
                                        <div align="center">
                                            <input type='button' name='aceptar' size='19' value='<?php
                                                   $busm = mysqli_fetch_array(mysqli_query($con ,"SELECT np_desc1 FROM ctmesas WHERE nparte1='" . $_GET['ms'] . "'"));
                                                   echo $busm['np_desc1'];
                                                   ?>'>
                                        </div>
                                    </td>  
                                </tr>	
            <?php
        }
    }
}
?> 
                    </tr>
                </table>

<?php
echo "";

//}
?>
                    <?php
                    /* For ($size=1;$size<=6;$size++)
                      {
                      echo"<font size=$size>Tamaño $size</font><br>n";
                      echo "<input type='button' name='aceptar' value='algo$size'>";
                      } */
                    ?>

            </div>
        </form>

    </body>
</html>
                <?php mysqli_close($con); ?>