<?php include "../index/conexion.inc" ?>
<?php include "../index/validacion.php" ?>
<?php
	$cV01 = $_POST['v1'];	/* DESDE */
	$cV02 = $_POST['v2'];	/* HASTA */
?>
<?php
	// conexión
	$servername = $svr_servidor;
	$conectioninfo = array("Database"=>$svr_base, "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
		if ($cV01 == "" and $cV02 == "")
		{
			$sql = "SELECT * FROM JOIN_UBICACIONES";
		}
		if ($cV01 != "" and $cV02 == "")
		{
			$sql = "SELECT * FROM JOIN_UBICACIONES WHERE (BODEGA = '".$cV01."')";
		}
		if ($cV01 == "" and $cV02 != "")
		{
			$sql = "SELECT * FROM JOIN_UBICACIONES WHERE (PASILLO = '".$cV02."')";
		}
		if ($cV01 != "" and $cV02 != "")
		{
			$sql = "SELECT * FROM JOIN_UBICACIONES WHERE (BODEGA = '".$cV01."') AND (PASILLO = '".$cV02."')";
		}
		$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='x_title'>
					<h3>Listado de etiquetas 2x3(8x5) desde ".$cV01." hasta ".$cV02. "</h3>
					<div class='clearfix'></div>					
				</div>
				<button type='submit' class='btn btn-warning'>
					<span class='glyphicon glyphicon-print' aria-hidden='true'></span> Imprimir
				</button>
				<div class='table-responsive'>
					<table class='table table-striped jambo_table bulk_action'>
						<thead>
							<tr class='headings'>
								<th>
									<input type='checkbox' id='check-all' class='flat'>
								</th>
								<th>IDUBICACION</th>
								<th>CODUBICACION</th>
								<th>BODEGA</th>
								<th>IDZONA</th>
								<th>PASILLO</th>
								<th>IDESTANTERIA</th>
								<th>COLUMNA</th>
								<th>NIVEL</th>
								<th>TIPOUBICACION</th>
								<th>USOUBICACION</th>
								<th>RESTRICCION</th>
								<th>CANTIDADMAX</th>
								<th>CANTIDADMIN</th>
								<th>LONGITUD</th>
								<th>LATITUD</th>
							</tr>
						</thead>";
						while($fila = sqlsrv_fetch_array($re1))
						{
							$cV01 = $fila['IDUBICACION'];
							echo "
								<tbody>
									<tr class='even pointer'>
										<td class='a-center'>
											<input type='checkbox' class='flat' name='lista[]' value='".$cV01."'>
										</td>															
										<td>".$fila['IDUBICACION']."</td>
										<td>".$fila['CODUBICACION']."</td>
										<td>".$fila['BODEGA']."</td>
										<td>".$fila['IDZONA']."</td>
										<td>".$fila['PASILLO']."</td>
										<td>".$fila['IDESTANTERIA']."</td>
										<td>".$fila['COLUMNA']."</td>
										<td>".$fila['NIVEL']."</td>
										<td>".$fila['TIPOUBICACION']."</td>
										<td>".$fila['USOUBICACION']."</td>
										<td>".$fila['RESTRICCION']."</td>
										<td>".$fila['CANTIDADMAX']."</td>
										<td>".$fila['CANTIDADMIN']."</td>
										<td>".$fila['LONGITUD']."</td>
										<td>".$fila['LATITUD']."</td>
									</tr>
								</tbody>
							";
						}
					echo "
					</table>
				</div>
				<button type='submit' class='btn btn-warning' onclick='recargar();'>
					<span class='glyphicon glyphicon-print' aria-hidden='true'></span> Imprimir
				</button>
			</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>
	// Script para seleccion o Deseleccionar chekBox
	$("#check-all").on("click", function() {
	  $(".flat").prop("checked", this.checked);
	});
	// if all checkbox are selected, check the selectall checkbox and viceversa
	$(".flat").on("click", function() {
	  if ($(".flat").length == $(".flat:checked").length) {
		$("#check-all").prop("checked", true);
	  } else {
		$("#check-all").prop("checked", false);
	  }
	});
</script>