3 * addrbook_search_html.php
5 * Handle addressbook searching with pure html.
7 * This file is included from compose.php
9 * @copyright © 1999-2006 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @package squirrelmail
13 * @subpackage addressbook
17 * Include the SquirrelMail initialization file.
18 * Because this file can also be included within compose we check for the $bInit
19 * var which is set inside ini.php. It's needed because compose already includes
23 include('../include/init.php');
26 /** SquirrelMail required files. */
27 include_once(SM_PATH
. 'functions/date.php');
28 include_once(SM_PATH
. 'functions/addressbook.php');
30 sqgetGlobalVar('session', $session, SQ_POST
);
31 sqgetGlobalVar('mailbox', $mailbox, SQ_POST
);
32 if (! sqgetGlobalVar('addrquery', $addrquery, SQ_POST
))
34 sqgetGlobalVar('listall', $listall, SQ_POST
);
35 sqgetGlobalVar('backend', $backend, SQ_POST
);
40 function addr_insert_hidden() {
41 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox,
44 if (substr($body, 0, 1) == "\r") {
45 echo addHidden('body', "\n".$body);
47 echo addHidden('body', $body);
50 echo addHidden('session', $session).
51 addHidden('subject', $subject).
52 addHidden('send_to', $send_to).
53 addHidden('send_to_bcc', $send_to_bcc).
54 addHidden('send_to_cc', $send_to_cc).
55 addHidden('identity', $identity).
56 addHidden('mailbox', $mailbox).
57 addHidden('from_htmladdr_search', 'true');
63 * @param array $res Array containing results of search
64 * @param bool $includesource If true, adds backend column to address listing
66 function addr_display_result($res, $includesource = true) {
67 global $color, $javascript_on, $PHP_SELF, $squirrelmail_language;
69 if (sizeof($res) <= 0) return;
71 echo addForm($PHP_SELF, 'post', 'addrbook').
72 addHidden('html_addr_search_done', 'true');
78 '<script type="text/javascript">' .
80 "function CheckAll(ch) {\n" .
81 " for (var i = 0; i < document.addrbook.elements.length; i++) {\n" .
82 " if( document.addrbook.elements[i].type == 'checkbox' &&\n" .
83 " document.addrbook.elements[i].name.substr(0,16) == 'send_to_search['+ch ) {\n" .
84 " document.addrbook.elements[i].checked = !(document.addrbook.elements[i].checked);\n".
90 $chk_all = '<a href="#" onclick="CheckAll(\'T\');">'._("All").'</a> <font color="'.$color[9].'">'._("To").'</font>'.
92 '<a href="#" onclick="CheckAll(\'C\');">' . _("All") . '</a> <font color="'.$color[9].'">'._("Cc").'</font>'.
94 '<a href="#" onclick="CheckAll(\'B\');">' . _("All") . '</a>';
96 // check_all links are used only in JavaScript. disable links in js=off environment.
99 echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) .
100 html_tag( 'tr', '', '', $color[9] ) .
101 html_tag( 'th', ' ' . $chk_all, 'left' ) .
102 html_tag( 'th', ' ' . _("Name"), 'left' ) .
103 html_tag( 'th', ' ' . _("E-mail"), 'left' ) .
104 html_tag( 'th', ' ' . _("Info"), 'left' );
106 if ($includesource) {
107 echo html_tag( 'th', ' ' . _("Source"), 'left', '', 'width="10%"' );
112 foreach ($res as $row) {
113 $email = AddressBook
::full_address($row);
115 $tr_bgcolor = $color[12];
117 $tr_bgcolor = $color[4];
119 if ($squirrelmail_language == 'ja_JP')
121 echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) .
123 '<input type="checkbox" name="send_to_search[T' . $line . ']" value = "' .
124 htmlspecialchars($email) . '" /> ' . _("To") . ' ' .
125 '<input type="checkbox" name="send_to_search[C' . $line . ']" value = "' .
126 htmlspecialchars($email) . '" /> ' . _("Cc") . ' ' .
127 '<input type="checkbox" name="send_to_search[B' . $line . ']" value = "' .
128 htmlspecialchars($email) . '" /> ' . _("Bcc") . ' ' ,
129 'center', '', 'width="5%" style="white-space: nowrap;"' ) .
130 html_tag( 'td', ' ' . htmlspecialchars($row['lastname']) . ' ' . htmlspecialchars($row['firstname']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) .
131 html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) .
132 html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'style="white-space: nowrap;"' );
134 echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) .
136 addCheckBox('send_to_search[T'.$line.']', FALSE, $email).
137 ' ' . _("To") . ' ' .
138 addCheckBox('send_to_search[C'.$line.']', FALSE, $email).
139 ' ' . _("Cc") . ' ' .
140 addCheckBox('send_to_search[B'.$line.']', FALSE, $email).
141 ' ' . _("Bcc") . ' ' ,
142 'center', '', 'width="5%" style="white-space: nowrap;"' ) .
143 html_tag( 'td', ' ' . htmlspecialchars($row['name']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) .
144 html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) .
145 html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'style="white-space: nowrap;"' );
148 if ($includesource) {
149 echo html_tag( 'td', ' ' . $row['source'] . ' ', 'left', '', 'style="white-space: nowrap;"' );
154 if ($includesource) { $td_colspan = '5'; } else { $td_colspan = '4'; }
157 '<input type="submit" name="addr_search_done" value="' .
158 _("Use Addresses") . '" /> ' .
159 '<input type="submit" name="addr_search_cancel" value="' .
160 _("Cancel") . '" />',
161 'center', '', 'colspan="'. $td_colspan .'"' )
164 addHidden('html_addr_search_done', '1').
168 /* --- End functions --- */
170 if ($compose_new_win == '1') {
171 compose_Header($color, $mailbox);
174 displayPageHeader($color, $mailbox);
177 /** set correct value of $default_charset */
178 global $default_charset;
181 /* Initialize addressbook */
182 $abook = addressbook_init();
188 html_tag( 'td', '<b>' . _("Address Book Search") . '</b>', 'center', $color[0] )
190 'center', '', 'width="95%" cellpadding="2" cellspacing="2" border="0"' );
194 echo '<div style="text-align: center;">' .
195 html_tag( 'table', '', 'center', '', 'border="0"' ) .
197 html_tag( 'td', '', 'left', '', 'style="white-space: nowrap;" valign="middle"' ) . "\n" .
198 addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f').
199 "\n<div style=\"text-align: center;\">\n" .
200 ' <nobr><strong>' . _("Search for") . "</strong>\n";
201 addr_insert_hidden();
202 echo addInput('addrquery', $addrquery, 26);
204 /* List all backends to allow the user to choose where to search */
205 if (!isset($backend)) { $backend = ''; }
206 if ($abook->numbackends
> 1) {
207 echo '<strong>' . _("in") . '</strong> ';
209 $selopts['-1'] = _("All address books");
210 $ret = $abook->get_backend_list();
212 while (list($undef,$v) = each($ret)) {
213 $selopts[$v->bnum
] = $v->sname
;
215 echo addSelect('backend', $selopts, $backend, TRUE);
217 echo addHidden('backend', '-1');
219 if (isset($session)) {
220 echo addHidden('session', $session);
223 echo '<input type="submit" value="' . _("Search") . '" />' .
224 ' | <input type="submit" value="' . _("List all") .
225 '" name="listall" />' . "\n" .
226 '</form></div></td></tr></table>' . "\n";
228 do_hook('addrbook_html_search_below');
229 /* End search form */
231 /* List addresses. Show personal addressbook */
232 if ($addrquery == '' ||
! empty($listall)) {
233 // TODO: recheck all conditions and simplity if statements
234 if (! isset($backend) ||
$backend != -1 ||
$addrquery == '') {
235 if ($addrquery == '' && empty($listall)) {
236 $backend = $abook->localbackend
;
239 /* echo '<h3 align="center">' . $abook->backends[$backend]->sname) . "</h3>\n"; */
241 $res = $abook->list_addr($backend);
243 if (is_array($res)) {
244 usort($res,'alistcmp');
245 addr_display_result($res, false);
247 echo html_tag( 'p', '<strong><br />' .
248 sprintf(_("Unable to list addresses from %s"),
249 $abook->backends
[$backend]->sname
) . "</strong>\n" ,
254 $res = $abook->list_addr();
255 usort($res,'alistcmp');
256 addr_display_result($res, true);
258 $oTemplate->display('footer.tpl');
260 } elseif (!empty($addrquery)) {
262 if ($backend == -1) {
263 $res = $abook->s_search($addrquery);
265 $res = $abook->s_search($addrquery, $backend);
268 if (!is_array($res)) {
269 echo html_tag( 'p', '<b><br />' .
270 _("Your search failed with the following error(s)") .
271 ':<br />' . $abook->error
. "</b>\n" ,
273 $oTemplate->display('footer.tpl');
275 if (sizeof($res) == 0) {
276 echo html_tag( 'p', '<br /><b>' .
277 _("No persons matching your search were found") . "</b>\n" ,
279 $oTemplate->display('footer.tpl');
281 addr_display_result($res);
285 // not first time display, not listall and search is empty
286 // TODO: I think, this part of control structure is never reached.
287 echo html_tag( 'p', '<br /><b>' .
288 _("Nothing to search") . "</b>\n" ,
292 if ($addrquery == '' ||
sizeof($res) == 0) {
293 echo '<div style="text-align: center;">'.
294 addForm('compose.php','post','k');
295 addr_insert_hidden();
296 echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" .
297 '</form></div></nobr>';
300 $oTemplate->display('footer.tpl');