<?php

include("../class/dB.class.php");
require_once("../tcpdf/tcpdf.php");
 
$mydb= new DB_MySQL('zeltlager','zeltlager','Z3ltlager3363','localhost');

 
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {

    //Page header
    public function Header()
    {
        
    }

    // Page footer
    public function Footer() 
    {
       
    }
}

// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator('www.fischerkoenig.de');
$pdf->SetAuthor('Team der Zeltlageranmeldung');
$pdf->SetTitle('Zeltlageranmeldung');
$pdf->SetSubject('Listen fürs Zeltlager');

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH,'Zeltlageranmeldung', PDF_HEADER_STRING, array(0,64,255), array(0,64,128));
$pdf->setFooterData(array(0,64,0), array(0,64,128));
 
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

// set margins
//$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetMargins(5, 0, 0);
$pdf->SetHeaderMargin(0);
$pdf->SetFooterMargin(0);

// set auto page breaks
//$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->SetAutoPageBreak(false, 0);

// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}

// ---------------------------------------------------------

// set default font subsetting mode
$pdf->setFontSubsetting(true);

//Datenbankabfrage
$mydb->query("SELECT * FROM AnmeldungAdressen as a LEFT JOIN AnmeldungPerson as p on a.uid = p.uid LEFT JOIN AnmeldungVerwaltung as v on a.uid = v.uid  LEFT Join VerwaltungZelte as z on z.zeltnummer = v.zeltnummer LEFT JOIN AnmeldungBankdaten as b on b.uid = p.uid Left Join VerwaltungGruppe as g on g.gruppe=v.gruppe ORDER BY a.nachname COLLATE latin1_german2_ci ASC, a.vorname COLLATE latin1_german2_ci ASC");
$NumberOfEntries =  $mydb->count();

$style= <<<EOF
<style>
    
    
     th {
      width: 120px;
      height:31px;
      text-align:center;
      border-top: 3px solid black;
      border-bottom: 2px solid black;
    }
    
     .header_middle {
      width: 120px;
      height:31px;
      text-align:center;
      border-top: 3px solid black;
      border-bottom: 2px solid black;
      border-left: 0.5px solid black;
      border-right: 0.5px solid black;
    }
    .header_middlecenter {
      width: 120px;
      height:31px;
      text-align:center;
      border-top: 3px solid black;
      border-bottom: 2px solid black;
      border-left: 0.5px solid black;
      border-right: 3px solid black;
    }
   
    .field_left{
        width: 120px;
        height:31px;
        border-bottom: 0.5px solid black;
        border-top: 0.5px solid black;
        text-align:center;
        font-size: 130%; 
    }
     .field_right{
        width: 120px;
        height:31px;
        border-bottom: 0.5px solid black;
        border-top: 0.5px solid black;
       
    }
     .field_middle{
        width: 120px;
        height:31px;
        border-bottom: 0.5px solid black;
        border-top: 0.5px solid black;
        border-left: 0.5px solid black;
        border-right: 0.5px solid black;
    }
    .field_middlecenter{
        width: 120px;
        height:31px;
        border-bottom: 0.5px solid black;
        border-top: 0.5px solid black;
        border-left: 0.5px solid black;
        border-right: 3px solid black;
    }
    
  
</style>
EOF;


 While ($NumberOfEntries > 0)
 {
    $pdf->AddPage();
  
   
   
    $row = $mydb->fetchRow();
    $pdf->SetFont('helvetica', 'B', 16);
    $pdf->Cell(0, 10, $row['nachname'] . ' ' . $row['vorname'] . ' (' . $row['zelt'].') - '.$row['gruppe_short_txt'] , 0, 1, 'L', false, '', 0, false, 'T', 'M');

    $pdf->SetFont('helvetica', 'B', 12);
    $tbl = $style . "<table boder=\"1\">"; 
    $tbl .= "<thead><tr><th >Einzahlung</th><th class=\"header_middle\">Auszahlung</th><th class=\"header_middlecenter\">Bestand</th><th class=\"header_middle\">Einzahlung</th><th class=\"header_middle\">Auszahlung</th><th>Bestand</th></tr></thead><tbody>";
    if ($row['kaufladen'] > 0)
     {
      $tbl .= "<tr><td class=\"field_left\">" . $row['kaufladen'] ."</td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
     }
     else
     {
      $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
     }
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "</tbody></table>";
    $pdf->writeHTMLCell	(0,0,3,15, $tbl, 0, 1, false, true,'',true);
    $pdf->Cell(120, 15, "AUSBEZAHLT:" , 0, 1, 'R', false, '', 0, false, 'T', 'M');
        
    $row = $mydb->fetchRow();
    $pdf->SetFont('helvetica', 'B', 16);
    $pdf->Cell(0, 30, $row['nachname'] . ' ' . $row['vorname'] . ' (' . $row['zelt'].') - '.$row['gruppe_short_txt']  , 0, 1, 'L', false, '', 0, false, 'T', 'M');

    $pdf->SetFont('helvetica', 'B', 12);
    $tbl = $style . "<table boder=\"1\">"; 
    $tbl .= "<thead><tr><th >Einzahlung</th><th class=\"header_middle\">Auszahlung</th><th class=\"header_middlecenter\">Bestand</th><th class=\"header_middle\">Einzahlung</th><th class=\"header_middle\">Auszahlung</th><th>Bestand</th></tr></thead><tbody>";
     if ($row['kaufladen'] > 0)
     {
      $tbl .= "<tr><td class=\"field_left\">" . $row['kaufladen'] ."</td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
     }
     else
     {
      $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
     }
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "<tr><td class=\"field_left\"> </td><td class=\"field_middle\"> </td><td class=\"field_middlecenter\"> </td><td class=\"field_middle\"> </td><td class=\"field_middle\"> </td><td class=\"field_right\"> </td></tr>";
    $tbl .= "</tbody></table>";
    $pdf->writeHTMLCell	(0,0,3,169, $tbl, 0, 1, false, true,'',true);
    $pdf->Cell(120, 15, "AUSBEZAHLT:" , 0, 1, 'R', false, '', 0, false, 'T', 'M');
   
    		
    $NumberOfEntries = $NumberOfEntries - 2;
 }


        
$filepath = '../pdf_listen/Karteikarten-Kaufladen.pdf';
$pdf->Output($filepath, 'F');

echo "...done";

$mydb->disconnect();
?>
<?php

?>