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!
15 // Function to include JavaScript code
16 function insert_javascript() {
18 <SCRIPT LANGUAGE
="Javascript"><!--
20 function to_and_close($addr) {
25 function to_address($addr) {
27 var pwintype
= typeof parent
.opener
.document
.compose
;
29 $addr = $addr.replace(/ {1,35}$
/, "");
31 if(pwintype
!= "undefined" ) {
32 if ( parent
.opener
.document
.compose
.send_to
.value
) {
34 parent
.opener
.document
.compose
.send_to
.value
=
35 parent
.opener
.document
.compose
.send_to
.value +
", " +
$addr;
38 parent
.opener
.document
.compose
.send_to
.value
= $addr;
43 function cc_address($addr) {
45 var pwintype
= typeof parent
.opener
.document
.compose
;
47 $addr = $addr.replace(/ {1,35}$
/, "");
49 if(pwintype
!= "undefined" ) {
50 if ( parent
.opener
.document
.compose
.send_to_cc
.value
) {
52 parent
.opener
.document
.compose
.send_to_cc
.value
=
53 parent
.opener
.document
.compose
.send_to_cc
.value +
", " +
$addr;
55 parent
.opener
.document
.compose
.send_to_cc
.value
= $addr;
60 function bcc_address($addr) {
62 var pwintype
= typeof parent
.opener
.document
.compose
;
64 $addr = $addr.replace(/ {1,35}$
/, "");
66 if(pwintype
!= "undefined" ) {
67 if ( parent
.opener
.document
.compose
.send_to_bcc
.value
) {
69 parent
.opener
.document
.compose
.send_to_bcc
.value
=
70 parent
.opener
.document
.compose
.send_to_bcc
.value +
", " +
$addr;
72 parent
.opener
.document
.compose
.send_to_bcc
.value
= $addr;
80 } // End of included JavaScript
83 // List search results
84 function display_result($res, $includesource = true) {
87 if(sizeof($res) <= 0) return;
92 print "<TABLE BORDER=0 WIDTH=\"98%\" ALIGN=center>";
93 printf("<TR BGCOLOR=\"$color[9]\"><TH ALIGN=left> ".
94 "<TH ALIGN=left> %s<TH ALIGN=left> %s".
95 "<TH ALIGN=left> %s",
96 _("Name"), _("E-mail"), _("Info"));
99 printf("<TH ALIGN=left WIDTH=\"10%%\"> %s", _("Source"));
103 while(list($undef, $row) = each($res)) {
104 printf("<tr%s nowrap><td valign=top nowrap align=center width=\"5%%\">".
105 "<small><a href=\"javascript:to_address('%s');\">To</A> | ".
106 "<a href=\"javascript:cc_address('%s');\">Cc</A> | ".
107 "<a href=\"javascript:bcc_address('%s');\">Bcc</A></small>".
108 "<td nowrap valign=top> %s <td nowrap valign=top>".
109 " <a href=\"javascript:to_and_close('%s');\">%s</A> ".
110 "<td valign=top> %s ",
111 ($line %
2) ?
" bgcolor=\"$color[0]\"" : "",
112 $row["email"], $row["email"], $row["email"],
113 $row["name"], $row["email"], $row["email"],
117 printf("<td nowrap valign=top> %s", $row["source"]);
125 /* ================= End of functions ================= */
129 if (!isset($i18n_php))
130 include("../functions/i18n.php");
132 if(!isset($logged_in)) {
133 set_up_language($squirrelmail_language, true);
134 echo _("You must login first.");
137 if(!isset($username) ||
!isset($key)) {
138 set_up_language($squirrelmail_language, true);
139 echo _("You need a valid user and password to access this page!");
143 if (!isset($config_php))
144 include("../config/config.php");
145 if (!isset($array_php))
146 include("../functions/array.php");
147 if (!isset($auth_php))
148 include("../functions/auth.php");
149 if (!isset($strings_php))
150 include("../functions/strings.php");
151 if (!isset($page_header_php))
152 include("../functions/page_header.php");
153 if (!isset($addressbook_php))
154 include("../functions/addressbook.php");
157 include("../src/load_prefs.php");
161 // Choose correct colors for top and bottom frame
162 if($show == "form") {
163 echo "<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" ";
164 echo "LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\" ";
165 echo "OnLoad=\"document.sform.query.focus();\">";
167 echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" ";
168 echo "LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
172 if(empty($query) && empty($show) && empty($listall)) {
173 printf("<P ALIGN=center><BR>%s</P>\n</BODY></HTML>\n",
174 _("No persons matching your search was found"));
178 // Initialize addressbook
179 $abook = addressbook_init();
181 // Create search form
182 if($show == "form") {
183 printf("<FORM NAME=sform TARGET=abookres ACTION=\"%s\" METHOD=\"POST\">\n",
185 printf("<TABLE BORDER=0 WIDTH=\"100%%\" HEIGHT=\"100%%\">");
186 printf("<TR><TD NOWRAP VALIGN=middle>\n");
187 printf(" <STRONG>%s</STRONG>\n", _("Search for"));
188 printf(" <INPUT TYPE=text NAME=query VALUE=\"%s\" SIZE=26>\n",
189 htmlspecialchars($query));
191 // List all backends to allow the user to choose where to search
192 if($abook->numbackends
> 1) {
193 printf("<STRONG>%s</STRONG> <SELECT NAME=backend>\n",
195 printf("<OPTION VALUE=-1 SELECTED>%s\n",
196 _("All address books"));
197 $ret = $abook->get_backend_list();
198 while(list($undef,$v) = each($ret))
199 printf("<OPTION VALUE=%d>%s\n", $v->bnum
, $v->sname
);
200 printf("</SELECT>\n");
202 printf("<INPUT TYPE=hidden NAME=backend VALUE=-1>\n");
205 printf("<INPUT TYPE=submit VALUE=\"%s\">",
207 printf(" | <INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n",
209 printf("</TD><TD ALIGN=right>\n");
210 printf("<INPUT TYPE=button VALUE=\"%s\" onclick=\"parent.close();\">\n",
212 printf("</TD></TR></TABLE></FORM>\n");
215 // Show personal addressbook
216 if($show == "blank" ||
!empty($listall)) {
218 if($backend != -1 ||
$show == "blank") {
220 $backend = $abook->localbackend
;
222 //printf("<H3 ALIGN=center>%s</H3>\n", $abook->backends[$backend]->sname);
224 $res = $abook->list_addr($backend);
227 display_result($res, false);
229 printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s").
230 "</STRONG></P>\n", $abook->backends
[$backend]->sname
);
234 $res = $abook->list_addr();
235 display_result($res, true);
241 if(!empty($query) && empty($listall)) {
244 $res = $abook->s_search($query);
246 $res = $abook->s_search($query, $backend);
249 if(!is_array($res)) {
250 printf("<P ALIGN=center><B><BR>%s:<br>%s</B></P>\n</BODY></HTML>\n",
251 _("Your search failed with the following error(s)"),
256 if(sizeof($res) == 0) {
257 printf("<P ALIGN=center><BR><B>%s.</B></P>\n</BODY></HTML>\n",
258 _("No persons matching your search was found"));
262 display_result($res);