<?php
session_start();
require_once ("../conexion.php");
require_once('../include/sesiones.php'); 
$q = mysqli_real_escape_string($con,(strip_tags($_REQUEST['q'], ENT_QUOTES)));
include '../include/pagination.php';

$count_query=mysqli_query($con, "SELECT count(*) AS numrows FROM ubicacion where empresa='$empresa' and ubi_nombre like '%$q%'");
$row= mysqli_fetch_array($count_query);
$numrows = $row['numrows'];
$sql = mysqli_query($con,"SELECT * FROM ubicacion where empresa='$empresa' and sucursal='$sucursal' and ubi_nombre like '%$q%' order by ubi_id asc");
if ($numrows>0){
?>
<div class="table-responsive">
	<table class="table table-bordered table-hover table-striped">
		<thead>
			<tr>
				<th>NOMBRE</th>
				<th width="12%"></th>
			</tr>
		</thead>
		<tbody >
		<?php
			while ($reg=mysqli_fetch_array($sql)){
        ?>
	        <input type="hidden" value="<?php echo $reg['ubi_nombre'];?>" id="ubi_nombre<?php echo $reg['ubi_id'];?>">
			<tr>
				<?php $id=$reg['ubi_id']; ?>
				<td><?php  echo $reg['ubi_nombre']; ?></td>
				<td>
				<?php
					if ($reg['ubi_nombre']=='SIN UBICACION')
						{
	  					echo'';
						}
						else
						{ 
					?>
	            		<a href="#" class='btn btn-xs btn-info' title='Editar' onclick="obtener_datos('<?php echo $reg['ubi_id'];?>');" data-toggle="modal" data-target="#modificar_ubicacion"><i class="btn-icon-only icon-edit"></i></a> 
	   					<a href="#" onclick="eliminar('<?php echo $reg['ubi_id'];?>')" title="Eliminar" class="btn btn-xs btn-danger"> <i class="btn-icon-only icon-remove"></i></a>
					<?php } ?>
				</td>
			</tr>
		<?php }?>
			
			</tbody>
		</table>
</div>		
<?php } ?>

<script>
function eliminar(ubi_id)
{
if (confirm("Realmente deseas eliminar la Ubicacion")){ 
    $.ajax({
        type: "GET",
        url: "php_ubicacion/eliminar_ubicacion.php",
        data: "ubi_id="+ubi_id,
      	beforeSend: function(objeto){
         	$('#resultados').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
        },
        success: function(datos){
      		$("#resultados").html(datos);
      		load(1);
      	}
        });
    }
} 
</script>