a0994cff9ddb574b24a2cbaa2c4e53191aa8a7a0
[squirrelmail.git] / src / vcard.php
1 <?php
2
3 /**
4 * vcard.php
5 *
6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This file shows an attched vcard
10 *
11 * @version $Id$
12 * @package squirrelmail
13 */
14
15 /**
16 * Path for SquirrelMail required files.
17 * @ignore
18 */
19 Define('SM_PATH','../');
20
21 /* SquirrelMail required files. */
22 require_once(SM_PATH . 'include/validate.php');
23 require_once(SM_PATH . 'functions/date.php');
24 require_once(SM_PATH . 'functions/page_header.php');
25 require_once(SM_PATH . 'functions/mime.php');
26 require_once(SM_PATH . 'include/load_prefs.php');
27
28 /* globals */
29 sqgetGlobalVar('username', $username, SQ_SESSION);
30 sqgetGlobalVar('key', $key, SQ_COOKIE);
31 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
32
33 sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
34 sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
35 sqgetGlobalVar('ent_id', $ent_id, SQ_GET);
36 sqgetGlobalVar('startMessage', $startMessage, SQ_GET);
37 /* end globals */
38
39 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
40 sqimap_mailbox_select($imapConnection, $mailbox);
41
42
43 displayPageHeader($color, 'None');
44
45 echo '<br /><table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
46 'align="center">' . "\n" .
47 '<tr><td bgcolor="' . $color[0] . '">' .
48 '<b><center>' .
49 _("Viewing a Business Card") . " - ";
50
51 $msg_url = 'read_body.php?mailbox='.urlencode($mailbox).
52 '&amp;startMessage='.urlencode($startMessage).
53 '&amp;passed_id='.urlencode($passed_id);
54
55 $msg_url = set_url_var($msg_url, 'ent_id', 0);
56
57 echo '<a href="'.$msg_url.'">'. _("View message") . '</a>';
58
59 echo '</center></b></td></tr>';
60
61 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
62
63 $entity_vcard = getEntity($message,$ent_id);
64
65 $vcard = mime_fetch_body ($imapConnection, $passed_id, $ent_id);
66 $vcard = decodeBody($vcard, $entity_vcard->header->encoding);
67 $vcard = explode ("\n",$vcard);
68 foreach ($vcard as $l) {
69 $k = substr($l, 0, strpos($l, ':'));
70 $v = substr($l, strpos($l, ':') + 1);
71 $attributes = explode(';', $k);
72 $k = strtolower(array_shift($attributes));
73 foreach ($attributes as $attr) {
74 if ($attr == 'quoted-printable')
75 $v = quoted_printable_decode($v);
76 else
77 $k .= ';' . strtolower($attr);
78 }
79
80 $v = str_replace(';', "\n", $v);
81 $vcard_nice[$k] = $v;
82 }
83
84 if ($vcard_nice['version'] == '2.1') {
85 // get firstname and lastname for sm addressbook
86 $vcard_nice['firstname'] = substr($vcard_nice['n'],
87 strpos($vcard_nice['n'], "\n") + 1, strlen($vcard_nice['n']));
88 $vcard_nice['lastname'] = substr($vcard_nice['n'], 0,
89 strpos($vcard_nice['n'], "\n"));
90 // workaround for Outlook, should be fixed in a better way,
91 // maybe in new 'vCard' class.
92 if (isset($vcard_nice['email;pref;internet'])) {
93 $vcard_nice['email;internet'] = $vcard_nice['email;pref;internet'];
94 }
95 } else {
96 echo '<tr><td align="center">' .
97 sprintf(_("vCard Version %s is not supported. Some information might not be converted correctly."),$vcard_nice['version']) .
98 "</td></tr>\n";
99 }
100
101 foreach ($vcard_nice as $k => $v) {
102 $v = htmlspecialchars($v);
103 $v = trim($v);
104 $vcard_safe[$k] = trim(nl2br($v));
105 }
106
107 $ShowValues = array(
108 'fn' => _("Name"),
109 'title' => _("Title"),
110 'email;internet' => _("Email"),
111 'url' => _("Web Page"),
112 'org' => _("Organization / Department"),
113 'adr' => _("Address"),
114 'tel;work' => _("Work Phone"),
115 'tel;home' => _("Home Phone"),
116 'tel;cell' => _("Cellular Phone"),
117 'tel;fax' => _("Fax"),
118 'note' => _("Note"));
119
120 echo '<tr><td><br />' .
121 '<table border="0" cellpadding="2" cellspacing="0" align="center">' . "\n";
122
123 if (isset($vcard_safe['email;internet'])) {
124 $vcard_safe['email;internet'] = makeComposeLink('src/compose.php?send_to='.urlencode($vcard_safe['email;internet']),
125 $vcard_safe['email;internet']);
126 }
127
128 if (isset($vcard_safe['url'])) {
129 $vcard_safe['url'] = '<a href="' . $vcard_safe['url'] . '">' .
130 $vcard_safe['url'] . '</a>';
131 }
132
133 foreach ($ShowValues as $k => $v) {
134 if (isset($vcard_safe[$k]) && $vcard_safe[$k]) {
135 echo "<tr><td align=\"right\"><b>$v:</b></td><td>" . $vcard_safe[$k] .
136 "</td><tr>\n";
137 }
138 }
139
140 echo '</table>' .
141 '<br />' .
142 '</td></tr></table>' .
143 '<table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
144 'align="center">' .
145 '<tr>' .
146 '<td bgcolor="' . $color[0] . '">' .
147 '<b><center>' .
148 _("Add to Addressbook") .
149 '</td></tr>' .
150 '<tr><td align="center">' .
151 addForm('../src/addressbook.php', 'POST', 'f_add') .
152 '<table border="0" cellpadding="2" cellspacing="0" align="center">' .
153 '<tr><td align="right"><b>' . _("Nickname:") . '</b></td>' .
154 '<td>'.
155 addInput('addaddr[nickname]', $vcard_safe['firstname'] . '-' . $vcard_safe['lastname'], '20').
156 '</td></tr>' .
157 '<tr><td align="right"><b>' . _("Note Field Contains:") . '</b></td><td>' ;
158
159 $opts = array();
160 if (isset($vcard_nice['url'])) {
161 $opts[$vcard_nice['url']] = _("Web Page");
162 }
163 if (isset($vcard_nice['adr'])) {
164 $opts[$vcard_nice['adr']] = _("Address");
165 }
166 if (isset($vcard_nice['title'])) {
167 $opts[$vcard_nice['title']] = _("Title");
168 }
169 if (isset($vcard_nice['org'])) {
170 $opts[$vcard_nice['org']] = _("Organization / Department");
171 }
172 if (isset($vcard_nice['title'])) {
173 $opts[$vcard_nice['title'].'; '.$vcard_nice['org']] = _("Title & Org. / Dept.");
174 }
175 if (isset($vcard_nice['tel;work'])) {
176 $opts[$vcard_nice['tel;work']] = _("Work Phone");
177 }
178 if (isset($vcard_nice['tel;home'])) {
179 $opts[$vcard_nice['tel;home']] = _("Home Phone");
180 }
181 if (isset($vcard_nice['tel;cell'])) {
182 $opts[$vcard_nice['tel;cell']] = _("Cellular Phone");
183 }
184 if (isset($vcard_nice['tel;fax'])) {
185 $opts[$vcard_nice['tel;fax']] = _("Fax");
186 }
187 if (isset($vcard_nice['note'])) {
188 $opts[$vcard_nice['note']] = _("Note");
189 }
190
191 echo addSelect('addaddr[label]', $opts, '', TRUE);
192 echo '</td></tr>' .
193 '<tr><td colspan="2" align="center">' .
194 addHidden('addaddr[email]', $vcard_nice['email;internet']).
195 addHidden('addaddr[firstname]', $vcard_safe['firstname']).
196 addHidden('addaddr[lastname]', $vcard_safe['lastname']).
197 addSubmit(_("Add to Address Book"), 'addaddr[SUBMIT]').
198 '</td></tr>' .
199 '</table>' .
200 '</form>' .
201 '</td></tr>' .
202 '<tr><td align="center">' .
203 '<a href="../src/download.php?absolute_dl=true&amp;passed_id=' .
204 urlencode($passed_id) . '&amp;mailbox=' . urlencode($mailbox) .
205 '&amp;ent_id=' . urlencode($ent_id) . '">' .
206 _("Download this as a file") . '</a>' .
207 '</td></tr></table>' .
208
209 '<table border="0" cellspacing="0" cellpadding="2" align="center">' .
210 '<tr><td bgcolor="' . $color[4] . '">' .
211 '</td></tr></table>' .
212 '</body></html>';
213
214 ?>