<?php
header('Location: paginas');
session_start();
if(isset($_COOKIE['persistID']))
{
    $userid = $_COOKIE['persistID'];
   $_SESSION['user'] = $userid;
}
if($userid == ''){
	header("Location: /admin");
}

if($_GET['logout'] == 1){
	   $_SESSION['uservipsdashboard'] = NULL;
     $_SESSION['roldashboard'] = NULL;
}

?>
<!DOCTYPE html>
<html lang="en">
<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="vendor/css/fontawesome/css/all.css" rel="stylesheet"> <!--load all styles -->

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

  <!-- Vendor CSS Files -->
  <link href="vendor/icofont/icofont.min.css" rel="stylesheet">
  <link href="vendor/line-awesome/css/line-awesome.min.css" rel="stylesheet">
  <link href="vendor/aos/aos.css" rel="stylesheet">
  <link href="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="vendor/css/balloon.css" />

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

  <style>
    .site-mobile-menu {
    background: #111;
  } 
  .site-mobile-menu .site-nav-wrap > li > a {
    color: #fff;
    font-weight: 500;
    padding: 20px 10px;
  }
  .sticky-wrapper {
    z-index: 9999;
  }
  table th {
    /* background: #fd9827; */
    color: #ffffff;
    text-transform: uppercase;
    background: #2b4365;
  }
.hero-section {
	background: linear-gradient(to right, rgba(26, 53, 8, 0.1) 0%, rgb(0, 0, 0) 100%), url(https://indeval-webdocs-publico-01122020.s3.amazonaws.com/img/inicio/bmv.jpg);
	position: relative;
  background-size:cover;
}
h1 {
  text-transform: none;
}
.hero-section.inner-page {
	min-height: 250px !important;
	padding-top: 0px;
}
.hero-section.inner-page {
	height: 250px;
	min-height: 0;
}
table.two-axis tr td:first-of-type {
	background: #d5e0cf;
}
table tr td {
	background: #e6eff5;
	color: #222;
}
body {
	background: #fff;
  font-family: "Montserrat", sans-serif;
}
h1, h2, h3, h4, h5, h6, .font-heading {
	color: #000;
	font-family: "Montserrat", sans-serif;
}
.hero-section.inner-page {
	height: 50vh;
	min-height: 0;
}

.hero-section.inner-page .hero-text {
	-webkit-transform: translateY(-150px);
	transform: translateY(-200px);
	margin-top: -140px;
}
.site-section {
	padding: 2rem 0;
}
.ui-datepicker .ui-datepicker-header {
	position: relative;
	padding: .2em 0;
	background:  #fd9827;
	color: #fff;
}
#ui-datepicker-div{
	font-size: 100%;
	font-family: inherit;
	opacity:.98;
}
.containertable {
	width: 100%;
	max-width: 100%;
	padding: 0 5%;
}
.imgbarc {
	width: 100%;
	cursor: pointer;
	padding: 10px;
	max-width: 50px;
	display: inline-block;
}
#btndates, #btnexcel {
	/* border-radius: 5px; */
	height: 45px;
	max-width: 45px;
	float: left;
	margin-bottom: 0;
	margin-top: 0px;
	margin-right: 25px;
	font-size: 20px;
	padding: 7.5px !important;
	border-radius: 50%;
}
table tr, table th, table td {
	font-family: inherit;
	text-align: center;
	font-size: 85%;
}
.sinresultados {
	text-align: center;
	width: 100%;
}
.sinresultados img {
	max-width: 150px;
}

table .fas, table .far {
	font-family: 'Font Awesome 5 Free';
	font-weight: 900;
	font-size: 20px;
	color: #fd9827;
	cursor: pointer;
	transition: .35s all ease;
	margin: 0 10px;
}
table .fas:hover, table .far:hover {
	transition: .35s all ease;
	transform: scale(1.1);
}

