<?php
$pdf_type = "kontakt";

$sql = "SELECT * FROM " . PREFIX . "_Kontakte WHERE (ID = \"" . $_POST['ID'] . "\");";
$result = $db->query($sql);
$nt = $result->fetch_assoc();
$sqltext = "SELECT * FROM " . PREFIX . "_Texte WHERE section= \"kontakt\";";
$rtext = $db->query($sqltext);
$nttext = $rtext->fetch_assoc();

class PDF extends TCPDF
{

	function Header()
	{
		include __DIR__ . "/header.php";
	}

	function Footer()
	{
		include __DIR__ . "/footer.php";
	}
}

$pdf = new PDF();
$pdf->SetDisplayMode('fullpage');
$pdf->AddPage();

if ("2" == $_SESSION['Firma']['Werbung'])
{
	include __DIR__ . "/header3.php";
}

$pdf->SetY(70);
$pdf->SetX(20);
$pdf->SetRightMargin(10);

$pdf->SetFont('Helvetica', 'B', 14);
$pdf->SetTextColor($_SESSION['Firma']['F2_Red'], $_SESSION['Firma']['F2_Green'], $_SESSION['Firma']['F2_Blue']);
$pdf->Write(4, "Datenschutzrechtliche Erklärung");
$pdf->Write(4, "\n\n");
$pdf->SetTextColor(0);

$pdf->SetFont('Helvetica', '', 10);
$var = $nttext['Text1'];
include __DIR__ . "/replace_token.php";
include __DIR__ . "/replace_bi.php";

$pdf->SetFont('Helvetica', '', 10);
$pdf->Write(4, $var . "\n\n");

$pdf->SetFont('Helvetica', 'B', 14);
$pdf->SetTextColor($_SESSION['Firma']['F1_Red'], $_SESSION['Firma']['F1_Green'], $_SESSION['Firma']['F1_Blue']);
$pdf->Write(4, "Datenschutzrechtliche Einwilligung");
$pdf->Write(4, "\n\n");
$pdf->SetTextColor(0);

$pdf->SetFont('Helvetica', '', 10);
$var = $nttext['Text2'];
include __DIR__ . "/replace_token.php";
include __DIR__ . "/replace_bi.php";

$pdf->SetFont('Helvetica', '', 10);
$pdf->Write(4, $var . "\n\n");

$pdf->SetFont('Helvetica', 'B', 14);
$pdf->SetTextColor($_SESSION['Firma']['F2_Red'], $_SESSION['Firma']['F2_Green'], $_SESSION['Firma']['F2_Blue']);
$pdf->Write(4, "Kontaktdaten");
$pdf->Write(4, "\n\n");
$pdf->SetTextColor(0);

$pdf->SetFont('Helvetica', '', 10);
$pdf->Cell(30, 4, "Firma");
$pdf->Cell(70, 4, $nt['Firma'], "B");
$pdf->SetX(130);
$pdf->Cell(30, 4, "Postalisch");
$pdf->Cell(4, 4, " ", "1");
$pdf->Cell(10, 4, "Ja");
$pdf->Cell(4, 4, " ", "1");
$pdf->Cell(10, 4, "Nein");
$pdf->Write(6, "\n");
$pdf->Cell(30, 4, "Name");
$pdf->Cell(70, 4, $nt['Vorname'] . " " . $nt['Nachname'], "B");
$pdf->SetX(130);
$pdf->Cell(30, 4, "Email / SMS");
$pdf->Cell(4, 4, " ", "1");
$pdf->Cell(10, 4, "Ja");
$pdf->Cell(4, 4, " ", "1");
$pdf->Cell(10, 4, "Nein");
$pdf->Write(6, "\n");
$pdf->Cell(30, 4, "Straße");
$pdf->Cell(70, 4, $nt['Strasse'] . " " . $nt['Nummer'], "B");
$pdf->SetX(130);
$pdf->Cell(30, 4, "Telefon / Fax");
$pdf->Cell(4, 4, " ", "1");
$pdf->Cell(10, 4, "Ja");
$pdf->Cell(4, 4, " ", "1");
$pdf->Cell(10, 4, "Nein");
$pdf->Write(6, "\n");
$pdf->Cell(30, 4, "PLZ / Ort");
$pdf->Cell(70, 4, $nt['PLZ'] . " " . $nt['Ort'], "B");
$pdf->Write(6, "\n");
$pdf->Cell(30, 4, "Telefon");
$pdf->Cell(70, 4, $nt['Telefon'], "B");
$pdf->Write(6, "\n");
$pdf->Cell(30, 4, "Fax");
$pdf->Cell(70, 4, $nt['Fax'], "B");
$pdf->Write(6, "\n");
$pdf->Cell(30, 4, "Mobil");
$pdf->Cell(70, 4, $nt['Mobil'], "B");
$pdf->Write(6, "\n");
$pdf->Cell(30, 4, "Email");
$pdf->Cell(70, 4, $nt['Email'], "B");
$pdf->Write(6, "\n\n\n\n");
$pdf->Cell(100, 4, " ", "B");
$pdf->Write(6, "\n");
$pdf->Cell(100, 4, "Datum, Unterschrift");

if(!is_dir(__DIR__ . "/" . PREFIX . "/kontakt"))
{
	mkdir(__DIR__ . "/" . PREFIX . "/kontakt", 0777, true);
}

$file = __DIR__ . "/" . PREFIX . "/kontakt/K_" . $nt['ID'] . ".pdf";
$pdf->Output($file, "F");

$var = $nttext['EMail'];
include __DIR__ . "/replace_token.php";
include __DIR__ . "/replace_angebot.php";