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 require_once('../src/validate.php');
19 require_once('../functions/strings.php');
20 require_once('../functions/html.php');
22 /* Function to include JavaScript code */
23 function insert_javascript() {
25 <SCRIPT LANGUAGE
="Javascript"><!--
27 function to_and_close($addr) {
32 function to_address($addr) {
34 var pwintype
= typeof parent
.opener
.document
.compose
;
36 $addr = $addr.replace(/ {1,35}$
/, "");
38 if (pwintype
!= "undefined") {
39 if (parent
.opener
.document
.compose
.send_to
.value
) {
41 parent
.opener
.document
.compose
.send_to
.value
=
42 parent
.opener
.document
.compose
.send_to
.value +
", " +
$addr;
44 parent
.opener
.document
.compose
.send_to
.value
= $addr;
49 function cc_address($addr) {
51 var pwintype
= typeof parent
.opener
.document
.compose
;
53 $addr = $addr.replace(/ {1,35}$
/, "");
55 if (pwintype
!= "undefined") {
56 if (parent
.opener
.document
.compose
.send_to_cc
.value
) {
58 parent
.opener
.document
.compose
.send_to_cc
.value
=
59 parent
.opener
.document
.compose
.send_to_cc
.value +
", " +
$addr;
61 parent
.opener
.document
.compose
.send_to_cc
.value
= $addr;
66 function bcc_address($addr) {
68 var pwintype
= typeof parent
.opener
.document
.compose
;
70 $addr = $addr.replace(/ {1,35}$
/, "");
72 if (pwintype
!= "undefined") {
73 if (parent
.opener
.document
.compose
.send_to_bcc
.value
) {
75 parent
.opener
.document
.compose
.send_to_bcc
.value
=
76 parent
.opener
.document
.compose
.send_to_bcc
.value +
", " +
$addr;
78 parent
.opener
.document
.compose
.send_to_bcc
.value
= $addr;
85 } /* End of included JavaScript */
88 /* List search results */
89 function display_result($res, $includesource = true) {
92 if(sizeof($res) <= 0) return;
97 echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) .
98 html_tag( 'tr', '', '', $color[9] ) .
99 html_tag( 'th', ' ', 'left' ) .
100 html_tag( 'th', ' ' . _("Name"), 'left' ) .
101 html_tag( 'th', ' ' . _("E-mail"), 'left' ) .
102 html_tag( 'th', ' ' . _("Info"), 'left' );
104 if ($includesource) {
105 echo html_tag( 'th', ' ' . _("Source"), 'left', 'width="10%"' );
109 while (list($undef, $row) = each($res)) {
111 $email = htmlspecialchars(addcslashes(AddressBook
::full_address($row), "'"), ENT_QUOTES
);
112 if ($line %
2) { $tr_bgcolor = $color[0]; }
113 echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) .
115 '<small><a href="javascript:to_address(' .
116 "'" . $email . "');\">To</A> | " .
117 '<a href="javascript:cc_address(' .
118 "'" . $email . "');\">Cc</A> | " .
119 '<a href="javascript:bcc_address(' .
120 "'" . $email . "');\">Bcc</A></small>",
121 'center', '', 'valign="top" width="5%" nowrap' ) .
122 html_tag( 'td', ' ' . htmlspecialchars($row['name']), 'left', '', 'valign="top" nowrap' ) .
123 html_tag( 'td', ' ' .
124 '<a href="javascript:to_and_close(' .
125 "'" . $email . "');\">" . htmlspecialchars($row['email']) . '</A>'
126 , 'left', '', 'valign="top"' ) .
127 html_tag( 'td', htmlspecialchars($row['label']), 'left', '', 'valign="top" nowrap' );
128 if ($includesource) {
129 echo html_tag( 'td', ' ' . $row['source'], 'left', '', 'valign="top" nowrap' );
138 /* ================= End of functions ================= */
140 require_once('../functions/array.php');
141 require_once('../functions/strings.php');
142 require_once('../functions/addressbook.php');
146 /* Initialize vars */
147 if (!isset($query)) { $query = ''; }
148 if (!isset($show)) { $show = ''; }
149 if (!isset($backend)) { $backend = ''; }
151 /* Choose correct colors for top and bottom frame */
152 if ($show == 'form' && !isset($listall)) {
153 echo '<BODY TEXT="' . $color[6] . '" BGCOLOR="' . $color[3] . '" ' .
154 'LINK="' . $color[6] . '" VLINK="' . $color[6] . '" ' .
155 'ALINK="' . $color[6] . '" ' .
156 'OnLoad="document.sform.query.focus();">';
158 echo '<BODY TEXT="' . $color[8] . '" BGCOLOR="' . $color[4] . '" ' .
159 'LINK="' . $color[7] . '" VLINK="' . $color[7] . '" ' .
160 'ALINK="' . $color[7] . "\">\n";
164 if (empty($query) && empty($show) && empty($listall)) {
165 echo html_tag( 'p', '<br>' .
166 _("No persons matching your search was found"),
168 "\n</BODY></HTML>\n",
172 /* Initialize addressbook */
173 $abook = addressbook_init();
175 /* Create search form */
176 if ($show == 'form' && empty($listall)) {
177 echo '<FORM NAME=sform TARGET=abookres ACTION="addrbook_search.php'.
178 '" METHOD="POST">' . "\n" .
179 html_tag( 'table', '', '', '', 'border="0" width="100%" height="100%"' ) .
181 html_tag( 'td', ' <strong>' . _("Search for") . "</strong>\n", 'left', '', 'nowrap valign="middle" width="10%"' ) .
182 html_tag( 'td', '', 'left', '', '' ) .
183 '<INPUT TYPE=text NAME=query VALUE="' . htmlspecialchars($query) .
186 /* List all backends to allow the user to choose where to search */
187 if ($abook->numbackends
> 1) {
188 echo '<STRONG>' . _("in") . '</STRONG> <SELECT NAME=backend>'."\n".
189 '<OPTION VALUE=-1 SELECTED>' . _("All address books") . "\n";
190 $ret = $abook->get_backend_list();
191 while (list($undef,$v) = each($ret)) {
192 echo '<OPTION VALUE=' . $v->bnum
. '>' . $v->sname
. "\n";
196 echo '<INPUT TYPE=hidden NAME=backend VALUE=-1>' . "\n";
201 html_tag( 'td', '', 'left' ) .
203 '<INPUT TYPE=submit VALUE="' . _("Search") . '" NAME=show>' .
204 ' | <INPUT TYPE=submit VALUE="' . _("List all") .
205 '" NAME=listall>' . "\n" .
206 ' | <INPUT TYPE=button VALUE="' . _("Close") .
207 '" onclick="parent.close();">' . "\n" ,
210 '</table></form>' . "\n";
213 /* Show personal addressbook */
214 if ($show == 'blank' && empty($listall)) {
216 if($backend != -1 ||
$show == 'blank') {
217 if ($show == 'blank') {
218 $backend = $abook->localbackend
;
220 $res = $abook->list_addr($backend);
223 usort($res,'alistcmp');
224 display_result($res, false);
226 echo html_tag( 'p', '<strong>' .
227 sprintf(_("Unable to list addresses from %s"),
228 $abook->backends
[$backend]->sname
) . '</strong>' ,
232 $res = $abook->list_addr();
233 usort($res,'alistcmp');
234 display_result($res, true);
238 if( !empty( $listall ) ){
243 if (!empty($query)) {
246 $res = $abook->s_search($query);
248 $res = $abook->s_search($query, $backend);
251 if (!is_array($res)) {
252 echo html_tag( 'p', '<b><br>' .
253 _("Your search failed with the following error(s)") .
254 ':<br>' . $abook->error
. "</b>\n" ,
256 "\n</BODY></HTML>\n";
260 if (sizeof($res) == 0) {
261 echo html_tag( 'p', '<br><b>' .
262 _("No persons matching your search was found") . "</b>\n" ,
264 "\n</BODY></HTML>\n";
268 display_result($res);
274 echo "</BODY></HTML>\n";