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