* All incoming form values now have stripslashes() ran on them automatically
[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 ** $Id$
17 **/
18
19 session_start();
20
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');
39
40 include('../src/load_prefs.php');
41
42 // Insert hidden data
43 function addr_insert_hidden() {
44 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc;
45
46 echo '<input type=hidden value="';
47 if (substr($body, 0, 1) == "\r")
48 echo "\n";
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";
59 }
60
61
62 // List search results
63 function addr_display_result($res, $includesource = true) {
64 global $color, $PHP_SELF;
65
66 if(sizeof($res) <= 0) return;
67
68 printf('<FORM METHOD=post ACTION="%s?html_addr_search_done=true">'."\n",
69 $PHP_SELF);
70 addr_insert_hidden();
71 $line = 0;
72
73 print "<TABLE BORDER=0 WIDTH=\"98%\" ALIGN=center>";
74 printf("<TR BGCOLOR=\"$color[9]\"><TH ALIGN=left>&nbsp;".
75 "<TH ALIGN=left>&nbsp;%s<TH ALIGN=left>&nbsp;%s".
76 "<TH ALIGN=left>&nbsp;%s",
77 _("Name"), _("E-mail"), _("Info"));
78
79 if($includesource)
80 printf("<TH ALIGN=left WIDTH=\"10%%\">&nbsp;%s", _("Source"));
81
82 print "</TR>\n";
83
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\">&nbsp;To".
87 "<input type=checkbox name=\"send_to_cc_search[]\" value=\"%s\">&nbsp;Cc&nbsp;".
88 "<td nowrap>&nbsp;%s&nbsp;<td nowrap>&nbsp;".
89 "%s".
90 "<td nowrap>&nbsp;%s&nbsp;",
91 ($line % 2) ? " bgcolor=\"$color[0]\"" : "",
92 htmlspecialchars($row["email"]), htmlspecialchars($row["email"]),
93 $row["name"], $row["email"], $row["label"]);
94 if($includesource)
95 printf("<td nowrap>&nbsp;%s", $row["source"]);
96
97 print "</TR>\n";
98 $line++;
99 }
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),
103 _("Use Addresses"));
104 print '</TABLE>';
105 print '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">';
106 print '</FORM>';
107 }
108
109 // --- End functions ---
110
111 displayPageHeader($color, 'None');
112
113 // Initialize addressbook
114 $abook = addressbook_init();
115
116 ?>
117
118 <br>
119 <table width=95% align=center cellpadding=2 cellspacing=2 border=0>
120 <tr><td bgcolor="<?php echo $color[0] ?>">
121 <center><b><?php echo _("Address Book Search") ?></b></center>
122 </td></tr></table>
123
124 <?php
125 // Search form
126 print "<CENTER>\n";
127 print "<TABLE BORDER=0>\n";
128 print "<TR><TD NOWRAP VALIGN=middle>\n";
129 printf('<FORM METHOD=post NAME=f ACTION="%s?html_addr_search=true">'."\n", $PHP_SELF);
130 print "<CENTER>\n";
131 printf(" <nobr><STRONG>%s</STRONG>\n", _("Search for"));
132 addr_insert_hidden();
133 if (! isset($addrquery))
134 $addrquery = "";
135 printf(" <INPUT TYPE=text NAME=addrquery VALUE=\"%s\" SIZE=26>\n",
136 htmlspecialchars($addrquery));
137
138 // List all backends to allow the user to choose where to search
139 if($abook->numbackends > 1) {
140 printf("<STRONG>%s</STRONG>&nbsp;<SELECT NAME=backend>\n",
141 _("in"));
142 printf("<OPTION VALUE=-1 %s>%s\n",
143 ($backend == -1) ? "SELECTED" : "",
144 _("All address books"));
145 $ret = $abook->get_backend_list();
146 while(list($undef,$v) = each($ret))
147 printf("<OPTION VALUE=%d %s>%s\n",
148 $v->bnum,
149 ($backend == $v->bnum) ? "SELECTED" : "",
150 $v->sname);
151 print "</SELECT>\n";
152 } else {
153 print "<INPUT TYPE=hidden NAME=backend VALUE=-1>\n";
154 }
155 printf("<INPUT TYPE=submit VALUE=\"%s\">",
156 _("Search"));
157 printf("&nbsp;|&nbsp;<INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n",
158 _("List all"));
159 print '</FORM></center>';
160
161 print "</TD></TR></TABLE>\n";
162 addr_insert_hidden();
163 print "</CENTER>";
164 do_hook('addrbook_html_search_below');
165 // End search form
166
167 // Show personal addressbook
168 if(!isset($addrquery) || !empty($listall)) {
169
170 if(! isset($backend) || $backend != -1 || !isset($addrquery)) {
171 if(!isset($addrquery))
172 $backend = $abook->localbackend;
173
174 //printf("<H3 ALIGN=center>%s</H3>\n", $abook->backends[$backend]->sname);
175
176 $res = $abook->list_addr($backend);
177
178 if(is_array($res)) {
179 addr_display_result($res, false);
180 } else {
181 printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s").
182 "</STRONG></P>\n", $abook->backends[$backend]->sname);
183 }
184
185 } else {
186 $res = $abook->list_addr();
187 addr_display_result($res, true);
188 }
189 exit;
190
191 } else
192
193 // Do the search
194 if(!empty($addrquery) && empty($listall)) {
195
196 if($backend == -1) {
197 $res = $abook->s_search($addrquery);
198 } else {
199 $res = $abook->s_search($addrquery, $backend);
200 }
201
202 if(!is_array($res)) {
203 printf("<P ALIGN=center><B><BR>%s:<br>%s</B></P>\n</BODY></HTML>\n",
204 _("Your search failed with the following error(s)"),
205 $abook->error);
206 } else if(sizeof($res) == 0) {
207 printf("<P ALIGN=center><BR><B>%s.</B></P>\n</BODY></HTML>\n",
208 _("No persons matching your search was found"));
209 } else {
210 addr_display_result($res);
211 }
212 }
213
214 if (!$addrquery || sizeof($res) == 0) {
215 printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF);
216 addr_insert_hidden();
217 printf("<INPUT TYPE=submit VALUE=\"%s\" NAME=return>\n", _("Return"));
218 print '</form>';
219 print '</center></nobr>';
220 }
221
222 ?>
223 </body></html>