<form name="display_contact" action="<?php echo Horde::applicationUrl('displayobject.php') ?>" method="post">

<table align="center" border="0" cellpadding="2" cellspacing="2">
<tr>
    <td colspan="2">

<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
    <td class="header">
        <b><?php echo $this->object->getValue('name') ?></b>&nbsp;
    </td>

<?php
$url = Turba::addParameter('', 'source=' . urlencode($this->object->source->name));
$url = Turba::addParameter($url, 'key=' . urlencode($this->object->getValue('__key')));

if ($this->object->isEditable()): ?>
    <td class="header" align="right"><span class="smallheader">
      <?php echo Horde::link(Horde::applicationUrl('editobject.php' . $url), _("Edit"), 'menuitem') . _("Edit") ?></a> |
      <?php echo Horde::link(Horde::applicationUrl('deleteobject.php' . $url), _("Delete"), 'menuitem') . _("Delete") ?></a>
    </span></td>
<?php endif; ?>
</tr>
</table>

    </td>
</tr>

<?php
foreach ($attributes as $key => $field) {
    if (!isset($fields[$key])) {
        continue;
    }
    $val = $this->object->getValue($key);
    $mapurl = null;
    if (empty($val)) {
        $value = '&nbsp;';
    } elseif ($field['type'] == 'email') {
        // Format the address according to RFC822.
        $mailbox_host = explode('@', $val);
        if (!isset($mailbox_host[1])) {
            $mailbox_host[1] = '';
        }
        $name = $this->object->getValue('name');
        $address = imap_rfc822_write_address($mailbox_host[0], $mailbox_host[1], $name);
        // Get rid of the trailing @ (when no host is included in the email address).
        $address = str_replace('@>', '>', $address);
        $mail_link = $GLOBALS['registry']->link('mail/compose', array('to' => $address, 'label' => $this->object->getvalue($key)));
        if (PEAR::isError($mail_link)) {
            $mail_link = 'mailto:' . urlencode($address);
        }

        $value = Horde::link($mail_link, sprintf(_("Send mail to %s"), $name)) . $this->object->getvalue($key) . '</a>';
    } elseif ($field['type'] == 'date') {
        $value = date('d. m. Y', $this->object->getValue($key));
    } else {
        if (stristr($key, 'address')) {
            if (preg_match('/(.*)\n(.*)\s*,\s*(\w+)\.?\s+(\d+|[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d)/', $this->object->getValue($key), $addressParts)) {
                // American/Canadian address style.
                $mapurl = 'http://www.mapquest.com/maps/map.adp?size=big&zoom=7';
                if (!empty($addressParts[1])) {
                    $mapurl .= '&address=' . urlencode($addressParts[1]);
                }
                if (!empty($addressParts[2])) {
                    $mapurl .= '&city=' . urlencode($addressParts[2]);
                }
                if (!empty($addressParts[3])) {
                    $mapurl .= '&state=' . urlencode($addressParts[3]);
                }
                if (!empty($addressParts[4])) {
                    $mapurl .= '&zipcode=' . urlencode($addressParts[4]);
                    if (preg_match('|[a-zA-Z]\d[a-zA-Z]\s?\d[a-zA-Z]\d|', $addressParts[4])) {
                        $mapurl .= '&country=CA';
                    }
                }
            } elseif (preg_match('/(.*)\nD-(\d{5})\s+(.*)/i', $this->object->getValue($key), $addressParts)) {
                // German address style.
                $mapurl = 'http://www.map24.de/map24/index.php3?maptype=RELOAD&country0=de&gcf=1';
                if (!empty($addressParts[1])) {
                    $mapurl .= '&street0=' . urlencode($addressParts[1]);
                }
                if (!empty($addressParts[2])) {
                    $mapurl .= '&zip0=' . urlencode($addressParts[2]);
                }
                if (!empty($addressParts[3])) {
                    $mapurl .= '&city0=' . urlencode($addressParts[3]);
                }
            }
        }
        $value = htmlspecialchars($this->object->getValue($key));
    }
?>
<tr>
    <td class="light" align="right" valign="top"><b><?php if (!empty($mapurl)) { echo Horde::link($mapurl, _("View map"), null, '_blank') . Horde::img('map.gif', 'alt="' . htmlspecialchars(_("View map")) . '" align="middle"') . '</a>'; } echo htmlspecialchars($field['desc']) ?>&nbsp;</b></td>
    <td class="text"><?php echo ($field['type'] == 'multiline') ? nl2br($value) : $value ?></td>
</tr>
<?php } ?>

<?php if ($this->object->isEditable()): ?>
<tr>
    <td colspan="2" class="header" align="right"><span class="smallheader">
      <?php echo Horde::link(Horde::applicationUrl('editobject.php' . $url), _("Edit"), 'menuitem') . _("Edit") ?></a> |
      <?php echo Horde::link(Horde::applicationUrl('deleteobject.php' . $url), _("Delete"), 'menuitem') . _("Delete") ?></a>
    </span></td>
</tr>
<?php endif; ?>

</table>
</form>
