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