<?php
require_once('shared/conexionBD.php');

if (isset($_GET['linea']) && isset($_GET['modelo'])) {
$lineaGet = htmlentities($_GET['linea']);
$articulo = htmlentities($_GET['modelo']);
}
if (empty($lineaGet) && empty($articulo)) {
  header('Location: 404.php');
}
mysqli_query($conexion,"SET NAMES utf8");
$rutaImagen = 'ALP/';
$query = "SELECT ID,LINEA,SUBMODELO FROM ITT_ALP_GLOBAL WHERE LINEA='".html_entity_decode($lineaGet)."' AND MODELO='".html_entity_decode($articulo)."' ";
$resultado = mysqli_query($conexion, $query);

//Crear un manejo de errores
if($resultado) {
  if((mysqli_num_rows($resultado)>0)) {
    while ($columna= mysqli_fetch_array($resultado)) {
      $modelosLineas[] = ["ID"=>$columna['ID'],"LINEA"=>$columna['LINEA'],"SUBMODELO"=>$columna['SUBMODELO']];
    }
  } else {
    $strMensaje = 'No se encontraron resultados. Intente nuevamente.';
  }
}else {
  $strMensaje= 'Ha ocurrido un error al consultar las líneas, por favor reporte el problema';
}


//creamos consulta para ver las imagenes de los banners interiores
$qryImagenes = "SELECT LINEA,MODELO,URLBAN from ITT_ASW_IMG  WHERE LINEA='".html_entity_decode($lineaGet)."' AND MODELO='".html_entity_decode($articulo)."'";
$qryImg = mysqli_query($conexion, $qryImagenes);
$arrImgs = [];
$arrBannInt = mysqli_fetch_assoc($qryImg);

?>
<!DOCTYPE html>
<!--[if IE 8 ]>    <html xml:lang="es" lang="es" class="no-js ie8"> <![endif]-->
<!--[if IE 9 ]>    <html xml:lang="es" lang="es" class="no-js ie9"> <![endif]-->
<html xml:lang="es" lang="es">

<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->

    <!--Producción-->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-125019062-2"></script>

    <!--Producción-->
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', 'UA-125019062-2');
    </script>

    <!-- End Global site tag (gtag.js) - Google Analytics -->
  <!-- [if IE]> -->
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
  <meta http-equiv="cleartype" content="on"/>
  <!-- <![endif] -->

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
  <title><?php echo ucfirst(strtolower($articulo)); ?> – S&amp;P</title>
  <meta name="keywords" content="Magento, Varien, E-commerce"/>
  <meta name="robots" content="INDEX,FOLLOW"/>
  <link rel="icon" href="https://statics.solerpalau.com/skin/frontend/solerpalau/default/favicon.ico" type="image/x-icon"/>
  <link rel="shortcut icon" href="https://statics.solerpalau.com/skin/frontend/solerpalau/default/favicon.ico" type="image/x-icon"/>

  <!-- estilo princripal -->
  <!-- bootstrap 4 -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <link href="css/style-shop.css" rel="stylesheet">
  <script type="text/javascript" src="js/events.js"></script>

  <!-- estilo princripal -->
  <link rel="stylesheet" type="text/css" href="css/style-css01.css" media="all" />
