String fix
[squirrelmail.git] / src / addrbook_search_html.php
CommitLineData
c1e15177 1<?php
895905c0 2
35586184 3/**
4 * addrbook_search_html.php
5 *
6c84ba1e 6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
35586184 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 *
30967a1e 13 * @version $Id$
8f6f9ba5 14 * @package squirrelmail
de00443c 15 * @subpackage addressbook
35586184 16 */
c1e15177 17
91e0dccc 18/**
30967a1e 19 * Path for SquirrelMail required files.
20 * @ignore
21 */
abb3c512 22if (! defined('SM_PATH') ) {
39bfea8f 23 define('SM_PATH','../');
abb3c512 24}
86725763 25
8f6f9ba5 26/** SquirrelMail required files. */
08185f2a 27require_once(SM_PATH . 'include/validate.php');
80945fcf 28include_once(SM_PATH . 'functions/global.php');
29include_once(SM_PATH . 'functions/date.php');
30include_once(SM_PATH . 'functions/display_messages.php');
31include_once(SM_PATH . 'functions/addressbook.php');
32include_once(SM_PATH . 'functions/plugin.php');
33include_once(SM_PATH . 'functions/strings.php');
34include_once(SM_PATH . 'functions/html.php');
c1e15177 35
1e12d1ff 36sqgetGlobalVar('session', $session, SQ_POST);
37sqgetGlobalVar('mailbox', $mailbox, SQ_POST);
80945fcf 38if (! sqgetGlobalVar('addrquery', $addrquery, SQ_POST))
39 $addrquery='';
1e12d1ff 40sqgetGlobalVar('listall', $listall, SQ_POST);
41sqgetGlobalVar('backend', $backend, SQ_POST);
0b97a708 42
8f6f9ba5 43/**
44 * Insert hidden data
45 */
00a065a6 46function addr_insert_hidden() {
47 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox,
6a12032e 48 $identity, $session;
00a065a6 49
65a5bae6 50 if (substr($body, 0, 1) == "\r") {
62366261 51 echo addHidden('body', "\n".$body);
52 } else {
53 echo addHidden('body', $body);
14f1b90b 54 }
55
62366261 56 echo addHidden('session', $session).
57 addHidden('subject', $subject).
39bfea8f 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');
62366261 64}
65
14f1b90b 66
8f6f9ba5 67/**
68 * List search results
69 * @param array $res Array containing results of search
70 * @param bool $includesource UNDOCUMENTED [Default=true]
71 */
00a065a6 72function addr_display_result($res, $includesource = true) {
e842b215 73 global $color, $javascript_on, $PHP_SELF, $squirrelmail_language;
00a065a6 74
75 if (sizeof($res) <= 0) return;
76
c435f076 77 echo addForm($PHP_SELF, 'post', 'addrbook').
62366261 78 addHidden('html_addr_search_done', 'true');
00a065a6 79 addr_insert_hidden();
80 $line = 0;
81
0bb8cc68 82if ($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";
c435f076 96 $chk_all = '<a href="#" onclick="CheckAll(\'T\');">' . _("All") . '</a>&nbsp;<font color="'.$color[9].'">'._("To").'</font>'.
0bb8cc68 97 '&nbsp;&nbsp;'.
c435f076 98 '<a href="#" onclick="CheckAll(\'C\');">' . _("All") . '</a>&nbsp;<font color="'.$color[9].'">'._("Cc").'</font>'.
0bb8cc68 99 '&nbsp;&nbsp;'.
c435f076 100 '<a href="#" onclick="CheckAll(\'B\');">' . _("All") . '</a>';
0bb8cc68 101 }
7b783475 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' );
00a065a6 108
109 if ($includesource) {
7b783475 110 echo html_tag( 'th', '&nbsp;' . _("Source"), 'left', '', 'width="10%"' );
00a065a6 111 }
112
7b783475 113 echo "</tr>\n";
00a065a6 114
115 foreach ($res as $row) {
3d0cada3 116 $email = AddressBook::full_address($row);
91e0dccc 117 if ($line % 2) {
93adc018 118 $tr_bgcolor = $color[12];
119 } else {
120 $tr_bgcolor = $color[4];
121 }
e842b215 122 if ($squirrelmail_language == 'ja_JP')
123 {
c435f076 124 echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) .
e842b215 125 html_tag( 'td',
39bfea8f 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;' ,
c435f076 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;"' );
e842b215 136 } else {
c435f076 137 echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) .
7b783475 138 html_tag( 'td',
39bfea8f 139 addCheckBox('send_to_search[T'.$line.']', FALSE, $email).
62366261 140 '&nbsp;' . _("To") . '&nbsp;' .
39bfea8f 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;' ,
c435f076 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;"' );
e842b215 149 }
7b783475 150
00a065a6 151 if ($includesource) {
c435f076 152 echo html_tag( 'td', '&nbsp;' . $row['source'] . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' );
00a065a6 153 }
154 echo "</tr>\n";
155 $line ++;
156 }
7b783475 157 if ($includesource) { $td_colspan = '5'; } else { $td_colspan = '4'; }
158 echo html_tag( 'tr',
159 html_tag( 'td',
39bfea8f 160 '<input type="submit" name="addr_search_done" value="' .
1bb8fb4c 161 _("Use Addresses") . '" /> ' .
f8a1ed5a 162 '<input type="submit" name="addr_search_cancel" value="' .
163 _("Cancel") . '" />',
7b783475 164 'center', '', 'colspan="'. $td_colspan .'"' )
165 ) .
39bfea8f 166 '</table>' .
167 addHidden('html_addr_search_done', '1').
168 '</form>';
00a065a6 169}
170
171/* --- End functions --- */
172
9c3e6cd4 173if ($compose_new_win == '1') {
174 compose_Header($color, $mailbox);
175}
176else {
177 displayPageHeader($color, $mailbox);
178}
40262494 179
180/** set correct value of $default_charset */
181global $default_charset;
182set_my_charset();
183
00a065a6 184/* Initialize addressbook */
185$abook = addressbook_init();
c1e15177 186
14f1b90b 187
39bfea8f 188echo '<br />' .
7b783475 189html_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"' );
14f1b90b 194
00a065a6 195
196/* Search form */
7b783475 197echo '<center>' .
198 html_tag( 'table', '', 'center', '', 'border="0"' ) .
199 html_tag( 'tr' ) .
c435f076 200 html_tag( 'td', '', 'left', '', 'style="white-space: nowrap;" valign="middle"' ) . "\n" .
39bfea8f 201 addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f').
202 "\n<center>\n" .
203 ' <nobr><strong>' . _("Search for") . "</strong>\n";
00a065a6 204addr_insert_hidden();
62366261 205echo addInput('addrquery', $addrquery, 26);
00a065a6 206
207/* List all backends to allow the user to choose where to search */
208if (!isset($backend)) { $backend = ''; }
209if ($abook->numbackends > 1) {
39bfea8f 210 echo '<strong>' . _("in") . '</strong>&nbsp;';
91e0dccc 211
212 $selopts['-1'] = _("All address books");
00a065a6 213 $ret = $abook->get_backend_list();
91e0dccc 214
00a065a6 215 while (list($undef,$v) = each($ret)) {
39bfea8f 216 $selopts[$v->bnum] = $v->sname;
00a065a6 217 }
62366261 218 echo addSelect('backend', $selopts, $backend, TRUE);
00a065a6 219} else {
62366261 220 echo addHidden('backend', '-1');
00a065a6 221}
6a12032e 222if (isset($session)) {
62366261 223 echo addHidden('session', $session);
6a12032e 224}
225
39bfea8f 226echo '<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";
7b783475 230echo '</center>';
00a065a6 231do_hook('addrbook_html_search_below');
232/* End search form */
233
80945fcf 234/* List addresses. Show personal addressbook */
235if ($addrquery == '' || ! empty($listall)) {
236 // TODO: recheck all conditions and simplity if statements
00a065a6 237 if (! isset($backend) || $backend != -1 || $addrquery == '') {
80945fcf 238 if ($addrquery == '' && empty($listall)) {
6e79bfe2 239 $backend = $abook->localbackend;
00a065a6 240 }
14f1b90b 241
39bfea8f 242 /* echo '<h3 align="center">' . $abook->backends[$backend]->sname) . "</h3>\n"; */
14f1b90b 243
00a065a6 244 $res = $abook->list_addr($backend);
14f1b90b 245
00a065a6 246 if (is_array($res)) {
a10110a5 247 usort($res,'alistcmp');
6e79bfe2 248 addr_display_result($res, false);
00a065a6 249 } else {
39bfea8f 250 echo html_tag( 'p', '<strong><br />' .
91e0dccc 251 sprintf(_("Unable to list addresses from %s"),
7b783475 252 $abook->backends[$backend]->sname) . "</strong>\n" ,
253 'center' );
00a065a6 254 }
255
256 } else {
257 $res = $abook->list_addr();
a10110a5 258 usort($res,'alistcmp');
00a065a6 259 addr_display_result($res, true);
260 }
80945fcf 261 echo "\n</body></html>";
00a065a6 262 exit;
80945fcf 263} elseif (!empty($addrquery)) {
00a065a6 264 /* Do the search */
80945fcf 265 if ($backend == -1) {
266 $res = $abook->s_search($addrquery);
267 } else {
268 $res = $abook->s_search($addrquery, $backend);
269 }
00a065a6 270
80945fcf 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" ,
dcc1cc82 275 'center' ) .
80945fcf 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' ) .
39bfea8f 282 "\n</body></html>\n";
80945fcf 283 } else {
284 addr_display_result($res);
00a065a6 285 }
286 }
80945fcf 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' );
00a065a6 293}
294
295if ($addrquery == '' || sizeof($res) == 0) {
62366261 296 echo '<center>'.
c435f076 297 addForm('compose.php','post','k');
00a065a6 298 addr_insert_hidden();
39bfea8f 299 echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" .
00a065a6 300 '</form></center></nobr>';
301}
6e79bfe2 302
dcc1cc82 303?>
f8a1ed5a 304</body></html>