6 * Copyright (c) 1999-2001 The Squirrelmail Development 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 /*****************************************************************/
19 /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
20 /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
21 /*** + Base level indent should begin at left margin, as ***/
22 /*** the require_once below looks. ***/
23 /*** + All identation should consist of four space blocks ***/
24 /*** + Tab characters are evil. ***/
25 /*** + all comments should use "slash-star ... star-slash" ***/
26 /*** style -- no pound characters, no slash-slash style ***/
27 /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
28 /*** ALWAYS USE { AND } CHARACTERS!!! ***/
29 /*** + Please use ' instead of ", when possible. Note " ***/
30 /*** should always be used in _( ) function calls. ***/
31 /*** Thank you for your help making the SM code more readable. ***/
32 /*****************************************************************/
34 require_once('../src/validate.php');
36 // Function to include JavaScript code
37 function insert_javascript() {
39 <SCRIPT LANGUAGE
="Javascript"><!--
41 function to_and_close($addr) {
46 function to_address($addr) {
48 var pwintype
= typeof parent
.opener
.document
.compose
;
50 $addr = $addr.replace(/ {1,35}$
/, "");
52 if(pwintype
!= "undefined" ) {
53 if ( parent
.opener
.document
.compose
.send_to
.value
) {
55 parent
.opener
.document
.compose
.send_to
.value
=
56 parent
.opener
.document
.compose
.send_to
.value +
", " +
$addr;
59 parent
.opener
.document
.compose
.send_to
.value
= $addr;
64 function cc_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_cc
.value
) {
73 parent
.opener
.document
.compose
.send_to_cc
.value
=
74 parent
.opener
.document
.compose
.send_to_cc
.value +
", " +
$addr;
76 parent
.opener
.document
.compose
.send_to_cc
.value
= $addr;
81 function bcc_address($addr) {
83 var pwintype
= typeof parent
.opener
.document
.compose
;
85 $addr = $addr.replace(/ {1,35}$
/, "");
87 if(pwintype
!= "undefined" ) {
88 if ( parent
.opener
.document
.compose
.send_to_bcc
.value
) {
90 parent
.opener
.document
.compose
.send_to_bcc
.value
=
91 parent
.opener
.document
.compose
.send_to_bcc
.value +
", " +
$addr;
93 parent
.opener
.document
.compose
.send_to_bcc
.value
= $addr;
101 } // End of included JavaScript
104 // List search results
105 function display_result($res, $includesource = true) {
108 if(sizeof($res) <= 0) return;
113 echo '<TABLE BORDER="0" WIDTH="98%" ALIGN=center>';
114 printf("<TR BGCOLOR=\"$color[9]\"><TH ALIGN=left> ".
115 "<TH ALIGN=left> %s<TH ALIGN=left> %s".
116 "<TH ALIGN=left> %s",
117 _("Name"), _("E-mail"), _("Info"));
120 printf("<TH ALIGN=left WIDTH=\"10%%\"> %s", _("Source"));
124 while(list($undef, $row) = each($res)) {
125 printf("<tr%s nowrap><td valign=top nowrap align=center width=\"5%%\">".
126 "<small><a href=\"javascript:to_address('%s');\">To</A> | ".
127 "<a href=\"javascript:cc_address('%s');\">Cc</A> | ".
128 "<a href=\"javascript:bcc_address('%s');\">Bcc</A></small>".
129 "<td nowrap valign=top> %s <td nowrap valign=top>".
130 " <a href=\"javascript:to_and_close('%s');\">%s</A> ".
131 "<td valign=top> %s ",
132 ($line %
2) ?
" bgcolor=\"$color[0]\"" : "",
133 $row["email"], $row["email"], $row["email"],
134 $row["name"], $row["email"], $row["email"],
138 printf("<td nowrap valign=top> %s", $row["source"]);
146 /* ================= End of functions ================= */
148 require_once('../functions/array.php');
149 require_once('../functions/strings.php');
150 require_once('../functions/addressbook.php');
155 if(!isset($query)) $query = "";
156 if(!isset($show)) $show = "";
158 // Choose correct colors for top and bottom frame
159 if($show == 'form') {
160 echo "<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" ";
161 echo "LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\" ";
162 echo 'OnLoad="document.sform.query.focus();">';
164 echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" ";
165 echo "LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n";
169 if(empty($query) && empty($show) && empty($listall)) {
170 printf("<P ALIGN=center><BR>%s</P>\n</BODY></HTML>\n",
171 _("No persons matching your search was found"));
175 // Initialize addressbook
176 $abook = addressbook_init();
178 // Create search form
179 if($show == 'form') {
180 echo "<FORM NAME=sform TARGET=abookres ACTION=\"$PHP_SELF\" METHOD=\"POST\">\n";
181 echo '<TABLE BORDER="0" WIDTH="100%" HEIGHT="100%">';
182 echo "<TR><TD NOWRAP VALIGN=middle>\n";
183 printf(" <STRONG>%s</STRONG>\n", _("Search for"));
184 printf(" <INPUT TYPE=text NAME=query VALUE=\"%s\" SIZE=26>\n",
185 htmlspecialchars($query));
187 // List all backends to allow the user to choose where to search
188 if($abook->numbackends
> 1) {
189 printf("<STRONG>%s</STRONG> <SELECT NAME=backend>\n",
191 printf("<OPTION VALUE=-1 SELECTED>%s\n",
192 _("All address books"));
193 $ret = $abook->get_backend_list();
194 while(list($undef,$v) = each($ret))
195 printf("<OPTION VALUE=%d>%s\n", $v->bnum
, $v->sname
);
198 print "<INPUT TYPE=hidden NAME=backend VALUE=-1>\n";
201 printf("<INPUT TYPE=submit VALUE=\"%s\">",
203 printf(" | <INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n",
205 print "</TD><TD ALIGN=right>\n";
206 printf("<INPUT TYPE=button VALUE=\"%s\" onclick=\"parent.close();\">\n",
208 print "</TD></TR></TABLE></FORM>\n";
211 // Show personal addressbook
212 if($show == 'blank' ||
!empty($listall)) {
214 if($backend != -1 ||
$show == 'blank') {
216 $backend = $abook->localbackend
;
218 $res = $abook->list_addr($backend);
221 display_result($res, false);
223 printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s").
224 "</STRONG></P>\n", $abook->backends
[$backend]->sname
);
228 $res = $abook->list_addr();
229 display_result($res, true);
235 if(!empty($query) && empty($listall)) {
238 $res = $abook->s_search($query);
240 $res = $abook->s_search($query, $backend);
243 if(!is_array($res)) {
244 printf("<P ALIGN=center><B><BR>%s:<br>%s</B></P>\n</BODY></HTML>\n",
245 _("Your search failed with the following error(s)"),
250 if(sizeof($res) == 0) {
251 printf("<P ALIGN=center><BR><B>%s.</B></P>\n</BODY></HTML>\n",
252 _("No persons matching your search was found"));
256 display_result($res);
259 echo "</BODY></HTML>\n";