</head>
<body class=" cms-page-view cms-produccion-distribucion-logistica level-2 customer-logged-out">
  <!-- aqui va el header -->
  <?php include 'header.php' ?>

  <script type="text/javascript">
    //<![CDATA[
    if (typeof HIB.menu == 'object' && typeof HIB.menu.init == 'function') {
      HIB.menu.init();
    }
    //]]>
  </script>

  <div class="main-container col1-layout">
    <div class="breadcrumbs">
      <div class="container">
        <ul xmlns:v="https://rdf.data-vocabulary.org/#">
          <li class="0" typeof="v:Breadcrumb">
            <a href="index.php"
            title="Inicio"
            rel="v:url" property="v:title">
          Inicio</a>
          <div class="arrow-breadcrumbs-level3"><img height="10" width="8" src="https://statics.solerpalau.com/skin/frontend/solerpalau/default/images/svg/arrow-breadcrumbs.svg"/></div>
          <div class="arrow-breadcrumbs-level2"><img height="10" width="8" src="https://statics.solerpalau.com/skin/frontend/solerpalau/default/images/svg/arrow-breadcrumbs-white.svg"/></div> &nbsp;

          <li class="2">
            <a href="linea.php?linea=<?php echo $lineaGet;  ?>">División <?php echo "$lineaGet"; ?></a>

          <div class="arrow-breadcrumbs-level3"><img height="10" width="8" src="https://statics.solerpalau.com/skin/frontend/solerpalau/default/images/svg/arrow-breadcrumbs.svg"/></div>
          <div class="arrow-breadcrumbs-level2"><img height="10" width="8" src="https://statics.solerpalau.com/skin/frontend/solerpalau/default/images/svg/arrow-breadcrumbs-white.svg"/></div>
        </li>
        <li class="2">
          <a><?php echo ($articulo); ?> </a>
        </li>
      </ul>
    </div>
  </div>
  <div class="main">
    <div class="col-main">
     <main>
       <div id="overlaySearch" class="overlay">
         <!-- Overlay content -->
         <div id="searchResults" class="overlay-content grid"></div>
       </div>
       <main>
         <div class="page-title category-title dark">

            <?php if (!empty($arrBannInt)) {
              $imgExplode = explode('/',$arrBannInt['URLBAN']);
              $img = 'ALP/'.$imgExplode[2];
              echo "<img src='".$img."' alt='Banner Interior'>";
            }else{ ?>
            <img src="media/home/categories_home/<?php
              if(file_exists("media/home/categories_home/".$lineaGet.".jpg")){
                echo($lineaGet);
              }else{
                echo('Habitat');
              }
            ?>.jpg" alt="<?php echo($lineaGet); ?>" class="category-image" />

          <?php } ?>


           <div class="category-title-container">
             <div class="category-title-content container">
               <h1 class="h1"><?php echo ($articulo); ?></h1>
             </div>
           </div>
           <div class="clearfix"></div>
         </div>

         <div class="container">
          <hr>
          <div class="row">
            <div class="col-12 col-lg-3">
              <div class="list-group">
               <!-- inicia busqueda -->
               <div class="float-right pad">
                <div class="input-group">
                  <input type="text" name="caja_busqueda" id="search" class="form-control input-lg" placeholder="Buscar" />
                </div>
              </div>

              <!-- termina busqueda -->
              <h5 class="breadcrumb-item activen pad"><b>DIVISIONES</b></h5>
              <!-- Inicia Menu principal -->
              <h6><a href="#" class="list-group-item list-group-item-action active">  <b> División <?php echo $lineaGet; ?> </b></a></h6>
              <ul class="links">
                <?php
                foreach ($arrGeneral as $modelo):

                 $query = 'linea=' . urlencode($modelo['LINEA']) . '&modelo=' . urlencode($modelo['MODELO']);

                 //Resaltar el item activo en rojo
                 if ($modelo['LINEA'] == html_entity_decode($lineaGet)) {

                  if ($modelo['MODELO'] == html_entity_decode($articulo)) {
                    echo "<a href='modelo.php?".$query."' class='activelist'>
                              <li class='group'> ".$modelo['MODELO'];
                        echo "</li>
                      </a>
                    <hr>";
                  }else{
                   echo "<a href='modelo.php?".$query."' class='group'><li class='group' > ".$modelo['MODELO'];
                   echo "</li></a><hr>";

                 } ?>
                 <!-- termina sub menus -->
               <?php } endforeach; ?>
             </ul>
             <!-- se imprimen las líneas -->
             <?php
             //Filtrar las lineas
             $arrLineas  = array();
             foreach ($arrGeneral as $modelo){
              $arrL[] = $modelo['LINEA'];
            }
            $arrLineas = array_unique($arrL);
            foreach ($arrLineas as $linea):
             if (html_entity_decode($lineaGet) != $linea) {
               ?>
               <a href="linea.php?linea=<?php echo $linea ?>"
                class='list-group-item list-group-item-action'>
                División <?php echo $linea; ?> </a>
             <?php  }
           endforeach; ?>

           </div>
           <!-- /.col-lg-4 -->
         </div>

         <div class="col-12 col-sm-12 col-lg-9">
          <br>
          <div  id="ac">
            <div class="row" id="result">
              <?php
              //imprimimos las tarjetas
              if (!empty($modelosLineas)){
                $cont = 0;
                foreach ($modelosLineas as $submodelos){

                  $arrIds[]    = $submodelos['ID'];
                  $nombreSubmodelo = $submodelos['SUBMODELO'];
                  //revisar las imagenes
                  $imagen = $submodelos['ID'].".jpg";
                  $fichero = $rutaImagen.$imagen;
                  $imagen = (file_exists($fichero)) ? $rutaImagenCompleta = $fichero :  $rutaImagenCompleta = 'media/noimagen.jpg' ;

                  $queryGet = 'linea='.urlencode(html_entity_decode($lineaGet)).'&modelo='.urlencode(html_entity_decode($articulo)).'&submodelo='.urlencode(html_entity_decode($nombreSubmodelo));
                  ?>
                  <div class="col-md-4">
                    <div class="card hp-100">
                      <p class="text-center producto">
                        <a class="loader" id="btn-<?php echo($cont) ?>" href="producto.php?<?php echo($queryGet) ?>">
                          <img  id="img-<?php echo($cont) ?>" class="loadImg" src='media/img/loader2.gif' width='50px' style="position: absolute;display:none" />
                          <img  id="img-producto" src="<?php echo $imagen ?>" alt="<?php echo $nombreSubmodelo ?>"  />
                        </p>
                        <div class="product-info">
                          <p class="text-center">
                            <b> <?php echo $nombreSubmodelo ?> </b>
                          </p>
                        </div>
                        </a>
                      </div>
                  </div>
                  <?php
                  $cont++;
                }

                ////////////////////////////////
                // Calculadora de atenuadores //
                ////////////////////////////////

                $string = 'calculadora de atenuadores';
                if(html_entity_decode($lineaGet) == 'Atenuación Acústica') {

                  echo "<div class='col-md-4'>
                          <div class='card hp-100'>
                            <p class='text-center producto'>
                              <a class='loader' id='btn-".$cont++."' href='atenuadores.php'>
                                <img  id='img-".$cont++."' class='loadImg' src='media/img/loader2.gif' width='50px' style='position: absolute;display:none' /> ";

                  echo          "<svg aria-hidden='true' style='max-width: 100px; height: 200px;' focusable='false' data-prefix='fas' data-icon='calculator' class='svg-inline--fa fa-calculator fa-w-14' role='img' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 448 512'><path fill='currentColor' d='M400 0H48C22.4 0 0 22.4 0 48v416c0 25.6 22.4 48 48 48h352c25.6 0 48-22.4 48-48V48c0-25.6-22.4-48-48-48zM128 435.2c0 6.4-6.4 12.8-12.8 12.8H76.8c-6.4 0-12.8-6.4-12.8-12.8v-38.4c0-6.4 6.4-12.8 12.8-12.8h38.4c6.4 0 12.8 6.4 12.8 12.8v38.4zm0-128c0 6.4-6.4 12.8-12.8 12.8H76.8c-6.4 0-12.8-6.4-12.8-12.8v-38.4c0-6.4 6.4-12.8 12.8-12.8h38.4c6.4 0 12.8 6.4 12.8 12.8v38.4zm128 128c0 6.4-6.4 12.8-12.8 12.8h-38.4c-6.4 0-12.8-6.4-12.8-12.8v-38.4c0-6.4 6.4-12.8 12.8-12.8h38.4c6.4 0 12.8 6.4 12.8 12.8v38.4zm0-128c0 6.4-6.4 12.8-12.8 12.8h-38.4c-6.4 0-12.8-6.4-12.8-12.8v-38.4c0-6.4 6.4-12.8 12.8-12.8h38.4c6.4 0 12.8 6.4 12.8 12.8v38.4zm128 128c0 6.4-6.4 12.8-12.8 12.8h-38.4c-6.4 0-12.8-6.4-12.8-12.8V268.8c0-6.4 6.4-12.8 12.8-12.8h38.4c6.4 0 12.8 6.4 12.8 12.8v166.4zm0-256c0 6.4-6.4 12.8-12.8 12.8H76.8c-6.4 0-12.8-6.4-12.8-12.8V76.8C64 70.4 70.4 64 76.8 64h294.4c6.4 0 12.8 6.4 12.8 12.8v102.4z'></path></svg>";
                  echo      "</p>
                            <div class='product-info'>
                              <p class='text-center'>
                                <b> Selecciona tu atenuador </b>
                              </p>
                            </div>
                          </a> 
                        </div>
                    </div>";
                }
              }else{
                echo "<h1>".$strMensaje."</h1>";
              } ?>
            </div>
          </div>
          <!-- /.row -->
          <br><br>
        </div> <!-- termina col-8 -->
      </div>
    </div>
    <script type="text/javascript">
       //<![CDATA[
       if (typeof HIB == 'object' && typeof HIB.infiniteScroll == 'object' && typeof HIB.infiniteScroll.init == 'function') {
         HIB.infiniteScroll.init('.products-grid', 1000);
       }
       //]]>
        </script>
           </main>
           <aside>
           </aside>
           <script type="text/javascript">
           //<![CDATA[
           if (typeof HIB == 'object' && typeof HIB.filter == 'object' && typeof HIB.filter.init == 'function') {
             HIB.filter.init();
           }
           //]]>
         </script>
       </main>
     </div>
   </div>
 </div>
 <style>
 .bar {
      height: 30px!important;
      }
 </style>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.js"></script>
 <script type="text/javascript">
   var $j = jQuery.noConflict();
 </script>
 <script type="text/javascript" src="js/search.js"></script>
 <script>
   $j('.loader').on("click",function(e){
    e.preventDefault();
     var usersid =  $j(this).attr("id");
     var cont = usersid.split('-');
     var href = $j(this).attr('href');
     $j('#img-'+cont[1]).show();

     setTimeout(function(){
        $j('#img-'+cont[1]).hide();
      }, 1000);
      window.location.href = href;
   });
 </script>
 <!-- aqui va el footer -->
 <?php
 // cerrar conexión de base de datos
 mysqli_close( $conexion );
 include 'footer.php' ?>



</div>
</div>
</body>

</html>
