if any of the standard headers are blank, read_body.php doesn't show
[squirrelmail.git] / src / addrbook_search_html.php
1 <?php
2 /**
3 ** addrbook_search.php
4 **
5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 **
8 ** Handle addressbook searching with pure html.
9 **
10 ** This file is included from compose.php
11 **
12 ** NOTE: A lot of this code is similar to the code in
13 ** addrbook_search.html -- If you change one, change
14 ** the other one too!
15 **/
16
17 session_start();
18
19 if (!isset($config_php))
20 include("../config/config.php");
21 if (!isset($strings_php))
22 include("../functions/strings.php");
23 if (!isset($auth_php))
24 include("../functions/auth.php");
25 if (!isset($page_header_php))
26 include("../functions/page_header.php");
27 if (!isset($date_php))
28 include("../functions/date.php");
29 if (!isset($smtp_php))
30 include("../functions/smtp.php");
31 if (!isset($display_messages_php))
32 include("../functions/display_messages.php");
33 if (!isset($addressbook_php))
34 include("../functions/addressbook.php");
35 if (!isset($plugin_php))
36 include("../functions/plugin.php");
37
38 include("../src/load_prefs.php");
39
40 // Insert hidden data
41 function addr_insert_hidden() {
42 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc;
43 printf("<input type=hidden value=\"%s\" name=body>\n",
44 htmlspecialchars($body));
45 printf("<input type=hidden value=\"%s\" name=subject>\n",
46 htmlspecialchars($subject));
47 printf("<input type=hidden value=\"%s\" name=send_to>\n",
48 htmlspecialchars($send_to));
49 printf("<input type=hidden value=\"%s\" name=send_to_cc>\n",
50 htmlspecialchars($send_to_cc));
51 printf("<input type=hidden value=\"%s\" name=send_to_bcc>\n",
52 htmlspecialchars($send_to_bcc));
53 printf("<input type=hidden value=\"true\" name=from_htmladdr_search>\n");
54 }
55
56
57 // List search results
58 function addr_display_result($res, $includesource = true) {
59 global $color, $PHP_SELF;
60
61 if(sizeof($res) <= 0) return;
62
63 printf('<FORM METHOD=post ACTION="%s?html_addr_search_done=true">'."\n",
64 $PHP_SELF);
65 addr_insert_hidden();
66 $line = 0;
67
68 print "<TABLE BORDER=0 WIDTH=\"98%\" ALIGN=center>";
69 printf("<TR BGCOLOR=\"$color[9]\"><TH ALIGN=left>&nbsp;".
70 "<TH ALIGN=left>&nbsp;%s<TH ALIGN=left>&nbsp;%s".
71 "<TH ALIGN=left>&nbsp;%s",
72 _("Name"), _("E-mail"), _("Info"));
73
74 if($includesource)
75 printf("<TH ALIGN=left WIDTH=\"10%%\">&nbsp;%s", _("Source"));
76
77 print "</TR>\n";
78
79 while(list($undef, $row) = each($res)) {
80 printf("<tr%s nowrap><td nowrap align=center width=\"5%%\">".
81 "<input type=checkbox name=\"send_to_search[]\" value=\"%s\">&nbsp;To".
82 "<input type=checkbox name=\"send_to_cc_search[]\" value=\"%s\">&nbsp;Cc&nbsp;".
83 "<td nowrap>&nbsp;%s&nbsp;<td nowrap>&nbsp;".
84 "%s".
85 "<td nowrap>&nbsp;%s&nbsp;",
86 ($line % 2) ? " bgcolor=\"$color[0]\"" : "",
87 htmlspecialchars($row["email"]), htmlspecialchars($row["email"]),
88 $row["name"], $row["email"], $row["label"]);
89 if($includesource)
90 printf("<td nowrap>&nbsp;%s", $row["source"]);
91
92 print "</TR>\n";
93 $line++;
94 }
95 printf('<TR><TD ALIGN=center COLSPAN=%d><INPUT TYPE=submit '.
96 'NAME="addr_search_done" VALUE="%s"></TD></TR>',
97 4 + ($includesource ? 1 : 0),
98 _("Use Addresses"));
99 print "</TABLE>";
100 print '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">';
101 print "</FORM>";
102 }
103
104 // --- End functions ---
105
106 displayPageHeader($color, "None");
107
108 // Initialize addressbook
109 $abook = addressbook_init();
110
111 $body = sqStripSlashes($body);
112 $send_to = sqStripSlashes($send_to);
113 $send_to_cc = sqStripSlashes($send_to_cc);
114 $send_to_bcc = sqStripSlashes($send_to_bcc);
115 $subject = sqStripSlashes($subject);
116
117 ?>
118
119 <br>
120 <table width=95% align=center cellpadding=2 cellspacing=2 border=0>
121 <tr><td bgcolor="<?php echo $color[0] ?>">
122 <center><b><?php echo _("Address Book Search") ?></b></center>
123 </td></tr></table>
124
125 <?php
126 // Search form
127 print "<CENTER>\n";
128 print "<TABLE BORDER=0>\n";
129 printf("<TR><TD NOWRAP VALIGN=middle>\n");
130 printf('<FORM METHOD=post NAME=f ACTION="%s?html_addr_search=true">'."\n", $PHP_SELF);
131 print "<CENTER>\n";
132 printf(" <nobr><STRONG>%s</STRONG>\n", _("Search for"));
133 addr_insert_hidden();
134 printf(" <INPUT TYPE=text NAME=addrquery VALUE=\"%s\" SIZE=26>\n",
135 htmlspecialchars($addrquery));
136
137 // List all backends to allow the user to choose where to search
138 if($abook->numbackends > 1) {
139 printf("<STRONG>%s</STRONG>&nbsp;<SELECT NAME=backend>\n",
140 _("in"));
141 printf("<OPTION VALUE=-1 %s>%s\n",
142 ($backend == -1) ? "SELECTED" : "",
143 _("All address books"));
144 $ret = $abook->get_backend_list();
145 while(list($undef,$v) = each($ret))
146 printf("<OPTION VALUE=%d %s>%s\n",
147 $v->bnum,
148 ($backend == $v->bnum) ? "SELECTED" : "",
149 $v->sname);
150 printf("</SELECT>\n");
151 } else {
152 printf("<INPUT TYPE=hidden NAME=backend VALUE=-1>\n");
153 }
154 printf("<INPUT TYPE=submit VALUE=\"%s\">",
155 _("Search"));
156 printf("&nbsp;|&nbsp;<INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n",
157 _("List all"));
158 print "</FORM></center>";
159
160 printf("</TD></TR></TABLE>\n");
161 addr_insert_hidden();
162 print "</CENTER>";
163 do_hook("addrbook_html_search_below");
164 // End search form
165
166 // Show personal addressbook
167 if(!isset($addrquery) || !empty($listall)) {
168
169 if($backend != -1 || !isset($addrquery)) {
170 if(!isset($addrquery))
171 $backend = $abook->localbackend;
172
173 //printf("<H3 ALIGN=center>%s</H3>\n", $abook->backends[$backend]->sname);
174
175 $res = $abook->list_addr($backend);
176
177 if(is_array($res)) {
178 addr_display_result($res, false);
179 } else {
180 printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s").
181 "</STRONG></P>\n", $abook->backends[$backend]->sname);
182 }
183
184 } else {
185 $res = $abook->list_addr();
186 addr_display_result($res, true);
187 }
188 exit;
189
190 } else
191
192 // Do the search
193 if(!empty($addrquery) && empty($listall)) {
194
195 if($backend == -1) {
196 $res = $abook->s_search($addrquery);
197 } else {
198 $res = $abook->s_search($addrquery, $backend);
199 }
200
201 if(!is_array($res)) {
202 printf("<P ALIGN=center><B><BR>%s:<br>%s</B></P>\n</BODY></HTML>\n",
203 _("Your search failed with the following error(s)"),
204 $abook->error);
205 } else if(sizeof($res) == 0) {
206 printf("<P ALIGN=center><BR><B>%s.</B></P>\n</BODY></HTML>\n",
207 _("No persons matching your search was found"));
208 } else {
209 addr_display_result($res);
210 }
211 }
212
213 if (!$addrquery || sizeof($res) == 0) {
214 printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF);
215 addr_insert_hidden();
216 printf("<INPUT TYPE=submit VALUE=\"%s\" NAME=return>\n", _("Return"));
217 printf('</form>');
218 printf("</center></nobr>");
219 }
220
221 ?>
222 </body></html>