<?php
include '../checkSession.php';
?>
<!DOCTYPE html>
<html lang="es" class="<?php echo $rol;?>">
<head>
  <meta charset="utf-8">
  <title>ADMINISTRADOR DE CONTENIDOS</title>
  <meta content="width=device-width, initial-scale=1.0" name="viewport">
  <meta content="" name="keywords">
  <meta content="" name="description">

  <!-- Favicons -->
  <link href="https://trafikatest.com/indeval/assets/img/favicon.ico" rel="icon">
  <link href="https://trafikatest.com/indeval/assets/img/favicon.ico" rel="apple-touch-icon">

  <!-- Google Fonts -->
  <link rel="preconnect" href="https://fonts.gstatic.com">
  <link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@200;400;500;700&display=swap" rel="stylesheet">
  <link href="/admin/vendor/css/fontawesome/css/all.css" rel="stylesheet"> <!--load all styles -->

  <!-- Bootstrap CSS File -->
  <link href="/admin/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

  <!-- Vendor CSS Files -->
  <link href="/admin/vendor/icofont/icofont.min.css" rel="stylesheet">
  <link href="/admin/vendor/line-awesome/css/line-awesome.min.css" rel="stylesheet">
  <link href="/admin/vendor/aos/aos.css" rel="stylesheet">
  <link href="/admin/vendor/owlcarousel/assets/owl.carousel.min.css" rel="stylesheet">
  <link rel="stylesheet" type="text/css" href="https://www.jerrylow.com/basictable/demo/css/style.css" />
  <link rel="stylesheet" type="text/css" href="https://www.jerrylow.com/basictable/basictable.css" />
  <link rel="stylesheet" type="text/css" href="/admin/vendor/css/balloon.css" />

  <!-- Main CSS File -->
  <link href="/admin/vendor/css/style.css" rel="stylesheet">

  <!-- CSS de contenidos tipo lista -->
  <link href="styles.css" rel="stylesheet">
</head>