#loadpopAbono, #popUpStatus {
	padding-bottom: 40px;
}
#loadpopAbono p {
	font-size: 15px;
}
header .container {
	max-width: 90%;
}
.mb-0.site-logo img {
	height: 50px;
	padding: 0;
	margin-top: -12.5px;
}
.site-navbar .site-logo {
	min-height: 70px;
}
.site-logo {
  opacity: 0;
  transition:.35s all ease;
}
.sticky-wrapper.is-sticky .imglogout{
  filter:none;
  transition:.35s all ease;
}
.sticky-wrapper.is-sticky .site-navbar.shrink .site-logo {
  opacity: 1;
  transition:.35s all ease;
}
.php-email-form .mensajeurl {
	display: none;
	color: #222;
	background: #fff;
	text-align: center;
	padding: 15px;
	font-weight: 400;
	border: 2px solid #18d26e;
	margin-top: 10px;
	font-size: 14px;
}
.php-email-form .mensajeurl span {
	margin-top: 10px;
	display: inline-block;
	color: #1d6d96;
	font-weight: 600;
	cursor: pointer;
}
#copiado {
	display: none;
	font-size: 13px;
	padding: 10px;
	color: #289a5d;
}
.far.fa-clock {
	color: #b3b3b3;
}
.tipo {
	color: #fd9827;
	font-weight: bold;
	font-size: 12px;
}
.rol {
	font-size: 11px;
	color: #222;
}
.items img {
	max-width: 50px;
	vertical-align: middle;
	padding-right: 5px;
}
.popUp, .popUpAbono, .popUpDate, .popUpExcel, .popUpStatus {
	position: fixed;
	width: 100%;
	height: 100%;
	top: 0;
	z-index: 99999;
	background: rgba(0,0,0,.65);
	display: none;
	text-align: center;
	overflow:auto;
}
.pocont {
	display: inline-block;
	background: #fff;
	width: 95%;
	height: auto;
	position: relative;
	margin: 1% auto;
	padding: 20px;
	border-radius: 20px;
	max-width: 800px;
}
.closepop {
	width: 22px;
	height: 22px;
	background: url(img/multiply.svg);
	background-size: 100%;
	float: right;
	cursor: pointer;
	margin: 0px;
}
.printpop {
	width: 26px;
	height: 26px;
	background: url(printer.png);
	background-size: 100%;
	float: left;
	cursor: pointer;
	margin: 10px;
	position: absolute;
	right: 5px;
	top: 50px;
}
.pocont p {
	margin: 0 !important;
	padding: 3px;
	font-size: 11px;
}
.popUpExcel h2 {
    font-size: 17.5px;
    padding: 10px;
}
#fecha1, #fecha2 {
	background-image: url(/img/navidad/calendario.svg);
	background-size: 20px;
	background-repeat: no-repeat;
	background-position: 95% 50%;
	margin: 10px;
	border: 2px solid #f18007;
	min-height: 40px;
	padding: 10px;
}
* {
	box-sizing: border-box;
}
#eventodiv p {
	margin: 6px 0;
}
#totalabonado {
	height: 40px;
	width: 60%;
	padding: 5px 10px;
}
.popUpDate .pocont, .popUpExcel .pocont {
	padding-bottom: 50px;
}
.btnabono, .filtrarfecha {
	display: inline-block;
	width: 60%;
  background: #fd9827;
  background:#2b4365;
	padding: 7.5px;
	margin-top: 10px;
	color: #fff !important;
	cursor: pointer;
	border-radius: 4px;
}
.btn.btn-primary {
  background: #fd9827;
  background:#2b4365;
}
.pagination > .active > a, .pagination > .active > a:focus, .pagination > .active > a:hover, .pagination > .active > span, .pagination > .active > span:focus, .pagination > .active > span:hover {
  background: #fd9827;
  background:#2b4365;
  border-color: #b33a2d;
}
.marked-text {
    background: #ffec02;
    padding: 1px 2px;
}
.imgabono {
	width: 25px;
  margin-left: 10px;
  cursor:pointer;
}
#respuestaabono {
	padding: 10px 0;
	font-size: 14px;
	font-weight: bold;
}

