
<?php
require('fpdf/fpdf.php');
date_default_timezone_set('UTC');

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

//if($val==1){
//$anno= $_GET['anno'];
//$mes= $_GET['mes'];
//$idj= $_GET['idj'];
//$ids= $_GET['ids'];
//$idtp= $_GET['idtp'];
//$ugid= $_GET['ugid'];
//}

$anno= 2011;
$mes= 9;
$idj= 1;
$ids= 1;
$idtp= 1;
$ugid= "JEF2";


//DATOS DEL REPORTE
$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');

//////FUNCIONES DEL REPORTE
class PDF extends FPDF
{
function ImprimirTablaHorario($data,$x, $y, $h, $w,$alig)
{
    $this->SetFillColor(224,200,255);
    $this->SetTextColor(0);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','B');
	$this->SetXY($x,$y);
    //Datos
	$dib=false;
   		for($j=0;$j<count($w);$j++)
		{
        $this->Cell($w[$j],$h,$data[$j],1,0,$alig,$dib);
		//$dib = !$dib;
		$x = $x + $w[$j];
		$this->SetXY($x,$y);
        }
}

function ImprimirTablaSinColorTitulo($data,$x, $y, $h, $w,$alig,$dibuja)
	{
    $this->SetFillColor(224,200,255);
    $this->SetTextColor(0);
    $this->SetDrawColor(128,0,0);
    $this->SetLineWidth(.3);
    $this->SetFont('','B');
	$this->SetXY($x,$y);
    //Datos
	$dib=false;
	        $this->Cell($w,$h,$data,$dibuja,0,$alig,$dib);
	}
}


//nombre de la jefatura
$sqljefatura = "select j_desc as nom from tb_jefatura where j_id='$idj'";
$resultjefatura = mysql_query($sqljefatura);
while ($rowj= mysql_fetch_array($resultjefatura)){
$nomjefatura = $rowj['nom']; 
}

//nombre de servicio
$sqlserv = "select s_desc as nom from tb_servicio where j_id='$idj' and s_id='$ids'";
$resultserv = mysql_query($sqlserv);
while ($rows= mysql_fetch_array($resultserv)){
$nomservicio = $rows['nom']; 
}

//descripcion del tipo del personal
$sqltp = "select tp_desc as descp from tb_tipoperson where tp_id='$idtp'";
$resulttp = mysql_query($sqltp);
while ($rowtp= mysql_fetch_array($resulttp)){
$descpersonal = $rowtp['descp']; 
}


/////////////
$alturaX = 25;
$ha = 4;

//INICIA REPORTE
$pdf=new PDF();
//$pdf->FPDF();
$pdf->AddPage();
//$pdf->SetTextColor(0);
$sumat = 255;

$pdf->SetFont('Helvetica','B',10);
$pdf->Image('../img/logoincor.jpg', 10, 10, 45, 16,'jpg');
$pdf->Image('../img/logoessalud.jpg', 160, 12, 40, 11,'jpg');

$texto = "REPROGRAMACION DE TURNOS DEL MES DE ".$arraymes[$mes-1]['mes']." DEL ".$anno;
	
$ini = 25;
$pdf->ImprimirTablaSinColorTitulo($nomjefatura,25,$ini,$ha,$sumat*0.65,'C',0);
$ini = $ini + $ha;
$pdf->ImprimirTablaSinColorTitulo($nomservicio,25,$ini,$ha,$sumat*0.65,'C',0);
$ini = $ini + $ha;
$pdf->ImprimirTablaSinColorTitulo($descpersonal,25,$ini,$ha,$sumat*0.65,'C',0);
$ini = $ini + $ha*1.5;
$pdf->SetFont('Helvetica','B',9);
$pdf->ImprimirTablaSinColorTitulo($texto,25,$ini,$ha,$sumat*0.65,'C',0);
$ini = $ini + $ha*1.5;
$pdf->SetFont('Arial','B',6);
					    $subtitulo = array('APELLIDOS Y NOMBRES','FECHA PROGRAMADA','TURNO','FECHA REPROGRAMADA','TURNO','OBSERVACIONES');
						$wh= array($sumat*0.2,$sumat*0.1,$sumat*0.1,$sumat*0.1,$sumat*0.1,$sumat*0.2);
						$pdf->ImprimirTablaHorario($subtitulo,15,$ini,$ha*1.5,$wh,'C');	
						

$pdf->Output();


