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