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
17 /** Path for SquirrelMail required files. */
18 if (! defined('SM_PATH') ) {
19 define('SM_PATH','../');
22 /** SquirrelMail required files. */
23 require_once(SM_PATH
. 'include/validate.php');
24 require_once(SM_PATH
. 'functions/global.php');
25 require_once(SM_PATH
. 'functions/date.php');
26 require_once(SM_PATH
. 'functions/display_messages.php');
27 require_once(SM_PATH
. 'functions/addressbook.php');
28 require_once(SM_PATH
. 'functions/plugin.php');
29 require_once(SM_PATH
. 'functions/strings.php');
30 require_once(SM_PATH
. 'functions/html.php');
32 sqgetGlobalVar('session', $session, SQ_POST
);
33 sqgetGlobalVar('mailbox', $mailbox, SQ_POST
);
34 sqgetGlobalVar('addrquery', $addrquery, SQ_POST
);
35 sqgetGlobalVar('listall', $listall, SQ_POST
);
36 sqgetGlobalVar('backend', $backend, SQ_POST
);
41 function addr_insert_hidden() {
42 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox,
45 if (substr($body, 0, 1) == "\r") {
46 echo addHidden('body', "\n".$body);
48 echo addHidden('body', $body);
51 echo addHidden('session', $session).
52 addHidden('subject', $subject).
53 addHidden('send_to', $send_to).
54 addHidden('send_to_bcc', $send_to_bcc).
55 addHidden('send_to_cc', $send_to_cc).
56 addHidden('identity', $identity).
57 addHidden('mailbox', $mailbox).
58 addHidden('from_htmladdr_search', 'true');
64 * @param array $res Array containing results of search
65 * @param bool $includesource UNDOCUMENTED [Default=true]
67 function addr_display_result($res, $includesource = true) {
68 global $color, $javascript_on, $PHP_SELF, $squirrelmail_language;
70 if (sizeof($res) <= 0) return;
72 echo addForm($PHP_SELF, 'POST', 'addrbook').
73 addHidden('html_addr_search_done', 'true');
79 '<script language="JavaScript" type="text/javascript">' .
81 "function CheckAll(ch) {\n" .
82 " for (var i = 0; i < document.addrbook.elements.length; i++) {\n" .
83 " if( document.addrbook.elements[i].type == 'checkbox' &&\n" .
84 " document.addrbook.elements[i].name.substr(0,16) == 'send_to_search['+ch ) {\n" .
85 " document.addrbook.elements[i].checked = !(document.addrbook.elements[i].checked);\n".
91 $chk_all = '<a href="#" onClick="CheckAll(\'T\');">' . _("All") . '</a> <font color="'.$color[9].'">To</font>'.
93 '<a href="#" onClick="CheckAll(\'C\');">' . _("All") . '</a> <font color="'.$color[9].'">Cc</font>'.
95 '<a href="#" onClick="CheckAll(\'B\');">' . _("All") . '</a>';
97 echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) .
98 html_tag( 'tr', '', '', $color[9] ) .
99 html_tag( 'th', ' ' . $chk_all, 'left' ) .
100 html_tag( 'th', ' ' . _("Name"), 'left' ) .
101 html_tag( 'th', ' ' . _("E-mail"), 'left' ) .
102 html_tag( 'th', ' ' . _("Info"), 'left' );
104 if ($includesource) {
105 echo html_tag( 'th', ' ' . _("Source"), 'left', '', 'width="10%"' );
110 foreach ($res as $row) {
112 $email = AddressBook
::full_address($row);
113 if ($line %
2) { $tr_bgcolor = $color[0]; }
114 if ($squirrelmail_language == 'ja_JP')
116 echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) .
118 '<input type=checkbox name="send_to_search[T' . $line . ']" value = "' .
119 htmlspecialchars($email) . '"> ' . _("To") . ' ' .
120 '<input type=checkbox name="send_to_search[C' . $line . ']" value = "' .
121 htmlspecialchars($email) . '"> ' . _("Cc") . ' ' .
122 '<input type=checkbox name="send_to_search[B' . $line . ']" value = "' .
123 htmlspecialchars($email) . '"> ' . _("Bcc") . ' ' ,
124 'center', '', 'width="5%" nowrap' ) .
125 html_tag( 'td', ' ' . htmlspecialchars($row['lastname']) . ' ' . htmlspecialchars($row['firstname']) . ' ', 'left', '', 'nowrap' ) .
126 html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'nowrap' ) .
127 html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'nowrap' );
129 echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) .
131 addCheckBox('send_to_search[T'.$line.']', FALSE, $email).
132 ' ' . _("To") . ' ' .
133 addCheckBox('send_to_search[C'.$line.']', FALSE, $email).
134 ' ' . _("Cc") . ' ' .
135 addCheckBox('send_to_search[B'.$line.']', FALSE, $email).
136 ' ' . _("Bcc") . ' ' ,
137 'center', '', 'width="5%" nowrap' ) .
138 html_tag( 'td', ' ' . htmlspecialchars($row['name']) . ' ', 'left', '', 'nowrap' ) .
139 html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'nowrap' ) .
140 html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'nowrap' );
143 if ($includesource) {
144 echo html_tag( 'td', ' ' . $row['source'] . ' ', 'left', '', 'nowrap' );
149 if ($includesource) { $td_colspan = '5'; } else { $td_colspan = '4'; }
152 '<INPUT TYPE=submit NAME="addr_search_done" VALUE="' .
153 _("Use Addresses") . '">' ,
154 'center', '', 'colspan="'. $td_colspan .'"' )
157 addHidden('html_addr_search_done', '1').
161 /* --- End functions --- */
163 if ($compose_new_win == '1') {
164 compose_Header($color, $mailbox);
167 displayPageHeader($color, $mailbox);
169 /* Initialize addressbook */
170 $abook = addressbook_init();
176 html_tag( 'td', '<b>' . _("Address Book Search") . '</b>', 'center', $color[0] )
178 'center', '', 'width="95%" cellpadding="2" cellspacing="2" border="0"' );
183 html_tag( 'table', '', 'center', '', 'border="0"' ) .
185 html_tag( 'td', '', 'left', '', 'nowrap valign="middle"' ) . "\n" .
186 addForm($PHP_SELF.'?html_addr_search=true', 'POST', 'f').
188 ' <nobr><STRONG>' . _("Search for") . "</STRONG>\n";
189 addr_insert_hidden();
190 if (! isset($addrquery))
192 echo addInput('addrquery', $addrquery, 26);
194 /* List all backends to allow the user to choose where to search */
195 if (!isset($backend)) { $backend = ''; }
196 if ($abook->numbackends
> 1) {
197 echo '<STRONG>' . _("in") . '</STRONG> ';
199 $selopts['-1'] = _("All address books");
200 $ret = $abook->get_backend_list();
202 while (list($undef,$v) = each($ret)) {
203 $selopts[$v->bnum
] = $v->sname
;
205 echo addSelect('backend', $selopts, $backend, TRUE);
207 echo addHidden('backend', '-1');
209 if (isset($session)) {
210 echo addHidden('session', $session);
213 echo '<INPUT TYPE=submit VALUE="' . _("Search") . '">' .
214 ' | <INPUT TYPE=submit VALUE="' . _("List all") .
215 '" NAME=listall>' . "\n" .
216 '</FORM></center></TD></TR></TABLE>' . "\n";
217 addr_insert_hidden();
219 do_hook('addrbook_html_search_below');
220 /* End search form */
222 /* Show personal addressbook */
224 if ( !empty( $listall ) ){
228 if ($addrquery == '' && empty($listall)) {
230 if (! isset($backend) ||
$backend != -1 ||
$addrquery == '') {
231 if ($addrquery == '') {
232 $backend = $abook->localbackend
;
235 /* echo '<H3 ALIGN=center>' . $abook->backends[$backend]->sname) . "</H3>\n"; */
237 $res = $abook->list_addr($backend);
239 if (is_array($res)) {
240 usort($res,'alistcmp');
241 addr_display_result($res, false);
243 echo html_tag( 'p', '<strong><br>' .
244 sprintf(_("Unable to list addresses from %s"),
245 $abook->backends
[$backend]->sname
) . "</strong>\n" ,
250 $res = $abook->list_addr();
251 usort($res,'alistcmp');
252 addr_display_result($res, true);
259 if (!empty($addrquery)) {
261 if ($backend == -1) {
262 $res = $abook->s_search($addrquery);
264 $res = $abook->s_search($addrquery, $backend);
267 if (!is_array($res)) {
268 echo html_tag( 'p', '<b><br>' .
269 _("Your search failed with the following error(s)") .
270 ':<br>' . $abook->error
. "</b>\n" ,
272 "\n</BODY></HTML>\n";
274 if (sizeof($res) == 0) {
275 echo html_tag( 'p', '<br><b>' .
276 _("No persons matching your search were found") . "</b>\n" ,
278 "\n</BODY></HTML>\n";
280 addr_display_result($res);
286 if ($addrquery == '' ||
sizeof($res) == 0) {
287 /* printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF); */
289 addForm('compose.php','POST','k');
290 addr_insert_hidden();
291 echo '<INPUT TYPE=submit VALUE="' . _("Return") . '" NAME=return>' . "\n" .
292 '</form></center></nobr>';