<?php include 'sesion_user.php';?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Panel</title>
  <style type="text/css">
    .caca {
        max-width: 200px;
    	max-height:200px;
    }
  </style>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M"
    crossorigin="anonymous">
  <link href="http://radioshosting.com/css/delalora4new.css" rel="stylesheet">
  

 <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
  <style>
    .spinner-overlay {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-color: rgba(255, 255, 255, 0.7);
      display: flex;
      justify-content: center;
      align-items: center;
      z-index: 9999;
    }

    .spinner {
      border: 4px solid rgba(0, 0, 0, 0.1);
      border-top: 4px solid #3498db;
      border-radius: 50%;
      width: 40px;
      height: 40px;
      animation: spin 1s linear infinite;
    }

    @keyframes spin {
      0% { transform: rotate(0deg); }
      100% { transform: rotate(360deg); }
    }

    .termino_fin {
      width: 200px;
      height: 200px;
      background-color: #3498db;
    }
  </style>
  <script>
    $(document).ready(function () {
      const spinner = $(".spinner-overlay");
      const terminoFin = $("#termino_fin");

      spinner.hide();

      const observer = new MutationObserver(function (mutationsList, observer) {
        if (terminoFin.is(":visible")) {
          spinner.hide();
          observer.disconnect();
        }
      });

      observer.observe(terminoFin[0], { attributes: true, childList: true, subtree: true });
    });
  </script>


</head>

<body>
     <div class="spinner-overlay" id="spinner">
    <div class="spinner"></div>
  </div>
  <div class="container-fluid">
    <div class="row">
      <div class="col-lg-3 col-md-3 col-sm-12">
        <?php
include 'nav.php';?>
      </div>
      <div class="col-lg-9 col-md-9 col-sm-12">
        <?php include 'inc_buscar.php';?>


<div style="padding-top:98px;">
</div>


        <?    $esta = 'no';


$inicial = substr($busqueda,0,1);




if (is_numeric($inicial)) {

    } else {
        $que = 1;
    }





include 'concha.php';
mysql_connect("$host","$usuario","$contra");



mysql_select_db ("$basedatos");

if ($multicaja == 1) { mysql_select_db ("$basedatos_multicaja"); };





if ($que == 1) {





///divido la palabra buscada en varios strings simples


$porciones = explode(" ", $busqueda);


$pal1 = $porciones[0]; // porción1
$pal2 = $porciones[1]; // porción2
$pal3 = $porciones[2]; // porción2
$pal4 = $porciones[3]; // porción2
$pal5 = $porciones[4]; // porción2
$pal6 = $porciones[5]; // porción2
$pal7 = $porciones[6]; // porción2
$pal8 = $porciones[7]; // porción2


if ($pal1 == '') {} else { $sql_pal1 = " `titulo` LIKE '%$pal1%' AND"; };
if ($pal2 == '') {} else { $sql_pal2 = " `titulo` LIKE '%$pal2%' AND"; };
if ($pal3 == '') {} else { $sql_pal3 = " `titulo` LIKE '%$pal3%' AND"; };
if ($pal4 == '') {} else { $sql_pal4 = " `titulo` LIKE '%$pal4%' AND"; };
if ($pal5 == '') {} else { $sql_pal5 = " `titulo` LIKE '%$pal5%' AND"; };
if ($pal6 == '') {} else { $sql_pal6 = " `titulo` LIKE '%$pal6%' AND"; };
if ($pal7 == '') {} else { $sql_pal7 = " `titulo` LIKE '%$pal7%' AND"; };
if ($pal8 == '') {} else { $sql_pal8 = " `titulo` LIKE '%$pal8%' AND"; };




$sql_total = "$sql_pal1$sql_pal2$sql_pal3$sql_pal4$sal_pal5$sql_pal6$sql_pal7$sql_pal8";



    $sql_totala =  substr($sql_total,0,-3);










$sql = "SELECT * FROM `articulos` WHERE  $sql_totala  ORDER BY `articulos`.`brand` DESC LIMIT 25";

};
if ($que == 2) {


    $busqueda = trim(str_replace(' ', '',$busqueda));
     $busqueda = $busqueda;

$sql = "SELECT * FROM `articulos` WHERE `barcode` LIKE '$busqueda' LIMIT 1";

};
$consulta = mysql_query ($sql);
while ($row = mysql_fetch_array($consulta))
{
$ID_producto = $row["ID"];
$titulo = $row["titulo"];
$foto = $row["foto"];

$fotopri = substr($foto,0,14);

if ($fotopri == 'fotos_usuarios') { } else {$foto = "https://img.sistemastock.com/img/$foto"; };

if ($fotopri == '') {$foto = "https://sistemastock.com/PRODUCTOSIN.jpg";}


$precio = $row["precio"];
$precio_costo = $row["precio_costo"];
$precio_manana = $row["precio_manana"];
$stock = $row["stock"];
$barcode = $row["barcode"];
$cat = $row["cat"];
$limite = $row["limite"];
$brand = $row["brand"];
?>
          <table width="100%" border="0" cellpadding="5" bgcolor="<? if ($brand == 1) {echo "#FFFFFF"; } else { echo "#cecece"; } ?>">
                
          
                
              
              
            <tr style="border: solid; border-width: 1px;">
                    <td align="center" width="10%">
                   <img  src="https://sistemastock.com/CARGANDOIMG.jpg" data-src="<? echo $foto ?>" class="img-fluid lazy">
                  </td>
              <td align="left">
                <span class="h2" style="font-size:25;"><?php echo $titulo ?></span> |
                <span class="h2" style="color:#006600">$ <?php echo $precio ?></span><br />
                <b>STOCK:</b><?php echo $stock ?>
                | <b>COD:</b> <?php echo $barcode ?>  (<a style="display: contents;" href="javascript:ventanaSecundaria56('https://sistemastock.com/codigosdebarras/codigodebarras.php?barcode=<? echo $barcode ?>&nombre=<? echo $titulo ?>&precio=<? echo $precio ?>')">IMPRIMIR CÓDIGO BARRAS</a>)
              <br>  | AVISO LIMITE: <b><?php echo $limite ?></b>  | costo: </b>$<? echo $precio_costo ?></b>) | ultima act: </b><?php echo $precio_manana ?></b> <? if ($multicaja != 1) { ?><a href="editar_articulo.php?ID_producto=<?php echo $ID_producto ?>"><button class="btn btn-primary"><img src="editar.png" style="width:25px; "> EDITAR</button></a> <? } ?><br>
