5 ** Handle addressbook searching with pure html.
6 ** This file is included from compose.php
8 ** NOTE: A lot of this code is similar to the code in
9 ** addrbook_search.html -- If you change one, change
16 if (!isset($config_php))
17 include("../config/config.php");
18 if (!isset($strings_php))
19 include("../functions/strings.php");
20 if (!isset($auth_php))
21 include("../functions/auth.php");
22 if (!isset($page_header_php))
23 include("../functions/page_header.php");
24 if (!isset($date_php))
25 include("../functions/date.php");
26 if (!isset($smtp_php))
27 include("../functions/smtp.php");
28 if (!isset($display_messages_php))
29 include("../functions/display_messages.php");
30 if (!isset($addressbook_php))
31 include("../functions/addressbook.php");
33 include("../src/load_prefs.php");
36 function addr_insert_hidden() {
37 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc;
38 printf("<input type=hidden value=\"%s\" name=body>\n",
39 htmlspecialchars($body));
40 printf("<input type=hidden value=\"%s\" name=subject>\n",
41 htmlspecialchars($subject));
42 printf("<input type=hidden value=\"%s\" name=send_to>\n",
43 htmlspecialchars($send_to));
44 printf("<input type=hidden value=\"%s\" name=send_to_cc>\n",
45 htmlspecialchars($send_to_cc));
46 printf("<input type=hidden value=\"%s\" name=send_to_bcc>\n",
47 htmlspecialchars($send_to_bcc));
51 // List search results
52 function addr_display_result($res, $includesource = true) {
53 global $color, $PHP_SELF;
55 if(sizeof($res) <= 0) return;
57 printf('<FORM METHOD=post ACTION="%s?html_addr_search_done=true">'."\n",
62 print "<TABLE BORDER=0 WIDTH=\"98%\" ALIGN=center>";
63 printf("<TR BGCOLOR=\"$color[9]\"><TH ALIGN=left> ".
64 "<TH ALIGN=left> %s<TH ALIGN=left> %s".
65 "<TH ALIGN=left> %s",
66 _("Name"), _("E-mail"), _("Info"));
69 printf("<TH ALIGN=left WIDTH=\"10%%\"> %s", _("Source"));
73 while(list($key, $row) = each($res)) {
74 printf("<tr%s nowrap><td nowrap align=center width=\"5%%\">".
75 "<input type=checkbox name=\"send_to_search[]\" value=\"%s\"> To".
76 "<input type=checkbox name=\"send_to_cc_search[]\" value=\"%s\"> Cc ".
77 "<td nowrap> %s <td nowrap> ".
79 "<td nowrap> %s ",
80 ($line %
2) ?
" bgcolor=\"$color[0]\"" : "",
81 htmlspecialchars($row["email"]), htmlspecialchars($row["email"]),
82 $row["name"], $row["email"], $row["label"]);
84 printf("<td nowrap> %s", $row["source"]);
89 printf('<TR><TD ALIGN=center COLSPAN=%d><INPUT TYPE=submit '.
90 'NAME="addr_search_done" VALUE="%s"></TD></TR>',
91 4 +
($includesource ?
1 : 0),
94 print '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">';
98 // --- End functions ---
100 displayPageHeader($color, "None");
102 // Initialize addressbook
103 $abook = addressbook_init();
105 $body = stripslashes($body);
106 $send_to = stripslashes($send_to);
107 $send_to_cc = stripslashes($send_to_cc);
108 $send_to_bcc = stripslashes($send_to_bcc);
109 $subject = stripslashes($subject);
113 print "<TABLE BORDER=0 WIDTH=100% COLS=1 ALIGN=CENTER>\n";
114 printf('<TR><TD BGCOLOR="%s" ALIGN=CENTER><STRONG>%s</STRONG></TD></TR>',
115 $color[0], _("Address Book Search"));
120 printf('<FORM METHOD=post ACTION="%s?html_addr_search=true">'."\n",
122 print "<TABLE BORDER=0>\n";
123 printf("<TR><TD NOWRAP VALIGN=middle>\n");
124 printf(" <STRONG>%s</STRONG>\n", _("Search for"));
125 printf(" <INPUT TYPE=text NAME=addrquery VALUE=\"%s\" SIZE=26>\n",
126 htmlspecialchars($addrquery));
128 // List all backends to allow the user to choose where to search
129 if($abook->numbackends
> 1) {
130 printf("<STRONG>%s</STRONG> <SELECT NAME=backend>\n",
132 printf("<OPTION VALUE=-1 %s>%s\n",
133 ($backend == -1) ?
"SELECTED" : "",
134 _("All address books"));
135 $ret = $abook->get_backend_list();
136 while(list($k,$v) = each($ret))
137 printf("<OPTION VALUE=%d %s>%s\n",
139 ($backend == $v->bnum
) ?
"SELECTED" : "",
141 printf("</SELECT>\n");
143 printf("<INPUT TYPE=hidden NAME=backend VALUE=-1>\n");
145 printf("<INPUT TYPE=submit VALUE=\"%s\">",
147 printf(" | <INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n",
149 printf("</TD></TR></TABLE>\n");
150 addr_insert_hidden();
155 // Show personal addressbook
156 if(!isset($addrquery) ||
!empty($listall)) {
158 if($backend != -1 ||
!isset($addrquery)) {
159 if(!isset($addrquery))
160 $backend = $abook->localbackend
;
162 //printf("<H3 ALIGN=center>%s</H3>\n", $abook->backends[$backend]->sname);
164 $res = $abook->list_addr($backend);
167 addr_display_result($res, false);
169 printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s").
170 "</STRONG></P>\n", $abook->backends
[$backend]->sname
);
174 $res = $abook->list_addr();
175 addr_display_result($res, true);
181 if(!empty($addrquery) && empty($listall)) {
184 $res = $abook->s_search($addrquery);
186 $res = $abook->s_search($addrquery, $backend);
189 if(!is_array($res)) {
190 printf("<P ALIGN=center><B><BR>%s:<br>%s</B></P>\n</BODY></HTML>\n",
191 _("Your search failed with the following error(s)"),
196 if(sizeof($res) == 0) {
197 printf("<P ALIGN=center><BR><B>%s.</B></P>\n</BODY></HTML>\n",
198 _("No persons matching your search was found"));
202 addr_display_result($res);