<body>
    
  <div class="site-wrap">

    <div class="site-mobile-menu site-navbar-target">
      <div class="site-mobile-menu-header">
        <div class="site-mobile-menu-close mt-3">
          <span class="icon-close2 js-menu-toggle"></span>
        </div>
      </div>
      <div class="site-mobile-menu-body"></div>
    </div>

    <header class="site-navbar js-sticky-header site-navbar-target" role="banner" >

      <div class="container">
        <div class="row align-items-center">
          
          <div class="col-6 col-lg-2">
            <h1 class="mb-0 site-logo"><a href="/admin/pag/home-banners" class="mb-0"><img src="https://trafikatest.com/indeval/assets/img/indeval_logo.svg"></a></h1>
          </div>

          <div class="col-12 col-md-10 d-none d-lg-block">
            <nav class="site-navigation position-relative text-right" role="navigation">

              <ul class="site-menu main-menu js-clone-nav mr-auto d-none d-lg-block">
                <?php include '../nav.php';?>

              </ul>
            </nav>
          </div>


          <div class="col-6 d-inline-block d-lg-none ml-md-0 py-3" style="position: relative; top: 3px;">

            <a href="#" class="burger site-menu-toggle js-menu-toggle" data-toggle="collapse" data-target="#main-navbar">
              <span></span>
            </a>
          </div>

        </div>
      </div>
      
    </header>


    <main id="main">
      <div class="hero-section inner-page">
        <div class="wave">
          
          <svg width="1920px" height="265px" viewBox="0 0 1920 265" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
              <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                  <g id="Apple-TV" transform="translate(0.000000, -402.000000)" fill="#FFFFFF">
                      <path d="M0,439.134243 C175.04074,464.89273 327.944386,477.771974 458.710937,477.771974 C654.860765,477.771974 870.645295,442.632362 1205.9828,410.192501 C1429.54114,388.565926 1667.54687,411.092417 1920,477.771974 L1920,667 L1017.15166,667 L0,667 L0,439.134243 Z" id="Path"></path>
                  </g>
              </g>
          </svg>

        </div>

        <div class="container">
          <div class="row align-items-center">
            <div class="col-12">
              <div class="row justify-content-center">
                <div class="col-md-12 text-center hero-text">
                  <h1 data-aos="fade-up" data-aos-delay="">Banners del Carousel del Home</h1>
                  

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

      <div class="site-section">
      <div class="container containertable">

        
            <div class="row">
            <div class="col-md-12" data-aos="fade-up">
                <form id="buscarform" onsubmit="return false" enctype="multipart/form-data" method="post" class="php-email-form">

                  <div class="row">

                  <?php
                    if($total_records < 1){
                  ?>
                  <style>
                  .centerbuscador div {
                      float: none;
                      display: inline-block;
                    }
                    .col-md-3.hideifnoresult {
                      display: none;
                    }
                    .hideifnoresult {
                      display: none !important;
                    }
                  </style>

                  <?php    
                     

                    }
                  ?>

                    <div class="col-md-3 form-group" style="padding-right: 0;">
                      <input value="<?php echo $q; ?>" placeholder="Buscar..." type="text" name="q" id="buscador" class="form-control" data-rule="minlen:3" data-msg="Ingresa al menos 3 caracteres">
                      <div class="validate" id="mensajebuscar">Ingresa al menos 3 caracteres</div>
                    </div>

                    <div class="col-md-1 form-group" style="padding-left: 0;">
                      <a aria-label="Buscar" data-balloon-pos="up"  class="btn btn-primary w-100"  id="btnbuscar" style="border-radius: 0 4px 4px 0; height: 53px;"> <i class='fas fa-search'></i></a>
                    </div>

                    <div class="col-md-1 form-group">
                    </div>

                    <div class="col-md-3 hideifnoresult">
                      <select name="campo" id="campo">
                        <option value="id">Ordenar por</option>
                        <option value="id">Fecha Recibido</option>
                        <option value="nombre">Nombre</option>
                        <option value="total">Email</option>
                        <option value="fecha_entrega">Empresa</option>
                        <option value="hora_entrega">Mensaje</option>
                        
                        
                      </select>
                    </div>
                    <div class="col-md-2 hideifnoresult" >
                      <select name="orden" id="orden">
                        <option value="DESC">Descendente</option>
                        <option value="ASC">Ascendente</option>
                      </select>
                    </div>
                    <div class="col-md-1 form-group hideifnoresult">
                      <a aria-label="Aplicar filtros" data-balloon-pos="up" class="btn btn-primary w-100"  id="btnfiltrar" style="border-radius: 0 4px 4px 0; height: 53px;"> <i class="fas fa-filter"></i></a>
                    </div>
                    <?php
                    if(strlen($_GET['por'])>2 || strlen($_GET['orden'])>2){?>

                    <div class="col-md-1 nofiltercont form-group hideifnoresult">
                      <a aria-label="Quitar todos los filtros" data-balloon-pos="up" class="btn btn-primary w-100"  id="btnnofiltrar" style="border-radius: 0 4px 4px 0; height: 53px;" href="/admin/pag/home-banners"> <i class="fas fa-undo"></i></a>
                    </div>

                    <?php

                    }?>

                    <?php
                      if($total_records < 1){
                        echo '</div>';
                      }
                    ?>
                  </div>

                </form>

              </div>


              <div class="col-md-12"  data-aos="fade-up">
                <a style="display:none;" onclcik="openDate();" aria-label="Filtrar por rango de fecha" data-balloon-pos="right" class="btn btn-primary w-100" id="btndates" onclick="openPopDates()" googl="true"> <i class="fas fa-calendar"></i></a>
                <a aria-label="Exportar resultados a excel (Próximamente)" data-balloon-pos="up" class="btn btn-primary w-100" id="btnexcel" onclick="openPopExcel()" googl="true"> <i class="fas fa-file-excel"></i></a>
                <div style='padding: 10px 0px 0px; border-top: dotted 1px #CCC; float: left; margin-top: -10px;'>
                  
                  
                </div>
              </div>


              <div class="col-md-12"  data-aos="fade-up">
              <div class="addnew" onclick="addNew();" googl="true">
                    <a id="btneadd" googl="true"> <i class="fas fa-plus"></i></a>
                    <div style="padding: 10px 0px 0px; border-top: dotted 1px #CCC; float: left; margin-top: -10px;">
                </div>

               
                  <strong>Agregar nuevo</strong>
                </div>

                <div class="col-12 opcionestab"  data-aos="fade-up">

                      <ul>
                        <li class="activetab1 tab-publicados" onclick="switchTab('publicados');"> Contenido publicado</li>
                        <li class="tab-borradores" onclick="switchTab('borradores');">Borradores <i class="circledraft" style="display:none;">0</i></li>

                      </ul>

                </div>
                
                <table id="table" class="two-axis publicados">
                <thead>
                <tr>
                    
                    <th >Título</th>
                    <th >Enlace</th>
                    <th>Texto</th>
                    <th>Imagen</th>
                    <th>Editar</th>
                    <th>Visibilidad en sitio</th>
                    <th>Eliminar</th>
                    
                </tr>
                </thead>
                <tbody>
             
              <?php

              if(strlen($_GET['q'])>0){
                $curl2 = curl_init();

                curl_setopt_array($curl2, array(
                    CURLOPT_URL => 'https://api-us-east-1.graphcms.com/v2/ckkxmrn6cw3ga01ywc1spb2qu/master',
                    CURLOPT_RETURNTRANSFER => true,
                    CURLOPT_ENCODING => '',
                    CURLOPT_MAXREDIRS => 10,
                    CURLOPT_TIMEOUT => 0,
                    CURLOPT_FOLLOWLOCATION => true,
                    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                    CURLOPT_CUSTOMREQUEST => 'POST',
                    CURLOPT_POSTFIELDS =>'{"query":"query MyQuery {\\r\\n  bannersHome(_search: \\"'.$_GET['q'].'\\", stage: PUBLISHED, where: {estatus_not: \\"oculto\\"}) {\\r\\n    imagenDeFondo\\r\\n  enviadoRevision\\r\\n   id\\r\\n    subtitulo\\r\\n    titulo\\r\\n  estatus\\r\\n    textoBoton\\r\\n    enlaceBoton\\r\\n    localizations {\\r\\n      enlaceBoton\\r\\n      imagenDeFondo\\r\\n  enviadoRevision\\r\\n     subtitulo\\r\\n      textoBoton\\r\\n      titulo\\r\\n  estatus\\r\\n    }\\r\\n  }\\r\\n}\\r\\n","variables":{}}',
                    CURLOPT_HTTPHEADER => array(
                      'Content-Type: application/json',
                      'Cookie: __cfduid=da2693cdfd39b7377a8a05e305da45b8f1613001694'
                    ),
                  ));

                    $response2 = curl_exec($curl2);

                    curl_close($curl2);
              }

              else{
                
              $curl2 = curl_init();
              
              curl_setopt_array($curl2, array(
                CURLOPT_URL => 'https://api-us-east-1.graphcms.com/v2/ckkxmrn6cw3ga01ywc1spb2qu/master',
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_ENCODING => '',
                CURLOPT_MAXREDIRS => 10,
                CURLOPT_TIMEOUT => 0,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST => 'POST',
                CURLOPT_POSTFIELDS =>'{"query":"query MyQuery {\\r\\n  bannersHome( stage: PUBLISHED, where: {estatus_not: \\"oculto\\"}) {\\r\\n    imagenDeFondo\\r\\n  enviadoRevision\\r\\n   id\\r\\n    subtitulo\\r\\n    titulo\\r\\n  estatus\\r\\n    textoBoton\\r\\n    enlaceBoton\\r\\n    localizations {\\r\\n      enlaceBoton\\r\\n      imagenDeFondo\\r\\n  enviadoRevision\\r\\n     subtitulo\\r\\n      textoBoton\\r\\n      titulo\\r\\n  estatus\\r\\n   }\\r\\n  }\\r\\n}\\r\\n","variables":{}}',
                CURLOPT_HTTPHEADER => array(
                  'Content-Type: application/json',
                  'Cookie: __cfduid=da2693cdfd39b7377a8a05e305da45b8f1613001694'
                ),
              ));
              

              $response2 = curl_exec($curl2);
              //print_r($response2);

              curl_close($curl2);


              }

              function excerpt($title, $cutOffLength) {

                $charAtPosition = "";
                $titleLength = strlen($title);
            
                do {
                    $cutOffLength++;
                    $charAtPosition = substr($title, $cutOffLength, 1);
                } while ($cutOffLength < $titleLength && $charAtPosition != " ");
            
                return substr($title, 0, $cutOffLength) . '...';
            
            }

              

                $arrayform2 = json_decode($response2, true);
                $bucket="";

                foreach ($arrayform2['data']['bannersHome'] as $item) {

                    foreach ($item['localizations'] as $subitem) {
                        if(strlen($subitem['imagenDeFondo'])>2){
                            
                            $imagen = "<img src=".$bucket.$subitem['imagenDeFondo']." style='width:100px;'>";
                        }
                        else{
                            $imagen ="";
                        }
                        if($subitem['estatus'] == 'oculto' ){
                          $status = '<span class="statusenespera">Oculto</span>';
                        }
                        if($subitem['estatus'] == 'publicado' ){
                            $status = '<span class="statusentregado">Visible</span>'; 
                        }

                        

                        echo '  
                            <tr id="tr'.$item['id'].'" class="'.$item['id'].'">
                            <td>'.$subitem['titulo'].'</td>
                            <td>'.$subitem['enlaceBoton'].'</td>
                            <td>'.$subitem['subtitulo'].'</td>
                            <td>'.$imagen.'</td>
                           
                            <td id="edit'.$item['id'].'" onclick="openEditEnlace(&quot;'.$item['id'].'&quot;)"><div aria-label="Editar" data-balloon-pos="left"><img src="/admin/img/writing.svg" style="width: 35px;"></div></td>

                            <td data-status= "'.$subitem['stage'].'" id="status'.$item['id'].'" onclick="openStatus(&quot;'.$item['id'].'&quot;)"><div aria-label="Cambiar status" data-balloon-pos="left">'.$status.'</div></td>

                            <td id="delete'.$item['id'].'" onclick="deleteThis(&quot;'.$item['id'].'&quot; , &quot;BannerHome&quot;)"><div aria-label="Eliminar" data-balloon-pos="left"><img src="/admin/img/trash.svg" style="width: 35px;"></div></td>
                    
                  </tr>';

                }
          
            
            }

                  
                echo '
                    </tbody>
                  </table>';
              ?>



