Missing global
[squirrelmail.git] / src / vcard.php
CommitLineData
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 19Define('SM_PATH','../');
86725763 20
21/* SquirrelMail required files. */
08185f2a 22require_once(SM_PATH . 'include/validate.php');
86725763 23require_once(SM_PATH . 'functions/date.php');
24require_once(SM_PATH . 'functions/page_header.php');
25require_once(SM_PATH . 'functions/mime.php');
08185f2a 26require_once(SM_PATH . 'include/load_prefs.php');
7baf86a9 27
0b97a708 28/* globals */
f38b7cf0 29sqgetGlobalVar('username', $username, SQ_SESSION);
30sqgetGlobalVar('key', $key, SQ_COOKIE);
31sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
32
33sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
34sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
35sqgetGlobalVar('ent_id', $ent_id, SQ_GET);
36sqgetGlobalVar('startMessage', $startMessage, SQ_GET);
0b97a708 37/* end globals */
38
65c3ec94 39$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
40sqimap_mailbox_select($imapConnection, $mailbox);
7baf86a9 41
42
65c3ec94 43displayPageHeader($color, 'None');
7baf86a9 44
04f17bd9 45?>
46<br />
47<table width="100%" border="0" cellspacing="0" cellpadding="2" align="center">
48<tr>
49<?php
50
51echo '<td bgcolor="' . $color[0] . '">' .
7baf86a9 52 '<b><center>' .
24d16195 53 _("Viewing a Business Card") . " - ";
33c8b76b 54$msg_url = 'read_body.php?mailbox='.urlencode($mailbox).
164584f0 55 '&amp;startMessage='.urlencode($startMessage).
56 '&amp;passed_id='.urlencode($passed_id);
33c8b76b 57
24d16195 58$msg_url = set_url_var($msg_url, 'ent_id', 0);
33c8b76b 59
24d16195 60echo '<a href="'.$msg_url.'">'. _("View message") . '</a>';
61
65c3ec94 62echo '</center></b></td></tr>';
63
64$message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
65
24d16195 66$entity_vcard = getEntity($message,$ent_id);
65c3ec94 67
24d16195 68$vcard = mime_fetch_body ($imapConnection, $passed_id, $ent_id);
65c3ec94 69$vcard = decodeBody($vcard, $entity_vcard->header->encoding);
70$vcard = explode ("\n",$vcard);
71foreach ($vcard as $l) {
72 $k = substr($l, 0, strpos($l, ':'));
73 $v = substr($l, strpos($l, ':') + 1);
74 $attributes = explode(';', $k);
75 $k = strtolower(array_shift($attributes));
76 foreach ($attributes as $attr) {
77 if ($attr == 'quoted-printable')
78 $v = quoted_printable_decode($v);
79 else
40a9d8b3 80 $k .= ';' . strtolower($attr);
65c3ec94 81 }
82
0f8a1ce9 83 $v = str_replace(';', "\n", $v);
65c3ec94 84 $vcard_nice[$k] = $v;
85}
86
87if ($vcard_nice['version'] == '2.1') {
88 // get firstname and lastname for sm addressbook
40a9d8b3 89 $vcard_nice['firstname'] = substr($vcard_nice['n'],
90 strpos($vcard_nice['n'], "\n") + 1, strlen($vcard_nice['n']));
91 $vcard_nice['lastname'] = substr($vcard_nice['n'], 0,
92 strpos($vcard_nice['n'], "\n"));
93 // workaround for Outlook, should be fixed in a better way,
94 // maybe in new 'vCard' class.
95 if (isset($vcard_nice['email;pref;internet'])) {
96 $vcard_nice['email;internet'] = $vcard_nice['email;pref;internet'];
97 }
65c3ec94 98} else {
89ac34a4 99 echo '<tr><td align="center">' .
100 sprintf(_("vCard Version %s is not supported. Some information might not be converted correctly."),$vcard_nice['version']) .
101 "</td></tr>\n";
65c3ec94 102}
103
104foreach ($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
04f17bd9 123echo '<tr><td><br />' .
24d16195 124 '<TABLE border=0 cellpadding=2 cellspacing=0 align=center>' . "\n";
65c3ec94 125
d62c4938 126if (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 131if (isset($vcard_safe['url'])) {
24d16195 132 $vcard_safe['url'] = '<A HREF="' . $vcard_safe['url'] . '">' .
133 $vcard_safe['url'] . '</A>';
65c3ec94 134}
135
136foreach ($ShowValues as $k => $v) {
137 if (isset($vcard_safe[$k]) && $vcard_safe[$k]) {
24d16195 138 echo "<tr><td align=right><b>$v:</b></td><td>" . $vcard_safe[$k] .
139 "</td><tr>\n";
65c3ec94 140 }
141}
7baf86a9 142
04f17bd9 143?>
144</table>
145<br />
146</td></tr></table>
147<table width="100%" border="0" cellspacing="0" cellpadding="2" align="center">
148<tr><td bgcolor="<?php echo $color[0]; ?>" align="center">
149<b><?php echo _("Add to Addressbook"); ?></b>
150</td></tr>
151<tr><td align="center">
152<?php addForm('../src/addressbook.php', 'POST', 'f_add') ?>
153<table border="0" cellpadding="2" cellspacing="0" align="center">
154<tr><td align="right"><b><?php echo _("Nickname:"); ?></b></td>
155<td>
156<?php addInput('addaddr[nickname]', $vcard_safe['firstname'] . '-' . $vcard_safe['lastname'], '20'); ?>
157</td></tr>
158<tr><td align="right"><b><?php echo _("Note Field Contains:"); ?></b></td><td>
159<?php
7baf86a9 160
64c9e87e 161$opts = array();
65c3ec94 162if (isset($vcard_nice['url'])) {
64c9e87e 163 $opts[$vcard_nice['url']] = _("Web Page");
65c3ec94 164}
165if (isset($vcard_nice['adr'])) {
64c9e87e 166 $opts[$vcard_nice['adr']] = _("Address");
65c3ec94 167}
168if (isset($vcard_nice['title'])) {
64c9e87e 169 $opts[$vcard_nice['title']] = _("Title");
65c3ec94 170}
171if (isset($vcard_nice['org'])) {
64c9e87e 172 $opts[$vcard_nice['org']] = _("Organization / Department");
65c3ec94 173}
174if (isset($vcard_nice['title'])) {
64c9e87e 175 $opts[$vcard_nice['title'].'; '.$vcard_nice['org']] = _("Title & Org. / Dept.");
65c3ec94 176}
177if (isset($vcard_nice['tel;work'])) {
64c9e87e 178 $opts[$vcard_nice['tel;work']] = _("Work Phone");
65c3ec94 179}
180if (isset($vcard_nice['tel;home'])) {
64c9e87e 181 $opts[$vcard_nice['tel;home']] = _("Home Phone");
65c3ec94 182}
183if (isset($vcard_nice['tel;cell'])) {
64c9e87e 184 $opts[$vcard_nice['tel;cell']] = _("Cellular Phone");
65c3ec94 185}
186if (isset($vcard_nice['tel;fax'])) {
64c9e87e 187 $opts[$vcard_nice['tel;fax']] = _("Fax");
65c3ec94 188}
189if (isset($vcard_nice['note'])) {
64c9e87e 190 $opts[$vcard_nice['note']] = _("Note");
65c3ec94 191}
64c9e87e 192
04f17bd9 193echo addSelect('addaddr[label]', $opts, '', TRUE);
194
195?>
196</td></tr>
197<tr><td colspan="2" align="center">
198<?php
199
200echo addHidden('addaddr[email]', $vcard_nice['email;internet']).
201 addHidden('addaddr[firstname]', $vcard_safe['firstname']).
202 addHidden('addaddr[lastname]', $vcard_safe['lastname']).
203 addSubmit(_("Add to Address Book"), 'addaddr[SUBMIT]');
204
205?>
206</td></tr>
207</table>
208</form>
209</td></tr>
210<tr><td align="center">
211<?php
212
213echo '<a href="../src/download.php?absolute_dl=true&amp;passed_id=' .
214 urlencode($passed_id) . '&amp;mailbox=' . urlencode($mailbox) .
215 '&amp;ent_id=' . urlencode($ent_id) . '">' .
216 _("Download this as a file") . '</a>';
65c3ec94 217
dcc1cc82 218?>
04f17bd9 219</td></tr></table>
220<table border="0" cellspacing="0" cellpadding="2" align="center">
221<tr><td bgcolor="<?php echo $color[4]; ?>"></td></tr>
222</table>
223</body></html>