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