6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * Handle addressbook searching in the popup window.
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!
18 require_once('../src/validate.php');
20 /* Function to include JavaScript code */
21 function insert_javascript() {
23 <SCRIPT LANGUAGE
="Javascript"><!--
25 function to_and_close($addr) {
30 function to_address($addr) {
32 var pwintype
= typeof parent
.opener
.document
.compose
;
34 $addr = $addr.replace(/ {1,35}$
/, "");
36 if (pwintype
!= "undefined") {
37 if (parent
.opener
.document
.compose
.send_to
.value
) {
39 parent
.opener
.document
.compose
.send_to
.value
=
40 parent
.opener
.document
.compose
.send_to
.value +
", " +
$addr;
42 parent
.opener
.document
.compose
.send_to
.value
= $addr;
47 function cc_address($addr) {
49 var pwintype
= typeof parent
.opener
.document
.compose
;
51 $addr = $addr.replace(/ {1,35}$
/, "");
53 if (pwintype
!= "undefined") {
54 if (parent
.opener
.document
.compose
.send_to_cc
.value
) {
56 parent
.opener
.document
.compose
.send_to_cc
.value
=
57 parent
.opener
.document
.compose
.send_to_cc
.value +
", " +
$addr;
59 parent
.opener
.document
.compose
.send_to_cc
.value
= $addr;
64 function bcc_address($addr) {
66 var pwintype
= typeof parent
.opener
.document
.compose
;
68 $addr = $addr.replace(/ {1,35}$
/, "");
70 if (pwintype
!= "undefined") {
71 if (parent
.opener
.document
.compose
.send_to_bcc
.value
) {
73 parent
.opener
.document
.compose
.send_to_bcc
.value
=
74 parent
.opener
.document
.compose
.send_to_bcc
.value +
", " +
$addr;
76 parent
.opener
.document
.compose
.send_to_bcc
.value
= $addr;
83 } /* End of included JavaScript */
86 /* List search results */
87 function display_result($res, $includesource = true) {
90 if(sizeof($res) <= 0) return;
95 echo '<TABLE BORDER="0" WIDTH="98%" ALIGN=center>' .
96 '<TR BGCOLOR="' . $color[9] . '"><TH ALIGN=left> ' .
97 '<TH ALIGN=left> ' . _("Name") .
98 '<TH ALIGN=left> ' . _("E-mail") .
99 '<TH ALIGN=left> ' . _("Info");
101 if ($includesource) {
102 echo '<TH ALIGN=left WIDTH="10%"> ' . _("Source");
106 while (list($undef, $row) = each($res)) {
108 if ($line %
2) { echo ' bgcolor="' . $color[0] . '"'; }
109 echo ' nowrap><td valign=top nowrap align=center width="5%">' .
110 '<small><a href="javascript:to_address(' .
111 "'" . $row['email'] . "');\">To</A> | " .
112 '<a href="javascript:cc_address(' .
113 "'" . $row['email'] . "');\">Cc</A> | " .
114 '<a href="javascript:bcc_address(' .
115 "'" . $row['email'] . "');\">Bcc</A></small>" .
116 '<td nowrap valign=top> ' .
117 $row['name'] . ' <td nowrap valign=top>' .
118 ' <a href="javascript:to_and_close(' .
119 "'" . $row['email'] . "');\">" . $row['email'] . '</A> ' .
120 '<td valign=top> ' . $row['label'] . ' ';
121 if ($includesource) {
122 echo '<td nowrap valign=top> ' . $row['source'];
131 /* ================= End of functions ================= */
133 require_once('../functions/array.php');
134 require_once('../functions/strings.php');
135 require_once('../functions/addressbook.php');
139 /* Initialize vars */
140 if (!isset($query)) { $query = ''; }
141 if (!isset($show)) { $show = ''; }
143 /* Choose correct colors for top and bottom frame */
144 if ($show == 'form') {
145 echo '<BODY TEXT="' . $color[6] . '" BGCOLOR="' . $color[3] . '" ' .
146 'LINK="' . $color[6] . '" VLINK="' . $color[6] . '" ' .
147 'ALINK="' . $color[6] . '" ' .
148 'OnLoad="document.sform.query.focus();">';
150 echo '<BODY TEXT="' . $color[8] . '" BGCOLOR="' . $color[4] . '" ' .
151 'LINK="' . $color[7] . '" VLINK="' . $color[7] . '" ' .
152 'ALINK="' . $color[7] . "\">\n";
156 if (empty($query) && empty($show) && empty($listall)) {
157 echo '<P ALIGN=center><BR>' .
158 _("No persons matching your search was found") .
159 "</P>\n</BODY></HTML>\n",
163 /* Initialize addressbook */
164 $abook = addressbook_init();
166 /* Create search form */
167 if ($show == 'form') {
168 echo '<FORM NAME=sform TARGET=abookres ACTION="' . $PHP_SELF .
169 '" METHOD="POST">' . "\n" .
170 '<TABLE BORDER="0" WIDTH="100%" HEIGHT="100%">' .
171 '<TR><TD NOWRAP VALIGN=middle>' . "\n" .
172 ' <STRONG>' . _("Search for") . "</STRONG>\n" .
173 ' <INPUT TYPE=text NAME=query VALUE="' . htmlspecialchars($query) .
176 /* List all backends to allow the user to choose where to search */
177 if ($abook->numbackends
> 1) {
178 echo '<STRONG>' . _("in") . '</STRONG> <SELECT NAME=backend>'."\n".
179 '<OPTION VALUE=-1 SELECTED>' . _("All address books") . "\n";
180 $ret = $abook->get_backend_list();
181 while (list($undef,$v) = each($ret)) {
182 echo '<OPTION VALUE=' . $v->bnum
. '>' . $v->sname
. "\n";
186 echo '<INPUT TYPE=hidden NAME=backend VALUE=-1>' . "\n";
189 echo '<INPUT TYPE=submit VALUE="' . _("Search") . '">' .
190 ' | <INPUT TYPE=submit VALUE="' . _("List all") .
191 '" NAME=listall>' . "\n" .
192 '</TD><TD ALIGN=right>' . "\n" .
193 '<INPUT TYPE=button VALUE="' . _("Close window") .
194 '" onclick="parent.close();">' . "\n" .
195 '</TD></TR></TABLE></FORM>' . "\n";
198 /* Show personal addressbook */
199 if ($show == 'blank' ||
!empty($listall)) {
201 if($backend != -1 ||
$show == 'blank') {
202 if ($show == 'blank') {
203 $backend = $abook->localbackend
;
205 $res = $abook->list_addr($backend);
208 usort($res,'alistcmp');
209 display_result($res, false);
211 echo '<P ALIGN=center><STRONG>' .
212 sprintf(_("Unable to list addresses from %s"),
213 $abook->backends
[$backend]->sname
) .
214 '</STRONG></P>' . "\n";
217 $res = $abook->list_addr();
218 usort($res,'alistcmp');
219 display_result($res, true);
225 if (!empty($query) && empty($listall)) {
228 $res = $abook->s_search($query);
230 $res = $abook->s_search($query, $backend);
233 if (!is_array($res)) {
234 echo '<P ALIGN=center><B><BR>' .
235 _("Your search failed with the following error(s)") .
236 ':<br>' . $abook->error
. "</B></P>\n</BODY></HTML>\n";
240 if (sizeof($res) == 0) {
241 echo '<P ALIGN=center><BR><B>' .
242 _("No persons matching your search was found") .
243 ".</B></P>\n</BODY></HTML>\n";
247 display_result($res);
253 echo "</BODY></HTML>\n";