</body></html> footer.tpl replacements
[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 &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 * Path for SquirrelMail required files.
18 * @ignore
19 */
20 if (! defined('SM_PATH') ) {
21 define('SM_PATH','../');
22 }
23
24 /** SquirrelMail required files. */
25 include_once(SM_PATH . 'include/validate.php');
26 include_once(SM_PATH . 'functions/global.php');
27 include_once(SM_PATH . 'functions/date.php');
28 include_once(SM_PATH . 'functions/display_messages.php');
29 include_once(SM_PATH . 'functions/addressbook.php');
30 include_once(SM_PATH . 'functions/plugin.php');
31 include_once(SM_PATH . 'functions/strings.php');
32 include_once(SM_PATH . 'functions/html.php');
33
34 sqgetGlobalVar('session', $session, SQ_POST);
35 sqgetGlobalVar('mailbox', $mailbox, SQ_POST);
36 if (! sqgetGlobalVar('addrquery', $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,
46 $identity, $session;
47
48 if (substr($body, 0, 1) == "\r") {
49 echo addHidden('body', "\n".$body);
50 } else {
51 echo addHidden('body', $body);
52 }
53
54 echo addHidden('session', $session).
55 addHidden('subject', $subject).
56 addHidden('send_to', $send_to).
57 addHidden('send_to_bcc', $send_to_bcc).
58 addHidden('send_to_cc', $send_to_cc).
59 addHidden('identity', $identity).
60 addHidden('mailbox', $mailbox).
61 addHidden('from_htmladdr_search', 'true');
62 }
63
64
65 /**
66 * List search results
67 * @param array $res Array containing results of search
68 * @param bool $includesource If true, adds backend column to address listing
69 */
70 function addr_display_result($res, $includesource = true) {
71 global $color, $javascript_on, $PHP_SELF, $squirrelmail_language;
72
73 if (sizeof($res) <= 0) return;
74
75 echo addForm($PHP_SELF, 'post', 'addrbook').
76 addHidden('html_addr_search_done', 'true');
77 addr_insert_hidden();
78 $line = 0;
79
80 if ($javascript_on) {
81 print
82 '<script language="JavaScript" type="text/javascript">' .
83 "\n<!-- \n" .
84 "function CheckAll(ch) {\n" .
85 " for (var i = 0; i < document.addrbook.elements.length; i++) {\n" .
86 " if( document.addrbook.elements[i].type == 'checkbox' &&\n" .
87 " document.addrbook.elements[i].name.substr(0,16) == 'send_to_search['+ch ) {\n" .
88 " document.addrbook.elements[i].checked = !(document.addrbook.elements[i].checked);\n".
89 " }\n" .
90 " }\n" .
91 "}\n" .
92 "//-->\n" .
93 "</script>\n";
94 $chk_all = '<a href="#" onclick="CheckAll(\'T\');">'._("All").'</a>&nbsp;<font color="'.$color[9].'">'._("To").'</font>'.
95 '&nbsp;&nbsp;'.
96 '<a href="#" onclick="CheckAll(\'C\');">' . _("All") . '</a>&nbsp;<font color="'.$color[9].'">'._("Cc").'</font>'.
97 '&nbsp;&nbsp;'.
98 '<a href="#" onclick="CheckAll(\'B\');">' . _("All") . '</a>';
99 } else {
100 // check_all links are used only in JavaScript. disable links in js=off environment.
101 $chk_all = '';
102 }
103 echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) .
104 html_tag( 'tr', '', '', $color[9] ) .
105 html_tag( 'th', '&nbsp;' . $chk_all, 'left' ) .
106 html_tag( 'th', '&nbsp;' . _("Name"), 'left' ) .
107 html_tag( 'th', '&nbsp;' . _("E-mail"), 'left' ) .
108 html_tag( 'th', '&nbsp;' . _("Info"), 'left' );
109
110 if ($includesource) {
111 echo html_tag( 'th', '&nbsp;' . _("Source"), 'left', '', 'width="10%"' );
112 }
113
114 echo "</tr>\n";
115
116 foreach ($res as $row) {
117 $email = AddressBook::full_address($row);
118 if ($line % 2) {
119 $tr_bgcolor = $color[12];
120 } else {
121 $tr_bgcolor = $color[4];
122 }
123 if ($squirrelmail_language == 'ja_JP')
124 {
125 echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) .
126 html_tag( 'td',
127 '<input type="checkbox" name="send_to_search[T' . $line . ']" value = "' .
128 htmlspecialchars($email) . '" />&nbsp;' . _("To") . '&nbsp;' .
129 '<input type="checkbox" name="send_to_search[C' . $line . ']" value = "' .
130 htmlspecialchars($email) . '" />&nbsp;' . _("Cc") . '&nbsp;' .
131 '<input type="checkbox" name="send_to_search[B' . $line . ']" value = "' .
132 htmlspecialchars($email) . '" />&nbsp;' . _("Bcc") . '&nbsp;' ,
133 'center', '', 'width="5%" style="white-space: nowrap;"' ) .
134 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['lastname']) . ' ' . htmlspecialchars($row['firstname']) . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' ) .
135 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['email']) . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' ) .
136 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['label']) . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' );
137 } else {
138 echo html_tag( 'tr', '', '', $tr_bgcolor, 'style="white-space: nowrap;"' ) .
139 html_tag( 'td',
140 addCheckBox('send_to_search[T'.$line.']', FALSE, $email).
141 '&nbsp;' . _("To") . '&nbsp;' .
142 addCheckBox('send_to_search[C'.$line.']', FALSE, $email).
143 '&nbsp;' . _("Cc") . '&nbsp;' .
144 addCheckBox('send_to_search[B'.$line.']', FALSE, $email).
145 '&nbsp;' . _("Bcc") . '&nbsp;' ,
146 'center', '', 'width="5%" style="white-space: nowrap;"' ) .
147 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['name']) . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' ) .
148 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['email']) . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' ) .
149 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['label']) . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' );
150 }
151
152 if ($includesource) {
153 echo html_tag( 'td', '&nbsp;' . $row['source'] . '&nbsp;', 'left', '', 'style="white-space: nowrap;"' );
154 }
155 echo "</tr>\n";
156 $line ++;
157 }
158 if ($includesource) { $td_colspan = '5'; } else { $td_colspan = '4'; }
159 echo html_tag( 'tr',
160 html_tag( 'td',
161 '<input type="submit" name="addr_search_done" value="' .
162 _("Use Addresses") . '" /> ' .
163 '<input type="submit" name="addr_search_cancel" value="' .
164 _("Cancel") . '" />',
165 'center', '', 'colspan="'. $td_colspan .'"' )
166 ) .
167 '</table>' .
168 addHidden('html_addr_search_done', '1').
169 '</form>';
170 }
171
172 /* --- End functions --- */
173
174 if ($compose_new_win == '1') {
175 compose_Header($color, $mailbox);
176 }
177 else {
178 displayPageHeader($color, $mailbox);
179 }
180
181 /** set correct value of $default_charset */
182 global $default_charset;
183 set_my_charset();
184
185 /* Initialize addressbook */
186 $abook = addressbook_init();
187
188
189 echo '<br />' .
190 html_tag( 'table',
191 html_tag( 'tr',
192 html_tag( 'td', '<b>' . _("Address Book Search") . '</b>', 'center', $color[0] )
193 ) ,
194 'center', '', 'width="95%" cellpadding="2" cellspacing="2" border="0"' );
195
196
197 /* Search form */
198 echo '<center>' .
199 html_tag( 'table', '', 'center', '', 'border="0"' ) .
200 html_tag( 'tr' ) .
201 html_tag( 'td', '', 'left', '', 'style="white-space: nowrap;" valign="middle"' ) . "\n" .
202 addForm($PHP_SELF.'?html_addr_search=true', 'post', 'f').
203 "\n<center>\n" .
204 ' <nobr><strong>' . _("Search for") . "</strong>\n";
205 addr_insert_hidden();
206 echo addInput('addrquery', $addrquery, 26);
207
208 /* List all backends to allow the user to choose where to search */
209 if (!isset($backend)) { $backend = ''; }
210 if ($abook->numbackends > 1) {
211 echo '<strong>' . _("in") . '</strong>&nbsp;';
212
213 $selopts['-1'] = _("All address books");
214 $ret = $abook->get_backend_list();
215
216 while (list($undef,$v) = each($ret)) {
217 $selopts[$v->bnum] = $v->sname;
218 }
219 echo addSelect('backend', $selopts, $backend, TRUE);
220 } else {
221 echo addHidden('backend', '-1');
222 }
223 if (isset($session)) {
224 echo addHidden('session', $session);
225 }
226
227 echo '<input type="submit" value="' . _("Search") . '" />' .
228 '&nbsp;|&nbsp;<input type="submit" value="' . _("List all") .
229 '" name="listall" />' . "\n" .
230 '</form></center></td></tr></table>' . "\n";
231 echo '</center>';
232 do_hook('addrbook_html_search_below');
233 /* End search form */
234
235 /* List addresses. Show personal addressbook */
236 if ($addrquery == '' || ! empty($listall)) {
237 // TODO: recheck all conditions and simplity if statements
238 if (! isset($backend) || $backend != -1 || $addrquery == '') {
239 if ($addrquery == '' && empty($listall)) {
240 $backend = $abook->localbackend;
241 }
242
243 /* echo '<h3 align="center">' . $abook->backends[$backend]->sname) . "</h3>\n"; */
244
245 $res = $abook->list_addr($backend);
246
247 if (is_array($res)) {
248 usort($res,'alistcmp');
249 addr_display_result($res, false);
250 } else {
251 echo html_tag( 'p', '<strong><br />' .
252 sprintf(_("Unable to list addresses from %s"),
253 $abook->backends[$backend]->sname) . "</strong>\n" ,
254 'center' );
255 }
256
257 } else {
258 $res = $abook->list_addr();
259 usort($res,'alistcmp');
260 addr_display_result($res, true);
261 }
262 $oTemplate->display('footer.tpl');
263 exit;
264 } elseif (!empty($addrquery)) {
265 /* Do the search */
266 if ($backend == -1) {
267 $res = $abook->s_search($addrquery);
268 } else {
269 $res = $abook->s_search($addrquery, $backend);
270 }
271
272 if (!is_array($res)) {
273 echo html_tag( 'p', '<b><br />' .
274 _("Your search failed with the following error(s)") .
275 ':<br />' . $abook->error . "</b>\n" ,
276 'center' ) . "\n";
277 $oTemplate->display('footer.tpl');
278 } else {
279 if (sizeof($res) == 0) {
280 echo html_tag( 'p', '<br /><b>' .
281 _("No persons matching your search were found") . "</b>\n" ,
282 'center' ) . "\n";
283 $oTemplate->display('footer.tpl');
284 } else {
285 addr_display_result($res);
286 }
287 }
288 } else {
289 // not first time display, not listall and search is empty
290 // TODO: I think, this part of control structure is never reached.
291 echo html_tag( 'p', '<br /><b>' .
292 _("Nothing to search") . "</b>\n" ,
293 'center' );
294 }
295
296 if ($addrquery == '' || sizeof($res) == 0) {
297 echo '<center>'.
298 addForm('compose.php','post','k');
299 addr_insert_hidden();
300 echo '<input type="submit" value="' . _("Return") . '" name="return" />' . "\n" .
301 '</form></center></nobr>';
302 }
303
304 $oTemplate->display('footer.tpl');
305 ?>