Adding comments about obsolete plugins.
[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 * Path for SquirrelMail required files.
16 * @ignore
17 */
18 Define('SM_PATH','../');
19
20 /* SquirrelMail required files. */
21 include_once(SM_PATH . 'include/validate.php');
22 require_once(SM_PATH . 'functions/mime.php');
23 require_once(SM_PATH . 'functions/url_parser.php');
24
25 /* globals */
26 sqgetGlobalVar('username', $username, SQ_SESSION);
27 sqgetGlobalVar('key', $key, SQ_COOKIE);
28 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
29
30 sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
31 sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
32 sqgetGlobalVar('ent_id', $ent_id, SQ_GET);
33 sqgetGlobalVar('startMessage', $startMessage, SQ_GET);
34 /* end globals */
35
36 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
37 sqimap_mailbox_select($imapConnection, $mailbox);
38
39 displayPageHeader($color, 'None');
40
41 echo '<br /><table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
42 'align="center">' . "\n" .
43 '<tr><td bgcolor="' . $color[0] . '"><b><div style="text-align: center;">' .
44 _("Viewing a Business Card") . " - ";
45
46 $msg_url = 'read_body.php?mailbox='.urlencode($mailbox).
47 '&amp;startMessage='.urlencode($startMessage).
48 '&amp;passed_id='.urlencode($passed_id);
49
50 $msg_url = set_url_var($msg_url, 'ent_id', 0);
51
52 echo '<a href="'.$msg_url.'">'. _("View message") . '</a>' .
53 '</div></b></td></tr>';
54
55 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
56
57 $entity_vcard = getEntity($message,$ent_id);
58
59 $vcard = mime_fetch_body($imapConnection, $passed_id, $ent_id);
60 $vcard = decodeBody($vcard, $entity_vcard->header->encoding);
61 $vcard = explode ("\n",$vcard);
62 foreach ($vcard as $l) {
63 $k = substr($l, 0, strpos($l, ':'));
64 $v = substr($l, strpos($l, ':') + 1);
65 $attributes = explode(';', $k);
66 $k = strtolower(array_shift($attributes));
67 foreach ($attributes as $attr) {
68 if ($attr == 'quoted-printable')
69 $v = quoted_printable_decode($v);
70 else
71 $k .= ';' . strtolower($attr);
72 }
73
74 $v = str_replace(';', "\n", $v);
75 $vcard_nice[$k] = $v;
76 }
77
78 if ($vcard_nice['version'] == '2.1') {
79 // get firstname and lastname for sm addressbook
80 $vcard_nice['firstname'] = substr($vcard_nice['n'],
81 strpos($vcard_nice['n'], "\n") + 1, strlen($vcard_nice['n']));
82 $vcard_nice['lastname'] = substr($vcard_nice['n'], 0,
83 strpos($vcard_nice['n'], "\n"));
84 // workaround for Outlook, should be fixed in a better way,
85 // maybe in new 'vCard' class.
86 if (isset($vcard_nice['email;pref;internet'])) {
87 $vcard_nice['email;internet'] = $vcard_nice['email;pref;internet'];
88 }
89 } else {
90 echo '<tr><td align="center">' .
91 sprintf(_("vCard Version %s is not supported. Some information might not be converted correctly."),
92 htmlspecialchars($vcard_nice['version'])) .
93 "</td></tr>\n";
94 $vcard_nice['firstname'] = '';
95 $vcard_nice['lastname'] = '';
96 }
97
98 foreach ($vcard_nice as $k => $v) {
99 $v = htmlspecialchars($v);
100 $v = trim($v);
101 $vcard_safe[$k] = trim(nl2br($v));
102 }
103
104 $ShowValues = array(
105 'fn' => _("Name"),
106 'title' => _("Title"),
107 'email;internet' => _("E-mail"),
108 'url' => _("Web Page"),
109 'org' => _("Organization / Department"),
110 'adr' => _("Address"),
111 'tel;work' => _("Work Phone"),
112 'tel;home' => _("Home Phone"),
113 'tel;cell' => _("Cellular Phone"),
114 'tel;fax' => _("Fax"),
115 'note' => _("Note"));
116
117 echo '<tr><td><br />' .
118 '<table border="0" cellpadding="2" cellspacing="0" align="center">' . "\n";
119
120 if (isset($vcard_safe['email;internet'])) {
121 $vcard_safe['email;internet'] = makeComposeLink('src/compose.php?send_to='.urlencode($vcard_safe['email;internet']),
122 $vcard_safe['email;internet']);
123 }
124
125 if (isset($vcard_safe['url'])) {
126 $vcard_safe['url'] = '<a href="' . $vcard_safe['url'] . '">' .
127 $vcard_safe['url'] . '</a>';
128 }
129
130 foreach ($ShowValues as $k => $v) {
131 if (isset($vcard_safe[$k]) && $vcard_safe[$k]) {
132 echo "<tr><td align=\"right\" valign=\"top\"><b>$v:</b></td><td>" .
133 $vcard_safe[$k] . "</td><tr>\n";
134 }
135 }
136
137 ?>
138 </table>
139 <br />
140 </td></tr></table>
141 <table width="100%" border="0" cellspacing="0" cellpadding="2" align="center">
142 <tr><td bgcolor="<?php echo $color[0]; ?>">
143 <div style="text-align: center;"><b><?php echo _("Add to address book"); ?></b></div>
144 </td></tr>
145 <tr><td align="center">
146 <?php echo addForm('../src/addressbook.php', 'post', 'f_add'); ?><br />
147 <table border="0" cellpadding="2" cellspacing="0" align="center">
148 <tr><td align="right"><b><?php echo _("Nickname"); ?>:</b></td>
149 <td>
150 <?php
151
152 echo addInput('addaddr[nickname]', $vcard_safe['firstname'] .
153 '-' . $vcard_safe['lastname'], '20');
154
155 /*
156 * If the vCard comes with an e-mail address it should be added to the
157 * address book, otherwise the user must add one manually to avoid an
158 * error message in src/addressbook.php. SquirrelMail is nice enough to
159 * suggest the e-mail address of the sender though.
160 */
161 if (isset($vcard_nice['email;internet'])) {
162 echo addHidden('addaddr[email]', $vcard_nice['email;internet']);
163 } else {
164 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
165 $header = $message->rfc822_header;
166 $from_name = $header->getAddr_s('from');
167
168 echo '</td></tr>' .
169 '<tr><td align="right"><b>' . _("E-mail address") . ':</b></td><td>' .
170 addInput('addaddr[email]',
171 getEmail(decodeHeader($from_name)), '20');
172 }
173
174 echo '</td></tr>' .
175 '<tr><td align="right"><b>' . _("Additional info") . ':</b></td><td>';
176
177 $opts = array();
178 if (isset($vcard_nice['url'])) {
179 $opts[$vcard_nice['url']] = _("Web Page");
180 }
181 if (isset($vcard_nice['adr'])) {
182 $opts[$vcard_nice['adr']] = _("Address");
183 }
184 if (isset($vcard_nice['title'])) {
185 $opts[$vcard_nice['title']] = _("Title");
186 }
187 if (isset($vcard_nice['org'])) {
188 $opts[$vcard_nice['org']] = _("Organization / Department");
189 }
190 if (isset($vcard_nice['title'])) {
191 $opts[$vcard_nice['title'].'; '.$vcard_nice['org']] = _("Title & Org. / Dept.");
192 }
193 if (isset($vcard_nice['tel;work'])) {
194 $opts[$vcard_nice['tel;work']] = _("Work Phone");
195 }
196 if (isset($vcard_nice['tel;home'])) {
197 $opts[$vcard_nice['tel;home']] = _("Home Phone");
198 }
199 if (isset($vcard_nice['tel;cell'])) {
200 $opts[$vcard_nice['tel;cell']] = _("Cellular Phone");
201 }
202 if (isset($vcard_nice['tel;fax'])) {
203 $opts[$vcard_nice['tel;fax']] = _("Fax");
204 }
205 if (isset($vcard_nice['note'])) {
206 $opts[$vcard_nice['note']] = _("Note");
207 }
208
209 /*
210 * If the vcard comes with nothing but name and e-mail address, the user gets
211 * the chance to type some additional info. If there's more info in the card,
212 * the user gets to choose what will be added as additional info.
213 */
214 if (count($opts) == 0) {
215 echo addInput('addaddr[label]', '', '20');
216 } else {
217 echo addSelect('addaddr[label]', $opts, '', TRUE);
218 }
219
220 ?>
221 </td></tr>
222 <tr><td colspan="2" align="center"><br />
223 <?php
224
225 echo addHidden('addaddr[firstname]', $vcard_safe['firstname']) .
226 addHidden('addaddr[lastname]', $vcard_safe['lastname']) .
227 addSubmit(_("Add to address book"), 'addaddr[SUBMIT]');
228
229 ?>
230 </td></tr>
231 </table>
232 </form>
233 </td></tr>
234 <tr><td align="center">
235 <?php
236 echo '<a href="../src/download.php?absolute_dl=true&amp;passed_id=' .
237 urlencode($passed_id) . '&amp;mailbox=' . urlencode($mailbox) .
238 '&amp;ent_id=' . urlencode($ent_id) . '">' .
239 _("Download this as a file") . '</a>';
240 ?>
241 </td></tr></table>
242 <table border="0" cellspacing="0" cellpadding="2" align="center">
243 <tr><td bgcolor="<?php echo $color[4]; ?>">
244 </td></tr></table>
245 <?php
246 $oTemplate->display('footer.tpl');
247 ?>