<?php

require("fpdf.php");

class GCPDF extends FPDF
{
   var $feld = array("","","","");

   var $pdf_version = "1.0";
   var $produkt     = "Undefiniert";


function setFeld ($feld) {
   $this->feld = $feld;
}

function Header()
{
        //assign Props:
        $this -> produkt = $_POST['pdf_titel'];




        //LucidaSansUnicode 20
        $this->SetFont('LucidaSansUnicode','', 20);
        //Font Color
        $this->SetTextColor(17, 17,175);
        //Fill Color
        $this->SetFillColor(147, 147, 147);
        //Title
        $this->Cell(160,7,$this->produkt,0,0,'L');
        //LucidaSansUnicode 10
        $this->SetFont('LucidaSansUnicode','',10);
        //Font Color
        $this->SetTextColor(147, 147, 147);
        //Niederlassung
        $this->Cell(60,7,$this->feld[0],0,0,'L');
        //Planner Version
        $this->Cell(60,7,$this->feld[1],0,1,'L');
        //Font Color
        $this->SetTextColor(255, 255, 255);
        //Version
        //$this->Cell(286,4,'PDF Generator Version: '.$this->pdf_version,0,1,'L',1);
        //Font Color
        $this->SetTextColor(255, 255, 255);
        //nach rechts
        $this->Cell(160,4,'',0,0,'L',1);
        //Bereich
        $this->Cell(60,4,$this->feld[2],0,0,'L',1);
        //Kategorie
        $this->Cell(60,4,$this->feld[3],0,0,'L',1);
        //Line break
        $this->Ln(15);
}

function Footer()
{

        //&Uuml;bermalen
        $this->SetTextColor(255, 255, 255);
        $this->SetX(0);
        $this->SetX(160);
        $this->Cell();
        $datenquelle = 'Datei';
        //Position at 1.5 cm from bottom
        $this->SetY(-15);
        //Arial italic 8
        $this->SetFont('Arial','I',8);
        //Font Color
        $this->SetTextColor(147, 147, 147);
        //Date
        $timestamp = time();
        $date = date("d.m.Y", $timestamp);
        $time = date("H:i:s", $timestamp);
        //Date
        $this->Cell(1,5,'Erstellungsdatum: '.$date . ' - ' . $time,0,0,'L');
        //Page number
        $this->Cell(0,5,'- Seite '.$this->PageNo().'/{nb} -',0,1,'C');
        //Arial italic 8
        $this->SetFont('Arial','',6);
        //Copyright information
        $this->Cell(0,4,'PDF Generator Version: ' . $this -> pdf_version . '  Copyright 2005  Global-Cube Business Solutions',0,0,'C');
}

   function insertData ($daten)
   {
      foreach ($daten as $key_tabelle => $tabelle)
      {
         if (!isset($daten[$key_tabelle][0][0])) die ("\$daten[" . $key_tabelle . "][0][0] ist undefiniert!");
         foreach ($tabelle as $key_zeile => $zeile)
         {
            foreach ($zeile as $key_zelle => $zelle)
            {
//echo "Tabelle: ".$key_tabelle." - Zeile: ".$key_zeile." - Zelle: ".$key_zelle." - Zelleninhalt: ".@$zelle['TEXT']." - Zellenbreite: ".@$zelle['WIDTH']." Background: ".@$zelle['BG_COLOR'][0].", ".@$zelle['BG_COLOR'][1].", ".@$zelle['BG_COLOR'][2]."<br>";
               if (!isset($daten[$key_tabelle][0][$key_zelle])) $daten[$key_tabelle][0][$key_zelle] = array();
               if (!isset($daten[$key_tabelle][$key_zeile][0])) $daten[$key_tabelle][$key_zeile][0] = array();
               if (!isset($daten[$key_tabelle][$key_zeile][$key_zelle])) $daten[$key_tabelle][$key_zeile][$key_zelle] = array();

               if (($key_zeile == 0) && ($key_zelle > 0))
               {
                  $ausgabe[$key_tabelle][$key_zeile][($key_zelle - 1)] = array_merge($daten[$key_tabelle][0][0], $daten[$key_tabelle][0][$key_zelle]);
               }

               if (($key_zeile > 0) && ($key_zelle > 0))
               {
                  $ausgabe[$key_tabelle][$key_zeile][($key_zelle - 1)] = array_merge($daten[$key_tabelle][0][0], $daten[$key_tabelle][0][$key_zelle], $daten[$key_tabelle][$key_zeile][0], $daten[$key_tabelle][$key_zeile][$key_zelle]);
               }
            }
         }
      }

      foreach ($ausgabe as $key_tabelle => $tabelle)
      {
         $cols = count($tabelle[0]);
         $rows = count ($tabelle) - 1;

         //initialize the table with 3 columns
         $this->Table_Init($cols);

         //set header style
         foreach ($tabelle[1] as $key_titel => $titel)
         {
            $header_type[$key_titel] = $titel;
         }

         $this->Set_Header_Type($header_type);

         //set data style
         foreach ($tabelle[0] as $key_spalten_format => $spalten_format)
         {
            $data_type[$key_spalten_format] = $tabelle[0][$key_spalten_format];
         }

         $this->Set_Data_Type($data_type);

         //draw the first header
         $this->Draw_Header();

         for($i=1; $i < $rows; $i++)
         {
            for($k=0; $k < $cols; $k++)
            {
               $data[$k] = $ausgabe[$key_tabelle][$i+1][$k];
            }
            $this->Draw_Data($data);
         }
      }

      $this->Set_Header_Type($header_type);

      $this->Draw_Table_Border();
   }
}
?>