"Jason Munro" <jason@stdbev.com>
[squirrelmail.git] / src / addrbook_search_html.php
CommitLineData
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 20require_once('../src/validate.php');
21require_once('../functions/date.php');
22require_once('../functions/smtp.php');
23require_once('../functions/display_messages.php');
24require_once('../functions/addressbook.php');
25require_once('../functions/plugin.php');
5177fb2b 26require_once('../functions/strings.php');
c1e15177 27
00a065a6 28/* Insert hidden data */
29function 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";
14f1b90b 50 }
51
14f1b90b 52
00a065a6 53/* List search results */
54function 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
106global $mailbox;
107displayPageHeader($color, $mailbox);
108
109/* Initialize addressbook */
110$abook = addressbook_init();
c1e15177 111
6e79bfe2 112?>
14f1b90b 113
6e79bfe2 114<br>
bd9bbfef 115<table width="95%" align=center cellpadding=2 cellspacing=2 border=0>
6e79bfe2 116<tr><td bgcolor="<?php echo $color[0] ?>">
117 <center><b><?php echo _("Address Book Search") ?></b></center>
118</td></tr></table>
14f1b90b 119
6e79bfe2 120<?php
00a065a6 121
122/* Search form */
123echo "<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";
127addr_insert_hidden();
128if (! isset($addrquery))
129 $addrquery = '';
130echo ' <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 */
134if (!isset($backend)) { $backend = ''; }
135if ($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}
150echo '<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";
154addr_insert_hidden();
155echo '</CENTER>';
156do_hook('addrbook_html_search_below');
157/* End search form */
158
159/* Show personal addressbook */
160if ($addrquery == '' || !empty($listall)) {
161
162 if (! isset($backend) || $backend != -1 || $addrquery == '') {
163 if ($addrquery == '') {
6e79bfe2 164 $backend = $abook->localbackend;
00a065a6 165 }
14f1b90b 166
00a065a6 167 /* echo '<H3 ALIGN=center>' . $abook->backends[$backend]->sname) . "</H3>\n"; */
14f1b90b 168
00a065a6 169 $res = $abook->list_addr($backend);
14f1b90b 170
00a065a6 171 if (is_array($res)) {
a10110a5 172 usort($res,'alistcmp');
6e79bfe2 173 addr_display_result($res, false);
00a065a6 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();
a10110a5 183 usort($res,'alistcmp');
00a065a6 184 addr_display_result($res, true);
185 }
186 exit;
187
db48e3f5 188 if ( !empty( $listall ) ){
189 $addrquery = '*';
190 }
00a065a6 191} else {
192
193 /* Do the search */
db48e3f5 194 if (!empty($addrquery)) {
00a065a6 195
196 if ($backend == -1) {
197 $res = $abook->s_search($addrquery);
198 } else {
199 $res = $abook->s_search($addrquery, $backend);
200 }
201
202 if (!is_array($res)) {
203 echo '<P ALIGN=center><B><BR>' .
204 _("Your search failed with the following error(s)") . ':<br>' .
205 $abook->error . "</B></P>\n</BODY></HTML>\n";
206 } else {
207 if (sizeof($res) == 0) {
208 echo '<P ALIGN=center><BR><B>' .
209 _("No persons matching your search was found") .
210 ".</B></P>\n</BODY></HTML>\n";
211 } else {
212 addr_display_result($res);
213 }
214 }
215 }
216}
217
218if ($addrquery == '' || sizeof($res) == 0) {
219 /* printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF); */
220 echo '<center><FORM METHOD=post NAME=k ACTION="compose.php">' . "\n";
221 addr_insert_hidden();
222 echo '<INPUT TYPE=submit VALUE="' . _("Return") . '" NAME=return>' . "\n" .
223 '</form></center></nobr>';
224}
6e79bfe2 225
c1e15177 226?>
d7d3c4d4 227</body></html>