6de409eb6d90c1ce26058fcbaafe35378fc15c1c
[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 $msg_url = 'read_body.php?mailbox='.urlencode($mailbox).
51 '&amp;startMessage='.$startMessage.
52 '&amp;passed_id='.$passed_id;
53
54 $msg_url = set_url_var($msg_url, 'ent_id', 0);
55
56 echo '<a href="'.$msg_url.'">'. _("View message") . '</a>';
57
58 echo '</center></b></td></tr>';
59
60 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
61
62 $entity_vcard = getEntity($message,$ent_id);
63
64 $vcard = mime_fetch_body ($imapConnection, $passed_id, $ent_id);
65 $vcard = decodeBody($vcard, $entity_vcard->header->encoding);
66 $vcard = explode ("\n",$vcard);
67 foreach ($vcard as $l) {
68 $k = substr($l, 0, strpos($l, ':'));
69 $v = substr($l, strpos($l, ':') + 1);
70 $attributes = explode(';', $k);
71 $k = strtolower(array_shift($attributes));
72 foreach ($attributes as $attr) {
73 if ($attr == 'quoted-printable')
74 $v = quoted_printable_decode($v);
75 else
76 $k .= ';' . strtolower($attr);
77 }
78
79 $v = str_replace(';', "\n", $v);
80 $vcard_nice[$k] = $v;
81 }
82
83 if ($vcard_nice['version'] == '2.1') {
84 // get firstname and lastname for sm addressbook
85 $vcard_nice['firstname'] = substr($vcard_nice['n'],
86 strpos($vcard_nice['n'], "\n") + 1, strlen($vcard_nice['n']));
87 $vcard_nice['lastname'] = substr($vcard_nice['n'], 0,
88 strpos($vcard_nice['n'], "\n"));
89 // workaround for Outlook, should be fixed in a better way,
90 // maybe in new 'vCard' class.
91 if (isset($vcard_nice['email;pref;internet'])) {
92 $vcard_nice['email;internet'] = $vcard_nice['email;pref;internet'];
93 }
94 } else {
95 echo '<tr><td align=center>vCard Version ' . $vcard_nice['version'] .
96 ' is not supported. Some information might not be converted ' .
97 "correctly.</td></tr>\n";
98 }
99
100 foreach ($vcard_nice as $k => $v) {
101 $v = htmlspecialchars($v);
102 $v = trim($v);
103 $vcard_safe[$k] = trim(nl2br($v));
104 }
105
106 $ShowValues = array(
107 'fn' => _("Name"),
108 'title' => _("Title"),
109 'email;internet' => _("Email"),
110 'url' => _("Web Page"),
111 'org' => _("Organization / Department"),
112 'adr' => _("Address"),
113 'tel;work' => _("Work Phone"),
114 'tel;home' => _("Home Phone"),
115 'tel;cell' => _("Cellular Phone"),
116 'tel;fax' => _("Fax"),
117 'note' => _("Note"));
118
119 echo '<tr><td><br>' .
120 '<TABLE border=0 cellpadding=2 cellspacing=0 align=center>' . "\n";
121
122 if (isset($vcard_safe['email;internet'])) {
123 $vcard_safe['email;internet'] = makeComposeLink('src/compose.php?send_to='.urlencode($vcard_safe['email;internet']),
124 $vcard_safe['email;internet']);
125 }
126
127 if (isset($vcard_safe['url'])) {
128 $vcard_safe['url'] = '<A HREF="' . $vcard_safe['url'] . '">' .
129 $vcard_safe['url'] . '</A>';
130 }
131
132 foreach ($ShowValues as $k => $v) {
133 if (isset($vcard_safe[$k]) && $vcard_safe[$k]) {
134 echo "<tr><td align=right><b>$v:</b></td><td>" . $vcard_safe[$k] .
135 "</td><tr>\n";
136 }
137 }
138
139 echo '</table>' .
140 '<br>' .
141 '</td></tr></table>' .
142 '<table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
143 'align="center">' .
144 '<tr>' .
145 '<td bgcolor="' . $color[0] . '">' .
146 '<b><center>' .
147 _("Add to Addressbook") .
148 '</td></tr>' .
149 '<tr><td align=center>' .
150 '<FORM ACTION="../src/addressbook.php" METHOD="POST" NAME=f_add>' .
151 '<table border=0 cellpadding=2 cellspacing=0 align=center>' .
152 '<tr><td align=right><b>Nickname:</b></td>' .
153 '<td><input type=text name="addaddr[nickname]" size=20 value="' .
154 $vcard_safe['firstname'] . '-' . $vcard_safe['lastname'] .
155 '"></td></tr>' .
156 '<tr><td align=right><b>Note Field Contains:</b></td><td>' .
157 '<select name="addaddr[label]">';
158
159 if (isset($vcard_nice['url'])) {
160 echo '<option value="' . htmlspecialchars($vcard_nice['url']) .
161 '">' . _("Web Page") . "</option>\n";
162 }
163 if (isset($vcard_nice['adr'])) {
164 echo '<option value="' . $vcard_nice['adr'] .
165 '">' . _("Address") . "</option>\n";
166 }
167 if (isset($vcard_nice['title'])) {
168 echo '<option value="' . $vcard_nice['title'] .
169 '">' . _("Title") . "</option>\n";
170 }
171 if (isset($vcard_nice['org'])) {
172 echo '<option value="' . $vcard_nice['org'] .
173 '">' . _("Organization / Department") . "</option>\n";
174 }
175 if (isset($vcard_nice['title'])) {
176 echo '<option value="' . $vcard_nice['title'] .
177 '; ' . $vcard_nice['org'] .
178 '">' . _("Title & Org. / Dept.") . "</option>\n";
179 }
180 if (isset($vcard_nice['tel;work'])) {
181 echo '<option value="' . $vcard_nice['tel;work'] .
182 '">' . _("Work Phone") . "</option>\n";
183 }
184 if (isset($vcard_nice['tel;home'])) {
185 echo '<option value="' . $vcard_nice['tel;home'] .
186 '">' . _("Home Phone") . "</option>\n";
187 }
188 if (isset($vcard_nice['tel;cell'])) {
189 echo '<option value="' . $vcard_nice['tel;cell'] .
190 '">' . _("Cellular Phone") . "</option>\n";
191 }
192 if (isset($vcard_nice['tel;fax'])) {
193 echo '<option value="' . $vcard_nice['tel;fax'] .
194 '">' . _("Fax") . "</option>\n";
195 }
196 if (isset($vcard_nice['note'])) {
197 echo '<option value="' . $vcard_nice['note'] .
198 '">' . _("Note") . "</option>\n";
199 }
200 echo '</select>' .
201 '</td></tr>' .
202 '<tr><td colspan=2 align=center>' .
203 '<INPUT NAME="addaddr[email]" type=hidden value="' .
204 htmlspecialchars($vcard_nice['email;internet']) . '">' .
205 '<INPUT NAME="addaddr[firstname]" type=hidden value="' .
206 $vcard_safe['firstname'] . '">' .
207 '<INPUT NAME="addaddr[lastname]" type=hidden value="' .
208 $vcard_safe['lastname'] . '">' .
209 '<INPUT TYPE=submit NAME="addaddr[SUBMIT]" ' .
210 'VALUE="Add to Address Book">' .
211 '</td></tr>' .
212 '</table>' .
213 '</FORM>' .
214 '</td></tr>' .
215 '<tr><td align=center>' .
216 '<a href="../src/download.php?absolute_dl=true&amp;passed_id=' .
217 $passed_id . '&amp;mailbox=' . urlencode($mailbox) .
218 '&amp;ent_id=' . urlencode($ent_id) . '">' .
219 _("Download this as a file") . '</A>' .
220 '</TD></TR></TABLE>' .
221
222 '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER>' .
223 '<TR><TD BGCOLOR="' . $color[4] . '">' .
224 '</TD></TR></TABLE>' .
225 '</body></html>';
226
227 ?>