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 | |
f740c049 |
19 | include('../src/validate.php'); |
20 | include('../functions/strings.php'); |
21 | include('../config/config.php'); |
22 | include('../functions/page_header.php'); |
23 | include('../functions/date.php'); |
24 | include('../functions/smtp.php'); |
25 | include('../functions/display_messages.php'); |
26 | include('../functions/addressbook.php'); |
27 | include('../functions/plugin.php'); |
c9e9b23c |
28 | include('../src/load_prefs.php'); |
c1e15177 |
29 | |
14f1b90b |
30 | // Insert hidden data |
31 | function addr_insert_hidden() { |
32 | global $body, $subject, $send_to, $send_to_cc, $send_to_bcc; |
441f2d33 |
33 | |
c9e9b23c |
34 | echo '<input type=hidden value="'; |
441f2d33 |
35 | if (substr($body, 0, 1) == "\r") |
36 | echo "\n"; |
b897ac2e |
37 | echo htmlspecialchars($body) . '" name=body>' . "\n"; |
c9e9b23c |
38 | echo '<input type=hidden value="' . htmlspecialchars($subject) |
b897ac2e |
39 | . '" name=subject>' . "\n"; |
c9e9b23c |
40 | echo '<input type=hidden value="' . htmlspecialchars($send_to) |
b897ac2e |
41 | . '" name=send_to>' . "\n"; |
441f2d33 |
42 | echo "<input type=hidden value=\"" . htmlspecialchars($send_to_cc) |
b897ac2e |
43 | . '" name=send_to_cc>' . "\n"; |
441f2d33 |
44 | echo "<input type=hidden value=\"" . htmlspecialchars($send_to_bcc) |
b897ac2e |
45 | . '" name=send_to_bcc>' . "\n"; |
441f2d33 |
46 | echo "<input type=hidden value=\"true\" name=from_htmladdr_search>\n"; |
14f1b90b |
47 | } |
48 | |
49 | |
50 | // List search results |
51 | function addr_display_result($res, $includesource = true) { |
52 | global $color, $PHP_SELF; |
53 | |
54 | if(sizeof($res) <= 0) return; |
55 | |
56 | printf('<FORM METHOD=post ACTION="%s?html_addr_search_done=true">'."\n", |
6e79bfe2 |
57 | $PHP_SELF); |
14f1b90b |
58 | addr_insert_hidden(); |
59 | $line = 0; |
60 | |
61 | print "<TABLE BORDER=0 WIDTH=\"98%\" ALIGN=center>"; |
62 | printf("<TR BGCOLOR=\"$color[9]\"><TH ALIGN=left> ". |
6e79bfe2 |
63 | "<TH ALIGN=left> %s<TH ALIGN=left> %s". |
64 | "<TH ALIGN=left> %s", |
65 | _("Name"), _("E-mail"), _("Info")); |
14f1b90b |
66 | |
67 | if($includesource) |
6e79bfe2 |
68 | printf("<TH ALIGN=left WIDTH=\"10%%\"> %s", _("Source")); |
14f1b90b |
69 | |
70 | print "</TR>\n"; |
71 | |
fb16d219 |
72 | while(list($undef, $row) = each($res)) { |
14f1b90b |
73 | printf("<tr%s nowrap><td nowrap align=center width=\"5%%\">". |
74 | "<input type=checkbox name=\"send_to_search[]\" value=\"%s\"> To". |
75 | "<input type=checkbox name=\"send_to_cc_search[]\" value=\"%s\"> Cc ". |
a98bed68 |
76 | "<input type=checkbox name=\"send_to_bcc_search[]\" value=\"%s\"> Bcc ". |
14f1b90b |
77 | "<td nowrap> %s <td nowrap> ". |
78 | "%s". |
79 | "<td nowrap> %s ", |
80 | ($line % 2) ? " bgcolor=\"$color[0]\"" : "", |
a98bed68 |
81 | htmlspecialchars($row["email"]), htmlspecialchars($row["email"]), htmlspecialchars($row["email"]), |
6e79bfe2 |
82 | $row["name"], $row["email"], $row["label"]); |
83 | if($includesource) |
84 | printf("<td nowrap> %s", $row["source"]); |
85 | |
86 | print "</TR>\n"; |
14f1b90b |
87 | $line++; |
88 | } |
89 | printf('<TR><TD ALIGN=center COLSPAN=%d><INPUT TYPE=submit '. |
6e79bfe2 |
90 | 'NAME="addr_search_done" VALUE="%s"></TD></TR>', |
91 | 4 + ($includesource ? 1 : 0), |
92 | _("Use Addresses")); |
c9e9b23c |
93 | print '</TABLE>'; |
14f1b90b |
94 | print '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">'; |
c9e9b23c |
95 | print '</FORM>'; |
14f1b90b |
96 | } |
97 | |
98 | // --- End functions --- |
99 | |
c9e9b23c |
100 | displayPageHeader($color, 'None'); |
507832e7 |
101 | |
14f1b90b |
102 | // Initialize addressbook |
103 | $abook = addressbook_init(); |
c1e15177 |
104 | |
6e79bfe2 |
105 | ?> |
14f1b90b |
106 | |
6e79bfe2 |
107 | <br> |
108 | <table width=95% align=center cellpadding=2 cellspacing=2 border=0> |
109 | <tr><td bgcolor="<?php echo $color[0] ?>"> |
110 | <center><b><?php echo _("Address Book Search") ?></b></center> |
111 | </td></tr></table> |
14f1b90b |
112 | |
6e79bfe2 |
113 | <?php |
14f1b90b |
114 | // Search form |
115 | print "<CENTER>\n"; |
14f1b90b |
116 | print "<TABLE BORDER=0>\n"; |
c9e9b23c |
117 | print "<TR><TD NOWRAP VALIGN=middle>\n"; |
6e79bfe2 |
118 | printf('<FORM METHOD=post NAME=f ACTION="%s?html_addr_search=true">'."\n", $PHP_SELF); |
119 | print "<CENTER>\n"; |
120 | printf(" <nobr><STRONG>%s</STRONG>\n", _("Search for")); |
121 | addr_insert_hidden(); |
245a6892 |
122 | if (! isset($addrquery)) |
507832e7 |
123 | $addrquery = ''; |
14f1b90b |
124 | printf(" <INPUT TYPE=text NAME=addrquery VALUE=\"%s\" SIZE=26>\n", |
6e79bfe2 |
125 | htmlspecialchars($addrquery)); |
14f1b90b |
126 | |
127 | // List all backends to allow the user to choose where to search |
12b4ef8b |
128 | if(!isset($backend)) $backend = ""; |
14f1b90b |
129 | if($abook->numbackends > 1) { |
130 | printf("<STRONG>%s</STRONG> <SELECT NAME=backend>\n", |
6e79bfe2 |
131 | _("in")); |
14f1b90b |
132 | printf("<OPTION VALUE=-1 %s>%s\n", |
6e79bfe2 |
133 | ($backend == -1) ? "SELECTED" : "", |
134 | _("All address books")); |
14f1b90b |
135 | $ret = $abook->get_backend_list(); |
fb16d219 |
136 | while(list($undef,$v) = each($ret)) |
6e79bfe2 |
137 | printf("<OPTION VALUE=%d %s>%s\n", |
138 | $v->bnum, |
139 | ($backend == $v->bnum) ? "SELECTED" : "", |
140 | $v->sname); |
c9e9b23c |
141 | print "</SELECT>\n"; |
14f1b90b |
142 | } else { |
c9e9b23c |
143 | print "<INPUT TYPE=hidden NAME=backend VALUE=-1>\n"; |
14f1b90b |
144 | } |
145 | printf("<INPUT TYPE=submit VALUE=\"%s\">", |
6e79bfe2 |
146 | _("Search")); |
14f1b90b |
147 | printf(" | <INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n", |
6e79bfe2 |
148 | _("List all")); |
c9e9b23c |
149 | print '</FORM></center>'; |
6e79bfe2 |
150 | |
c9e9b23c |
151 | print "</TD></TR></TABLE>\n"; |
14f1b90b |
152 | addr_insert_hidden(); |
14f1b90b |
153 | print "</CENTER>"; |
c9e9b23c |
154 | do_hook('addrbook_html_search_below'); |
14f1b90b |
155 | // End search form |
156 | |
157 | // Show personal addressbook |
507832e7 |
158 | if($addrquery == '' || !empty($listall)) { |
14f1b90b |
159 | |
507832e7 |
160 | if(! isset($backend) || $backend != -1 || $addrquery == '') { |
161 | if($addrquery == '') |
6e79bfe2 |
162 | $backend = $abook->localbackend; |
14f1b90b |
163 | |
6e79bfe2 |
164 | //printf("<H3 ALIGN=center>%s</H3>\n", $abook->backends[$backend]->sname); |
14f1b90b |
165 | |
6e79bfe2 |
166 | $res = $abook->list_addr($backend); |
14f1b90b |
167 | |
6e79bfe2 |
168 | if(is_array($res)) { |
169 | addr_display_result($res, false); |
170 | } else { |
171 | printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s"). |
172 | "</STRONG></P>\n", $abook->backends[$backend]->sname); |
173 | } |
14f1b90b |
174 | |
175 | } else { |
6e79bfe2 |
176 | $res = $abook->list_addr(); |
177 | addr_display_result($res, true); |
14f1b90b |
178 | } |
6e79bfe2 |
179 | exit; |
14f1b90b |
180 | |
181 | } else |
182 | |
183 | // Do the search |
184 | if(!empty($addrquery) && empty($listall)) { |
185 | |
186 | if($backend == -1) { |
6e79bfe2 |
187 | $res = $abook->s_search($addrquery); |
14f1b90b |
188 | } else { |
6e79bfe2 |
189 | $res = $abook->s_search($addrquery, $backend); |
14f1b90b |
190 | } |
c1e15177 |
191 | |
192 | if(!is_array($res)) { |
6e79bfe2 |
193 | printf("<P ALIGN=center><B><BR>%s:<br>%s</B></P>\n</BODY></HTML>\n", |
194 | _("Your search failed with the following error(s)"), |
195 | $abook->error); |
196 | } else 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")); |
199 | } else { |
200 | addr_display_result($res); |
c1e15177 |
201 | } |
c1e15177 |
202 | } |
203 | |
507832e7 |
204 | if ($addrquery == '' || sizeof($res) == 0) { |
6e79bfe2 |
205 | printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF); |
206 | addr_insert_hidden(); |
207 | printf("<INPUT TYPE=submit VALUE=\"%s\" NAME=return>\n", _("Return")); |
c9e9b23c |
208 | print '</form>'; |
209 | print '</center></nobr>'; |
6e79bfe2 |
210 | } |
211 | |
c1e15177 |
212 | ?> |
d7d3c4d4 |
213 | </body></html> |