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