5100704d |
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. |
7 | ** |
5100704d |
8 | ** Handle addressbook searching in the popup window. |
9 | ** |
2c5d4cd4 |
10 | ** NOTE: A lot of this code is similar to the code in |
11 | ** addrbook_search_html.html -- If you change one, |
12 | ** change the other one too! |
245a6892 |
13 | ** |
14 | ** $Id$ |
5100704d |
15 | **/ |
16 | |
f740c049 |
17 | include("../src/validate.php"); |
18 | |
2f73dc15 |
19 | // Function to include JavaScript code |
20 | function insert_javascript() { |
5100704d |
21 | ?> |
22 | <SCRIPT LANGUAGE="Javascript"><!-- |
23 | |
87332e20 |
24 | function to_and_close($addr) { |
25 | to_address($addr); |
26 | parent.close(); |
27 | } |
28 | |
5100704d |
29 | function to_address($addr) { |
30 | var prefix = ""; |
31 | var pwintype = typeof parent.opener.document.compose; |
32 | |
dfadb553 |
33 | $addr = $addr.replace(/ {1,35}$/, ""); |
34 | |
5100704d |
35 | if(pwintype != "undefined" ) { |
36 | if ( parent.opener.document.compose.send_to.value ) { |
37 | prefix = ", "; |
38 | parent.opener.document.compose.send_to.value = |
dfadb553 |
39 | parent.opener.document.compose.send_to.value + ", " + $addr; |
40 | |
5100704d |
41 | } else { |
42 | parent.opener.document.compose.send_to.value = $addr; |
43 | } |
44 | } |
45 | } |
46 | |
47 | function cc_address($addr) { |
48 | var prefix = ""; |
49 | var pwintype = typeof parent.opener.document.compose; |
50 | |
dfadb553 |
51 | $addr = $addr.replace(/ {1,35}$/, ""); |
52 | |
5100704d |
53 | if(pwintype != "undefined" ) { |
54 | if ( parent.opener.document.compose.send_to_cc.value ) { |
55 | prefix = ", "; |
56 | parent.opener.document.compose.send_to_cc.value = |
57 | parent.opener.document.compose.send_to_cc.value + ", " + $addr; |
58 | } else { |
59 | parent.opener.document.compose.send_to_cc.value = $addr; |
60 | } |
61 | } |
62 | } |
63 | |
64 | function bcc_address($addr) { |
65 | var prefix = ""; |
66 | var pwintype = typeof parent.opener.document.compose; |
dfadb553 |
67 | |
68 | $addr = $addr.replace(/ {1,35}$/, ""); |
5100704d |
69 | |
70 | if(pwintype != "undefined" ) { |
a4fe507d |
71 | if ( parent.opener.document.compose.send_to_bcc.value ) { |
5100704d |
72 | prefix = ", "; |
a4fe507d |
73 | parent.opener.document.compose.send_to_bcc.value = |
74 | parent.opener.document.compose.send_to_bcc.value + ", " + $addr; |
5100704d |
75 | } else { |
a4fe507d |
76 | parent.opener.document.compose.send_to_bcc.value = $addr; |
5100704d |
77 | } |
78 | } |
79 | } |
80 | |
81 | // --></SCRIPT> |
82 | |
83 | <?php |
2f73dc15 |
84 | } // End of included JavaScript |
85 | |
86 | |
87 | // List search results |
88 | function display_result($res, $includesource = true) { |
89 | global $color; |
90 | |
91 | if(sizeof($res) <= 0) return; |
92 | |
93 | insert_javascript(); |
94 | |
95 | $line = 0; |
c9e9b23c |
96 | print '<TABLE BORDER="0" WIDTH="98%" ALIGN=center>'; |
2f73dc15 |
97 | printf("<TR BGCOLOR=\"$color[9]\"><TH ALIGN=left> ". |
98 | "<TH ALIGN=left> %s<TH ALIGN=left> %s". |
99 | "<TH ALIGN=left> %s", |
100 | _("Name"), _("E-mail"), _("Info")); |
101 | |
102 | if($includesource) |
103 | printf("<TH ALIGN=left WIDTH=\"10%%\"> %s", _("Source")); |
104 | |
105 | print "</TR>\n"; |
106 | |
fb16d219 |
107 | while(list($undef, $row) = each($res)) { |
2c5d4cd4 |
108 | printf("<tr%s nowrap><td valign=top nowrap align=center width=\"5%%\">". |
2f73dc15 |
109 | "<small><a href=\"javascript:to_address('%s');\">To</A> | ". |
110 | "<a href=\"javascript:cc_address('%s');\">Cc</A> | ". |
111 | "<a href=\"javascript:bcc_address('%s');\">Bcc</A></small>". |
2c5d4cd4 |
112 | "<td nowrap valign=top> %s <td nowrap valign=top>". |
113 | " <a href=\"javascript:to_and_close('%s');\">%s</A> ". |
114 | "<td valign=top> %s ", |
2f73dc15 |
115 | ($line % 2) ? " bgcolor=\"$color[0]\"" : "", |
116 | $row["email"], $row["email"], $row["email"], |
117 | $row["name"], $row["email"], $row["email"], |
118 | $row["label"]); |
119 | |
120 | if($includesource) |
2c5d4cd4 |
121 | printf("<td nowrap valign=top> %s", $row["source"]); |
2f73dc15 |
122 | |
123 | print "</TR>\n"; |
124 | $line++; |
125 | } |
c9e9b23c |
126 | print '</TABLE>'; |
2f73dc15 |
127 | } |
128 | |
129 | /* ================= End of functions ================= */ |
130 | |
f740c049 |
131 | include('../functions/array.php'); |
132 | include('../functions/strings.php'); |
f740c049 |
133 | include('../functions/addressbook.php'); |
2f73dc15 |
134 | |
135 | displayHtmlHeader(); |
136 | |
12b4ef8b |
137 | // Initialize vars |
138 | if(!isset($query)) $query = ""; |
139 | if(!isset($show)) $show = ""; |
140 | |
2f73dc15 |
141 | // Choose correct colors for top and bottom frame |
c9e9b23c |
142 | if($show == 'form') { |
2f73dc15 |
143 | echo "<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" "; |
144 | echo "LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\" "; |
c9e9b23c |
145 | echo 'OnLoad="document.sform.query.focus();">'; |
2f73dc15 |
146 | } else { |
147 | echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" "; |
148 | echo "LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n"; |
149 | } |
150 | |
151 | // Empty search |
152 | if(empty($query) && empty($show) && empty($listall)) { |
153 | printf("<P ALIGN=center><BR>%s</P>\n</BODY></HTML>\n", |
154 | _("No persons matching your search was found")); |
155 | exit; |
156 | } |
157 | |
158 | // Initialize addressbook |
159 | $abook = addressbook_init(); |
160 | |
161 | // Create search form |
c9e9b23c |
162 | if($show == 'form') { |
2f73dc15 |
163 | printf("<FORM NAME=sform TARGET=abookres ACTION=\"%s\" METHOD=\"POST\">\n", |
164 | $PHP_SELF); |
c9e9b23c |
165 | print('<TABLE BORDER="0" WIDTH="100%" HEIGHT="100%">'); |
166 | print("<TR><TD NOWRAP VALIGN=middle>\n"); |
2f73dc15 |
167 | printf(" <STRONG>%s</STRONG>\n", _("Search for")); |
168 | printf(" <INPUT TYPE=text NAME=query VALUE=\"%s\" SIZE=26>\n", |
169 | htmlspecialchars($query)); |
170 | |
171 | // List all backends to allow the user to choose where to search |
172 | if($abook->numbackends > 1) { |
173 | printf("<STRONG>%s</STRONG> <SELECT NAME=backend>\n", |
174 | _("in")); |
175 | printf("<OPTION VALUE=-1 SELECTED>%s\n", |
176 | _("All address books")); |
177 | $ret = $abook->get_backend_list(); |
fb16d219 |
178 | while(list($undef,$v) = each($ret)) |
2c5d4cd4 |
179 | printf("<OPTION VALUE=%d>%s\n", $v->bnum, $v->sname); |
c9e9b23c |
180 | print "</SELECT>\n"; |
2f73dc15 |
181 | } else { |
c9e9b23c |
182 | print "<INPUT TYPE=hidden NAME=backend VALUE=-1>\n"; |
2f73dc15 |
183 | } |
184 | |
185 | printf("<INPUT TYPE=submit VALUE=\"%s\">", |
186 | _("Search")); |
187 | printf(" | <INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n", |
188 | _("List all")); |
c9e9b23c |
189 | print "</TD><TD ALIGN=right>\n"; |
2f73dc15 |
190 | printf("<INPUT TYPE=button VALUE=\"%s\" onclick=\"parent.close();\">\n", |
191 | _("Close window")); |
c9e9b23c |
192 | print "</TD></TR></TABLE></FORM>\n"; |
2f73dc15 |
193 | } else |
194 | |
195 | // Show personal addressbook |
c9e9b23c |
196 | if($show == 'blank' || !empty($listall)) { |
2f73dc15 |
197 | |
c9e9b23c |
198 | if($backend != -1 || $show == 'blank') { |
199 | if($show == 'blank') |
2f73dc15 |
200 | $backend = $abook->localbackend; |
201 | |
202 | //printf("<H3 ALIGN=center>%s</H3>\n", $abook->backends[$backend]->sname); |
203 | |
204 | $res = $abook->list_addr($backend); |
205 | |
206 | if(is_array($res)) { |
207 | display_result($res, false); |
208 | } else { |
209 | printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s"). |
210 | "</STRONG></P>\n", $abook->backends[$backend]->sname); |
211 | } |
212 | |
213 | } else { |
214 | $res = $abook->list_addr(); |
215 | display_result($res, true); |
216 | } |
217 | |
218 | } else |
5100704d |
219 | |
220 | // Do the search |
2f73dc15 |
221 | if(!empty($query) && empty($listall)) { |
222 | |
223 | if($backend == -1) { |
224 | $res = $abook->s_search($query); |
225 | } else { |
226 | $res = $abook->s_search($query, $backend); |
227 | } |
5100704d |
228 | |
229 | if(!is_array($res)) { |
2c5d4cd4 |
230 | printf("<P ALIGN=center><B><BR>%s:<br>%s</B></P>\n</BODY></HTML>\n", |
a51f9f4b |
231 | _("Your search failed with the following error(s)"), |
232 | $abook->error); |
233 | exit; |
234 | } |
235 | |
236 | if(sizeof($res) == 0) { |
2c5d4cd4 |
237 | printf("<P ALIGN=center><BR><B>%s.</B></P>\n</BODY></HTML>\n", |
5100704d |
238 | _("No persons matching your search was found")); |
239 | exit; |
240 | } |
241 | |
2f73dc15 |
242 | display_result($res); |
5100704d |
243 | } |
244 | ?> |
245 | |
246 | </BODY></HTML> |