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) {
115 $email = AddressBook
::full_address($row);
116 if ($line %
2) { $tr_bgcolor = $color[0]; }
117 if ($squirrelmail_language == 'ja_JP')
119 echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) .
121 '<input type=checkbox name="send_to_search[T' . $line . ']" value = "' .
122 htmlspecialchars($email) . '"> ' . _("To") . ' ' .
123 '<input type=checkbox name="send_to_search[C' . $line . ']" value = "' .
124 htmlspecialchars($email) . '"> ' . _("Cc") . ' ' .
125 '<input type=checkbox name="send_to_search[B' . $line . ']" value = "' .
126 htmlspecialchars($email) . '"> ' . _("Bcc") . ' ' ,
127 'center', '', 'width="5%" nowrap' ) .
128 html_tag( 'td', ' ' . htmlspecialchars($row['lastname']) . ' ' . htmlspecialchars($row['firstname']) . ' ', 'left', '', 'nowrap' ) .
129 html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'nowrap' ) .
130 html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'nowrap' );
132 echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) .
134 addCheckBox('send_to_search[T'.$line.']', FALSE, $email).
135 ' ' . _("To") . ' ' .
136 addCheckBox('send_to_search[C'.$line.']', FALSE, $email).
137 ' ' . _("Cc") . ' ' .
138 addCheckBox('send_to_search[B'.$line.']', FALSE, $email).
139 ' ' . _("Bcc") . ' ' ,
140 'center', '', 'width="5%" nowrap' ) .
141 html_tag( 'td', ' ' . htmlspecialchars($row['name']) . ' ', 'left', '', 'nowrap' ) .
142 html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'nowrap' ) .
143 html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'nowrap' );
146 if ($includesource) {
147 echo html_tag( 'td', ' ' . $row['source'] . ' ', 'left', '', 'nowrap' );
152 if ($includesource) { $td_colspan = '5'; } else { $td_colspan = '4'; }
155 '<INPUT TYPE=submit NAME="addr_search_done" VALUE="' .
156 _("Use Addresses") . '">' ,
157 'center', '', 'colspan="'. $td_colspan .'"' )
160 addHidden('html_addr_search_done', '1').
164 /* --- End functions --- */
166 if ($compose_new_win == '1') {
167 compose_Header($color, $mailbox);
170 displayPageHeader($color, $mailbox);
172 /* Initialize addressbook */
173 $abook = addressbook_init();
179 html_tag( 'td', '<b>' . _("Address Book Search") . '</b>', 'center', $color[0] )
181 'center', '', 'width="95%" cellpadding="2" cellspacing="2" border="0"' );
186 html_tag( 'table', '', 'center', '', 'border="0"' ) .
188 html_tag( 'td', '', 'left', '', 'nowrap valign="middle"' ) . "\n" .
189 addForm($PHP_SELF.'?html_addr_search=true', 'POST', 'f').
191 ' <nobr><STRONG>' . _("Search for") . "</STRONG>\n";
192 addr_insert_hidden();
193 if (! isset($addrquery))
195 echo addInput('addrquery', $addrquery, 26);
197 /* List all backends to allow the user to choose where to search */
198 if (!isset($backend)) { $backend = ''; }
199 if ($abook->numbackends
> 1) {
200 echo '<STRONG>' . _("in") . '</STRONG> ';
202 $selopts['-1'] = _("All address books");
203 $ret = $abook->get_backend_list();
205 while (list($undef,$v) = each($ret)) {
206 $selopts[$v->bnum
] = $v->sname
;
208 echo addSelect('backend', $selopts, $backend, TRUE);
210 echo addHidden('backend', '-1');
212 if (isset($session)) {
213 echo addHidden('session', $session);
216 echo '<INPUT TYPE=submit VALUE="' . _("Search") . '">' .
217 ' | <INPUT TYPE=submit VALUE="' . _("List all") .
218 '" NAME=listall>' . "\n" .
219 '</FORM></center></TD></TR></TABLE>' . "\n";
220 addr_insert_hidden();
222 do_hook('addrbook_html_search_below');
223 /* End search form */
225 /* Show personal addressbook */
227 if ( !empty( $listall ) ){
231 if ($addrquery == '' && empty($listall)) {
233 if (! isset($backend) ||
$backend != -1 ||
$addrquery == '') {
234 if ($addrquery == '') {
235 $backend = $abook->localbackend
;
238 /* echo '<H3 ALIGN=center>' . $abook->backends[$backend]->sname) . "</H3>\n"; */
240 $res = $abook->list_addr($backend);
242 if (is_array($res)) {
243 usort($res,'alistcmp');
244 addr_display_result($res, false);
246 echo html_tag( 'p', '<strong><br>' .
247 sprintf(_("Unable to list addresses from %s"),
248 $abook->backends
[$backend]->sname
) . "</strong>\n" ,
253 $res = $abook->list_addr();
254 usort($res,'alistcmp');
255 addr_display_result($res, true);
262 if (!empty($addrquery)) {
264 if ($backend == -1) {
265 $res = $abook->s_search($addrquery);
267 $res = $abook->s_search($addrquery, $backend);
270 if (!is_array($res)) {
271 echo html_tag( 'p', '<b><br>' .
272 _("Your search failed with the following error(s)") .
273 ':<br>' . $abook->error
. "</b>\n" ,
275 "\n</BODY></HTML>\n";
277 if (sizeof($res) == 0) {
278 echo html_tag( 'p', '<br><b>' .
279 _("No persons matching your search were found") . "</b>\n" ,
281 "\n</BODY></HTML>\n";
283 addr_display_result($res);
289 if ($addrquery == '' ||
sizeof($res) == 0) {
290 /* printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF); */
292 addForm('compose.php','POST','k');
293 addr_insert_hidden();
294 echo '<INPUT TYPE=submit VALUE="' . _("Return") . '" NAME=return>' . "\n" .
295 '</form></center></nobr>';