<?php

if (isset($_SESSION['usuario'])) {

	$user = $_SESSION['usuario'];
} else {

?>

	<script>
		location.href = "index.php?errorusuario=3";
	</script>

<?php }

include("conexion.php");

$id = $_GET['idProd'];

$cons1 = "SELECT * FROM productos WHERE id='$id'";
$res1 = mysql_query($cons1, $conex) or die("No se consulto nombre de producto");
$prod = mysql_fetch_array($res1);
?>



<link href="ucaestilos.css" rel="stylesheet" type="text/css" />


<table width="95%" border="0" align="center">

	<tr>
		<td>
			<p class="style10">AGREGAR PRODUCTO A PAQUETE</p>
		</td>
	</tr>

	<tr>
		<td>
			<HR />
		</td>
	</tr>

	<tr>
		<td>
			<div align="center">
				<?php if (isset($_GET['error']))
					$error = $_GET['error']; {
					if (isset($error)) {
						$error = $_GET['error'];
						if ($error == 1) {
							echo "<p class='style3'>�Requiere seleccionar paquetes!</p>";
						}
					}
				}
				?>
			</div>

			<table width="100%" height="0" border="0" cellpadding="0" cellspacing="10">
				<tr>
					<td width="46%" valign="top">
						

							<div align="left"><span class="style10">PRODUCTO:</span><br>
							<span class="style9"><?php echo $prod['nombre']; ?></span></div>

<br>
						<div align="left" class="style10">PAQUETES EN LOS QUE SE ENCUENTRA:</div>

						<p>

							<?php
							echo "<table cellpadding='5' class='tablaBordes' width='90%' >";
							echo "<tr class='tablaCabecera'>";

							echo "<td> ID </td>";
							echo "<td>Paquete</td>";
							echo "<td align='center'>Cantidad</td>";
							echo "<td>Eliminar</td>";

							echo "</tr>";

							$query = "SELECT cantidad,idPaquete FROM contenido_paquete WHERE clave='$id'";
							$result = mysql_query($query, $conex) or die("No se consulto contenido paquete");
							while ($fila = mysql_fetch_array($result)) {

								echo "<tr class='tablaBordes'>";

								echo "<td class='style1' align='center'>$fila[1]</td>";

								//paquete
								$cons2 = "SELECT nompaquete FROM paquetes WHERE idPaquete ='$fila[1]'";
								$res2 = mysql_query($cons2, $conex) or die("No se consulto nombre de paquete");
								$nompaquete = mysql_result($res2, 0, 'nompaquete');

								echo "<td class='style1'>$nompaquete</td>";
						
								echo "<td class='style1' align='center'>".$fila['cantidad']."</td>";

								//Eliminar
								echo "<td class='style4' align='center'>";
								echo "<a href='deletepaqueteproducto.php?paquete=" . $fila[1] . "&producto=" . $id . "'> <img src='img/icon_delete.jpg' border='0' ALT='Quitar producto'></a>";
								echo "</td>";

								echo "</tr>";
							}

							echo "</table>";

							mysql_free_result($res);
							?>

						</p>
					</td>

					<td width="54%" valign="top">
						<form id="form1" name="form1" method="post" action="svcontenidopaquete.php">

							<p class="style10">Selecciona paquetes a agregar:</p>

								<?php
								echo "<table align='center' cellpadding='4' class='tablaBordes'>";
								echo "<tr class='tablaCabecera' align='center'>";

								echo "<td>Sel.</td>";
								echo "<td>  ID  </td>";
								echo "<td>Paquete</td>";
								echo "<td>Cantidad</td>";


								echo "</tr>";

								$cual=0;
								$query = "SELECT a.idPaquete,a.nompaquete FROM paquetes as a INNER JOIN contenido_paquete as b ON a.idPaquete=b.idPaquete WHERE b.clave!='$id' GROUP BY idPaquete ORDER BY nompaquete ";
								$result = mysql_query($query, $conex) or die("No se consultaron los paquetes");
								while ($fila = mysql_fetch_array($result))
								{
									echo "<tr class='tablaBordes filaSeleccion'>";
									echo "<td class='style1' align='center'><input name='paquetes[]' id='prod_$cual' type='checkbox' value='" . $fila[0] . "' ></td>";
									echo "<td class='style1' align='center'>$fila[0]</td>";
									echo "<td class='style1'><label for='prod_$cual'> $fila[1]</label></td>";
									echo "<td><input type='number' name='cantidad[]' value='0' style='width:50px;'></td>";
									echo "</tr>";
									$cual++;
								}

								echo "</table>";

								?>

					

							<input name="producto" type="hidden" id="producto" value="<?php echo $id; ?>" />

							<table width="100" border="0" align="center" cellpadding="0" cellspacing="10">

								<tr>

									<td><input name="button" type="button" class="boton2" id="button" onClick="javascript:history.back()" value="Cancelar y regresar" /></td>

									<td><input name="button2" type="submit" class="boton2" id="button2" value="Agregar a paquetes" /></td>

								</tr>

							</table>

						</form>
					</td>

				</tr>

			</table>
		</td>

	</tr>

</table>