use same width as other tables on src/addressbook.php
[squirrelmail.git] / src / addrbook_search_html.php
1 <?php
2
3 /**
4 * addrbook_search_html.php
5 *
6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
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 *
13 * @version $Id$
14 * @package squirrelmail
15 * @subpackage addressbook
16 */
17
18 /**
19 * Path for SquirrelMail required files.
20 * @ignore
21 */
22 if (! defined('SM_PATH') ) {
23 define('SM_PATH','../');
24 }
25
26 /** SquirrelMail required files. */
27 require_once(SM_PATH . 'include/validate.php');
28 require_once(SM_PATH . 'functions/global.php');
29 require_once(SM_PATH . 'functions/date.php');
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');
35
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);
41
42 /**
43 * Insert hidden data
44 */
45 function addr_insert_hidden() {
46 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox,
47 $identity, $session;
48
49 if (substr($body, 0, 1) == "\r") {
50 echo addHidden('body', "\n".$body);
51 } else {
52 echo addHidden('body', $body);
53 }
54
55 echo addHidden('session', $session).
56 addHidden('subject', $subject).
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');
63 }
64
65
66 /**
67 * List search results
68 * @param array $res Array containing results of search
69 * @param bool $includesource UNDOCUMENTED [Default=true]
70 */
71 function addr_display_result($res, $includesource = true) {
72 global $color, $javascript_on, $PHP_SELF, $squirrelmail_language;
73
74 if (sizeof($res) <= 0) return;
75
76 echo addForm($PHP_SELF, 'post', 'addrbook').
77 addHidden('html_addr_search_done', 'true');
78 addr_insert_hidden();
79 $line = 0;
80
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";
95 $chk_all = '<a href="#" onclick="CheckAll(\'T\');">' . _("All") . '</a>&nbsp;<font color="'.$color[9].'">'._("To").'</font>'.
96 '&nbsp;&nbsp;'.
97 '<a href="#" onclick="CheckAll(\'C\');">' . _("All") . '</a>&nbsp;<font color="'.$color[9].'">'._("Cc").'</font>'.
98 '&nbsp;&nbsp;'.
99 '<a href="#" onclick="CheckAll(\'B\');">' . _("All") . '</a>';
100 }
101 echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) .
102 html_tag( 'tr', '', '', $color[9] ) .
103 html_tag( 'th', '&nbsp;' . $chk_all, 'left' ) .
104 html_tag( 'th', '&nbsp;' . _("Name"), 'left' ) .
105 html_tag( 'th', '&nbsp;' . _("E-mail"), 'left' ) .
106 html_tag( 'th', '&nbsp;' . _("Info"), 'left' );
107
108 if ($includesource) {
109 echo html_tag( 'th', '&nbsp;' . _("Source"), 'left', '', 'width="10%"' );
110 }
111
112 echo "</tr>\n";
113
114 foreach ($res as $row) {
115 $email = AddressBook::full_address($row);
116 if ($line % 2) {
117 $tr_bgcolor = $color[12];
118 } else {
119 $tr_bgcolor = $color[4];
120 }
121 if ($squirrelmail_language == 'ja_JP')
122 {
123 echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) .
124 html_tag( 'td',
125 '<input type="checkbox" name="send_to_search[T' . $line . ']" value = "' .
126 htmlspecialchars($email) . '" />&nbsp;' . _("To") . '&nbsp;' .
127 '<input type="checkbox" name="send_to_search[C' . $line . ']" value = "' .
128 htmlspecialchars($email) . '" />&nbsp;' . _("Cc") . '&nbsp;' .
129 '<input type="checkbox" name="send_to_search[B' . $line . ']" value = "' .
130 htmlspecialchars($email) . '" />&nbsp;' . _("Bcc") . '&nbsp;' ,
131 'center', '', 'width="5%" style="white-space: nowrap;"' ) .
132 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['lastname']) . ' ' . htmlspecialchars($row['firstname']) . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' ) .
133 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['email']) . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' ) .
134 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['label']) . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' );
135 } else {
136 echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) .
137 html_tag( 'td',
138 addCheckBox('send_to_search[T'.$line.']', FALSE, $email).
139 '&nbsp;' . _("To") . '&nbsp;' .
140 addCheckBox('send_to_search[C'.$line.']', FALSE, $email).
141 '&nbsp;' . _("Cc") . '&nbsp;' .
142 addCheckBox('send_to_search[B'.$line.']', FALSE, $email).
143 '&nbsp;' . _("Bcc") . '&nbsp;' ,
144 'center', '', 'width="5%" style="white-space: nowrap;"' ) .
145 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['name']) . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' ) .
146 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['email']) . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' ) .
147 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['label']) . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' );
148 }
149
150 if ($includesource) {
151 echo html_tag( 'td', '&nbsp;' . $row['source'] . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' );
152 }
153 echo "</tr>\n";
154 $line ++;
155 }
156 if ($includesource) { $td_colspan = '5'; } else { $td_colspan = '4'; }
157 echo html_tag( 'tr',
158 html_tag( 'td',
159 '<input type="submit" name="addr_search_done" value="' .
160 _("Use Addresses") . '" />' ,
161 'center', '', 'colspan="'. $td_colspan .'"' )
162 ) .
163 '</table>' .
164 addHidden('html_addr_search_done', '1').
165 '</form>';
166 }
167
168 /* --- End functions --- */
169
170 if ($compose_new_win == '1') {
171 compose_Header($color, $mailbox);
172 }
173 else {
174 displayPageHeader($color, $mailbox);
175 }
176
177 /** set correct value of $default_charset */
178 global $default_charset;
179 set_my_charset();
180
181 /* Initialize addressbook */
182 $abook = addressbook_init();
183
184
185 echo '<br />' .
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"' );
191
192
193 /* Search form */
194 echo '<center>' .
195 html_tag( 'table', '', 'center', '', 'border="0"' ) .
196 html_tag( 'tr' ) .
197 html_tag( 'td', '', 'left', '', 'style="white-space: nowrap;" valign="middle"' ) . "\n" .
198 addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f').
199 "\n<center>\n" .
200 ' <nobr><strong>' . _("Search for") . "</strong>\n";
201 addr_insert_hidden();
202 if (! isset($addrquery))
203 $addrquery = '';
204 echo addInput('addrquery', $addrquery, 26);
205
206 /* List all backends to allow the user to choose where to search */
207 if (!isset($backend)) { $backend = ''; }
208 if ($abook->numbackends > 1) {
209 echo '<strong>' . _("in") . '</strong>&nbsp;';
210
211 $selopts['-1'] = _("All address books");
212 $ret = $abook->get_backend_list();
213
214 while (list($undef,$v) = each($ret)) {
215 $selopts[$v->bnum] = $v->sname;
216 }
217 echo addSelect('backend', $selopts, $backend, TRUE);
218 } else {
219 echo addHidden('backend', '-1');
220 }
221 if (isset($session)) {
222 echo addHidden('session', $session);
223 }
224
225 echo '<input type="submit" value="' . _("Search") . '" />' .
226 '&nbsp;|&nbsp;<input type="submit" value="' . _("List all") .
227 '" name="listall" />' . "\n" .
228 '</form></center></td></tr></table>' . "\n";
229 addr_insert_hidden();
230 echo '</center>';
231 do_hook('addrbook_html_search_below');
232 /* End search form */
233
234 /* Show personal addressbook */
235
236 if ( !empty( $listall ) ){
237 $addrquery = '*';
238 }
239
240 if ($addrquery == '' && empty($listall)) {
241
242 if (! isset($backend) || $backend != -1 || $addrquery == '') {
243 if ($addrquery == '') {
244 $backend = $abook->localbackend;
245 }
246
247 /* echo '<h3 align="center">' . $abook->backends[$backend]->sname) . "</h3>\n"; */
248
249 $res = $abook->list_addr($backend);
250
251 if (is_array($res)) {
252 usort($res,'alistcmp');
253 addr_display_result($res, false);
254 } else {
255 echo html_tag( 'p', '<strong><br />' .
256 sprintf(_("Unable to list addresses from %s"),
257 $abook->backends[$backend]->sname) . "</strong>\n" ,
258 'center' );
259 }
260
261 } else {
262 $res = $abook->list_addr();
263 usort($res,'alistcmp');
264 addr_display_result($res, true);
265 }
266 exit;
267 }
268 else {
269
270 /* Do the search */
271 if (!empty($addrquery)) {
272
273 if ($backend == -1) {
274 $res = $abook->s_search($addrquery);
275 } else {
276 $res = $abook->s_search($addrquery, $backend);
277 }
278
279 if (!is_array($res)) {
280 echo html_tag( 'p', '<b><br />' .
281 _("Your search failed with the following error(s)") .
282 ':<br />' . $abook->error . "</b>\n" ,
283 'center' ) .
284 "\n</body></html>\n";
285 } else {
286 if (sizeof($res) == 0) {
287 echo html_tag( 'p', '<br /><b>' .
288 _("No persons matching your search were found") . "</b>\n" ,
289 'center' ) .
290 "\n</body></html>\n";
291 } else {
292 addr_display_result($res);
293 }
294 }
295 }
296 }
297
298 if ($addrquery == '' || sizeof($res) == 0) {
299 /* printf('<center><form method="post" name="k" action="compose.php">'."\n", $PHP_SELF); */
300 echo '<center>'.
301 addForm('compose.php','post','k');
302 addr_insert_hidden();
303 echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" .
304 '</form></center></nobr>';
305 }
306
307 ?>
308 </body></html>