98cbe4ca35188386e39109d7c61115d8acf8a6a4
[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 require_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 }
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";
51 }
52
53
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>&nbsp;' .
67 '<TH ALIGN=left>&nbsp;' . _("Name") .
68 '<TH ALIGN=left>&nbsp;' . _("E-mail") .
69 '<TH ALIGN=left>&nbsp;' . _("Info");
70
71 if ($includesource) {
72 echo '<TH ALIGN=left WIDTH="10%">&nbsp;' . _("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 = "' .
82 htmlspecialchars($row['email']) . '">&nbsp;' . _("To") . '&nbsp;' .
83 '<input type=checkbox name="send_to_search[C' . $line . ']" value = "' .
84 htmlspecialchars($row['email']) . '">&nbsp;' . _("Cc") . '&nbsp;' .
85 '<input type=checkbox name="send_to_search[B' . $line . ']" value = "' .
86 htmlspecialchars($row['email']) . '">&nbsp;' . _("Bcc") . '&nbsp;' .
87 '</td><td nowrap>&nbsp;' . $row['name'] . '&nbsp;</td>' .
88 '<td nowrap>&nbsp;' . $row['email'] . '&nbsp;</td>' .
89 '<td nowrap>&nbsp;' . $row['label'] . '&nbsp;</td>';
90 if ($includesource) {
91 echo '<td nowrap>&nbsp;' . $row['source'] . '&nbsp;</td>';
92 }
93 echo "</tr>\n";
94 $line ++;
95 }
96 echo '<TR><TD ALIGN=center COLSPAN=';
97 if ($includesource) { echo '4'; } else { echo '5'; }
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;
108 displayPageHeader($color, $mailbox);
109
110 /* Initialize addressbook */
111 $abook = addressbook_init();
112
113 ?>
114
115 <br>
116 <table width="95%" align=center cellpadding=2 cellspacing=2 border=0>
117 <tr><td bgcolor="<?php echo $color[0] ?>">
118 <center><b><?php echo _("Address Book Search") ?></b></center>
119 </td></tr></table>
120
121 <?php
122
123 /* Search form */
124 echo "<CENTER>\n<TABLE BORDER=0><TR><TD NOWRAP VALIGN=middle>\n" .
125 '<FORM METHOD=post NAME=f ACTION="' . $PHP_SELF .
126 '?html_addr_search=true">' . "\n<CENTER>\n" .
127 ' <nobr><STRONG>' . _("Search for") . "</STRONG>\n";
128 addr_insert_hidden();
129 if (! isset($addrquery))
130 $addrquery = '';
131 echo ' <INPUT TYPE=text NAME=addrquery VALUE="' .
132 htmlspecialchars($addrquery) . "\" SIZE=26>\n";
133
134 /* List all backends to allow the user to choose where to search */
135 if (!isset($backend)) { $backend = ''; }
136 if ($abook->numbackends > 1) {
137 echo '<STRONG>' . _("in") . '</STRONG>&nbsp;<SELECT NAME=backend>' . "\n" .
138 '<OPTION VALUE=-1';
139 if ($backend == -1) { echo ' SELECTED'; }
140 echo '>' . _("All address books") . "\n";
141 $ret = $abook->get_backend_list();
142 while (list($undef,$v) = each($ret)) {
143 echo '<OPTION VALUE=' . $v->bnum;
144 if ($backend == $v->bnum) { echo ' SELECTED'; }
145 echo '>' . $v->sname . "\n";
146 }
147 echo "</SELECT>\n";
148 } else {
149 echo '<INPUT TYPE=hidden NAME=backend VALUE=-1>' . "\n";
150 }
151 echo '<INPUT TYPE=submit VALUE="' . _("Search") . '">' .
152 '&nbsp;|&nbsp;<INPUT TYPE=submit VALUE="' . _("List all") .
153 '" NAME=listall>' . "\n" .
154 '</FORM></center></TD></TR></TABLE>' . "\n";
155 addr_insert_hidden();
156 echo '</CENTER>';
157 do_hook('addrbook_html_search_below');
158 /* End search form */
159
160 /* Show personal addressbook */
161 if ($addrquery == '' || !empty($listall)) {
162
163 if (! isset($backend) || $backend != -1 || $addrquery == '') {
164 if ($addrquery == '') {
165 $backend = $abook->localbackend;
166 }
167
168 /* echo '<H3 ALIGN=center>' . $abook->backends[$backend]->sname) . "</H3>\n"; */
169
170 $res = $abook->list_addr($backend);
171
172 if (is_array($res)) {
173 usort($res,'alistcmp');
174 addr_display_result($res, false);
175 } else {
176 echo '<P ALIGN=center><STRONG>' .
177 sprintf(_("Unable to list addresses from %s"),
178 $abook->backends[$backend]->sname) .
179 "</STRONG></P>\n";
180 }
181
182 } else {
183 $res = $abook->list_addr();
184 usort($res,'alistcmp');
185 addr_display_result($res, true);
186 }
187 exit;
188
189 if ( !empty( $listall ) ){
190 $addrquery = '*';
191 }
192 } else {
193
194 /* Do the search */
195 if (!empty($addrquery)) {
196
197 if ($backend == -1) {
198 $res = $abook->s_search($addrquery);
199 } else {
200 $res = $abook->s_search($addrquery, $backend);
201 }
202
203 if (!is_array($res)) {
204 echo '<P ALIGN=center><B><BR>' .
205 _("Your search failed with the following error(s)") . ':<br>' .
206 $abook->error . "</B></P>\n</BODY></HTML>\n";
207 } else {
208 if (sizeof($res) == 0) {
209 echo '<P ALIGN=center><BR><B>' .
210 _("No persons matching your search was found") .
211 ".</B></P>\n</BODY></HTML>\n";
212 } else {
213 addr_display_result($res);
214 }
215 }
216 }
217 }
218
219 if ($addrquery == '' || sizeof($res) == 0) {
220 /* printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF); */
221 echo '<center><FORM METHOD=post NAME=k ACTION="compose.php">' . "\n";
222 addr_insert_hidden();
223 echo '<INPUT TYPE=submit VALUE="' . _("Return") . '" NAME=return>' . "\n" .
224 '</form></center></nobr>';
225 }
226
227 ?>
228 </body></html>