Happy New Year
[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 *
c4faef33 9 * @copyright 1999-2020 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?!?
69e110f3 49 // someone tell me why this is needed and if so, why it isn't something like replace \r\n with \n
50 // if (substr($body, 0, 1) == "\r") {
51 // echo addHidden('body', "\n".$body);
52 // } else {
62366261 53 echo addHidden('body', $body);
69e110f3 54 // }
14f1b90b 55
1b70e7a5 56 if (is_object($composeMessage) && $composeMessage->entities)
e6d142e7 57 echo addHidden('attachments', urlencode(serialize($composeMessage->entities)));
1b70e7a5 58
62366261 59 echo addHidden('session', $session).
1b15e6a5 60 addHidden('smaction', $action).
62366261 61 addHidden('subject', $subject).
39bfea8f 62 addHidden('send_to', $send_to).
63 addHidden('send_to_bcc', $send_to_bcc).
64 addHidden('send_to_cc', $send_to_cc).
191042a9 65 addHidden('mailprio', $mailprio).
66 addHidden('request_mdn', $request_mdn).
67 addHidden('request_dr', $request_dr).
39bfea8f 68 addHidden('identity', $identity).
69 addHidden('mailbox', $mailbox).
70 addHidden('from_htmladdr_search', 'true');
62366261 71}
72
14f1b90b 73
8f6f9ba5 74/**
75 * List search results
76 * @param array $res Array containing results of search
c6f1c1ac 77 * @param bool $includesource If true, adds backend column to address listing
8f6f9ba5 78 */
00a065a6 79function addr_display_result($res, $includesource = true) {
856e58ef 80 global $PHP_SELF, $oTemplate, $oErrorHandler;
3f92c0c7 81
00a065a6 82
199a9ab8 83//FIXME: no HTML output from core
84 echo addForm($PHP_SELF, 'post', 'addressbook', '', '', array(), TRUE).
62366261 85 addHidden('html_addr_search_done', 'true');
00a065a6 86 addr_insert_hidden();
191042a9 87
0885e0d7 88 $oTemplate->assign('compose_addr_pop', false);
3f92c0c7 89 $oTemplate->assign('include_abook_name', $includesource);
90 $oTemplate->assign('addresses', formatAddressList($res));
91
92 $oTemplate->display('addrbook_search_list.tpl');
93
94 echo '</form>';
00a065a6 95}
96
97/* --- End functions --- */
98
9c3e6cd4 99if ($compose_new_win == '1') {
100 compose_Header($color, $mailbox);
101}
102else {
103 displayPageHeader($color, $mailbox);
104}
40262494 105
106/** set correct value of $default_charset */
40262494 107set_my_charset();
108
00a065a6 109/* Initialize addressbook */
110$abook = addressbook_init();
c1e15177 111
14f1b90b 112
00a065a6 113/* Search form */
3f92c0c7 114echo addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f');
00a065a6 115addr_insert_hidden();
6a12032e 116if (isset($session)) {
62366261 117 echo addHidden('session', $session);
6a12032e 118}
119
0885e0d7 120$oTemplate->assign('compose_addr_pop', false);
3f92c0c7 121$oTemplate->assign('backends', getBackends());
122
123$oTemplate->display('addressbook_search_form.tpl');
124
125echo "</form>\n";
6e515418 126do_hook('addrbook_html_search_below', $null);
00a065a6 127/* End search form */
128
80945fcf 129/* List addresses. Show personal addressbook */
130if ($addrquery == '' || ! empty($listall)) {
131 // TODO: recheck all conditions and simplity if statements
00a065a6 132 if (! isset($backend) || $backend != -1 || $addrquery == '') {
80945fcf 133 if ($addrquery == '' && empty($listall)) {
6e79bfe2 134 $backend = $abook->localbackend;
00a065a6 135 }
14f1b90b 136
00a065a6 137 $res = $abook->list_addr($backend);
14f1b90b 138
00a065a6 139 if (is_array($res)) {
a10110a5 140 usort($res,'alistcmp');
6e79bfe2 141 addr_display_result($res, false);
00a065a6 142 } else {
3f92c0c7 143 plain_error_message(_("Unable to list addresses from %s"), $abook->backends[$backend]->sname);
00a065a6 144 }
145
146 } else {
147 $res = $abook->list_addr();
a10110a5 148 usort($res,'alistcmp');
00a065a6 149 addr_display_result($res, true);
150 }
879e86ec 151 $oTemplate->display('footer.tpl');
00a065a6 152 exit;
80945fcf 153} elseif (!empty($addrquery)) {
00a065a6 154 /* Do the search */
80945fcf 155 if ($backend == -1) {
156 $res = $abook->s_search($addrquery);
157 } else {
158 $res = $abook->s_search($addrquery, $backend);
159 }
00a065a6 160
80945fcf 161 if (!is_array($res)) {
3047e291 162 plain_error_message(_("Your search failed with the following error(s)") .':<br />'. nl2br(sm_encode_html_special_chars($abook->error)));
3f92c0c7 163 } elseif (sizeof($res) == 0) {
164 $oTemplate->assign('note', _("No persons matching your search were found"));
165 $oTemplate->display('note.tpl');
80945fcf 166 } else {
3f92c0c7 167 addr_display_result($res);
00a065a6 168 }
80945fcf 169} else {
170 // not first time display, not listall and search is empty
171 // TODO: I think, this part of control structure is never reached.
3f92c0c7 172 plain_error_message(_("Nothing to search"));
00a065a6 173}
174
175if ($addrquery == '' || sizeof($res) == 0) {
1b70e7a5 176//FIXME don't echo HTML from core -- especially convoluted given that there is template code immediately above AND below this block
f265009a 177 echo '<div style="text-align: center;">'.
199a9ab8 178 addForm('compose.php','post','k', '', '', array(), TRUE);
00a065a6 179 addr_insert_hidden();
39bfea8f 180 echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" .
f265009a 181 '</form></div></nobr>';
00a065a6 182}
879e86ec 183
3f92c0c7 184echo '<hr />';
185
5c4ff7bf 186$oTemplate->display('footer.tpl');