Пример #1
0
function load()
{
    $id_plat_cat = array();
    $platos_cat = array();
    $platos_obj = array();
    $platos_obj_r = array();
    $platos_rango = array();
    $i = 0;
    $j = 0;
    $k = 0;
    if (!isset($_POST) || !isset($_SESSION['user_bd13']) || $_SESSION['user_bd13']->rol != 1) {
        header('Location: ../login.php');
        exit;
    } else {
        $db = new phpDB();
        $db->connect();
        if (isset($_POST['filtro_busqueda_categ'])) {
            $categoria = $_POST['categoria'];
            $query = "SELECT * FROM categoria WHERE nombre_categoria LIKE '%{$categoria}%'";
            $db->exec($query, array());
            $rs1 = $db->fobject();
            if (is_null($rs1)) {
                echo '<div class="alert alert-info"> No hay resultados para la búsqueda</div>';
                return;
            } else {
                do {
                    $id_plat_cat[$i] = $rs1->id_categoria;
                    $i++;
                } while ($db->nextRow());
                foreach ($id_plat_cat as $key => $value) {
                    $query2 = "SELECT * FROM plato WHERE id_categoria = '{$value}'";
                    $db->exec($query2, array());
                    do {
                        $rs2 = $db->fobject();
                        $platos_cat[$k] = $rs2->nombre_plato;
                        $platos_obj[$k] = $rs2;
                        $k++;
                    } while ($db->nextRow());
                }
            }
        }
        if (isset($_POST['filtro_busqueda_rango'])) {
            $rango_start = $_POST['start'];
            $rango_end = $_POST['end'];
            if ($rango_start > $rango_end || $rango_start == 0 && $rango_end == 0) {
                echo '<div class="alert alert-danger"> Se ingreso mal los rangos de búsqueda</div>';
                return;
            }
            $query3 = "SELECT * FROM plato WHERE precio BETWEEN {$rango_start} AND {$rango_end}";
            $db->exec($query3, array());
            do {
                $rs3 = $db->fobject();
                $platos_rango[$j] = $rs3->nombre_plato;
                $platos_obj_r[$j] = $rs3;
                $j++;
            } while ($db->nextRow());
        }
        if (isset($_POST['filtro_busqueda_categ']) && isset($_POST['filtro_busqueda_rango'])) {
            $result = array();
            $indice = 0;
            foreach ($platos_obj as $key => $value) {
                foreach ($platos_obj_r as $key2 => $value2) {
                    if ($value->id_plato == $value2->id_plato) {
                        $result[$indice] = $value;
                        $indice++;
                    }
                }
            }
            //$result = array_intersect($platos_obj, $platos_obj_r);
            ?>
            <div class="well table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>Nombre</th>
                            <th>Precio</th>
                            <th>Cantidad</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
            foreach ($result as $key => $pl) {
                ?>
                            <tr>
                                <td>
                                    <button class="btn btn-link" data-toggle="modal" data-target="#myModal<?php 
                echo $pl->id_plato;
                ?>
">
                                        <?php 
                echo $pl->nombre_plato;
                ?>
                                    </button>
                                    <?php 
                include 'modal_busqueda.php';
                ?>
                                </td>
                                <td> $
                                    <?php 
                echo $pl->precio . "<br>";
                ?>
                                </td>
                                <td>
                                    <form method="post" id ="cant<?php 
                echo $pl->id_plato;
                ?>
" action="handlers/add_carrito_handler.php?idprod=<?php 
                echo $pl->id_plato;
                ?>
&nombre=<?php 
                echo $pl->nombre_plato;
                ?>
&precio=<?php 
                echo $pl->precio;
                ?>
&dir=carta.php&descrip=<?php 
                echo str_replace(' ', '+', $pl->descripcion);
                ?>
">
                                        <input type = "number" min = "1" max = "20" step = "1" value = "1" size = "3" name="cantidad"> 
                                        <button type="submit" class="btn btn-success btn-xs">Agregar</button>
                                    </form>
                                </td>
                            </tr>
                        <?php 
            }
            ?>
                    </tbody>
                </table>
            </div>
            <?php 
        } else {
            if (!empty($platos_cat)) {
                ?>
                <div class="well table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>Nombre</th>
                                <th>Precio</th>
                                <th>Cantidad</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php 
                foreach ($platos_cat as $key => $pl) {
                    ?>
                                <tr>
                                    <td>
                                        <button class="btn btn-link" data-toggle="modal" data-target="#myModal<?php 
                    echo $platos_obj[$key]->id_plato;
                    ?>
">
                                            <?php 
                    echo $platos_obj[$key]->nombre_plato;
                    ?>
                                        </button>
                                        <?php 
                    include 'descripcionModal.php';
                    ?>
                                    </td>
                                    <td> $
                                        <?php 
                    echo $platos_obj[$key]->precio . "<br>";
                    ?>
                                    </td>
                                    <td>
                                        <form method="post" id ="cant<?php 
                    echo $platos_obj[$key]->id_plato;
                    ?>
" action="handlers/add_carrito_handler.php?idprod=<?php 
                    echo $platos_obj[$key]->id_plato;
                    ?>
&nombre=<?php 
                    echo $platos_obj[$key]->nombre_plato;
                    ?>
&precio=<?php 
                    echo $platos_obj[$key]->precio;
                    ?>
&dir=carta.php&descrip=<?php 
                    echo str_replace(' ', '+', $platos_obj[$key]->descripcion);
                    ?>
">
                                            <input type = "number" min = "1" max = "20" step = "1" value = "1" size = "3" name="cantidad"> 
                                            <button type="submit" class="btn btn-success btn-xs">Agregar</button>
                                        </form>
                                    </td>
                                </tr>
                            <?php 
                }
                ?>
                        </tbody>
                    </table>
                </div>
                <?php 
            } elseif (!empty($platos_rango)) {
                ?>
                <div class="well table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>Nombre</th>
                                <th>Precio</th>
                                <th>Cantidad</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php 
                foreach ($platos_rango as $key => $pl) {
                    ?>
                                <tr>
                                    <td>
                                        <button class="btn btn-link" data-toggle="modal" data-target="#myModal<?php 
                    echo $platos_obj_r[$key]->id_plato;
                    ?>
">
                                            <?php 
                    echo $platos_obj_r[$key]->nombre_plato;
                    ?>
                                        </button>
                                        <?php 
                    include 'descripcionModal.php';
                    ?>
                                    </td>
                                    <td> $
                                        <?php 
                    echo $platos_obj_r[$key]->precio . "<br>";
                    ?>
                                    </td>
                                    <td>
                                        <form method="post" id ="cant<?php 
                    echo $platos_obj_r[$key]->id_plato;
                    ?>
" action="handlers/add_carrito_handler.php?idprod=<?php 
                    echo $platos_obj_r[$key]->id_plato;
                    ?>
&nombre=<?php 
                    echo $platos_obj_r[$key]->nombre_plato;
                    ?>
&precio=<?php 
                    echo $platos_obj_r[$key]->precio;
                    ?>
&dir=carta.php&descrip=<?php 
                    echo str_replace(' ', '+', $platos_obj_r[$key]->descripcion);
                    ?>
">
                                            <input type = "number" min = "1" max = "20" step = "1" value = "1" size = "3" name="cantidad"> 
                                            <button type="submit" class="btn btn-success btn-xs">Agregar</button>
                                        </form>
                                    </td>
                                </tr>
                            <?php 
                }
                ?>

                        </tbody>
                    </table>
                </div>
                <?php 
            } else {
                echo '<div class="alert alert-info"> Marque una opción de búsqueda para iniciar el proceso</div>';
            }
        }
    }
}
Пример #2
0
<?php

