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