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