3 * addrbook_search_html.php
5 * Handle addressbook searching with pure html.
7 * This file is included from compose.php
9 * @copyright 1999-2011 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 /** This is the addrbook_search_html page */
24 define('PAGE_NAME', 'addrbook_search_html');
26 include('../include/init.php');
29 /** SquirrelMail required files. */
30 include_once(SM_PATH
. 'functions/date.php');
31 include_once(SM_PATH
. 'functions/addressbook.php');
32 include_once(SM_PATH
. 'templates/util_addressbook.php');
34 sqgetGlobalVar('session', $session, SQ_POST
);
35 sqgetGlobalVar('mailbox', $mailbox, SQ_POST
);
36 if (! sqgetGlobalVar('query', $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, $mailprio,
46 $request_mdn, $request_dr, $identity, $session, $composeMessage;
48 //FIXME Do not echo HTML from the core. This file already uses templates mostly, so why are we echoing here at all?!?
49 if (substr($body, 0, 1) == "\r") {
50 echo addHidden('body', "\n".$body);
52 echo addHidden('body', $body);
55 if (is_object($composeMessage) && $composeMessage->entities
)
56 echo addHidden('attachments', urlencode(serialize($composeMessage->entities
)));
58 echo addHidden('session', $session).
59 addHidden('subject', $subject).
60 addHidden('send_to', $send_to).
61 addHidden('send_to_bcc', $send_to_bcc).
62 addHidden('send_to_cc', $send_to_cc).
63 addHidden('mailprio', $mailprio).
64 addHidden('request_mdn', $request_mdn).
65 addHidden('request_dr', $request_dr).
66 addHidden('identity', $identity).
67 addHidden('mailbox', $mailbox).
68 addHidden('from_htmladdr_search', 'true');
74 * @param array $res Array containing results of search
75 * @param bool $includesource If true, adds backend column to address listing
77 function addr_display_result($res, $includesource = true) {
78 global $PHP_SELF, $oTemplate, $oErrorHandler;
81 //FIXME: no HTML output from core
82 echo addForm($PHP_SELF, 'post', 'addressbook', '', '', array(), TRUE).
83 addHidden('html_addr_search_done', 'true');
86 $oTemplate->assign('compose_addr_pop', false);
87 $oTemplate->assign('include_abook_name', $includesource);
88 $oTemplate->assign('addresses', formatAddressList($res));
90 $oTemplate->display('addrbook_search_list.tpl');
95 /* --- End functions --- */
97 if ($compose_new_win == '1') {
98 compose_Header($color, $mailbox);
101 displayPageHeader($color, $mailbox);
104 /** set correct value of $default_charset */
107 /* Initialize addressbook */
108 $abook = addressbook_init();
112 echo addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f');
113 addr_insert_hidden();
114 if (isset($session)) {
115 echo addHidden('session', $session);
118 $oTemplate->assign('compose_addr_pop', false);
119 $oTemplate->assign('backends', getBackends());
121 $oTemplate->display('addressbook_search_form.tpl');
124 do_hook('addrbook_html_search_below', $null);
125 /* End search form */
127 /* List addresses. Show personal addressbook */
128 if ($addrquery == '' ||
! empty($listall)) {
129 // TODO: recheck all conditions and simplity if statements
130 if (! isset($backend) ||
$backend != -1 ||
$addrquery == '') {
131 if ($addrquery == '' && empty($listall)) {
132 $backend = $abook->localbackend
;
135 $res = $abook->list_addr($backend);
137 if (is_array($res)) {
138 usort($res,'alistcmp');
139 addr_display_result($res, false);
141 plain_error_message(_("Unable to list addresses from %s"), $abook->backends
[$backend]->sname
);
145 $res = $abook->list_addr();
146 usort($res,'alistcmp');
147 addr_display_result($res, true);
149 $oTemplate->display('footer.tpl');
151 } elseif (!empty($addrquery)) {
153 if ($backend == -1) {
154 $res = $abook->s_search($addrquery);
156 $res = $abook->s_search($addrquery, $backend);
159 if (!is_array($res)) {
160 plain_error_message(_("Your search failed with the following error(s)") .':<br />'. nl2br(htmlspecialchars($abook->error
)));
161 } elseif (sizeof($res) == 0) {
162 $oTemplate->assign('note', _("No persons matching your search were found"));
163 $oTemplate->display('note.tpl');
165 addr_display_result($res);
168 // not first time display, not listall and search is empty
169 // TODO: I think, this part of control structure is never reached.
170 plain_error_message(_("Nothing to search"));
173 if ($addrquery == '' ||
sizeof($res) == 0) {
174 //FIXME don't echo HTML from core -- especially convoluted given that there is template code immediately above AND below this block
175 echo '<div style="text-align: center;">'.
176 addForm('compose.php','post','k', '', '', array(), TRUE);
177 addr_insert_hidden();
178 echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" .
179 '</form></div></nobr>';
184 $oTemplate->display('footer.tpl');