<table id="table" class="two-axis borradores" style="display:none;">
                <thead>
                <tr>
                    
                    <th >Título</th>
                    <th >Enlace</th>
                    <th>Texto</th>
                    <th>Imagen</th>
                    <th>Editar</th>
                    <th>Publicar</th>
                    <th>Eliminar</th>
                    
                </tr>
                </thead>
                <tbody>
             
              <?php

              if(strlen($_GET['q'])>0){
                $curl2 = curl_init();

                curl_setopt_array($curl2, array(
                    CURLOPT_URL => 'https://api-us-east-1.graphcms.com/v2/ckkxmrn6cw3ga01ywc1spb2qu/master',
                    CURLOPT_RETURNTRANSFER => true,
                    CURLOPT_ENCODING => '',
                    CURLOPT_MAXREDIRS => 10,
                    CURLOPT_TIMEOUT => 0,
                    CURLOPT_FOLLOWLOCATION => true,
                    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                    CURLOPT_CUSTOMREQUEST => 'POST',
                    CURLOPT_POSTFIELDS =>'{"query":"query MyQuery {\\r\\n  bannersHome(_search: \\"'.$_GET['q'].'\\", stage: DRAFT, where: {estatus_not_contains: \\"eliminado\\"}) {\\r\\n    imagenDeFondo\\r\\n  enviadoRevision\\r\\n   id\\r\\n    subtitulo\\r\\n    titulo\\r\\n  estatus\\r\\n    textoBoton\\r\\n    enlaceBoton\\r\\n    localizations {\\r\\n      enlaceBoton\\r\\n      imagenDeFondo\\r\\n  enviadoRevision\\r\\n     subtitulo\\r\\n      textoBoton\\r\\n      titulo\\r\\n  estatus\\r\\n    }\\r\\n  }\\r\\n}\\r\\n","variables":{}}',
                    CURLOPT_HTTPHEADER => array(
                      'Content-Type: application/json',
                      'Cookie: __cfduid=da2693cdfd39b7377a8a05e305da45b8f1613001694'
                    ),
                  ));

                    $response2 = curl_exec($curl2);

                    curl_close($curl2);
              }

              else{
                
              $curl2 = curl_init();
              
              curl_setopt_array($curl2, array(
                CURLOPT_URL => 'https://api-us-east-1.graphcms.com/v2/ckkxmrn6cw3ga01ywc1spb2qu/master',
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_ENCODING => '',
                CURLOPT_MAXREDIRS => 10,
                CURLOPT_TIMEOUT => 0,
                CURLOPT_FOLLOWLOCATION => true,
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                CURLOPT_CUSTOMREQUEST => 'POST',
                CURLOPT_POSTFIELDS =>'{"query":"query MyQuery {\\r\\n  bannersHome( stage: DRAFT, where: {estatus_not_contains: \\"eliminado\\"}) {\\r\\n    imagenDeFondo\\r\\n  enviadoRevision\\r\\n   id\\r\\n    subtitulo\\r\\n    titulo\\r\\n  estatus\\r\\n    textoBoton\\r\\n    enlaceBoton\\r\\n    localizations {\\r\\n      enlaceBoton\\r\\n      imagenDeFondo\\r\\n  enviadoRevision\\r\\n     subtitulo\\r\\n      textoBoton\\r\\n      titulo\\r\\n  estatus\\r\\n   }\\r\\n  }\\r\\n}\\r\\n","variables":{}}',
                CURLOPT_HTTPHEADER => array(
                  'Content-Type: application/json',
                  'Cookie: __cfduid=da2693cdfd39b7377a8a05e305da45b8f1613001694'
                ),
              ));
              

              $response2 = curl_exec($curl2);
              //print_r($response2);

              curl_close($curl2);


              }

  
              

                $arrayform2 = json_decode($response2, true);
                $bucket="";

                foreach ($arrayform2['data']['bannersHome'] as $item) {

                    foreach ($item['localizations'] as $subitem) {
                        if(strlen($subitem['imagenDeFondo'])>2){
                            
                            $imagen = "<img src=".$bucket.$subitem['imagenDeFondo']." style='width:100px;'>";
                        }
                        else{
                            $imagen ="";
                        }
                        if($subitem['estatus'] == 'oculto' ){
                          $status = '<span class="statusenespera">Oculto</span>';
                        }
                        if($subitem['estatus'] == 'publicado' ){
                            $status = '<span class="statusentregado">Visible</span>'; 
                        }

                        if($item['enviadoRevision'] == 'enviar' || $subitem['enviadoRevision'] == 'enviar' ){
                          
                          
                          $activar = '<td onclick="openStatus2(&quot;'.$item['id'].'&quot;)" data-status= "'.$subitem['stage'].'" id="status'.$item['id'].'" ><div aria-label="Publicar en el sitio" data-balloon-pos="left"><span class="statusentregado2"> <i class="fas fa-upload"></i>Listo para publicar</span></div></td>';
                        }
                        else{
                          
  
                          $activar = '<td style="pointer-events:none; opacity:.5;" data-status= "'.$subitem['stage'].'" id="status'.$item['id'].'" ><div aria-label="Publicar en el sitio" data-balloon-pos="left"><span class="statusentregado2"> <i class="fas fa-pencil-ruler"></i>Borrador guardado</span></div></td>';
                        }

                        

                        echo '  
                            <tr id="tr'.$item['id'].'" class="'.$item['id'].' stat'.$subitem['enviadoRevision'].'" >
                            <td>'.$subitem['titulo'].'</td>
                            <td>'.$subitem['enlaceBoton'].'</td>
                            <td>'.$subitem['subtitulo'].'</td>
                            <td>'.$imagen.'</td>
                           
                            <td id="edit'.$item['id'].'" onclick="openEditEnlace(&quot;'.$item['id'].'&quot;, &quot;draft&quot; )"><div aria-label="Editar" data-balloon-pos="left"><img src="/admin/img/writing.svg" style="width: 35px;"></div></td>

                            '.$activar.'
                            <td id="delete'.$item['id'].'" onclick="deleteThis(&quot;'.$item['id'].'&quot; , &quot;BannerHome&quot;)"><div aria-label="Eliminar" data-balloon-pos="left"><img src="/admin/img/trash.svg" style="width: 35px;"></div></td>
                    
                  </tr>';

                }
          
            
            }

                  
                echo '
                    </tbody>
                  </table>';
              ?>

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

    </main>
  </div> <!-- .site-wrap -->


  <div class="popUpEnlace">
    <div class="pocont">
      <div class="closepop" onclick="closeEditEnlace();"></div>
      <h3>Editar Banner</h3> 
        <div class="tab-block" id = "tab-block">
  
        <ul class="tab-mnu">
            <li class = "active" data-lang="es">Español</li>
            <li data-lang="en">Inglés</li>
        </ul>
        
        <div class="tab-cont">
            <div class="tab-pane"><div id="loadcontentes"></div></div>
            <div class="tab-pane"><div id="loadcontenten"></div></div>
            
        </div>

        </div>
        <div style="display:inline-block; width:100%; padding:10px; float:left;" id="respuestaedit"></div>
    </div>
  </div>
  
  <div class="popUpDate">
    <div class="pocont">
      <div class="closepop" onclick="closePopDate();"></div>
      <h2>Selecciona el rango de fechas</h2>
      <div style="display:inline-block; width:100%; padding:10px; float:left;" id="respuestaedit"></div>
      <input type="text" id="fecha1" placeholder="Fecha inicial">
      <input type="text" id="fecha2" placeholder="Fecha final">
      <a class="filtrarfecha" onclick="filtrarFecha();">Filtrar</a>
      
    </div>
  </div>
  
  
    <div class="popUpExcel">
    <div class="pocont">
      <div class="closepop" onclick="closePopExcel();"></div>
      <h2>Generar Excel <span style="font-size:11px;"></span></h2>
      <a download href="" class="btn btn-primary w-100"><i class="fas fa-file-download"></i> Todos los pedidos</a>
      <a download href="" class="btn btn-primary w-100"><i class="fas fa-file-download"></i> Sólo resultados actuales</a>
      
      
    </div>
  </div>

  <div id="respuestauser"></div>
  <div class="popUp">
	<div class="pocont">
		<div class="printpop" onclick="printPop();"></div>
		<div class="closepop" onclick="closePop();"></div>
		<div id="loadpop"></div>
	</div>
