<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>SUSPENSION DEL PERSONAL</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 suspenderPersonal(){
   var repro = document.getElementById("repro").value;
    var idso = document.getElementById("idso").value;
	var tsus = document.getElementById("tsus").value;
	var msus = document.getElementById("msus").value;
	var ths = document.getElementById("ths").value;
	var descsusp = document.getElementById("descsusp").value;
	
   var he = document.getElementById("he").value;
   var idj = document.getElementById("idj").value;
   var ids = document.getElementById("ids").value;
   var idh = document.getElementById("idh").value;
   var idga = document.getElementById("idga").value;
   var ida = document.getElementById("ida").value;
   var idtp = document.getElementById("idtp").value;
   var cod = document.getElementById("cod").value;
   var ugcod = document.getElementById("ugcod").value;
   var ugid = document.getElementById("ugid").value;
   var dia = document.getElementById("dia").value;
   var mes = document.getElementById("mes").value;
   var anno = document.getElementById("anno").value;
   var codtxt = document.getElementById("codprog").value;
   var horario = document.getElementById("horario").value;
   var turno = document.getElementById("turno").value;
var cadena = "suspenderpersonal.php?idj="+idj+"&ids="+ids+"&dia="+dia+"&mes="+mes+"&anno="+anno+"&ugid="+ugid+"&repro=1&idso="+idso+"&tsus="+tsus;
cadena = cadena + "&msus="+msus+"&descsusp="+descsusp+"&he="+he+"&idh="+idh+"&idga="+idga+"&ida="+ida+"&idtp="+idtp+"&cod="+cod+"&ugcod="+ugcod+"&ugid="+ugid+"&codtxt="+codtxt+"&horario="+horario+"&turno="+turno+"&ths="+ths;
document.location= cadena;   
}
</script>
</head>
<body>
<?php

include("../bd/sql_variables.php");
include("validareprogramacion.php");

$db_conexion= mysql_connect("$sql_host", "$sql_usuario", "$sql_pass") or die(header ("No Disponible Servidor de Base de Datos"));
mysql_select_db("$sql_db");
$he=$_GET['he'];
$idj=$_GET['idj'];
$ids=$_GET['ids'];
$idh=$_GET['idh'];
$idga=$_GET['idga'];
$ida=$_GET['ida'];
$idtp=$_GET['idtp'];
$cod=$_GET['cod'];
$ugid=$_GET['ugid'];
$dia=$_GET['dia'];
$mes=$_GET['mes'];
$anno=$_GET['anno'];
$turno = $_GET['turno'];


$sqlper ="SELECT ug_id, s_id FROM tb_usutrab WHERE ut_codprog = '$cod' and tp_id='$idtp' and uap_anno='$anno' and uap_mes='$mes' and ut_idserva='$ids' and j_id='$idj'";
$resultper = mysql_query($sqlper);
while ($rowpp= mysql_fetch_array($resultper)){
$ugcod=$rowpp['ug_id'];
$idso=$rowpp['s_id'];
//seleccionando al personal
$sqlp = "select concat(ua_apepat,' ',ua_apemat,' ',ua_nom) as nombre from tb_usuasist where ug_id='$ugcod'";
//echo $sqltc;
$resultp = mysql_query($sqlp);
while ($rowp= mysql_fetch_array($resultp)){
$nombre = $rowp['nombre'];
}
}
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='idso' name='idso' value='".$idso."'>";
echo "<input type='hidden' id='idh' name='idh' value='".$idh."'>";
echo "<input type='hidden' id='idga' name='idga' value='".$idga."'>";
echo "<input type='hidden' id='ida' name='ida' value='".$ida."'>";
echo "<input type='hidden' id='idtp' name='idtp' value='".$idtp."'>";
echo "<input type='hidden' id='cod' name='cod' value='".$cod."'>";
echo "<input type='hidden' id='ugcod' name='ugcod' value='".$ugcod."'>";
echo "<input type='hidden' id='idso' name='idso' value='".$idso."'>";
echo "<input type='hidden' id='dia' name='dia' value='".$dia."'>";
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."'>";
echo "<input type='hidden' id='turno' name='turno' value='".$turno."'>";

