Allow HTML in option info
[squirrelmail.git] / src / addrbook_search_html.php
CommitLineData
c1e15177 1<?php
35586184 2/**
3 * addrbook_search_html.php
4 *
35586184 5 * Handle addressbook searching with pure html.
6 *
7 * This file is included from compose.php
8 *
22387c8d 9 * @copyright 1999-2017 The SquirrelMail Project Team
4b4abf93 10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
30967a1e 11 * @version $Id$
8f6f9ba5 12 * @package squirrelmail
de00443c 13 * @subpackage addressbook
35586184 14 */
c1e15177 15
91e0dccc 16/**
202bcbcc 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
20 * init.php.
30967a1e 21 */
202bcbcc 22if (!isset($bInit)) {
ebd2391c 23 /** This is the addrbook_search_html page */
24 define('PAGE_NAME', 'addrbook_search_html');
25
202bcbcc 26 include('../include/init.php');
abb3c512 27}
86725763 28
8f6f9ba5 29/** SquirrelMail required files. */
80945fcf 30include_once(SM_PATH . 'functions/date.php');
80945fcf 31include_once(SM_PATH . 'functions/addressbook.php');
3f92c0c7 32include_once(SM_PATH . 'templates/util_addressbook.php');
c1e15177 33
1e12d1ff 34sqgetGlobalVar('session', $session, SQ_POST);
35sqgetGlobalVar('mailbox', $mailbox, SQ_POST);
3f92c0c7 36if (! sqgetGlobalVar('query', $addrquery, SQ_POST))
80945fcf 37 $addrquery='';
1e12d1ff 38sqgetGlobalVar('listall', $listall, SQ_POST);
39sqgetGlobalVar('backend', $backend, SQ_POST);
0b97a708 40
8f6f9ba5 41/**
42 * Insert hidden data
43 */
00a065a6 44function addr_insert_hidden() {
1b70e7a5 45 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox, $mailprio,
1b15e6a5 46 $request_mdn, $request_dr, $identity, $session, $composeMessage, $action;
00a065a6 47
1b70e7a5 48//FIXME Do not echo HTML from the core. This file already uses templates mostly, so why are we echoing here at all?!?
65a5bae6 49 if (substr($body, 0, 1) == "\r") {
62366261 50 echo addHidden('body', "\n".$body);
51 } else {
52 echo addHidden('body', $body);
14f1b90b 53 }
54
1b70e7a5 55 if (is_object($composeMessage) && $composeMessage->entities)
e6d142e7 56 echo addHidden('attachments', urlencode(serialize($composeMessage->entities)));
1b70e7a5 57
62366261 58 echo addHidden('session', $session).
1b15e6a5 59 addHidden('smaction', $action).
62366261 60 addHidden('subject', $subject).
39bfea8f 61 addHidden('send_to', $send_to).
62 addHidden('send_to_bcc', $send_to_bcc).
63 addHidden('send_to_cc', $send_to_cc).
191042a9 64 addHidden('mailprio', $mailprio).
65 addHidden('request_mdn', $request_mdn).
66 addHidden('request_dr', $request_dr).
39bfea8f 67 addHidden('identity', $identity).
68 addHidden('mailbox', $mailbox).
69 addHidden('from_htmladdr_search', 'true');
62366261 70}
71
14f1b90b 72
8f6f9ba5 73/**
74 * List search results
75 * @param array $res Array containing results of search
c6f1c1ac 76 * @param bool $includesource If true, adds backend column to address listing
8f6f9ba5 77 */
00a065a6 78function addr_display_result($res, $includesource = true) {
856e58ef 79 global $PHP_SELF, $oTemplate, $oErrorHandler;
3f92c0c7 80
00a065a6 81
199a9ab8 82//FIXME: no HTML output from core
83 echo addForm($PHP_SELF, 'post', 'addressbook', '', '', array(), TRUE).
62366261 84 addHidden('html_addr_search_done', 'true');
00a065a6 85 addr_insert_hidden();
191042a9 86
0885e0d7 87 $oTemplate->assign('compose_addr_pop', false);
3f92c0c7 88 $oTemplate->assign('include_abook_name', $includesource);
89 $oTemplate->assign('addresses', formatAddressList($res));
90
91 $oTemplate->display('addrbook_search_list.tpl');
92
93 echo '</form>';
00a065a6 94}
95
96/* --- End functions --- */
97
9c3e6cd4 98if ($compose_new_win == '1') {
99 compose_Header($color, $mailbox);
100}
101else {
102 displayPageHeader($color, $mailbox);
103}
40262494 104
105/** set correct value of $default_charset */
40262494 106set_my_charset();
107
00a065a6 108/* Initialize addressbook */
109$abook = addressbook_init();
c1e15177 110
14f1b90b 111
00a065a6 112/* Search form */
3f92c0c7 113echo addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f');
00a065a6 114addr_insert_hidden();
6a12032e 115if (isset($session)) {
62366261 116 echo addHidden('session', $session);
6a12032e 117}
118
0885e0d7 119$oTemplate->assign('compose_addr_pop', false);
3f92c0c7 120$oTemplate->assign('backends', getBackends());
121
122$oTemplate->display('addressbook_search_form.tpl');
123
124echo "</form>\n";
6e515418 125do_hook('addrbook_html_search_below', $null);
00a065a6 126/* End search form */
127
80945fcf 128/* List addresses. Show personal addressbook */
129if ($addrquery == '' || ! empty($listall)) {
130 // TODO: recheck all conditions and simplity if statements
00a065a6 131 if (! isset($backend) || $backend != -1 || $addrquery == '') {
80945fcf 132 if ($addrquery == '' && empty($listall)) {
6e79bfe2 133 $backend = $abook->localbackend;
00a065a6 134 }
14f1b90b 135
00a065a6 136 $res = $abook->list_addr($backend);
14f1b90b 137
00a065a6 138 if (is_array($res)) {
a10110a5 139 usort($res,'alistcmp');
6e79bfe2 140 addr_display_result($res, false);
00a065a6 141 } else {
3f92c0c7 142 plain_error_message(_("Unable to list addresses from %s"), $abook->backends[$backend]->sname);
00a065a6 143 }
144
145 } else {
146 $res = $abook->list_addr();
a10110a5 147 usort($res,'alistcmp');
00a065a6 148 addr_display_result($res, true);
149 }
879e86ec 150 $oTemplate->display('footer.tpl');
00a065a6 151 exit;
80945fcf 152} elseif (!empty($addrquery)) {
00a065a6 153 /* Do the search */
80945fcf 154 if ($backend == -1) {
155 $res = $abook->s_search($addrquery);
156 } else {
157 $res = $abook->s_search($addrquery, $backend);
158 }
00a065a6 159
80945fcf 160 if (!is_array($res)) {
3047e291 161 plain_error_message(_("Your search failed with the following error(s)") .':<br />'. nl2br(sm_encode_html_special_chars($abook->error)));
3f92c0c7 162 } elseif (sizeof($res) == 0) {
163 $oTemplate->assign('note', _("No persons matching your search were found"));
164 $oTemplate->display('note.tpl');
80945fcf 165 } else {
3f92c0c7 166 addr_display_result($res);
00a065a6 167 }
80945fcf 168} else {
169 // not first time display, not listall and search is empty
170 // TODO: I think, this part of control structure is never reached.
3f92c0c7 171 plain_error_message(_("Nothing to search"));
00a065a6 172}
173
174if ($addrquery == '' || sizeof($res) == 0) {
1b70e7a5 175//FIXME don't echo HTML from core -- especially convoluted given that there is template code immediately above AND below this block
f265009a 176 echo '<div style="text-align: center;">'.
199a9ab8 177 addForm('compose.php','post','k', '', '', array(), TRUE);
00a065a6 178 addr_insert_hidden();
39bfea8f 179 echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" .
f265009a 180 '</form></div></nobr>';
00a065a6 181}
879e86ec 182
3f92c0c7 183echo '<hr />';
184
5c4ff7bf 185$oTemplate->display('footer.tpl');