5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 ** Handle addressbook searching with pure html.
8 ** This file is included from compose.php
10 ** NOTE: A lot of this code is similar to the code in
11 ** addrbook_search.html -- If you change one, change
18 if (!isset($config_php))
19 include("../config/config.php");
20 if (!isset($strings_php))
21 include("../functions/strings.php");
22 if (!isset($auth_php))
23 include("../functions/auth.php");
24 if (!isset($page_header_php))
25 include("../functions/page_header.php");
26 if (!isset($date_php))
27 include("../functions/date.php");
28 if (!isset($smtp_php))
29 include("../functions/smtp.php");
30 if (!isset($display_messages_php))
31 include("../functions/display_messages.php");
32 if (!isset($addressbook_php))
33 include("../functions/addressbook.php");
35 include("../src/load_prefs.php");
38 function addr_insert_hidden() {
39 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc;
40 printf("<input type=hidden value=\"%s\" name=body>\n",
41 htmlspecialchars($body));
42 printf("<input type=hidden value=\"%s\" name=subject>\n",
43 htmlspecialchars($subject));
44 printf("<input type=hidden value=\"%s\" name=send_to>\n",
45 htmlspecialchars($send_to));
46 printf("<input type=hidden value=\"%s\" name=send_to_cc>\n",
47 htmlspecialchars($send_to_cc));
48 printf("<input type=hidden value=\"%s\" name=send_to_bcc>\n",
49 htmlspecialchars($send_to_bcc));
53 // List search results
54 function addr_display_result($res, $includesource = true) {
55 global $color, $PHP_SELF;
57 if(sizeof($res) <= 0) return;
59 printf('<FORM METHOD=post ACTION="%s?html_addr_search_done=true">'."\n",
64 print "<TABLE BORDER=0 WIDTH=\"98%\" ALIGN=center>";
65 printf("<TR BGCOLOR=\"$color[9]\"><TH ALIGN=left> ".
66 "<TH ALIGN=left> %s<TH ALIGN=left> %s".
67 "<TH ALIGN=left> %s",
68 _("Name"), _("E-mail"), _("Info"));
71 printf("<TH ALIGN=left WIDTH=\"10%%\"> %s", _("Source"));
75 while(list($key, $row) = each($res)) {
76 printf("<tr%s nowrap><td nowrap align=center width=\"5%%\">".
77 "<input type=checkbox name=\"send_to_search[]\" value=\"%s\"> To".
78 "<input type=checkbox name=\"send_to_cc_search[]\" value=\"%s\"> Cc ".
79 "<td nowrap> %s <td nowrap> ".
81 "<td nowrap> %s ",
82 ($line %
2) ?
" bgcolor=\"$color[0]\"" : "",
83 htmlspecialchars($row["email"]), htmlspecialchars($row["email"]),
84 $row["name"], $row["email"], $row["label"]);
86 printf("<td nowrap> %s", $row["source"]);
91 printf('<TR><TD ALIGN=center COLSPAN=%d><INPUT TYPE=submit '.
92 'NAME="addr_search_done" VALUE="%s"></TD></TR>',
93 4 +
($includesource ?
1 : 0),
96 print '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">';
100 // --- End functions ---
102 displayPageHeader($color, "None");
104 // Initialize addressbook
105 $abook = addressbook_init();
107 $body = stripslashes($body);
108 $send_to = stripslashes($send_to);
109 $send_to_cc = stripslashes($send_to_cc);
110 $send_to_bcc = stripslashes($send_to_bcc);
111 $subject = stripslashes($subject);
115 print "<TABLE BORDER=0 WIDTH=100% COLS=1 ALIGN=CENTER>\n";
116 printf('<TR><TD BGCOLOR="%s" ALIGN=CENTER><STRONG>%s</STRONG></TD></TR>',
117 $color[0], _("Address Book Search"));
122 printf('<FORM METHOD=post ACTION="%s?html_addr_search=true">'."\n",
124 print "<TABLE BORDER=0>\n";
125 printf("<TR><TD NOWRAP VALIGN=middle>\n");
126 printf(" <STRONG>%s</STRONG>\n", _("Search for"));
127 printf(" <INPUT TYPE=text NAME=addrquery VALUE=\"%s\" SIZE=26>\n",
128 htmlspecialchars($addrquery));
130 // List all backends to allow the user to choose where to search
131 if($abook->numbackends
> 1) {
132 printf("<STRONG>%s</STRONG> <SELECT NAME=backend>\n",
134 printf("<OPTION VALUE=-1 %s>%s\n",
135 ($backend == -1) ?
"SELECTED" : "",
136 _("All address books"));
137 $ret = $abook->get_backend_list();
138 while(list($k,$v) = each($ret))
139 printf("<OPTION VALUE=%d %s>%s\n",
141 ($backend == $v->bnum
) ?
"SELECTED" : "",
143 printf("</SELECT>\n");
145 printf("<INPUT TYPE=hidden NAME=backend VALUE=-1>\n");
147 printf("<INPUT TYPE=submit VALUE=\"%s\">",
149 printf(" | <INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n",
151 printf("</TD></TR></TABLE>\n");
152 addr_insert_hidden();
157 // Show personal addressbook
158 if(!isset($addrquery) ||
!empty($listall)) {
160 if($backend != -1 ||
!isset($addrquery)) {
161 if(!isset($addrquery))
162 $backend = $abook->localbackend
;
164 //printf("<H3 ALIGN=center>%s</H3>\n", $abook->backends[$backend]->sname);
166 $res = $abook->list_addr($backend);
169 addr_display_result($res, false);
171 printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s").
172 "</STRONG></P>\n", $abook->backends
[$backend]->sname
);
176 $res = $abook->list_addr();
177 addr_display_result($res, true);
183 if(!empty($addrquery) && empty($listall)) {
186 $res = $abook->s_search($addrquery);
188 $res = $abook->s_search($addrquery, $backend);
191 if(!is_array($res)) {
192 printf("<P ALIGN=center><B><BR>%s:<br>%s</B></P>\n</BODY></HTML>\n",
193 _("Your search failed with the following error(s)"),
198 if(sizeof($res) == 0) {
199 printf("<P ALIGN=center><BR><B>%s.</B></P>\n</BODY></HTML>\n",
200 _("No persons matching your search was found"));
204 addr_display_result($res);