<?php include "../index/conexion.inc" ?>
<?php include "../index/validacion.php" ?>
<?php
	$cV01 = $_POST['v1'];	/* DESDE */
	$cV02 = $_POST['v2'];	/* HASTA */
	$cV03 = $_POST['v3'];	/* SELECCION SERVICIO */
?>
<?php
	// conexión
	$servername = $svr_servidor;
	$conectioninfo = array("Database"=>"JoinIntegrador", "UID"=>$svr_usuario, "PWD"=>$svr_contrasena, "CharacterSet"=>"UTF-8");
	$conexion = sqlsrv_connect($servername, $conectioninfo);
	if ($conexion == false)
	{
		$mensaje = "Existe un error al intentar conectarse con el servidor...";
	}
	else
	{
		// CONSULTA SQL
		$sql = "SELECT * \n"
			  ."FROM log_joinmanager AS W \n"
			  ."WHERE (CONVERT(DATE, W.FechaAccion) >= '".$cV01."' AND CONVERT(DATE, W.FechaAccion) <= '".$cV02."') AND (W.IdModulo = ".$cV03.") \n"
			  ."ORDER BY W.FechaAccion DESC";
		$pa1 = array();
		$op1 = array("scrollable" => SQLSRV_CURSOR_KEYSET);
		// Lanzar la consulta
		$re1 = sqlsrv_query($conexion, $sql, $pa1, $op1);
		if (sqlsrv_num_rows($re1) != 0)
		{
			echo "
			<div class='x_panel'>
				<div class='table-responsive'>
					<table id='example' class='table table-striped table-bordered' style='width:100%'>
						<thead>
							<tr>
								<th>MODULO</th>
								<th>CAMPO</th>
								<th>RESPONSABLE</th>
								<th>VALOR</th>
								<th>FECHA</th>
							</tr>
						</thead>
						<tbody>";
						while($fila = sqlsrv_fetch_array($re1))
						{
							echo "
								<tr>
									<td>".$fila['Modulo']."</td>
									<td>".$fila['Campo']."</td>
									<td>".$fila['Responsable']."</td>
									<td>".$fila['Valor']."</td>
									<td>".$fila['FechaAccion']->format('Y-m-d h:m:s')."</td>
								</tr>
							";
						}
						echo "
						</tbody>
					</table>
				</div>
			</div>
			";
		}
		else
		{
			echo "
			<div class='alert alert-warning alert-dismissible fade in' role='alert'>
			<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span>
			</button>
				Registros <strong>NO</strong> localizados.
			</div>
			";
		}
		sqlsrv_free_stmt($re1);
	}
	sqlsrv_close($conexion);
?>
<script>
	$(document).ready(function() {
		$('#example').DataTable();
	} );
</script>