<?php
include('conexion.php');
session_start();
?>
<!doctype html>
<html lang="en" onclick="cerrar();cerrar2();">

<head>
    <?php
    include('./include/sesiones.php');
    include('./include/head.php');
    ?>
    <div id="div_buscador"></div>
    <?php include('./php_menu/menu_principal.php');
    include('./php_menu/menu_izquierdo.php');
    ?>


    <script src="https://www.google.com/recaptcha/api.js"></script>

    <script>
        function onSubmit(token) {
            document.getElementById("form_login").submit();
        }
    </script>


</head>

<body>
    <section class="slider_section mt-20">
        <div class="container">
            <div class="row">
                <div class="col-lg-3">
                    <div class="categories_menu">
                        <div class="categories_title">
                            <h2 class="categori_toggle">Categorias</h2>
                        </div>
                        <div class="categories_menu_toggle">
                            <ul style="height: 470px;overflow-y: scroll;">
                                <?php
                                $cano = mysqli_query($con, "SELECT * FROM familias where empresa='$emp_id' order by fam_nombre asc LIMIT 9 ") or die(mysqli_error($con));
                                while ($dato1 = mysqli_fetch_array($cano)) {
                                    $nombre = utf8_encode($dato1['fam_nombre']);
                                    $id = ($dato1['fam_id']);
                                ?>
                                    <li><a href="articulos_categoria.php?fam_id=<?php echo $id; ?>"><?php echo $nombre; ?></a></li>
                                <?php }
                                $casa3 = mysqli_query($con, "SELECT * FROM familias where empresa='$emp_id' order by fam_nombre asc limit 9,200000000")
                                    or die(mysqli_error($con));
                                while ($dato1 = mysqli_fetch_array($casa3)) {
                                    $nombre = utf8_encode($dato1['fam_nombre']);
                                    $id = ($dato1['fam_id']);
                                ?>
                                    <li class="hidden"><a href="articulos_categoria.php?fam_id=<?php echo $id; ?>"><?php echo $nombre; ?></a> </li>
                                <?php } ?>
                                <li><a  id="more-btn"><i class="fa fa-plus" aria-hidden="true"></i> Mas Categorias</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <div class="col-lg-9">
                    <div class="col-lg-12 ">
                        <div id="carrusel-contenido">
                            <div id="carrusel-caja">
                                <?php
                                $cano = mysqli_query($con, "SELECT * FROM slider where sli_ubicacion='slider' and empresa='$emp_id' ") or die(mysqli_error($con));
                                while ($dato1 = mysqli_fetch_array($cano)) {
                                    $sli_id = ($dato1['sli_id']);
                                    $sli_url = ($dato1['sli_url']); ?>
                                    <div class="carrusel-elemento">
                                        <?php
                                        $files = glob("img/slider/$sli_id.jpg");
                                        if (count($files) > 0) {
                                            foreach ($files as $file) { ?>

                                                <?php $nu = rand(1, 1000);
                                                $nu; ?>
                                                <a href="<?php echo $sli_url ?>">
                                                    <img class="imagenes" src="img/slider/<?php echo $sli_id . '.jpg?' . $nu . ''; ?>" alt="" />
                                                </a>

                                            <?php   }
                                        } else { ?>
                                            <?php $nu = rand(1, 1000);
                                            $nu; ?>
                                            <img class="imagenes" src="img/slider/sin_imagen.jpg?' <?php $nu . ''; ?>" alt="" />

                                        <?php } ?>

                                    </div>
                                <?php } ?>
                            </div>
                        </div>
                    </div>
                    <div class="col-12 ">

                        <?php
                        $cano1 = mysqli_query($con, "SELECT * FROM slider where sli_ubicacion='imagen izquierda' and empresa='$emp_id' ") or die(mysqli_error($con));
                        $dato2 = mysqli_fetch_array($cano1);
                        $sli_id1 = $dato2['sli_id'];
                        $sli_url1 = $dato2['sli_url'];

                        $files = glob("img/slider/$sli_id1.jpg");
                        if (count($files) > 0) {
                            foreach ($files as $file) { ?>

                                <?php $nu = rand(1, 1000);
                                $nu; ?>
                                <a href="<?php echo $sli_url1 ?>">
                                    <img class="" src="img/slider/<?php echo $sli_id1 . '.jpg?' . $nu . ''; ?>" style="height: 230px; width: 435px;padding-top: 5px;" />
                                </a>

                            <?php   }
                        } else { ?>
                            <?php $nu = rand(1, 1000);
                            $nu; ?>
                            <img class="" src="img/slider/sin_imagen.jpg?' <?php $nu . ''; ?>" style="height: 230px; width: 435px;padding-top: 5px;" />

                        <?php } ?>

                        <?php $cano2 = mysqli_query($con, "SELECT * FROM slider where sli_ubicacion='imagen derecha' and empresa='$emp_id' ") or die(mysqli_error($con));
                        $dato3 = mysqli_fetch_array($cano2);
                        $sli_id2 = $dato3['sli_id'];
                        $sli_url2 = $dato3['sli_url'];

                        $files = glob("img/slider/$sli_id2.jpg");
                        if (count($files) > 0) {
                            foreach ($files as $file) { ?>

                                <?php $nu = rand(1, 1000);
                                $nu; ?>
                                <a href="<?php echo $sli_url2 ?>">
                                    <img class="" src="img/slider/<?php echo $sli_id2 . '.jpg?' . $nu . ''; ?>" style="height: 230px; width: 435px;padding-top: 5px;" />
                                </a>

                            <?php   }
                        } else { ?>
                            <?php $nu = rand(1, 1000);
                            $nu; ?>
                            <img class="" src="img/slider/sin_imagen.jpg?' <?php $nu . ''; ?>" style="height: 230px; width: 435px;padding-top: 5px;" />

                        <?php } ?>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <section class="category_product_area mt-30 mb-50">
        <div class="container">
            <div class="row">
                <div class="col-12">
                    <div class="category_product_carousel category_column4 owl-carousel">
                        <?php
                        $centrar = mysqli_query($con, "SELECT * FROM familias where fam_destacado='si' and empresa='$emp_id' limit 4") or die(mysqli_error($con));
                        while ($cero = mysqli_fetch_array($centrar)) {
                            $fam_nombre = ($cero['fam_nombre']);
                            $fam_id = $cero['fam_id'];

                            $nombre_archivo = '../img/categorias/' . $fam_id . '.jpg';
                        ?>
                            <div class="single_category_product">
                                <div class="category_product_thumb">
                                    <?php
                                    if (file_exists($nombre_archivo)) { ?>
                                        <?php $nu = rand(1, 1000);
                                        $nu; ?>
                                        <a href="articulos_categoria.php?fam_id=<?php echo $fam_id ?>">
                                            <center>
                                                <div class="contenedor_img">
                                                    <img class="categorias" src="<?php echo $emp_url_sub; ?>/img/categorias/<?php echo $fam_id . '.jpg?' . $nu . ''; ?>" alt="">
                                                </div>
                                            </center>
                                        </a>
                                    <?php } else { ?>
                                        <a href="articulos_categoria.php?fam_id=<?php echo $fam_id ?>">
                                            <center>
                                                <div class="contenedor_img">
                                                    <?php $nu = rand(1, 1000);
                                                    $nu; ?>
                                                    <img class="categorias" src="<?php echo $emp_url_sub; ?>/img/categorias/sin_imagen.jpg?' <?php $nu . ''; ?>" alt="#">
                                                </div>
                                            </center>
                                        </a>
                                    <?php   }   ?>
                                </div>
                                <div class="category_product_name">
                                    <h2><a href="articulos_categoria.php?fam_id=<?php echo $fam_id ?>"><?php echo $fam_nombre; ?></a></h2>
                                </div>
                            </div>
                        <?php   }    ?>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <section class="home_product_area mb-100">
        <div class="container">
            <div class="row">
                <div class="col-12">
                    <div class="section_title" id="ultimos_productos">
                        <h2>Últimos <span>Productos</span></h2>
                        <div class="shop_area shop_fullwidth mt-100 mb-50">
                            <div class="row no-gutters shop_wrapper">

                                <div id="mis_articulos"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
    </section>
    <div class="banner_area mb-50">
        <div class="container">
            <div class="row">
                <div class="col-12">
                    <div class="single_banner">
                        <?php
                        $cano1 = mysqli_query($con, "SELECT * FROM slider where sli_ubicacion='pie pagina' and empresa='$emp_id' ") or die(mysqli_error($con));
                        $dato2 = mysqli_fetch_array($cano1);
                        $sli_id3 = $dato2['sli_id'];
                        $sli_url3 = $dato2['sli_url'];
                        $url = 'hotel.php';
                        ?>
                        <div class="banner_thumb">

                            <?php
                            $files = glob("img/slider/$sli_id3.jpg");
                            if (count($files) > 0) {
                                foreach ($files as $file) { ?>

                                    <?php $nu = rand(1, 1000);
                                    $nu; ?>
                                    <a href="<?php echo $sli_url3 ?>">
                                        <img class="#" src="img/slider/<?php echo $sli_id3 . '.jpg?' . $nu . ''; ?>" alt="#" style="height: 350px; width: 100%;" />
                                    </a>

                                <?php   }
                            } else { ?>
                                <?php $nu = rand(1, 1000);
                                $nu; ?>
                                <img class="" src="img/slider/sin_imagen.jpg?'<?php $nu . ''; ?>" alt="#" style="height: 350px; width: 100%;" />

                            <?php } ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="container">
        <div class="row">
            <div class="col-12">
                <div class="carrusel">
                    <div class="carrusel-items">
                        <?php
                        $centrar5 = mysqli_query($con, "SELECT * FROM marca where mar_nombre<>'SIN MARCA' AND empresa='$emp_id'") or die(mysqli_error($con));
                        while ($cero5 = mysqli_fetch_array($centrar5)) {
                            $mar_id = $cero5['mar_id'];
                            $nombre_archivo = '../img/marca/' . $mar_id . '.jpg';
                        ?>
                            <div class="carrusel-item">
                                <?php
                                if (file_exists($nombre_archivo)) {
                                ?> <?php $nu = rand(1, 1000);
                                    $nu; ?>
                                    <a href="articulos_marcas.php?mar_id=<?php echo $mar_id ?>">
                                        <img style="width: 150px; height: auto;" src="<?php echo $emp_url_sub; ?>/img/marca/<?php echo $mar_id . '.jpg?' . $nu . ''; ?>" alt="#">
                                    </a>
                                <?php } else { ?>
                                    <a href="articulos_marcas.php?mar_id=<?php echo $mar_id ?>">
                                        <?php $nu = rand(1, 1000);
                                        $nu; ?>
                                        <img style="width: 150px; height: auto;" src="<?php echo $emp_url_sub . '/img/marca/sin_imagen.jpg?' . $nu . ''; ?>" alt="#">
                                    </a>
                                <?php   }   ?>
                            </div>
                        <?php   } ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="resultados"></div>

    <?php include('include/footer.php') ?>


    <!--footer area end-->



    <!--news letter popup start-->


    <!--<div class="newletter-popup">
