<?php

include('pdf/fpdf.php');
session_cache_limiter('private');
session_start();
include("DMMYSQLG.php");
$com = "I";
include("DSA3000.php");
class PDF extends FPDF
{
	//Cabecera de página
	function Header()
	{
	    //Logo
	    include("DYIM_VER.php");
	    //Arial bold 14
	    $this->SetFont('Arial','B',12);
	   
	    $this->Cell(190,1,'DELEGACION / MUNICIPIO',0,1,'C');
	    //Salto de línea
	    $this->Ln(3);
		
		$this->SetFont('Arial','',7);//establece tamaño de letra
		$this->SetFillColor(192,192,192);
		$this->Cell(10,5,'CLAVE',1,'','C',1);
		$this->Cell(40,5,'PAIS',1,'','C',1);
		$this->Cell(40,5,'ESTADO',1,'','C',1);
		$this->Cell(40,5,'DELEGACION / MUNICIPIO',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().'/{nb}',0,0,'C');
	}
}


$pdf=new PDF('P','mm','A4');
$pdf->AddPage();
$pdf->AliasNbPages();
$pdf->SetFont('Arial','',7);

if(!isset($_POST['bot']))$_POST['bot']="";
if($_POST['bot']==""){
if(!isset($_POST['tip_bus']))$_POST['tip_bus']="";
	if($_POST['tip_bus']=="clave"){
		$sql1 ="SELECT * FROM dxdelmun WHERE cve_delmun = '".$_POST['txt_bus']."' order by cve_delmun";
	}elseif($_POST['tip_bus']=="nombre"){
		$sql1 ="SELECT * FROM dxdelmun WHERE des_delmun LIKE '%".$_POST['txt_bus']."%' order by cve_delmun";
	}else{
		$sql1 = "SELECT * FROM dxdelmun order by cve_delmun";
	}
}else{
	$sql1 = "SELECT * FROM dxdelmun WHERE cve_delmun = '".$_POST['bot']."'";
}

include("DMMYSQLG.php");

$sql = mysqli_query ($sql1); 
while ($reg = mysqli_fetch_row($sql)) { 
    $data[] = $reg[0]; 
	$data1[] = $reg[1]; 
	$data2[] = $reg[2]; 
	$data3[] = $reg[3];
	}
$num_elementos=count($data);

for($i=0;$i<=$num_elementos;$i++){

	include("DMMYSQLG.php");
	
	$pdf->Cell(10,5,$data[$i],0,0,'C');
	if(!isset($data1['$i']))$data1['$i']="";
	$bus = mysqli_query($GLOBALS['con'] ,"SELECT * FROM dxpaises WHERE cve_pais = '$data1[$i]'");
	@$re = mysqli_fetch_array($bus);
	$pdf->Cell(40,5, $re['des_pais'],0,'','L');
	if(!isset($data2['$i']))$data2['$i']="";
	$bus = mysqli_query($GLOBALS['con'] ,"SELECT * FROM dxestado WHERE cve_estado = '$data2[$i]'");
	@$re = mysqli_fetch_array($bus);
	$pdf->Cell(40,5,$re['des_estado'],0,'','L');
	$pdf->Cell(40,5,$data3[$i],0,1,'L');
	
} 
ob_end_clean();
$pdf->Output();
?> 
