<?php

require_once("../class/dB.class.php");
require_once("../tcpdf/tcpdf.php");
 
$mydb= new DB_MySQL('zeltlager','zeltlager','Z3ltlager3363','localhost');
         
$mydb->query("SELECT * FROM VerwaltungBeitraegePreise ORDER BY jahr DESC limit 1");
$row = $mydb->fetchRow(); 

$BierPreis = money_format('%.2n €', $row["bier"]);
$LimoPreis = money_format('%.2n €', $row["limo"]);
$WasserPreis = money_format('%.2n €', $row["wasser"]);
$SchorlePreis = money_format('%.2n €', $row["schorle"]);

$RowsOnPage = 29;
$RowsWritten = 0;
 
 
// Extend the TCPDF class to create custom Header and Footer
class MYPDFKIZ extends TCPDF {

    //Page header
    public function Header()
    {
         //aktuelle Jahreszahl auslesen
        $mydb= new DB_MySQL('zeltlager','zeltlager','Z3ltlager3363','localhost');
         
        $mydb->query("SELECT * FROM VerwaltungLagerplatz ORDER BY jahr DESC limit 1");
        $row = $mydb->fetchRow();
        
        
        $this->SetFont('helvetica', 'B', 10);
        $this->Cell(170, 10, 'Evang. Gemeindejugend Memmingen - '. $row['platz'], 0, false, 'C', 0, '', 0, false, 'C', 'B');
        
       
        // Logo
        $image_file = "../images/gemeindejugend_logo.jpg";
        $this->Image($image_file, 15, 5, '20', '', 'JPG', '', 'M', true, 600, '', false, false, 0, false, false, false);
        
        $mydb->disconnect();
    }

    // Page footer
    public function Footer() 
    {
       
        // Position at 10 mm from bottom
        $this->SetY(-10);
        // Set font
        $this->SetFont('helvetica', '', 8);
        // Status zeile
        $datum  = date("d.m.Y", time());
        $this->Cell(0, 10, 'created: ' . $datum . "  -   www.zeltlageranmeldung.de                                          Seite ".$this->PageNo(). " von " . $this->getAliasNbPages(), 0, false, 'L', 0, '', 0, false, 'T', 'M');
    }
}

// create new PDF document
$pdf = new MYPDFKIZ(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(PDF_MARGIN_LEFT, 0, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

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

// 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);


$style= <<<EOF
<style>
    
    table {
        
    }
    td {
        height:28px;
        line-height:2px;
        text-align:left;
        border-bottom: 1px solid black;
    }
    .namefield{
        width: 160px;
    }
    .bierfield{
        width: 90px;
        border-left: 1px solid black;
    }
     .schorlefield{
        width: 90px;
        border-left: 1px solid black;
    }
    .limofield{
        width: 90px;
        border-left: 1px solid black;
    }
    .wasserfield{
        width: 90px;
        border-left: 1px solid black;
    }
    .sonstfield{
        width: 90px;
        border-left: 1px solid black;
    }
    
    th {
        text-align:center;
        border-bottom: 2px solid black;
    }
  
</style>
EOF;

 
$pdf->AddPage();


$pdf->SetFont('helvetica', '', 11);
$tbl = $style . "<table>"; //  cellspacing=\"0\" cellpadding=\"1\"
 $tbl .= "<thead><tr><th class=\"namefield\">&nbsp;</th><th class=\"bierfield\"><b>Bier<br>Weinschorle</b><br><br>$BierPreis</th><th class=\"schorlefield\"><b>Saftschorle</b><br><br><br>$SchorlePreis</th><th class=\"limofield\"><b>Limo, Spezi</b><br><br><br>$LimoPreis</th><th class=\"wasserfield\"><b>Wasser</b><br><br><br>$WasserPreis</th><th  class=\"sonstfield\"><b>Sonstiges</b></th></tr></thead></tbody>";


while($RowsWritten <= $RowsOnPage)
{
    $RowsWritten++; 
    $tbl .= "<tr><td class=\"namefield\"> </td><td class=\"bierfield\"> </td><td class=\"schorlefield\"> </td> <td class=\"limofield\"> </td><td class=\"wasserfield\"> </td><td class=\"sonstfield\"> </td></tr>"; 
}


$tbl .= "</tbody></table>";
//$pdf->writeHTML($tbl, true, false, false, false, '');
$pdf->writeHTMLCell	(0,0,15,30, $tbl, 0, 0, false, true,'',true);		
$RowsWritten = 0;



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


$mydb->disconnect();
?>           
