<?php

require_once 'Contact_Vcard_Build.php';
require_once "inc/stdLib.php";
include "inc/FirmenLib.php";
$Q = $_GET["Q"] ? $_GET["Q"] : $_POST["Q"];
// instantiate a builder object (defaults to version 3.0)
$vcard = new Contact_Vcard_Build();
if ($_GET["pid"]) {
    include "inc/persLib.php";
    $data = getKontaktStamm($_GET["pid"]);
    //UID
    $UID = 'P' . $_GET["pid"] . '@' . $_SESSION['mandant'];
    $vcard->setKey($_GET["pid"]);
    $vcard->setUniqueID($UID);
    $vcard->setRevision(date('c'));
    // set a formatted name
    $vcard->setFormattedName($data["cp_givenname"] . " " . $data["cp_name"]);
    // set the structured name parts
    $prefix = $data["cp_greeting"] ? $data["cp_greeting"] . " " . $data["cp_title"] : $data["cp_title"];
    $vcard->setName($data["cp_name"], $data["cp_givenname"], "", $prefix, "");
    // add a work email.  note that we add the value
    // first and the param after -- Contact_Vcard_Build
    // is smart enough to add the param in the correct place.
    if ($data["cp_email"]) {
        $vcard->addEmail($data["cp_email"]);
        $vcard->addParam('TYPE', 'WORK');
        $vcard->addParam('TYPE', 'PREF');
    }
    // add a work address
    $vcard->addAddress('', '', $data["cp_street"], $data["cp_city"], '', $data["cp_zipcode"], $data["cp_country"]);