/*
$sqlaskpr = "SELECT * FROM tb_horareprog where tp_id='$idtp' and uap_anno='$anno' and uap_mes='$mes' and hr_idserva='$ids' and j_id='$idj'";
$resultaskp = mysql_query($sqlaskpr);
if(mysql_num_rows($resultaskp)!=0){

//pregunta por el personal
$sqlper1="select a.ug_id as cod, a.ua_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' and b.s_id='$ids' ";
$sqlper1= $sqlper1." and b.tp_id='$idtp' and b.ut_idserva='$ids' and b.uap_anno='$anno' and b.uap_mes ='$mes' order by nombre";
//echo $sqlper1."<br>";
$resultper1 = mysql_query($sqlper1);



while ($row= mysql_fetch_array($resultper1)){
$codper=$row['cod'];
$codprog=$row['codigo'];
$nombre=$row['nombre'];

//pregunta por turno prog
$sqlprog = "select a.ut_codprog as codprog, a.ug_id as ugid, a.h_id as idhora, a.a_id as area, a.ga_id as garea, a.rh_dia as dia, concat(a.rh_dia,'/', a.uap_mes,'/', a.uap_anno) as fechap, concat(c.h_horanum,'(',c.h_horaturn,')') as turnop ";
$sqlprog = $sqlprog." from tb_reprohrs a inner join tb_horario c on a.h_id=c.h_id where tp_id='$idtp' and a.ug_id='$codper' and a.uap_anno='$anno' and a.uap_mes='$mes' and a.rh_idserva='$ids' and a.j_id='$idj' and a.rh_tipo='1'";

//pregunta por turno reprog
$sqlrprog = "select a.ut_codprog as codprog, a.ug_id as ugid, a.h_id as idhora, a.a_id as area, a.ga_id as garea, a.rh_dia as dia, concat(a.rh_dia,'/', a.uap_mes,'/', a.uap_anno) as fechap, concat(c.h_horanum,'(',c.h_horaturn,')') as turnop ";
$sqlrprog = $sqlrprog." from tb_reprohrs a inner join tb_horario c on a.h_id=c.h_id where tp_id='$idtp' and a.ug_id='$codper' and a.uap_anno='$anno' and a.uap_mes='$mes' and a.rh_idserva='$ids' and a.j_id='$idj' and a.rh_tipo='2'";


$resulthp = mysql_query($sqlprog);
$resulthrp = mysql_query($sqlrprog);



						
//echo "<tr><td >".$nombre."</td>";

if(mysql_num_rows($resulthp)!=0){

//PERSONAL QUE AUN NO ESTA LISTA EN REPRO
$sqlsaverepro ="select * from tb_reprohrs where uap_anno='$anno' and ug_id='$codper' and uap_mes='$mes' and s_id='$idso' and rh_idserva='$ids' and j_id='$idj' and tp_id='$idtp'";
$resultsaverepro = mysql_query($sqlsaverepro);
//echo $sqlsaverepro."<br>";
if(mysql_num_rows($resultsaverepro)==0){
$texto2 ='AUN NO ESTA INFORMADA 2';
$ini = $ini + $ha;
$pdf->ImprimirTablaSinColorTitulo($texto2,25,$ini,$ha,$sumat*0.65,'C',0);
}else{
//PERSONAL REGISTRADO CON LAS REPROGRAMACIONES
//cuando ya esta registrado la reprogramacion
$cadenaprog ="<table>";
while ($rowhp= mysql_fetch_array($resulthp)){

$cadenaprog= $cadenaprog."<tr><td align='center' width='100'>".$rowhp['fechap']."</td><td width='40' align='center'>".$rowhp['turnop']."</td><td width='20' align='center'>";
$cadenaprog= $cadenaprog."</td></tr>";
}
$cadenaprog =$cadenaprog."</table>";

//turnos reprogramados
$cadenareprog ="<table>";
while ($rowhrp= mysql_fetch_array($resulthrp)){

$cadenareprog= $cadenareprog."<tr><td align='center' width='100'>".$rowhrp['fechap']."</td><td width='40' align='center'>".$rowhrp['turnop']."</td><td width='20' align='center'>";
$cadenareprog= $cadenareprog."</td></tr>";

}
$cadenareprog =$cadenareprog."</table>";


//imprime cambios
$sqlask2 ="select or_obs from tb_obsreprog where j_id='$idj' and ug_id='$codper' and s_id='$idso' and uap_anno='$anno' and uap_mes='$mes' and or_idserva='$ids'";
$resultask2 = mysql_query($sqlask2);
//echo $sqlask2."<br>";
//echo "<td colspan='2' align='center' >".$cadenaprog."</td><td colspan='2' align='center'>".$cadenareprog."</td><td align='center'>";
if(mysql_num_rows($resultask2)!=0){
while ($rowob= mysql_fetch_array($resultask2)){
//echo $rowob['or_obs'];
}
}
//echo "</td></tr>";

}
}
}}

*/
?>
