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