js=off triggers e_notice level error.
[squirrelmail.git] / src / addrbook_search_html.php
CommitLineData
c1e15177 1<?php
35586184 2/**
3 * addrbook_search_html.php
4 *
35586184 5 * Handle addressbook searching with pure html.
6 *
7 * This file is included from compose.php
8 *
4b4abf93 9 * @copyright &copy; 1999-2005 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 11 * @version $Id$
8f6f9ba5 12 * @package squirrelmail
de00443c 13 * @subpackage addressbook
35586184 14 */
c1e15177 15
91e0dccc 16/**
30967a1e 17 * Path for SquirrelMail required files.
18 * @ignore
19 */
abb3c512 20if (! defined('SM_PATH') ) {
39bfea8f 21 define('SM_PATH','../');
abb3c512 22}
86725763 23
8f6f9ba5 24/** SquirrelMail required files. */
08185f2a 25require_once(SM_PATH . 'include/validate.php');
80945fcf 26include_once(SM_PATH . 'functions/global.php');
27include_once(SM_PATH . 'functions/date.php');
28include_once(SM_PATH . 'functions/display_messages.php');
29include_once(SM_PATH . 'functions/addressbook.php');
30include_once(SM_PATH . 'functions/plugin.php');
31include_once(SM_PATH . 'functions/strings.php');
32include_once(SM_PATH . 'functions/html.php');
c1e15177 33
1e12d1ff 34sqgetGlobalVar('session', $session, SQ_POST);
35sqgetGlobalVar('mailbox', $mailbox, SQ_POST);
80945fcf 36if (! sqgetGlobalVar('addrquery', $addrquery, SQ_POST))
37 $addrquery='';
1e12d1ff 38sqgetGlobalVar('listall', $listall, SQ_POST);
39sqgetGlobalVar('backend', $backend, SQ_POST);
0b97a708 40
8f6f9ba5 41/**
42 * Insert hidden data
43 */
00a065a6 44function addr_insert_hidden() {
45 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox,
6a12032e 46 $identity, $session;
00a065a6 47
65a5bae6 48 if (substr($body, 0, 1) == "\r") {
62366261 49 echo addHidden('body', "\n".$body);
50 } else {
51 echo addHidden('body', $body);
14f1b90b 52 }
53
62366261 54 echo addHidden('session', $session).
55 addHidden('subject', $subject).
39bfea8f 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');
62366261 62}
63
14f1b90b 64
8f6f9ba5 65/**
66 * List search results
67 * @param array $res Array containing results of search
c6f1c1ac 68 * @param bool $includesource If true, adds backend column to address listing
8f6f9ba5 69 */
00a065a6 70function addr_display_result($res, $includesource = true) {
e842b215 71 global $color, $javascript_on, $PHP_SELF, $squirrelmail_language;
00a065a6 72
73 if (sizeof($res) <= 0) return;
74
c435f076 75 echo addForm($PHP_SELF, 'post', 'addrbook').
62366261 76 addHidden('html_addr_search_done', 'true');
00a065a6 77 addr_insert_hidden();
78 $line = 0;
79
c6f1c1ac 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>'.
0bb8cc68 95 '&nbsp;&nbsp;'.
c435f076 96 '<a href="#" onclick="CheckAll(\'C\');">' . _("All") . '</a>&nbsp;<font color="'.$color[9].'">'._("Cc").'</font>'.
0bb8cc68 97 '&nbsp;&nbsp;'.
c435f076 98 '<a href="#" onclick="CheckAll(\'B\');">' . _("All") . '</a>';
c6f1c1ac 99 } else {
100 // check_all links are used only in JavaScript. disable links in js=off environment.
101 $chk_all = '';
0bb8cc68 102 }
7b783475 103 echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) .
104 html_tag( 'tr', '', '', $color[9] ) .
105 html_tag( 'th', '&nbsp;' . $chk_all, 'left' ) .
106 html_tag( 'th', '&nbsp;' . _("Name"), 'left' ) .
107 html_tag( 'th', '&nbsp;' . _("E-mail"), 'left' ) .
108 html_tag( 'th', '&nbsp;' . _("Info"), 'left' );
00a065a6 109
110 if ($includesource) {
7b783475 111 echo html_tag( 'th', '&nbsp;' . _("Source"), 'left', '', 'width="10%"' );
00a065a6 112 }
113
7b783475 114 echo "</tr>\n";
00a065a6 115
116 foreach ($res as $row) {
3d0cada3 117 $email = AddressBook::full_address($row);
91e0dccc 118 if ($line % 2) {
93adc018 119 $tr_bgcolor = $color[12];
120 } else {
121 $tr_bgcolor = $color[4];
122 }
e842b215 123 if ($squirrelmail_language == 'ja_JP')
124 {
c435f076 125 echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) .
e842b215 126 html_tag( 'td',
39bfea8f 127 '<input type="checkbox" name="send_to_search[T' . $line . ']" value = "' .
128 htmlspecialchars($email) . '" />&nbsp;' . _("To") . '&nbsp;' .
129 '<input type="checkbox" name="send_to_search[C' . $line . ']" value = "' .
130 htmlspecialchars($email) . '" />&nbsp;' . _("Cc") . '&nbsp;' .
131 '<input type="checkbox" name="send_to_search[B' . $line . ']" value = "' .
132 htmlspecialchars($email) . '" />&nbsp;' . _("Bcc") . '&nbsp;' ,
c435f076 133 'center', '', 'width="5%" style="white-space: nowrap;"' ) .
134 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['lastname']) . ' ' . htmlspecialchars($row['firstname']) . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' ) .
135 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['email']) . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' ) .
136 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['label']) . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' );
e842b215 137 } else {
c435f076 138 echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) .
7b783475 139 html_tag( 'td',
39bfea8f 140 addCheckBox('send_to_search[T'.$line.']', FALSE, $email).
62366261 141 '&nbsp;' . _("To") . '&nbsp;' .
39bfea8f 142 addCheckBox('send_to_search[C'.$line.']', FALSE, $email).
143 '&nbsp;' . _("Cc") . '&nbsp;' .
144 addCheckBox('send_to_search[B'.$line.']', FALSE, $email).
145 '&nbsp;' . _("Bcc") . '&nbsp;' ,
c435f076 146 'center', '', 'width="5%" style="white-space: nowrap;"' ) .
147 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['name']) . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' ) .
148 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['email']) . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' ) .
149 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['label']) . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' );
e842b215 150 }
7b783475 151
00a065a6 152 if ($includesource) {
c435f076 153 echo html_tag( 'td', '&nbsp;' . $row['source'] . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' );
00a065a6 154 }
155 echo "</tr>\n";
156 $line ++;
157 }
7b783475 158 if ($includesource) { $td_colspan = '5'; } else { $td_colspan = '4'; }
159 echo html_tag( 'tr',
160 html_tag( 'td',
39bfea8f 161 '<input type="submit" name="addr_search_done" value="' .
1bb8fb4c 162 _("Use Addresses") . '" /> ' .
f8a1ed5a 163 '<input type="submit" name="addr_search_cancel" value="' .
164 _("Cancel") . '" />',
7b783475 165 'center', '', 'colspan="'. $td_colspan .'"' )
166 ) .
39bfea8f 167 '</table>' .
168 addHidden('html_addr_search_done', '1').
169 '</form>';
00a065a6 170}
171
172/* --- End functions --- */
173
9c3e6cd4 174if ($compose_new_win == '1') {
175 compose_Header($color, $mailbox);
176}
177else {
178 displayPageHeader($color, $mailbox);
179}
40262494 180
181/** set correct value of $default_charset */
182global $default_charset;
183set_my_charset();
184
00a065a6 185/* Initialize addressbook */
186$abook = addressbook_init();
c1e15177 187
14f1b90b 188
39bfea8f 189echo '<br />' .
7b783475 190html_tag( 'table',
191 html_tag( 'tr',
192 html_tag( 'td', '<b>' . _("Address Book Search") . '</b>', 'center', $color[0] )
193 ) ,
194'center', '', 'width="95%" cellpadding="2" cellspacing="2" border="0"' );
14f1b90b 195
00a065a6 196
197/* Search form */
7b783475 198echo '<center>' .
199 html_tag( 'table', '', 'center', '', 'border="0"' ) .
200 html_tag( 'tr' ) .
c435f076 201 html_tag( 'td', '', 'left', '', 'style="white-space: nowrap;" valign="middle"' ) . "\n" .
39bfea8f 202 addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f').
203 "\n<center>\n" .
204 ' <nobr><strong>' . _("Search for") . "</strong>\n";
00a065a6 205addr_insert_hidden();
62366261 206echo addInput('addrquery', $addrquery, 26);
00a065a6 207
208/* List all backends to allow the user to choose where to search */
209if (!isset($backend)) { $backend = ''; }
210if ($abook->numbackends > 1) {
39bfea8f 211 echo '<strong>' . _("in") . '</strong>&nbsp;';
91e0dccc 212
213 $selopts['-1'] = _("All address books");
00a065a6 214 $ret = $abook->get_backend_list();
91e0dccc 215
00a065a6 216 while (list($undef,$v) = each($ret)) {
39bfea8f 217 $selopts[$v->bnum] = $v->sname;
00a065a6 218 }
62366261 219 echo addSelect('backend', $selopts, $backend, TRUE);
00a065a6 220} else {
62366261 221 echo addHidden('backend', '-1');
00a065a6 222}
6a12032e 223if (isset($session)) {
62366261 224 echo addHidden('session', $session);
6a12032e 225}
226
39bfea8f 227echo '<input type="submit" value="' . _("Search") . '" />' .
228 '&nbsp;|&nbsp;<input type="submit" value="' . _("List all") .
229 '" name="listall" />' . "\n" .
230 '</form></center></td></tr></table>' . "\n";
7b783475 231echo '</center>';
00a065a6 232do_hook('addrbook_html_search_below');
233/* End search form */
234
80945fcf 235/* List addresses. Show personal addressbook */
236if ($addrquery == '' || ! empty($listall)) {
237 // TODO: recheck all conditions and simplity if statements
00a065a6 238 if (! isset($backend) || $backend != -1 || $addrquery == '') {
80945fcf 239 if ($addrquery == '' && empty($listall)) {
6e79bfe2 240 $backend = $abook->localbackend;
00a065a6 241 }
14f1b90b 242
39bfea8f 243 /* echo '<h3 align="center">' . $abook->backends[$backend]->sname) . "</h3>\n"; */
14f1b90b 244
00a065a6 245 $res = $abook->list_addr($backend);
14f1b90b 246
00a065a6 247 if (is_array($res)) {
a10110a5 248 usort($res,'alistcmp');
6e79bfe2 249 addr_display_result($res, false);
00a065a6 250 } else {
39bfea8f 251 echo html_tag( 'p', '<strong><br />' .
91e0dccc 252 sprintf(_("Unable to list addresses from %s"),
7b783475 253 $abook->backends[$backend]->sname) . "</strong>\n" ,
254 'center' );
00a065a6 255 }
256
257 } else {
258 $res = $abook->list_addr();
a10110a5 259 usort($res,'alistcmp');
00a065a6 260 addr_display_result($res, true);
261 }
80945fcf 262 echo "\n</body></html>";
00a065a6 263 exit;
80945fcf 264} elseif (!empty($addrquery)) {
00a065a6 265 /* Do the search */
80945fcf 266 if ($backend == -1) {
267 $res = $abook->s_search($addrquery);
268 } else {
269 $res = $abook->s_search($addrquery, $backend);
270 }
00a065a6 271
80945fcf 272 if (!is_array($res)) {
273 echo html_tag( 'p', '<b><br />' .
274 _("Your search failed with the following error(s)") .
275 ':<br />' . $abook->error . "</b>\n" ,
dcc1cc82 276 'center' ) .
80945fcf 277 "\n</body></html>\n";
278 } else {
279 if (sizeof($res) == 0) {
280 echo html_tag( 'p', '<br /><b>' .
281 _("No persons matching your search were found") . "</b>\n" ,
282 'center' ) .
39bfea8f 283 "\n</body></html>\n";
80945fcf 284 } else {
285 addr_display_result($res);
00a065a6 286 }
287 }
80945fcf 288} else {
289 // not first time display, not listall and search is empty
290 // TODO: I think, this part of control structure is never reached.
291 echo html_tag( 'p', '<br /><b>' .
292 _("Nothing to search") . "</b>\n" ,
293 'center' );
00a065a6 294}
295
296if ($addrquery == '' || sizeof($res) == 0) {
62366261 297 echo '<center>'.
c435f076 298 addForm('compose.php','post','k');
00a065a6 299 addr_insert_hidden();
39bfea8f 300 echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" .
00a065a6 301 '</form></center></nobr>';
302}
6e79bfe2 303
dcc1cc82 304?>
f8a1ed5a 305</body></html>