XHTML fixes
[squirrelmail.git] / src / vcard.php
CommitLineData
7baf86a9 1<?php
895905c0 2
35586184 3/**
4 * vcard.php
5 *
82d304a0 6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This file shows an attched vcard
10 *
30967a1e 11 * @version $Id$
8f6f9ba5 12 * @package squirrelmail
35586184 13 */
7baf86a9 14
30967a1e 15/**
16 * Path for SquirrelMail required files.
17 * @ignore
18 */
846a3a21 19Define('SM_PATH','../');
86725763 20
21/* SquirrelMail required files. */
08185f2a 22require_once(SM_PATH . 'include/validate.php');
86725763 23require_once(SM_PATH . 'functions/mime.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" .
d444fa27 43 '<tr><td bgcolor="' . $color[0] . '"><b><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>' .
53 '</center></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"),
107 'email;internet' => _("Email"),
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]; ?>">
143<center><b><?php echo _("Add to Addressbook"); ?></b></center>
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/*
156 * If the vcard comes with an e-mail address it should be added to the
157 * address book, otherwise the user must add one manually to avoid an
158 * error message in src/addressbook.php.
159 *
160 * TODO: If there's no e-mail address in the vcard, use the sender's address
161 * instead of letting the user entering it manually.
162 */
163if (isset($vcard_nice['email;internet'])) {
164 echo addHidden('addaddr[email]', $vcard_nice['email;internet']);
165} else {
166 echo '</td></tr>' .
167 '<tr><td align="right"><b>' . _("E-mail address") . ':</b></td><td>' .
168 addInput('addaddr[email]', '', '20');
169}
170
171echo '</td></tr>' .
172 '<tr><td align="right"><b>' . _("Additional info") . ':</b></td><td>';
7baf86a9 173
64c9e87e 174$opts = array();
65c3ec94 175if (isset($vcard_nice['url'])) {
64c9e87e 176 $opts[$vcard_nice['url']] = _("Web Page");
65c3ec94 177}
178if (isset($vcard_nice['adr'])) {
64c9e87e 179 $opts[$vcard_nice['adr']] = _("Address");
65c3ec94 180}
181if (isset($vcard_nice['title'])) {
64c9e87e 182 $opts[$vcard_nice['title']] = _("Title");
65c3ec94 183}
184if (isset($vcard_nice['org'])) {
64c9e87e 185 $opts[$vcard_nice['org']] = _("Organization / Department");
65c3ec94 186}
187if (isset($vcard_nice['title'])) {
64c9e87e 188 $opts[$vcard_nice['title'].'; '.$vcard_nice['org']] = _("Title & Org. / Dept.");
65c3ec94 189}
190if (isset($vcard_nice['tel;work'])) {
64c9e87e 191 $opts[$vcard_nice['tel;work']] = _("Work Phone");
65c3ec94 192}
193if (isset($vcard_nice['tel;home'])) {
64c9e87e 194 $opts[$vcard_nice['tel;home']] = _("Home Phone");
65c3ec94 195}
196if (isset($vcard_nice['tel;cell'])) {
64c9e87e 197 $opts[$vcard_nice['tel;cell']] = _("Cellular Phone");
65c3ec94 198}
199if (isset($vcard_nice['tel;fax'])) {
64c9e87e 200 $opts[$vcard_nice['tel;fax']] = _("Fax");
65c3ec94 201}
202if (isset($vcard_nice['note'])) {
64c9e87e 203 $opts[$vcard_nice['note']] = _("Note");
65c3ec94 204}
64c9e87e 205
d444fa27 206/*
207 * If the vcard comes with nothing but name and e-mail address, the user gets
208 * the chance to type some additional info. If there's more info in the card,
209 * the user gets to choose what will be added as additional info.
210 */
211if (count($opts) == 0) {
212 echo addInput('addaddr[label]', '', '20');
213} else {
214 echo addSelect('addaddr[label]', $opts, '', TRUE);
215}
216
2841ba15 217?>
218</td></tr>
d444fa27 219<tr><td colspan="2" align="center"><br />
2841ba15 220<?php
6b2eed75 221
d444fa27 222echo addHidden('addaddr[firstname]', $vcard_safe['firstname']) .
223 addHidden('addaddr[lastname]', $vcard_safe['lastname']) .
224 addSubmit(_("Add to Address Book"), 'addaddr[SUBMIT]');
225
2841ba15 226?>
227</td></tr>
228</table>
229</form>
230</td></tr>
231<tr><td align="center">
232<?php
d444fa27 233echo '<a href="../src/download.php?absolute_dl=true&amp;passed_id=' .
2841ba15 234 urlencode($passed_id) . '&amp;mailbox=' . urlencode($mailbox) .
d444fa27 235 '&amp;ent_id=' . urlencode($ent_id) . '">' .
2841ba15 236 _("Download this as a file") . '</a>';
237?>
238</td></tr></table>
2841ba15 239<table border="0" cellspacing="0" cellpadding="2" align="center">
240<tr><td bgcolor="<?php echo $color[4]; ?>">
241</td></tr></table>
242</body></html>