<?php

include("../bd/sql_variables.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");

$idj = $_GET['idj'];
$ids = $_GET['ids'];
$ugid = $_GET['ugid'];

//$idj='1';
//$ids='2';

//seleccionando al combo tipo de personal
$sqltpersonal = "select a.tp_id as cod, (select tp_desc from tb_tipoperson where tp_id=a.tp_id) as descripcion from tb_areatipopersona a where a.j_id='$idj' and a.s_id='$ids'";
$resulttpersonal = mysql_query($sqltpersonal);
$cadenatp="<select id='tipopersonal' onChange='listarpersonal();'><option value='0' selected>TODOS</option>";
while ($rowtp= mysql_fetch_array($resulttpersonal)){
$cadenatp=$cadenatp."<option value='".$rowtp['cod']."'>".$rowtp['descripcion']."</option>";
}
$cadenatp=$cadenatp."</select>";

//seleccionando al comnbo especialidad
$sqlespecialidad = "select a.ua_idespec as cod, (select esp_desc from tb_especialidad where ua_idespec=a.ua_idespec) as descripcion from tb_areaespecialidad a where a.j_id='$idj' and a.s_id='$ids'";
$resultespecialidad = mysql_query($sqlespecialidad);
$cadenaesp="<select id='especialidad' onChange='listarpersonal();'><option value='0' selected>TODOS</option>";
while ($rowe= mysql_fetch_array($resultespecialidad)){
$cadenaesp=$cadenaesp."<option value='".$rowe['cod']."'>".$rowe['descripcion']."</option>";
}
$cadenaesp=$cadenaesp."</select>";


