46207d5c5f427014b1efba91f421a5e452be27d6
[squirrelmail.git] / src / vcard.php
1 <?php
2
3 /**
4 * vcard.php
5 *
6 * Copyright (c) 1999-2002 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 * $Id$
12 */
13
14 require_once('../src/validate.php');
15 require_once('../functions/date.php');
16 require_once('../functions/page_header.php');
17 require_once('../functions/mime.php');
18 require_once('../src/load_prefs.php');
19
20 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
21 sqimap_mailbox_select($imapConnection, $mailbox);
22
23
24 displayPageHeader($color, 'None');
25
26 echo '<br>' .
27 html_tag( 'table', '', 'center', '', 'width="100%" border="0" cellspacing="0" cellpadding="2"' ) ."\n" .
28 html_tag( 'tr' ) . "\n" .
29 html_tag( 'td', '', 'left', $color[0] ) .
30 '<b><center>' .
31 _("Viewing a Business Card") . ' - ';
32 if (isset($where) && isset($what)) {
33 // from a search
34 echo '<a href="../src/read_body.php?mailbox=' . urlencode($mailbox) .
35 '&amp;passed_id=' . $passed_id . '&amp;where=' . urlencode($where) .
36 '&amp;what=' . urlencode($what). '">' . _("View message") . '</a>';
37 } else {
38 echo '<a href="../src/read_body.php?mailbox=' . urlencode($mailbox) .
39 '&amp;passed_id=' . $passed_id . '&amp;startMessage=' . $startMessage .
40 '&amp;show_more=0">' . _("View message") . '</a>';
41 }
42 echo '</center></b></td></tr>';
43
44 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
45
46 $entity_vcard = getEntity($message,$passed_ent_id);
47
48 $vcard = mime_fetch_body ($imapConnection, $passed_id, $passed_ent_id);
49 $vcard = decodeBody($vcard, $entity_vcard->header->encoding);
50 $vcard = explode ("\n",$vcard);
51 foreach ($vcard as $l) {
52 $k = substr($l, 0, strpos($l, ':'));
53 $v = substr($l, strpos($l, ':') + 1);
54 $attributes = explode(';', $k);
55 $k = strtolower(array_shift($attributes));
56 foreach ($attributes as $attr) {
57 if ($attr == 'quoted-printable')
58 $v = quoted_printable_decode($v);
59 else
60 $k .= ';' . $attr;
61 }
62
63 $v = str_replace(';', "\n", $v);
64 $vcard_nice[$k] = $v;
65 }
66
67 if ($vcard_nice['version'] == '2.1') {
68 // get firstname and lastname for sm addressbook
69 $vcard_nice["firstname"] = substr($vcard_nice["n"],
70 strpos($vcard_nice["n"], "\n") + 1, strlen($vcard_nice["n"]));
71 $vcard_nice["lastname"] = substr($vcard_nice["n"], 0,
72 strpos($vcard_nice["n"], "\n"));
73 } else {
74 echo html_tag( 'tr',
75 html_tag( 'td', 'vCard Version ' . $vcard_nice['version'] .
76 ' is not supported. Some information might not be converted ' .
77 'correctly.' ,
78 'center' )
79 ) . "\n";
80 }
81
82 foreach ($vcard_nice as $k => $v) {
83 $v = htmlspecialchars($v);
84 $v = trim($v);
85 $vcard_safe[$k] = trim(nl2br($v));
86 }
87
88 $ShowValues = array(
89 'fn' => _("Name"),
90 'title' => _("Title"),
91 'email;internet' => _("Email"),
92 'url' => _("Web Page"),
93 'org' => _("Organization / Department"),
94 'adr' => _("Address"),
95 'tel;work' => _("Work Phone"),
96 'tel;home' => _("Home Phone"),
97 'tel;cell' => _("Cellular Phone"),
98 'tel;fax' => _("Fax"),
99 'note' => _("Note"));
100
101 echo html_tag( 'tr' ) . html_tag( 'td', '', 'left' ) . '<br>' .
102 html_tag( 'table', '', 'center', '', 'border="0" cellpadding="2" cellspacing="0"' ) . "\n";
103
104 if (isset($vcard_safe['email;internet'])) { $vcard_safe['email;internet'] = '<a href="../src/compose.php?send_to=' .
105 $vcard_safe['email;internet'] . '">' . $vcard_safe['email;internet'] .
106 '</a>';
107 }
108 if (isset($vcard_safe['url'])) {
109 $vcard_safe['url'] = '<a href="' . $vcard_safe['url'] . '">' .
110 $vcard_safe['url'] . '</a>';
111 }
112
113 foreach ($ShowValues as $k => $v) {
114 if (isset($vcard_safe[$k]) && $vcard_safe[$k]) {
115 echo html_tag( 'tr',
116 html_tag( 'td', '<b>' . $v . ':</b>', 'right' ) .
117 html_tag( 'td', $vcard_safe[$k], 'left' )
118 ) . "\n";
119 }
120 }
121
122 echo '</table>' .
123 '<br>' .
124 '</td></tr></table>' .
125 html_tag( 'table', '', 'center', '', 'border="0" cellpadding="2" cellspacing="0" width="100%"' ) . "\n";
126 html_tag( 'tr',
127 html_tag( 'td',
128 '<b><center>' .
129 _("Add to Addressbook") . '</b></center>' ,
130 'left', $color[0] )
131 ) .
132 html_tag( 'tr' ) .
133 html_tag( 'td', '', 'center' ) .
134 '<form action="../src/addressbook.php" method="post" name="f_add">' .
135 html_tag( 'table', '', 'center', '', 'border="0" cellpadding="2" cellspacing="0" width="100%"' ) .
136 html_tag( 'tr',
137 html_tag( 'td',
138 '<b>Nickname:</b>' ,
139 'right' ) .
140 html_tag( 'td',
141 '<input type=text name="addaddr[nickname]" size=20 value="' .
142 $vcard_safe['firstname'] . '-' . $vcard_safe['lastname'] . '">' ,
143 'left' )
144 ) .
145 html_tag( 'tr' ) .
146 html_tag( 'td', '<b>Note Field Contains:</b>', 'right' ) .
147 html_tag( 'td', '', 'left' ) .
148 '<select name="addaddr[label]">';
149
150 if (isset($vcard_nice['url'])) {
151 echo '<option value="' . htmlspecialchars($vcard_nice['url']) .
152 '">' . _("Web Page") . "</option>\n";
153 }
154 if (isset($vcard_nice['adr'])) {
155 echo '<option value="' . $vcard_nice['adr'] .
156 '">' . _("Address") . "</option>\n";
157 }
158 if (isset($vcard_nice['title'])) {
159 echo '<option value="' . $vcard_nice['title'] .
160 '">' . _("Title") . "</option>\n";
161 }
162 if (isset($vcard_nice['org'])) {
163 echo '<option value="' . $vcard_nice['org'] .
164 '">' . _("Organization / Department") . "</option>\n";
165 }
166 if (isset($vcard_nice['title'])) {
167 echo '<option value="' . $vcard_nice['title'] .
168 '; ' . $vcard_nice['org'] .
169 '">' . _("Title & Org. / Dept.") . "</option>\n";
170 }
171 if (isset($vcard_nice['tel;work'])) {
172 echo '<option value="' . $vcard_nice['tel;work'] .
173 '">' . _("Work Phone") . "</option>\n";
174 }
175 if (isset($vcard_nice['tel;home'])) {
176 echo '<option value="' . $vcard_nice['tel;home'] .
177 '">' . _("Home Phone") . "</option>\n";
178 }
179 if (isset($vcard_nice['tel;cell'])) {
180 echo '<option value="' . $vcard_nice['tel;cell'] .
181 '">' . _("Cellular Phone") . "</option>\n";
182 }
183 if (isset($vcard_nice['tel;fax'])) {
184 echo '<option value="' . $vcard_nice['tel;fax'] .
185 '">' . _("Fax") . "</option>\n";
186 }
187 if (isset($vcard_nice['note'])) {
188 echo '<option value="' . $vcard_nice['note'] .
189 '">' . _("Note") . "</option>\n";
190 }
191 echo '</select>' .
192 '</td></tr>' .
193 html_tag( 'tr',
194 html_tag( 'td',
195 '<input name="addaddr[email]" type=hidden value="' .
196 htmlspecialchars($vcard_nice['email;internet']) . '">' .
197 '<input name="addaddr[firstname]" type=hidden value="' .
198 $vcard_safe['firstname'] . '">' .
199 '<input name="addaddr[lastname]" type=hidden value="' .
200 $vcard_safe['lastname'] . '">' .
201 '<input type="submit" name="addaddr[SUBMIT]" ' .
202 'value="Add to Address Book">' ,
203 'center', '', 'colspan="2"' )
204 ) .
205 '</table>' .
206 '</form>' .
207 '</td></tr>' .
208 html_tag( 'tr',
209 html_tag( 'td',
210 '<a href="../src/download.php?absolute_dl=true&amp;passed_id=' .
211 $passed_id . '&amp;mailbox=' . urlencode($mailbox) .
212 '&amp;passed_ent_id=' . $passed_ent_id . '">' .
213 _("Download this as a file") . '</a>' ,
214 'center' )
215 ) .
216 '</table>' .
217
218 html_tag( 'table',
219 html_tag( 'tr',
220 html_tag( 'td', '&nbsp;', 'left', $color[4] )
221 ) ,
222 'center', '', 'border="0" cellspacing="0" cellpadding="2"' ) .
223 '</body></html>';
224
225 ?>