c1e15177 |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * addrbook_search_html.php |
5 | * |
15e6162e |
6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * Handle addressbook searching with pure html. |
10 | * |
11 | * This file is included from compose.php |
12 | * |
13 | * NOTE: A lot of this code is similar to the code in |
14 | * addrbook_search.html -- If you change one, change |
15 | * the other one too! |
16 | * |
17 | * $Id$ |
18 | */ |
c1e15177 |
19 | |
35586184 |
20 | require_once('../src/validate.php'); |
21 | require_once('../functions/date.php'); |
22 | require_once('../functions/smtp.php'); |
23 | require_once('../functions/display_messages.php'); |
24 | require_once('../functions/addressbook.php'); |
25 | require_once('../functions/plugin.php'); |
5177fb2b |
26 | require_once('../functions/strings.php'); |
c1e15177 |
27 | |
00a065a6 |
28 | /* Insert hidden data */ |
29 | function addr_insert_hidden() { |
30 | global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox, |
31 | $identity; |
32 | |
33 | echo '<input type=hidden value="'; |
65a5bae6 |
34 | if (substr($body, 0, 1) == "\r") { |
00a065a6 |
35 | echo "\n"; |
65a5bae6 |
36 | } |
00a065a6 |
37 | echo htmlspecialchars($body) . '" name=body>' . "\n" . |
38 | '<input type=hidden value="' . htmlspecialchars($subject) . |
39 | '" name=subject>' . "\n" . |
40 | '<input type=hidden value="' . htmlspecialchars($send_to) . |
41 | '" name=send_to>' . "\n" . |
42 | '<input type=hidden value="' . htmlspecialchars($send_to_cc) . |
43 | '" name=send_to_cc>' . "\n" . |
44 | '<input type=hidden value="' . htmlspecialchars($send_to_bcc) . |
45 | '" name=send_to_bcc>' . "\n" . |
46 | '<input type=hidden value="' . htmlspecialchars($identity) . |
47 | '" name=identity>' . "\n" . |
48 | '<input type=hidden name=mailbox value="' . htmlspecialchars($mailbox) . |
49 | "\">\n" . '<input type=hidden value="true" name=from_htmladdr_search>' . |
50 | "\n"; |
14f1b90b |
51 | } |
52 | |
14f1b90b |
53 | |
00a065a6 |
54 | /* List search results */ |
55 | function addr_display_result($res, $includesource = true) { |
56 | global $color, $PHP_SELF; |
57 | |
58 | if (sizeof($res) <= 0) return; |
59 | |
60 | echo '<form method=post action="' . $PHP_SELF . "\">\n" . |
61 | '<input type=hidden name="html_addr_search_done" value="true">' . "\n"; |
62 | addr_insert_hidden(); |
63 | $line = 0; |
64 | |
65 | echo '<TABLE BORDER=0 WIDTH="98%" ALIGN=center>' . |
66 | '<TR BGCOLOR="' . $color[9] . '"><TH ALIGN=left> ' . |
67 | '<TH ALIGN=left> ' . _("Name") . |
68 | '<TH ALIGN=left> ' . _("E-mail") . |
69 | '<TH ALIGN=left> ' . _("Info"); |
70 | |
71 | if ($includesource) { |
72 | echo '<TH ALIGN=left WIDTH="10%"> ' . _("Source"); |
73 | } |
74 | |
75 | echo "</TR>\n"; |
76 | |
77 | foreach ($res as $row) { |
78 | echo '<tr'; |
79 | if ($line % 2) { echo ' bgcolor="' . $color[0] . '"'; } |
80 | echo ' nowrap><td nowrap align=center width="5%">' . |
81 | '<input type=checkbox name="send_to_search[T' . $line . ']" value = "' . |
65a5bae6 |
82 | htmlspecialchars($row['email']) . '"> ' . _("To") . ' ' . |
00a065a6 |
83 | '<input type=checkbox name="send_to_search[C' . $line . ']" value = "' . |
65a5bae6 |
84 | htmlspecialchars($row['email']) . '"> ' . _("Cc") . ' ' . |
00a065a6 |
85 | '<input type=checkbox name="send_to_search[B' . $line . ']" value = "' . |
65a5bae6 |
86 | htmlspecialchars($row['email']) . '"> ' . _("Bcc") . ' ' . |
00a065a6 |
87 | '</td><td nowrap> ' . $row['name'] . ' </td>' . |
88 | '<td nowrap> ' . $row['email'] . ' </td>' . |
89 | '<td nowrap> ' . $row['label'] . ' </td>'; |
90 | if ($includesource) { |
91 | echo '<td nowrap> ' . $row['source'] . ' </td>'; |
92 | } |
93 | echo "</tr>\n"; |
94 | $line ++; |
95 | } |
96 | echo '<TR><TD ALIGN=center COLSPAN='; |
0b232d04 |
97 | if ($includesource) { echo '5'; } else { echo '4'; } |
00a065a6 |
98 | echo '><INPUT TYPE=submit NAME="addr_search_done" VALUE="' . |
99 | _("Use Addresses") . '"></TD></TR>' . |
100 | '</TABLE>' . |
101 | '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">' . |
102 | '</FORM>'; |
103 | } |
104 | |
105 | /* --- End functions --- */ |
106 | |
107 | global $mailbox; |
9c3e6cd4 |
108 | if ($compose_new_win == '1') { |
109 | compose_Header($color, $mailbox); |
110 | } |
111 | else { |
112 | displayPageHeader($color, $mailbox); |
113 | } |
00a065a6 |
114 | /* Initialize addressbook */ |
115 | $abook = addressbook_init(); |
c1e15177 |
116 | |
6e79bfe2 |
117 | ?> |
14f1b90b |
118 | |
6e79bfe2 |
119 | <br> |
bd9bbfef |
120 | <table width="95%" align=center cellpadding=2 cellspacing=2 border=0> |
6e79bfe2 |
121 | <tr><td bgcolor="<?php echo $color[0] ?>"> |
122 | <center><b><?php echo _("Address Book Search") ?></b></center> |
123 | </td></tr></table> |
14f1b90b |
124 | |
6e79bfe2 |
125 | <?php |
00a065a6 |
126 | |
127 | /* Search form */ |
128 | echo "<CENTER>\n<TABLE BORDER=0><TR><TD NOWRAP VALIGN=middle>\n" . |
129 | '<FORM METHOD=post NAME=f ACTION="' . $PHP_SELF . |
130 | '?html_addr_search=true">' . "\n<CENTER>\n" . |
131 | ' <nobr><STRONG>' . _("Search for") . "</STRONG>\n"; |
132 | addr_insert_hidden(); |
133 | if (! isset($addrquery)) |
134 | $addrquery = ''; |
135 | echo ' <INPUT TYPE=text NAME=addrquery VALUE="' . |
136 | htmlspecialchars($addrquery) . "\" SIZE=26>\n"; |
137 | |
138 | /* List all backends to allow the user to choose where to search */ |
139 | if (!isset($backend)) { $backend = ''; } |
140 | if ($abook->numbackends > 1) { |
141 | echo '<STRONG>' . _("in") . '</STRONG> <SELECT NAME=backend>' . "\n" . |
142 | '<OPTION VALUE=-1'; |
143 | if ($backend == -1) { echo ' SELECTED'; } |
144 | echo '>' . _("All address books") . "\n"; |
145 | $ret = $abook->get_backend_list(); |
146 | while (list($undef,$v) = each($ret)) { |
147 | echo '<OPTION VALUE=' . $v->bnum; |
148 | if ($backend == $v->bnum) { echo ' SELECTED'; } |
149 | echo '>' . $v->sname . "\n"; |
150 | } |
151 | echo "</SELECT>\n"; |
152 | } else { |
153 | echo '<INPUT TYPE=hidden NAME=backend VALUE=-1>' . "\n"; |
154 | } |
155 | echo '<INPUT TYPE=submit VALUE="' . _("Search") . '">' . |
156 | ' | <INPUT TYPE=submit VALUE="' . _("List all") . |
157 | '" NAME=listall>' . "\n" . |
158 | '</FORM></center></TD></TR></TABLE>' . "\n"; |
159 | addr_insert_hidden(); |
160 | echo '</CENTER>'; |
161 | do_hook('addrbook_html_search_below'); |
162 | /* End search form */ |
163 | |
164 | /* Show personal addressbook */ |
cc99433e |
165 | |
166 | if ( !empty( $listall ) ){ |
167 | $addrquery = '*'; |
168 | } |
169 | |
170 | if ($addrquery == '' && empty($listall)) { |
00a065a6 |
171 | |
172 | if (! isset($backend) || $backend != -1 || $addrquery == '') { |
173 | if ($addrquery == '') { |
6e79bfe2 |
174 | $backend = $abook->localbackend; |
00a065a6 |
175 | } |
14f1b90b |
176 | |
00a065a6 |
177 | /* echo '<H3 ALIGN=center>' . $abook->backends[$backend]->sname) . "</H3>\n"; */ |
14f1b90b |
178 | |
00a065a6 |
179 | $res = $abook->list_addr($backend); |
14f1b90b |
180 | |
00a065a6 |
181 | if (is_array($res)) { |
a10110a5 |
182 | usort($res,'alistcmp'); |
6e79bfe2 |
183 | addr_display_result($res, false); |
00a065a6 |
184 | } else { |
185 | echo '<P ALIGN=center><STRONG>' . |
186 | sprintf(_("Unable to list addresses from %s"), |
187 | $abook->backends[$backend]->sname) . |
188 | "</STRONG></P>\n"; |
189 | } |
190 | |
191 | } else { |
192 | $res = $abook->list_addr(); |
a10110a5 |
193 | usort($res,'alistcmp'); |
00a065a6 |
194 | addr_display_result($res, true); |
195 | } |
196 | exit; |
cc99433e |
197 | } |
198 | else { |
00a065a6 |
199 | |
200 | /* Do the search */ |
db48e3f5 |
201 | if (!empty($addrquery)) { |
00a065a6 |
202 | |
203 | if ($backend == -1) { |
204 | $res = $abook->s_search($addrquery); |
205 | } else { |
206 | $res = $abook->s_search($addrquery, $backend); |
207 | } |
208 | |
209 | if (!is_array($res)) { |
210 | echo '<P ALIGN=center><B><BR>' . |
211 | _("Your search failed with the following error(s)") . ':<br>' . |
212 | $abook->error . "</B></P>\n</BODY></HTML>\n"; |
213 | } else { |
214 | if (sizeof($res) == 0) { |
215 | echo '<P ALIGN=center><BR><B>' . |
216 | _("No persons matching your search was found") . |
217 | ".</B></P>\n</BODY></HTML>\n"; |
218 | } else { |
219 | addr_display_result($res); |
220 | } |
221 | } |
222 | } |
223 | } |
224 | |
225 | if ($addrquery == '' || sizeof($res) == 0) { |
226 | /* printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF); */ |
227 | echo '<center><FORM METHOD=post NAME=k ACTION="compose.php">' . "\n"; |
228 | addr_insert_hidden(); |
229 | echo '<INPUT TYPE=submit VALUE="' . _("Return") . '" NAME=return>' . "\n" . |
230 | '</form></center></nobr>'; |
231 | } |
6e79bfe2 |
232 | |
c1e15177 |
233 | ?> |
cc99433e |
234 | </body></html> |