//construytento listado
$sqllistado = "select a.ug_id as cod, concat(a.ua_apepat,' ',a.ua_apemat,' ',a.ua_nom) as nombre, (select esp_desc from tb_especialidad ";
$sqllistado = $sqllistado." where ua_idespec=a.ua_idespec) as especialidad, date_format(b.ud_fechaing,'%d/%m/%Y') as fingreso, (select tc_abrev from tb_tipocont ";
$sqllistado = $sqllistado." where tc_idcont=a.tc_idcont) as tipocontrato, (select tp_desc from tb_tipoperson where tp_id=b.tp_id) as tpersona from tb_usuasist a inner join tb_usudep b on ";
$sqllistado = $sqllistado." a.ug_id = b.ug_id where b.j_id='$idj' and b.s_id='$ids' and (a.ua_estado= 1 or a.ua_estado= 2) order by nombre, especialidad";
//$sqllistado = $sqllistado." a.ug_id = b.ug_id where b.j_id='$idj' and b.s_id='$ids' and b.tp_id=1 and a.ua_idespec='2'";
//echo $sqllistado;
$resultlistado = mysql_query($sqllistado);
$sumap=0;
while ($rowl= mysql_fetch_array($resultlistado)){
$codigo=$rowl['cod'];
$cadenalis=$cadenalis."<tr><td align='left'>".$rowl['nombre']."</td><td align='center'>".$rowl['tpersona']."</td><td align='center'>".$rowl['especialidad']."</td><td align='center'>".$rowl['tipocontrato']."</td><td align='center'>".$rowl['fingreso']."</td><td align='center'><img src='img/b_edit.png' value='$codigo' onClick=editarpersonal(this.value);></td><td align='center'><img src='img/ver.jpg' width='17' height='17' value='$codigo' onClick=transferirpersonal(this.value);></td><td align='center'><img src='img/b_drop.png' value='$codigo' onClick=suspenderpersonal(this.value);></td><td align='center'><img src='img/ver.jpg' width='17' height='17' id='person' value='$codigo' onClick=datospersonal(this.value);></td></tr>";
$sumap=$sumap+1;
}
$cadenalis=$cadenalis."<tr><td colspan='8' align='center'>El numero de Personal es ".$sumap."</td></tr>";
?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<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 agregarpersonal(){
	var idj = document.getElementById("depa").value;
	var ids = document.getElementById("serv").value;
    var ugid = document.getElementById("ugid").value;
   window.open("adminpersonal.php?idj="+idj+"&ids="+ids+"&ugid="+ugid,"","height=400,width=600,scrollbars=NO");
}
function datospersonal(codigo){
	var idj = document.getElementById("depa").value;
	var ids = document.getElementById("serv").value;
	window.open("vistapersonal.php?ugid="+codigo+"&idj="+idj+"&ids="+ids,"","height=410,width=390,scrollbars=NO");
} 
function transferirpersonal(codigo){
	var idj = document.getElementById("depa").value;
	var ids = document.getElementById("serv").value;
	window.open("transferirpersonal.php?ugid="+codigo+"&idj="+idj+"&ids="+ids,"","height=200,width=700,scrollbars=NO");
} 
function editarpersonal(codigo){
		var idj = document.getElementById("depa").value;
		var ids = document.getElementById("serv").value;
		window.open("modificarpersonal.php?ugid="+codigo+"&idj="+idj+"&ids="+ids,"","height=400,width=600,scrollbars=NO");
} 
function suspenderpersonal(codigo){
		window.open("suspenderpersonal.php?ugid="+codigo,"","height=400,width=600,scrollbars=NO");
} 
function retornarmenu(){
		var idj = document.getElementById("depa").value;
		var ids = document.getElementById("serv").value;
        var ugid = document.getElementById("ugid").value;		
		document.location= "menuadmin.php?idj="+idj+"&ids="+ids+"&ugid="+ugid;
} 
</script> 
</head>
<body id="lista" name="lista">
<?php
echo "<input type='hidden' id='depa' name='depa' value='".$idj."'>";
echo "<input type='hidden' id='serv'  name='serv' value='".$ids."'>";
echo "<input type='hidden' id='ugid'  name='ugid' value='".$ugid."'>";
?>
<table align='center'>
<tr><td>
<div id='adminpersonal'>
<fieldset>
	<legend align='left'><font color='blue'>Listado del Personal Asistencial</font></legend>
	<br>
	<table align='center' ><tr><td align='left'>Tipo de Personal</td>
	<td><?php echo $cadenatp;?></td>
	<td align='left'>Especialidad</td>
	<td><?php echo $cadenaesp;?></td>
	<td align='center'><button type='button' id='pprog' style='width:80px' class='FacetButton' onclick='agregarpersonal();' >Agregar<br>Nuevo<br>Personal</button></td><td width='50'></td><td><button type='button' id='pprog' style='width:80px' class='FacetButton' onclick='retornarmenu();' >Retornar Al<br>Menu Principal</button></td>
	</tr></table>
	<br>
	<div id='admlista'>
	<table align='center' class='FacetFormTABLE'>
	<tr><td colspan='9'class='FacetFieldCaptionTDT' align='center'> PERSONAL ASISTENCIAL </td></tr>
	<tr><td class='FacetFieldCaptionTD' align='center' width='250'>APEDLLIDOS Y NOMBRES</td><td class='FacetFieldCaptionTD' align='center' width='130'>TIPO PERSONAL</td><td class='FacetFieldCaptionTD' align='center' width='130'>ESPECIALIDAD</td><td class='FacetFieldCaptionTD' align='center' width='130'>TIPO DE CONTRATO</td><td class='FacetFieldCaptionTD' align='center' width='100'>FECHA DE INGRESO</td><td class='FacetFieldCaptionTD' align='center'>EDITAR</td><td class='FacetFieldCaptionTD' align='center'>TRANSF</td><td class='FacetFieldCaptionTD' align='center'>SUSPE</td><td class='FacetFieldCaptionTD' align='center'>DATOS</td></tr>
	
	<?php echo $cadenalis;?>
	
	</table>
	</div>
	<br>
</fieldset>
</td></tr>
</table>
</body>
</html>