4cfca0968c951cf6e4c36e60f63698c90a1fbaee
6 * Copyright (c) 1999-2004 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!
16 * @package squirrelmail
20 * Path for SquirrelMail required files.
22 define('SM_PATH','../');
24 /** SquirrelMail required files. */
25 require_once(SM_PATH
. 'include/validate.php');
26 require_once(SM_PATH
. 'functions/strings.php');
27 require_once(SM_PATH
. 'functions/global.php');
28 require_once(SM_PATH
. 'functions/html.php');
30 /** lets get the global vars we may need */
31 sqgetGlobalVar('key', $key, SQ_COOKIE
);
32 sqgetGlobalVar('username', $username, SQ_SESSION
);
33 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
34 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
36 sqgetGlobalVar('show' , $show);
37 sqgetGlobalVar('query', $query, SQ_POST
);
38 sqgetGlobalVar('listall', $listall, SQ_POST
);
39 sqgetGlobalVar('backend', $backend, SQ_POST
);
42 * Function to include JavaScript code
45 function insert_javascript() {
47 <SCRIPT LANGUAGE
="Javascript"><!--
49 function to_and_close($addr) {
54 function to_address($addr) {
56 var pwintype
= typeof parent
.opener
.document
.compose
;
58 $addr = $addr.replace(/ {1,35}$
/, "");
60 if (pwintype
!= "undefined") {
61 if (parent
.opener
.document
.compose
.send_to
.value
) {
63 parent
.opener
.document
.compose
.send_to
.value
=
64 parent
.opener
.document
.compose
.send_to
.value +
", " +
$addr;
66 parent
.opener
.document
.compose
.send_to
.value
= $addr;
71 function cc_address($addr) {
73 var pwintype
= typeof parent
.opener
.document
.compose
;
75 $addr = $addr.replace(/ {1,35}$
/, "");
77 if (pwintype
!= "undefined") {
78 if (parent
.opener
.document
.compose
.send_to_cc
.value
) {
80 parent
.opener
.document
.compose
.send_to_cc
.value
=
81 parent
.opener
.document
.compose
.send_to_cc
.value +
", " +
$addr;
83 parent
.opener
.document
.compose
.send_to_cc
.value
= $addr;
88 function bcc_address($addr) {
90 var pwintype
= typeof parent
.opener
.document
.compose
;
92 $addr = $addr.replace(/ {1,35}$
/, "");
94 if (pwintype
!= "undefined") {
95 if (parent
.opener
.document
.compose
.send_to_bcc
.value
) {
97 parent
.opener
.document
.compose
.send_to_bcc
.value
=
98 parent
.opener
.document
.compose
.send_to_bcc
.value +
", " +
$addr;
100 parent
.opener
.document
.compose
.send_to_bcc
.value
= $addr;
107 } /* End of included JavaScript */
111 * List search results
112 * @param array $res Array of search results
113 * @param bool $includesource [Default=true]
116 function display_result($res, $includesource = true) {
119 if(sizeof($res) <= 0) return;
124 echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) .
125 html_tag( 'tr', '', '', $color[9] ) .
126 html_tag( 'th', ' ', 'left' ) .
127 html_tag( 'th', ' ' . _("Name"), 'left' ) .
128 html_tag( 'th', ' ' . _("E-mail"), 'left' ) .
129 html_tag( 'th', ' ' . _("Info"), 'left' );
131 if ($includesource) {
132 echo html_tag( 'th', ' ' . _("Source"), 'left', 'width="10%"' );
136 while (list($undef, $row) = each($res)) {
138 $email = htmlspecialchars(addcslashes(AddressBook
::full_address($row), "'"), ENT_QUOTES
);
139 if ($line %
2) { $tr_bgcolor = $color[0]; }
140 echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) .
142 '<small><a href="javascript:to_address(' .
143 "'" . $email . "');\">To</A> | " .
144 '<a href="javascript:cc_address(' .
145 "'" . $email . "');\">Cc</A> | " .
146 '<a href="javascript:bcc_address(' .
147 "'" . $email . "');\">Bcc</A></small>",
148 'center', '', 'valign="top" width="5%" nowrap' ) .
149 html_tag( 'td', ' ' . htmlspecialchars($row['name']), 'left', '', 'valign="top" nowrap' ) .
150 html_tag( 'td', ' ' .
151 '<a href="javascript:to_and_close(' .
152 "'" . $email . "');\">" . htmlspecialchars($row['email']) . '</A>'
153 , 'left', '', 'valign="top"' ) .
154 html_tag( 'td', htmlspecialchars($row['label']), 'left', '', 'valign="top" nowrap' );
155 if ($includesource) {
156 echo html_tag( 'td', ' ' . $row['source'], 'left', '', 'valign="top" nowrap' );
165 /* ================= End of functions ================= */
167 require_once('../functions/strings.php');
168 require_once('../functions/addressbook.php');
172 /* Initialize vars */
173 if (!isset($query)) { $query = ''; }
174 if (!isset($show)) { $show = ''; }
175 if (!isset($backend)) { $backend = ''; }
177 /* Choose correct colors for top and bottom frame */
178 if ($show == 'form' && !isset($listall)) {
179 echo '<BODY TEXT="' . $color[6] . '" BGCOLOR="' . $color[3] . '" ' .
180 'LINK="' . $color[6] . '" VLINK="' . $color[6] . '" ' .
181 'ALINK="' . $color[6] . '" ' .
182 'OnLoad="document.sform.query.focus();">';
184 echo '<BODY TEXT="' . $color[8] . '" BGCOLOR="' . $color[4] . '" ' .
185 'LINK="' . $color[7] . '" VLINK="' . $color[7] . '" ' .
186 'ALINK="' . $color[7] . "\">\n";
190 if (empty($query) && empty($show) && empty($listall)) {
191 echo html_tag( 'p', '<br>' .
192 _("No persons matching your search was found"),
194 "\n</BODY></HTML>\n",
198 /* Initialize addressbook */
199 $abook = addressbook_init();
201 /* Create search form */
202 if ($show == 'form' && empty($listall)) {
203 echo '<FORM NAME=sform TARGET=abookres ACTION="addrbook_search.php'.
204 '" METHOD="POST">' . "\n" .
205 html_tag( 'table', '', '', '', 'border="0" width="100%" height="100%"' ) .
207 html_tag( 'td', ' <strong>' . _("Search for") . "</strong>\n", 'left', '', 'nowrap valign="middle" width="10%"' ) .
208 html_tag( 'td', '', 'left', '', '' ) .
209 '<INPUT TYPE=text NAME=query VALUE="' . htmlspecialchars($query) .
212 /* List all backends to allow the user to choose where to search */
213 if ($abook->numbackends
> 1) {
214 echo '<STRONG>' . _("in") . '</STRONG> <SELECT NAME=backend>'."\n".
215 '<OPTION VALUE=-1 SELECTED>' . _("All address books") . "\n";
216 $ret = $abook->get_backend_list();
217 while (list($undef,$v) = each($ret)) {
218 echo '<OPTION VALUE=' . $v->bnum
. '>' . $v->sname
. "\n";
222 echo '<INPUT TYPE=hidden NAME=backend VALUE=-1>' . "\n";
227 html_tag( 'td', '', 'left' ) .
229 '<INPUT TYPE=submit VALUE="' . _("Search") . '" NAME=show>' .
230 ' | <INPUT TYPE=submit VALUE="' . _("List all") .
231 '" NAME=listall>' . "\n" .
232 ' | <INPUT TYPE=button VALUE="' . _("Close") .
233 '" onclick="parent.close();">' . "\n" ,
236 '</table></form>' . "\n";
239 /* Show personal addressbook */
240 if ($show == 'blank' && empty($listall)) {
242 if($backend != -1 ||
$show == 'blank') {
243 if ($show == 'blank') {
244 $backend = $abook->localbackend
;
246 $res = $abook->list_addr($backend);
249 usort($res,'alistcmp');
250 display_result($res, false);
252 echo html_tag( 'p', '<strong>' .
253 sprintf(_("Unable to list addresses from %s"),
254 $abook->backends
[$backend]->sname
) . '</strong>' ,
258 $res = $abook->list_addr();
259 usort($res,'alistcmp');
260 display_result($res, true);
264 if( !empty( $listall ) ){
269 if (!empty($query)) {
272 $res = $abook->s_search($query);
274 $res = $abook->s_search($query, $backend);
277 if (!is_array($res)) {
278 echo html_tag( 'p', '<b><br>' .
279 _("Your search failed with the following error(s)") .
280 ':<br>' . $abook->error
. "</b>\n" ,
282 "\n</BODY></HTML>\n";
286 if (sizeof($res) == 0) {
287 echo html_tag( 'p', '<br><b>' .
288 _("No persons matching your search was found") . "</b>\n" ,
290 "\n</BODY></HTML>\n";
294 display_result($res);
300 echo "</BODY></HTML>\n";