<?php

include('pdf/fpdf.php');
session_cache_limiter('private');
session_start();
$com = "I";
include("DMMYSQLG.php");
require_once("DF80000.php");
class PDF extends FPDF{
//Cabecera de página
	function Header(){
	    //Logo
	         include("DYIM_VER.php");
	    //Arial bold 14
		$this->SetFont('Arial','B',12);
		//Título
		$this->Cell(225,5,'HISTORICO DE ESTANCIAS',0,1,'C',0);
		
		$this->Cell(50,5,'Fecha: '.$_POST['fec'].' al '.$_POST['fec2'],0,0,'C',0);
		
		if($_POST['r1']=="FOLIO" and $_POST['r2']=='1'){
		$this->Ln(8);
		$this->SetFont('Arial','B',7);//establece tamaño de letra
		$this->SetFillColor(192,192,192);
		$this->Cell(5,5,'',0,0,'C',0);
		$this->Cell(15,5,'FOLIO',1,0,'C',1);
		$this->Cell(60,5,'APELLIDO Y NOMBRE',1,0,'C',1);
		$this->cell(15,5,'STATUS',1,0,'C',1);
		$this->cell(10,5,'HAB',1,0,'C',1);
		$this->cell(20,5,'TELEFONO',1,0,'C',1);
		$this->cell(55,5,'DIRECCION',1,0,'C',1);
		$this->cell(45,5,'E-MAIL',1,0,'C',1);
		$this->cell(15,5,'F. LLEGADA',1,0,'C',1);
		$this->cell(15,5,'F. SALIDA',1,1,'C',1);
        }elseif($_POST['r1']=="FOLIO" and $_POST['r2']!='1'){
		$this->Ln(8);
		$this->SetFont('Arial','B',7);//establece tamaño de letra
		$this->SetFillColor(192,192,192);
		$this->Cell(5,5,'',0,0,'C',0);
		$this->Cell(50,5,'APELLIDO Y NOMBRE',1,0,'C',1);
		$this->Cell(15,5,'FOLIO',1,0,'C',1);
		$this->cell(15,5,'STATUS',1,0,'C',1);
		$this->cell(10,5,'HAB',1,0,'C',1);
		$this->cell(20,5,'TELEFONO',1,0,'C',1);
		$this->cell(60,5,'DIRECCION',1,0,'C',1);
		$this->cell(45,5,'E-MAIL',1,0,'C',1);
		$this->cell(16,5,'F. LLEGADA',1,0,'C',1);
		$this->cell(15,5,'F. SALIDA',1,1,'C',1);
		          }elseif($_POST['r1']=="HABITACION" and $_POST['r2']=='1'){
		          $this->Ln(8);
		          $this->SetFont('Arial','B',7);//establece tamaño de letra
		          $this->SetFillColor(192,192,192);
		          $this->Cell(5,5,'',0,0,'C',0);
		          $this->cell(10,5,'HAB',1,0,'C',1);
				  $this->Cell(60,5,'APELLIDO Y NOMBRE',1,0,'C',1);
				  $this->Cell(15,5,'FOLIO',1,0,'C',1);
		          $this->cell(15,5,'STATUS',1,0,'C',1);
		          $this->cell(20,5,'TELEFONO',1,0,'C',1);
		          $this->cell(55,5,'DIRECCION',1,0,'C',1);
		          $this->cell(45,5,'E-MAIL',1,0,'C',1);
		          $this->cell(15,5,'F. LLEGADA',1,0,'C',1);
		          $this->cell(15,5,'F. SALIDA',1,1,'C',1);
		          }elseif($_POST['r1']=="HABITACION" and $_POST['r2']!='1'){
		          $this->Ln(8);
		          $this->SetFont('Arial','B',7);//establece tamaño de letra
		          $this->SetFillColor(192,192,192);
		          $this->Cell(5,5,'',0,0,'C',0);
		          $this->Cell(50,5,'APELLIDO Y NOMBRE',1,0,'C',1);
				  $this->cell(10,5,'HAB',1,0,'C',1);
				  $this->Cell(15,5,'FOLIO',1,0,'C',1);
		          $this->cell(15,5,'STATUS',1,0,'C',1);
		          $this->cell(20,5,'TELEFONO',1,0,'C',1);
		          $this->cell(60,5,'DIRECCION',1,0,'C',1);
		          $this->cell(45,5,'E-MAIL',1,0,'C',1);
		          $this->cell(16,5,'F. LLEGADA',1,0,'C',1);
		          $this->cell(15,5,'F. SALIDA',1,1,'C',1);
		                    }elseif($_POST['r1']=="APELLIDO" and $_POST['r2']=='1'){
		                    $this->Ln(8);
		                    $this->SetFont('Arial','B',7);//establece tamaño de letra
		                    $this->SetFillColor(192,192,192);
		                    $this->Cell(5,5,'',0,0,'C',0);
		                    $this->Cell(60,5,'APELLIDO Y NOMBRE',1,0,'C',1);
							$this->Cell(15,5,'FOLIO',1,0,'C',1);
		                    $this->cell(15,5,'STATUS',1,0,'C',1);
		                    $this->cell(10,5,'HAB',1,0,'C',1);
		                    $this->cell(20,5,'TELEFONO',1,0,'C',1);
		                    $this->cell(55,5,'DIRECCION',1,0,'C',1);
		                    $this->cell(45,5,'E-MAIL',1,0,'C',1);
		                    $this->cell(15,5,'F. LLEGADA',1,0,'C',1);
		                    $this->cell(15,5,'F. SALIDA',1,1,'C',1);
		                    }elseif($_POST['r1']=="APELLIDO" and $_POST['r2']!='1'){
		                    $this->Ln(8);
		                    $this->SetFont('Arial','B',7);//establece tamaño de letra
		                    $this->SetFillColor(192,192,192);
		                    $this->Cell(5,5,'',0,0,'C',0);
		                    $this->Cell(50,5,'APELLIDO Y NOMBRE',1,0,'C',1);
							$this->Cell(15,5,'FOLIO',1,0,'C',1);
		                    $this->cell(15,5,'STATUS',1,0,'C',1);
		                    $this->cell(10,5,'HAB',1,0,'C',1);
		                    $this->cell(20,5,'TELEFONO',1,0,'C',1);
		                    $this->cell(60,5,'DIRECCION',1,0,'C',1);
		                    $this->cell(45,5,'E-MAIL',1,0,'C',1);
		                    $this->cell(16,5,'F. LLEGADA',1,0,'C',1);
		                    $this->cell(15,5,'F. SALIDA',1,1,'C',1);
		}
	}	
	//Pie de página
	function Footer()
	{
	//Posición: a 1,5 cm del final
	$this->SetY(-15);
	//Arial italic 8
	$this->SetFont('Arial','I',8);
	//Número de página
	$this->Cell(0,10, $this->PageNo(),0,0,'C');
	}
}