</div>
  </div>

  <input type="hidden" id="current" value="0"/>
  <input type="hidden" id="currentstage" value="0"/>

  <?php 
  $newpage = 'banner'; $newtext = 'nuevo banner'; $modelo = 'BannerHome';
  include '../footer.php';?>

  <script type="text/javascript">
    $(document).ready(function() {

      $('#table').basictable({
      });
      $('.two-axis.borradores').basictable({});
    });

    <?php
    if(strlen($q)>2){
      echo ' $("table").mark("'.$q.'");';
    }
    ?>
    
    $("#btnbuscar").click(function(){
          $("#mensajebuscar").slideUp();
          var q = $("#buscador").val();
          if(q.length > 2){
            window.location.href = '/admin/pag/home-banners?q='+q;
          }
          else{
            $("#mensajebuscar").slideDown();
          }
        });

        $("#btnfiltrar").click(function(){
          var campo = $("#campo").val();
          var orden = $("#orden").val();

          var urlfilter = "/admin/pag/home-banners?a=1<?php if(strlen($q)>2){echo '&q='.$q;} if(strlen($rango)>2){echo '&f1='.urlencode($fecha_inicial).'&f2='.urlencode($fecha_final);}?>&por="+campo+"&orden="+orden;
          window.location.href = urlfilter;
        });

        $('#buscador').keypress(function(event) {
            if (event.keyCode == 13) {
              $("#btnbuscar").click();
            }
        });


  </script>

  <script>
  function openEditEnlace(id, stage){
    $("#currentstage").val(stage);
    $("#current").val(id);
    $(".popUpEnlace").fadeIn();
    $('.tab-mnu li.active').click();
  }
  function closeEditEnlace(){
    $(".popUpEnlace").fadeOut();

  }
  

  function validateNumber(elem) {
    var validNumber = new RegExp(/^\d*\.?\d*$/);
    var lastValid = document.getElementById("totalabonado").value;
    if (validNumber.test(elem.value)) {
      lastValid = elem.value;
    } else {
      elem.value = lastValid;
    }
  }


