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

date_default_timezone_set("America/Lima"); setlocale(LC_TIME,"es_PE.UTF-8");

$mes =date('n',time());

//$mes =2;
$sqljefatura="select distinct(b.j_id) as id, (select j_desc from tb_jefatura where j_id=b.j_id) as jefatura ";
$sqljefatura=$sqljefatura." from tb_usuasist a inner join tb_usudep b on a.ug_id = b.ug_id where month(a.ua_fechanac)='$mes' and b.ua_estado not in (0)";
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles/Style.css">
</head>
<body>
<br>
<?php
$arraymes = array();
$arraymes[] = array('idmes'=>'1','mes'=>'ENERO');
$arraymes[] = array('idmes'=>'2','mes'=>'FEBRERO');
$arraymes[] = array('idmes'=>'3','mes'=>'MARZO');
$arraymes[] = array('idmes'=>'4','mes'=>'ABRIL');
$arraymes[] = array('idmes'=>'5','mes'=>'MAYO');
$arraymes[] = array('idmes'=>'6','mes'=>'JUNIO');
$arraymes[] = array('idmes'=>'7','mes'=>'JULIO');
$arraymes[] = array('idmes'=>'8','mes'=>'AGOSTO');
$arraymes[] = array('idmes'=>'9','mes'=>'SETIEMBRE');
$arraymes[] = array('idmes'=>'10','mes'=>'OCTUBRE');
$arraymes[] = array('idmes'=>'11','mes'=>'NOVIEMBRE');
$arraymes[] = array('idmes'=>'12','mes'=>'DICIEMBRE');

$resultf = mysqli_query($con, $sqljefatura);
if(mysqli_num_rows($resultf)!=0){
$cadena = "<table width='280' align='center' class='FacetFormTABLE'><tr><td colspan='2' align='center' class='FacetFieldCaptionTT'>ONOMASTICOS EN ".$arraymes[$mes-1]['mes']."</td></tr>";
while ($row= mysqli_fetch_assoc($resultf)){
$idj = $row['id'];
$jefatura = $row['jefatura'];

$cadena = $cadena."<tr><td colspan='2' align='center' class='FacetFieldCaptionTDR'>".$jefatura."</td></tr>";

$sqljefaturas="select distinct(b.s_id) as id, (select s_desc from tb_servicio where j_id=b.j_id and s_id=b.s_id) as jefatura ";
$sqljefaturas=$sqljefaturas." from tb_usuasist a inner join tb_usudep b on a.ug_id = b.ug_id where month(a.ua_fechanac)='$mes' and b.j_id='$idj'";
//echo $sqljefaturas;
$resultfs = mysqli_query($con, $sqljefaturas);
if(mysqli_num_rows($resultfs)!=0){
while ($rows= mysqli_fetch_assoc($resultfs)){
$ids = $rows['id'];
$jefaturas = $rows['jefatura'];
$cadena = $cadena."<tr><td colspan='2' align='center' class='FacetFieldCaptionTDT'>".$jefaturas."</td></tr>";
//pregunta por el personal de onomastico
$sqlask="select a.ug_id as coduni, concat(a.ua_apepat,' ', a.ua_apemat,' ', a.ua_nom) as nombre, date_format(a.ua_fechanac, '%d/%m/%Y') as fechanac, day(a.ua_fechanac) as dia from tb_usuasist a inner join ";
$sqlask=$sqlask." tb_usudep b on a.ug_id = b.ug_id where b.j_id='$idj' and b.s_id='$ids' and month(a.ua_fechanac)='$mes' and b.ua_estado not in (0) order by dia asc";
//echo $sqlask;
$resultdia = mysqli_query($con, $sqlask);
if(mysqli_num_rows($resultdia)!=0){
$cadena = $cadena."<tr><td align='center' class='FacetFieldCaptionTL'>PERSONAL</td><td align='center' class='FacetFieldCaptionTL'>DIA</td></tr>";
$color = 1;
while ($rowp= mysqli_fetch_assoc($resultdia)){
$coduni = $rowp['coduni'];
$nombre = $rowp['nombre'];
$dia = $rowp['dia'];
if($color==1){
$cadena = $cadena."<tr><td class='FacetFieldCaptionON'>".$nombre."</td><td align='center' class='FacetFieldCaptionON'>".$dia."</td></tr>";
$color =0;
}else{
$cadena = $cadena."<tr><td class='FacetFieldCaptionUP'>".$nombre."</td><td align='center' class='FacetFieldCaptionUP'>".$dia."</td></tr>";
$color=1;
}
}
}
}}

}}

echo $cadena;
?>
</body>
</html>