<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>ROTACION DE TURNOS</title>
<link rel="stylesheet" type="text/css" href="styles/Style.css">
<script language="JavaScript" type="text/javascript" src="ajax.js"></script>
<script type="text/javascript"> 

function ventanaClose(){ 
   //alert("hola mundo");
    window.close();
} 

function cambiarturnos(){

var nombre1 = document.getElementById("nombre1").value;
var nombre2 = document.getElementById("nombre2").value;
	
if(nombre1==1 && nombre2==1){
   
   var idtp = document.getElementById("idtp").value;
   var idj = document.getElementById("idj").value;
   var ids = document.getElementById("ids").value;
   var mes = document.getElementById("mes").value;
   var anno = document.getElementById("anno").value;
   var ugid = document.getElementById("ugid").value;
   var cod1 = document.getElementById("codprog1").value;
   var cod2 = document.getElementById("codprog2").value;
   cadena = "cambioturno.php?idj="+idj+"&ids="+ids+"&mes="+mes+"&anno="+anno+"&ugid="+ugid+"&idtp="+idtp+"&cod1="+cod1+"&cod2="+cod2+"&camt=1";
   document.location= cadena;   
}else{
alert('INGRESE LOS CODIGOS');
}
}
</script>
</head>
<body>
<?php

include("bd/sql_variables.php");

$con= mysqli_connect("$sql_host", "$sql_usuario", "$sql_pass") or die(header ("No Disponible Servidor de Base de Datos"));
mysqli_select_db($con,"$sql_db");


$idj=$_GET['idj'];
$ids=$_GET['ids'];
$idtp=$_GET['idtp'];
$mes=$_GET['mes'];
$anno=$_GET['anno'];
$ugid=$_GET['ugid'];

if(isset($_GET['camt'])){
if($_GET['camt']==1){

$idj=$_GET['idj'];
$ids=$_GET['ids'];
$idtp=$_GET['idtp'];
$mes=$_GET['mes'];
$anno=$_GET['anno'];
$ugid=$_GET['ugid'];
$cod1=$_GET['cod1'];
$cod2=$_GET['cod2'];

//personal 1
$sqlper1 ="SELECT ug_id, s_id FROM tb_usutrab WHERE ut_codprog = '$cod1' and tp_id='$idtp' and uap_anno='$anno' and uap_mes='$mes' and ut_idserva='$ids' and j_id='$idj'";
$resultper1 = mysqli_query($con,$sqlper1);
while ($rowp1= mysqli_fetch_assoc($resultper1)){
$ugcod1=$rowp1['ug_id'];
$idso1=$rowp1['s_id'];

}
//personal 2
$sqlper2 ="SELECT ug_id, s_id FROM tb_usutrab WHERE ut_codprog = '$cod2' and tp_id='$idtp' and uap_anno='$anno' and uap_mes='$mes' and ut_idserva='$ids' and j_id='$idj'";
$resultper2 = mysqli_query($con, $sqlper2);
while ($rowp2= mysqli_fetch_assoc($resultper2)){
$ugcod2=$rowp2['ug_id'];
$idso2=$rowp2['s_id'];
}
echo "<input type='hidden' id='idj' name='idj' value='".$idj."'>";
echo "<input type='hidden' id='ids' name='ids' value='".$ids."'>";
echo "<input type='hidden' id='idtp' name='idtp' value='".$idtp."'>";
echo "<input type='hidden' id='mes' name='mes' value='".$mes."'>";
echo "<input type='hidden' id='anno' name='anno' value='".$anno."'>";
echo "<input type='hidden' id='ugid' name='ugid' value='".$ugid."'>";

$sql1="update tb_horaprog".$anno." set ut_codprog='XX', ug_id='XXXX', s_id='XXX' where ut_codprog='$cod1' and ug_id='$ugcod1' and uap_anno='$anno' and uap_mes='$mes' and s_id='$idso1' and j_id='$idj' and tp_id='$idtp' and hp_idserva='$ids'";

//echo $sql1."<br>";
$result1 = mysqli_query($con,$sql1);

$sql2="update tb_horaprog".$anno." set ut_codprog=upper('$cod1'), ug_id='$ugcod1', s_id='$idso1' where ut_codprog='$cod2' and ug_id='$ugcod2' and uap_anno='$anno' and uap_mes='$mes' and s_id='$idso2' and j_id='$idj' and tp_id='$idtp' and hp_idserva='$ids'";
//echo $sql2."<br>";
$result2 = mysqli_query($con, $sql2);

$sql3="update tb_horaprog".$anno." set ut_codprog=upper('$cod2'), ug_id='$ugcod2', s_id='$idso2' where ut_codprog='XX' and ug_id='XXXX' and uap_anno='$anno' and uap_mes='$mes' and s_id='XXX' and j_id='$idj' and tp_id='$idtp' and hp_idserva='$ids'";
//echo $sql3."<br>";
$result3 = mysqli_query($con,$sql3);

			echo "<script type='text/javascript'>window.opener.location.reload(); window.close();</script>";
			echo "<script type='text/javascript'>alert('SE CAMBIO TURNOS CORRECTAMENTE')</script>";

}}

