ac0be5609901293ef996935f7239efd147327d13
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];
120 echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) .
122 addCheckBox('send_to_search[T'.$line.']', FALSE, $email).
123 ' ' . _("To") . ' ' .
124 addCheckBox('send_to_search[C'.$line.']', FALSE, $email).
125 ' ' . _("Cc") . ' ' .
126 addCheckBox('send_to_search[B'.$line.']', FALSE, $email).
127 ' ' . _("Bcc") . ' ' ,
128 'center', '', 'width="5%" style="white-space: nowrap;"' ) .
129 html_tag( 'td', ' ' . htmlspecialchars($row['name']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) .
130 html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'style="white-space: nowrap;"' ) .
131 html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'style="white-space: nowrap;"' );
133 if ($includesource) {
134 echo html_tag( 'td', ' ' . $row['source'] . ' ', 'left', '', 'style="white-space: nowrap;"' );
139 if ($includesource) { $td_colspan = '5'; } else { $td_colspan = '4'; }
142 '<input type="submit" name="addr_search_done" value="' .
143 _("Use Addresses") . '" /> ' .
144 '<input type="submit" name="addr_search_cancel" value="' .
145 _("Cancel") . '" />',
146 'center', '', 'colspan="'. $td_colspan .'"' )
149 addHidden('html_addr_search_done', '1').
153 /* --- End functions --- */
155 if ($compose_new_win == '1') {
156 compose_Header($color, $mailbox);
159 displayPageHeader($color, $mailbox);
162 /** set correct value of $default_charset */
163 global $default_charset;
166 /* Initialize addressbook */
167 $abook = addressbook_init();
173 html_tag( 'td', '<b>' . _("Address Book Search") . '</b>', 'center', $color[0] )
175 'center', '', 'width="95%" cellpadding="2" cellspacing="2" border="0"' );
179 echo '<div style="text-align: center;">' .
180 html_tag( 'table', '', 'center', '', 'border="0"' ) .
182 html_tag( 'td', '', 'left', '', 'style="white-space: nowrap;" valign="middle"' ) . "\n" .
183 addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f').
184 "\n<div style=\"text-align: center;\">\n" .
185 ' <nobr><strong>' . _("Search for") . "</strong>\n";
186 addr_insert_hidden();
187 echo addInput('addrquery', $addrquery, 26);
189 /* List all backends to allow the user to choose where to search */
190 if (!isset($backend)) { $backend = ''; }
191 if ($abook->numbackends
> 1) {
192 echo '<strong>' . _("in") . '</strong> ';
194 $selopts['-1'] = _("All address books");
195 $ret = $abook->get_backend_list();
197 while (list($undef,$v) = each($ret)) {
198 $selopts[$v->bnum
] = $v->sname
;
200 echo addSelect('backend', $selopts, $backend, TRUE);
202 echo addHidden('backend', '-1');
204 if (isset($session)) {
205 echo addHidden('session', $session);
208 echo '<input type="submit" value="' . _("Search") . '" />' .
209 ' | <input type="submit" value="' . _("List all") .
210 '" name="listall" />' . "\n" .
211 '</form></div></td></tr></table>' . "\n";
213 do_hook('addrbook_html_search_below');
214 /* End search form */
216 /* List addresses. Show personal addressbook */
217 if ($addrquery == '' ||
! empty($listall)) {
218 // TODO: recheck all conditions and simplity if statements
219 if (! isset($backend) ||
$backend != -1 ||
$addrquery == '') {
220 if ($addrquery == '' && empty($listall)) {
221 $backend = $abook->localbackend
;
224 /* echo '<h3 align="center">' . $abook->backends[$backend]->sname) . "</h3>\n"; */
226 $res = $abook->list_addr($backend);
228 if (is_array($res)) {
229 usort($res,'alistcmp');
230 addr_display_result($res, false);
232 echo html_tag( 'p', '<strong><br />' .
233 sprintf(_("Unable to list addresses from %s"),
234 $abook->backends
[$backend]->sname
) . "</strong>\n" ,
239 $res = $abook->list_addr();
240 usort($res,'alistcmp');
241 addr_display_result($res, true);
243 $oTemplate->display('footer.tpl');
245 } elseif (!empty($addrquery)) {
247 if ($backend == -1) {
248 $res = $abook->s_search($addrquery);
250 $res = $abook->s_search($addrquery, $backend);
253 if (!is_array($res)) {
254 echo html_tag( 'p', '<b><br />' .
255 _("Your search failed with the following error(s)") .
256 ':<br />' . nl2br(htmlspecialchars($abook->error
)) . "</b>\n" ,
258 $oTemplate->display('footer.tpl');
260 if (sizeof($res) == 0) {
261 echo html_tag( 'p', '<br /><b>' .
262 _("No persons matching your search were found") . "</b>\n" ,
264 $oTemplate->display('footer.tpl');
266 addr_display_result($res);
270 // not first time display, not listall and search is empty
271 // TODO: I think, this part of control structure is never reached.
272 echo html_tag( 'p', '<br /><b>' .
273 _("Nothing to search") . "</b>\n" ,
277 if ($addrquery == '' ||
sizeof($res) == 0) {
278 echo '<div style="text-align: center;">'.
279 addForm('compose.php','post','k');
280 addr_insert_hidden();
281 echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" .
282 '</form></div></nobr>';
285 $oTemplate->display('footer.tpl');