<? session_start();

//RESTRICCIÃN DE ACCESO A TRABAJADOR (ACCESO INDIVIDUAL) 
if (isset($_SESSION['tipousuario'])) {
	if ($_SESSION['tipousuario'] == '1')
		header('location:menu_personal.php');
}
if (trim($_SESSION['nombre_validar']) == '') header('location:index.php');
$db1 = 'pedidosm_mynomina_' . $_POST['empresa1'];
$db2 = 'pedidosm_mynomina_' . $_POST['empresa2'];
include("fphp.php");
$enlace = cargar_conexion();
menu();
echo "<b>Opciones:</b> &nbsp;&nbsp;<img border = 0 src='images/b_regresa.png' alt='Regresar'>:<a href='archivo_trabajador_contratos.php'>Regresar</a><hr>";
echo "<h2>Copiar Art&iacute;culos de un Contrato a Otro</h2></center><br><br>";
echo "<form name = 'entrada' action = '" . $_SERVER['PHP_SELF'] . "' method = 'POST' enctype='multipart/form-data'>
		<input type = 'hidden' name = 'bandera' value = '1'>
		<table align='center'>";
echo "<tr>";
$query = "Select * from contrato where id='" . $_SESSION['id_validar'] . "'  order by detalle, detalle";
$consulta = mysqli_query($enlace, $query) or die("no se pudo leer los contratos...");
echo "<td align = 'right'> <font face='verdana' size=2>Nro. de Contrato Desde? </font>";
echo "<td><select name = 'contrato1'>";
while ($row1 = mysqli_fetch_array($consulta)) {
	echo "<option width = '30%' value='" . $row1['codigo'] . "'>" . trim($row1['codigo']) . " - " . $row1['detalle'];
}
mysqli_free_result($consulta);
echo "</select></tr>";
echo "<tr>";
$query = "Select * from contrato where id='" . $_SESSION['id_validar'] . "' order by detalle, detalle";
$consulta = mysqli_query($enlace, $query) or die("no se pudo leer los contratos...");
echo "<td align = 'right'> <font face='verdana' size=2>Nro. de Contrato Hasta? </font>";
echo "<td><select name = 'contrato2'>";
while ($row1 = mysqli_fetch_array($consulta)) {
	echo "<option width = '30%' value='" . $row1['codigo'] . "'>" . trim($row1['codigo']) . " - " . $row1['detalle'];
}
mysqli_free_result($consulta);
echo "</select></tr>";
echo "<tr>";
echo "<td align = 'right'><font face='verdana' size='2' color='black'>Validar Operaci&oacute;n? (SI): </font></td>";
echo "<td align = 'left'> <input type = 'text' name = 'si' size = '5' maxlength = '2' </td>";
echo "</tr>";

echo "</table>";

echo "<table align = 'center'>
			<tr>
				<td ><input type = 'submit' style='margin-left: 5px;' value = 'Copiar Articulos?'></td>
			</tr></table>
			<script language='javascript' type='text/javascript'>
				document.entrada.contrato1.focus();
			</script><br>
			</form><hr>";

///=====================================================================================================================
if ($_POST['bandera'] == '1') {
	if (strtoupper($_POST['si']) == "SI") {
		if ($_POST['contrato1'] != $_POST['contrato2']) {

			$consulta = "Select * from contrato_articulo where id='" . $_SESSION['id_validar'] . "' and codigo = '" . $_POST['contrato1'] . "'";
			$resultado = mysqli_query($enlace, $consulta) or die($consulta . mysqli_error($enlace));
			while ($row = mysqli_fetch_array($resultado)) {
				$consultax = "insert into contrato_articulo (id, codigo,articulo,detalle) values ('" . $_SESSION['id_validar'] . "','" . $_POST['contrato2'] . "',ucase('" . $row['articulo'] . "'),'" . $row['detalle'] . "')";
				$resultadox = mysqli_query($enlace, $consultax) or die($consulta . mysqli_error($enlace));
			}
			echo "<center><b><font face='verdana' size='2' color='red'>Carga Efectuada Satisfactoriamente</b></font></center>";
   
		} else echo "<center><b><font face='verdana' size='2' color='red'>Contratos deben ser diferentes...</b></font></center>";
	} else echo "<b><center><font face='verdana' size='2' color='red'>Ha solicitado NO validar...</font></b></center>";
}

mysqli_close($enlace);
?>
<br><br>
</body>

</html>