6 * Copyright (c) 1999-2002 The SquirrelMail Project 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 /* Path for SquirrelMail required files. */
19 define('SM_PATH','../');
21 /* SquirrelMail required files. */
22 require_once(SM_PATH
. 'include/validate.php');
23 require_once(SM_PATH
. 'functions/strings.php');
24 require_once(SM_PATH
. 'functions/html.php');
26 /* Function to include JavaScript code */
27 function insert_javascript() {
29 <SCRIPT LANGUAGE
="Javascript"><!--
31 function to_and_close($addr) {
36 function to_address($addr) {
38 var pwintype
= typeof parent
.opener
.document
.compose
;
40 $addr = $addr.replace(/ {1,35}$
/, "");
42 if (pwintype
!= "undefined") {
43 if (parent
.opener
.document
.compose
.send_to
.value
) {
45 parent
.opener
.document
.compose
.send_to
.value
=
46 parent
.opener
.document
.compose
.send_to
.value +
", " +
$addr;
48 parent
.opener
.document
.compose
.send_to
.value
= $addr;
53 function cc_address($addr) {
55 var pwintype
= typeof parent
.opener
.document
.compose
;
57 $addr = $addr.replace(/ {1,35}$
/, "");
59 if (pwintype
!= "undefined") {
60 if (parent
.opener
.document
.compose
.send_to_cc
.value
) {
62 parent
.opener
.document
.compose
.send_to_cc
.value
=
63 parent
.opener
.document
.compose
.send_to_cc
.value +
", " +
$addr;
65 parent
.opener
.document
.compose
.send_to_cc
.value
= $addr;
70 function bcc_address($addr) {
72 var pwintype
= typeof parent
.opener
.document
.compose
;
74 $addr = $addr.replace(/ {1,35}$
/, "");
76 if (pwintype
!= "undefined") {
77 if (parent
.opener
.document
.compose
.send_to_bcc
.value
) {
79 parent
.opener
.document
.compose
.send_to_bcc
.value
=
80 parent
.opener
.document
.compose
.send_to_bcc
.value +
", " +
$addr;
82 parent
.opener
.document
.compose
.send_to_bcc
.value
= $addr;
89 } /* End of included JavaScript */
92 /* List search results */
93 function display_result($res, $includesource = true) {
96 if(sizeof($res) <= 0) return;
101 echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) .
102 html_tag( 'tr', '', '', $color[9] ) .
103 html_tag( 'th', ' ', 'left' ) .
104 html_tag( 'th', ' ' . _("Name"), 'left' ) .
105 html_tag( 'th', ' ' . _("E-mail"), 'left' ) .
106 html_tag( 'th', ' ' . _("Info"), 'left' );
108 if ($includesource) {
109 echo html_tag( 'th', ' ' . _("Source"), 'left', 'width="10%"' );
113 while (list($undef, $row) = each($res)) {
115 $email = htmlspecialchars(addcslashes(AddressBook
::full_address($row), "'"), ENT_QUOTES
);
116 if ($line %
2) { $tr_bgcolor = $color[0]; }
117 echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) .
119 '<small><a href="javascript:to_address(' .
120 "'" . $email . "');\">To</A> | " .
121 '<a href="javascript:cc_address(' .
122 "'" . $email . "');\">Cc</A> | " .
123 '<a href="javascript:bcc_address(' .
124 "'" . $email . "');\">Bcc</A></small>",
125 'center', '', 'valign="top" width="5%" nowrap' ) .
126 html_tag( 'td', ' ' . htmlspecialchars($row['name']), 'left', '', 'valign="top" nowrap' ) .
127 html_tag( 'td', ' ' .
128 '<a href="javascript:to_and_close(' .
129 "'" . $email . "');\">" . htmlspecialchars($row['email']) . '</A>'
130 , 'left', '', 'valign="top"' ) .
131 html_tag( 'td', htmlspecialchars($row['label']), 'left', '', 'valign="top" nowrap' );
132 if ($includesource) {
133 echo html_tag( 'td', ' ' . $row['source'], 'left', '', 'valign="top" nowrap' );
142 /* ================= End of functions ================= */
144 require_once('../functions/array.php');
145 require_once('../functions/strings.php');
146 require_once('../functions/addressbook.php');
150 /* Initialize vars */
151 if (!isset($query)) { $query = ''; }
152 if (!isset($show)) { $show = ''; }
153 if (!isset($backend)) { $backend = ''; }
155 /* Choose correct colors for top and bottom frame */
156 if ($show == 'form' && !isset($listall)) {
157 echo '<BODY TEXT="' . $color[6] . '" BGCOLOR="' . $color[3] . '" ' .
158 'LINK="' . $color[6] . '" VLINK="' . $color[6] . '" ' .
159 'ALINK="' . $color[6] . '" ' .
160 'OnLoad="document.sform.query.focus();">';
162 echo '<BODY TEXT="' . $color[8] . '" BGCOLOR="' . $color[4] . '" ' .
163 'LINK="' . $color[7] . '" VLINK="' . $color[7] . '" ' .
164 'ALINK="' . $color[7] . "\">\n";
168 if (empty($query) && empty($show) && empty($listall)) {
169 echo html_tag( 'p', '<br>' .
170 _("No persons matching your search was found"),
172 "\n</BODY></HTML>\n",
176 /* Initialize addressbook */
177 $abook = addressbook_init();
179 /* Create search form */
180 if ($show == 'form' && empty($listall)) {
181 echo '<FORM NAME=sform TARGET=abookres ACTION="addrbook_search.php'.
182 '" METHOD="POST">' . "\n" .
183 html_tag( 'table', '', '', '', 'border="0" width="100%" height="100%"' ) .
185 html_tag( 'td', ' <strong>' . _("Search for") . "</strong>\n", 'left', '', 'nowrap valign="middle" width="10%"' ) .
186 html_tag( 'td', '', 'left', '', '' ) .
187 '<INPUT TYPE=text NAME=query VALUE="' . htmlspecialchars($query) .
190 /* List all backends to allow the user to choose where to search */
191 if ($abook->numbackends
> 1) {
192 echo '<STRONG>' . _("in") . '</STRONG> <SELECT NAME=backend>'."\n".
193 '<OPTION VALUE=-1 SELECTED>' . _("All address books") . "\n";
194 $ret = $abook->get_backend_list();
195 while (list($undef,$v) = each($ret)) {
196 echo '<OPTION VALUE=' . $v->bnum
. '>' . $v->sname
. "\n";
200 echo '<INPUT TYPE=hidden NAME=backend VALUE=-1>' . "\n";
205 html_tag( 'td', '', 'left' ) .
207 '<INPUT TYPE=submit VALUE="' . _("Search") . '" NAME=show>' .
208 ' | <INPUT TYPE=submit VALUE="' . _("List all") .
209 '" NAME=listall>' . "\n" .
210 ' | <INPUT TYPE=button VALUE="' . _("Close") .
211 '" onclick="parent.close();">' . "\n" ,
214 '</table></form>' . "\n";
217 /* Show personal addressbook */
218 if ($show == 'blank' && empty($listall)) {
220 if($backend != -1 ||
$show == 'blank') {
221 if ($show == 'blank') {
222 $backend = $abook->localbackend
;
224 $res = $abook->list_addr($backend);
227 usort($res,'alistcmp');
228 display_result($res, false);
230 echo html_tag( 'p', '<strong>' .
231 sprintf(_("Unable to list addresses from %s"),
232 $abook->backends
[$backend]->sname
) . '</strong>' ,
236 $res = $abook->list_addr();
237 usort($res,'alistcmp');
238 display_result($res, true);
242 if( !empty( $listall ) ){
247 if (!empty($query)) {
250 $res = $abook->s_search($query);
252 $res = $abook->s_search($query, $backend);
255 if (!is_array($res)) {
256 echo html_tag( 'p', '<b><br>' .
257 _("Your search failed with the following error(s)") .
258 ':<br>' . $abook->error
. "</b>\n" ,
260 "\n</BODY></HTML>\n";
264 if (sizeof($res) == 0) {
265 echo html_tag( 'p', '<br><b>' .
266 _("No persons matching your search was found") . "</b>\n" ,
268 "\n</BODY></HTML>\n";
272 display_result($res);
278 echo "</BODY></HTML>\n";