Fix issue with multi-part related messages not showing all attachments (#2830140).
[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-2009 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;
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 if (substr($body, 0, 1) == "\r") {
50 echo addHidden('body', "\n".$body);
51 } else {
52 echo addHidden('body', $body);
53 }
54
55 if (is_object($composeMessage) && $composeMessage->entities)
56 echo addHidden('attachments', urlencode(serialize($composeMessage->entities)));
57
58 echo addHidden('session', $session).
59 addHidden('subject', $subject).
60 addHidden('send_to', $send_to).
61 addHidden('send_to_bcc', $send_to_bcc).
62 addHidden('send_to_cc', $send_to_cc).
63 addHidden('mailprio', $mailprio).
64 addHidden('request_mdn', $request_mdn).
65 addHidden('request_dr', $request_dr).
66 addHidden('identity', $identity).
67 addHidden('mailbox', $mailbox).
68 addHidden('from_htmladdr_search', 'true');
69 }
70
71
72 /**
73 * List search results
74 * @param array $res Array containing results of search
75 * @param bool $includesource If true, adds backend column to address listing
76 */
77 function addr_display_result($res, $includesource = true) {
78 global $PHP_SELF, $oTemplate, $oErrorHandler;
79
80
81 //FIXME: no HTML output from core
82 echo addForm($PHP_SELF, 'post', 'addressbook', '', '', array(), TRUE).
83 addHidden('html_addr_search_done', 'true');
84 addr_insert_hidden();
85
86 $oTemplate->assign('compose_addr_pop', false);
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>';
93 }
94
95 /* --- End functions --- */
96
97 if ($compose_new_win == '1') {
98 compose_Header($color, $mailbox);
99 }
100 else {
101 displayPageHeader($color, $mailbox);
102 }
103
104 /** set correct value of $default_charset */
105 set_my_charset();
106
107 /* Initialize addressbook */
108 $abook = addressbook_init();
109
110
111 /* Search form */
112 echo addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f');
113 addr_insert_hidden();
114 if (isset($session)) {
115 echo addHidden('session', $session);
116 }
117
118 $oTemplate->assign('compose_addr_pop', false);
119 $oTemplate->assign('backends', getBackends());
120
121 $oTemplate->display('addressbook_search_form.tpl');
122
123 echo "</form>\n";
124 do_hook('addrbook_html_search_below', $null);
125 /* End search form */
126
127 /* List addresses. Show personal addressbook */
128 if ($addrquery == '' || ! empty($listall)) {
129 // TODO: recheck all conditions and simplity if statements
130 if (! isset($backend) || $backend != -1 || $addrquery == '') {
131 if ($addrquery == '' && empty($listall)) {
132 $backend = $abook->localbackend;
133 }
134
135 $res = $abook->list_addr($backend);
136
137 if (is_array($res)) {
138 usort($res,'alistcmp');
139 addr_display_result($res, false);
140 } else {
141 plain_error_message(_("Unable to list addresses from %s"), $abook->backends[$backend]->sname);
142 }
143
144 } else {
145 $res = $abook->list_addr();
146 usort($res,'alistcmp');
147 addr_display_result($res, true);
148 }
149 $oTemplate->display('footer.tpl');
150 exit;
151 } elseif (!empty($addrquery)) {
152 /* Do the search */
153 if ($backend == -1) {
154 $res = $abook->s_search($addrquery);
155 } else {
156 $res = $abook->s_search($addrquery, $backend);
157 }
158
159 if (!is_array($res)) {
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');
164 } else {
165 addr_display_result($res);
166 }
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.
170 plain_error_message(_("Nothing to search"));
171 }
172
173 if ($addrquery == '' || sizeof($res) == 0) {
174 //FIXME don't echo HTML from core -- especially convoluted given that there is template code immediately above AND below this block
175 echo '<div style="text-align: center;">'.
176 addForm('compose.php','post','k', '', '', array(), TRUE);
177 addr_insert_hidden();
178 echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" .
179 '</form></div></nobr>';
180 }
181
182 echo '<hr />';
183
184 $oTemplate->display('footer.tpl');