Replacing deprecated HTML "center" element.
[squirrelmail.git] / src / vcard.php
CommitLineData
7baf86a9 1<?php
895905c0 2
35586184 3/**
4 * vcard.php
5 *
35586184 6 * This file shows an attched vcard
7 *
47ccfad4 8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
4b4abf93 9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 10 * @version $Id$
8f6f9ba5 11 * @package squirrelmail
35586184 12 */
7baf86a9 13
30967a1e 14/**
15 * Path for SquirrelMail required files.
16 * @ignore
17 */
846a3a21 18Define('SM_PATH','../');
86725763 19
20/* SquirrelMail required files. */
5c4ff7bf 21include_once(SM_PATH . 'include/validate.php');
86725763 22require_once(SM_PATH . 'functions/mime.php');
916669ad 23require_once(SM_PATH . 'functions/url_parser.php');
7baf86a9 24
0b97a708 25/* globals */
f38b7cf0 26sqgetGlobalVar('username', $username, SQ_SESSION);
27sqgetGlobalVar('key', $key, SQ_COOKIE);
28sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
29
30sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
31sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
32sqgetGlobalVar('ent_id', $ent_id, SQ_GET);
33sqgetGlobalVar('startMessage', $startMessage, SQ_GET);
0b97a708 34/* end globals */
35
65c3ec94 36$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
37sqimap_mailbox_select($imapConnection, $mailbox);
7baf86a9 38
65c3ec94 39displayPageHeader($color, 'None');
7baf86a9 40
3c621ba1 41echo '<br /><table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
42 'align="center">' . "\n" .
f265009a 43 '<tr><td bgcolor="' . $color[0] . '"><b><div style="text-align: center;">' .
3c621ba1 44 _("Viewing a Business Card") . " - ";
45
33c8b76b 46$msg_url = 'read_body.php?mailbox='.urlencode($mailbox).
164584f0 47 '&amp;startMessage='.urlencode($startMessage).
48 '&amp;passed_id='.urlencode($passed_id);
33c8b76b 49
24d16195 50$msg_url = set_url_var($msg_url, 'ent_id', 0);
33c8b76b 51
d444fa27 52echo '<a href="'.$msg_url.'">'. _("View message") . '</a>' .
f265009a 53 '</div></b></td></tr>';
65c3ec94 54
55$message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
56
24d16195 57$entity_vcard = getEntity($message,$ent_id);
65c3ec94 58
d444fa27 59$vcard = mime_fetch_body($imapConnection, $passed_id, $ent_id);
65c3ec94 60$vcard = decodeBody($vcard, $entity_vcard->header->encoding);
61$vcard = explode ("\n",$vcard);
62foreach ($vcard as $l) {
63 $k = substr($l, 0, strpos($l, ':'));
64 $v = substr($l, strpos($l, ':') + 1);
65 $attributes = explode(';', $k);
66 $k = strtolower(array_shift($attributes));
67 foreach ($attributes as $attr) {
68 if ($attr == 'quoted-printable')
69 $v = quoted_printable_decode($v);
70 else
40a9d8b3 71 $k .= ';' . strtolower($attr);
65c3ec94 72 }
73
0f8a1ce9 74 $v = str_replace(';', "\n", $v);
65c3ec94 75 $vcard_nice[$k] = $v;
76}
77
78if ($vcard_nice['version'] == '2.1') {
79 // get firstname and lastname for sm addressbook
40a9d8b3 80 $vcard_nice['firstname'] = substr($vcard_nice['n'],
81 strpos($vcard_nice['n'], "\n") + 1, strlen($vcard_nice['n']));
82 $vcard_nice['lastname'] = substr($vcard_nice['n'], 0,
83 strpos($vcard_nice['n'], "\n"));
84 // workaround for Outlook, should be fixed in a better way,
85 // maybe in new 'vCard' class.
86 if (isset($vcard_nice['email;pref;internet'])) {
87 $vcard_nice['email;internet'] = $vcard_nice['email;pref;internet'];
88 }
65c3ec94 89} else {
89ac34a4 90 echo '<tr><td align="center">' .
1bae252c 91 sprintf(_("vCard Version %s is not supported. Some information might not be converted correctly."),
92 htmlspecialchars($vcard_nice['version'])) .
134e4174 93 "</td></tr>\n";
d543fbac 94 $vcard_nice['firstname'] = '';
95 $vcard_nice['lastname'] = '';
65c3ec94 96}
97
98foreach ($vcard_nice as $k => $v) {
99 $v = htmlspecialchars($v);
100 $v = trim($v);
101 $vcard_safe[$k] = trim(nl2br($v));
102}
103
104$ShowValues = array(
105 'fn' => _("Name"),
106 'title' => _("Title"),
674a2ca2 107 'email;internet' => _("E-mail"),
65c3ec94 108 'url' => _("Web Page"),
109 'org' => _("Organization / Department"),
110 'adr' => _("Address"),
111 'tel;work' => _("Work Phone"),
112 'tel;home' => _("Home Phone"),
113 'tel;cell' => _("Cellular Phone"),
114 'tel;fax' => _("Fax"),
115 'note' => _("Note"));
116
3c621ba1 117echo '<tr><td><br />' .
118 '<table border="0" cellpadding="2" cellspacing="0" align="center">' . "\n";
65c3ec94 119
d62c4938 120if (isset($vcard_safe['email;internet'])) {
121 $vcard_safe['email;internet'] = makeComposeLink('src/compose.php?send_to='.urlencode($vcard_safe['email;internet']),
122 $vcard_safe['email;internet']);
65c3ec94 123}
d62c4938 124
65c3ec94 125if (isset($vcard_safe['url'])) {
3c621ba1 126 $vcard_safe['url'] = '<a href="' . $vcard_safe['url'] . '">' .
127 $vcard_safe['url'] . '</a>';
65c3ec94 128}
129
130foreach ($ShowValues as $k => $v) {
131 if (isset($vcard_safe[$k]) && $vcard_safe[$k]) {
d444fa27 132 echo "<tr><td align=\"right\" valign=\"top\"><b>$v:</b></td><td>" .
133 $vcard_safe[$k] . "</td><tr>\n";
65c3ec94 134 }
135}
7baf86a9 136
d444fa27 137?>
138</table>
139<br />
140</td></tr></table>
141<table width="100%" border="0" cellspacing="0" cellpadding="2" align="center">
142<tr><td bgcolor="<?php echo $color[0]; ?>">
f265009a 143<div style="text-align: center;"><b><?php echo _("Add to address book"); ?></b></div>
d444fa27 144</td></tr>
145<tr><td align="center">
146<?php echo addForm('../src/addressbook.php', 'post', 'f_add'); ?><br />
147<table border="0" cellpadding="2" cellspacing="0" align="center">
148<tr><td align="right"><b><?php echo _("Nickname"); ?>:</b></td>
149<td>
150<?php
151
152echo addInput('addaddr[nickname]', $vcard_safe['firstname'] .
153 '-' . $vcard_safe['lastname'], '20');
154
155/*
916669ad 156 * If the vCard comes with an e-mail address it should be added to the
d444fa27 157 * address book, otherwise the user must add one manually to avoid an
916669ad 158 * error message in src/addressbook.php. SquirrelMail is nice enough to
159 * suggest the e-mail address of the sender though.
d444fa27 160 */
161if (isset($vcard_nice['email;internet'])) {
162 echo addHidden('addaddr[email]', $vcard_nice['email;internet']);
163} else {
916669ad 164 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
165 $header = $message->rfc822_header;
166 $from_name = $header->getAddr_s('from');
167
d444fa27 168 echo '</td></tr>' .
169 '<tr><td align="right"><b>' . _("E-mail address") . ':</b></td><td>' .
916669ad 170 addInput('addaddr[email]',
171 getEmail(decodeHeader($from_name)), '20');
d444fa27 172}
173
174echo '</td></tr>' .
175 '<tr><td align="right"><b>' . _("Additional info") . ':</b></td><td>';
7baf86a9 176
64c9e87e 177$opts = array();
65c3ec94 178if (isset($vcard_nice['url'])) {
64c9e87e 179 $opts[$vcard_nice['url']] = _("Web Page");
65c3ec94 180}
181if (isset($vcard_nice['adr'])) {
64c9e87e 182 $opts[$vcard_nice['adr']] = _("Address");
65c3ec94 183}
184if (isset($vcard_nice['title'])) {
64c9e87e 185 $opts[$vcard_nice['title']] = _("Title");
65c3ec94 186}
187if (isset($vcard_nice['org'])) {
64c9e87e 188 $opts[$vcard_nice['org']] = _("Organization / Department");
65c3ec94 189}
190if (isset($vcard_nice['title'])) {
64c9e87e 191 $opts[$vcard_nice['title'].'; '.$vcard_nice['org']] = _("Title & Org. / Dept.");
65c3ec94 192}
193if (isset($vcard_nice['tel;work'])) {
64c9e87e 194 $opts[$vcard_nice['tel;work']] = _("Work Phone");
65c3ec94 195}
196if (isset($vcard_nice['tel;home'])) {
64c9e87e 197 $opts[$vcard_nice['tel;home']] = _("Home Phone");
65c3ec94 198}
199if (isset($vcard_nice['tel;cell'])) {
64c9e87e 200 $opts[$vcard_nice['tel;cell']] = _("Cellular Phone");
65c3ec94 201}
202if (isset($vcard_nice['tel;fax'])) {
64c9e87e 203 $opts[$vcard_nice['tel;fax']] = _("Fax");
65c3ec94 204}
205if (isset($vcard_nice['note'])) {
64c9e87e 206 $opts[$vcard_nice['note']] = _("Note");
65c3ec94 207}
64c9e87e 208
d444fa27 209/*
210 * If the vcard comes with nothing but name and e-mail address, the user gets
211 * the chance to type some additional info. If there's more info in the card,
212 * the user gets to choose what will be added as additional info.
213 */
214if (count($opts) == 0) {
215 echo addInput('addaddr[label]', '', '20');
216} else {
217 echo addSelect('addaddr[label]', $opts, '', TRUE);
218}
219
2841ba15 220?>
221</td></tr>
d444fa27 222<tr><td colspan="2" align="center"><br />
2841ba15 223<?php
6b2eed75 224
d444fa27 225echo addHidden('addaddr[firstname]', $vcard_safe['firstname']) .
226 addHidden('addaddr[lastname]', $vcard_safe['lastname']) .
674a2ca2 227 addSubmit(_("Add to address book"), 'addaddr[SUBMIT]');
d444fa27 228
2841ba15 229?>
230</td></tr>
231</table>
232</form>
233</td></tr>
234<tr><td align="center">
235<?php
d444fa27 236echo '<a href="../src/download.php?absolute_dl=true&amp;passed_id=' .
2841ba15 237 urlencode($passed_id) . '&amp;mailbox=' . urlencode($mailbox) .
d444fa27 238 '&amp;ent_id=' . urlencode($ent_id) . '">' .
2841ba15 239 _("Download this as a file") . '</a>';
240?>
241</td></tr></table>
2841ba15 242<table border="0" cellspacing="0" cellpadding="2" align="center">
243<tr><td bgcolor="<?php echo $color[4]; ?>">
244</td></tr></table>
5c4ff7bf 245<?php
246$oTemplate->display('footer.tpl');
247?>