<br></td>
           
  
  <td align="right" width="100px" style="background-color: #28a745;">

                
    <form action="agregar_productos.php" method="post" style="margin:0; text-align:center;">

  <input type="hidden" name="barcode" value="<? echo $barcode ?>" />

  <div style="margin-bottom:6px;">
    <input 
      type="number" 
      name="cantidad" 
      value="1" 
      min="1" 
      style="width:80px; text-align:center; font-size:22px; font-weight:bold;"
      class="form-control"
    >
  </div>

  <!-- Campos vacíos para mantener compatibilidad -->
  <input type="hidden" name="varios" value="">
  <input type="hidden" name="precio_varios" value="">

  <input 
    type="submit" 
    value="VENDER" 
    class="btn btn-success"
    style="height:110px; width:100%; font-size:20px; font-weight:bold;"
  />

</form>


                
                </td>
                
                
            </tr>
          </table>
          <br />
          <?
          $esta = 'si';
}
mysql_free_result($consulta);


if ($esta == 'no') {echo  "No se encontro el articulo, puede cargar el articulo desde <a href='cargar_articulo.php'>aquí</a>"; };








if ($multicaja == 1) { mysql_select_db ("$basedatos"); };

?>








      </div>
    </div>
<div id="termino_fin" class="termino_fin"></div>
  
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4"
      crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1"
      crossorigin="anonymous"></script>


    <script type="text/javascript">
      window.setInterval(function(){
        $('.grid').isotope({
        itemSelector: '.grid-item'
      });
      }, 2000);
    </script>
    <script language=javascript>
      function ventanaSecundaria56 (URL){
         window.open(URL,"ventana1","width=960,height=630,scrollbars=NO")
      }
    </script>


  <script>

        // Set the options to make LazyLoad self-initialize
        window.lazyLoadOptions = {
            elements_selector: ".lazy",
            data_sizes: "100"
            // ... more custom settings?
        };
        // Listen to the initialization event and get the instance of LazyLoad
        window.addEventListener('LazyLoad::Initialized', function (event) {
            window.lazyLoadInstance = event.detail.instance;
        }, false);
    </script>
    <script async src="https://cdn.jsdelivr.net/npm/vanilla-lazyload@12.4.0/dist/lazyload.min.js"></script>


</body>

</html>
