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