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