54de9f8ff27c002704a2beb7c7e6e63ce4b83ae1
4 * addrbook_search_html.php
6 * Copyright (c) 1999-2002 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
13 * NOTE: A lot of this code is similar to the code in
14 * addrbook_search.html -- If you change one, change
20 require_once('../src/validate.php');
21 require_once('../functions/date.php');
22 require_once('../functions/smtp.php');
23 require_once('../functions/display_messages.php');
24 require_once('../functions/addressbook.php');
25 require_once('../functions/plugin.php');
26 require_once('../functions/strings.php');
27 require_once('../functions/html.php');
29 /* Insert hidden data */
30 function addr_insert_hidden() {
31 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox,
34 echo '<input type=hidden value="';
35 if (substr($body, 0, 1) == "\r") {
38 echo htmlspecialchars($body) . '" name=body>' . "\n" .
39 '<input type=hidden value="' . $session . '" name=session>' . "\n" .
40 '<input type=hidden value="' . htmlspecialchars($subject) .
41 '" name=subject>' . "\n" .
42 '<input type=hidden value="' . htmlspecialchars($send_to) .
43 '" name=send_to>' . "\n" .
44 '<input type=hidden value="' . htmlspecialchars($send_to_cc) .
45 '" name=send_to_cc>' . "\n" .
46 '<input type=hidden value="' . htmlspecialchars($send_to_bcc) .
47 '" name=send_to_bcc>' . "\n" .
48 '<input type=hidden value="' . htmlspecialchars($identity) .
49 '" name=identity>' . "\n" .
50 '<input type=hidden name=mailbox value="' . htmlspecialchars($mailbox) .
51 "\">\n" . '<input type=hidden value="true" name=from_htmladdr_search>' .
56 /* List search results */
57 function addr_display_result($res, $includesource = true) {
58 global $color, $javascript_on, $PHP_SELF;
60 if (sizeof($res) <= 0) return;
62 echo '<form method=post action="' . $PHP_SELF . '" name="addrbook">'."\n" .
63 '<input type=hidden name="html_addr_search_done" value="true">' . "\n";
69 '<script language="JavaScript" type="text/javascript">' .
71 "function CheckAll(ch) {\n" .
72 " for (var i = 0; i < document.addrbook.elements.length; i++) {\n" .
73 " if( document.addrbook.elements[i].type == 'checkbox' &&\n" .
74 " document.addrbook.elements[i].name.substr(0,16) == 'send_to_search['+ch ) {\n" .
75 " document.addrbook.elements[i].checked = !(document.addrbook.elements[i].checked);\n".
81 $chk_all = '<a href="#" onClick="CheckAll(\'T\');">' . _("All") . '</a> <font color="'.$color[9].'">To</font>'.
83 '<a href="#" onClick="CheckAll(\'C\');">' . _("All") . '</a> <font color="'.$color[9].'">Cc</font>'.
85 '<a href="#" onClick="CheckAll(\'B\');">' . _("All") . '</a>';
87 echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) .
88 html_tag( 'tr', '', '', $color[9] ) .
89 html_tag( 'th', ' ' . $chk_all, 'left' ) .
90 html_tag( 'th', ' ' . _("Name"), 'left' ) .
91 html_tag( 'th', ' ' . _("E-mail"), 'left' ) .
92 html_tag( 'th', ' ' . _("Info"), 'left' );
95 echo html_tag( 'th', ' ' . _("Source"), 'left', '', 'width="10%"' );
100 foreach ($res as $row) {
102 $email = AddressBook
::full_address($row);
103 if ($line %
2) { $tr_bgcolor = $color[0]; }
104 echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) .
106 '<input type=checkbox name="send_to_search[T' . $line . ']" value = "' .
107 htmlspecialchars($email) . '"> ' . _("To") . ' ' .
108 '<input type=checkbox name="send_to_search[C' . $line . ']" value = "' .
109 htmlspecialchars($email) . '"> ' . _("Cc") . ' ' .
110 '<input type=checkbox name="send_to_search[B' . $line . ']" value = "' .
111 htmlspecialchars($email) . '"> ' . _("Bcc") . ' ' ,
112 'center', '', 'width="5%" nowrap' ) .
113 html_tag( 'td', ' ' . htmlspecialchars($row['name']) . ' ', 'left', '', 'nowrap' ) .
114 html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'nowrap' ) .
115 html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'nowrap' );
117 if ($includesource) {
118 echo html_tag( 'td', ' ' . $row['source'] . ' ', 'left', '', 'nowrap' );
123 if ($includesource) { $td_colspan = '5'; } else { $td_colspan = '4'; }
126 '<INPUT TYPE=submit NAME="addr_search_done" VALUE="' .
127 _("Use Addresses") . '">' ,
128 'center', '', 'colspan="'. $td_colspan .'"' )
131 '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">' .
135 /* --- End functions --- */
138 if ($compose_new_win == '1') {
139 compose_Header($color, $mailbox);
142 displayPageHeader($color, $mailbox);
144 /* Initialize addressbook */
145 $abook = addressbook_init();
151 html_tag( 'td', '<b>' . _("Address Book Search") . '</b>', 'center', $color[0] )
153 'center', '', 'width="95%" cellpadding="2" cellspacing="2" border="0"' );
158 html_tag( 'table', '', 'center', '', 'border="0"' ) .
160 html_tag( 'td', '', 'left', '', 'nowrap valign="middle"' ) . "\n" .
161 '<FORM METHOD=post NAME=f ACTION="' . $PHP_SELF .
162 '?html_addr_search=true">' . "\n<CENTER>\n" .
163 ' <nobr><STRONG>' . _("Search for") . "</STRONG>\n";
164 addr_insert_hidden();
165 if (! isset($addrquery))
167 echo ' <INPUT TYPE=text NAME=addrquery VALUE="' .
168 htmlspecialchars($addrquery) . "\" SIZE=26>\n";
170 /* List all backends to allow the user to choose where to search */
171 if (!isset($backend)) { $backend = ''; }
172 if ($abook->numbackends
> 1) {
173 echo '<STRONG>' . _("in") . '</STRONG> <SELECT NAME=backend>' . "\n" .
175 if ($backend == -1) { echo ' SELECTED'; }
176 echo '>' . _("All address books") . "\n";
177 $ret = $abook->get_backend_list();
178 while (list($undef,$v) = each($ret)) {
179 echo '<OPTION VALUE=' . $v->bnum
;
180 if ($backend == $v->bnum
) { echo ' SELECTED'; }
181 echo '>' . $v->sname
. "\n";
185 echo '<INPUT TYPE=hidden NAME=backend VALUE=-1>' . "\n";
187 if (isset($session)) {
188 echo "<input type=hidden name=\"session\" value=\"$session\">";
191 echo '<INPUT TYPE=submit VALUE="' . _("Search") . '">' .
192 ' | <INPUT TYPE=submit VALUE="' . _("List all") .
193 '" NAME=listall>' . "\n" .
194 '</FORM></center></TD></TR></TABLE>' . "\n";
195 addr_insert_hidden();
197 do_hook('addrbook_html_search_below');
198 /* End search form */
200 /* Show personal addressbook */
202 if ( !empty( $listall ) ){
206 if ($addrquery == '' && empty($listall)) {
208 if (! isset($backend) ||
$backend != -1 ||
$addrquery == '') {
209 if ($addrquery == '') {
210 $backend = $abook->localbackend
;
213 /* echo '<H3 ALIGN=center>' . $abook->backends[$backend]->sname) . "</H3>\n"; */
215 $res = $abook->list_addr($backend);
217 if (is_array($res)) {
218 usort($res,'alistcmp');
219 addr_display_result($res, false);
221 echo html_tag( 'p', '<strong><br>' .
222 sprintf(_("Unable to list addresses from %s"),
223 $abook->backends
[$backend]->sname
) . "</strong>\n" ,
228 $res = $abook->list_addr();
229 usort($res,'alistcmp');
230 addr_display_result($res, true);
237 if (!empty($addrquery)) {
239 if ($backend == -1) {
240 $res = $abook->s_search($addrquery);
242 $res = $abook->s_search($addrquery, $backend);
245 if (!is_array($res)) {
246 echo html_tag( 'p', '<b><br>' .
247 _("Your search failed with the following error(s)") .
248 ':<br>' . $abook->error
. "</b>\n" ,
250 "\n</BODY></HTML>\n";
252 if (sizeof($res) == 0) {
253 echo html_tag( 'p', '<br><b>' .
254 _("No persons matching your search was found") . "</b>\n" ,
256 "\n</BODY></HTML>\n";
258 addr_display_result($res);
264 if ($addrquery == '' ||
sizeof($res) == 0) {
265 /* printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF); */
266 echo '<center><FORM METHOD=post NAME=k ACTION="compose.php">' . "\n";
267 addr_insert_hidden();
268 echo '<INPUT TYPE=submit VALUE="' . _("Return") . '" NAME=return>' . "\n" .
269 '</form></center></nobr>';