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 // Function to include JavaScript code
18 function insert_javascript() {
20 <SCRIPT LANGUAGE
="Javascript"><!--
22 function to_and_close($addr) {
27 function to_address($addr) {
29 var pwintype
= typeof parent
.opener
.document
.compose
;
31 $addr = $addr.replace(/ {1,35}$
/, "");
33 if(pwintype
!= "undefined" ) {
34 if ( parent
.opener
.document
.compose
.send_to
.value
) {
36 parent
.opener
.document
.compose
.send_to
.value
=
37 parent
.opener
.document
.compose
.send_to
.value +
", " +
$addr;
40 parent
.opener
.document
.compose
.send_to
.value
= $addr;
45 function cc_address($addr) {
47 var pwintype
= typeof parent
.opener
.document
.compose
;
49 $addr = $addr.replace(/ {1,35}$
/, "");
51 if(pwintype
!= "undefined" ) {
52 if ( parent
.opener
.document
.compose
.send_to_cc
.value
) {
54 parent
.opener
.document
.compose
.send_to_cc
.value
=
55 parent
.opener
.document
.compose
.send_to_cc
.value +
", " +
$addr;
57 parent
.opener
.document
.compose
.send_to_cc
.value
= $addr;
62 function bcc_address($addr) {
64 var pwintype
= typeof parent
.opener
.document
.compose
;
66 $addr = $addr.replace(/ {1,35}$
/, "");
68 if(pwintype
!= "undefined" ) {
69 if ( parent
.opener
.document
.compose
.send_to_bcc
.value
) {
71 parent
.opener
.document
.compose
.send_to_bcc
.value
=
72 parent
.opener
.document
.compose
.send_to_bcc
.value +
", " +
$addr;
74 parent
.opener
.document
.compose
.send_to_bcc
.value
= $addr;
82 } // End of included JavaScript
85 // List search results
86 function display_result($res, $includesource = true) {
89 if(sizeof($res) <= 0) return;
94 print "<TABLE BORDER=0 WIDTH=\"98%\" ALIGN=center>";
95 printf("<TR BGCOLOR=\"$color[9]\"><TH ALIGN=left> ".
96 "<TH ALIGN=left> %s<TH ALIGN=left> %s".
97 "<TH ALIGN=left> %s",
98 _("Name"), _("E-mail"), _("Info"));
101 printf("<TH ALIGN=left WIDTH=\"10%%\"> %s", _("Source"));
105 while(list($undef, $row) = each($res)) {
106 printf("<tr%s nowrap><td valign=top nowrap align=center width=\"5%%\">".
107 "<small><a href=\"javascript:to_address('%s');\">To</A> | ".
108 "<a href=\"javascript:cc_address('%s');\">Cc</A> | ".
109 "<a href=\"javascript:bcc_address('%s');\">Bcc</A></small>".
110 "<td nowrap valign=top> %s <td nowrap valign=top>".
111 " <a href=\"javascript:to_and_close('%s');\">%s</A> ".
112 "<td valign=top> %s ",
113 ($line %
2) ?
" bgcolor=\"$color[0]\"" : "",
114 $row["email"], $row["email"], $row["email"],
115 $row["name"], $row["email"], $row["email"],
119 printf("<td nowrap valign=top> %s", $row["source"]);
127 /* ================= End of functions ================= */
131 if (!isset($i18n_php))
132 include("../functions/i18n.php");
134 if(!isset($logged_in) ||
!isset($username) ||
!isset($key)) {
135 include ("../themes/default_theme.php");
136 include ("../functions/display_messages.php");
137 printf('<html><BODY TEXT="%s" BGCOLOR="%s" LINK="%s" VLINK="%s" ALINK="%s">',
138 $color[8], $color[4], $color[7], $color[7], $color[7]);
139 plain_error_message(_("You need a valid user and password to access this page!")
140 . "<br><a href=\"../src/login.php\">"
141 . _("Click here to log back in.") . "</a>.", $color);
142 echo "</body></html>";
145 if (!isset($config_php))
146 include("../config/config.php");
147 if (!isset($array_php))
148 include("../functions/array.php");
149 if (!isset($auth_php))
150 include("../functions/auth.php");
151 if (!isset($strings_php))
152 include("../functions/strings.php");
153 if (!isset($page_header_php))
154 include("../functions/page_header.php");
155 if (!isset($addressbook_php))
156 include("../functions/addressbook.php");
159 include("../src/load_prefs.php");
163 // Choose correct colors for top and bottom frame
164 if($show == "form") {
165 echo "<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" ";
166 echo "LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\" ";
167 echo "OnLoad=\"document.sform.query.focus();\">";
169 echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" ";
170 echo "LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
174 if(empty($query) && empty($show) && empty($listall)) {
175 printf("<P ALIGN=center><BR>%s</P>\n</BODY></HTML>\n",
176 _("No persons matching your search was found"));
180 // Initialize addressbook
181 $abook = addressbook_init();
183 // Create search form
184 if($show == "form") {
185 printf("<FORM NAME=sform TARGET=abookres ACTION=\"%s\" METHOD=\"POST\">\n",
187 printf("<TABLE BORDER=0 WIDTH=\"100%%\" HEIGHT=\"100%%\">");
188 printf("<TR><TD NOWRAP VALIGN=middle>\n");
189 printf(" <STRONG>%s</STRONG>\n", _("Search for"));
190 printf(" <INPUT TYPE=text NAME=query VALUE=\"%s\" SIZE=26>\n",
191 htmlspecialchars($query));
193 // List all backends to allow the user to choose where to search
194 if($abook->numbackends
> 1) {
195 printf("<STRONG>%s</STRONG> <SELECT NAME=backend>\n",
197 printf("<OPTION VALUE=-1 SELECTED>%s\n",
198 _("All address books"));
199 $ret = $abook->get_backend_list();
200 while(list($undef,$v) = each($ret))
201 printf("<OPTION VALUE=%d>%s\n", $v->bnum
, $v->sname
);
202 printf("</SELECT>\n");
204 printf("<INPUT TYPE=hidden NAME=backend VALUE=-1>\n");
207 printf("<INPUT TYPE=submit VALUE=\"%s\">",
209 printf(" | <INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n",
211 printf("</TD><TD ALIGN=right>\n");
212 printf("<INPUT TYPE=button VALUE=\"%s\" onclick=\"parent.close();\">\n",
214 printf("</TD></TR></TABLE></FORM>\n");
217 // Show personal addressbook
218 if($show == "blank" ||
!empty($listall)) {
220 if($backend != -1 ||
$show == "blank") {
222 $backend = $abook->localbackend
;
224 //printf("<H3 ALIGN=center>%s</H3>\n", $abook->backends[$backend]->sname);
226 $res = $abook->list_addr($backend);
229 display_result($res, false);
231 printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s").
232 "</STRONG></P>\n", $abook->backends
[$backend]->sname
);
236 $res = $abook->list_addr();
237 display_result($res, true);
243 if(!empty($query) && empty($listall)) {
246 $res = $abook->s_search($query);
248 $res = $abook->s_search($query, $backend);
251 if(!is_array($res)) {
252 printf("<P ALIGN=center><B><BR>%s:<br>%s</B></P>\n</BODY></HTML>\n",
253 _("Your search failed with the following error(s)"),
258 if(sizeof($res) == 0) {
259 printf("<P ALIGN=center><BR><B>%s.</B></P>\n</BODY></HTML>\n",
260 _("No persons matching your search was found"));
264 display_result($res);