5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
8 ** Handle addressbook searching in the popup window.
10 ** NOTE: A lot of this code is similar to the code in
11 ** addrbook_search_html.html -- If you change one,
12 ** change the other one too!
17 require_once('../src/validate.php');
19 // Function to include JavaScript code
20 function insert_javascript() {
22 <SCRIPT LANGUAGE
="Javascript"><!--
24 function to_and_close($addr) {
29 function to_address($addr) {
31 var pwintype
= typeof parent
.opener
.document
.compose
;
33 $addr = $addr.replace(/ {1,35}$
/, "");
35 if(pwintype
!= "undefined" ) {
36 if ( parent
.opener
.document
.compose
.send_to
.value
) {
38 parent
.opener
.document
.compose
.send_to
.value
=
39 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;
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 printf("<TR BGCOLOR=\"$color[9]\"><TH ALIGN=left> ".
98 "<TH ALIGN=left> %s<TH ALIGN=left> %s".
99 "<TH ALIGN=left> %s",
100 _("Name"), _("E-mail"), _("Info"));
103 printf("<TH ALIGN=left WIDTH=\"10%%\"> %s", _("Source"));
107 while(list($undef, $row) = each($res)) {
108 printf("<tr%s nowrap><td valign=top nowrap align=center width=\"5%%\">".
109 "<small><a href=\"javascript:to_address('%s');\">To</A> | ".
110 "<a href=\"javascript:cc_address('%s');\">Cc</A> | ".
111 "<a href=\"javascript:bcc_address('%s');\">Bcc</A></small>".
112 "<td nowrap valign=top> %s <td nowrap valign=top>".
113 " <a href=\"javascript:to_and_close('%s');\">%s</A> ".
114 "<td valign=top> %s ",
115 ($line %
2) ?
" bgcolor=\"$color[0]\"" : "",
116 $row["email"], $row["email"], $row["email"],
117 $row["name"], $row["email"], $row["email"],
121 printf("<td nowrap valign=top> %s", $row["source"]);
129 /* ================= End of functions ================= */
131 require_once('../functions/array.php');
132 require_once('../functions/strings.php');
133 require_once('../functions/addressbook.php');
138 if(!isset($query)) $query = "";
139 if(!isset($show)) $show = "";
141 // Choose correct colors for top and bottom frame
142 if($show == 'form') {
143 echo "<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" ";
144 echo "LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\" ";
145 echo 'OnLoad="document.sform.query.focus();">';
147 echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" ";
148 echo "LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
152 if(empty($query) && empty($show) && empty($listall)) {
153 printf("<P ALIGN=center><BR>%s</P>\n</BODY></HTML>\n",
154 _("No persons matching your search was found"));
158 // Initialize addressbook
159 $abook = addressbook_init();
161 // Create search form
162 if($show == 'form') {
163 echo "<FORM NAME=sform TARGET=abookres ACTION=\"$PHP_SELF\" METHOD=\"POST\">\n";
164 echo '<TABLE BORDER="0" WIDTH="100%" HEIGHT="100%">';
165 echo "<TR><TD NOWRAP VALIGN=middle>\n";
166 printf(" <STRONG>%s</STRONG>\n", _("Search for"));
167 printf(" <INPUT TYPE=text NAME=query VALUE=\"%s\" SIZE=26>\n",
168 htmlspecialchars($query));
170 // List all backends to allow the user to choose where to search
171 if($abook->numbackends
> 1) {
172 printf("<STRONG>%s</STRONG> <SELECT NAME=backend>\n",
174 printf("<OPTION VALUE=-1 SELECTED>%s\n",
175 _("All address books"));
176 $ret = $abook->get_backend_list();
177 while(list($undef,$v) = each($ret))
178 printf("<OPTION VALUE=%d>%s\n", $v->bnum
, $v->sname
);
181 print "<INPUT TYPE=hidden NAME=backend VALUE=-1>\n";
184 printf("<INPUT TYPE=submit VALUE=\"%s\">",
186 printf(" | <INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n",
188 print "</TD><TD ALIGN=right>\n";
189 printf("<INPUT TYPE=button VALUE=\"%s\" onclick=\"parent.close();\">\n",
191 print "</TD></TR></TABLE></FORM>\n";
194 // Show personal addressbook
195 if($show == 'blank' ||
!empty($listall)) {
197 if($backend != -1 ||
$show == 'blank') {
199 $backend = $abook->localbackend
;
201 $res = $abook->list_addr($backend);
204 display_result($res, false);
206 printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s").
207 "</STRONG></P>\n", $abook->backends
[$backend]->sname
);
211 $res = $abook->list_addr();
212 display_result($res, true);
218 if(!empty($query) && empty($listall)) {
221 $res = $abook->s_search($query);
223 $res = $abook->s_search($query, $backend);
226 if(!is_array($res)) {
227 printf("<P ALIGN=center><B><BR>%s:<br>%s</B></P>\n</BODY></HTML>\n",
228 _("Your search failed with the following error(s)"),
233 if(sizeof($res) == 0) {
234 printf("<P ALIGN=center><BR><B>%s.</B></P>\n</BODY></HTML>\n",
235 _("No persons matching your search was found"));
239 display_result($res);
242 echo "</BODY></HTML>\n";