$('#fecha1').focus(function(e) {
    $(this).blur();
});

$('#fecha2').focus(function(e) {
    $(this).blur();
});

function openPopDates(){
  $('#fecha1').datepicker({
    maxDate: '03/01/25',
    minDate: '01/02/21',
	closeText: 'Cerrar',
        prevText: '<Ant',
        nextText: 'Sig>',
        currentText: 'Hoy',
        monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
        monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
        dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
        dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mié', 'Juv', 'Vie', 'Sáb'],
        dayNamesMin: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sá'],
        weekHeader: 'Sm',
        dateFormat: 'dd/mm/y',
        firstDay: 1,
        isRTL: false,
        showMonthAfterYear: false,
        yearSuffix: ''
});//end datepicker


$('#fecha2').datepicker({
    maxDate: '03/01/25',
    minDate: '01/02/21',
	closeText: 'Cerrar',
        prevText: '<Ant',
        nextText: 'Sig>',
        currentText: 'Hoy',
        monthNames: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre'],
        monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
        dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
        dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mié', 'Juv', 'Vie', 'Sáb'],
        dayNamesMin: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sá'],
        weekHeader: 'Sm',
        dateFormat: 'dd/mm/y',
        firstDay: 1,
        isRTL: false,
        showMonthAfterYear: false,
        yearSuffix: ''
});//end datepicker

	$(".popUpDate").fadeIn();

}

