<?php
$sql =		"SELECT * FROM objekte WHERE ID = \"".$_GET['obj']."\";";
$result =	$db->query($sql);
$nt =		$result->fetch_assoc();
class PDF extends FPDF {

	function Header() {
		include "inhalte/pdf/header.php";
	}
	function Footer() {
		include "inhalte/pdf/footer.php";
	}
}

$pdf=new PDF();
$pdf->AliasNbPages(); 
$pdf->SetDisplayMode('fullpage');
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetLeftMargin(20);
$pdf->SetTopMargin(70);
$pdf->SetAutoPageBreak(true, 17);
$pdf->SetFont('Helvetica', '', 12);

$j = 0;
$y = 90;
for ($i=1; $i<10; $i++) {
	$pic = "./img/objekte/".$_GET['obj']."_". $i. ".jpg";
	if (file_exists($pic)) {
		list($width,$height)=getimagesize($pic);
		$pdf->Rect(111,$y-11,82,92);
		$pdf->SetLeftMargin(112);
		$pdf->SetY($y-10);
		$pdf->Cell(82, 8, $nt['Foto'.$i], 0, 0, 'C');
		if ($width > $height) {
			$pdf->Image($pic,112,$y+10,80);
		} else {
			$pdf->Image($pic,112+10,$y,0,80);
		}
		$j++;
		$y=190;
		if (2 == $j) {
			break;
		}
	}
}

$pdf->SetY(80);
$pdf->SetX(20);
$pdf->SetLeftMargin(20);
$pdf->SetFont('Helvetica', '', 12);

if ("wmiete" == $_GET['topic']) {
	include "inhalte/pdf/wmiete.php";
} elseif ("wkauf" == $_GET['topic']) {
	include "inhalte/pdf/wkauf.php";
} elseif ("gmiete" == $_GET['topic']) {
	include "inhalte/pdf/gmiete.php";
} elseif ("gkauf" == $_GET['topic']) {
	include "inhalte/pdf/gkauf.php";
} elseif ("rkauf" == $_GET['topic']) {
	include "inhalte/pdf/rkauf.php";
} elseif ("akauf" == $_GET['topic']) {
	include "inhalte/pdf/akauf.php";
}
$pdf->AddPage();
$pdf->SetY(80);
$pdf->SetX(20);
$pdf->SetLeftMargin(20);
$pdf->SetFont('Helvetica', '', 12);
$pdf->Write(8, "Objektbeschreibung\n");
$pdf->SetFont('Helvetica', '', 10);
$pdf->Write(4, $nt['OBeschreibung']."\n\n");
if ("gewerbe" == $_GET['section']) {
	$pdf->SetFont('Helvetica', '', 12);
	$pdf->Write(8, "Auflagen\n");
	$pdf->SetFont('Helvetica', '', 10);
	$pdf->Write(4, $nt['Auflagen']."\n\n");
}
$pdf->SetFont('Helvetica', '', 12);
$pdf->Write(8, "Ausstattung\n");
$pdf->SetFont('Helvetica', '', 10);
$pdf->Write(4, $nt['Ausstatt']."\n\n");
$pdf->SetFont('Helvetica', '', 12);
$pdf->Write(8, "Lage\n");
$pdf->SetFont('Helvetica', '', 10);
$pdf->Write(4, $nt['Lage']."\n\n");
$pdf->SetFont('Helvetica', '', 12);
$pdf->Write(8, "Sonstiges\n");
$pdf->SetFont('Helvetica', '', 10);
$pdf->Write(4, $nt['Sonstiges']."\n\n\n\n");
$pdf->Write(4, "Für die Richtigkeit der Angaben können wir keine Gewähr übernehmen.\n");
$pdf->Write(4, "Grundrisse sind nicht maßstabsgetreu.\n\n");
$nodes = glob('./img/objekte/'.$_GET['obj'].'*');
if ( count ( $nodes ) >= 3 )
	{
		$pdf->AddPage();
		$pdf->SetY(80);
		$pdf->SetX(20);
		$pdf->SetLeftMargin(20);
		$pdf->SetFont('Helvetica', '', 12);
		$pdf->Write(8, "Weitere Bilder");
		$pdf->SetY(90);
		$pdf->SetX(20);

		$x = 20;
		$y = 100;
		$j = 0;
		for ($i=1; $i<10; $i++) {
			$pic = "./img/objekte/".$_GET['obj']."_". $i. ".jpg";
			if (file_exists($pic)) {
				list($width,$height)=getimagesize($pic);
				$j++;
				if (3 > $j) {
				} else {
					if (7 == $j) {
						$pdf->AddPage();
						$pdf->SetY(80);
						$pdf->SetX(20);
						$pdf->SetLeftMargin(20);
						$pdf->Write(8, "Weitere Bilder");
						$x = 20;
						$y = 100;
						$pdf->SetY(90);
						$pdf->SetX(20);
					}
					$pdf->Rect($x-1,$y-11,82,92);
					$pdf->Cell(82, 8, $nt['Foto'.$i], 0, 0, 'C');
					if ($width > $height) {
						$pdf->Image($pic,$x,$y+10,80);
					} else {
						$pdf->Image($pic,$x+10,$y,0,80);
					}
					if (20 == $x) {
						$x2 = 112;
						$pdf->SetLeftMargin(112);
					}
					if (112 == $x) {
						$y = 190;
						$x2 = 20;
						$pdf->SetY(172);
						$pdf->SetLeftMargin(20);
						$pdf->Ln();
					}
					$x = $x2;
				}
			}
		}
	}


$file = "expose".$_GET['obj'].".pdf";
$pdf->Output($file, "D");

?>