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