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