.statusenespera {
	color: #26a1de;
	font-weight: bold;
	background: url(img/hourglass.svg);
	background-size: 20px;
	background-repeat: no-repeat;
	background-position: left center;
	min-height: 30px;
	display: inline-block;
	text-align: left;
	line-height: 1.1;
	padding: 10px;
	padding-left: 30px;
}
.statusentregado {
	color: #05AD00;
	font-weight: bold;
	padding: 10px;
	padding-left: 30px;
	background: url(img/check.svg);
	background-size: 20px;
	background-repeat: no-repeat;
	background-position: left;
	min-height: 30px;
	display: inline-block;
	text-align: left;
	line-height: 1.1;
}
.statuscancelado {
	color: #f40000;
	font-weight: bold;
	padding: 10px;
	padding-left: 30px;
	background: url(img/prohibition.svg);
	background-size: 20px;
	background-repeat: no-repeat;
	background-position: left;
	min-height: 30px;
	display: inline-block;
	text-align: left;
	line-height: 1.1;
}
.pocont h3 {
	font-weight: bold;
}
.statusicon {
	width: 46%;
	float: left;
	background: #f4f4f4;
	border-radius: 10px;
	margin: 1.6666%;
	padding: 20px;
	/* border: 1px solid #ccc; */
	box-shadow: 1px 2px 10px #e1e1e1;
  cursor:pointer;
}

table {
	width: 100%;
	margin-top: 20px;
	float: left;
	/* width: 100%; */
}
/*RESPONSIVE */

@media (max-width:780px){
  .col-md-6.aos-init.aos-animate {
    text-align: center;
    padding: 10px;
  }
  #btnnofiltrar {
    float: none !important;
  }
  table tr, table th, table td {
	text-align: left;
}
table.bt tbody td::before {
	width: 40%;
}
table.bt tbody td .bt-content {
	line-height: 1.5;
}
.bt-content p {
	margin-bottom: 0;
}
}

@media (max-width:600px){
  .bt-content img {
    margin: 12px 0;
  }
  .imgbarc {
	width: 50px;
	padding: 0 10px;
	object-position: 10%;
}
.statusicon {
	width: 100%;
	margin-bottom: 10px;
}
}

table.two-axis tr td:first-of-type, table.two-axis tr:nth-of-type(2n+2) td:first-of-type, table.two-axis tr td:first-of-type::before {
	background: #fd9827;
	color: #ffffff;
	background: #2b4365;
}
table.bt tbody td::before {
    background: #fd9827;
}

.openpaylogohead{
  width:100px;
  padding:0 5px;
}
h4 {
	padding: 20px;
	width: 100%;
	text-align: center;
	font-size: 17.5px;
}
.popUpExcel .pocont {
    max-width: 500px;
    padding: 40px;
}
.popUpExcel .btn {
    margin: 15px 0;
}
i.fas.fa-file-download {
    position: absolute;
    left: 25px;
    font-size: 20px;
}
a.btn.btn-primary.w-100 {
    position: relative;
}
  </style>
