3 * addrbook_search_html.php
5 * Handle addressbook searching with pure html.
7 * This file is included from compose.php
9 * @copyright © 1999-2005 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @package squirrelmail
13 * @subpackage addressbook
17 * Path for SquirrelMail required files.
20 if (! defined('SM_PATH') ) {
21 define('SM_PATH','../');
24 /** SquirrelMail required files. */
25 require_once(SM_PATH
. 'include/validate.php');
26 include_once(SM_PATH
. 'functions/global.php');
27 include_once(SM_PATH
. 'functions/date.php');
28 include_once(SM_PATH
. 'functions/display_messages.php');
29 include_once(SM_PATH
. 'functions/addressbook.php');
30 include_once(SM_PATH
. 'functions/plugin.php');
31 include_once(SM_PATH
. 'functions/strings.php');
32 include_once(SM_PATH
. 'functions/html.php');
34 sqgetGlobalVar('session', $session, SQ_POST
);
35 sqgetGlobalVar('mailbox', $mailbox, SQ_POST
);
36 if (! sqgetGlobalVar('addrquery', $addrquery, SQ_POST
))
38 sqgetGlobalVar('listall', $listall, SQ_POST
);
39 sqgetGlobalVar('backend', $backend, SQ_POST
);
44 function addr_insert_hidden() {
45 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox,
48 if (substr($body, 0, 1) == "\r") {
49 echo addHidden('body', "\n".$body);
51 echo addHidden('body', $body);
54 echo addHidden('session', $session).
55 addHidden('subject', $subject).
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');
67 * @param array $res Array containing results of search
68 * @param bool $includesource If true, adds backend column to address listing
70 function addr_display_result($res, $includesource = true) {
71 global $color, $javascript_on, $PHP_SELF, $squirrelmail_language;
73 if (sizeof($res) <= 0) return;
75 echo addForm($PHP_SELF, 'post', 'addrbook').
76 addHidden('html_addr_search_done', 'true');
82 '<script language="JavaScript" type="text/javascript">' .
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".
94 $chk_all = '<a href="#" onclick="CheckAll(\'T\');">'._("All").'</a> <font color="'.$color[9].'">'._("To").'</font>'.
96 '<a href="#" onclick="CheckAll(\'C\');">' . _("All") . '</a> <font color="'.$color[9].'">'._("Cc").'</font>'.
98 '<a href="#" onclick="CheckAll(\'B\');">' . _("All") . '</a>';
100 // check_all links are used only in JavaScript. disable links in js=off environment.
103 echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) .
104 html_tag( 'tr', '', '', $color[9] ) .
105 html_tag( 'th', ' ' . $chk_all, 'left' ) .
106 html_tag( 'th', ' ' . _("Name"), 'left' ) .
107 html_tag( 'th', ' ' . _("E-mail"), 'left' ) .
108 html_tag( 'th', ' ' . _("Info"), 'left' );
110 if ($includesource) {
111 echo html_tag( 'th', ' ' . _("Source"), 'left', '', 'width="10%"' );
116 foreach ($res as $row) {
117 $email = AddressBook
::full_address($row);
119 $tr_bgcolor = $color[12];
121 $tr_bgcolor = $color[4];
123 if ($squirrelmail_language == 'ja_JP')
125 echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) .
127 '<input type="checkbox" name="send_to_search[T' . $line . ']" value = "' .
128 htmlspecialchars($email) . '" /> ' . _("To") . ' ' .
129 '<input type="checkbox" name="send_to_search[C' . $line . ']" value = "' .
130 htmlspecialchars($email) . '" /> ' . _("Cc") . ' ' .
131 '<input type="checkbox" name="send_to_search[B' . $line . ']" value = "' .
132 htmlspecialchars($email) . '" /> ' . _("Bcc") . ' ' ,
133 'center', '', 'width="5%" style="white-space: nowrap;"' ) .
134 html_tag( 'td', ' ' . htmlspecialchars($row['lastname']) . ' ' . htmlspecialchars($row['firstname']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) .
135 html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) .
136 html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'style="white-space: nowrap;"' );
138 echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) .
140 addCheckBox('send_to_search[T'.$line.']', FALSE, $email).
141 ' ' . _("To") . ' ' .
142 addCheckBox('send_to_search[C'.$line.']', FALSE, $email).
143 ' ' . _("Cc") . ' ' .
144 addCheckBox('send_to_search[B'.$line.']', FALSE, $email).
145 ' ' . _("Bcc") . ' ' ,
146 'center', '', 'width="5%" style="white-space: nowrap;"' ) .
147 html_tag( 'td', ' ' . htmlspecialchars($row['name']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) .
148 html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) .
149 html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'style="white-space: nowrap;"' );
152 if ($includesource) {
153 echo html_tag( 'td', ' ' . $row['source'] . ' ', 'left', '', 'style="white-space: nowrap;"' );
158 if ($includesource) { $td_colspan = '5'; } else { $td_colspan = '4'; }
161 '<input type="submit" name="addr_search_done" value="' .
162 _("Use Addresses") . '" /> ' .
163 '<input type="submit" name="addr_search_cancel" value="' .
164 _("Cancel") . '" />',
165 'center', '', 'colspan="'. $td_colspan .'"' )
168 addHidden('html_addr_search_done', '1').
172 /* --- End functions --- */
174 if ($compose_new_win == '1') {
175 compose_Header($color, $mailbox);
178 displayPageHeader($color, $mailbox);
181 /** set correct value of $default_charset */
182 global $default_charset;
185 /* Initialize addressbook */
186 $abook = addressbook_init();
192 html_tag( 'td', '<b>' . _("Address Book Search") . '</b>', 'center', $color[0] )
194 'center', '', 'width="95%" cellpadding="2" cellspacing="2" border="0"' );
199 html_tag( 'table', '', 'center', '', 'border="0"' ) .
201 html_tag( 'td', '', 'left', '', 'style="white-space: nowrap;" valign="middle"' ) . "\n" .
202 addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f').
204 ' <nobr><strong>' . _("Search for") . "</strong>\n";
205 addr_insert_hidden();
206 echo addInput('addrquery', $addrquery, 26);
208 /* List all backends to allow the user to choose where to search */
209 if (!isset($backend)) { $backend = ''; }
210 if ($abook->numbackends
> 1) {
211 echo '<strong>' . _("in") . '</strong> ';
213 $selopts['-1'] = _("All address books");
214 $ret = $abook->get_backend_list();
216 while (list($undef,$v) = each($ret)) {
217 $selopts[$v->bnum
] = $v->sname
;
219 echo addSelect('backend', $selopts, $backend, TRUE);
221 echo addHidden('backend', '-1');
223 if (isset($session)) {
224 echo addHidden('session', $session);
227 echo '<input type="submit" value="' . _("Search") . '" />' .
228 ' | <input type="submit" value="' . _("List all") .
229 '" name="listall" />' . "\n" .
230 '</form></center></td></tr></table>' . "\n";
232 do_hook('addrbook_html_search_below');
233 /* End search form */
235 /* List addresses. Show personal addressbook */
236 if ($addrquery == '' ||
! empty($listall)) {
237 // TODO: recheck all conditions and simplity if statements
238 if (! isset($backend) ||
$backend != -1 ||
$addrquery == '') {
239 if ($addrquery == '' && empty($listall)) {
240 $backend = $abook->localbackend
;
243 /* echo '<h3 align="center">' . $abook->backends[$backend]->sname) . "</h3>\n"; */
245 $res = $abook->list_addr($backend);
247 if (is_array($res)) {
248 usort($res,'alistcmp');
249 addr_display_result($res, false);
251 echo html_tag( 'p', '<strong><br />' .
252 sprintf(_("Unable to list addresses from %s"),
253 $abook->backends
[$backend]->sname
) . "</strong>\n" ,
258 $res = $abook->list_addr();
259 usort($res,'alistcmp');
260 addr_display_result($res, true);
262 echo "\n</body></html>";
264 } elseif (!empty($addrquery)) {
266 if ($backend == -1) {
267 $res = $abook->s_search($addrquery);
269 $res = $abook->s_search($addrquery, $backend);
272 if (!is_array($res)) {
273 echo html_tag( 'p', '<b><br />' .
274 _("Your search failed with the following error(s)") .
275 ':<br />' . $abook->error
. "</b>\n" ,
277 "\n</body></html>\n";
279 if (sizeof($res) == 0) {
280 echo html_tag( 'p', '<br /><b>' .
281 _("No persons matching your search were found") . "</b>\n" ,
283 "\n</body></html>\n";
285 addr_display_result($res);
289 // not first time display, not listall and search is empty
290 // TODO: I think, this part of control structure is never reached.
291 echo html_tag( 'p', '<br /><b>' .
292 _("Nothing to search") . "</b>\n" ,
296 if ($addrquery == '' ||
sizeof($res) == 0) {
298 addForm('compose.php','post','k');
299 addr_insert_hidden();
300 echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" .
301 '</form></center></nobr>';