<?php
class PDF extends FPDF
{

  function Header()
  {
    $tom                      = new tom();
    $this->SetFont('Arial','B',15);
    $this->SetY(20);
    $this->SetX(20);
    $this->Cell(170,6,'TOM - ' . $tom->getClientCompany($_GET['id']) . ' - Seite '.$this->PageNo().'/{nb}');
    $this->Ln(20);
  }

  function Footer()
  {
    // Position at 1.5 cm from bottom
    $this->SetY(-15);
    // Arial italic 8
    $this->SetFont('Arial','B',10);
    // Page number
    $this->Cell(0,10,'Seite '.$this->PageNo().'/{nb}',0,0,'');
  }
}


$pdf                              = new PDF('P', 'mm', 'A4');
$pdf->SetCreator("DSB-Holzheu");
$pdf->SetAuthor("DSB-Holzheu");
$pdf->AliasNbPages();
$pdf->AddPage();
$replaceArray                     = array(
    '&bull;',
    '&quot;',
);
$replacementArray                 = array(
    '- ',
    '"'
);

foreach ($rows as $row) {
  $frage                          = str_replace($replaceArray, $replacementArray, $row['frage']);
  $empfehlung                     = str_replace($replaceArray, $replacementArray, $row['bemerkung_begruendung']);
  $status                         = $tom->getStatusVal($row['status']);
  $y1                             = $pdf->GetY();
  $pdf->SetFont('Arial','B',12);
  $pdf->SetY($y1 +10);
  $pdf->SetX(20);
  $pdf->Cell(170,6,'Themenblock: ' . html_entity_decode($tom->getThemenblockName($row['themenblock_id'], ENT_QUOTES, "iso-8859-1")) . ' - Frage: ' . $row['themenfrage_id']);
  $pdf->SetFont('Arial','B',12);
  $pdf->SetY($y1 + 20);
  $pdf->SetX(20);
  $pdf->Cell(170,6,iconv("UTF-8","iso-8859-1","Maßnahme"));
  $pdf->SetFont('Arial','',10);
  $pdf->SetY($y1 + 30);
  $pdf->SetX(20);
  $pdf->MultiCell(170,6, html_entity_decode($frage, ENT_QUOTES, "iso-8859-1"));
  $pdf->SetFont('Arial','B',12);
  $y2                         = $pdf->GetY();

  $pdf->SetY($y2 + 10);
  $pdf->SetX(20);
  $pdf->Cell(170,6,iconv("UTF-8","iso-8859-1","Bemerkung / Begründung"));
  $pdf->SetFont('Arial','',10);
  $pdf->SetY($y2 + 20);
  $pdf->SetX(20);
  $pdf->MultiCell(170,6, html_entity_decode($empfehlung, ENT_QUOTES, "iso-8859-1"));
  $y3                         = $pdf->GetY();
  $pdf->SetFont('Arial','B',10);
  $pdf->SetY($y3 + 5);
  $pdf->SetX(20);
  $pdf->Cell(170,6,'Status: ' . iconv("UTF-8","iso-8859-1",$status),1,2);
  if ($y3                     >= 190) {
    $pdf->AddPage();
  }
}


$pdf->Output( 'tom-report.pdf', 'I' );