translator moved to other address
[squirrelmail.git] / src / addrbook_search_html.php
CommitLineData
c1e15177 1<?php
895905c0 2
35586184 3/**
4 * addrbook_search_html.php
5 *
82d304a0 6 * Copyright (c) 1999-2004 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
35586184 15 */
c1e15177 16
30967a1e 17/**
18 * Path for SquirrelMail required files.
19 * @ignore
20 */
abb3c512 21if (! defined('SM_PATH') ) {
22 define('SM_PATH','../');
23}
86725763 24
8f6f9ba5 25/** SquirrelMail required files. */
08185f2a 26require_once(SM_PATH . 'include/validate.php');
1e12d1ff 27require_once(SM_PATH . 'functions/global.php');
86725763 28require_once(SM_PATH . 'functions/date.php');
86725763 29require_once(SM_PATH . 'functions/display_messages.php');
30require_once(SM_PATH . 'functions/addressbook.php');
31require_once(SM_PATH . 'functions/plugin.php');
32require_once(SM_PATH . 'functions/strings.php');
33require_once(SM_PATH . 'functions/html.php');
c1e15177 34
1e12d1ff 35sqgetGlobalVar('session', $session, SQ_POST);
36sqgetGlobalVar('mailbox', $mailbox, SQ_POST);
37sqgetGlobalVar('addrquery', $addrquery, SQ_POST);
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).
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
14f1b90b 64
8f6f9ba5 65/**
66 * List search results
67 * @param array $res Array containing results of search
68 * @param bool $includesource UNDOCUMENTED [Default=true]
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
62366261 75 echo addForm($PHP_SELF, 'POST', 'addrbook').
76 addHidden('html_addr_search_done', 'true');
00a065a6 77 addr_insert_hidden();
78 $line = 0;
79
0bb8cc68 80if ($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 }
7b783475 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' );
00a065a6 106
107 if ($includesource) {
7b783475 108 echo html_tag( 'th', '&nbsp;' . _("Source"), 'left', '', 'width="10%"' );
00a065a6 109 }
110
7b783475 111 echo "</tr>\n";
00a065a6 112
113 foreach ($res as $row) {
7b783475 114 $tr_bgcolor = '';
3d0cada3 115 $email = AddressBook::full_address($row);
7b783475 116 if ($line % 2) { $tr_bgcolor = $color[0]; }
e842b215 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 {
7b783475 132 echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) .
133 html_tag( 'td',
62366261 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;' ,
7b783475 140 'center', '', 'width="5%" nowrap' ) .
4e160237 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' );
e842b215 144 }
7b783475 145
00a065a6 146 if ($includesource) {
7b783475 147 echo html_tag( 'td', '&nbsp;' . $row['source'] . '&nbsp;', 'left', '', 'nowrap' );
00a065a6 148 }
149 echo "</tr>\n";
150 $line ++;
151 }
7b783475 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 ) .
00a065a6 159 '</TABLE>' .
62366261 160 addHidden('html_addr_search_done', '1').
00a065a6 161 '</FORM>';
162}
163
164/* --- End functions --- */
165
9c3e6cd4 166if ($compose_new_win == '1') {
167 compose_Header($color, $mailbox);
168}
169else {
170 displayPageHeader($color, $mailbox);
171}
00a065a6 172/* Initialize addressbook */
173$abook = addressbook_init();
c1e15177 174
14f1b90b 175
7b783475 176echo '<br>' .
177html_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"' );
14f1b90b 182
00a065a6 183
184/* Search form */
7b783475 185echo '<center>' .
186 html_tag( 'table', '', 'center', '', 'border="0"' ) .
187 html_tag( 'tr' ) .
188 html_tag( 'td', '', 'left', '', 'nowrap valign="middle"' ) . "\n" .
62366261 189 addForm($PHP_SELF.'?html_addr_search=true', 'POST', 'f').
190 "\n<CENTER>\n" .
7b783475 191 ' <nobr><STRONG>' . _("Search for") . "</STRONG>\n";
00a065a6 192addr_insert_hidden();
193if (! isset($addrquery))
194 $addrquery = '';
62366261 195echo addInput('addrquery', $addrquery, 26);
00a065a6 196
197/* List all backends to allow the user to choose where to search */
198if (!isset($backend)) { $backend = ''; }
199if ($abook->numbackends > 1) {
62366261 200 echo '<STRONG>' . _("in") . '</STRONG>&nbsp;';
201
202 $selopts['-1'] = _("All address books");
00a065a6 203 $ret = $abook->get_backend_list();
62366261 204
00a065a6 205 while (list($undef,$v) = each($ret)) {
62366261 206 $selopts[$v->bnum] = $v->sname;
00a065a6 207 }
62366261 208 echo addSelect('backend', $selopts, $backend, TRUE);
00a065a6 209} else {
62366261 210 echo addHidden('backend', '-1');
00a065a6 211}
6a12032e 212if (isset($session)) {
62366261 213 echo addHidden('session', $session);
6a12032e 214}
215
00a065a6 216echo '<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";
220addr_insert_hidden();
7b783475 221echo '</center>';
00a065a6 222do_hook('addrbook_html_search_below');
223/* End search form */
224
225/* Show personal addressbook */
cc99433e 226
227if ( !empty( $listall ) ){
228 $addrquery = '*';
229}
230
231if ($addrquery == '' && empty($listall)) {
00a065a6 232
233 if (! isset($backend) || $backend != -1 || $addrquery == '') {
234 if ($addrquery == '') {
6e79bfe2 235 $backend = $abook->localbackend;
00a065a6 236 }
14f1b90b 237
00a065a6 238 /* echo '<H3 ALIGN=center>' . $abook->backends[$backend]->sname) . "</H3>\n"; */
14f1b90b 239
00a065a6 240 $res = $abook->list_addr($backend);
14f1b90b 241
00a065a6 242 if (is_array($res)) {
a10110a5 243 usort($res,'alistcmp');
6e79bfe2 244 addr_display_result($res, false);
00a065a6 245 } else {
7b783475 246 echo html_tag( 'p', '<strong><br>' .
00a065a6 247 sprintf(_("Unable to list addresses from %s"),
7b783475 248 $abook->backends[$backend]->sname) . "</strong>\n" ,
249 'center' );
00a065a6 250 }
251
252 } else {
253 $res = $abook->list_addr();
a10110a5 254 usort($res,'alistcmp');
00a065a6 255 addr_display_result($res, true);
256 }
257 exit;
cc99433e 258}
259else {
00a065a6 260
261 /* Do the search */
db48e3f5 262 if (!empty($addrquery)) {
00a065a6 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)) {
7b783475 271 echo html_tag( 'p', '<b><br>' .
272 _("Your search failed with the following error(s)") .
273 ':<br>' . $abook->error . "</b>\n" ,
dcc1cc82 274 'center' ) .
275 "\n</BODY></HTML>\n";
00a065a6 276 } else {
277 if (sizeof($res) == 0) {
7b783475 278 echo html_tag( 'p', '<br><b>' .
62366261 279 _("No persons matching your search were found") . "</b>\n" ,
dcc1cc82 280 'center' ) .
281 "\n</BODY></HTML>\n";
00a065a6 282 } else {
283 addr_display_result($res);
284 }
285 }
286 }
287}
288
289if ($addrquery == '' || sizeof($res) == 0) {
290 /* printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF); */
62366261 291 echo '<center>'.
292 addForm('compose.php','POST','k');
00a065a6 293 addr_insert_hidden();
294 echo '<INPUT TYPE=submit VALUE="' . _("Return") . '" NAME=return>' . "\n" .
295 '</form></center></nobr>';
296}
6e79bfe2 297
dcc1cc82 298?>
299</body></html>