6 * Copyright (c) 1999-2003 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/global.php');
25 require_once(SM_PATH
. 'functions/html.php');
27 /* lets get the global vars we may need */
28 sqgetGlobalVar('key', $key, SQ_COOKIE
);
29 sqgetGlobalVar('username', $username, SQ_SESSION
);
30 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
31 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
33 sqgetGlobalVar('show' , $show);
34 sqgetGlobalVar('query', $query, SQ_POST
);
35 sqgetGlobalVar('listall', $listall, SQ_POST
);
36 sqgetGlobalVar('backend', $backend, SQ_POST
);
38 /* Function to include JavaScript code */
39 function insert_javascript() {
41 <SCRIPT LANGUAGE
="Javascript"><!--
43 function to_and_close($addr) {
48 function to_address($addr) {
50 var pwintype
= typeof parent
.opener
.document
.compose
;
52 $addr = $addr.replace(/ {1,35}$
/, "");
54 if (pwintype
!= "undefined") {
55 if (parent
.opener
.document
.compose
.send_to
.value
) {
57 parent
.opener
.document
.compose
.send_to
.value
=
58 parent
.opener
.document
.compose
.send_to
.value +
", " +
$addr;
60 parent
.opener
.document
.compose
.send_to
.value
= $addr;
65 function cc_address($addr) {
67 var pwintype
= typeof parent
.opener
.document
.compose
;
69 $addr = $addr.replace(/ {1,35}$
/, "");
71 if (pwintype
!= "undefined") {
72 if (parent
.opener
.document
.compose
.send_to_cc
.value
) {
74 parent
.opener
.document
.compose
.send_to_cc
.value
=
75 parent
.opener
.document
.compose
.send_to_cc
.value +
", " +
$addr;
77 parent
.opener
.document
.compose
.send_to_cc
.value
= $addr;
82 function bcc_address($addr) {
84 var pwintype
= typeof parent
.opener
.document
.compose
;
86 $addr = $addr.replace(/ {1,35}$
/, "");
88 if (pwintype
!= "undefined") {
89 if (parent
.opener
.document
.compose
.send_to_bcc
.value
) {
91 parent
.opener
.document
.compose
.send_to_bcc
.value
=
92 parent
.opener
.document
.compose
.send_to_bcc
.value +
", " +
$addr;
94 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 html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) .
114 html_tag( 'tr', '', '', $color[9] ) .
115 html_tag( 'th', ' ', 'left' ) .
116 html_tag( 'th', ' ' . _("Name"), 'left' ) .
117 html_tag( 'th', ' ' . _("E-mail"), 'left' ) .
118 html_tag( 'th', ' ' . _("Info"), 'left' );
120 if ($includesource) {
121 echo html_tag( 'th', ' ' . _("Source"), 'left', 'width="10%"' );
125 while (list($undef, $row) = each($res)) {
127 $email = htmlspecialchars(addcslashes(AddressBook
::full_address($row), "'"), ENT_QUOTES
);
128 if ($line %
2) { $tr_bgcolor = $color[0]; }
129 echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) .
131 '<small><a href="javascript:to_address(' .
132 "'" . $email . "');\">To</A> | " .
133 '<a href="javascript:cc_address(' .
134 "'" . $email . "');\">Cc</A> | " .
135 '<a href="javascript:bcc_address(' .
136 "'" . $email . "');\">Bcc</A></small>",
137 'center', '', 'valign="top" width="5%" nowrap' ) .
138 html_tag( 'td', ' ' . htmlspecialchars($row['name']), 'left', '', 'valign="top" nowrap' ) .
139 html_tag( 'td', ' ' .
140 '<a href="javascript:to_and_close(' .
141 "'" . $email . "');\">" . htmlspecialchars($row['email']) . '</A>'
142 , 'left', '', 'valign="top"' ) .
143 html_tag( 'td', htmlspecialchars($row['label']), 'left', '', 'valign="top" nowrap' );
144 if ($includesource) {
145 echo html_tag( 'td', ' ' . $row['source'], 'left', '', 'valign="top" nowrap' );
154 /* ================= End of functions ================= */
156 require_once('../functions/strings.php');
157 require_once('../functions/addressbook.php');
161 /* Initialize vars */
162 if (!isset($query)) { $query = ''; }
163 if (!isset($show)) { $show = ''; }
164 if (!isset($backend)) { $backend = ''; }
166 /* Choose correct colors for top and bottom frame */
167 if ($show == 'form' && !isset($listall)) {
168 echo '<BODY TEXT="' . $color[6] . '" BGCOLOR="' . $color[3] . '" ' .
169 'LINK="' . $color[6] . '" VLINK="' . $color[6] . '" ' .
170 'ALINK="' . $color[6] . '" ' .
171 'OnLoad="document.sform.query.focus();">';
173 echo '<BODY TEXT="' . $color[8] . '" BGCOLOR="' . $color[4] . '" ' .
174 'LINK="' . $color[7] . '" VLINK="' . $color[7] . '" ' .
175 'ALINK="' . $color[7] . "\">\n";
179 if (empty($query) && empty($show) && empty($listall)) {
180 echo html_tag( 'p', '<br>' .
181 _("No persons matching your search was found"),
183 "\n</BODY></HTML>\n",
187 /* Initialize addressbook */
188 $abook = addressbook_init();
190 /* Create search form */
191 if ($show == 'form' && empty($listall)) {
192 echo '<FORM NAME=sform TARGET=abookres ACTION="addrbook_search.php'.
193 '" METHOD="POST">' . "\n" .
194 html_tag( 'table', '', '', '', 'border="0" width="100%" height="100%"' ) .
196 html_tag( 'td', ' <strong>' . _("Search for") . "</strong>\n", 'left', '', 'nowrap valign="middle" width="10%"' ) .
197 html_tag( 'td', '', 'left', '', '' ) .
198 '<INPUT TYPE=text NAME=query VALUE="' . htmlspecialchars($query) .
201 /* List all backends to allow the user to choose where to search */
202 if ($abook->numbackends
> 1) {
203 echo '<STRONG>' . _("in") . '</STRONG> <SELECT NAME=backend>'."\n".
204 '<OPTION VALUE=-1 SELECTED>' . _("All address books") . "\n";
205 $ret = $abook->get_backend_list();
206 while (list($undef,$v) = each($ret)) {
207 echo '<OPTION VALUE=' . $v->bnum
. '>' . $v->sname
. "\n";
211 echo '<INPUT TYPE=hidden NAME=backend VALUE=-1>' . "\n";
216 html_tag( 'td', '', 'left' ) .
218 '<INPUT TYPE=submit VALUE="' . _("Search") . '" NAME=show>' .
219 ' | <INPUT TYPE=submit VALUE="' . _("List all") .
220 '" NAME=listall>' . "\n" .
221 ' | <INPUT TYPE=button VALUE="' . _("Close") .
222 '" onclick="parent.close();">' . "\n" ,
225 '</table></form>' . "\n";
228 /* Show personal addressbook */
229 if ($show == 'blank' && empty($listall)) {
231 if($backend != -1 ||
$show == 'blank') {
232 if ($show == 'blank') {
233 $backend = $abook->localbackend
;
235 $res = $abook->list_addr($backend);
238 usort($res,'alistcmp');
239 display_result($res, false);
241 echo html_tag( 'p', '<strong>' .
242 sprintf(_("Unable to list addresses from %s"),
243 $abook->backends
[$backend]->sname
) . '</strong>' ,
247 $res = $abook->list_addr();
248 usort($res,'alistcmp');
249 display_result($res, true);
253 if( !empty( $listall ) ){
258 if (!empty($query)) {
261 $res = $abook->s_search($query);
263 $res = $abook->s_search($query, $backend);
266 if (!is_array($res)) {
267 echo html_tag( 'p', '<b><br>' .
268 _("Your search failed with the following error(s)") .
269 ':<br>' . $abook->error
. "</b>\n" ,
271 "\n</BODY></HTML>\n";
275 if (sizeof($res) == 0) {
276 echo html_tag( 'p', '<br><b>' .
277 _("No persons matching your search was found") . "</b>\n" ,
279 "\n</BODY></HTML>\n";
283 display_result($res);
289 echo "</BODY></HTML>\n";