<?php



include('is_logged.php');
require_once("../config/db.php");
require_once("../config/conexion.php");

$action = (isset($_REQUEST['action']) && $_REQUEST['action'] != NULL) ? $_REQUEST['action'] : '';
if ($action == 'ajax') {
	$usr = $_SESSION['user_name'];

	$sql = "SELECT * FROM asociados ";
	$query = mysqli_query($con, $sql);

?>
	<style>
		tfoot input {
			width: 100%;
			padding: 3px;
			box-sizing: border-box;
		}
	</style>
	<!-- <div id="intento" style="overflow: auto;">	 -->
	<div class="table-responsive">
		<table class="table table-hover" id="planes">
			<thead>
				<tr>
					<th>N° Cuenta.</th>
					<th>C.c Asociado</th>
					<th>Nombres</th>
					<th>Apellidos</th>
					<th style="padding-right: 30px;" class='text-right'>Acciones</th>
				</tr>
			</thead>

			<tbody>
				<?php
				while ($row = mysqli_fetch_array($query)) {
					$id = $row['n_cuenta'];
					$cc = $row['cc_asociado'];
					$n1 = $row['nombre_1'];
					$n2 = $row['nombre_2'];
					$ap1 = $row['apellido_1'];
					$ap2 = $row['apellido_2'];
				?>
					<tr>
						<td><?php echo $id ?></td>
						<td><?php echo $cc ?></td>
						<td><?php echo $n1 . " ". $n2 ?></td>
						<td><?php echo $ap1 ." " . $ap2 ?></td>
						<td><span class="pull-right">
							<a class='btn btn-primary' title='Editar usuario' onclick="obtener_datos23('<?php echo $row['cc_asociado']; ?>');"><i class="glyphicon glyphicon-print"></i></a> </td>
					</tr>
				<?php
				}
				?>

			</tbody>
			<tfoot>
				<tr class="">
					<th>N° Cuenta.</th>
					<th>C.c Asociado</th>
					<th>Nombres</th>
					<th>Apellidos</th>
					<th hidden class='text-right'>Acciones</th>
				</tr>
			</tfoot>
		</table>
	</div>
	<script>
		$(document).ready(function() {
			$('#planes tfoot th').each(function() {
				var title = $(this).text();
				$(this).html('<input class="form-control" type="text" placeholder=" ' + title + '" />');
			});

			var table = $('#planes').DataTable({
				"ordering": false,
				"searching": true,
				"responsive": true,
				"language": {
					"url": "https://cdn.datatables.net/plug-ins/1.10.19/i18n/Spanish.json"
				},
				"order": [
					[0, "desc"]
				],
				"initComplete": function() {
					this.api().columns().every(function() {
						var that = this;

						$('input', this.footer()).on('keyup change', function() {
							if (that.search() !== this.value) {
								that
									.search(this.value)
									.draw();
							}
						});
					})
				}
			});
		});
	</script>


	<script>
		function obtener_datos23(id) {

			$.ajax({
				type: "GET",
				url: "ajax/reporte.php",
				data: {
					id: id
				},
				success: function(data) {
					var URL = "pdf2/pdf_separado.php?nume=" + id;
					var W = window.open(URL);
					W.window.print();

				}

			});

		}
	</script>
	<br>
	<br>
	<br>
	<br>
<?php
}
?>