81997272da00d67e403b94e26d6f1d7c3063f3fd
[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 $tr_bgcolor = '';
115 $email = AddressBook::full_address($row);
116 if ($line % 2) { $tr_bgcolor = $color[0]; }
117 if ($squirrelmail_language == 'ja_JP')
118 {
119 echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) .
120 html_tag( 'td',
121 '<input type=checkbox name="send_to_search[T' . $line . ']" value = "' .
122 htmlspecialchars($email) . '">&nbsp;' . _("To") . '&nbsp;' .
123 '<input type=checkbox name="send_to_search[C' . $line . ']" value = "' .
124 htmlspecialchars($email) . '">&nbsp;' . _("Cc") . '&nbsp;' .
125 '<input type=checkbox name="send_to_search[B' . $line . ']" value = "' .
126 htmlspecialchars($email) . '">&nbsp;' . _("Bcc") . '&nbsp;' ,
127 'center', '', 'width="5%" nowrap' ) .
128 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['lastname']) . ' ' . htmlspecialchars($row['firstname']) . '&nbsp;', 'left', '', 'nowrap' ) .
129 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['email']) . '&nbsp;', 'left', '', 'nowrap' ) .
130 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['label']) . '&nbsp;', 'left', '', 'nowrap' );
131 } else {
132 echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) .
133 html_tag( 'td',
134 addCheckBox('send_to_search[T'.$line.']', FALSE, $email).
135 '&nbsp;' . _("To") . '&nbsp;' .
136 addCheckBox('send_to_search[C'.$line.']', FALSE, $email).
137 '&nbsp;' . _("Cc") . '&nbsp;' .
138 addCheckBox('send_to_search[B'.$line.']', FALSE, $email).
139 '&nbsp;' . _("Bcc") . '&nbsp;' ,
140 'center', '', 'width="5%" nowrap' ) .
141 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['name']) . '&nbsp;', 'left', '', 'nowrap' ) .
142 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['email']) . '&nbsp;', 'left', '', 'nowrap' ) .
143 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['label']) . '&nbsp;', 'left', '', 'nowrap' );
144 }
145
146 if ($includesource) {
147 echo html_tag( 'td', '&nbsp;' . $row['source'] . '&nbsp;', 'left', '', 'nowrap' );
148 }
149 echo "</tr>\n";
150 $line ++;
151 }
152 if ($includesource) { $td_colspan = '5'; } else { $td_colspan = '4'; }
153 echo html_tag( 'tr',
154 html_tag( 'td',
155 '<INPUT TYPE=submit NAME="addr_search_done" VALUE="' .
156 _("Use Addresses") . '">' ,
157 'center', '', 'colspan="'. $td_colspan .'"' )
158 ) .
159 '</TABLE>' .
160 addHidden('html_addr_search_done', '1').
161 '</FORM>';
162 }
163
164 /* --- End functions --- */
165
166 if ($compose_new_win == '1') {
167 compose_Header($color, $mailbox);
168 }
169 else {
170 displayPageHeader($color, $mailbox);
171 }
172 /* Initialize addressbook */
173 $abook = addressbook_init();
174
175
176 echo '<br>' .
177 html_tag( 'table',
178 html_tag( 'tr',
179 html_tag( 'td', '<b>' . _("Address Book Search") . '</b>', 'center', $color[0] )
180 ) ,
181 'center', '', 'width="95%" cellpadding="2" cellspacing="2" border="0"' );
182
183
184 /* Search form */
185 echo '<center>' .
186 html_tag( 'table', '', 'center', '', 'border="0"' ) .
187 html_tag( 'tr' ) .
188 html_tag( 'td', '', 'left', '', 'nowrap valign="middle"' ) . "\n" .
189 addForm($PHP_SELF.'?html_addr_search=true', 'POST', 'f').
190 "\n<CENTER>\n" .
191 ' <nobr><STRONG>' . _("Search for") . "</STRONG>\n";
192 addr_insert_hidden();
193 if (! isset($addrquery))
194 $addrquery = '';
195 echo addInput('addrquery', $addrquery, 26);
196
197 /* List all backends to allow the user to choose where to search */
198 if (!isset($backend)) { $backend = ''; }
199 if ($abook->numbackends > 1) {
200 echo '<STRONG>' . _("in") . '</STRONG>&nbsp;';
201
202 $selopts['-1'] = _("All address books");
203 $ret = $abook->get_backend_list();
204
205 while (list($undef,$v) = each($ret)) {
206 $selopts[$v->bnum] = $v->sname;
207 }
208 echo addSelect('backend', $selopts, $backend, TRUE);
209 } else {
210 echo addHidden('backend', '-1');
211 }
212 if (isset($session)) {
213 echo addHidden('session', $session);
214 }
215
216 echo '<INPUT TYPE=submit VALUE="' . _("Search") . '">' .
217 '&nbsp;|&nbsp;<INPUT TYPE=submit VALUE="' . _("List all") .
218 '" NAME=listall>' . "\n" .
219 '</FORM></center></TD></TR></TABLE>' . "\n";
220 addr_insert_hidden();
221 echo '</center>';
222 do_hook('addrbook_html_search_below');
223 /* End search form */
224
225 /* Show personal addressbook */
226
227 if ( !empty( $listall ) ){
228 $addrquery = '*';
229 }
230
231 if ($addrquery == '' && empty($listall)) {
232
233 if (! isset($backend) || $backend != -1 || $addrquery == '') {
234 if ($addrquery == '') {
235 $backend = $abook->localbackend;
236 }
237
238 /* echo '<H3 ALIGN=center>' . $abook->backends[$backend]->sname) . "</H3>\n"; */
239
240 $res = $abook->list_addr($backend);
241
242 if (is_array($res)) {
243 usort($res,'alistcmp');
244 addr_display_result($res, false);
245 } else {
246 echo html_tag( 'p', '<strong><br>' .
247 sprintf(_("Unable to list addresses from %s"),
248 $abook->backends[$backend]->sname) . "</strong>\n" ,
249 'center' );
250 }
251
252 } else {
253 $res = $abook->list_addr();
254 usort($res,'alistcmp');
255 addr_display_result($res, true);
256 }
257 exit;
258 }
259 else {
260
261 /* Do the search */
262 if (!empty($addrquery)) {
263
264 if ($backend == -1) {
265 $res = $abook->s_search($addrquery);
266 } else {
267 $res = $abook->s_search($addrquery, $backend);
268 }
269
270 if (!is_array($res)) {
271 echo html_tag( 'p', '<b><br>' .
272 _("Your search failed with the following error(s)") .
273 ':<br>' . $abook->error . "</b>\n" ,
274 'center' ) .
275 "\n</BODY></HTML>\n";
276 } else {
277 if (sizeof($res) == 0) {
278 echo html_tag( 'p', '<br><b>' .
279 _("No persons matching your search were found") . "</b>\n" ,
280 'center' ) .
281 "\n</BODY></HTML>\n";
282 } else {
283 addr_display_result($res);
284 }
285 }
286 }
287 }
288
289 if ($addrquery == '' || sizeof($res) == 0) {
290 /* printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF); */
291 echo '<center>'.
292 addForm('compose.php','POST','k');
293 addr_insert_hidden();
294 echo '<INPUT TYPE=submit VALUE="' . _("Return") . '" NAME=return>' . "\n" .
295 '</form></center></nobr>';
296 }
297
298 ?>
299 </body></html>