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