Wrong include path
[squirrelmail.git] / src / addrbook_search.php
CommitLineData
5100704d 1<?php
895905c0 2
35586184 3/**
4 * addrbook_search.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Handle addressbook searching in the popup window.
10 *
11 * NOTE: A lot of this code is similar to the code in
12 * addrbook_search_html.html -- If you change one,
13 * change the other one too!
14 *
15 * $Id$
16 */
17
86725763 18/* Path for SquirrelMail required files. */
19define('SM_PATH','../');
20
21/* SquirrelMail required files. */
08185f2a 22require_once(SM_PATH . 'include/validate.php');
86725763 23require_once(SM_PATH . 'functions/strings.php');
24require_once(SM_PATH . 'functions/html.php');
f740c049 25
b0c39665 26/* Function to include JavaScript code */
27function insert_javascript() {
28 ?>
29 <SCRIPT LANGUAGE="Javascript"><!--
87332e20 30
b0c39665 31 function to_and_close($addr) {
32 to_address($addr);
33 parent.close();
34 }
5100704d 35
b0c39665 36 function to_address($addr) {
37 var prefix = "";
38 var pwintype = typeof parent.opener.document.compose;
dfadb553 39
b0c39665 40 $addr = $addr.replace(/ {1,35}$/, "");
9487c2ff 41
b0c39665 42 if (pwintype != "undefined") {
43 if (parent.opener.document.compose.send_to.value) {
44 prefix = ", ";
45 parent.opener.document.compose.send_to.value =
46 parent.opener.document.compose.send_to.value + ", " + $addr;
47 } else {
48 parent.opener.document.compose.send_to.value = $addr;
49 }
50 }
5100704d 51 }
5100704d 52
b0c39665 53 function cc_address($addr) {
54 var prefix = "";
55 var pwintype = typeof parent.opener.document.compose;
5100704d 56
b0c39665 57 $addr = $addr.replace(/ {1,35}$/, "");
dfadb553 58
b0c39665 59 if (pwintype != "undefined") {
60 if (parent.opener.document.compose.send_to_cc.value) {
61 prefix = ", ";
62 parent.opener.document.compose.send_to_cc.value =
63 parent.opener.document.compose.send_to_cc.value + ", " + $addr;
64 } else {
65 parent.opener.document.compose.send_to_cc.value = $addr;
66 }
67 }
5100704d 68 }
5100704d 69
b0c39665 70 function bcc_address($addr) {
71 var prefix = "";
72 var pwintype = typeof parent.opener.document.compose;
9487c2ff 73
b0c39665 74 $addr = $addr.replace(/ {1,35}$/, "");
5100704d 75
b0c39665 76 if (pwintype != "undefined") {
77 if (parent.opener.document.compose.send_to_bcc.value) {
78 prefix = ", ";
79 parent.opener.document.compose.send_to_bcc.value =
80 parent.opener.document.compose.send_to_bcc.value + ", " + $addr;
81 } else {
82 parent.opener.document.compose.send_to_bcc.value = $addr;
83 }
84 }
5100704d 85 }
5100704d 86
87// --></SCRIPT>
9487c2ff 88<?php
b0c39665 89} /* End of included JavaScript */
2f73dc15 90
91
b0c39665 92/* List search results */
93function display_result($res, $includesource = true) {
94 global $color;
9487c2ff 95
b0c39665 96 if(sizeof($res) <= 0) return;
9487c2ff 97
b0c39665 98 insert_javascript();
9487c2ff 99
b0c39665 100 $line = 0;
ac987a56 101 echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) .
102 html_tag( 'tr', '', '', $color[9] ) .
103 html_tag( 'th', '&nbsp;', 'left' ) .
104 html_tag( 'th', '&nbsp;' . _("Name"), 'left' ) .
105 html_tag( 'th', '&nbsp;' . _("E-mail"), 'left' ) .
106 html_tag( 'th', '&nbsp;' . _("Info"), 'left' );
b0c39665 107
108 if ($includesource) {
ac987a56 109 echo html_tag( 'th', '&nbsp;' . _("Source"), 'left', 'width="10%"' );
b0c39665 110 }
ac987a56 111 echo "</tr>\n";
9487c2ff 112
b0c39665 113 while (list($undef, $row) = each($res)) {
ac987a56 114 $tr_bgcolor = '';
4e160237 115 $email = htmlspecialchars(addcslashes(AddressBook::full_address($row), "'"), ENT_QUOTES);
ac987a56 116 if ($line % 2) { $tr_bgcolor = $color[0]; }
117 echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) .
118 html_tag( 'td',
b0c39665 119 '<small><a href="javascript:to_address(' .
3d0cada3 120 "'" . $email . "');\">To</A> | " .
b0c39665 121 '<a href="javascript:cc_address(' .
3d0cada3 122 "'" . $email . "');\">Cc</A> | " .
b0c39665 123 '<a href="javascript:bcc_address(' .
3d0cada3 124 "'" . $email . "');\">Bcc</A></small>",
ac987a56 125 'center', '', 'valign="top" width="5%" nowrap' ) .
4e160237 126 html_tag( 'td', '&nbsp;' . htmlspecialchars($row['name']), 'left', '', 'valign="top" nowrap' ) .
ac987a56 127 html_tag( 'td', '&nbsp;' .
b22c4e16 128 '<a href="javascript:to_and_close(' .
4e160237 129 "'" . $email . "');\">" . htmlspecialchars($row['email']) . '</A>'
ac987a56 130 , 'left', '', 'valign="top"' ) .
4e160237 131 html_tag( 'td', htmlspecialchars($row['label']), 'left', '', 'valign="top" nowrap' );
b0c39665 132 if ($includesource) {
ac987a56 133 echo html_tag( 'td', '&nbsp;' . $row['source'], 'left', '', 'valign="top" nowrap' );
9487c2ff 134 }
b0c39665 135
ac987a56 136 echo "</tr>\n";
b0c39665 137 $line++;
9487c2ff 138 }
ac987a56 139 echo '</table>';
b0c39665 140}
9487c2ff 141
b0c39665 142/* ================= End of functions ================= */
9487c2ff 143
b0c39665 144require_once('../functions/array.php');
145require_once('../functions/strings.php');
146require_once('../functions/addressbook.php');
9487c2ff 147
b0c39665 148displayHtmlHeader();
9487c2ff 149
b0c39665 150/* Initialize vars */
151if (!isset($query)) { $query = ''; }
152if (!isset($show)) { $show = ''; }
5a1ae5ca 153if (!isset($backend)) { $backend = ''; }
9487c2ff 154
b0c39665 155/* Choose correct colors for top and bottom frame */
b22c4e16 156if ($show == 'form' && !isset($listall)) {
b0c39665 157 echo '<BODY TEXT="' . $color[6] . '" BGCOLOR="' . $color[3] . '" ' .
158 'LINK="' . $color[6] . '" VLINK="' . $color[6] . '" ' .
159 'ALINK="' . $color[6] . '" ' .
160 'OnLoad="document.sform.query.focus();">';
161} else {
162 echo '<BODY TEXT="' . $color[8] . '" BGCOLOR="' . $color[4] . '" ' .
163 'LINK="' . $color[7] . '" VLINK="' . $color[7] . '" ' .
164 'ALINK="' . $color[7] . "\">\n";
165}
9487c2ff 166
b0c39665 167/* Empty search */
168if (empty($query) && empty($show) && empty($listall)) {
ac987a56 169 echo html_tag( 'p', '<br>' .
170 _("No persons matching your search was found"),
171 'center' ) .
172 "\n</BODY></HTML>\n",
b0c39665 173 exit;
174}
9487c2ff 175
b0c39665 176/* Initialize addressbook */
177$abook = addressbook_init();
9487c2ff 178
b0c39665 179/* Create search form */
0397590e 180if ($show == 'form' && empty($listall)) {
5a1ae5ca 181 echo '<FORM NAME=sform TARGET=abookres ACTION="addrbook_search.php'.
b0c39665 182 '" METHOD="POST">' . "\n" .
ac987a56 183 html_tag( 'table', '', '', '', 'border="0" width="100%" height="100%"' ) .
184 html_tag( 'tr' ) .
185 html_tag( 'td', ' <strong>' . _("Search for") . "</strong>\n", 'left', '', 'nowrap valign="middle" width="10%"' ) .
186 html_tag( 'td', '', 'left', '', '' ) .
187 '<INPUT TYPE=text NAME=query VALUE="' . htmlspecialchars($query) .
188 "\" SIZE=28>\n";
b0c39665 189
190 /* List all backends to allow the user to choose where to search */
191 if ($abook->numbackends > 1) {
192 echo '<STRONG>' . _("in") . '</STRONG>&nbsp;<SELECT NAME=backend>'."\n".
193 '<OPTION VALUE=-1 SELECTED>' . _("All address books") . "\n";
194 $ret = $abook->get_backend_list();
195 while (list($undef,$v) = each($ret)) {
196 echo '<OPTION VALUE=' . $v->bnum . '>' . $v->sname . "\n";
9487c2ff 197 }
b0c39665 198 echo "</SELECT>\n";
199 } else {
200 echo '<INPUT TYPE=hidden NAME=backend VALUE=-1>' . "\n";
201 }
9487c2ff 202
ac987a56 203 echo '</td></tr>' .
204 html_tag( 'tr',
205 html_tag( 'td', '', 'left' ) .
206 html_tag( 'td',
207 '<INPUT TYPE=submit VALUE="' . _("Search") . '" NAME=show>' .
208 '&nbsp;|&nbsp;<INPUT TYPE=submit VALUE="' . _("List all") .
209 '" NAME=listall>' . "\n" .
210 '&nbsp;|&nbsp;<INPUT TYPE=button VALUE="' . _("Close") .
211 '" onclick="parent.close();">' . "\n" ,
212 'left' )
213 ) .
214 '</table></form>' . "\n";
b0c39665 215} else {
9487c2ff 216
b0c39665 217 /* Show personal addressbook */
db48e3f5 218 if ($show == 'blank' && empty($listall)) {
9487c2ff 219
220 if($backend != -1 || $show == 'blank') {
b0c39665 221 if ($show == 'blank') {
9487c2ff 222 $backend = $abook->localbackend;
b0c39665 223 }
9487c2ff 224 $res = $abook->list_addr($backend);
225
226 if(is_array($res)) {
a10110a5 227 usort($res,'alistcmp');
9487c2ff 228 display_result($res, false);
229 } else {
ac987a56 230 echo html_tag( 'p', '<strong>' .
231 sprintf(_("Unable to list addresses from %s"),
232 $abook->backends[$backend]->sname) . '</strong>' ,
233 'center' ) . "\n";
9487c2ff 234 }
9487c2ff 235 } else {
b0c39665 236 $res = $abook->list_addr();
a10110a5 237 usort($res,'alistcmp');
b0c39665 238 display_result($res, true);
9487c2ff 239 }
240
b0c39665 241 } else {
db48e3f5 242 if( !empty( $listall ) ){
243 $query = '*';
244 }
9487c2ff 245
b0c39665 246 /* Do the search */
db48e3f5 247 if (!empty($query)) {
9487c2ff 248
b0c39665 249 if($backend == -1) {
250 $res = $abook->s_search($query);
251 } else {
252 $res = $abook->s_search($query, $backend);
253 }
9487c2ff 254
b0c39665 255 if (!is_array($res)) {
ac987a56 256 echo html_tag( 'p', '<b><br>' .
257 _("Your search failed with the following error(s)") .
258 ':<br>' . $abook->error . "</b>\n" ,
259 'center' ) .
260 "\n</BODY></HTML>\n";
b0c39665 261 exit;
262 }
9487c2ff 263
b0c39665 264 if (sizeof($res) == 0) {
ac987a56 265 echo html_tag( 'p', '<br><b>' .
266 _("No persons matching your search was found") . "</b>\n" ,
267 'center' ) .
268 "\n</BODY></HTML>\n";
b0c39665 269 exit;
270 }
9487c2ff 271
b0c39665 272 display_result($res);
273 }
9487c2ff 274 }
275
b0c39665 276}
277
278echo "</BODY></HTML>\n";
9487c2ff 279
35586184 280?>