<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>
</head>
<body>
<?php
include("../bd/sql_variables.php");
include("paginacion/config_newpag.php");
include("paginacion/my_pagina_class.php");
define("NUM_ROWS",'10');
define("NUM_LINKS",'10');

if(isset($_GET['tprog']) && isset($_GET['tc'])){
$idj=$_GET['idj'];
$ids=$_GET['ids'];
$ugid=$_GET['udig'];
$tc=$_GET['tc'];
$anno=$_GET['anno'];
$mm=$_GET['mes'];
$idtp=$_GET['idtp'];
$nombre=$_GET['nombre'];

if(isset($_GET['tusu'])){
echo "<input type='hidden' id='tusu' name='tusu' value='1'>";
}else{
echo "<input type='hidden' id='tusu' name='tusu' value='0'>";
}


$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");


echo "<input type='hidden' id='idj' value='".$idj."'>";
echo "<input type='hidden' id='ids' value='".$ids."'>";
echo "<input type='hidden' id='mes' value='".$mm."'>";
echo "<input type='hidden' id='anno' value='".$anno."'>";


//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'";
//echo $sqltpersonal;
$resulttpersonal = mysql_query($sqltpersonal);
//$cadenatp="<select id='tipopersonal' name='tipopersonal'>";
$a=0;
$idtp="";
$cadenatp = "<select id='progtp' onchange='buscalistapersonal()'>";
while ($rowtp= mysql_fetch_array($resulttpersonal)){
$cadenatp=$cadenatp."<option value='".$rowtp['cod']."'";
if($a==0){
$cadenatp=$cadenatp." selected ";
$a=1;
$idtp=$rowtp['cod'];
}
$cadenatp=$cadenatp." >".$rowtp['descripcion']."</option>";
}
$cadenatp=$cadenatp."</select>";



//armando grupo de servicios y sus dependencias
$sqldepa="select j_id as codj, 0 as cods ,j_abrev as nom from tb_jefatura where j_id='$idj'";
$sqlserv="select j_id as codj, s_id as cods, s_abrev as nom from tb_servicio where j_id='$idj'";
$resultdepa = mysql_query($sqldepa);
$resultserv = mysql_query($sqlserv);
$a=0;
$cad="";
//$cad = $cad."<tr>";
$serv[] = array();
$nomserv[] = array();
//echo $sqlserv;
while ($rows= mysql_fetch_array($resultserv)){
$a=$a+1;
$serv[$a]=$rows['cods'];
$nomserv[$a]=$rows['nom'];
}
while ($rowj= mysql_fetch_array($resultdepa)){
$a=$a+1;
$serv[$a]=$rowj['cods'];
$nomserv[$a]=$rowj['nom'];
}
//<div id='buscalistado'>
?>


<table align='center'><tr><td colspan='3' align='center' class='LlenarTablaGarea'>LISTADO DEL PERSONAL</td></tr>
<tr><td width='50' class='facetfilaTD'>CODIGO</td><td width='250' class='facetfilaTD' align='center'>NOMBRE DEL PERSONAL</td><td class='facetfilaTD' width='50' align='center'>VER</td></tr>

<?php

if($tc==0){
$_pagi_sql="select a.ug_id as cod, b.ut_codprog as codigo, CONCAT(a.ua_apepat,' ',a.ua_apemat,' ',a.ua_nom) as nombre, ";
$_pagi_sql= $_pagi_sql." b.ut_idserva as idsa from tb_usutrab b  inner join tb_usuasist a on a.ug_id= b.ug_id where b.j_id='$idj' ";
$_pagi_sql= $_pagi_sql." and b.tp_id='$idtp' and b.ut_idserva='$ids' and b.uap_anno='$anno' and b.uap_mes ='$mm' and ";
$_pagi_sql= $_pagi_sql." (a.ua_apepat like '$nombre%' or  a.ua_apemat like '$nombre%' or a.ua_nom like '$nombre%') order by nombre";
//echo $_pagi_sql;
}
if($tc==1){
$_pagi_sql="select a.ug_id as cod, b.ut_codprog as codigo, CONCAT(a.ua_apepat,' ',a.ua_apemat,' ',a.ua_nom) as nombre, ";
$_pagi_sql= $_pagi_sql." b.ut_idserva as idsa from tb_usutrab b  inner join tb_usuasist a on a.ug_id= b.ug_id where b.j_id='$idj' ";
$_pagi_sql= $_pagi_sql." and b.tp_id='$idtp' and b.ut_idserva='$ids' and b.uap_anno='$anno' and b.uap_mes ='$mm' and ";
$_pagi_sql= $_pagi_sql." (a.ua_apepat like '$nombre%' or  a.ua_apemat like '$nombre%' or a.ua_nom like '$nombre%') and a.tc_idcont not in ('3') order by nombre";
//echo $_pagi_sql;
}
if($tc==2){
$_pagi_sql="select a.ug_id as cod, b.ut_codprog as codigo, CONCAT(a.ua_apepat,' ',a.ua_apemat,' ',a.ua_nom) as nombre, ";
$_pagi_sql= $_pagi_sql." b.ut_idserva as idsa from tb_usutrab b  inner join tb_usuasist a on a.ug_id= b.ug_id where b.j_id='$idj' ";
$_pagi_sql= $_pagi_sql." and b.tp_id='$idtp' and b.ut_idserva='$ids' and b.uap_anno='$anno' and b.uap_mes ='$mm' and ";
$_pagi_sql= $_pagi_sql." (a.ua_apepat like '$nombre%' or  a.ua_apemat like '$nombre%' or a.ua_nom like '$nombre%') and a.tc_idcont in ('3') order by nombre";
//echo $_pagi_sql;
}
}else{

if(isset($_GET['tusu'])){
echo "<input type='hidden' id='tusu' name='tusu' value='1'>";
}else{
echo "<input type='hidden' id='tusu' name='tusu' value='0'>";
}

$_pagi_sql="select a.ug_id as cod, b.ut_codprog as codigo, CONCAT(a.ua_apepat,' ',a.ua_apemat,' ',a.ua_nom) as nombre, ";
$_pagi_sql= $_pagi_sql." b.ut_idserva as idsa from tb_usutrab b  inner join tb_usuasist a on a.ug_id= b.ug_id where b.j_id='$idj' ";
$_pagi_sql= $_pagi_sql." and b.tp_id='$idtp' and b.ut_idserva='$ids' and b.uap_anno='$anno' and b.uap_mes ='$mm' ";
$_pagi_sql= $_pagi_sql."  order by nombre";
}
//Echo $_pagi_sql."<br>";

	$test = new MyPagina;
       $test->sql = $_pagi_sql;
       $result = $test->get_page_result(); 
       $num_rows = $test->get_page_num_rows();  
       $nav_links = $test->navigation(" | ", "currentStyle"); 
	   $nav_info = $test->page_info("al"); 
       $simple_nav_links = $test->back_forward_link(); 
       $total_recs = $test->get_total_rows(); 


		if ($total_recs>=1)
	   {
		 $i = 0;
		 do
   		 {
		 $ugid = mysql_result($result, $i, "cod");
		 $codprog = mysql_result($result, $i, "codigo");
		 $nombre = mysql_result($result, $i, "nombre");
   		 

		echo "<tr><td align='center' width='50' class ='FacetDataTextC'>".$codprog."</td><td width='300' class ='FacetDataTextC'>".$nombre."</td><td align='center' class ='FacetDataTextC'><img src='../img/ver.jpg' width='17' height='17' value='$ugid' onClick=verprog(this.value);></td></tr>";

		$i++;
  		}while($i < $num_rows);}
  
echo "</table><br>";

echo "<table align='center'><tr><td colspan='4' class='FacetFieldCaptionTD' align='center'><center>";
 if ((isset($total_recs))&&($total_recs>=1)){ echo ' Registros(s) del '.$nav_info.' de '.$total_recs.' encontrado(s).' ;}else{ echo '0 Registros(s) encontrado(s).';} 
 echo "</center></td></tr><tr><td colspan='4' class='FacetFieldCaptionTD' align='center'><center>";
 if (isset($total_recs)){ echo $nav_links; }
echo "</center></td></tr></table>"; 
//</div>
	?>

</body>
</html>