function closePopDate(){
	$(".popUpDate").fadeOut();
}

function openPopExcel(){
  //$(".popUpExcel").fadeIn();
}

function closePopExcel(){
	$(".popUpExcel").fadeOut();
}
function filtrarFecha(){
  
  var f1= $("#fecha1").val();
  var f2= $("#fecha2").val();
  var encoded1 = encodeURIComponent(f1);
  var encoded2 = encodeURIComponent(f2);

  if(f1=="" || f2 ==""){
    $("#respuestafechas").html("Selecciona ambas fechas");
  }
  else{
    var urlfilter = "/admin/pag/home-banners?f1="+encoded1+"&f2="+encoded2+"&por=<?php echo $por;?>&orden=<?php echo $orden;if(strlen($q)>2){echo'&q='.$q;}?>";
    window.location.href = urlfilter;
  }

}

function generaExcel(id){

  if(id == 1){
    var url = "/admin/excel-report/openpay.php";
    $("#linkexcel").attr("href", url);
    $("#linkexcel").fadeIn();
    $("#linkexcel").trigger("click");
  }
  if(id == 2){
    var f1= $("#fecha1").val();
    var f2= $("#fecha2").val();
    var encoded1 = encodeURIComponent(f1);
    var encoded2 = encodeURIComponent(f2);
    var url = "/admin/excel-report/openpay?f1="+encoded1+"&f2="+encoded2+"&por=<?php echo $por;?>&orden=<?php echo $orden;if(strlen($q)>2){echo'&q='.$q;}?>";
    $("#linkexcel").attr("href", url);
    $("#linkexcel").fadeIn();
    $("#linkexcel").trigger("click");


    }
  }

  $(document).ready(function(){
  
  var tabWrapper = $('#tab-block'),
      tabMnu = tabWrapper.find('.tab-mnu  li'),
      tabContent = tabWrapper.find('.tab-cont > .tab-pane');
  
  tabContent.not(':first-child').hide();
  
  tabMnu.each(function(i){
    $(this).attr('data-tab','tab'+i);
  });
  tabContent.each(function(i){
    $(this).attr('data-tab','tab'+i);
  });
  
  tabMnu.click(function(){
    var tabData = $(this).data('tab');
    tabWrapper.find(tabContent).hide();
    tabWrapper.find(tabContent).filter('[data-tab='+tabData+']').show(); 
  });
  
  $('.tab-mnu > li').click(function(){
    $("#loadcontentes").html("");
    $("#loadcontenten").html("");
    var before = $('.tab-mnu li.active');
    before.removeClass('active');
    $(this).addClass('active');
    var current = $("#current").val();
    var stage = $("#currentstage").val();
    setTimeout(() => {
      
      var lang = $(this).attr('data-lang');
      if(lang == 'es'){
        $("#loadcontentes").load("loadbanner?lang=es&stage="+stage+"&id="+current);
      }
      if(lang == 'en'){
        $("#loadcontenten").load("loadbanner?lang=en&stage="+stage+"&id="+current);
      }

    }, 100);

   });
  
});

  </script>

  <!-- include summernote css/js -->
<link href="/admin/vendor/summernote/summernote-lite.css" rel="stylesheet">
<script src="/admin/vendor/summernote/summernote-lite.js"></script>

  </body>
</html>
