c1e15177 |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * addrbook_search_html.php |
5 | * |
6c84ba1e |
6 | * Copyright (c) 1999-2005 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * Handle addressbook searching with pure html. |
10 | * |
11 | * This file is included from compose.php |
12 | * |
30967a1e |
13 | * @version $Id$ |
8f6f9ba5 |
14 | * @package squirrelmail |
de00443c |
15 | * @subpackage addressbook |
35586184 |
16 | */ |
c1e15177 |
17 | |
91e0dccc |
18 | /** |
30967a1e |
19 | * Path for SquirrelMail required files. |
20 | * @ignore |
21 | */ |
abb3c512 |
22 | if (! defined('SM_PATH') ) { |
39bfea8f |
23 | define('SM_PATH','../'); |
abb3c512 |
24 | } |
86725763 |
25 | |
8f6f9ba5 |
26 | /** SquirrelMail required files. */ |
08185f2a |
27 | require_once(SM_PATH . 'include/validate.php'); |
1e12d1ff |
28 | require_once(SM_PATH . 'functions/global.php'); |
86725763 |
29 | require_once(SM_PATH . 'functions/date.php'); |
86725763 |
30 | require_once(SM_PATH . 'functions/display_messages.php'); |
31 | require_once(SM_PATH . 'functions/addressbook.php'); |
32 | require_once(SM_PATH . 'functions/plugin.php'); |
33 | require_once(SM_PATH . 'functions/strings.php'); |
34 | require_once(SM_PATH . 'functions/html.php'); |
c1e15177 |
35 | |
1e12d1ff |
36 | sqgetGlobalVar('session', $session, SQ_POST); |
37 | sqgetGlobalVar('mailbox', $mailbox, SQ_POST); |
38 | sqgetGlobalVar('addrquery', $addrquery, SQ_POST); |
39 | sqgetGlobalVar('listall', $listall, SQ_POST); |
40 | sqgetGlobalVar('backend', $backend, SQ_POST); |
0b97a708 |
41 | |
8f6f9ba5 |
42 | /** |
43 | * Insert hidden data |
44 | */ |
00a065a6 |
45 | function addr_insert_hidden() { |
46 | global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox, |
6a12032e |
47 | $identity, $session; |
00a065a6 |
48 | |
65a5bae6 |
49 | if (substr($body, 0, 1) == "\r") { |
62366261 |
50 | echo addHidden('body', "\n".$body); |
51 | } else { |
52 | echo addHidden('body', $body); |
14f1b90b |
53 | } |
54 | |
62366261 |
55 | echo addHidden('session', $session). |
56 | addHidden('subject', $subject). |
39bfea8f |
57 | addHidden('send_to', $send_to). |
58 | addHidden('send_to_bcc', $send_to_bcc). |
59 | addHidden('send_to_cc', $send_to_cc). |
60 | addHidden('identity', $identity). |
61 | addHidden('mailbox', $mailbox). |
62 | addHidden('from_htmladdr_search', 'true'); |
62366261 |
63 | } |
64 | |
14f1b90b |
65 | |
8f6f9ba5 |
66 | /** |
67 | * List search results |
68 | * @param array $res Array containing results of search |
69 | * @param bool $includesource UNDOCUMENTED [Default=true] |
70 | */ |
00a065a6 |
71 | function addr_display_result($res, $includesource = true) { |
e842b215 |
72 | global $color, $javascript_on, $PHP_SELF, $squirrelmail_language; |
00a065a6 |
73 | |
74 | if (sizeof($res) <= 0) return; |
75 | |
c435f076 |
76 | echo addForm($PHP_SELF, 'post', 'addrbook'). |
62366261 |
77 | addHidden('html_addr_search_done', 'true'); |
00a065a6 |
78 | addr_insert_hidden(); |
79 | $line = 0; |
80 | |
0bb8cc68 |
81 | if ($javascript_on) { |
82 | print |
83 | '<script language="JavaScript" type="text/javascript">' . |
84 | "\n<!-- \n" . |
85 | "function CheckAll(ch) {\n" . |
86 | " for (var i = 0; i < document.addrbook.elements.length; i++) {\n" . |
87 | " if( document.addrbook.elements[i].type == 'checkbox' &&\n" . |
88 | " document.addrbook.elements[i].name.substr(0,16) == 'send_to_search['+ch ) {\n" . |
89 | " document.addrbook.elements[i].checked = !(document.addrbook.elements[i].checked);\n". |
90 | " }\n" . |
91 | " }\n" . |
92 | "}\n" . |
93 | "//-->\n" . |
94 | "</script>\n"; |
c435f076 |
95 | $chk_all = '<a href="#" onclick="CheckAll(\'T\');">' . _("All") . '</a> <font color="'.$color[9].'">'._("To").'</font>'. |
0bb8cc68 |
96 | ' '. |
c435f076 |
97 | '<a href="#" onclick="CheckAll(\'C\');">' . _("All") . '</a> <font color="'.$color[9].'">'._("Cc").'</font>'. |
0bb8cc68 |
98 | ' '. |
c435f076 |
99 | '<a href="#" onclick="CheckAll(\'B\');">' . _("All") . '</a>'; |
0bb8cc68 |
100 | } |
7b783475 |
101 | echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) . |
102 | html_tag( 'tr', '', '', $color[9] ) . |
103 | html_tag( 'th', ' ' . $chk_all, 'left' ) . |
104 | html_tag( 'th', ' ' . _("Name"), 'left' ) . |
105 | html_tag( 'th', ' ' . _("E-mail"), 'left' ) . |
106 | html_tag( 'th', ' ' . _("Info"), 'left' ); |
00a065a6 |
107 | |
108 | if ($includesource) { |
7b783475 |
109 | echo html_tag( 'th', ' ' . _("Source"), 'left', '', 'width="10%"' ); |
00a065a6 |
110 | } |
111 | |
7b783475 |
112 | echo "</tr>\n"; |
00a065a6 |
113 | |
114 | foreach ($res as $row) { |
3d0cada3 |
115 | $email = AddressBook::full_address($row); |
91e0dccc |
116 | if ($line % 2) { |
93adc018 |
117 | $tr_bgcolor = $color[12]; |
118 | } else { |
119 | $tr_bgcolor = $color[4]; |
120 | } |
e842b215 |
121 | if ($squirrelmail_language == 'ja_JP') |
122 | { |
c435f076 |
123 | echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) . |
e842b215 |
124 | html_tag( 'td', |
39bfea8f |
125 | '<input type="checkbox" name="send_to_search[T' . $line . ']" value = "' . |
126 | htmlspecialchars($email) . '" /> ' . _("To") . ' ' . |
127 | '<input type="checkbox" name="send_to_search[C' . $line . ']" value = "' . |
128 | htmlspecialchars($email) . '" /> ' . _("Cc") . ' ' . |
129 | '<input type="checkbox" name="send_to_search[B' . $line . ']" value = "' . |
130 | htmlspecialchars($email) . '" /> ' . _("Bcc") . ' ' , |
c435f076 |
131 | 'center', '', 'width="5%" style="white-space: nowrap;"' ) . |
132 | html_tag( 'td', ' ' . htmlspecialchars($row['lastname']) . ' ' . htmlspecialchars($row['firstname']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) . |
133 | html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) . |
134 | html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'style="white-space: nowrap;"' ); |
e842b215 |
135 | } else { |
c435f076 |
136 | echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) . |
7b783475 |
137 | html_tag( 'td', |
39bfea8f |
138 | addCheckBox('send_to_search[T'.$line.']', FALSE, $email). |
62366261 |
139 | ' ' . _("To") . ' ' . |
39bfea8f |
140 | addCheckBox('send_to_search[C'.$line.']', FALSE, $email). |
141 | ' ' . _("Cc") . ' ' . |
142 | addCheckBox('send_to_search[B'.$line.']', FALSE, $email). |
143 | ' ' . _("Bcc") . ' ' , |
c435f076 |
144 | 'center', '', 'width="5%" style="white-space: nowrap;"' ) . |
145 | html_tag( 'td', ' ' . htmlspecialchars($row['name']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) . |
146 | html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) . |
147 | html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'style="white-space: nowrap;"' ); |
e842b215 |
148 | } |
7b783475 |
149 | |
00a065a6 |
150 | if ($includesource) { |
c435f076 |
151 | echo html_tag( 'td', ' ' . $row['source'] . ' ', 'left', '', 'style="white-space: nowrap;"' ); |
00a065a6 |
152 | } |
153 | echo "</tr>\n"; |
154 | $line ++; |
155 | } |
7b783475 |
156 | if ($includesource) { $td_colspan = '5'; } else { $td_colspan = '4'; } |
157 | echo html_tag( 'tr', |
158 | html_tag( 'td', |
39bfea8f |
159 | '<input type="submit" name="addr_search_done" value="' . |
160 | _("Use Addresses") . '" />' , |
7b783475 |
161 | 'center', '', 'colspan="'. $td_colspan .'"' ) |
162 | ) . |
39bfea8f |
163 | '</table>' . |
164 | addHidden('html_addr_search_done', '1'). |
165 | '</form>'; |
00a065a6 |
166 | } |
167 | |
168 | /* --- End functions --- */ |
169 | |
9c3e6cd4 |
170 | if ($compose_new_win == '1') { |
171 | compose_Header($color, $mailbox); |
172 | } |
173 | else { |
174 | displayPageHeader($color, $mailbox); |
175 | } |
00a065a6 |
176 | /* Initialize addressbook */ |
177 | $abook = addressbook_init(); |
c1e15177 |
178 | |
14f1b90b |
179 | |
39bfea8f |
180 | echo '<br />' . |
7b783475 |
181 | html_tag( 'table', |
182 | html_tag( 'tr', |
183 | html_tag( 'td', '<b>' . _("Address Book Search") . '</b>', 'center', $color[0] ) |
184 | ) , |
185 | 'center', '', 'width="95%" cellpadding="2" cellspacing="2" border="0"' ); |
14f1b90b |
186 | |
00a065a6 |
187 | |
188 | /* Search form */ |
7b783475 |
189 | echo '<center>' . |
190 | html_tag( 'table', '', 'center', '', 'border="0"' ) . |
191 | html_tag( 'tr' ) . |
c435f076 |
192 | html_tag( 'td', '', 'left', '', 'style="white-space: nowrap;" valign="middle"' ) . "\n" . |
39bfea8f |
193 | addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f'). |
194 | "\n<center>\n" . |
195 | ' <nobr><strong>' . _("Search for") . "</strong>\n"; |
00a065a6 |
196 | addr_insert_hidden(); |
197 | if (! isset($addrquery)) |
198 | $addrquery = ''; |
62366261 |
199 | echo addInput('addrquery', $addrquery, 26); |
00a065a6 |
200 | |
201 | /* List all backends to allow the user to choose where to search */ |
202 | if (!isset($backend)) { $backend = ''; } |
203 | if ($abook->numbackends > 1) { |
39bfea8f |
204 | echo '<strong>' . _("in") . '</strong> '; |
91e0dccc |
205 | |
206 | $selopts['-1'] = _("All address books"); |
00a065a6 |
207 | $ret = $abook->get_backend_list(); |
91e0dccc |
208 | |
00a065a6 |
209 | while (list($undef,$v) = each($ret)) { |
39bfea8f |
210 | $selopts[$v->bnum] = $v->sname; |
00a065a6 |
211 | } |
62366261 |
212 | echo addSelect('backend', $selopts, $backend, TRUE); |
00a065a6 |
213 | } else { |
62366261 |
214 | echo addHidden('backend', '-1'); |
00a065a6 |
215 | } |
6a12032e |
216 | if (isset($session)) { |
62366261 |
217 | echo addHidden('session', $session); |
6a12032e |
218 | } |
219 | |
39bfea8f |
220 | echo '<input type="submit" value="' . _("Search") . '" />' . |
221 | ' | <input type="submit" value="' . _("List all") . |
222 | '" name="listall" />' . "\n" . |
223 | '</form></center></td></tr></table>' . "\n"; |
00a065a6 |
224 | addr_insert_hidden(); |
7b783475 |
225 | echo '</center>'; |
00a065a6 |
226 | do_hook('addrbook_html_search_below'); |
227 | /* End search form */ |
228 | |
229 | /* Show personal addressbook */ |
cc99433e |
230 | |
231 | if ( !empty( $listall ) ){ |
232 | $addrquery = '*'; |
233 | } |
234 | |
235 | if ($addrquery == '' && empty($listall)) { |
00a065a6 |
236 | |
237 | if (! isset($backend) || $backend != -1 || $addrquery == '') { |
238 | if ($addrquery == '') { |
6e79bfe2 |
239 | $backend = $abook->localbackend; |
00a065a6 |
240 | } |
14f1b90b |
241 | |
39bfea8f |
242 | /* echo '<h3 align="center">' . $abook->backends[$backend]->sname) . "</h3>\n"; */ |
14f1b90b |
243 | |
00a065a6 |
244 | $res = $abook->list_addr($backend); |
14f1b90b |
245 | |
00a065a6 |
246 | if (is_array($res)) { |
a10110a5 |
247 | usort($res,'alistcmp'); |
6e79bfe2 |
248 | addr_display_result($res, false); |
00a065a6 |
249 | } else { |
39bfea8f |
250 | echo html_tag( 'p', '<strong><br />' . |
91e0dccc |
251 | sprintf(_("Unable to list addresses from %s"), |
7b783475 |
252 | $abook->backends[$backend]->sname) . "</strong>\n" , |
253 | 'center' ); |
00a065a6 |
254 | } |
255 | |
256 | } else { |
257 | $res = $abook->list_addr(); |
a10110a5 |
258 | usort($res,'alistcmp'); |
00a065a6 |
259 | addr_display_result($res, true); |
260 | } |
261 | exit; |
cc99433e |
262 | } |
263 | else { |
00a065a6 |
264 | |
265 | /* Do the search */ |
db48e3f5 |
266 | if (!empty($addrquery)) { |
00a065a6 |
267 | |
268 | if ($backend == -1) { |
269 | $res = $abook->s_search($addrquery); |
270 | } else { |
271 | $res = $abook->s_search($addrquery, $backend); |
272 | } |
273 | |
274 | if (!is_array($res)) { |
39bfea8f |
275 | echo html_tag( 'p', '<b><br />' . |
7b783475 |
276 | _("Your search failed with the following error(s)") . |
39bfea8f |
277 | ':<br />' . $abook->error . "</b>\n" , |
dcc1cc82 |
278 | 'center' ) . |
39bfea8f |
279 | "\n</body></html>\n"; |
00a065a6 |
280 | } else { |
281 | if (sizeof($res) == 0) { |
39bfea8f |
282 | echo html_tag( 'p', '<br /><b>' . |
62366261 |
283 | _("No persons matching your search were found") . "</b>\n" , |
dcc1cc82 |
284 | 'center' ) . |
39bfea8f |
285 | "\n</body></html>\n"; |
00a065a6 |
286 | } else { |
287 | addr_display_result($res); |
288 | } |
289 | } |
290 | } |
291 | } |
292 | |
293 | if ($addrquery == '' || sizeof($res) == 0) { |
39bfea8f |
294 | /* printf('<center><form method="post" name="k" action="compose.php">'."\n", $PHP_SELF); */ |
62366261 |
295 | echo '<center>'. |
c435f076 |
296 | addForm('compose.php','post','k'); |
00a065a6 |
297 | addr_insert_hidden(); |
39bfea8f |
298 | echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" . |
00a065a6 |
299 | '</form></center></nobr>'; |
300 | } |
6e79bfe2 |
301 | |
dcc1cc82 |
302 | ?> |
91e0dccc |
303 | </body></html> |