if(isset($_GET['repro'])){
$idso = $_GET['idso'];
$tipos = $_GET['tsus'];
$tipom = $_GET['msus'];
$ths = $_GET['ths'];
$obs = $_GET['descsusp'];

$tipoh=$_GET['he'];
$idj=$_GET['idj'];
$ids=$_GET['ids'];
$idh=$_GET['idh'];
$idga=$_GET['idga'];
$ida=$_GET['ida'];
$idtp=$_GET['idtp'];
$cod=$_GET['cod'];
$ugcod=$_GET['ugcod'];
$ugid=$_GET['ugid'];
$dia=$_GET['dia'];
$mes=$_GET['mes'];
$anno=$_GET['anno'];
$codtxt=$_GET['codtxt'];
$idhp = $_GET['horario'];
$turno = $_GET['turno'];

$valor = validareprog($anno, $mes, $dia, $idj, $ids, $idtp, $codtxt, $idga, $ida, $idhp);
//1 cruce de horario en el serv
//6 cruce de hoarario con otro serv
//2 post guardia en el serv
//7 post guardia entre serv
//3 cumpleanos
//4 vacaciones
//5 descanso medico
//8 mas de 10 guardias
if($valor=='1'){
$texto = "CRUCE CON OTRO TURNO EN EL SERVICIO";
}
if($valor=='2'){
$texto = "SALIO DE GUARDIA NOCTURNA EN EL SERVICIO";
}
if($valor=='3'){
$texto = "ONOMASTICO DEL PERSONAL";
}
if($valor=='4'){
$texto = "ESTA DE VACACIONES";
}
if($valor=='5'){
$texto = "PERSONAL CON DESCANSO MEDICO";
}
if($valor=='6'){
$texto = "CRUCE CON OTRO TURNO EN OTRO SERVICIO";
}
if($valor=='7'){
$texto = "SALIO DE GUARDIA NOCTURNA EN OTRO SERVICIO";
}
if($valor=='8'){
$texto = "YA TIENE 10 GUARDIAS";
}

if($valor=='0'){
$sqldelrepro="insert into tb_suspension value ('$dia',UPPER('$cod'),'$idh','$ida','$idga','$idtp','$ugcod','$anno','$mes','$ids','$idj','$tipoh','$ids','$ugid','$tipos','$tipom',UPPER('$obs'),now())";
$resultrepro = mysql_query($sqldelrepro);
if ($resultrepro == false){
echo 'NO SE PUEDE SUSPENDER PERSONAL';
//echo $sqldelrepro;
}else{
	$sqlsusp="delete from tb_horareprog".$anno." where ug_id='$ugcod' and hr_dia='$dia' and uap_mes='$mes' and uap_anno='$anno' and hr_idserva='$ids' and j_id='$idj' and h_id='$idh' and a_id='$ida' and ga_id='$idga' and tp_id='$idtp'";
	$resultsusp = mysql_query($sqlsusp);
	//echo $sqlsusp;
	//$sqlask="select * from tb_suspension where ug_id='$ugcod' and ss_dia='$dia' and uap_mes='$mes' and uap_anno='$anno' and ss_idserva='$ids' and j_id='$idj' and h_id='$idh' and a_id='$ida' and ga_id='$idga' and tp_id='$idtp'";
	//echo $sqlask;
		if ($resultsusp == false){
		echo 'NO SE REGISTRO LA SUSPENSION';
		}else{
			//registra al persona q reemplaza
			if($codtxt!=''){
			$valor = guardarturno($anno, $mes, $dia, $idj, $ids, $idtp, $codtxt, $idga, $ida, $idhp, $ugid, $ths);
			if($valor==10){
			echo "<script type='text/javascript'>alert('SE REGISTRO CORRECTAMENTE')</script>";
			echo "<script type='text/javascript'>window.opener.location.reload(); window.close();</script>";
			}}}}
			echo "<script type='text/javascript'>alert('SE SUSPENDIO CORRECTAMENTE')</script>";
			echo "<script type='text/javascript'>window.opener.location.reload(); window.close();</script>";

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

<form action='suspenderpersonal.php' method=''>
<?php
echo "<input type='hidden' id='he' name='he' value='".$he."'>";
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='idso' name='idso' value='".$idso."'>";
echo "<input type='hidden' id='idh' name='idh' value='".$idh."'>";
echo "<input type='hidden' id='idga' name='idga' value='".$idga."'>";
echo "<input type='hidden' id='ida' name='ida' value='".$ida."'>";
echo "<input type='hidden' id='idtp' name='idtp' value='".$idtp."'>";
echo "<input type='hidden' id='cod' name='cod' value='".$cod."'>";
echo "<input type='hidden' id='ugcod' name='ugcod' value='".$ugcod."'>";
echo "<input type='hidden' id='idso' name='idso' value='".$idso."'>";
echo "<input type='hidden' id='dia' name='dia' value='".$dia."'>";
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."'>";
echo "<input type='hidden' id='turno' name='turno' value='".$turno."'>";

//combobox /busca primer horario de area
if($turno==1){
$sqlh = "select a.h_id as idh, concat(date_format(b.h_horaini,'%k:%i %p'), ' - ',date_format(b.h_horafin,'%k:%i %p')) as hora, h_horaturn as turno, h_horanum as numhora from areahora a inner join tb_horario b on a.h_id=b.h_id where a.s_id='$ids' and a.j_id='$idj' and a.ga_id='$idga' and a.a_id='$ida' and a.ah_estado=1 and b.h_horaturn in ('D','M')";
}
if($turno==3){
$sqlh = "select a.h_id as idh, concat(date_format(b.h_horaini,'%k:%i %p'), ' - ',date_format(b.h_horafin,'%k:%i %p')) as hora, h_horaturn as turno, h_horanum as numhora from areahora a inner join tb_horario b on a.h_id=b.h_id where a.s_id='$ids' and a.j_id='$idj' and a.ga_id='$idga' and a.a_id='$ida' and a.ah_estado=1 and b.h_horaturn in ('T')";
}
if($turno==4){
$sqlh = "select a.h_id as idh, concat(date_format(b.h_horaini,'%k:%i %p'), ' - ',date_format(b.h_horafin,'%k:%i %p')) as hora, h_horaturn as turno, h_horanum as numhora from areahora a inner join tb_horario b on a.h_id=b.h_id where a.s_id='$ids' and a.j_id='$idj' and a.ga_id='$idga' and a.a_id='$ida' and a.ah_estado=1 and b.h_horaturn in ('N')";
}
//echo $sqlh;
$resulth = mysql_query($sqlh);
if ($resulth == false){
echo 'PROVOCO UN ERROR EN LA CONSULTA 1';
}else{
$horario = "<select name='horario' id='horario'>";
while ($rowh= mysql_fetch_array($resulth)){
$horario = $horario."<option value='".$rowh['idh']."'>".$rowh['hora']."</option>";
}
$horario=$horario."</select>";
}


?>
<fieldset>
	<legend align='left'><font color='blue' size='15'>Registre Datos de Suspencion </font></legend>
	<br>
		<table align='center' class='FacetFormTABLE' width='500'>
		<tr><td class='FacetFieldCaptionTDT' colspan='2'><center>SUSPENSION DEL PERSONAL ASISTENCIAL</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' width='150'>PERSONAL A SUSPENDER </td><td align='center' class ='FacetDataTextC'><?php echo $nombre; ?></td></tr>
		<tr><td class='FacetFieldCaptionTD'>TIPO DE SUSPENSION</td><td align='center' class ='FacetDataTextC'><select id='tsus' name='tsus'>
		<option value='1'>Rotacion de Area</option>
		<option value='2'>Rotacion de Turno</option>
		<option value='3'>Suspension</option>
		</select></td></tr>
		<tr><td class='FacetFieldCaptionTD'>MOTIVO DE SUSPENSION</td><td align='center' class ='FacetDataTextC'><select id='msus' name='msus'>
		<option value='1'>Necesidad de Servicio</option>
		<option value='2'>Solicitud del Personal</option>
		<option value='3'>Otro</option>
		</select></td></tr>
		<tr><td class='FacetFieldCaptionTD'>NOMBRE DEL PERSONAL QUE REEMPLAZA </td><td align='center' class ='FacetDataTextC'><table width='350' align='center'><tr><td align='center' width='50'><input type='text' id='codprog' name='codprog' size='4' onKeyPress='buscarpersonal()' ></td><td align='center'><div id='divper'><input type='hidden' id='nombre' name='nombre' value='0'></div></td></tr></table></td></tr>
		<tr><td class='FacetFieldCaptionTD'>HORARIO</td>
		<td align='center' class ='FacetDataTextC'><select id='ths' name='ths'>
		<option value='0'>HORA ORDINARIA</option>
		<option value='1'>HORA EXTRA</option>
		</select></td></tr>
		<tr><td class='FacetFieldCaptionTD'>TIPO DE HORA</td>
		<td align='center' class ='FacetDataTextC'><?php echo $horario;?></td></tr>
		
		<tr><td class='FacetFieldCaptionTD' colspan='2'>OBSERVACIONES</td></tr>
		<tr><td colspan='2' class ='FacetDataTextC'><input type='text' id='descsusp' name='descsusp' size='80'></td></tr>
		<input type='hidden' id='repro' name='repro' value='1'>
		<tr><td align='center' colspan='2'><input type='button' id='pprog' style='width:150px' class='FacetButton'  value='Suspender' onClick='suspenderPersonal();'>
		<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>