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