<?php
  $seccion      = 'Promociones';
  $position     = '../';

  require_once($position.'../switch/access.php');
  require_once($position.'assets/global.php');
  require_once($position.'assets/session.php');
  require_once($position.'assets/funciones.php');

  //Buscador
  $Where = "
    WHERE
      pro.id != 0
  ";

  if( $_GET['buscar'] == 'Ok' ){

    //Nombre
    if( $_GET['nombre'] ){
      $nom = $_GET['nombre'];
      $Where .= "
        AND pro.nombre LIKE 'pro.nombre%'
      ";
    }

    //Fecha Inicio
    if( $_GET['fechainicio'] && $_GET['fechalimite'] ){
      $fei = $_GET['fechainicio'];
      $Where .= "
        AND pro.fechainicio BETWEEN '$fei' AND '$fel'
      ";
    }




  }

  //Query's
  $qrPromos = "
    SELECT
      pro.id,
      pro.fechainicio, pro.fechalimite,
      pro.nombre, pro.precio,
      pro.contacto_whatsapp, pro.contacto_telefono,
      pro.contacto_email, pro.activo
    FROM promociones pro
    $Where
      ORDER BY pro.fechainicio ASC
  ";
  $pros = mysqli_query($mysqli, $qrPromos);

?>
<!DOCTYPE html>
<html lang="es_MX">
    <head>
        <meta charset="utf-8" />
        <title>Switch Point | <?php echo $seccion;?> </title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <!-- App favicon -->
        <link rel="shortcut icon" href="<?php echo $position; ?>assets/images/favicon.ico">

		<!-- App css -->
		<link href="<?php echo $position; ?>assets/css/bootstrap-corporate.min.css" rel="stylesheet" type="text/css" id="bs-default-stylesheet" />
		<link href="<?php echo $position; ?>assets/css/app-corporate.min.css" rel="stylesheet" type="text/css" id="app-default-stylesheet" />

		<link href="<?php echo $position; ?>assets/css/bootstrap-corporate-dark.min.css" rel="stylesheet" type="text/css" id="bs-dark-stylesheet" />
		<link href="<?php echo $position; ?>assets/css/app-corporate-dark.min.css" rel="stylesheet" type="text/css" id="app-dark-stylesheet" />
        <link href="<?php echo $position; ?>assets/css/style.css" rel="stylesheet" type="text/css" id="app-dark-stylesheet" />

		<!-- icons -->
		<link href="<?php echo $position; ?>assets/css/icons.min.css" rel="stylesheet" type="text/css" />

        <!-- third party css -->
        <link href="<?php echo $position; ?>assets/libs/datatables.net-bs4/css/dataTables.bootstrap4.min.css" rel="stylesheet" type="text/css" />
        <link href="<?php echo $position; ?>assets/libs/datatables.net-responsive-bs4/css/responsive.bootstrap4.min.css" rel="stylesheet" type="text/css" />
        <link href="<?php echo $position; ?>assets/libs/datatables.net-buttons-bs4/css/buttons.bootstrap4.min.css" rel="stylesheet" type="text/css" />
        <link href="<?php echo $position; ?>assets/libs/datatables.net-select-bs4/css//select.bootstrap4.min.css" rel="stylesheet" type="text/css" />
        <!-- third party css end -->

    </head>

    <body class="loading" data-layout='{"mode": "light", "width": "fluid", "menuPosition": "fixed", "sidebar": { "color": "dark", "size": "default", "showuser": false}, "topbar": {"color": "light"}, "showRightSidebarOnPageLoad": false}'>

        <!-- Pagina de inicio -->
        <div id="wrapper">

            <!-- ========== Inicio nav-izq ========== -->
            <?php include_once($position.'assets/nav.php'); ?>
            <!-- Fin nav-izq -->

            <!-- ============================================================== -->
            <!-- Incio de Contenido -->
            <!-- ============================================================== -->

            <div class="content-page">
                <div class="content">

                    <!-- Topbar -->
                    <?php include_once($position.'assets/topbar.php'); ?>
                    <!-- /Topbar -->

                    <!-- Content-->
                    <div class="container-fluid">

                        <!-- page title -->
                        <div class="row">
                          <div class="col-12">
                            <div class="page-title-box">
                              <h4 class="page-title"><?php echo $seccion; ?></h4>
                              <div class="page-title-right">
                                <ol class="breadcrumb m-0">
                                  <li class="breadcrumb-item"><a href="<?php echo $dir; ?>inicio/">Inicio</a></li>
                                  <li class="breadcrumb-item active"><?php echo $seccion; ?></li>
                                </ol>
                              </div>
                            </div>
                          </div>
                        </div>
                        <!-- /page title -->

                        <!-- Botones -->
            						<div class="row">
            							<div class="col-12 text-right">
            								<button type="button" class="btn btn-sp btn-sm" onclick="window.location.href='promocion.php'">
                              <i class="fe-plus"></i>&nbsp; Nueva Promo</button>
            							</div>
            							<div class="col-12" style="height: 5px;">&nbsp;</div>
            						</div>

            						<!-- usuarios -->
                        <div class="row">
                          <div class="col-12">
                            <div class="card">
                                <div class="card-body">
                                  <h4 class="header-title">Lista de <?php echo $seccion; ?></h4>
                                  <p class="text-muted font-13 mb-4">
                                    Promociones
                                  </p>

                                  <!-- Tabla -->
                                  <table id="" class="table dt-responsive nowrap w-100">
                                    <thead>
                                      <tr>
                                        <th>Img</th>
                                        <th>Nombre</th>
                                        <th>Fecha Inicio</th>
                                        <th>Fecha Limite</th>
                                        <th>Estatus</th>
              													<th></th>
                                        <th></th>
                                      </tr>
                                    </thead>
                                    <tbody>
											              <?php
                                      mysqli_data_seek($pros, 0);
                                      while($pro = mysqli_fetch_array($pros)) {
                                    ?>
                                      <tr>

                                        <!-- Img -->
                                        <td>
                                          <?php
    																				$ImageFirm = $RootSite.'/'.$UrlImg.'/'.$promo[id].'.jpg';
    																				//if (file_exists($ImageFirm)) {
    																			?>
  																					<img
  																						class="ImgLogo img-responsive"
  																						style="max-width: 150px;"
  																						src="<?php echo $position; ?>../promos/<?php echo $pro[id]; ?>.jpg"
  																					/>
    																			<?php //} ?>
                                        </td>
                                        <!-- End Img -->

                                        <!-- Nombre -->
                                        <td>
                                          <?php echo $pro['nombre']; ?>
                                        </td>
                                        <!-- End Nombre -->

                                        <!-- Fecha Inicio -->
                                        <td>
                                          <?php echo cambio_fecha_numerica_texto($pro['fechainicio']); ?>
                                        </td>
                                        <!-- End Fecha Inicio -->

                                        <!-- Fecha Limite -->
                                        <td>
                                          <?php echo cambio_fecha_numerica_texto($pro['fechalimite']); ?>
                                        </td>
                                        <!-- End Fecha Limite -->

                                        <!-- Btn Activo-->
                                        <td>
              														<?php if ($pro['activo'] == 1){$btnClass = "btn-success"; $btnStatus = "Activo";}else{$btnClass = "btn-primary"; $btnStatus = "Inactivo";}?>
              														<button class="btn <?php echo $btnClass ?> btn-xs"><?php echo $btnStatus ?></button>
                                        </td>
                                        <!-- End Btn Activo-->

                                        <!-- Btn Editar -->
                                        <td>
                                          <a class="btn  btn-outline-secondary waves-effect btn-xs" href="promocion.php?id=<?php echo $pro['id'];?>">
                                            <i class="fe-edit-1"></i>
                                            Editar
                                          </a>
                                        </td>
                                        <!-- End Btn Editar -->

                                        <!-- Btn Borrar -->
                                        <td>
                                          <a class="btn btn-danger waves-effect waves-light btn-xs" href="#?id=<?php echo $pro['id'];?>">
                                            <i class="fa fa-times"></i>
                                          </a>
                                        </td>
                                        <!-- End Btn Borrar -->

                                      </tr>
											               <?php } ?>
                                  </tbody>
                                </table>
                                <!-- End Tabla -->

                              </div> <!-- end card body-->
                            </div> <!-- end card -->
                          </div><!-- end col-->
                        </div>
                        <!-- /secciones -->

                    </div> <!-- /container -->

                </div> <!-- /content -->

                <!-- Footer -->
                <?php include_once($position.'assets/footer.php'); ?>
                <!-- /Footer -->

            </div>

            <!-- ============================================================== -->
            <!-- Fin de Contenido -->
            <!-- ============================================================== -->


        </div>
        <!--  /wrapper -->

        <?php require_once($position.'scripts.php') ?>

    </body>
</html>
