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