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