<div id="boxes" class="newletter-container">
    <div id="dialog" class="window">
        <div id="popup2">
            <span class="b-close"><span>close</span></span>
        </div>
        <div class="box">
            <div class="newletter-title">
                <h2>Newsletter</h2>
            </div>
            <div class="box-content newleter-content">
                <label class="newletter-label">Enter your email address to subscribe our notification of our new post &amp; features by email.</label>
                <div id="frm_subscribe">
                    <form name="subscribe" id="subscribe_popup">
                            <input type="text" value="" name="subscribe_pemail" id="subscribe_pemail" placeholder="Enter you email address here...">
                            <input type="hidden" value="" name="subscribe_pname" id="subscribe_pname">
                            <div id="notification"></div>
                            <a class="theme-btn-outlined" onclick="email_subscribepopup()"><span>Subscribe</span></a>
                    </form>
                    <div class="subscribe-bottom">
                        <input type="checkbox" id="newsletter_popup_dont_show_again">
                        <label for="newsletter_popup_dont_show_again">Don't show this popup again</label>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>-->

    <!--news letter popup start-->

    <script src="main.js"></script>
    <script src="assets/js/plugins.js"></script>
    <script src="assets/js/main.js"></script>

    <script>
        function buscador() {
            $.get("./php_menu/buscador.php", "", function(data) {
                $("#div_buscador").html(data);
            })
        }
        buscador();



        function loadArticulos() {
            $.get("./php_tienda/tabla_articulos.php", "", function(data) {
                $("#mis_articulos").html(data);
            })
        }
        loadArticulos();
        buscador();


        function envia_carrito1(art_id, cantidad) {
            var parametros = {
                "art_id": art_id,
                "cantidad": cantidad
            };
            $.ajax({
                data: parametros,
                url: './php_tienda/sessiones_cart.php',
                type: 'POST',
                beforeSend: function() {
                    $('#resultados').html('');
                },
                success: function(datos) {
                    $("#resultados").html(datos);
                   // loadArticulos();
                    buscador();
                }
            });
        }



        function envia_deseos(art_id) {
            var parametros = {
                "art_id": art_id
            };
            $.ajax({
                data: parametros,
                url: './php_tienda/registrar_deseos.php',
                type: 'POST',
                beforeSend: function() {
                    $('#resultados').html('');
                },
                success: function(datos) {
                    $("#resultados").html(datos);
                    loadArticulos();
                    buscador();
                }
            });
        }



        function eliminar_deseo(art_id) {
            var parametros = {
                "art_id": art_id
            };
            $.ajax({
                data: parametros,
                url: './php_tienda/eliminar_deseo.php',
                type: 'POST',
                beforeSend: function() {
                    $('#resultados').html('');
                },
                success: function(datos) {
                    $("#resultados").html(datos);
                    loadArticulos();
                    buscador();
                }
            });
        }
    </script>

</body>

</html>

<style type="text/css">
    /*Supongamos que nuestro contenedor mide 150px x 150px*/
    .contenedor_img {
        padding-top: 15px;
        background-color: white;
        width: 220px;
        height: 220px;
    }

    /*Aplicamos la propiedad object-fit cover, ajustar su tamaño y no perder la proporcion de nuestra imagen*/
    .categorias {
        object-fit: scale-down;
        width: 100%;
        height: 100%;
    }
</style>