8d61d4ea46000a93f0125904b870938ea901f873
[squirrelmail.git] / src / vcard.php
1 <?php
2
3 /**
4 * vcard.php
5 *
6 * This file shows an attched vcard
7 *
8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 */
13
14 /**
15 * Include the SquirrelMail initialization file.
16 */
17 require('../include/init.php');
18
19 /* SquirrelMail required files. */
20
21 /** imap functions depend on date functions */
22 include_once(SM_PATH . 'functions/date.php');
23 /** form functions */
24 include_once(SM_PATH . 'functions/forms.php');
25 /** mime decoding */
26 include_once(SM_PATH . 'functions/mime.php');
27 /** url parser */
28 include_once(SM_PATH . 'functions/url_parser.php');
29 /** imap functions used to retrieve vcard */
30 include_once(SM_PATH . 'functions/imap_general.php');
31 include_once(SM_PATH . 'functions/imap_messages.php');
32
33 /* globals */
34
35 sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
36 sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
37 sqgetGlobalVar('ent_id', $ent_id, SQ_GET);
38 sqgetGlobalVar('startMessage', $startMessage, SQ_GET);
39 /* end globals */
40
41 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
42 sqimap_mailbox_select($imapConnection, $mailbox);
43
44 displayPageHeader($color, 'None');
45
46 echo '<br /><table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
47 'align="center">' . "\n" .
48 '<tr><td bgcolor="' . $color[0] . '"><b><div style="text-align: 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 '</div></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">' .
96 sprintf(_("vCard Version %s is not supported. Some information might not be converted correctly."),
97 htmlspecialchars($vcard_nice['version'])) .
98 "</td></tr>\n";
99 $vcard_nice['firstname'] = '';
100 $vcard_nice['lastname'] = '';
101 }
102
103 foreach ($vcard_nice as $k => $v) {
104 $v = htmlspecialchars($v);
105 $v = trim($v);
106 $vcard_safe[$k] = trim(nl2br($v));
107 }
108
109 $ShowValues = array(
110 'fn' => _("Name"),
111 'title' => _("Title"),
112 'email;internet' => _("E-mail"),
113 'url' => _("Web Page"),
114 'org' => _("Organization / Department"),
115 'adr' => _("Address"),
116 'tel;work' => _("Work Phone"),
117 'tel;home' => _("Home Phone"),
118 'tel;cell' => _("Cellular Phone"),
119 'tel;fax' => _("Fax"),
120 'note' => _("Note"));
121
122 echo '<tr><td><br />' .
123 '<table border="0" cellpadding="2" cellspacing="0" align="center">' . "\n";
124
125 if (isset($vcard_safe['email;internet'])) {
126 $vcard_safe['email;internet'] = makeComposeLink('src/compose.php?send_to='.urlencode($vcard_safe['email;internet']),
127 $vcard_safe['email;internet']);
128 }
129
130 if (isset($vcard_safe['url'])) {
131 $vcard_safe['url'] = '<a href="' . $vcard_safe['url'] . '">' .
132 $vcard_safe['url'] . '</a>';
133 }
134
135 foreach ($ShowValues as $k => $v) {
136 if (isset($vcard_safe[$k]) && $vcard_safe[$k]) {
137 echo "<tr><td align=\"right\" valign=\"top\"><b>$v:</b></td><td>" .
138 $vcard_safe[$k] . "</td><tr>\n";
139 }
140 }
141
142 ?>
143 </table>
144 <br />
145 </td></tr></table>
146 <table width="100%" border="0" cellspacing="0" cellpadding="2" align="center">
147 <tr><td bgcolor="<?php echo $color[0]; ?>">
148 <div style="text-align: center;"><b><?php echo _("Add to address book"); ?></b></div>
149 </td></tr>
150 <tr><td align="center">
151 <?php echo addForm('../src/addressbook.php', 'post', 'f_add'); ?><br />
152 <table border="0" cellpadding="2" cellspacing="0" align="center">
153 <tr><td align="right"><b><?php echo _("Nickname"); ?>:</b></td>
154 <td>
155 <?php
156
157 echo addInput('addaddr[nickname]', $vcard_safe['firstname'] .
158 '-' . $vcard_safe['lastname'], '20');
159
160 /*
161 * If the vCard comes with an e-mail address it should be added to the
162 * address book, otherwise the user must add one manually to avoid an
163 * error message in src/addressbook.php. SquirrelMail is nice enough to
164 * suggest the e-mail address of the sender though.
165 */
166 if (isset($vcard_nice['email;internet'])) {
167 echo addHidden('addaddr[email]', $vcard_nice['email;internet']);
168 } else {
169 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
170 $header = $message->rfc822_header;
171 $from_name = $header->getAddr_s('from');
172
173 echo '</td></tr>' .
174 '<tr><td align="right"><b>' . _("E-mail address") . ':</b></td><td>' .
175 addInput('addaddr[email]',
176 getEmail(decodeHeader($from_name)), '20');
177 }
178
179 echo '</td></tr>' .
180 '<tr><td align="right"><b>' . _("Additional info") . ':</b></td><td>';
181
182 $opts = array();
183 if (isset($vcard_nice['url'])) {
184 $opts[$vcard_nice['url']] = _("Web Page");
185 }
186 if (isset($vcard_nice['adr'])) {
187 $opts[$vcard_nice['adr']] = _("Address");
188 }
189 if (isset($vcard_nice['title'])) {
190 $opts[$vcard_nice['title']] = _("Title");
191 }
192 if (isset($vcard_nice['org'])) {
193 $opts[$vcard_nice['org']] = _("Organization / Department");
194 }
195 if (isset($vcard_nice['title'])) {
196 $opts[$vcard_nice['title'].'; '.$vcard_nice['org']] = _("Title &amp; Org. / Dept.");
197 }
198 if (isset($vcard_nice['tel;work'])) {
199 $opts[$vcard_nice['tel;work']] = _("Work Phone");
200 }
201 if (isset($vcard_nice['tel;home'])) {
202 $opts[$vcard_nice['tel;home']] = _("Home Phone");
203 }
204 if (isset($vcard_nice['tel;cell'])) {
205 $opts[$vcard_nice['tel;cell']] = _("Cellular Phone");
206 }
207 if (isset($vcard_nice['tel;fax'])) {
208 $opts[$vcard_nice['tel;fax']] = _("Fax");
209 }
210 if (isset($vcard_nice['note'])) {
211 $opts[$vcard_nice['note']] = _("Note");
212 }
213
214 /*
215 * If the vcard comes with nothing but name and e-mail address, the user gets
216 * the chance to type some additional info. If there's more info in the card,
217 * the user gets to choose what will be added as additional info.
218 */
219 if (count($opts) == 0) {
220 echo addInput('addaddr[label]', '', '20');
221 } else {
222 echo addSelect('addaddr[label]', $opts, '', TRUE);
223 }
224
225 ?>
226 </td></tr>
227 <tr><td colspan="2" align="center"><br />
228 <?php
229
230 echo addHidden('addaddr[firstname]', $vcard_safe['firstname']) .
231 addHidden('addaddr[lastname]', $vcard_safe['lastname']) .
232 addSubmit(_("Add to address book"), 'addaddr[SUBMIT]');
233
234 ?>
235 </td></tr>
236 </table>
237 </form>
238 </td></tr>
239 <tr><td align="center">
240 <?php
241 echo '<a href="../src/download.php?absolute_dl=true&amp;passed_id=' .
242 urlencode($passed_id) . '&amp;mailbox=' . urlencode($mailbox) .
243 '&amp;ent_id=' . urlencode($ent_id) . '">' .
244 _("Download this as a file") . '</a>';
245 ?>
246 </td></tr></table>
247 <table border="0" cellspacing="0" cellpadding="2" align="center">
248 <tr><td bgcolor="<?php echo $color[4]; ?>">
249 </td></tr></table>
250 <?php
251 $oTemplate->display('footer.tpl');
252 ?>