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