<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>SISTEMA INTEGRADO DE LA PROGRAMACION ASISTENCIAL</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"> 
//ver programacion
function verprog(ugid){
alert(ugid);
var mes = document.getElementById("mes").value;
var anno= document.getElementById("anno").value;
window.open("verdetalle.php?ugid="+ugid+"&anno="+anno+"&mes="+mes,"","height=300,width=600,scrollbars=NO");
}
</script>
</head>
<body>
<?php

//if(isset($_GET['idj']) && isset($_GET['ids']) && isset($_GET['idtp']) && isset($_GET['anno'])  && isset($_GET['mes'])){
//$idj = $_GET['idj'];
//$ids = $_GET['ids'];
//$per = $_GET['idtp'];
//$anno = $_GET['anno'];
//$mm = $_GET['mes'];
//}


//$idj = 1;
//$ids = 2;
//$idtp = 1;
//$anno = 2011;
//$mm = 1;

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

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

//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)){
$cad = $cad."<td width='10' class='facetfilaTD' colspan='4' align='center' >".$rows['nom']."</td>";
$a=$a+1;
$serv[$a]=$rows['cods'];
$nomserv[$a]=$rows['nom'];
}
while ($rowj= mysql_fetch_array($resultdepa)){
$cad = $cad."<td width='10' class='facetfilaTD' colspan='4'  align='center' >".$rowj['nom']."</td>";
$a=$a+1;
$serv[$a]=$rowj['cods'];
$nomserv[$a]=$rowj['nom'];
}

$cdhrs ="<td class='facetfilaTD'>GD</td><td class='facetfilaTD'>GN</td><td class='facetfilaTD'>HO</td><td class='facetfilaTD'>HE</td>";

$ncadena = 4*(count($serv)-1);
$ntotal = $ncadena + 11;
$cadena1 = "<table><tr><td colspan='$ntotal' align='center'>LISTADO DEL PERSONAL PROGRAMADO</td></tr>";
$cadena1 = $cadena1."<tr><td width='50' class='facetfilaTD' rowspan='3'>CODIGO</td><td width='300' class='facetfilaTD' rowspan='3' align='center'>NOMBRE DEL PERSONAL</td><td width='300' class='facetfilaTD' colspan='$ncadena' align='center'>SERVICIOS PROGRAMADOS</td><td class='facetfilaTD' align='center' rowspan='2' colspan='4'  >TOTALES</td><td class='facetfilaTD' align='center' rowspan='3'>HRS A <br>PROGRAMAR<br> X MES</td><td class='facetfilaTD' align='center' rowspan='3' colspan='4'>PROG<BR>INDIVIDUAL</td></tr>";
$cadena1 = $cadena1."<tr>".$cad."</tr>";

//pregunta por el personal
$sqlper1="select a.ug_id as cod, b.ut_codprog as codigo, CONCAT(a.ua_apepat,' ',a.ua_apemat,' ',a.ua_nom) as nombre, ";
$sqlper1= $sqlper1." 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'";
$sqlper1= $sqlper1." and b.tp_id='$idtp' and b.ut_idserva='$ids' and b.uap_anno='$anno' and b.uap_mes ='$mm' order by nombre";
//Echo $sqlper1."<br>";
//horas por los servicios
$cadena1 = $cadena1."<tr>";
for($i=0;$i<count($serv)-1;$i++){
$cadena1 = $cadena1.$cdhrs;
}
$cadena1 = $cadena1.$cdhrs."</tr>";

$resultper = mysql_query($sqlper1);
while ($rowp= mysql_fetch_array($resultper)){
$ugid = $rowp['cod'];
$codprog = $rowp['codigo'];
$nombre = $rowp['nombre'];
$registro=$registro."<tr><td align='center'>".$codprog."</td><td>".$nombre."</td>";
//listado al persoonal 
for($i=0;$i<count($serv)-1;$i++){
$idso = $serv[$i+1];
$sqlhoras="select chp_numgd as gd, chp_numgn as gn, chp_numho as ho, chp_numhe as he from tb_consolhprog where ug_id='$ugid' and uap_anno='$anno' and uap_mes='$mm' and ut_idserva='$idso' and tp_id='$idtp' and j_id='$idj'";
//echo $sqlhoras."<br>";
$resulthoras = mysql_query($sqlhoras);
	if(mysql_num_rows($resulthoras)==0){
			$registro=$registro."<td>-</td><td>-</td><td>-</td><td>-</td>";
	}else{
	while ($rowhs= mysql_fetch_array($resulthoras)){
		$gd = $rowhs['gd'];
		$gn = $rowhs['gn'];
		$ho = $rowhs['ho'];
		$he = $rowhs['he'];
	
		$registro=$registro."<td>".$gd."</td><td>".$gn."</td><td>".$ho."</td><td>".$he."</td>";
	}
	}
}

//total de horas
$sqltotalhrs="select sum(chp_numgd) as tgd, sum(chp_numgn) as tgn, sum(chp_numho) as tho, sum(chp_numhe) as the from tb_consolhprog where ug_id='$ugid' and uap_anno='$anno' and uap_mes='$mm' and tp_id='$idtp'";
$resultthrs = mysql_query($sqltotalhrs);
//echo $sqltotalhrs."<br>";
	if(mysql_num_rows($resultthrs)==0){
			$registro=$registro."<td>0</td><td>0</td><td>0</td><td>0</td>";
			echo 0;
	}else{
		while ($rowth= mysql_fetch_array($resultthrs)){
		
		$tgd = $rowth['tgd'];
		$tgn = $rowth['tgn'];
		$tho = $rowth['tho'];
		$the = $rowth['the'];
	
		$registro=$registro."<td align='center'>".$tgd."</td><td align='center'>".$tgn."</td><td align='center'>".$tho."</td><td align='center'>".$the."</td>";
	}}


//cantidad de horas programadas por mes
$sqltotalhrs="select b.tc_hrsprog as hora from tb_usuasist a inner join tb_tipocont b on a.tc_idcont = b.tc_idcont where a.ug_id='$ugid'";
$resulttproghrs = mysql_query($sqltotalhrs);
while ($rowtph= mysql_fetch_array($resulttproghrs)){
		$thrs = $rowtph['hora'];
			
		$registro=$registro."<td align='center'>".$thrs."</td><td align='center' class='FacetDataTextC'><input class='FacetButton' type='button' value='VER' onClick='verprog(".$ugid.")'></td></tr>";
	}

}
ECHO $cadena1.$registro;
?>
</body>
</html>