5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
8 ** Handle addressbook searching with pure html.
10 ** This file is included from compose.php
12 ** NOTE: A lot of this code is similar to the code in
13 ** addrbook_search.html -- If you change one, change
21 if (!isset($config_php))
22 include('../config/config.php');
23 if (!isset($strings_php))
24 include('../functions/strings.php');
25 if (!isset($auth_php))
26 include('../functions/auth.php');
27 if (!isset($page_header_php))
28 include('../functions/page_header.php');
29 if (!isset($date_php))
30 include('../functions/date.php');
31 if (!isset($smtp_php))
32 include('../functions/smtp.php');
33 if (!isset($display_messages_php))
34 include('../functions/display_messages.php');
35 if (!isset($addressbook_php))
36 include('../functions/addressbook.php');
37 if (!isset($plugin_php))
38 include('../functions/plugin.php');
40 include('../src/load_prefs.php');
43 function addr_insert_hidden() {
44 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc;
46 echo '<input type=hidden value="';
47 if (substr($body, 0, 1) == "\r")
49 echo htmlspecialchars($body) . '" name=body>' . "\n";
50 echo '<input type=hidden value="' . htmlspecialchars($subject)
51 . '" name=subject>' . "\n";
52 echo '<input type=hidden value="' . htmlspecialchars($send_to)
53 . '" name=send_to>' . "\n";
54 echo "<input type=hidden value=\"" . htmlspecialchars($send_to_cc)
55 . '" name=send_to_cc>' . "\n";
56 echo "<input type=hidden value=\"" . htmlspecialchars($send_to_bcc)
57 . '" name=send_to_bcc>' . "\n";
58 echo "<input type=hidden value=\"true\" name=from_htmladdr_search>\n";
62 // List search results
63 function addr_display_result($res, $includesource = true) {
64 global $color, $PHP_SELF;
66 if(sizeof($res) <= 0) return;
68 printf('<FORM METHOD=post ACTION="%s?html_addr_search_done=true">'."\n",
73 print "<TABLE BORDER=0 WIDTH=\"98%\" ALIGN=center>";
74 printf("<TR BGCOLOR=\"$color[9]\"><TH ALIGN=left> ".
75 "<TH ALIGN=left> %s<TH ALIGN=left> %s".
76 "<TH ALIGN=left> %s",
77 _("Name"), _("E-mail"), _("Info"));
80 printf("<TH ALIGN=left WIDTH=\"10%%\"> %s", _("Source"));
84 while(list($undef, $row) = each($res)) {
85 printf("<tr%s nowrap><td nowrap align=center width=\"5%%\">".
86 "<input type=checkbox name=\"send_to_search[]\" value=\"%s\"> To".
87 "<input type=checkbox name=\"send_to_cc_search[]\" value=\"%s\"> Cc ".
88 "<td nowrap> %s <td nowrap> ".
90 "<td nowrap> %s ",
91 ($line %
2) ?
" bgcolor=\"$color[0]\"" : "",
92 htmlspecialchars($row["email"]), htmlspecialchars($row["email"]),
93 $row["name"], $row["email"], $row["label"]);
95 printf("<td nowrap> %s", $row["source"]);
100 printf('<TR><TD ALIGN=center COLSPAN=%d><INPUT TYPE=submit '.
101 'NAME="addr_search_done" VALUE="%s"></TD></TR>',
102 4 +
($includesource ?
1 : 0),
105 print '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">';
109 // --- End functions ---
111 displayPageHeader($color, 'None');
113 // Initialize addressbook
114 $abook = addressbook_init();
116 $body = sqStripSlashes($body);
117 $send_to = sqStripSlashes($send_to);
118 $send_to_cc = sqStripSlashes($send_to_cc);
119 $send_to_bcc = sqStripSlashes($send_to_bcc);
120 $subject = sqStripSlashes($subject);
125 <table width
=95% align
=center cellpadding
=2 cellspacing
=2 border
=0>
126 <tr
><td bgcolor
="<?php echo $color[0] ?>">
127 <center
><b
><?php
echo _("Address Book Search") ?
></b
></center
>
133 print "<TABLE BORDER=0>\n";
134 print "<TR><TD NOWRAP VALIGN=middle>\n";
135 printf('<FORM METHOD=post NAME=f ACTION="%s?html_addr_search=true">'."\n", $PHP_SELF);
137 printf(" <nobr><STRONG>%s</STRONG>\n", _("Search for"));
138 addr_insert_hidden();
139 if (! isset($addrquery))
141 printf(" <INPUT TYPE=text NAME=addrquery VALUE=\"%s\" SIZE=26>\n",
142 htmlspecialchars($addrquery));
144 // List all backends to allow the user to choose where to search
145 if($abook->numbackends
> 1) {
146 printf("<STRONG>%s</STRONG> <SELECT NAME=backend>\n",
148 printf("<OPTION VALUE=-1 %s>%s\n",
149 ($backend == -1) ?
"SELECTED" : "",
150 _("All address books"));
151 $ret = $abook->get_backend_list();
152 while(list($undef,$v) = each($ret))
153 printf("<OPTION VALUE=%d %s>%s\n",
155 ($backend == $v->bnum
) ?
"SELECTED" : "",
159 print "<INPUT TYPE=hidden NAME=backend VALUE=-1>\n";
161 printf("<INPUT TYPE=submit VALUE=\"%s\">",
163 printf(" | <INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n",
165 print '</FORM></center>';
167 print "</TD></TR></TABLE>\n";
168 addr_insert_hidden();
170 do_hook('addrbook_html_search_below');
173 // Show personal addressbook
174 if(!isset($addrquery) ||
!empty($listall)) {
176 if(! isset($backend) ||
$backend != -1 ||
!isset($addrquery)) {
177 if(!isset($addrquery))
178 $backend = $abook->localbackend
;
180 //printf("<H3 ALIGN=center>%s</H3>\n", $abook->backends[$backend]->sname);
182 $res = $abook->list_addr($backend);
185 addr_display_result($res, false);
187 printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s").
188 "</STRONG></P>\n", $abook->backends
[$backend]->sname
);
192 $res = $abook->list_addr();
193 addr_display_result($res, true);
200 if(!empty($addrquery) && empty($listall)) {
203 $res = $abook->s_search($addrquery);
205 $res = $abook->s_search($addrquery, $backend);
208 if(!is_array($res)) {
209 printf("<P ALIGN=center><B><BR>%s:<br>%s</B></P>\n</BODY></HTML>\n",
210 _("Your search failed with the following error(s)"),
212 } else if(sizeof($res) == 0) {
213 printf("<P ALIGN=center><BR><B>%s.</B></P>\n</BODY></HTML>\n",
214 _("No persons matching your search was found"));
216 addr_display_result($res);
220 if (!$addrquery ||
sizeof($res) == 0) {
221 printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF);
222 addr_insert_hidden();
223 printf("<INPUT TYPE=submit VALUE=\"%s\" NAME=return>\n", _("Return"));
225 print '</center></nobr>';