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