
<div align="left" style="padding: 10px 0px;">
	<table width="100%">
    	<tr>
        	<td><h5 style="margin-top: 8px;"><i class="fas fa-check"></i> BANNERS</h5></td>
            <td align="right" width="200">
            	<input class="form-control" type="text" placeholder="Búsqueda rápida..." id="buscador" />
            </td>
        </tr>
    </table>
</div>

<div align="right">
	<a href="?pg=banner/detalle">
		<button type="button" class="btn btn-warning btn-md " style="margin-bottom:15px">
			<i class="fa fa-plus btn-left"></i> Crear Banner
		</button>
	</a>
</div>

<table class="table table-bordered table-sm">
	<thead class="thead-dark">
	<tr>
		<th scope="col">#</th>
        <th scope="col" width="150">Imágen</th>
		<th scope="col">Título</th>
        <th scope="col">Estado</th>
		<th scope="col" style="width: 75px; text-align:center">
        </th>
	</tr>
	</thead>
    
	<tbody id="tabla_lista">
	<?php
		$count = 1;
		$query = mysqli_query($connect,"SELECT * FROM Banners ORDER BY id DESC ");
		while($data = mysqli_fetch_array($query)){
			
			$text_estado = '';
			if($data["estado"] == 1){ $text_estado = 'Activo'; }
			if($data["estado"] == 2){ $text_estado = 'Inactivo'; }

			echo '
			<tr>
				<th scope="row">'.$count.'</th>
				<td><img src="'.$recursos_plubico.'/'.$data["imagen"].'" width="100%" />   </td>
				<td>'.$data["titulo"].'</td>
				<td>'.$text_estado.'</td>
				<td align="center">
					<a href="?pg=banner/detalle&id='.$data["id"].'">
					<button type="button" class="btn btn-success btn-sm">
						<i class="fa fa-edit"></i>
					</button>
					</a>
					<button type="button" class="btn btn-danger btn-sm"  onclick="Eliminar('.$data["id"].')">
						<i class="fa fa-times"></i>
					</button>
				</td>
			</tr>
			';
			$count++;
					
		}
	?>
	</tbody>
</table>

<script>

$(document).ready(function(){
	$("#buscador").on("keyup", function() {
		var value = $(this).val().toLowerCase();
		$("#tabla_lista tr").filter(function() {
		  $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
		});
	});	  
});

var api = 'https://ganadeuna.com/admin/api/';

function Ficha(id){
	jQuery.ajax({
		url: api+"ficha_banner.php",
		type:'post',
		data: {id: id, url:"?pg=candidatos"},
		}).done(function (resp){
			$("#formulario").html(resp);
		})
		.fail(function(resp) {
			console.log(resp);
		})
		.always(function(resp){
		}
	);
}
var activar = false;
function Eliminar(id){
	if(activar == false){
		$("#modal_body").html('Estas a punto de eliminar un banner, esta acción es irreversible ¿Estás seguro?<br><br>');
		$("#modal_body").append('<button type="button" class="btn btn-danger" style="margin-right: 10px;" onclick="activar = true; Eliminar('+id+')">Eliminar</button>');
		$("#modal_general").modal('show');
	}
	else{
	
		jQuery.ajax({
			url: api+"eliminar_banner.php",
			type:'post',
			data: {id: id, url:"?pg=banners"},
			}).done(function (resp){
				$("#xscript").html(resp);
			})
			.fail(function(resp) {
				console.log(resp);
			})
			.always(function(resp){
			}
		);
		
	}
}

var formulario = $("#formulario").html();
function Setear(){
	$("#formulario").html(formulario);
}

function Del_Imagen(elem,tipo){
	$( elem).parent().html('<input type="file" class="form-control" name="image" required>');
}


</script>

<script src="js/functions.js"></script>