<?php
/* GLOBAL PDF GENERATOR v2.0
 *
 * class.pdf_from_HTML.inc - extension class for fpdf.php
 * ____________________________________________________________
 *
 * To run this class you need to install FPDF.
 * This version of Global PDF Generator is tested with FPDF v1.53
 * Get a copy from http://www.fpdf.de
 *
 * Developed by Dennis Ritz <ritz@global-cube.de>
 * Copyright (c) 2005-2006 Global-Cube Business Solutions, http://www.global-cube.de/
 * All rights reserved.
 *
 * You are not allowed to sell, rent or lend this software
 */

/* Global PDF Generator/class.pdf_from_HTML.inc, v2.0 2006/01/15 23:06:13 */


require("C:/Programme/Apache2/htdocs/qbuilder/pdf/FPDF/fpdf.php");


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

   var $pdf_version = "2.0";
   var $produkt     = "Undefiniert";
   var $scaling		= 3.5;
   var $relPos 		= null;
   var $bMargin		= 20;


   function makePDF($objects)
   {
		$this->SetAutoPageBreak(false, $this->bMargin);
      	$this->AliasNbPages();
      	$this->AddPage();
        $this->setMargins(10, 30);
      	$this->insertObjects($objects);
      	$this->Output();
   }


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

	function Header()
	{
        $this -> SetXY(10, 10);
        //assign Props:
        $this -> produkt = "Global PDF Generator";




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

        //Zweite Zeile
        $this -> SetX(10);
        //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()
	{

        $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,'Global PDF Generator Version: ' . $this -> pdf_version . '  Copyright 2005  Global-Cube Business Solutions  All rights reserved',0,0,'C');
	}

	function insertObjects($objects)
	{
		//FOR Debugging
/*		echo "<pre>";
    		print_r($objects);
        echo "</pre>";
*/

		foreach ($objects['objects'] as $key_object => $object)
		{
        	$this -> SetFontSize(6);
            $object = $this -> SetScale($object);
            $object = $this -> SetPos($object);
/*        echo "<br>-------------------------------------------------------------------------------<br>";
		echo "<pre>";
    		print_r($objects);
        echo "</pre>";
*/          $object['TEXT'] = str_replace("<BR>", "\n", $object['TEXT']);
            $this -> SetFillColor($object['BGCOLOR'][0], $object['BGCOLOR'][1], $object['BGCOLOR'][2]);
        	$this -> MultiCell($object['WIDTH'], $object['HEIGHT'], $object['TEXT'], 1, $object['ALIGN'], 1);
        }
    }


function SetScale($object)
{
	$object['LEFT'] = $object['LEFT'] / $this -> scaling;
    $object['TOP'] = $object['TOP'] / $this -> scaling;
    $object['WIDTH'] = $object['WIDTH'] / $this -> scaling;
    $object['HEIGHT'] = $object['HEIGHT'] / $this -> scaling;

    return $object;
}


function SetPos($object)
{
	//If the height h would cause an overflow, add a new page immediately

	if($object['TOP'] + $object['HEIGHT'] + abs($this->tMargin) - $this -> relPos > $this->PageBreakTrigger){
		$this -> AddPage();
        $this -> relPos = $object['TOP'];
	}
    $object['HEIGHT'] = $object['HEIGHT'] / (substr_count($object['TEXT'], "<BR>") + 1);
    $object['TOP'] = $object['TOP'] + abs($this->tMargin) - $this -> relPos;
    $object['LEFT'] = $object['LEFT'] + $this -> lMargin;


    $this -> SetXY( $object['LEFT'],$object['TOP']);
    return $object;
}
//End of PDF_FROM_HTML class
}
?>