<?php
session_start();
require_once ("../conexion.php");
require_once('../include/sesiones.php'); 
	$action = (isset($_REQUEST['action'])&& $_REQUEST['action'] !=NULL)?$_REQUEST['action']:'';
	if($action == 'ajax'){
         $q = mysqli_real_escape_string($con,(strip_tags($_REQUEST['q'], ENT_QUOTES)));
         include '../include/pagination.php';
		$page = (isset($_REQUEST['page']) && !empty($_REQUEST['page']))?$_REQUEST['page']:1;
		$per_page = 15; //how much records you want to show
		$adjacents  = 4; //gap between pages after number of adjacents
		$offset = ($page - 1) * $per_page;

		$count_query   = mysqli_query($con, "SELECT count(*) AS numrows FROM familias  where empresa='$empresa' and  fam_nombre like '%$q%' ");
		$row= mysqli_fetch_array($count_query);
		$numrows = $row['numrows'];
		$total_pages = ceil($numrows/$per_page);
		$reload = '../F_familias.php';

		$sql = mysqli_query($con,"SELECT * FROM  familias where  empresa='$empresa' and  fam_nombre like '%$q%'  order by fam_nombre asc LIMIT $offset,$per_page");
		
		if ($numrows>0){
			?>
			<div class="table-responsive">
			<table class="table table-bordered table-hover table-striped">
				<thead>
					<tr>
						<th>NOMBRE</th>
						<th width="20%"></th>
					</tr>
				</thead>
				<tbody >
						<?php
 							while ($reg=mysqli_fetch_array($sql)){
 							 	$id=$reg['fam_id'];
                        ?>
                        <input type="hidden" value="<?php echo $reg['fam_nombre'];?>" id="fam_nombre<?php echo $reg['fam_id'];?>">
							<tr>
								<td><?php  echo utf8_encode($reg['fam_nombre']);?></td>
								<td>
								<?php
                					if ($reg['fam_nombre']=='SIN FAMILIA')
               						 {
                  					 echo'';
                					 }
                					 else
                					 { 
                				?>
                            	
                                    <a href="libraries/tcpdf/documentos/catalogo.php?fam_id=<?php echo $reg['fam_id'];?>&&tar_id=1" class='btn btn-xs btn-warning' target="black" title='Catalogo '  ><i class="btn-icon-only icon-print"></i></a>                   				
									<script>
										$("#del-"+<?php echo $reg["fam_id"];?>).click(function(e){
											e.preventDefault();
											p = confirm("Estas seguro?");
											if(p){
												$.get("./php_familias/eliminar_familia.php","fam_id="+<?php echo $reg["fam_id"];?>,function(data){
												load(1);
												});
												}
											});
									</script>
								<?php } ?>
								</td>
							</tr>
							<?php }?>
							<tr>
								<td colspan=6>
									<span class="pull-right">
										<?php echo paginate($reload, $page, $total_pages, $adjacents);?>
									</span>
								</td>
							</tr>
					</tbody>
				</table>
				</div>		
			<?php
		}
	}
?>
 