<?php

include('pdf/fpdf.php');
session_cache_limiter('private');
session_start();
$com = "I";
include("DSA3000.php");
include("DMMYSQLG.php");
include('DF80000.php');
class PDF extends FPDF{
//Cabecera de página
	function Header(){
	    //Logo
	         include("DYIM_SI.php");
	    //Arial bold 14
		$this->SetFont('Arial','B',13);
		//Título
		$this->Cell(225,5,'REPORTE DE MERCADOTECNIA',0,1,'C',0);
		//Salto de línea
		$this->SetFont('Arial','B',12);
		$this->Cell(45,5,'',0,0,'C',0);
		$this->Cell(55,5,'Periodo: '.$_POST['fec'].' al '.$_POST['fec2'],0,0,'C',0);
		
		$this->Ln(8);
		$this->SetFont('Arial','B',8);//establece tamaño de letra
		$this->SetFillColor(192,192,192);
		$this->Cell(5,5,'',0,0,'C',0);
		$this->Cell(14,5,'FOLIO',1,0,'C',1);
		$this->Cell(30,5,'CÓMO SE ENTERO?',1,0,'C',1);
		$this->Cell(52,5,'HUESPED',1,0,'C',1);
		$this->cell(35,5,'TELEFONO',1,0,'C',1);
		$this->Cell(50,5,'EMAIL',1,0,'C',1);
		$this->Cell(17,5,'F LLEGADA',1,0,'C',1);
		$this->Cell(17,5,'F SALIDA',1,0,'C',1);
		$this->Cell(30,5,'SEGMENTO',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','',8);//establece tamaño de letra
$vtb=(isset($_POST['tbus']))?$_POST['tbus']:"";
$tbus=mysqli_real_escape_string($GLOBALS['con'],$vtb);
$fec = $_POST['fec'];
  include('DF20000.php');
    $fecha_inicial = $f_m;
    $fec = $_POST['fec2'];
    include('DF20000.php');
    $fecha_final = $f_m;
if(isset($_POST['entero'])&&$_POST['entero']!="T"){
  $result = mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus19 where ftiphuesped='".$_POST['entero']."' and cancelado='0' and ffecsalida between '$fecha_inicial' and '$fecha_final' and status='HISTORICO' order by ffecllegada");   
//		$sql=mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus19 where ftiphuesped='".$_POST['entero']."' and cancelado='0' and ffecsalida between '$fecha_inicial' and '$fecha_final' and status='HISTORICO' order by ffecllegada");
		
		$a=0;
while($row = mysqli_fetch_array($result)){
        $a++;
	$pdf->SetFont('Arial','',7);
    $pdf-> Cell(5,5,'',0,0,'C',0);
	if ($a>1){
	$pdf-> Cell(245,0.3,'',0,1,'L',1);		
	$pdf-> Cell(5,5,'',0,0,'C',0);
	}	
	  $pdf-> Cell(14,5, $row["n_reg"],10,0,'C',0);
	  $pdf-> Cell(30,5, substr($row["ftiphuesped"],0,17),10,0,'L',0);
	  $pdf-> Cell(52,5, substr($row["fapellido"] . ' ' .$row["fnombre"],0,32),10,0,'L',0);	  
	  $pdf-> Cell(35,5, $row["ftelefono"],10,0,'C',0);
	  $pdf-> Cell(50,5, substr($row["fmail"],0,29),10,0,'L',0);
	  $pdf-> Cell(17,5, chfecha($row['ffecllegada'],'Y-m-d'),10,0,'C',0);
	  $pdf-> Cell(17,5, chfecha($row['ffecsalida'],'Y-m-d'),10,0,'C',0);
	  $pdf-> Cell(30,5, $row["codseg"],10,1,'C',0);	
}
      $pdf-> Cell(5,5, '' ,10,0,'L',0);	 
	  $pdf-> Cell(44,5, 'Total de Folios: ',10,0,'R',1);
	  $pdf-> Cell(52,5, $a ,10,0,'L',1);	  
	  $pdf-> Cell(144,5, '',10,1,'C',0);
	}else{
	    //$como=mysqli_query($GLOBALS['con'] ,"select distinct(ftiphuesped) from valeryus19 where cancelado='0' and ffecsalida between '$fecha_inicial' and '$fecha_final' and status='HISTORICO' order by ftiphuesped");
		$como=mysqli_query($GLOBALS['con'] ,"select distinct(ftiphuesped) from valeryus19 where cancelado='0' and ffecsalida between '$fecha_inicial' and '$fecha_final' and status='HISTORICO' order by ftiphuesped");
		while ($entero=mysqli_fetch_array($como)){
		
		//$sql=mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus19 where cancelado='0' and ffecsalida between '$fecha_inicial' and '$fecha_final' and status='HISTORICO' and ftiphuesped='".$entero['ftiphuesped']."' order by n_reg");
	@$result = mysqli_query($GLOBALS['con'] ,"SELECT * FROM valeryus19 where cancelado='0' and ffecsalida between '$fecha_inicial' and '$fecha_final' and status='HISTORICO' and ftiphuesped='".$entero['ftiphuesped']."' order by n_reg");
$a=0;
while($row = mysqli_fetch_array($result)){
$a++;
	$pdf->SetFont('Arial','',7);
    $pdf-> Cell(5,5,'',0,0,'C',0);
	if ($a>1){
	$pdf-> Cell(245,0.3,'',0,1,'L',1);		
	$pdf-> Cell(5,5,'',0,0,'C',0);
	}	
	  $pdf-> Cell(14,5, $row["n_reg"],10,0,'C',0);
	  $pdf-> Cell(30,5, substr($row["ftiphuesped"],0,17),10,0,'L',0);
	  $pdf-> Cell(52,5, substr($row["fapellido"] . ' ' .$row["fnombre"],0,32),10,0,'L',0);	  
	  $pdf-> Cell(35,5, $row["ftelefono"],10,0,'C',0);
	  $pdf-> Cell(50,5, substr($row["fmail"],0,29),10,0,'L',0);
	  $pdf-> Cell(17,5, chfecha($row['ffecllegada'],'Y-m-d'),10,0,'C',0);
	  $pdf-> Cell(17,5, chfecha($row['ffecsalida'],'Y-m-d'),10,0,'C',0);
	  $pdf-> Cell(30,5, $row["codseg"],10,1,'C',0);	
}
      $pdf-> Cell(5,5, '' ,10,0,'L',0);	 
	  $pdf-> Cell(44,5, 'Total de Folios de '.$entero['ftiphuesped'].': ',10,0,'L',1);
	  $pdf-> Cell(52,5, $a ,10,0,'L',1);	  
	  $pdf-> Cell(144,5, '',10,1,'C',0);
}
}
$pdf->Output("Reporte_de_Mercadotecnia.pdf","D");
//163-->90 ULTIMA ACTUALIZACION 21/AGOSTO/2012 
?> 