4 * addrbook_search_html.php
6 * Copyright (c) 1999-2005 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
15 * @subpackage addressbook
19 * Path for SquirrelMail required files.
22 if (! defined('SM_PATH') ) {
23 define('SM_PATH','../');
26 /** SquirrelMail required files. */
27 require_once(SM_PATH
. 'include/validate.php');
28 require_once(SM_PATH
. 'functions/global.php');
29 require_once(SM_PATH
. 'functions/date.php');
30 require_once(SM_PATH
. 'functions/display_messages.php');
31 require_once(SM_PATH
. 'functions/addressbook.php');
32 require_once(SM_PATH
. 'functions/plugin.php');
33 require_once(SM_PATH
. 'functions/strings.php');
34 require_once(SM_PATH
. 'functions/html.php');
36 sqgetGlobalVar('session', $session, SQ_POST
);
37 sqgetGlobalVar('mailbox', $mailbox, SQ_POST
);
38 sqgetGlobalVar('addrquery', $addrquery, SQ_POST
);
39 sqgetGlobalVar('listall', $listall, SQ_POST
);
40 sqgetGlobalVar('backend', $backend, SQ_POST
);
45 function addr_insert_hidden() {
46 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox,
49 if (substr($body, 0, 1) == "\r") {
50 echo addHidden('body', "\n".$body);
52 echo addHidden('body', $body);
55 echo addHidden('session', $session).
56 addHidden('subject', $subject).
57 addHidden('send_to', $send_to).
58 addHidden('send_to_bcc', $send_to_bcc).
59 addHidden('send_to_cc', $send_to_cc).
60 addHidden('identity', $identity).
61 addHidden('mailbox', $mailbox).
62 addHidden('from_htmladdr_search', 'true');
68 * @param array $res Array containing results of search
69 * @param bool $includesource UNDOCUMENTED [Default=true]
71 function addr_display_result($res, $includesource = true) {
72 global $color, $javascript_on, $PHP_SELF, $squirrelmail_language;
74 if (sizeof($res) <= 0) return;
76 echo addForm($PHP_SELF, 'post', 'addrbook').
77 addHidden('html_addr_search_done', 'true');
83 '<script language="JavaScript" type="text/javascript">' .
85 "function CheckAll(ch) {\n" .
86 " for (var i = 0; i < document.addrbook.elements.length; i++) {\n" .
87 " if( document.addrbook.elements[i].type == 'checkbox' &&\n" .
88 " document.addrbook.elements[i].name.substr(0,16) == 'send_to_search['+ch ) {\n" .
89 " document.addrbook.elements[i].checked = !(document.addrbook.elements[i].checked);\n".
95 $chk_all = '<a href="#" onclick="CheckAll(\'T\');">' . _("All") . '</a> <font color="'.$color[9].'">'._("To").'</font>'.
97 '<a href="#" onclick="CheckAll(\'C\');">' . _("All") . '</a> <font color="'.$color[9].'">'._("Cc").'</font>'.
99 '<a href="#" onclick="CheckAll(\'B\');">' . _("All") . '</a>';
101 echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) .
102 html_tag( 'tr', '', '', $color[9] ) .
103 html_tag( 'th', ' ' . $chk_all, 'left' ) .
104 html_tag( 'th', ' ' . _("Name"), 'left' ) .
105 html_tag( 'th', ' ' . _("E-mail"), 'left' ) .
106 html_tag( 'th', ' ' . _("Info"), 'left' );
108 if ($includesource) {
109 echo html_tag( 'th', ' ' . _("Source"), 'left', '', 'width="10%"' );
114 foreach ($res as $row) {
115 $email = AddressBook
::full_address($row);
117 $tr_bgcolor = $color[12];
119 $tr_bgcolor = $color[4];
121 if ($squirrelmail_language == 'ja_JP')
123 echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) .
125 '<input type="checkbox" name="send_to_search[T' . $line . ']" value = "' .
126 htmlspecialchars($email) . '" /> ' . _("To") . ' ' .
127 '<input type="checkbox" name="send_to_search[C' . $line . ']" value = "' .
128 htmlspecialchars($email) . '" /> ' . _("Cc") . ' ' .
129 '<input type="checkbox" name="send_to_search[B' . $line . ']" value = "' .
130 htmlspecialchars($email) . '" /> ' . _("Bcc") . ' ' ,
131 'center', '', 'width="5%" style="white-space: nowrap;"' ) .
132 html_tag( 'td', ' ' . htmlspecialchars($row['lastname']) . ' ' . htmlspecialchars($row['firstname']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) .
133 html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) .
134 html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'style="white-space: nowrap;"' );
136 echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) .
138 addCheckBox('send_to_search[T'.$line.']', FALSE, $email).
139 ' ' . _("To") . ' ' .
140 addCheckBox('send_to_search[C'.$line.']', FALSE, $email).
141 ' ' . _("Cc") . ' ' .
142 addCheckBox('send_to_search[B'.$line.']', FALSE, $email).
143 ' ' . _("Bcc") . ' ' ,
144 'center', '', 'width="5%" style="white-space: nowrap;"' ) .
145 html_tag( 'td', ' ' . htmlspecialchars($row['name']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) .
146 html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) .
147 html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'style="white-space: nowrap;"' );
150 if ($includesource) {
151 echo html_tag( 'td', ' ' . $row['source'] . ' ', 'left', '', 'style="white-space: nowrap;"' );
156 if ($includesource) { $td_colspan = '5'; } else { $td_colspan = '4'; }
159 '<input type="submit" name="addr_search_done" value="' .
160 _("Use Addresses") . '" /> ' .
161 '<input type="submit" name="addr_search_cancel" value="' .
162 _("Cancel") . '" />',
163 'center', '', 'colspan="'. $td_colspan .'"' )
166 addHidden('html_addr_search_done', '1').
170 /* --- End functions --- */
172 if ($compose_new_win == '1') {
173 compose_Header($color, $mailbox);
176 displayPageHeader($color, $mailbox);
179 /** set correct value of $default_charset */
180 global $default_charset;
183 /* Initialize addressbook */
184 $abook = addressbook_init();
190 html_tag( 'td', '<b>' . _("Address Book Search") . '</b>', 'center', $color[0] )
192 'center', '', 'width="95%" cellpadding="2" cellspacing="2" border="0"' );
197 html_tag( 'table', '', 'center', '', 'border="0"' ) .
199 html_tag( 'td', '', 'left', '', 'style="white-space: nowrap;" valign="middle"' ) . "\n" .
200 addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f').
202 ' <nobr><strong>' . _("Search for") . "</strong>\n";
203 addr_insert_hidden();
204 if (! isset($addrquery))
206 echo addInput('addrquery', $addrquery, 26);
208 /* List all backends to allow the user to choose where to search */
209 if (!isset($backend)) { $backend = ''; }
210 if ($abook->numbackends
> 1) {
211 echo '<strong>' . _("in") . '</strong> ';
213 $selopts['-1'] = _("All address books");
214 $ret = $abook->get_backend_list();
216 while (list($undef,$v) = each($ret)) {
217 $selopts[$v->bnum
] = $v->sname
;
219 echo addSelect('backend', $selopts, $backend, TRUE);
221 echo addHidden('backend', '-1');
223 if (isset($session)) {
224 echo addHidden('session', $session);
227 echo '<input type="submit" value="' . _("Search") . '" />' .
228 ' | <input type="submit" value="' . _("List all") .
229 '" name="listall" />' . "\n" .
230 '</form></center></td></tr></table>' . "\n";
231 addr_insert_hidden();
233 do_hook('addrbook_html_search_below');
234 /* End search form */
236 /* Show personal addressbook */
238 if ( !empty( $listall ) ){
242 if ($addrquery == '' && empty($listall)) {
244 if (! isset($backend) ||
$backend != -1 ||
$addrquery == '') {
245 if ($addrquery == '') {
246 $backend = $abook->localbackend
;
249 /* echo '<h3 align="center">' . $abook->backends[$backend]->sname) . "</h3>\n"; */
251 $res = $abook->list_addr($backend);
253 if (is_array($res)) {
254 usort($res,'alistcmp');
255 addr_display_result($res, false);
257 echo html_tag( 'p', '<strong><br />' .
258 sprintf(_("Unable to list addresses from %s"),
259 $abook->backends
[$backend]->sname
) . "</strong>\n" ,
264 $res = $abook->list_addr();
265 usort($res,'alistcmp');
266 addr_display_result($res, true);
273 if (!empty($addrquery)) {
275 if ($backend == -1) {
276 $res = $abook->s_search($addrquery);
278 $res = $abook->s_search($addrquery, $backend);
281 if (!is_array($res)) {
282 echo html_tag( 'p', '<b><br />' .
283 _("Your search failed with the following error(s)") .
284 ':<br />' . $abook->error
. "</b>\n" ,
286 "\n</body></html>\n";
288 if (sizeof($res) == 0) {
289 echo html_tag( 'p', '<br /><b>' .
290 _("No persons matching your search were found") . "</b>\n" ,
292 "\n</body></html>\n";
294 addr_display_result($res);
300 if ($addrquery == '' ||
sizeof($res) == 0) {
301 /* printf('<center><form method="post" name="k" action="compose.php">'."\n", $PHP_SELF); */
303 addForm('compose.php','post','k');
304 addr_insert_hidden();
305 echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" .
306 '</form></center></nobr>';