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