5 ** Handle addressbook searching in the popup window.
7 ** NOTE: A lot of this code is similar to the code in
8 ** addrbook_search_html.html -- If you change one,
9 ** change the other one too!
12 // Function to include JavaScript code
13 function insert_javascript() {
15 <SCRIPT LANGUAGE
="Javascript"><!--
17 function to_and_close($addr) {
22 function to_address($addr) {
24 var pwintype
= typeof parent
.opener
.document
.compose
;
26 $addr = $addr.replace(/ {1,35}$
/, "");
28 if(pwintype
!= "undefined" ) {
29 if ( parent
.opener
.document
.compose
.send_to
.value
) {
31 parent
.opener
.document
.compose
.send_to
.value
=
32 parent
.opener
.document
.compose
.send_to
.value +
", " +
$addr;
35 parent
.opener
.document
.compose
.send_to
.value
= $addr;
40 function cc_address($addr) {
42 var pwintype
= typeof parent
.opener
.document
.compose
;
44 $addr = $addr.replace(/ {1,35}$
/, "");
46 if(pwintype
!= "undefined" ) {
47 if ( parent
.opener
.document
.compose
.send_to_cc
.value
) {
49 parent
.opener
.document
.compose
.send_to_cc
.value
=
50 parent
.opener
.document
.compose
.send_to_cc
.value +
", " +
$addr;
52 parent
.opener
.document
.compose
.send_to_cc
.value
= $addr;
57 function bcc_address($addr) {
59 var pwintype
= typeof parent
.opener
.document
.compose
;
61 $addr = $addr.replace(/ {1,35}$
/, "");
63 if(pwintype
!= "undefined" ) {
64 if ( parent
.opener
.document
.compose
.send_to_bcc
.value
) {
66 parent
.opener
.document
.compose
.send_to_bcc
.value
=
67 parent
.opener
.document
.compose
.send_to_bcc
.value +
", " +
$addr;
69 parent
.opener
.document
.compose
.send_to_bcc
.value
= $addr;
77 } // End of included JavaScript
80 // List search results
81 function display_result($res, $includesource = true) {
84 if(sizeof($res) <= 0) return;
89 print "<TABLE BORDER=0 WIDTH=\"98%\" ALIGN=center>";
90 printf("<TR BGCOLOR=\"$color[9]\"><TH ALIGN=left> ".
91 "<TH ALIGN=left> %s<TH ALIGN=left> %s".
92 "<TH ALIGN=left> %s",
93 _("Name"), _("E-mail"), _("Info"));
96 printf("<TH ALIGN=left WIDTH=\"10%%\"> %s", _("Source"));
100 while(list($key, $row) = each($res)) {
101 printf("<tr%s nowrap><td valign=top nowrap align=center width=\"5%%\">".
102 "<small><a href=\"javascript:to_address('%s');\">To</A> | ".
103 "<a href=\"javascript:cc_address('%s');\">Cc</A> | ".
104 "<a href=\"javascript:bcc_address('%s');\">Bcc</A></small>".
105 "<td nowrap valign=top> %s <td nowrap valign=top>".
106 " <a href=\"javascript:to_and_close('%s');\">%s</A> ".
107 "<td valign=top> %s ",
108 ($line %
2) ?
" bgcolor=\"$color[0]\"" : "",
109 $row["email"], $row["email"], $row["email"],
110 $row["name"], $row["email"], $row["email"],
114 printf("<td nowrap valign=top> %s", $row["source"]);
122 /* ================= End of functions ================= */
126 if(!isset($logged_in)) {
127 echo _("You must login first.");
130 if(!isset($username) ||
!isset($key)) {
131 echo _("You need a valid user and password to access this page!");
135 if (!isset($config_php))
136 include("../config/config.php");
137 if (!isset($array_php))
138 include("../functions/array.php");
139 if (!isset($auth_php))
140 include("../functions/auth.php");
141 if (!isset($strings_php))
142 include("../functions/strings.php");
143 if (!isset($page_header_php))
144 include("../functions/page_header.php");
145 if (!isset($addressbook_php))
146 include("../functions/addressbook.php");
149 include("../src/load_prefs.php");
153 // Choose correct colors for top and bottom frame
154 if($show == "form") {
155 echo "<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" ";
156 echo "LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\" ";
157 echo "OnLoad=\"document.sform.query.focus();\">";
159 echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" ";
160 echo "LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
164 if(empty($query) && empty($show) && empty($listall)) {
165 printf("<P ALIGN=center><BR>%s</P>\n</BODY></HTML>\n",
166 _("No persons matching your search was found"));
170 // Initialize addressbook
171 $abook = addressbook_init();
173 // Create search form
174 if($show == "form") {
175 printf("<FORM NAME=sform TARGET=abookres ACTION=\"%s\" METHOD=\"POST\">\n",
177 printf("<TABLE BORDER=0 WIDTH=\"100%%\" HEIGHT=\"100%%\">");
178 printf("<TR><TD NOWRAP VALIGN=middle>\n");
179 printf(" <STRONG>%s</STRONG>\n", _("Search for"));
180 printf(" <INPUT TYPE=text NAME=query VALUE=\"%s\" SIZE=26>\n",
181 htmlspecialchars($query));
183 // List all backends to allow the user to choose where to search
184 if($abook->numbackends
> 1) {
185 printf("<STRONG>%s</STRONG> <SELECT NAME=backend>\n",
187 printf("<OPTION VALUE=-1 SELECTED>%s\n",
188 _("All address books"));
189 $ret = $abook->get_backend_list();
190 while(list($k,$v) = each($ret))
191 printf("<OPTION VALUE=%d>%s\n", $v->bnum
, $v->sname
);
192 printf("</SELECT>\n");
194 printf("<INPUT TYPE=hidden NAME=backend VALUE=-1>\n");
197 printf("<INPUT TYPE=submit VALUE=\"%s\">",
199 printf(" | <INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n",
201 printf("</TD><TD ALIGN=right>\n");
202 printf("<INPUT TYPE=button VALUE=\"%s\" onclick=\"parent.close();\">\n",
204 printf("</TD></TR></TABLE></FORM>\n");
207 // Show personal addressbook
208 if($show == "blank" ||
!empty($listall)) {
210 if($backend != -1 ||
$show == "blank") {
212 $backend = $abook->localbackend
;
214 //printf("<H3 ALIGN=center>%s</H3>\n", $abook->backends[$backend]->sname);
216 $res = $abook->list_addr($backend);
219 display_result($res, false);
221 printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s").
222 "</STRONG></P>\n", $abook->backends
[$backend]->sname
);
226 $res = $abook->list_addr();
227 display_result($res, true);
233 if(!empty($query) && empty($listall)) {
236 $res = $abook->s_search($query);
238 $res = $abook->s_search($query, $backend);
241 if(!is_array($res)) {
242 printf("<P ALIGN=center><B><BR>%s:<br>%s</B></P>\n</BODY></HTML>\n",
243 _("Your search failed with the following error(s)"),
248 if(sizeof($res) == 0) {
249 printf("<P ALIGN=center><BR><B>%s.</B></P>\n</BODY></HTML>\n",
250 _("No persons matching your search was found"));
254 display_result($res);