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