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 if ($line %
2) { $tr_bgcolor = $color[0]; }
112 echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) .
114 '<small><a href="javascript:to_address(' .
115 "'" . $row['email'] . "');\">To</A> | " .
116 '<a href="javascript:cc_address(' .
117 "'" . $row['email'] . "');\">Cc</A> | " .
118 '<a href="javascript:bcc_address(' .
119 "'" . $row['email'] . "');\">Bcc</A></small>",
120 'center', '', 'valign="top" width="5%" nowrap' ) .
121 html_tag( 'td', ' ' . $row['name'], 'left', '', 'valign="top" nowrap' ) .
122 html_tag( 'td', ' ' .
123 '<a href="javascript:to_and_close(' .
124 "'" . $row['email'] . "');\">" . $row['email'] . '</A>'
125 , 'left', '', 'valign="top"' ) .
126 html_tag( 'td', $row['label'], 'left', '', 'valign="top" nowrap' );
127 if ($includesource) {
128 echo html_tag( 'td', ' ' . $row['source'], 'left', '', 'valign="top" nowrap' );
137 /* ================= End of functions ================= */
139 require_once('../functions/array.php');
140 require_once('../functions/strings.php');
141 require_once('../functions/addressbook.php');
145 /* Initialize vars */
146 if (!isset($query)) { $query = ''; }
147 if (!isset($show)) { $show = ''; }
148 if (!isset($backend)) { $backend = ''; }
150 /* Choose correct colors for top and bottom frame */
151 if ($show == 'form' && !isset($listall)) {
152 echo '<BODY TEXT="' . $color[6] . '" BGCOLOR="' . $color[3] . '" ' .
153 'LINK="' . $color[6] . '" VLINK="' . $color[6] . '" ' .
154 'ALINK="' . $color[6] . '" ' .
155 'OnLoad="document.sform.query.focus();">';
157 echo '<BODY TEXT="' . $color[8] . '" BGCOLOR="' . $color[4] . '" ' .
158 'LINK="' . $color[7] . '" VLINK="' . $color[7] . '" ' .
159 'ALINK="' . $color[7] . "\">\n";
163 if (empty($query) && empty($show) && empty($listall)) {
164 echo html_tag( 'p', '<br>' .
165 _("No persons matching your search was found"),
167 "\n</BODY></HTML>\n",
171 /* Initialize addressbook */
172 $abook = addressbook_init();
174 /* Create search form */
175 if ($show == 'form' && empty($listall)) {
176 echo '<FORM NAME=sform TARGET=abookres ACTION="addrbook_search.php'.
177 '" METHOD="POST">' . "\n" .
178 html_tag( 'table', '', '', '', 'border="0" width="100%" height="100%"' ) .
180 html_tag( 'td', ' <strong>' . _("Search for") . "</strong>\n", 'left', '', 'nowrap valign="middle" width="10%"' ) .
181 html_tag( 'td', '', 'left', '', '' ) .
182 '<INPUT TYPE=text NAME=query VALUE="' . htmlspecialchars($query) .
185 /* List all backends to allow the user to choose where to search */
186 if ($abook->numbackends
> 1) {
187 echo '<STRONG>' . _("in") . '</STRONG> <SELECT NAME=backend>'."\n".
188 '<OPTION VALUE=-1 SELECTED>' . _("All address books") . "\n";
189 $ret = $abook->get_backend_list();
190 while (list($undef,$v) = each($ret)) {
191 echo '<OPTION VALUE=' . $v->bnum
. '>' . $v->sname
. "\n";
195 echo '<INPUT TYPE=hidden NAME=backend VALUE=-1>' . "\n";
200 html_tag( 'td', '', 'left' ) .
202 '<INPUT TYPE=submit VALUE="' . _("Search") . '" NAME=show>' .
203 ' | <INPUT TYPE=submit VALUE="' . _("List all") .
204 '" NAME=listall>' . "\n" .
205 ' | <INPUT TYPE=button VALUE="' . _("Close") .
206 '" onclick="parent.close();">' . "\n" ,
209 '</table></form>' . "\n";
212 /* Show personal addressbook */
213 if ($show == 'blank' && empty($listall)) {
215 if($backend != -1 ||
$show == 'blank') {
216 if ($show == 'blank') {
217 $backend = $abook->localbackend
;
219 $res = $abook->list_addr($backend);
222 usort($res,'alistcmp');
223 display_result($res, false);
225 echo html_tag( 'p', '<strong>' .
226 sprintf(_("Unable to list addresses from %s"),
227 $abook->backends
[$backend]->sname
) . '</strong>' ,
231 $res = $abook->list_addr();
232 usort($res,'alistcmp');
233 display_result($res, true);
237 if( !empty( $listall ) ){
242 if (!empty($query)) {
245 $res = $abook->s_search($query);
247 $res = $abook->s_search($query, $backend);
250 if (!is_array($res)) {
251 echo html_tag( 'p', '<b><br>' .
252 _("Your search failed with the following error(s)") .
253 ':<br>' . $abook->error
. "</b>\n" ,
255 "\n</BODY></HTML>\n";
259 if (sizeof($res) == 0) {
260 echo html_tag( 'p', '<br><b>' .
261 _("No persons matching your search was found") . "</b>\n" ,
263 "\n</BODY></HTML>\n";
267 display_result($res);
273 echo "</BODY></HTML>\n";