Fix cancel button in HTML address book.
[squirrelmail.git] / src / addrbook_search_html.php
... / ...
CommitLineData
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 &copy; 1999-2006 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 */
22if (!isset($bInit)) {
23 include('../include/init.php');
24}
25
26/** SquirrelMail required files. */
27include_once(SM_PATH . 'functions/date.php');
28include_once(SM_PATH . 'functions/addressbook.php');
29include_once(SM_PATH . 'templates/util_addressbook.php');
30
31sqgetGlobalVar('session', $session, SQ_POST);
32sqgetGlobalVar('mailbox', $mailbox, SQ_POST);
33if (! sqgetGlobalVar('query', $addrquery, SQ_POST))
34 $addrquery='';
35sqgetGlobalVar('listall', $listall, SQ_POST);
36sqgetGlobalVar('backend', $backend, SQ_POST);
37
38/**
39 * Insert hidden data
40 */
41function addr_insert_hidden() {
42 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox,
43 $identity, $session;
44
45 if (substr($body, 0, 1) == "\r") {
46 echo addHidden('body', "\n".$body);
47 } else {
48 echo addHidden('body', $body);
49 }
50
51 echo addHidden('session', $session).
52 addHidden('subject', $subject).
53 addHidden('send_to', $send_to).
54 addHidden('send_to_bcc', $send_to_bcc).
55 addHidden('send_to_cc', $send_to_cc).
56 addHidden('identity', $identity).
57 addHidden('mailbox', $mailbox).
58 addHidden('from_htmladdr_search', 'true');
59}
60
61
62/**
63 * List search results
64 * @param array $res Array containing results of search
65 * @param bool $includesource If true, adds backend column to address listing
66 */
67function addr_display_result($res, $includesource = true) {
68 global $color, $javascript_on, $PHP_SELF, $squirrelmail_language;
69
70 global $oTemplate, $oErrorHandler;
71
72 if (sizeof($res) <= 0) return;
73
74 echo addForm($PHP_SELF, 'post', 'addressbook').
75 addHidden('html_addr_search_done', 'true');
76 addr_insert_hidden();
77
78 $oTemplate->assign('use_js', false);
79 $oTemplate->assign('include_abook_name', $includesource);
80 $oTemplate->assign('addresses', formatAddressList($res));
81
82 $oTemplate->display('addrbook_search_list.tpl');
83
84 echo '</form>';
85}
86
87/* --- End functions --- */
88
89if ($compose_new_win == '1') {
90 compose_Header($color, $mailbox);
91}
92else {
93 displayPageHeader($color, $mailbox);
94}
95
96/** set correct value of $default_charset */
97global $default_charset;
98set_my_charset();
99
100/* Initialize addressbook */
101$abook = addressbook_init();
102
103
104/* Search form */
105echo addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f');
106addr_insert_hidden();
107if (isset($session)) {
108 echo addHidden('session', $session);
109}
110
111$oTemplate->assign('use_js', false);
112$oTemplate->assign('backends', getBackends());
113
114$oTemplate->display('addressbook_search_form.tpl');
115
116echo "</form>\n";
117do_hook('addrbook_html_search_below');
118/* End search form */
119
120/* List addresses. Show personal addressbook */
121if ($addrquery == '' || ! empty($listall)) {
122 // TODO: recheck all conditions and simplity if statements
123 if (! isset($backend) || $backend != -1 || $addrquery == '') {
124 if ($addrquery == '' && empty($listall)) {
125 $backend = $abook->localbackend;
126 }
127
128 $res = $abook->list_addr($backend);
129
130 if (is_array($res)) {
131 usort($res,'alistcmp');
132 addr_display_result($res, false);
133 } else {
134 plain_error_message(_("Unable to list addresses from %s"), $abook->backends[$backend]->sname);
135 }
136
137 } else {
138 $res = $abook->list_addr();
139 usort($res,'alistcmp');
140 addr_display_result($res, true);
141 }
142 $oTemplate->display('footer.tpl');
143 exit;
144} elseif (!empty($addrquery)) {
145 /* Do the search */
146 if ($backend == -1) {
147 $res = $abook->s_search($addrquery);
148 } else {
149 $res = $abook->s_search($addrquery, $backend);
150 }
151
152 if (!is_array($res)) {
153 plain_error_message(_("Your search failed with the following error(s)") .':<br />'. nl2br(htmlspecialchars($abook->error)));
154 } elseif (sizeof($res) == 0) {
155 $oTemplate->assign('note', _("No persons matching your search were found"));
156 $oTemplate->display('note.tpl');
157 } else {
158 addr_display_result($res);
159 }
160} else {
161 // not first time display, not listall and search is empty
162 // TODO: I think, this part of control structure is never reached.
163 plain_error_message(_("Nothing to search"));
164}
165
166if ($addrquery == '' || sizeof($res) == 0) {
167 echo '<div style="text-align: center;">'.
168 addForm('compose.php','post','k');
169 addr_insert_hidden();
170 echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" .
171 '</form></div></nobr>';
172}
173
174echo '<hr />';
175
176$oTemplate->display('footer.tpl');
177?>