c1e15177 |
1 | <?php |
35586184 |
2 | /** |
3 | * addrbook_search_html.php |
4 | * |
35586184 |
5 | * Handle addressbook searching with pure html. |
6 | * |
7 | * This file is included from compose.php |
8 | * |
47ccfad4 |
9 | * @copyright © 1999-2006 The SquirrelMail Project Team |
4b4abf93 |
10 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
30967a1e |
11 | * @version $Id$ |
8f6f9ba5 |
12 | * @package squirrelmail |
de00443c |
13 | * @subpackage addressbook |
35586184 |
14 | */ |
c1e15177 |
15 | |
91e0dccc |
16 | /** |
202bcbcc |
17 | * Include the SquirrelMail initialization file. |
18 | * Because this file can also be included within compose we check for the $bInit |
19 | * var which is set inside ini.php. It's needed because compose already includes |
20 | * init.php. |
30967a1e |
21 | */ |
202bcbcc |
22 | if (!isset($bInit)) { |
23 | include('../include/init.php'); |
abb3c512 |
24 | } |
86725763 |
25 | |
8f6f9ba5 |
26 | /** SquirrelMail required files. */ |
80945fcf |
27 | include_once(SM_PATH . 'functions/date.php'); |
80945fcf |
28 | include_once(SM_PATH . 'functions/addressbook.php'); |
c1e15177 |
29 | |
1e12d1ff |
30 | sqgetGlobalVar('session', $session, SQ_POST); |
31 | sqgetGlobalVar('mailbox', $mailbox, SQ_POST); |
80945fcf |
32 | if (! sqgetGlobalVar('addrquery', $addrquery, SQ_POST)) |
33 | $addrquery=''; |
1e12d1ff |
34 | sqgetGlobalVar('listall', $listall, SQ_POST); |
35 | sqgetGlobalVar('backend', $backend, SQ_POST); |
0b97a708 |
36 | |
8f6f9ba5 |
37 | /** |
38 | * Insert hidden data |
39 | */ |
00a065a6 |
40 | function addr_insert_hidden() { |
41 | global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox, |
6a12032e |
42 | $identity, $session; |
00a065a6 |
43 | |
65a5bae6 |
44 | if (substr($body, 0, 1) == "\r") { |
62366261 |
45 | echo addHidden('body', "\n".$body); |
46 | } else { |
47 | echo addHidden('body', $body); |
14f1b90b |
48 | } |
49 | |
62366261 |
50 | echo addHidden('session', $session). |
51 | addHidden('subject', $subject). |
39bfea8f |
52 | addHidden('send_to', $send_to). |
53 | addHidden('send_to_bcc', $send_to_bcc). |
54 | addHidden('send_to_cc', $send_to_cc). |
55 | addHidden('identity', $identity). |
56 | addHidden('mailbox', $mailbox). |
57 | addHidden('from_htmladdr_search', 'true'); |
62366261 |
58 | } |
59 | |
14f1b90b |
60 | |
8f6f9ba5 |
61 | /** |
62 | * List search results |
63 | * @param array $res Array containing results of search |
c6f1c1ac |
64 | * @param bool $includesource If true, adds backend column to address listing |
8f6f9ba5 |
65 | */ |
00a065a6 |
66 | function addr_display_result($res, $includesource = true) { |
e842b215 |
67 | global $color, $javascript_on, $PHP_SELF, $squirrelmail_language; |
00a065a6 |
68 | |
69 | if (sizeof($res) <= 0) return; |
70 | |
c435f076 |
71 | echo addForm($PHP_SELF, 'post', 'addrbook'). |
62366261 |
72 | addHidden('html_addr_search_done', 'true'); |
00a065a6 |
73 | addr_insert_hidden(); |
74 | $line = 0; |
75 | |
c6f1c1ac |
76 | if ($javascript_on) { |
77 | print |
2c92ea9d |
78 | '<script type="text/javascript">' . |
c6f1c1ac |
79 | "\n<!-- \n" . |
80 | "function CheckAll(ch) {\n" . |
81 | " for (var i = 0; i < document.addrbook.elements.length; i++) {\n" . |
82 | " if( document.addrbook.elements[i].type == 'checkbox' &&\n" . |
83 | " document.addrbook.elements[i].name.substr(0,16) == 'send_to_search['+ch ) {\n" . |
84 | " document.addrbook.elements[i].checked = !(document.addrbook.elements[i].checked);\n". |
85 | " }\n" . |
86 | " }\n" . |
87 | "}\n" . |
88 | "//-->\n" . |
89 | "</script>\n"; |
90 | $chk_all = '<a href="#" onclick="CheckAll(\'T\');">'._("All").'</a> <font color="'.$color[9].'">'._("To").'</font>'. |
0bb8cc68 |
91 | ' '. |
c435f076 |
92 | '<a href="#" onclick="CheckAll(\'C\');">' . _("All") . '</a> <font color="'.$color[9].'">'._("Cc").'</font>'. |
0bb8cc68 |
93 | ' '. |
c435f076 |
94 | '<a href="#" onclick="CheckAll(\'B\');">' . _("All") . '</a>'; |
c6f1c1ac |
95 | } else { |
96 | // check_all links are used only in JavaScript. disable links in js=off environment. |
97 | $chk_all = ''; |
0bb8cc68 |
98 | } |
7b783475 |
99 | echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) . |
100 | html_tag( 'tr', '', '', $color[9] ) . |
101 | html_tag( 'th', ' ' . $chk_all, 'left' ) . |
102 | html_tag( 'th', ' ' . _("Name"), 'left' ) . |
103 | html_tag( 'th', ' ' . _("E-mail"), 'left' ) . |
104 | html_tag( 'th', ' ' . _("Info"), 'left' ); |
00a065a6 |
105 | |
106 | if ($includesource) { |
7b783475 |
107 | echo html_tag( 'th', ' ' . _("Source"), 'left', '', 'width="10%"' ); |
00a065a6 |
108 | } |
109 | |
7b783475 |
110 | echo "</tr>\n"; |
00a065a6 |
111 | |
112 | foreach ($res as $row) { |
3d0cada3 |
113 | $email = AddressBook::full_address($row); |
91e0dccc |
114 | if ($line % 2) { |
93adc018 |
115 | $tr_bgcolor = $color[12]; |
116 | } else { |
117 | $tr_bgcolor = $color[4]; |
118 | } |
e842b215 |
119 | if ($squirrelmail_language == 'ja_JP') |
120 | { |
c435f076 |
121 | echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) . |
e842b215 |
122 | html_tag( 'td', |
39bfea8f |
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") . ' ' , |
c435f076 |
129 | 'center', '', 'width="5%" style="white-space: nowrap;"' ) . |
130 | html_tag( 'td', ' ' . htmlspecialchars($row['lastname']) . ' ' . htmlspecialchars($row['firstname']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) . |
131 | html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) . |
132 | html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'style="white-space: nowrap;"' ); |
e842b215 |
133 | } else { |
c435f076 |
134 | echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) . |
7b783475 |
135 | html_tag( 'td', |
39bfea8f |
136 | addCheckBox('send_to_search[T'.$line.']', FALSE, $email). |
62366261 |
137 | ' ' . _("To") . ' ' . |
39bfea8f |
138 | addCheckBox('send_to_search[C'.$line.']', FALSE, $email). |
139 | ' ' . _("Cc") . ' ' . |
140 | addCheckBox('send_to_search[B'.$line.']', FALSE, $email). |
141 | ' ' . _("Bcc") . ' ' , |
c435f076 |
142 | 'center', '', 'width="5%" style="white-space: nowrap;"' ) . |
143 | html_tag( 'td', ' ' . htmlspecialchars($row['name']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) . |
144 | html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) . |
145 | html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'style="white-space: nowrap;"' ); |
e842b215 |
146 | } |
7b783475 |
147 | |
00a065a6 |
148 | if ($includesource) { |
c435f076 |
149 | echo html_tag( 'td', ' ' . $row['source'] . ' ', 'left', '', 'style="white-space: 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', |
39bfea8f |
157 | '<input type="submit" name="addr_search_done" value="' . |
1bb8fb4c |
158 | _("Use Addresses") . '" /> ' . |
f8a1ed5a |
159 | '<input type="submit" name="addr_search_cancel" value="' . |
160 | _("Cancel") . '" />', |
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 | } |
40262494 |
176 | |
177 | /** set correct value of $default_charset */ |
178 | global $default_charset; |
179 | set_my_charset(); |
180 | |
00a065a6 |
181 | /* Initialize addressbook */ |
182 | $abook = addressbook_init(); |
c1e15177 |
183 | |
14f1b90b |
184 | |
39bfea8f |
185 | echo '<br />' . |
7b783475 |
186 | html_tag( 'table', |
187 | html_tag( 'tr', |
188 | html_tag( 'td', '<b>' . _("Address Book Search") . '</b>', 'center', $color[0] ) |
189 | ) , |
190 | 'center', '', 'width="95%" cellpadding="2" cellspacing="2" border="0"' ); |
14f1b90b |
191 | |
00a065a6 |
192 | |
193 | /* Search form */ |
f265009a |
194 | echo '<div style="text-align: center;">' . |
7b783475 |
195 | html_tag( 'table', '', 'center', '', 'border="0"' ) . |
196 | html_tag( 'tr' ) . |
c435f076 |
197 | html_tag( 'td', '', 'left', '', 'style="white-space: nowrap;" valign="middle"' ) . "\n" . |
39bfea8f |
198 | addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f'). |
0e271f86 |
199 | "\n<div style=\"text-align: center;\">\n" . |
39bfea8f |
200 | ' <nobr><strong>' . _("Search for") . "</strong>\n"; |
00a065a6 |
201 | addr_insert_hidden(); |
62366261 |
202 | echo addInput('addrquery', $addrquery, 26); |
00a065a6 |
203 | |
204 | /* List all backends to allow the user to choose where to search */ |
205 | if (!isset($backend)) { $backend = ''; } |
206 | if ($abook->numbackends > 1) { |
39bfea8f |
207 | echo '<strong>' . _("in") . '</strong> '; |
91e0dccc |
208 | |
209 | $selopts['-1'] = _("All address books"); |
00a065a6 |
210 | $ret = $abook->get_backend_list(); |
91e0dccc |
211 | |
00a065a6 |
212 | while (list($undef,$v) = each($ret)) { |
39bfea8f |
213 | $selopts[$v->bnum] = $v->sname; |
00a065a6 |
214 | } |
62366261 |
215 | echo addSelect('backend', $selopts, $backend, TRUE); |
00a065a6 |
216 | } else { |
62366261 |
217 | echo addHidden('backend', '-1'); |
00a065a6 |
218 | } |
6a12032e |
219 | if (isset($session)) { |
62366261 |
220 | echo addHidden('session', $session); |
6a12032e |
221 | } |
222 | |
39bfea8f |
223 | echo '<input type="submit" value="' . _("Search") . '" />' . |
224 | ' | <input type="submit" value="' . _("List all") . |
225 | '" name="listall" />' . "\n" . |
f265009a |
226 | '</form></div></td></tr></table>' . "\n"; |
227 | echo '</div>'; |
00a065a6 |
228 | do_hook('addrbook_html_search_below'); |
229 | /* End search form */ |
230 | |
80945fcf |
231 | /* List addresses. Show personal addressbook */ |
232 | if ($addrquery == '' || ! empty($listall)) { |
233 | // TODO: recheck all conditions and simplity if statements |
00a065a6 |
234 | if (! isset($backend) || $backend != -1 || $addrquery == '') { |
80945fcf |
235 | if ($addrquery == '' && empty($listall)) { |
6e79bfe2 |
236 | $backend = $abook->localbackend; |
00a065a6 |
237 | } |
14f1b90b |
238 | |
39bfea8f |
239 | /* echo '<h3 align="center">' . $abook->backends[$backend]->sname) . "</h3>\n"; */ |
14f1b90b |
240 | |
00a065a6 |
241 | $res = $abook->list_addr($backend); |
14f1b90b |
242 | |
00a065a6 |
243 | if (is_array($res)) { |
a10110a5 |
244 | usort($res,'alistcmp'); |
6e79bfe2 |
245 | addr_display_result($res, false); |
00a065a6 |
246 | } else { |
39bfea8f |
247 | echo html_tag( 'p', '<strong><br />' . |
91e0dccc |
248 | sprintf(_("Unable to list addresses from %s"), |
7b783475 |
249 | $abook->backends[$backend]->sname) . "</strong>\n" , |
250 | 'center' ); |
00a065a6 |
251 | } |
252 | |
253 | } else { |
254 | $res = $abook->list_addr(); |
a10110a5 |
255 | usort($res,'alistcmp'); |
00a065a6 |
256 | addr_display_result($res, true); |
257 | } |
879e86ec |
258 | $oTemplate->display('footer.tpl'); |
00a065a6 |
259 | exit; |
80945fcf |
260 | } elseif (!empty($addrquery)) { |
00a065a6 |
261 | /* Do the search */ |
80945fcf |
262 | if ($backend == -1) { |
263 | $res = $abook->s_search($addrquery); |
264 | } else { |
265 | $res = $abook->s_search($addrquery, $backend); |
266 | } |
00a065a6 |
267 | |
80945fcf |
268 | if (!is_array($res)) { |
269 | echo html_tag( 'p', '<b><br />' . |
270 | _("Your search failed with the following error(s)") . |
271 | ':<br />' . $abook->error . "</b>\n" , |
879e86ec |
272 | 'center' ) . "\n"; |
273 | $oTemplate->display('footer.tpl'); |
80945fcf |
274 | } else { |
275 | if (sizeof($res) == 0) { |
276 | echo html_tag( 'p', '<br /><b>' . |
277 | _("No persons matching your search were found") . "</b>\n" , |
879e86ec |
278 | 'center' ) . "\n"; |
279 | $oTemplate->display('footer.tpl'); |
80945fcf |
280 | } else { |
281 | addr_display_result($res); |
00a065a6 |
282 | } |
283 | } |
80945fcf |
284 | } else { |
285 | // not first time display, not listall and search is empty |
286 | // TODO: I think, this part of control structure is never reached. |
287 | echo html_tag( 'p', '<br /><b>' . |
288 | _("Nothing to search") . "</b>\n" , |
289 | 'center' ); |
00a065a6 |
290 | } |
291 | |
292 | if ($addrquery == '' || sizeof($res) == 0) { |
f265009a |
293 | echo '<div style="text-align: center;">'. |
c435f076 |
294 | addForm('compose.php','post','k'); |
00a065a6 |
295 | addr_insert_hidden(); |
39bfea8f |
296 | echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" . |
f265009a |
297 | '</form></div></nobr>'; |
00a065a6 |
298 | } |
879e86ec |
299 | |
5c4ff7bf |
300 | $oTemplate->display('footer.tpl'); |
301 | ?> |