</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/dashboard" 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="">Administrador de contenido</h1>
                  <p>Entradas del Formulario de Contacto</p>

                </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/dashboard"> <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 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">
                <table id="table" class="two-axis">
                <thead>
                <tr>
                    <th >ID</th>
                    <th >Recibido</th>
                    <th >Nombre</th>
                    <th >Correo</th>
                    <th>Empresa</th>
                    <th>Mensaje</th>
                    <th>Status</th>
                </tr>
                </thead>
                <tbody>
             
              <?php

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

                curl_setopt_array($curl, array(
                    CURLOPT_URL => 'https://api-us-east-1.graphcms.com/v2/ckjukjw7gdtmf01xq5jz8glx2/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  entradasFormulario(where: {_search: \\"'.$_GET['q'].'\\"}) {\\r\\n    id\\r\\n    email\\r\\n    empresa\\r\\n    mensaje\\r\\n    nombre\\r\\n    statusForm\\r\\n    createdAt\\r\\n  }\\r\\n}\\r\\n","variables":{}}',
                    CURLOPT_HTTPHEADER => array(
                      'Content-Type: application/json',
                      'Cookie: __cfduid=da2693cdfd39b7377a8a05e305da45b8f1613001694'
                    ),
                  ));

                    $response = curl_exec($curl);

                    curl_close($curl);
              }

              else{
                
              $curl = curl_init();

              curl_setopt_array($curl, array(
              CURLOPT_URL => 'https://api-us-east-1.graphcms.com/v2/ckjukjw7gdtmf01xq5jz8glx2/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  entradasFormulario(orderBy: createdAt_DESC) {\\r\\n    id\\r\\n    createdAt\\r\\n    mensaje\\r\\n    nombre\\r\\n    empresa\\r\\n   statusForm\\r\\n   email\\r\\n  }\\r\\n}\\r\\n","variables":{}}',
              CURLOPT_HTTPHEADER => array(
                  'Content-Type: application/json',
                  'Cookie: __cfduid=da2693cdfd39b7377a8a05e305da45b8f1613001694'
              ),
              ));

              $response = curl_exec($curl);

              curl_close($curl);


              }

              

                $arrayform = json_decode($response, true);
                

                foreach ($arrayform['data']['entradasFormulario'] as $item) {
                            if(strlen($item['statusForm'])<1 || $item['statusForm'] == '0' ){
                                $status = '<span class="statusenespera">En espera</span>';
                            }
                            else{
                                $status = '<span class="statusentregado">Procesado</span>'; 
                            }
                            $fecha = $item['createdAt'];
                            $newdate = date("d/m/Y H:i", strtotime($fecha) - 60 * 60 * 6); ;
                        echo '  
                        <tr id="tr'.$item['id'].'">
                            <td>'.$item['id'].'</td>
                            <td>'.$newdate.'</td>
                            <td>'.$item['nombre'].'</td>
                            <td>'.$item['email'].'</td>
                            <td>'.$item['empresa'].'</td>
                            <td>'.$item['mensaje'].'</td>
                            <td id="status'.$item['id'].'" onclick="openStatus(&quot;'.$item['id'].'&quot;)"><div aria-label="Cambiar status" data-balloon-pos="left">'.$status.'</div></td>
                    
                  </tr>';
          
            
            }

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

              </div>
              

              <ul class="pagination">
                <?php if($page_no > 1){
                echo "<li><a href='?page_no=1'>Primera</a></li>";
                } ?>
                    
                <li <?php if($page_no <= 1){ echo "class='disabled'"; } ?>>
                <a <?php if($page_no > 1){
                echo "href='?pag=$previous_page'";
                } ?>>Anterior</a>
                </li>

                <?php
                if ($total_no_of_pages <= 20){   
                  for ($counter = 1; $counter <= $total_no_of_pages; $counter++){
                  if ($counter == $page_no) {
                  echo "<li class='active'><a>$counter</a></li>"; 
                  }
                  else{
                    echo "<li><a href='?pag=$counter'>$counter</a></li>";
                  }
                  }
                 }
                ?>
                    
                <li <?php if($page_no >= $total_no_of_pages){
                echo "class='disabled'";
                } ?>>
                <a <?php if($page_no < $total_no_of_pages) {
                echo "href='?pag=$next_page'";
                } ?>>Siguiente</a>
                </li>
                
                <?php if($page_no < $total_no_of_pages){
                echo "<li><a href='?pag=$total_no_of_pages'>Última &rsaquo;&rsaquo;</a></li>";
                } ?>
              </ul>
          
            </div>
      </div>
    </div>

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


  <div class="popUpAbono">
    <div class="pocont">
      <div class="closepop" onclick="closePopAbono();"></div>
      <div id="loadpopAbono"></div>
    </div>
  </div>

  <div class="popUpStatus">
    <div class="pocont">
      <div class="closepop" onclick="closeStatus();"></div>
      <h3>Cambiar status del mensaje</h3>
        <div class="statusicon" onclick="changeStatus('enespera');"><span class="statusenespera" googl="true">En espera</span></div>
        <div class="statusicon" onclick="changeStatus('entregado');"><span class="statusentregado" googl="true">Procesado</span></div>  

        <div style="display:inline-block; width:100%; padding:10px; float:left;" id="respuestastatus"></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="respuestafechas"></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="/admin/excel-report/openpay.php" class="btn btn-primary w-100"><i class="fas fa-file-download"></i> Todos los pedidos</a>
      <a download href="/admin/excel-report/openpay?f1=<?php urlencode($fecha_inicial);?>&f2=<?php urlencode($fecha_final);?>&por=<?php echo $por;?>&orden=<?php echo $orden;if(strlen($q)>2){echo'&q='.$q;}?>" 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"/>


  <!-- Vendor JS Files -->
  <script src="vendor/jquery/jquery.min.js"></script>
  <script src="vendor/jquery/jquery-migrate.min.js"></script>
  <script src="vendor/bootstrap/js/bootstrap.min.js"></script>
  <script src="vendor/easing/easing.min.js"></script>
  <script src="vendor/sticky/sticky.js"></script>
  <script src="vendor/aos/aos.js"></script>
  <script src="vendor/owlcarousel/owl.carousel.min.js"></script>
  <script type="text/javascript" src="https://www.jerrylow.com/basictable/jquery.basictable.min.js"></script>
  <script src="vendor/js/jquitelight.js"></script>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />
  <script src="https://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
  <!-- Main JS File -->
  <script src="vendor/js/main.js"></script>
  <script type="text/javascript">
    $(document).ready(function() {

      $('#table').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/dashboard?q='+q;
          }
          else{
            $("#mensajebuscar").slideDown();
          }
        });

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

          var urlfilter = "/admin/dashboard?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 type="text/javascript" src="printThis.js"></script>
  <script>
  function openPop(id){
    $("#loadpop").load("/pedido-qr?id="+id, function() {
        $(".popUp").fadeIn();
      });
  }

  function closePop(){
    $(".popUp").fadeOut();

  }
  
  function openStatus(id){
    $('#respuestastatus').html("");
    $(".popUpStatus").fadeIn();
    $("#current").val(id);
    console.log(id);
  }

  function closeStatus(){
    $(".popUpStatus").fadeOut();

  }

  function changeStatus(status){
    $(".statusicon").prop( "disabled", true );
    $(".statusicon").css("opacity", ".6");
    $(".statusicon").css("pointer-events", "none");
    var current = $("#current").val();
    console.log(current);
    $.ajax({
        url : "updateForm.php",
        type: "POST",
        data : "id="+current+"&status="+status,
        success:function(data){
            $('#respuestastatus').html(data);
            setTimeout(() => {
              $(".statusicon").prop( "disabled", false );
              $(".statusicon").css("opacity", "1");
              $(".statusicon").css("pointer-events", "inherit");
        }, 1000);
      }
    });
  }
  function printPop(){
    $("#loadpop").printThis({
      importCSS: true,            // import parent page css
      importStyle: true         // import style tags


  });

  }

  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;
    }
  }

  function openPopAbono(id){
	$("#loadpopAbono").load("loadpopdeposito?id="+id, function() {
			$(".popUpAbono").fadeIn();
		});
}

