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