4 * addrbook_search_html.php
6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * Handle addressbook searching with pure html.
11 * This file is included from compose.php
14 * @package squirrelmail
18 * Path for SquirrelMail required files.
21 if (! defined('SM_PATH') ) {
22 define('SM_PATH','../');
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');
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
);
44 function addr_insert_hidden() {
45 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox,
48 if (substr($body, 0, 1) == "\r") {
49 echo addHidden('body', "\n".$body);
51 echo addHidden('body', $body);
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');
67 * @param array $res Array containing results of search
68 * @param bool $includesource UNDOCUMENTED [Default=true]
70 function addr_display_result($res, $includesource = true) {
71 global $color, $javascript_on, $PHP_SELF, $squirrelmail_language;
73 if (sizeof($res) <= 0) return;
75 echo addForm($PHP_SELF, 'POST', 'addrbook').
76 addHidden('html_addr_search_done', 'true');
82 '<script language="JavaScript" type="text/javascript">' .
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".
94 $chk_all = '<a href="#" onClick="CheckAll(\'T\');">' . _("All") . '</a> <font color="'.$color[9].'">'._("To").'</font>'.
96 '<a href="#" onClick="CheckAll(\'C\');">' . _("All") . '</a> <font color="'.$color[9].'">'._("Cc").'</font>'.
98 '<a href="#" onClick="CheckAll(\'B\');">' . _("All") . '</a>';
100 echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) .
101 html_tag( 'tr', '', '', $color[9] ) .
102 html_tag( 'th', ' ' . $chk_all, 'left' ) .
103 html_tag( 'th', ' ' . _("Name"), 'left' ) .
104 html_tag( 'th', ' ' . _("E-mail"), 'left' ) .
105 html_tag( 'th', ' ' . _("Info"), 'left' );
107 if ($includesource) {
108 echo html_tag( 'th', ' ' . _("Source"), 'left', '', 'width="10%"' );
113 foreach ($res as $row) {
114 $email = AddressBook
::full_address($row);
116 $tr_bgcolor = $color[12];
118 $tr_bgcolor = $color[4];
120 if ($squirrelmail_language == 'ja_JP')
122 echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) .
124 '<input type="checkbox" name="send_to_search[T' . $line . ']" value = "' .
125 htmlspecialchars($email) . '" /> ' . _("To") . ' ' .
126 '<input type="checkbox" name="send_to_search[C' . $line . ']" value = "' .
127 htmlspecialchars($email) . '" /> ' . _("Cc") . ' ' .
128 '<input type="checkbox" name="send_to_search[B' . $line . ']" value = "' .
129 htmlspecialchars($email) . '" /> ' . _("Bcc") . ' ' ,
130 'center', '', 'width="5%" nowrap' ) .
131 html_tag( 'td', ' ' . htmlspecialchars($row['lastname']) . ' ' . htmlspecialchars($row['firstname']) . ' ', 'left', '', 'nowrap' ) .
132 html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'nowrap' ) .
133 html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'nowrap' );
135 echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) .
137 addCheckBox('send_to_search[T'.$line.']', FALSE, $email).
138 ' ' . _("To") . ' ' .
139 addCheckBox('send_to_search[C'.$line.']', FALSE, $email).
140 ' ' . _("Cc") . ' ' .
141 addCheckBox('send_to_search[B'.$line.']', FALSE, $email).
142 ' ' . _("Bcc") . ' ' ,
143 'center', '', 'width="5%" nowrap' ) .
144 html_tag( 'td', ' ' . htmlspecialchars($row['name']) . ' ', 'left', '', 'nowrap' ) .
145 html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'nowrap' ) .
146 html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'nowrap' );
149 if ($includesource) {
150 echo html_tag( 'td', ' ' . $row['source'] . ' ', 'left', '', 'nowrap' );
155 if ($includesource) { $td_colspan = '5'; } else { $td_colspan = '4'; }
158 '<input type="submit" name="addr_search_done" value="' .
159 _("Use Addresses") . '" />' ,
160 'center', '', 'colspan="'. $td_colspan .'"' )
163 addHidden('html_addr_search_done', '1').
167 /* --- End functions --- */
169 if ($compose_new_win == '1') {
170 compose_Header($color, $mailbox);
173 displayPageHeader($color, $mailbox);
175 /* Initialize addressbook */
176 $abook = addressbook_init();
182 html_tag( 'td', '<b>' . _("Address Book Search") . '</b>', 'center', $color[0] )
184 'center', '', 'width="95%" cellpadding="2" cellspacing="2" border="0"' );
189 html_tag( 'table', '', 'center', '', 'border="0"' ) .
191 html_tag( 'td', '', 'left', '', 'nowrap valign="middle"' ) . "\n" .
192 addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f').
194 ' <nobr><strong>' . _("Search for") . "</strong>\n";
195 addr_insert_hidden();
196 if (! isset($addrquery))
198 echo addInput('addrquery', $addrquery, 26);
200 /* List all backends to allow the user to choose where to search */
201 if (!isset($backend)) { $backend = ''; }
202 if ($abook->numbackends
> 1) {
203 echo '<strong>' . _("in") . '</strong> ';
205 $selopts['-1'] = _("All address books");
206 $ret = $abook->get_backend_list();
208 while (list($undef,$v) = each($ret)) {
209 $selopts[$v->bnum
] = $v->sname
;
211 echo addSelect('backend', $selopts, $backend, TRUE);
213 echo addHidden('backend', '-1');
215 if (isset($session)) {
216 echo addHidden('session', $session);
219 echo '<input type="submit" value="' . _("Search") . '" />' .
220 ' | <input type="submit" value="' . _("List all") .
221 '" name="listall" />' . "\n" .
222 '</form></center></td></tr></table>' . "\n";
223 addr_insert_hidden();
225 do_hook('addrbook_html_search_below');
226 /* End search form */
228 /* Show personal addressbook */
230 if ( !empty( $listall ) ){
234 if ($addrquery == '' && empty($listall)) {
236 if (! isset($backend) ||
$backend != -1 ||
$addrquery == '') {
237 if ($addrquery == '') {
238 $backend = $abook->localbackend
;
241 /* echo '<h3 align="center">' . $abook->backends[$backend]->sname) . "</h3>\n"; */
243 $res = $abook->list_addr($backend);
245 if (is_array($res)) {
246 usort($res,'alistcmp');
247 addr_display_result($res, false);
249 echo html_tag( 'p', '<strong><br />' .
250 sprintf(_("Unable to list addresses from %s"),
251 $abook->backends
[$backend]->sname
) . "</strong>\n" ,
256 $res = $abook->list_addr();
257 usort($res,'alistcmp');
258 addr_display_result($res, true);
265 if (!empty($addrquery)) {
267 if ($backend == -1) {
268 $res = $abook->s_search($addrquery);
270 $res = $abook->s_search($addrquery, $backend);
273 if (!is_array($res)) {
274 echo html_tag( 'p', '<b><br />' .
275 _("Your search failed with the following error(s)") .
276 ':<br />' . $abook->error
. "</b>\n" ,
278 "\n</body></html>\n";
280 if (sizeof($res) == 0) {
281 echo html_tag( 'p', '<br /><b>' .
282 _("No persons matching your search were found") . "</b>\n" ,
284 "\n</body></html>\n";
286 addr_display_result($res);
292 if ($addrquery == '' ||
sizeof($res) == 0) {
293 /* printf('<center><form method="post" name="k" action="compose.php">'."\n", $PHP_SELF); */
295 addForm('compose.php','POST','k');
296 addr_insert_hidden();
297 echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" .
298 '</form></center></nobr>';