//else{
?>
<table align='center'>
<tr><td>

<form action='cambiarturno.php' method=''>
<?php
echo "<input type='hidden' id='idj' name='idj' value='".$idj."'>";
echo "<input type='hidden' id='ids' name='ids' value='".$ids."'>";
echo "<input type='hidden' id='idtp' name='idtp' value='".$idtp."'>";
echo "<input type='hidden' id='mes' name='mes' value='".$mes."'>";
echo "<input type='hidden' id='anno' name='anno' value='".$anno."'>";
echo "<input type='hidden' id='ugid' name='ugid' value='".$ugid."'>";

?>
<fieldset>
	<legend align='left'><font color='blue' size='15'>Ingrese los Codigos ha Cambiar</font></legend>
	<br>
		<table align='center' class='FacetFormTABLE' width='500'>
		<tr><td class='FacetFieldCaptionTDT' colspan='2'><center>ROTACION DE TURNOS</center></td></tr>
		<tr><td colspan='2'><center><font color='red'><?php //if($texto!=""){ echo $texto;}?></font></center></td></tr>
		<tr><td ><center><?php //if($error=='0'){ echo "REVISE LOS DATOS, PERSONAL NO REGISTRADO";}elseif($error=='1'){ echo "PERSONAL REGISTRADO";}?></center></td></tr>
        <tr><td class='FacetFieldCaptionTD'>PERSONAL 1</td><td align='center' class ='FacetDataTextC'><table width='350' align='center'><tr><td align='center' width='50'><input type='text' id='codprog1' name='codprog1' size='4' onKeyPress='buscarpersonal(1)' ></td><td align='center'><div id='divper1'><input type='hidden' id='nombre1' name='nombre1' value='0'></div></td></tr></table></td></tr>
		<tr><td class='FacetFieldCaptionTD'>PERSONAL 2 </td><td align='center' class ='FacetDataTextC'><table width='350' align='center'><tr><td align='center' width='50'><input type='text' id='codprog2' name='codprog2' size='4' onKeyPress='buscarpersonal(2)' ></td><td align='center'><div id='divper2'><input type='hidden' id='nombre2' name='nombre2' value='0'></div></td></tr></table></td></tr>
		<tr><td align='center' colspan='2'><input type='button' id='pprog' style='width:150px' class='FacetButton'  value='Cambiar Turnos' onClick='cambiarturnos();'>
		<button type='button' id='pprog' style='width:150px' class='FacetButton' onClick='ventanaClose();' >Cancelar</button>
		</td></tr></table>
	  <br>
	</fieldset>
</form>
</td><tr>
</table>


<?php
//}
//echo "<script type='text/javascript'>window.opener.location.reload();</script>";

?>
</body>
</html>