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