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