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