$db = new phpDB();
$db->connect();
$query = "SELECT * FROM categoria";
$db->exec($query, array());
?>


<div class="table-responsive">
    <table class="table table-hover table-bordered">
        <tbody>
            <?php 
do {
    $rs = $db->fobject();
    ?>
                <tr>
                    <td class="capitalize"><?php 
    echo $rs->nombre_categoria;
    ?>
</td>
                </tr>
            <?php 
} while ($db->nextRow());
?>
        </tbody>
    </table>
</div>
Пример #3
0
require_once 'include/pedido.class.php';
$db = new phpDB();
$db->connect();
$query1 = '';
if ($_SESSION['user_bd13']->rol == '1') {
    $query1 = "SELECT * from pedidos WHERE rut = \$1";
    $db->exec($query1, array($_SESSION['user_bd13']->rut));
} elseif ($_SESSION['user_bd13']->rol == '0') {
    $query1 = "SELECT * from pedidos";
    $db->exec($query1, array());
}
$pedidos = array();
$plato_pedidos = array(array());
$index = 0;
do {
    $rs1 = $db->fobject();
    $pedido = new pedido($rs1->id_pedidos, $rs1->rut, $rs1->fecha);
    $pedidos[$index] = $pedido;
    $index++;
} while ($db->nextRow());
foreach ($pedidos as $key => $value) {
    $id = $value->getID();
    $query2 = "SELECT * from plato_pedidos WHERE id_pedidos = '{$id}'";
    $db->exec($query2, array());
    $platos = array(array());
    $i = 0;
    do {
        $rs2 = $db->fobject();
        $platos[$i] = array($rs2->id_plato, $rs2->cantidad);
        $i++;
    } while ($db->nextRow());
Пример #4
0
$db = new phpDB();
$db->connect();
$query = "SELECT * FROM plato";
$db->exec($query, array());
$calegorias_arr = array();
$index = 0;
?>


<div class="table-responsive">
    <table class="table table-hover table-bordered">
        <tbody>
            <?php 
do {
    $rs = $db->fobject();
    ?>
                <tr>
                    <td class="capitalize"><?php 
    echo $rs->nombre_plato;
    ?>
</td>
                </tr>
            <?php 
} while ($db->nextRow());
?>
        </tbody>
    </table>
</div>
<?php 
$query2 = "SELECT * FROM categoria";
Пример #5
0
<?php

require_once "../include/db.php";
# Permite la comunicación con la bd
# Se hace la conexión a la BD #
$db = new phpDB();
# La variable $db guarda la referencia a la BD
$db->connect();
# Se hacen distintas cosas dependiendo del valor del parámetro "action" #
if ($_GET['action'] == 'login') {
    $query = "SELECT * FROM usuario WHERE rut = \$1 and password = \$2";
    $db->exec($query, array(RUT_formatear($_POST['rut']), $_POST['password']));
    # Si hay un resultado, el login fue correcto #
    if ($db->numRows() == 1) {
        session_start();
        $_SESSION['user_bd13'] = $db->fobject();
        $db->close();
        if ($_SESSION['user_bd13']->rol == '0') {
            header('Location: ../login_cajero.php');
        } else {
            header('Location: ../index.php');
            # Redirecciona a /index.php
        }
    } else {
        header('Location: ../login.php?error=true');
        # Redirecciona al login con error
    }
} else {
    if ($_GET['action'] == 'logout') {
        $db->close();
        session_start();