Second round of cleanup.
[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 14/*****************************************************************/
15/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
16/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
17/*** + Base level indent should begin at left margin, as ***/
18/*** the require_once below looks. ***/
19/*** + All identation should consist of four space blocks ***/
20/*** + Tab characters are evil. ***/
21/*** + all comments should use "slash-star ... star-slash" ***/
22/*** style -- no pound characters, no slash-slash style ***/
23/*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
24/*** ALWAYS USE { AND } CHARACTERS!!! ***/
25/*** + Please use ' instead of ", when possible. Note " ***/
26/*** should always be used in _( ) function calls. ***/
27/*** Thank you for your help making the SM code more readable. ***/
28/*****************************************************************/
29
30require_once('../src/validate.php');
31require_once('../functions/date.php');
32require_once('../functions/page_header.php');
33require_once('../functions/mime.php');
34require_once('../src/load_prefs.php');
7baf86a9 35
36 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
37 sqimap_mailbox_select($imapConnection, $mailbox);
38
39
40 displayPageHeader($color, 'None');
41
42 echo '<br><table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
43 'align="center">' . "\n" .
44 '<tr><td bgcolor="' . $color[0] . '">' .
45 '<b><center>' .
46 _("Viewing a Business Card") . " - ";
47 if (isset($where) && isset($what)) {
48 // from a search
49 echo '<a href="../src/read_body.php?mailbox=' . urlencode($mailbox) .
50 '&passed_id=' . $passed_id . '&where=' . urlencode($where) .
51 '&what=' . urlencode($what). '">' . _("View message") . '</a>';
52 } else {
53 echo '<a href="../src/read_body.php?mailbox=' . urlencode($mailbox) .
54 '&passed_id=' . $passed_id . '&startMessage=' . $startMessage .
55 '&show_more=0">' . _("View message") . '</a>';
56 }
57 echo '</center></b></td></tr>';
58
59 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
60
61 $entity_vcard = getEntity($message,$passed_ent_id);
62
63 $vcard = mime_fetch_body ($imapConnection, $passed_id, $passed_ent_id);
64 $vcard = decodeBody($vcard, $entity_vcard->header->encoding);
65 $vcard = explode ("\n",$vcard);
66 foreach ($vcard as $l)
67 {
68 $k = substr($l, 0, strpos($l, ':'));
69 $v = substr($l, strpos($l, ':') + 1);
70 $attributes = explode(';', $k);
71 $k = strtolower(array_shift($attributes));
72 foreach ($attributes as $attr)
73 {
74 if ($attr == 'quoted-printable')
75 $v = quoted_printable_decode($v);
76 else
77 $k .= ';' . $attr;
78 }
79
80 $v = ereg_replace(';', "\n", $v);
81 $vcard_nice[$k] = $v;
82 }
83
84 if ($vcard_nice['version'] == '2.1')
85 {
86 // get firstname and lastname for sm addressbook
87 $vcard_nice["firstname"] = substr($vcard_nice["n"],
88 strpos($vcard_nice["n"], "\n") + 1, strlen($vcard_nice["n"]));
89 $vcard_nice["lastname"] = substr($vcard_nice["n"], 0,
90 strpos($vcard_nice["n"], "\n"));
91 }
92 else
93 {
94 echo '<tr><td align=center>vCard Version ' . $vcard_nice['version'] .
95 ' is not supported. Some information might not be converted ' .
96 "correctly.</td></tr>\n";
97 }
98
99 foreach ($vcard_nice as $k => $v)
100 {
101 $v = htmlspecialchars($v);
102 $v = trim($v);
103 $vcard_safe[$k] = trim(nl2br($v));
104 }
105
106 $ShowValues = array(
107 'fn' => _("Name"),
108 'title' => _("Title"),
109 'email;internet' => _("Email"),
110 'url' => _("Web Page"),
111 'org' => _("Organization / Department"),
112 'adr' => _("Address"),
113 'tel;work' => _("Work Phone"),
114 'tel;home' => _("Home Phone"),
115 'tel;cell' => _("Cellular Phone"),
116 'tel;fax' => _("Fax"),
117 'note' => _("Note"));
118
119 echo '<tr><td><br>' .
120 '<TABLE border=0 cellpadding=2 cellspacing=0 align=center>' . "\n";
121
122 if (isset($vcard_safe['email;internet'])) {
123 $vcard_safe['email;internet'] = '<A HREF="../src/compose.php?send_to=' .
124 $vcard_safe['email;internet'] . '">' . $vcard_safe['email;internet'] .
125 '</A>';
126 }
127 if (isset($vcard_safe['url'])) {
128 $vcard_safe['url'] = '<A HREF="' . $vcard_safe['url'] . '">' .
129 $vcard_safe['url'] . '</A>';
130 }
131
132 foreach ($ShowValues as $k => $v)
133 {
134 if (isset($vcard_safe[$k]) && $vcard_safe[$k])
135 {
136 echo "<tr><td align=right><b>$v:</b></td><td>" . $vcard_safe[$k] .
137 "</td><tr>\n";
138 }
139 }
140
141 echo '</table>' .
142 '<br>' .
143 '</td></tr></table>' .
144 '<table width="100%" border="0" cellspacing="0" cellpadding="2" ' .
145 'align="center">' .
146 '<tr>' .
147 '<td bgcolor="' . $color[0] . '">' .
148 '<b><center>' .
149 _("Add to Addressbook") .
150 '</td></tr>' .
151 '<tr><td align=center>' .
152 '<FORM ACTION="../src/addressbook.php" METHOD="POST" NAME=f_add>' .
153 '<table border=0 cellpadding=2 cellspacing=0 align=center>' .
154 '<tr><td align=right><b>Nickname:</b></td>' .
155 '<td><input type=text name="addaddr[nickname]" size=20 value="' .
156 $vcard_safe['firstname'] . '-' . $vcard_safe['lastname'] .
157 '"></td></tr>' .
158 '<tr><td align=right><b>Note Field Contains:</b></td><td>' .
159 '<select name="addaddr[label]">';
160
161 if (isset($vcard_nice['url']))
162 echo '<option value="' . htmlspecialchars($vcard_nice['url']) .
163 '">' . _("Web Page") . "</option>\n";
164 if (isset($vcard_nice['adr']))
165 echo '<option value="' . $vcard_nice['adr'] .
166 '">' . _("Address") . "</option>\n";
167 if (isset($vcard_nice['title']))
168 echo '<option value="' . $vcard_nice['title'] .
169 '">' . _("Title") . "</option>\n";
170 if (isset($vcard_nice['org']))
171 echo '<option value="' . $vcard_nice['org'] .
172 '">' . _("Organization / Department") . "</option>\n";
173 if (isset($vcard_nice['title']))
174 echo '<option value="' . $vcard_nice['title'] .
175 '; ' . $vcard_nice['org'] .
176 '">' . _("Title & Org. / Dept.") . "</option>\n";
177 if (isset($vcard_nice['tel;work']))
178 echo '<option value="' . $vcard_nice['tel;work'] .
179 '">' . _("Work Phone") . "</option>\n";
180 if (isset($vcard_nice['tel;home']))
181 echo '<option value="' . $vcard_nice['tel;home'] .
182 '">' . _("Home Phone") . "</option>\n";
183 if (isset($vcard_nice['tel;cell']))
184 echo '<option value="' . $vcard_nice['tel;cell'] .
185 '">' . _("Cellular Phone") . "</option>\n";
186 if (isset($vcard_nice['tel;fax']))
187 echo '<option value="' . $vcard_nice['tel;fax'] .
188 '">' . _("Fax") . "</option>\n";
189 if (isset($vcard_nice['note']))
190 echo '<option value="' . $vcard_nice['note'] .
191 '">' . _("Note") . "</option>\n";
192
193 echo '</select>' .
194 '</td></tr>' .
195 '<tr><td colspan=2 align=center>' .
196 '<INPUT NAME="addaddr[email]" type=hidden value="' .
197 htmlspecialchars($vcard_nice['email;internet']) . '">' .
198 '<INPUT NAME="addaddr[firstname]" type=hidden value="' .
199 $vcard_safe['firstname'] . '">' .
200 '<INPUT NAME="addaddr[lastname]" type=hidden value="' .
201 $vcard_safe['lastname'] . '">' .
202 '<INPUT TYPE=submit NAME="addaddr[SUBMIT]" ' .
203 'VALUE="Add to Address Book">' .
204 '</td></tr>' .
205 '</table>' .
206 '</FORM>' .
207 '</td></tr>' .
208 '<tr><td align=center>' .
209 '<a href="../src/download.php?absolute_dl=true&passed_id=' .
210 $passed_id . '&mailbox=' . urlencode($mailbox) .
211 '&passed_ent_id=' . $passed_ent_id . '">' .
212 _("Download this as a file") . '</A>' .
213 '</TD></TR></TABLE>' .
214
215 '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 ALIGN=CENTER>' .
216 '<TR><TD BGCOLOR="' . $color[4] . '">' .
217 '</TD></TR></TABLE>' .
218 '</body></html>';