bf9d46f1c499df8a1268b6eb89205660264443e9
[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 "<tr><td align=right><b>$v:</b></td><td>" . $vcard_safe[$k] .
116 "</td><tr>\n";
117 }
118 }
119
120 echo '</table>' .
121 '<br>' .
122 '</td></tr></table>' .
123 html_tag( 'table', '', 'center', '', 'border="0" cellpadding="2" cellspacing="0" width="100%"' ) . "\n";
124 html_tag( 'tr',
125 html_tag( 'td',
126 '<b><center>' .
127 _("Add to Addressbook") . '</b></center>' ,
128 'left', $color[0] )
129 ) .
130 html_tag( 'tr' ) .
131 html_tag( 'td', '', 'center' ) .
132 '<form action="../src/addressbook.php" method="post" name="f_add">' .
133 html_tag( 'table', '', 'center', '', 'border="0" cellpadding="2" cellspacing="0" width="100%"' ) .
134 html_tag( 'tr',
135 html_tag( 'td',
136 '<b>Nickname:</b>' ,
137 'right' ) .
138 html_tag( 'td',
139 '<input type=text name="addaddr[nickname]" size=20 value="' .
140 $vcard_safe['firstname'] . '-' . $vcard_safe['lastname'] . '">' ,
141 'left' )
142 ) .
143 html_tag( 'tr' ) .
144 html_tag( 'td', '<b>Note Field Contains:</b>', 'right' ) .
145 html_tag( 'td', '', 'left' ) .
146 '<select name="addaddr[label]">';
147
148 if (isset($vcard_nice['url'])) {
149 echo '<option value="' . htmlspecialchars($vcard_nice['url']) .
150 '">' . _("Web Page") . "</option>\n";
151 }
152 if (isset($vcard_nice['adr'])) {
153 echo '<option value="' . $vcard_nice['adr'] .
154 '">' . _("Address") . "</option>\n";
155 }
156 if (isset($vcard_nice['title'])) {
157 echo '<option value="' . $vcard_nice['title'] .
158 '">' . _("Title") . "</option>\n";
159 }
160 if (isset($vcard_nice['org'])) {
161 echo '<option value="' . $vcard_nice['org'] .
162 '">' . _("Organization / Department") . "</option>\n";
163 }
164 if (isset($vcard_nice['title'])) {
165 echo '<option value="' . $vcard_nice['title'] .
166 '; ' . $vcard_nice['org'] .
167 '">' . _("Title & Org. / Dept.") . "</option>\n";
168 }
169 if (isset($vcard_nice['tel;work'])) {
170 echo '<option value="' . $vcard_nice['tel;work'] .
171 '">' . _("Work Phone") . "</option>\n";
172 }
173 if (isset($vcard_nice['tel;home'])) {
174 echo '<option value="' . $vcard_nice['tel;home'] .
175 '">' . _("Home Phone") . "</option>\n";
176 }
177 if (isset($vcard_nice['tel;cell'])) {
178 echo '<option value="' . $vcard_nice['tel;cell'] .
179 '">' . _("Cellular Phone") . "</option>\n";
180 }
181 if (isset($vcard_nice['tel;fax'])) {
182 echo '<option value="' . $vcard_nice['tel;fax'] .
183 '">' . _("Fax") . "</option>\n";
184 }
185 if (isset($vcard_nice['note'])) {
186 echo '<option value="' . $vcard_nice['note'] .
187 '">' . _("Note") . "</option>\n";
188 }
189 echo '</select>' .
190 '</td></tr>' .
191 html_tag( 'tr',
192 html_tag( 'td',
193 '<input name="addaddr[email]" type=hidden value="' .
194 htmlspecialchars($vcard_nice['email;internet']) . '">' .
195 '<input name="addaddr[firstname]" type=hidden value="' .
196 $vcard_safe['firstname'] . '">' .
197 '<input name="addaddr[lastname]" type=hidden value="' .
198 $vcard_safe['lastname'] . '">' .
199 '<input type="submit" name="addaddr[SUBMIT]" ' .
200 'value="Add to Address Book">' ,
201 'center', '', 'colspan="2"' )
202 ) .
203 '</table>' .
204 '</form>' .
205 '</td></tr>' .
206 html_tag( 'tr',
207 html_tag( 'td',
208 '<a href="../src/download.php?absolute_dl=true&amp;passed_id=' .
209 $passed_id . '&amp;mailbox=' . urlencode($mailbox) .
210 '&amp;passed_ent_id=' . $passed_ent_id . '">' .
211 _("Download this as a file") . '</a>' ,
212 'center' )
213 ) .
214 '</table>' .
215
216 html_tag( 'table',
217 html_tag( 'tr',
218 html_tag( 'td', '&nbsp;', 'left', $color[4] )
219 ) ,
220 'center', '', 'border="0" cellspacing="0" cellpadding="2"' ) .
221 '</body></html>';
222
223 ?>