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