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