4 * addrbook_search_html.php
6 * Copyright (c) 1999-2003 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
16 /* Path for SquirrelMail required files. */
17 if (! defined('SM_PATH') ) {
18 define('SM_PATH','../');
21 /* SquirrelMail required files. */
22 require_once(SM_PATH
. 'include/validate.php');
23 require_once(SM_PATH
. 'functions/global.php');
24 require_once(SM_PATH
. 'functions/date.php');
25 require_once(SM_PATH
. 'functions/display_messages.php');
26 require_once(SM_PATH
. 'functions/addressbook.php');
27 require_once(SM_PATH
. 'functions/plugin.php');
28 require_once(SM_PATH
. 'functions/strings.php');
29 require_once(SM_PATH
. 'functions/html.php');
31 sqgetGlobalVar('session', $session, SQ_POST
);
32 sqgetGlobalVar('mailbox', $mailbox, SQ_POST
);
33 sqgetGlobalVar('addrquery', $addrquery, SQ_POST
);
34 sqgetGlobalVar('listall', $listall, SQ_POST
);
35 sqgetGlobalVar('backend', $backend, SQ_POST
);
37 /* Insert hidden data */
38 function addr_insert_hidden() {
39 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox,
42 echo '<input type=hidden value="';
43 if (substr($body, 0, 1) == "\r") {
46 echo htmlspecialchars($body) . '" name=body>' . "\n" .
47 '<input type=hidden value="' . $session . '" name=session>' . "\n" .
48 '<input type=hidden value="' . htmlspecialchars($subject) .
49 '" name=subject>' . "\n" .
50 '<input type=hidden value="' . htmlspecialchars($send_to) .
51 '" name=send_to>' . "\n" .
52 '<input type=hidden value="' . htmlspecialchars($send_to_cc) .
53 '" name=send_to_cc>' . "\n" .
54 '<input type=hidden value="' . htmlspecialchars($send_to_bcc) .
55 '" name=send_to_bcc>' . "\n" .
56 '<input type=hidden value="' . htmlspecialchars($identity) .
57 '" name=identity>' . "\n" .
58 '<input type=hidden name=mailbox value="' . htmlspecialchars($mailbox) .
59 "\">\n" . '<input type=hidden value="true" name=from_htmladdr_search>' .
64 /* List search results */
65 function addr_display_result($res, $includesource = true) {
66 global $color, $javascript_on, $PHP_SELF;
68 if (sizeof($res) <= 0) return;
70 echo '<form method=post action="' . $PHP_SELF . '" name="addrbook">'."\n" .
71 '<input type=hidden name="html_addr_search_done" value="true">' . "\n";
77 '<script language="JavaScript" type="text/javascript">' .
79 "function CheckAll(ch) {\n" .
80 " for (var i = 0; i < document.addrbook.elements.length; i++) {\n" .
81 " if( document.addrbook.elements[i].type == 'checkbox' &&\n" .
82 " document.addrbook.elements[i].name.substr(0,16) == 'send_to_search['+ch ) {\n" .
83 " document.addrbook.elements[i].checked = !(document.addrbook.elements[i].checked);\n".
89 $chk_all = '<a href="#" onClick="CheckAll(\'T\');">' . _("All") . '</a> <font color="'.$color[9].'">To</font>'.
91 '<a href="#" onClick="CheckAll(\'C\');">' . _("All") . '</a> <font color="'.$color[9].'">Cc</font>'.
93 '<a href="#" onClick="CheckAll(\'B\');">' . _("All") . '</a>';
95 echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) .
96 html_tag( 'tr', '', '', $color[9] ) .
97 html_tag( 'th', ' ' . $chk_all, 'left' ) .
98 html_tag( 'th', ' ' . _("Name"), 'left' ) .
99 html_tag( 'th', ' ' . _("E-mail"), 'left' ) .
100 html_tag( 'th', ' ' . _("Info"), 'left' );
102 if ($includesource) {
103 echo html_tag( 'th', ' ' . _("Source"), 'left', '', 'width="10%"' );
108 foreach ($res as $row) {
110 $email = AddressBook
::full_address($row);
111 if ($line %
2) { $tr_bgcolor = $color[0]; }
112 echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) .
114 '<input type=checkbox name="send_to_search[T' . $line . ']" value = "' .
115 htmlspecialchars($email) . '"> ' . _("To") . ' ' .
116 '<input type=checkbox name="send_to_search[C' . $line . ']" value = "' .
117 htmlspecialchars($email) . '"> ' . _("Cc") . ' ' .
118 '<input type=checkbox name="send_to_search[B' . $line . ']" value = "' .
119 htmlspecialchars($email) . '"> ' . _("Bcc") . ' ' ,
120 'center', '', 'width="5%" nowrap' ) .
121 html_tag( 'td', ' ' . htmlspecialchars($row['name']) . ' ', 'left', '', 'nowrap' ) .
122 html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'nowrap' ) .
123 html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'nowrap' );
125 if ($includesource) {
126 echo html_tag( 'td', ' ' . $row['source'] . ' ', 'left', '', 'nowrap' );
131 if ($includesource) { $td_colspan = '5'; } else { $td_colspan = '4'; }
134 '<INPUT TYPE=submit NAME="addr_search_done" VALUE="' .
135 _("Use Addresses") . '">' ,
136 'center', '', 'colspan="'. $td_colspan .'"' )
139 '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">' .
143 /* --- End functions --- */
145 if ($compose_new_win == '1') {
146 compose_Header($color, $mailbox);
149 displayPageHeader($color, $mailbox);
151 /* Initialize addressbook */
152 $abook = addressbook_init();
158 html_tag( 'td', '<b>' . _("Address Book Search") . '</b>', 'center', $color[0] )
160 'center', '', 'width="95%" cellpadding="2" cellspacing="2" border="0"' );
165 html_tag( 'table', '', 'center', '', 'border="0"' ) .
167 html_tag( 'td', '', 'left', '', 'nowrap valign="middle"' ) . "\n" .
168 '<FORM METHOD=post NAME=f ACTION="' . $PHP_SELF .
169 '?html_addr_search=true">' . "\n<CENTER>\n" .
170 ' <nobr><STRONG>' . _("Search for") . "</STRONG>\n";
171 addr_insert_hidden();
172 if (! isset($addrquery))
174 echo ' <INPUT TYPE=text NAME=addrquery VALUE="' .
175 htmlspecialchars($addrquery) . "\" SIZE=26>\n";
177 /* List all backends to allow the user to choose where to search */
178 if (!isset($backend)) { $backend = ''; }
179 if ($abook->numbackends
> 1) {
180 echo '<STRONG>' . _("in") . '</STRONG> <SELECT NAME=backend>' . "\n" .
182 if ($backend == -1) { echo ' SELECTED'; }
183 echo '>' . _("All address books") . "\n";
184 $ret = $abook->get_backend_list();
185 while (list($undef,$v) = each($ret)) {
186 echo '<OPTION VALUE=' . $v->bnum
;
187 if ($backend == $v->bnum
) { echo ' SELECTED'; }
188 echo '>' . $v->sname
. "\n";
192 echo '<INPUT TYPE=hidden NAME=backend VALUE=-1>' . "\n";
194 if (isset($session)) {
195 echo "<input type=hidden name=\"session\" value=\"$session\">";
198 echo '<INPUT TYPE=submit VALUE="' . _("Search") . '">' .
199 ' | <INPUT TYPE=submit VALUE="' . _("List all") .
200 '" NAME=listall>' . "\n" .
201 '</FORM></center></TD></TR></TABLE>' . "\n";
202 addr_insert_hidden();
204 do_hook('addrbook_html_search_below');
205 /* End search form */
207 /* Show personal addressbook */
209 if ( !empty( $listall ) ){
213 if ($addrquery == '' && empty($listall)) {
215 if (! isset($backend) ||
$backend != -1 ||
$addrquery == '') {
216 if ($addrquery == '') {
217 $backend = $abook->localbackend
;
220 /* echo '<H3 ALIGN=center>' . $abook->backends[$backend]->sname) . "</H3>\n"; */
222 $res = $abook->list_addr($backend);
224 if (is_array($res)) {
225 usort($res,'alistcmp');
226 addr_display_result($res, false);
228 echo html_tag( 'p', '<strong><br>' .
229 sprintf(_("Unable to list addresses from %s"),
230 $abook->backends
[$backend]->sname
) . "</strong>\n" ,
235 $res = $abook->list_addr();
236 usort($res,'alistcmp');
237 addr_display_result($res, true);
244 if (!empty($addrquery)) {
246 if ($backend == -1) {
247 $res = $abook->s_search($addrquery);
249 $res = $abook->s_search($addrquery, $backend);
252 if (!is_array($res)) {
253 echo html_tag( 'p', '<b><br>' .
254 _("Your search failed with the following error(s)") .
255 ':<br>' . $abook->error
. "</b>\n" ,
257 "\n</BODY></HTML>\n";
259 if (sizeof($res) == 0) {
260 echo html_tag( 'p', '<br><b>' .
261 _("No persons matching your search was found") . "</b>\n" ,
263 "\n</BODY></HTML>\n";
265 addr_display_result($res);
271 if ($addrquery == '' ||
sizeof($res) == 0) {
272 /* printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF); */
273 echo '<center><FORM METHOD=post NAME=k ACTION="compose.php">' . "\n";
274 addr_insert_hidden();
275 echo '<INPUT TYPE=submit VALUE="' . _("Return") . '" NAME=return>' . "\n" .
276 '</form></center></nobr>';