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 |
19 | Define('SM_PATH','../'); |
86725763 |
20 | |
21 | /* SquirrelMail required files. */ |
08185f2a |
22 | require_once(SM_PATH . 'include/validate.php'); |
86725763 |
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'); |
08185f2a |
26 | require_once(SM_PATH . 'include/load_prefs.php'); |
7baf86a9 |
27 | |
0b97a708 |
28 | /* globals */ |
f38b7cf0 |
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); |
0b97a708 |
37 | /* end globals */ |
38 | |
65c3ec94 |
39 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
40 | sqimap_mailbox_select($imapConnection, $mailbox); |
7baf86a9 |
41 | |
42 | |
65c3ec94 |
43 | displayPageHeader($color, 'None'); |
7baf86a9 |
44 | |
3c621ba1 |
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 | |
33c8b76b |
51 | $msg_url = 'read_body.php?mailbox='.urlencode($mailbox). |
164584f0 |
52 | '&startMessage='.urlencode($startMessage). |
53 | '&passed_id='.urlencode($passed_id); |
33c8b76b |
54 | |
24d16195 |
55 | $msg_url = set_url_var($msg_url, 'ent_id', 0); |
33c8b76b |
56 | |
24d16195 |
57 | echo '<a href="'.$msg_url.'">'. _("View message") . '</a>'; |
58 | |
65c3ec94 |
59 | echo '</center></b></td></tr>'; |
60 | |
61 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
62 | |
24d16195 |
63 | $entity_vcard = getEntity($message,$ent_id); |
65c3ec94 |
64 | |
24d16195 |
65 | $vcard = mime_fetch_body ($imapConnection, $passed_id, $ent_id); |
65c3ec94 |
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 |
40a9d8b3 |
77 | $k .= ';' . strtolower($attr); |
65c3ec94 |
78 | } |
79 | |
0f8a1ce9 |
80 | $v = str_replace(';', "\n", $v); |
65c3ec94 |
81 | $vcard_nice[$k] = $v; |
82 | } |
83 | |
84 | if ($vcard_nice['version'] == '2.1') { |
85 | // get firstname and lastname for sm addressbook |
40a9d8b3 |
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 | } |
65c3ec94 |
95 | } else { |
89ac34a4 |
96 | echo '<tr><td align="center">' . |
1bae252c |
97 | sprintf(_("vCard Version %s is not supported. Some information might not be converted correctly."), |
98 | htmlspecialchars($vcard_nice['version'])) . |
134e4174 |
99 | "</td></tr>\n"; |
1bae252c |
100 | $vcard_nice['firstname']=''; |
101 | $vcard_nice['lastname']=''; |
65c3ec94 |
102 | } |
103 | |
104 | foreach ($vcard_nice as $k => $v) { |
105 | $v = htmlspecialchars($v); |
106 | $v = trim($v); |
107 | $vcard_safe[$k] = trim(nl2br($v)); |
108 | } |
109 | |
110 | $ShowValues = array( |
111 | 'fn' => _("Name"), |
112 | 'title' => _("Title"), |
113 | 'email;internet' => _("Email"), |
114 | 'url' => _("Web Page"), |
115 | 'org' => _("Organization / Department"), |
116 | 'adr' => _("Address"), |
117 | 'tel;work' => _("Work Phone"), |
118 | 'tel;home' => _("Home Phone"), |
119 | 'tel;cell' => _("Cellular Phone"), |
120 | 'tel;fax' => _("Fax"), |
121 | 'note' => _("Note")); |
122 | |
3c621ba1 |
123 | echo '<tr><td><br />' . |
124 | '<table border="0" cellpadding="2" cellspacing="0" align="center">' . "\n"; |
65c3ec94 |
125 | |
d62c4938 |
126 | if (isset($vcard_safe['email;internet'])) { |
127 | $vcard_safe['email;internet'] = makeComposeLink('src/compose.php?send_to='.urlencode($vcard_safe['email;internet']), |
128 | $vcard_safe['email;internet']); |
65c3ec94 |
129 | } |
d62c4938 |
130 | |
65c3ec94 |
131 | if (isset($vcard_safe['url'])) { |
3c621ba1 |
132 | $vcard_safe['url'] = '<a href="' . $vcard_safe['url'] . '">' . |
133 | $vcard_safe['url'] . '</a>'; |
65c3ec94 |
134 | } |
135 | |
136 | foreach ($ShowValues as $k => $v) { |
137 | if (isset($vcard_safe[$k]) && $vcard_safe[$k]) { |
3c621ba1 |
138 | echo "<tr><td align=\"right\"><b>$v:</b></td><td>" . $vcard_safe[$k] . |
24d16195 |
139 | "</td><tr>\n"; |
65c3ec94 |
140 | } |
141 | } |
7baf86a9 |
142 | |
975f0272 |
143 | echo '</table>' . |
3c621ba1 |
144 | '<br />' . |
145 | '</td></tr></table>' . |
146 | '<table width="100%" border="0" cellspacing="0" cellpadding="2" ' . |
975f0272 |
147 | 'align="center">' . |
3c621ba1 |
148 | '<tr>' . |
149 | '<td bgcolor="' . $color[0] . '">' . |
150 | '<b><center>' . |
151 | _("Add to Addressbook") . |
152 | '</td></tr>' . |
153 | '<tr><td align="center">' . |
2841ba15 |
154 | addForm('../src/addressbook.php', 'post', 'f_add') . |
3c621ba1 |
155 | '<table border="0" cellpadding="2" cellspacing="0" align="center">' . |
156 | '<tr><td align="right"><b>' . _("Nickname:") . '</b></td>' . |
157 | '<td>'. |
158 | addInput('addaddr[nickname]', $vcard_safe['firstname'] . '-' . $vcard_safe['lastname'], '20'). |
159 | '</td></tr>' . |
160 | '<tr><td align="right"><b>' . _("Note Field Contains:") . '</b></td><td>' ; |
7baf86a9 |
161 | |
64c9e87e |
162 | $opts = array(); |
65c3ec94 |
163 | if (isset($vcard_nice['url'])) { |
64c9e87e |
164 | $opts[$vcard_nice['url']] = _("Web Page"); |
65c3ec94 |
165 | } |
166 | if (isset($vcard_nice['adr'])) { |
64c9e87e |
167 | $opts[$vcard_nice['adr']] = _("Address"); |
65c3ec94 |
168 | } |
169 | if (isset($vcard_nice['title'])) { |
64c9e87e |
170 | $opts[$vcard_nice['title']] = _("Title"); |
65c3ec94 |
171 | } |
172 | if (isset($vcard_nice['org'])) { |
64c9e87e |
173 | $opts[$vcard_nice['org']] = _("Organization / Department"); |
65c3ec94 |
174 | } |
175 | if (isset($vcard_nice['title'])) { |
64c9e87e |
176 | $opts[$vcard_nice['title'].'; '.$vcard_nice['org']] = _("Title & Org. / Dept."); |
65c3ec94 |
177 | } |
178 | if (isset($vcard_nice['tel;work'])) { |
64c9e87e |
179 | $opts[$vcard_nice['tel;work']] = _("Work Phone"); |
65c3ec94 |
180 | } |
181 | if (isset($vcard_nice['tel;home'])) { |
64c9e87e |
182 | $opts[$vcard_nice['tel;home']] = _("Home Phone"); |
65c3ec94 |
183 | } |
184 | if (isset($vcard_nice['tel;cell'])) { |
64c9e87e |
185 | $opts[$vcard_nice['tel;cell']] = _("Cellular Phone"); |
65c3ec94 |
186 | } |
187 | if (isset($vcard_nice['tel;fax'])) { |
64c9e87e |
188 | $opts[$vcard_nice['tel;fax']] = _("Fax"); |
65c3ec94 |
189 | } |
190 | if (isset($vcard_nice['note'])) { |
64c9e87e |
191 | $opts[$vcard_nice['note']] = _("Note"); |
65c3ec94 |
192 | } |
64c9e87e |
193 | |
975f0272 |
194 | echo addSelect('addaddr[label]', $opts, '', TRUE); |
2841ba15 |
195 | ?> |
196 | </td></tr> |
197 | <tr><td colspan="2" align="center"> |
198 | <?php |
6b2eed75 |
199 | if (isset($vcard_nice['email;internet'])) |
200 | echo addHidden('addaddr[email]', $vcard_nice['email;internet']); |
201 | |
202 | echo addHidden('addaddr[firstname]', $vcard_safe['firstname']). |
203 | addHidden('addaddr[lastname]', $vcard_safe['lastname']). |
204 | addSubmit(_("Add to Address Book"), 'addaddr[SUBMIT]'); |
2841ba15 |
205 | ?> |
206 | </td></tr> |
207 | </table> |
208 | </form> |
209 | </td></tr> |
210 | <tr><td align="center"> |
211 | <?php |
212 | echo '<a href="../src/download.php?absolute_dl=true&passed_id='. |
213 | urlencode($passed_id) . '&mailbox=' . urlencode($mailbox) . |
214 | '&ent_id=' . urlencode($ent_id) .'">'. |
215 | _("Download this as a file") . '</a>'; |
216 | ?> |
217 | </td></tr></table> |
218 | |
219 | <table border="0" cellspacing="0" cellpadding="2" align="center"> |
220 | <tr><td bgcolor="<?php echo $color[4]; ?>"> |
221 | </td></tr></table> |
222 | </body></html> |