<?php

if (isset($_POST['b'])) {
    $buscar = $_POST['b'];
    include '../model/productos.php';
    $con = new Productos();
    $listar = $con->ConsultarByDesc($buscar);
    if (empty($listar)) {
        echo "<tr>";
        echo "<td colspan='4'>There were not records</td>";
        echo "</tr>";
    } else {
        for ($i = 0; $i < count($listar); $i++) {
            echo "<tr>\n                    <td>{$listar[$i]['idproducto']}</td>\n                    <td>{$listar[$i]['nom_pro']}</td>\n                    <td>{$listar[$i]['unidad_med']}</td>\n                    <td>{$listar[$i]['precio']}</td>\n\n                    <td>\n                        <a href='../controller/productos.controller.php?action=delete&id={$listar[$i]['id']}'><img src='../recursos/images/delete.png'></a>\n                        <a href='productosEdit.php?action=edit&id={$listar[$i]['id']}'><img src='../recursos/images/edit.png'></a>\n                    </td>\n                    </tr>\n\n                    ";
        }
    }
}
if (isset($_POST['submit']) && $_POST['submit'] == "Guardar") {
    $nom = $_POST['nom_pro'];
    $uni = $_POST['unidad_med'];
    $pre = $_POST['precio'];
    echo $nom;
    include '../model/productos.php';
    $con = new Productos();
    $result = $con->Nuevo($nom, $uni, $pre);
    if ($result > 0) {
        header('Location: ../views/productosList.php');
    }
}
if (isset($_POST['submit']) && $_POST['submit'] == "Editar") {
    $id = $_POST['idproducto'];