<?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 W.IdLog, W.Campo1, W.Campo2, W.Campo3, W.Trama, W.WS_Respuesta, W.WS_Status, W.WS_Status_text, CONVERT(VARCHAR, W.Fecha, 120) AS Fecha \n"
			  ."FROM ws_log AS W \n"
			  ."WHERE (CONVERT(DATE, W.Fecha) >= '".$cV01."' AND CONVERT(DATE, W.Fecha) <= '".$cV02."') AND (W.IdWS = ".$cV03.") \n"
			  ."ORDER BY W.Fecha 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>CAMPO 1</th>
								<th>CAMPO 2</th>
								<th>CAMPO 3</th>
								<th>TRAMA</th>
								<th>WS STATUS</th>
								<th>WS STATUS TEXT</th>
								<th>WS RESPUESTA</th>
								<th>FECHA</th>
							</tr>
						</thead>
						<tbody>";
						while($fila = sqlsrv_fetch_array($re1))
						{
							$cV01 = $fila['IdLog'];
							echo "
								<tr>
									<td>".$fila['Campo1']."</td>
									<td>".$fila['Campo2']."</td>
									<td>".$fila['Campo3']."</td>
									<td class='a-center'>
										<button class='btn btn-sm btn-warning' type='button' data-placement='top' onclick='popup01($cV01)' data-toggle='tooltip' data-original-title='Ver Trama'><i class='fa fa-edit'></i></button>
									</td>
									<td>".$fila['WS_Status']."</td>
									<td>".$fila['WS_Status_text']."</td>
									<td class='a-center'>
										<button class='btn btn-sm btn-warning' type='button' data-placement='top' onclick='popup02($cV01)' data-toggle='tooltip' data-original-title='Ver Respuesta WS'><i class='fa fa-edit'></i></button>
									</td>
									<td>".$fila['Fecha']."</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>