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

if(isset($_GET['idj']) && isset($_GET['ids']) && isset($_GET['mes']) && isset($_GET['anno'])){
$idj=$_GET['idj'];
$ids=$_GET['ids'];
$anno=$_GET['anno'];
$mes=$_GET['mes'];
$idtp=$_GET['idtp'];
if($idtp==0){
$sqlask="SELECT  concat(b.ua_apepat,' ',b.ua_apemat,' ',b.ua_nom) as nombre, ";
$sqlask=$sqlask." (select tp_desc from tb_tipoperson where tp_id=c.tp_id) as tipo_personal, ";
$sqlask=$sqlask." concat(date_format(a.dm_fechaini,'%d/%m/%Y'),' - ', date_format(a.dm_fechafin,'%d/%m/%Y'),' (', a.dm_numdias,')') as fecha, ";
$sqlask=$sqlask." a.dm_obs as observ FROM tb_descmed a inner join tb_usuasist b on a.ug_id= b.ug_id inner join tb_usudep c on b.ug_id=c.ug_id where  (month(a.dm_fechaini)='$mes' or ";
$sqlask=$sqlask." month(a.dm_fechafin)='$mes') and (year(a.dm_fechaini)='$anno' or year(a.dm_fechafin)='$anno') and c.j_id='$idj' and c.s_id='$ids'";
}else{
$sqlask="SELECT  concat(b.ua_apepat,' ',b.ua_apemat,' ',b.ua_nom) as nombre, ";
$sqlask=$sqlask." (select tp_desc from tb_tipoperson where tp_id=c.tp_id) as tipo_personal, ";
$sqlask=$sqlask." concat(date_format(a.dm_fechaini,'%d/%m/%Y'),' - ', date_format(a.dm_fechafin,'%d/%m/%Y'),' (', a.dm_numdias,')') as fecha, ";
$sqlask=$sqlask." a.dm_obs as observ FROM tb_descmed a inner join tb_usuasist b on a.ug_id= b.ug_id inner join tb_usudep c on b.ug_id=c.ug_id where  (month(a.dm_fechaini)='$mes' or ";
$sqlask=$sqlask." month(a.dm_fechafin)='$mes') and (year(a.dm_fechaini)='$anno' or year(a.dm_fechafin)='$anno') and c.j_id='$idj' and c.s_id='$ids' and c.tp_id='$idtp'";
}

}else{
$sqlask="SELECT  concat(b.ua_apepat,' ',b.ua_apemat,' ',b.ua_nom) as nombre, ";
$sqlask=$sqlask." (select tp_desc from tb_tipoperson where tp_id=c.tp_id) as tipo_personal, ";
$sqlask=$sqlask." concat(date_format(a.dm_fechaini,'%d/%m/%Y'),' - ', date_format(a.dm_fechafin,'%d/%m/%Y'),' (', a.dm_numdias,')') as fecha, ";
$sqlask=$sqlask." a.dm_obs as observ FROM tb_descmed a inner join tb_usuasist b on a.ug_id= b.ug_id inner join tb_usudep c on b.ug_id=c.ug_id where  (month(a.dm_fechaini)='$mes' or ";
$sqlask=$sqlask." month(a.dm_fechafin)='$mes') and (year(a.dm_fechaini)='$anno' or year(a.dm_fechafin)='$anno') and c.j_id='$idj' and c.s_id='$ids'";
}
//echo $sqlask;



$resultdm = mysqli_query($con,$sqlask);
if(mysqli_num_rows($resultdm)!=0){
$salida = "<table><tr><td class='Listadohead' width='280'>APELLIDOS Y NOMBRES </td><td class='Listadohead' width='200'>TIPO DE PERSONAL</td><td class='Listadohead' width='200'>FECHA DEL DM</td><td class='Listadohead' width='250'>OBSERVACIONES</td></tr>";
while($row = mysqli_fetch_assoc($resultdm)){
$observ= $row['observ'];
if($observ==''){
$observ = "-";
}

$salida = $salida."<tr><td align='left'  class='Listadobody' height='25'>".$row['nombre']."</td><td class='Listadobody' align='center'>".$row['tipo_personal']."</td><td class='Listadobody' align='center'>".$row['fecha']."</td><td class='Listadobody' align='center'>".$observ."</td></tr>";
}
$salida = $salida."<table>";
}else{
echo "<table align='center'><tr><td class='Listadohead' width='300'>NO SE ENCONTRARON DESCANSOS MEDICOS</td>";
}


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