$pdf=new PDF('L','mm','Letter');
$pdf->AddPage();

$pdf->SetFillColor(192,192,192);
$pdf->SetFont('Arial','',7);//establece tamaño de letra
$vartb=(isset($_POST['tbus']))?$_POST['tbus']:"";
$tbus=mysqli_real_escape_string($GLOBALS['con'],$vartb);
$fec = $_POST['fec'];
include('DF20000.php');
$fecha_inicial = $f_m;
$fec = $_POST['fec2'];
include('DF20000.php');
$fecha_final = $f_m;
 
	if($_POST['r1']=="FOLIO" and $_POST['r2']=='1'){
	$sql=mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus19 WHERE ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto!='900' and fmuncto!='901' order by n_reg");
    @$tot=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select count(*) as total from valeryus19 WHERE ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto!='900' and fmuncto!='901'"));
	}elseif($_POST['r1']=="FOLIO" and $_POST['r2']!="1"){
	$sql=mysqli_query($GLOBALS['con'] ,"SELECT *, CONCAT(fapellido,' ',fnombre) as NomApe, count(*) as cnt from valeryus19 where ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto!='900' and fmuncto!='901' group by NomApe having cnt >= '".$_POST['r2']."'");
		
            }elseif($_POST['r1']=="HABITACION" and $_POST['r2']=='1'){
	        $sql = mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus19 WHERE ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto!='900' and fmuncto!='901' order by fmuncto");
   	        @$tot=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select count(*) as total from valeryus19 WHERE ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto!='900' and fmuncto!='901'"));
	        }elseif($_POST['r1']=="HABITACION" and $_POST['r2']!='1'){
		    $sql=mysqli_query($GLOBALS['con'] ,"SELECT *, CONCAT(fapellido,' ',fnombre) as NomApe, count(*) as cnt from valeryus19 where ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto!='900' and fmuncto!='901' group by NomApe having cnt >= '".$_POST['r2']."'");
		  
	                } elseif($_POST['r1']=="APELLIDO" and $_POST['r2']=='1'){
	  	            $sql = mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus19 WHERE ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto!='900' and fmuncto!='901' ORDER BY fapellido");
	                @$tot=mysqli_fetch_array(mysqli_query($GLOBALS['con'] ,"select count(*) as total from valeryus19 where ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status = 'HISTORICO' and fmuncto!='900' and fmuncto!='901'"));  
	                } elseif($_POST['r1']=="APELLIDO" and $_POST['r2']!='1'){
		            $sql=mysqli_query($GLOBALS['con'] ,"SELECT *, CONCAT(fapellido,' ',fnombre) as NomApe, count(*) as cnt from valeryus19 where ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto!='900' and fmuncto!='901' group by NomApe having cnt >= '".$_POST['r2']."'");
		            }
	
	if($_POST['r1']=="FOLIO" and $_POST['r2']=='1'){
	while($row = mysqli_fetch_array($sql)){
    $pdf-> Cell(5,5,'',0,0,'C',0);
	$pdf-> Cell(15,5, $row["n_reg"],10,0,'C',0);
	$pdf-> Cell(60,5, $row["fapellido"].''.$row["fnombre"],10,0,'C',0);
	$pdf-> Cell(15,5, $row["status"],10,0,'C',0);
	$pdf-> Cell(10,5, $row["fmuncto"],10,0,'C',0);
	$pdf-> Cell(20,5, $row["ftelefono"],10,0,'C',0);
	$pdf-> Cell(55,5, $row["fdireccion"],10,0,'C',0);
	$pdf-> Cell(45,5, $row["fmail"],10,0,'C',0);
	$pdf-> Cell(15,5, chfecha($row['ffecllegada'],'Y-m-d'),10,0,'C',0);
	$pdf-> Cell(15,5, chfecha($row['ffecsalida'],'Y-m-d'),10,1,'C',0);
	}
	$pdf-> Cell(60,5,'FOLIOS :',10,1,'C',0);
	$pdf-> Cell(80,-5, $tot['total'],10,1,'C',0);
	}elseif($_POST['r1']=="FOLIO" and $_POST['r2']!="1"){
	$i=0;
	while($row = mysqli_fetch_array($sql)){
    $pdf-> Cell(5,5,'',0,0,'C',0);
	$pdf-> Cell(50,5, $row["NomApe"],1,1,'L',0);
	$esT=mysqli_query($GLOBALS['con'] ,"select * from valeryus19 where fnombre='".$row['fnombre']."' and fapellido='".$row['fapellido']."' and ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto!='900' and fmuncto!='901'");
    while ($anC=mysqli_fetch_array($esT)){
	$pdf-> Cell(55,5, '',10,0,'C',0);
	$pdf-> Cell(15,5, $anC["n_reg"],1,0,'C',0);
	$pdf-> Cell(15,5, $anC["status"],1,0,'C',0);
	$pdf-> Cell(10,5, $anC["fmuncto"],1,0,'C',0);
	$pdf-> Cell(20,5, $anC["ftelefono"],1,0,'C',0);
	$pdf-> Cell(60,5, $anC["fdireccion"],1,0,'C',0);
	$pdf-> Cell(45,5, $anC["fmail"],1,0,'C',0);
	$pdf-> Cell(16,5, chfecha($anC['ffecllegada'],'Y-m-d'),1,0,'C',0);
	$pdf-> Cell(15,5, chfecha($anC['ffecsalida'],'Y-m-d'),1,1,'C',0);
	} $i++; }
	$pdf-> Cell(60,5,'HUESPEDES :',10,1,'C',0);
	$pdf-> Cell(80,-5, $i,10,1,'C',0);
	                    }elseif($_POST['r1']=="HABITACION" and $_POST['r2']=='1'){
	                    while($row = mysqli_fetch_array($sql)){
                        $pdf-> Cell(5,5,'',0,0,'C',0);
	                    $pdf-> Cell(10,5, $row["fmuncto"],10,0,'C',0);
	                    $pdf-> Cell(60,5, $row["fapellido"].''.$row["fnombre"],10,0,'C',0);
	                    $pdf-> Cell(15,5, $row["n_reg"],10,0,'C',0);
	                    $pdf-> Cell(15,5, $row["status"],10,0,'C',0);
	                    $pdf-> Cell(20,5, $row["ftelefono"],10,0,'C',0);
	                    $pdf-> Cell(55,5, $row["fdireccion"],10,0,'C',0);
	                    $pdf-> Cell(45,5, $row["fmail"],10,0,'C',0);
	                    $pdf-> Cell(15,5, chfecha($row['ffecllegada'],'Y-m-d'),10,0,'C',0);
	                    $pdf-> Cell(15,5, chfecha($row['ffecsalida'],'Y-m-d'),10,1,'C',0);
	                    }
	                    $pdf-> Cell(60,5,'FOLIOS :',10,1,'C',0);
	                    $pdf-> Cell(80,-5, $tot['total'],10,1,'C',0);
	                    }elseif($_POST['r1']=="HABITACION" and $_POST['r2']!='1'){
	                    $e=0;
	                    while($row = mysqli_fetch_array($sql)){
                        $pdf-> Cell(5,5,'',0,0,'C',0);
	                    $pdf-> Cell(50,5, $row["NomApe"],1,1,'L',0);
	                    $esT=mysqli_query($GLOBALS['con'] ,"select * from valeryus19 where fnombre='".$row['fnombre']."' and fapellido='".$row['fapellido']."' and ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto!='900' and fmuncto!='901'");
                        while ($anC=mysqli_fetch_array($esT)){
	                    $pdf-> Cell(55,5, '',10,0,'C',0);
	                    $pdf-> Cell(10,5, $anC["fmuncto"],1,0,'C',0);
	                    $pdf-> Cell(15,5, $anC["n_reg"],1,0,'C',0);
	                    $pdf-> Cell(15,5, $anC["status"],1,0,'C',0);
	                    $pdf-> Cell(20,5, $anC["ftelefono"],1,0,'C',0);
	                    $pdf-> Cell(60,5, $anC["fdireccion"],1,0,'C',0);
	                    $pdf-> Cell(45,5, $anC["fmail"],1,0,'C',0);
	                    $pdf-> Cell(16,5, chfecha($anC['ffecllegada'],'Y-m-d'),1,0,'C',0);
	                    $pdf-> Cell(15,5, chfecha($anC['ffecsalida'],'Y-m-d'),1,1,'C',0);
	                    } $e++; }
	                    $pdf-> Cell(60,5,'HUESPEDES :',10,1,'C',0);
	                    $pdf-> Cell(80,-5, $e,10,1,'C',0);
	                                        }elseif($_POST['r1']=="APELLIDO" and $_POST['r2']=='1'){
	                                        while($row = mysqli_fetch_array($sql)){
                                            $pdf-> Cell(5,5,'',0,0,'C',0);
	                                        $pdf-> Cell(60,5, $row["fapellido"].''.$row["fnombre"],10,0,'C',0);
	                                        $pdf-> Cell(15,5, $row["n_reg"],10,0,'C',0);
	                                        $pdf-> Cell(15,5, $row["status"],10,0,'C',0);
	                                        $pdf-> Cell(10,5, $row["fmuncto"],10,0,'C',0);
	                                        $pdf-> Cell(20,5, $row["ftelefono"],10,0,'C',0);
	                                        $pdf-> Cell(55,5, $row["fdireccion"],10,0,'C',0);
	                                        $pdf-> Cell(45,5, $row["fmail"],10,0,'C',0);
	                                        $pdf-> Cell(15,5, chfecha($row['ffecllegada'],'Y-m-d'),10,0,'C',0);
	                                        $pdf-> Cell(15,5, chfecha($row['ffecsalida'],'Y-m-d'),10,1,'C',0);
	                                        }
	                                        $pdf-> Cell(60,5,'FOLIOS :',10,1,'C',0);
	                                        $pdf-> Cell(80,-5, $tot['total'],10,1,'C',0);
	                                        }elseif($_POST['r1']=="APELLIDO" and $_POST['r2']!='1'){
	                                        $g=0;
	                                        while($row = mysqli_fetch_array($sql)){
                                            $pdf-> Cell(5,5,'',0,0,'C',0);
	                                        $pdf-> Cell(50,5, $row["NomApe"],1,1,'L',0);
	                                        $esT=mysqli_query($GLOBALS['con'] ,"select * from valeryus19 where fnombre='".$row['fnombre']."' and fapellido='".$row['fapellido']."' and ffecllegada >= '$fecha_inicial' and fecha_real <= '$fecha_final' AND status='HISTORICO' and fmuncto!='900' and fmuncto!='901'");
                                            while ($anC=mysqli_fetch_array($esT)){
	                                        $pdf-> Cell(55,5, '',10,0,'C',0);
	                                        $pdf-> Cell(15,5, $anC["n_reg"],1,0,'C',0);
	                                        $pdf-> Cell(15,5, $anC["status"],1,0,'C',0);
	                                        $pdf-> Cell(10,5, $anC["fmuncto"],1,0,'C',0);
						                    $pdf-> Cell(20,5, $anC["ftelefono"],1,0,'C',0);
	                                        $pdf-> Cell(60,5, $anC["fdireccion"],1,0,'C',0);
	                                        $pdf-> Cell(45,5, $anC["fmail"],1,0,'C',0);
	                                        $pdf-> Cell(16,5, chfecha($anC['ffecllegada'],'Y-m-d'),1,0,'C',0);
	                                        $pdf-> Cell(15,5, chfecha($anC['ffecsalida'],'Y-m-d'),1,1,'C',0);
	                                        } $g++; }
	                                        $pdf-> Cell(60,5,'HUESPEDES :',10,1,'C',0);
	                                        $pdf-> Cell(80,-5, $g,10,1,'C',0);
                                           	}
											
$pdf->Output("Historico De Estancias.pdf","D");
//95--> 100 ultima actualizacion 30/noviembre/2011 HISTORICO DE ESTANCIAS
//258--> 200 ultima actualizacion 15/diciembre/2011 Huespedes asiduos
?> 