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');
19 require_once('../functions/strings.php');
21 /* Function to include JavaScript code */
22 function insert_javascript() {
24 <SCRIPT LANGUAGE
="Javascript"><!--
26 function to_and_close($addr) {
31 function to_address($addr) {
33 var pwintype
= typeof parent
.opener
.document
.compose
;
35 $addr = $addr.replace(/ {1,35}$
/, "");
37 if (pwintype
!= "undefined") {
38 if (parent
.opener
.document
.compose
.send_to
.value
) {
40 parent
.opener
.document
.compose
.send_to
.value
=
41 parent
.opener
.document
.compose
.send_to
.value +
", " +
$addr;
43 parent
.opener
.document
.compose
.send_to
.value
= $addr;
48 function cc_address($addr) {
50 var pwintype
= typeof parent
.opener
.document
.compose
;
52 $addr = $addr.replace(/ {1,35}$
/, "");
54 if (pwintype
!= "undefined") {
55 if (parent
.opener
.document
.compose
.send_to_cc
.value
) {
57 parent
.opener
.document
.compose
.send_to_cc
.value
=
58 parent
.opener
.document
.compose
.send_to_cc
.value +
", " +
$addr;
60 parent
.opener
.document
.compose
.send_to_cc
.value
= $addr;
65 function bcc_address($addr) {
67 var pwintype
= typeof parent
.opener
.document
.compose
;
69 $addr = $addr.replace(/ {1,35}$
/, "");
71 if (pwintype
!= "undefined") {
72 if (parent
.opener
.document
.compose
.send_to_bcc
.value
) {
74 parent
.opener
.document
.compose
.send_to_bcc
.value
=
75 parent
.opener
.document
.compose
.send_to_bcc
.value +
", " +
$addr;
77 parent
.opener
.document
.compose
.send_to_bcc
.value
= $addr;
84 } /* End of included JavaScript */
87 /* List search results */
88 function display_result($res, $includesource = true) {
91 if(sizeof($res) <= 0) return;
96 echo '<TABLE BORDER="0" WIDTH="98%" ALIGN=center>' .
97 '<TR BGCOLOR="' . $color[9] . '"><TH ALIGN=left> ' .
98 '<TH ALIGN=left> ' . _("Name") .
99 '<TH ALIGN=left> ' . _("E-mail") .
100 '<TH ALIGN=left> ' . _("Info");
102 if ($includesource) {
103 echo '<TH ALIGN=left WIDTH="10%"> ' . _("Source");
107 while (list($undef, $row) = each($res)) {
109 if ($line %
2) { echo ' bgcolor="' . $color[0] . '"'; }
110 echo ' nowrap><td valign=top nowrap align=center width="5%">' .
111 '<small><a href="javascript:to_address(' .
112 "'" . $row['email'] . "');\">To</A> | " .
113 '<a href="javascript:cc_address(' .
114 "'" . $row['email'] . "');\">Cc</A> | " .
115 '<a href="javascript:bcc_address(' .
116 "'" . $row['email'] . "');\">Bcc</A></small>" .
117 '<td nowrap valign=top> ' .
118 $row['name'] . '<td valign=top>' .
119 '<a href="javascript:to_and_close(' .
120 "'" . $row['email'] . "');\">" . $row['email'] . '</A>' .
121 '<td valign=top nowrap>' . $row['label'];
122 if ($includesource) {
123 echo '<td nowrap valign=top> ' . $row['source'];
132 /* ================= End of functions ================= */
134 require_once('../functions/array.php');
135 require_once('../functions/strings.php');
136 require_once('../functions/addressbook.php');
140 /* Initialize vars */
141 if (!isset($query)) { $query = ''; }
142 if (!isset($show)) { $show = ''; }
143 if (!isset($backend)) { $backend = ''; }
145 /* Choose correct colors for top and bottom frame */
146 if ($show == 'form' && !isset($listall)) {
147 echo '<BODY TEXT="' . $color[6] . '" BGCOLOR="' . $color[3] . '" ' .
148 'LINK="' . $color[6] . '" VLINK="' . $color[6] . '" ' .
149 'ALINK="' . $color[6] . '" ' .
150 'OnLoad="document.sform.query.focus();">';
152 echo '<BODY TEXT="' . $color[8] . '" BGCOLOR="' . $color[4] . '" ' .
153 'LINK="' . $color[7] . '" VLINK="' . $color[7] . '" ' .
154 'ALINK="' . $color[7] . "\">\n";
158 if (empty($query) && empty($show) && empty($listall)) {
159 echo '<P ALIGN=center><BR>' .
160 _("No persons matching your search was found") .
161 "</P>\n</BODY></HTML>\n",
165 /* Initialize addressbook */
166 $abook = addressbook_init();
168 /* Create search form */
169 if ($show == 'form' && empty($listall)) {
170 echo '<FORM NAME=sform TARGET=abookres ACTION="addrbook_search.php'.
171 '" METHOD="POST">' . "\n" .
172 '<TABLE BORDER="0" WIDTH="100%" HEIGHT="100%">' .
173 '<TR><TD NOWRAP VALIGN=middle align=left width=10%>' . "\n" .
174 ' <STRONG>' . _("Search for") . "</STRONG>\n" .
175 ' </TD><TD align=left><INPUT TYPE=text NAME=query VALUE="' . htmlspecialchars($query) .
178 /* List all backends to allow the user to choose where to search */
179 if ($abook->numbackends
> 1) {
180 echo '<STRONG>' . _("in") . '</STRONG> <SELECT NAME=backend>'."\n".
181 '<OPTION VALUE=-1 SELECTED>' . _("All address books") . "\n";
182 $ret = $abook->get_backend_list();
183 while (list($undef,$v) = each($ret)) {
184 echo '<OPTION VALUE=' . $v->bnum
. '>' . $v->sname
. "\n";
188 echo '<INPUT TYPE=hidden NAME=backend VALUE=-1>' . "\n";
191 echo '</TD></TR><TR><TD></TD><TD align=left>'.
192 '<INPUT TYPE=submit VALUE="' . _("Search") . '" NAME=show>' .
193 ' | <INPUT TYPE=submit VALUE="' . _("List all") .
194 '" NAME=listall>' . "\n" .
195 ' | <INPUT TYPE=button VALUE="' . _("Close") .
196 '" onclick="parent.close();">' . "\n" .
197 '</TD></TR></TABLE></FORM>' . "\n";
200 /* Show personal addressbook */
201 if ($show == 'blank' && empty($listall)) {
203 if($backend != -1 ||
$show == 'blank') {
204 if ($show == 'blank') {
205 $backend = $abook->localbackend
;
207 $res = $abook->list_addr($backend);
210 usort($res,'alistcmp');
211 display_result($res, false);
213 echo '<P ALIGN=center><STRONG>' .
214 sprintf(_("Unable to list addresses from %s"),
215 $abook->backends
[$backend]->sname
) .
216 '</STRONG></P>' . "\n";
219 $res = $abook->list_addr();
220 usort($res,'alistcmp');
221 display_result($res, true);
225 if( !empty( $listall ) ){
230 if (!empty($query)) {
233 $res = $abook->s_search($query);
235 $res = $abook->s_search($query, $backend);
238 if (!is_array($res)) {
239 echo '<P ALIGN=center><B><BR>' .
240 _("Your search failed with the following error(s)") .
241 ':<br>' . $abook->error
. "</B></P>\n</BODY></HTML>\n";
245 if (sizeof($res) == 0) {
246 echo '<P ALIGN=center><BR><B>' .
247 _("No persons matching your search was found") .
248 ".</B></P>\n</BODY></HTML>\n";
252 display_result($res);
258 echo "</BODY></HTML>\n";