phpdoc updates
[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 *
11 * $Id$
8f6f9ba5 12 * @package squirrelmail
35586184 13 */
7baf86a9 14
8f6f9ba5 15/** Path for SquirrelMail required files. */
846a3a21 16Define('SM_PATH','../');
86725763 17
18/* SquirrelMail required files. */
08185f2a 19require_once(SM_PATH . 'include/validate.php');
86725763 20require_once(SM_PATH . 'functions/date.php');
21require_once(SM_PATH . 'functions/page_header.php');
22require_once(SM_PATH . 'functions/mime.php');
08185f2a 23require_once(SM_PATH . 'include/load_prefs.php');
7baf86a9 24
0b97a708 25/* globals */
f38b7cf0 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);
0b97a708 34/* end globals */
35
65c3ec94 36$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
37sqimap_mailbox_select($imapConnection, $mailbox);
7baf86a9 38
39
65c3ec94 40displayPageHeader($color, 'None');
7baf86a9 41
24d16195 42echo '<br><table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
43 'align="center">' . "\n" .
44 '<tr><td bgcolor="' . $color[0] . '">' .
7baf86a9 45 '<b><center>' .
24d16195 46 _("Viewing a Business Card") . " - ";
33c8b76b 47$msg_url = 'read_body.php?mailbox='.urlencode($mailbox).
48 '&amp;startMessage='.$startMessage.
49 '&amp;passed_id='.$passed_id;
50
24d16195 51$msg_url = set_url_var($msg_url, 'ent_id', 0);
33c8b76b 52
24d16195 53echo '<a href="'.$msg_url.'">'. _("View message") . '</a>';
54
65c3ec94 55echo '</center></b></td></tr>';
56
57$message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
58
24d16195 59$entity_vcard = getEntity($message,$ent_id);
65c3ec94 60
24d16195 61$vcard = mime_fetch_body ($imapConnection, $passed_id, $ent_id);
65c3ec94 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
40a9d8b3 73 $k .= ';' . strtolower($attr);
65c3ec94 74 }
75
0f8a1ce9 76 $v = str_replace(';', "\n", $v);
65c3ec94 77 $vcard_nice[$k] = $v;
78}
79
80if ($vcard_nice['version'] == '2.1') {
81 // get firstname and lastname for sm addressbook
40a9d8b3 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 }
65c3ec94 91} else {
24d16195 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";
65c3ec94 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
24d16195 116echo '<tr><td><br>' .
117 '<TABLE border=0 cellpadding=2 cellspacing=0 align=center>' . "\n";
65c3ec94 118
d62c4938 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']);
65c3ec94 122}
d62c4938 123
65c3ec94 124if (isset($vcard_safe['url'])) {
24d16195 125 $vcard_safe['url'] = '<A HREF="' . $vcard_safe['url'] . '">' .
126 $vcard_safe['url'] . '</A>';
65c3ec94 127}
128
129foreach ($ShowValues as $k => $v) {
130 if (isset($vcard_safe[$k]) && $vcard_safe[$k]) {
24d16195 131 echo "<tr><td align=right><b>$v:</b></td><td>" . $vcard_safe[$k] .
132 "</td><tr>\n";
65c3ec94 133 }
134}
7baf86a9 135
65c3ec94 136echo '</table>' .
7baf86a9 137 '<br>' .
138 '</td></tr></table>' .
24d16195 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>' .
7baf86a9 154 '<select name="addaddr[label]">';
155
65c3ec94 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>' .
7baf86a9 198 '</td></tr>' .
24d16195 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">' .
7baf86a9 208 '</td></tr>' .
fab3baa6 209 '</table>' .
24d16195 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) .
0fa23001 215 '&amp;ent_id=' . urlencode($ent_id) . '">' .
24d16195 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] . '">' .
dcc1cc82 221 '</TD></TR></TABLE>' .
222 '</body></html>';
65c3ec94 223
dcc1cc82 224?>