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');
28 /* Insert hidden data */
29 function addr_insert_hidden() {
30 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox,
33 echo '<input type=hidden value="';
34 if (substr($body, 0, 1) == "\r") {
37 echo htmlspecialchars($body) . '" name=body>' . "\n" .
38 '<input type=hidden value="' . $session . '" name=session>' . "\n" .
39 '<input type=hidden value="' . htmlspecialchars($subject) .
40 '" name=subject>' . "\n" .
41 '<input type=hidden value="' . htmlspecialchars($send_to) .
42 '" name=send_to>' . "\n" .
43 '<input type=hidden value="' . htmlspecialchars($send_to_cc) .
44 '" name=send_to_cc>' . "\n" .
45 '<input type=hidden value="' . htmlspecialchars($send_to_bcc) .
46 '" name=send_to_bcc>' . "\n" .
47 '<input type=hidden value="' . htmlspecialchars($identity) .
48 '" name=identity>' . "\n" .
49 '<input type=hidden name=mailbox value="' . htmlspecialchars($mailbox) .
50 "\">\n" . '<input type=hidden value="true" name=from_htmladdr_search>' .
55 /* List search results */
56 function addr_display_result($res, $includesource = true) {
57 global $color, $javascript_on, $PHP_SELF;
59 if (sizeof($res) <= 0) return;
61 echo '<form method=post action="' . $PHP_SELF . '" name="addrbook">'."\n" .
62 '<input type=hidden name="html_addr_search_done" value="true">' . "\n";
68 '<script language="JavaScript" type="text/javascript">' .
70 "function CheckAll(ch) {\n" .
71 " for (var i = 0; i < document.addrbook.elements.length; i++) {\n" .
72 " if( document.addrbook.elements[i].type == 'checkbox' &&\n" .
73 " document.addrbook.elements[i].name.substr(0,16) == 'send_to_search['+ch ) {\n" .
74 " document.addrbook.elements[i].checked = !(document.addrbook.elements[i].checked);\n".
80 $chk_all = '<a href="#" onClick="CheckAll(\'T\');">' . _("All") . '</a> <font color="'.$color[9].'">To</font>'.
82 '<a href="#" onClick="CheckAll(\'C\');">' . _("All") . '</a> <font color="'.$color[9].'">Cc</font>'.
84 '<a href="#" onClick="CheckAll(\'B\');">' . _("All") . '</a>';
86 echo '<TABLE BORDER="0" WIDTH="98%" ALIGN="center">' .
87 '<TR BGCOLOR="' . $color[9] . '"><TH ALIGN="left"> ' . $chk_all . '</TH>' .
88 '<TH ALIGN="left"> ' . _("Name") . '</TH>' .
89 '<TH ALIGN="left"> ' . _("E-mail") . '</TH>' .
90 '<TH ALIGN="left"> ' . _("Info") . '</TH>';
95 echo '<TH ALIGN=left WIDTH="10%"> ' . _("Source"). '</TH>';
100 foreach ($res as $row) {
102 if ($line %
2) { echo ' bgcolor="' . $color[0] . '"'; }
103 echo ' nowrap><td nowrap align=center width="5%">' .
104 '<input type=checkbox name="send_to_search[T' . $line . ']" value = "' .
105 htmlspecialchars($row['email']) . '"> ' . _("To") . ' ' .
106 '<input type=checkbox name="send_to_search[C' . $line . ']" value = "' .
107 htmlspecialchars($row['email']) . '"> ' . _("Cc") . ' ' .
108 '<input type=checkbox name="send_to_search[B' . $line . ']" value = "' .
109 htmlspecialchars($row['email']) . '"> ' . _("Bcc") . ' ' .
110 '</td><td nowrap> ' . $row['name'] . ' </td>' .
111 '<td nowrap> ' . $row['email'] . ' </td>' .
112 '<td nowrap> ' . $row['label'] . ' </td>';
113 if ($includesource) {
114 echo '<td nowrap> ' . $row['source'] . ' </td>';
119 echo '<TR><TD ALIGN=center COLSPAN=';
120 if ($includesource) { echo '5'; } else { echo '4'; }
121 echo '><INPUT TYPE=submit NAME="addr_search_done" VALUE="' .
122 _("Use Addresses") . '"></TD></TR>' .
124 '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">' .
128 /* --- End functions --- */
131 if ($compose_new_win == '1') {
132 compose_Header($color, $mailbox);
135 displayPageHeader($color, $mailbox);
137 /* Initialize addressbook */
138 $abook = addressbook_init();
143 <table width
="95%" align
=center cellpadding
=2 cellspacing
=2 border
=0>
144 <tr
><td bgcolor
="<?php echo $color[0] ?>">
145 <center
><b
><?php
echo _("Address Book Search") ?
></b
></center
>
151 echo "<CENTER>\n<TABLE BORDER=0><TR><TD NOWRAP VALIGN=middle>\n" .
152 '<FORM METHOD=post NAME=f ACTION="' . $PHP_SELF .
153 '?html_addr_search=true">' . "\n<CENTER>\n" .
154 ' <nobr><STRONG>' . _("Search for") . "</STRONG>\n";
155 addr_insert_hidden();
156 if (! isset($addrquery))
158 echo ' <INPUT TYPE=text NAME=addrquery VALUE="' .
159 htmlspecialchars($addrquery) . "\" SIZE=26>\n";
161 /* List all backends to allow the user to choose where to search */
162 if (!isset($backend)) { $backend = ''; }
163 if ($abook->numbackends
> 1) {
164 echo '<STRONG>' . _("in") . '</STRONG> <SELECT NAME=backend>' . "\n" .
166 if ($backend == -1) { echo ' SELECTED'; }
167 echo '>' . _("All address books") . "\n";
168 $ret = $abook->get_backend_list();
169 while (list($undef,$v) = each($ret)) {
170 echo '<OPTION VALUE=' . $v->bnum
;
171 if ($backend == $v->bnum
) { echo ' SELECTED'; }
172 echo '>' . $v->sname
. "\n";
176 echo '<INPUT TYPE=hidden NAME=backend VALUE=-1>' . "\n";
178 if (isset($session)) {
179 echo "<input type=hidden name=\"session\" value=\"$session\">";
182 echo '<INPUT TYPE=submit VALUE="' . _("Search") . '">' .
183 ' | <INPUT TYPE=submit VALUE="' . _("List all") .
184 '" NAME=listall>' . "\n" .
185 '</FORM></center></TD></TR></TABLE>' . "\n";
186 addr_insert_hidden();
188 do_hook('addrbook_html_search_below');
189 /* End search form */
191 /* Show personal addressbook */
193 if ( !empty( $listall ) ){
197 if ($addrquery == '' && empty($listall)) {
199 if (! isset($backend) ||
$backend != -1 ||
$addrquery == '') {
200 if ($addrquery == '') {
201 $backend = $abook->localbackend
;
204 /* echo '<H3 ALIGN=center>' . $abook->backends[$backend]->sname) . "</H3>\n"; */
206 $res = $abook->list_addr($backend);
208 if (is_array($res)) {
209 usort($res,'alistcmp');
210 addr_display_result($res, false);
212 echo '<P ALIGN=center><STRONG>' .
213 sprintf(_("Unable to list addresses from %s"),
214 $abook->backends
[$backend]->sname
) .
219 $res = $abook->list_addr();
220 usort($res,'alistcmp');
221 addr_display_result($res, true);
228 if (!empty($addrquery)) {
230 if ($backend == -1) {
231 $res = $abook->s_search($addrquery);
233 $res = $abook->s_search($addrquery, $backend);
236 if (!is_array($res)) {
237 echo '<P ALIGN=center><B><BR>' .
238 _("Your search failed with the following error(s)") . ':<br>' .
239 $abook->error
. "</B></P>\n</BODY></HTML>\n";
241 if (sizeof($res) == 0) {
242 echo '<P ALIGN=center><BR><B>' .
243 _("No persons matching your search was found") .
244 ".</B></P>\n</BODY></HTML>\n";
246 addr_display_result($res);
252 if ($addrquery == '' ||
sizeof($res) == 0) {
253 /* printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF); */
254 echo '<center><FORM METHOD=post NAME=k ACTION="compose.php">' . "\n";
255 addr_insert_hidden();
256 echo '<INPUT TYPE=submit VALUE="' . _("Return") . '" NAME=return>' . "\n" .
257 '</form></center></nobr>';