<?php
/**
 * phpaga
 *
 * PDF template: show the letterhead
 *
 * This file contains the necessary routines to manage expenses.
 *
 * @author Florian Lanthaler <florian@phpaga.net>
 * @version $Id: letterhead.tpl.php 522 2005-05-05 20:36:24Z worf $
 *
 * Copyright (c) 2003, Florian Lanthaler <florian@phpaga.net>
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 *    * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *
 *    * Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in
 *      the documentation and/or other materials provided with the
 *      distribution.
 *
 *    * Neither the name of Florian Lanthaler nor the names of his
 *      contributors may be used to endorse or promote products derived
 *      from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

$logo_filename = $data["logo_filename"];

$loc = "";

$header = array ();
$header[] = PHPAGA_LETTERHEAD_OWNER_PERSONALTAXNR;
$header[] = PHPAGA_LETTERHEAD_COMPANY_TAXNR;
$header[] = "";
$header[] = PHPAGA_LETTERHEAD_COMPANY_PHONE;
$header[] = "";

$loc = array_reverse(explode("\n", PHPAGA_LETTERHEAD_COMPANY_FULLLOCATION));

foreach($loc as $line)
{
    $header[] = $line;
}

$header[] = PHPAGA_LETTERHEAD_COMPANY_STREET;

$lethead = $this->openObject();
$this->saveState();

$this->setStrokeColor(0,0,0, 1);
$this->setLineStyle(0.5);
$this->setColor(0,0,0, 1);

/* show company logo if available */

if (isset($logo_filename) && strlen($logo_filename)
    && is_file($logo_filename) && is_readable($logo_filename))
{
    $this->addJpegFromFile($logo_filename,
                           PHPAGA_PDF_BORDER_LEFT,
                           PHPAGA_PDF_POS_Y_LOGO,
                           PHPAGA_PDF_LOGOWIDTH);
}

/* show company name */

$this->ezSetY(PHPAGA_PDF_POS_Y_HEADER_NAME);
$this->ezText(PHPAGA_LETTERHEAD_COMPANY_NAME,
              PHPAGA_PDF_FONT_SIZE_HEADER,
              array('aleft' => PHPAGA_PDF_BORDER_LEFT));

/* email address */

$this->ezSetY(PHPAGA_PDF_POS_Y_HEADER_EMAIL);
$this->ezText(PHPAGA_LETTERHEAD_COMPANY_EMAIL,
              PHPAGA_PDF_FONT_SIZE_NORMAL,
              array('aleft' => PHPAGA_PDF_BORDER_LEFT));


/* show the rest */

$y = PHPAGA_PDF_POS_Y_HEADER_RLINE5;

foreach ($header as $h)
{
    if ($h == "")
    {
        /* just hop a little bit upward */
        $y = ($y + PHPAGA_PDF_HEADER_NEXTLINE / 2);
    }
    else
    {

        $this->ezSetY($y);
        $this->ezText($h,
                      PHPAGA_PDF_FONT_SIZE_SMALL,
                      array('aleft' =>
                            PHPAGA_PDF_START_RIGHT -
                            $this->getTextWidth(
                                PHPAGA_PDF_FONT_SIZE_SMALL,
                                $h)));

        $y += PHPAGA_PDF_HEADER_NEXTLINE;
    }
}

/* draw top and bottom separator */

$this->setStrokeColor(0.5,0.5,0.5, 1);
$this->setLineStyle(0.5);

$this->line(PHPAGA_PDF_BORDER_LEFT,
            PHPAGA_PDF_SEPARATOR_TOP_HEIGHT,
            PHPAGA_PDF_DOCWIDTH - PHPAGA_PDF_BORDER_RIGHT,
            PHPAGA_PDF_SEPARATOR_TOP_HEIGHT);

$this->line(PHPAGA_PDF_BORDER_LEFT,
            PHPAGA_PDF_SEPARATOR_BOTTOM_HEIGHT,
            PHPAGA_PDF_DOCWIDTH - PHPAGA_PDF_BORDER_RIGHT,
            PHPAGA_PDF_SEPARATOR_BOTTOM_HEIGHT);

/* draw the footer */
$this->setColor(0.2,0.2,0.2, 1);
/*
$this->ezSetY(PHPAGA_PDF_SEPARATOR_BOTTOM_HEIGHT);

$this->ezText(PHPAGA_LETTERHEAD_FOOTER,
              PHPAGA_PDF_FONT_SIZE_SMALL,
              array('justification'=>'centre'));
*/


$this->addText(PHPAGA_PDF_BORDER_LEFT,
               PHPAGA_PDF_SEPARATOR_BOTTOM_HEIGHT - PHPAGA_PDF_HEADER_NEXTLINE,
               PHPAGA_PDF_FONT_SIZE_SMALL,
               PHPAGA_LETTERHEAD_FOOTER);

$this->setColor(0,0,0, 1);
$this->setStrokeColor(0,0,0, 1);

$this->restoreState();
$this->closeObject();

?>