function closePopAbono(){
	$(".popUpAbono").fadeOut();
}

function updateAbono(monedero){
	$('#respuestaabono').html("<i class='fas fa-spinner fa-spin'></i> Espera un momento...");
	$(".btnabono").prop( "disabled", true );
	$(".btnabono").css("opacity", ".4");
	$(".btnabono").css("pointer-events", "none");
	var cantidad = $("#totalabonado").val();
	if (cantidad == "" || parseFloat(cantidad) <1){
		$("#respuestaabono").html("La cantidad no es válida");
		setTimeout(() => {
			$(".btnabono").prop( "disabled", false );
			$(".btnabono").css("opacity", "1");
			$(".btnabono").css("pointer-events", "inherit");
		}, 1000);
	}
	else{
    if (confirm('Confirmar depósito de '+cantidad+' al monedero '+monedero)) {
      $.ajax({
        url : "/include/navidad/depositomonedero.php",
        type: "POST",
        data : "monedero="+monedero+"&cantidad="+cantidad,
        success:function(data){
            $('#respuestaabono').html(data);
            $("#totalabonado").val("");
            setTimeout(() => {
              $(".btnabono").prop( "disabled", false );
              $(".btnabono").css("opacity", "1");
              $(".btnabono").css("pointer-events", "inherit");
        }, 1000);
      }
    });
    } 
    else {
      $("#respuestaabono").html("Depósito cancelado");
      setTimeout(() => {
        $(".btnabono").prop( "disabled", false );
        $(".btnabono").css("opacity", "1");
        $(".btnabono").css("pointer-events", "inherit");
      }, 1000);
    }


	}	

}




$('#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/dashboard?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");


    }
  }
  </script>

  </body>
</html>
