53f81c9bf3eb71c69976b1cd953896ad157403a3
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 /* lets get the global vars we may need */
27 $key = $_COOKIE['key'];
28 $username = $_SESSION['username'];
29 $onetimepad = $_SESSION['onetimepad'];
30 $base_uri = $_SESSION['base_uri'];
32 sqextractGlobalVar('show');
33 if ( isset($_POST['query']) ) {
34 $query = $_POST['query'];
36 if ( isset($_POST['listall']) ) {
37 $listall = $_POST['listall'];
39 if ( isset($_POST['backend'] ) ) {
40 $backend = $_POST['backend'];
43 /* Function to include JavaScript code */
44 function insert_javascript() {
46 <SCRIPT LANGUAGE
="Javascript"><!--
48 function to_and_close($addr) {
53 function to_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
.value
) {
62 parent
.opener
.document
.compose
.send_to
.value
=
63 parent
.opener
.document
.compose
.send_to
.value +
", " +
$addr;
65 parent
.opener
.document
.compose
.send_to
.value
= $addr;
70 function cc_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_cc
.value
) {
79 parent
.opener
.document
.compose
.send_to_cc
.value
=
80 parent
.opener
.document
.compose
.send_to_cc
.value +
", " +
$addr;
82 parent
.opener
.document
.compose
.send_to_cc
.value
= $addr;
87 function bcc_address($addr) {
89 var pwintype
= typeof parent
.opener
.document
.compose
;
91 $addr = $addr.replace(/ {1,35}$
/, "");
93 if (pwintype
!= "undefined") {
94 if (parent
.opener
.document
.compose
.send_to_bcc
.value
) {
96 parent
.opener
.document
.compose
.send_to_bcc
.value
=
97 parent
.opener
.document
.compose
.send_to_bcc
.value +
", " +
$addr;
99 parent
.opener
.document
.compose
.send_to_bcc
.value
= $addr;
106 } /* End of included JavaScript */
109 /* List search results */
110 function display_result($res, $includesource = true) {
113 if(sizeof($res) <= 0) return;
118 echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) .
119 html_tag( 'tr', '', '', $color[9] ) .
120 html_tag( 'th', ' ', 'left' ) .
121 html_tag( 'th', ' ' . _("Name"), 'left' ) .
122 html_tag( 'th', ' ' . _("E-mail"), 'left' ) .
123 html_tag( 'th', ' ' . _("Info"), 'left' );
125 if ($includesource) {
126 echo html_tag( 'th', ' ' . _("Source"), 'left', 'width="10%"' );
130 while (list($undef, $row) = each($res)) {
132 $email = htmlspecialchars(addcslashes(AddressBook
::full_address($row), "'"), ENT_QUOTES
);
133 if ($line %
2) { $tr_bgcolor = $color[0]; }
134 echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) .
136 '<small><a href="javascript:to_address(' .
137 "'" . $email . "');\">To</A> | " .
138 '<a href="javascript:cc_address(' .
139 "'" . $email . "');\">Cc</A> | " .
140 '<a href="javascript:bcc_address(' .
141 "'" . $email . "');\">Bcc</A></small>",
142 'center', '', 'valign="top" width="5%" nowrap' ) .
143 html_tag( 'td', ' ' . htmlspecialchars($row['name']), 'left', '', 'valign="top" nowrap' ) .
144 html_tag( 'td', ' ' .
145 '<a href="javascript:to_and_close(' .
146 "'" . $email . "');\">" . htmlspecialchars($row['email']) . '</A>'
147 , 'left', '', 'valign="top"' ) .
148 html_tag( 'td', htmlspecialchars($row['label']), 'left', '', 'valign="top" nowrap' );
149 if ($includesource) {
150 echo html_tag( 'td', ' ' . $row['source'], 'left', '', 'valign="top" nowrap' );
159 /* ================= End of functions ================= */
161 require_once('../functions/array.php');
162 require_once('../functions/strings.php');
163 require_once('../functions/addressbook.php');
167 /* Initialize vars */
168 if (!isset($query)) { $query = ''; }
169 if (!isset($show)) { $show = ''; }
170 if (!isset($backend)) { $backend = ''; }
172 /* Choose correct colors for top and bottom frame */
173 if ($show == 'form' && !isset($listall)) {
174 echo '<BODY TEXT="' . $color[6] . '" BGCOLOR="' . $color[3] . '" ' .
175 'LINK="' . $color[6] . '" VLINK="' . $color[6] . '" ' .
176 'ALINK="' . $color[6] . '" ' .
177 'OnLoad="document.sform.query.focus();">';
179 echo '<BODY TEXT="' . $color[8] . '" BGCOLOR="' . $color[4] . '" ' .
180 'LINK="' . $color[7] . '" VLINK="' . $color[7] . '" ' .
181 'ALINK="' . $color[7] . "\">\n";
185 if (empty($query) && empty($show) && empty($listall)) {
186 echo html_tag( 'p', '<br>' .
187 _("No persons matching your search was found"),
189 "\n</BODY></HTML>\n",
193 /* Initialize addressbook */
194 $abook = addressbook_init();
196 /* Create search form */
197 if ($show == 'form' && empty($listall)) {
198 echo '<FORM NAME=sform TARGET=abookres ACTION="addrbook_search.php'.
199 '" METHOD="POST">' . "\n" .
200 html_tag( 'table', '', '', '', 'border="0" width="100%" height="100%"' ) .
202 html_tag( 'td', ' <strong>' . _("Search for") . "</strong>\n", 'left', '', 'nowrap valign="middle" width="10%"' ) .
203 html_tag( 'td', '', 'left', '', '' ) .
204 '<INPUT TYPE=text NAME=query VALUE="' . htmlspecialchars($query) .
207 /* List all backends to allow the user to choose where to search */
208 if ($abook->numbackends
> 1) {
209 echo '<STRONG>' . _("in") . '</STRONG> <SELECT NAME=backend>'."\n".
210 '<OPTION VALUE=-1 SELECTED>' . _("All address books") . "\n";
211 $ret = $abook->get_backend_list();
212 while (list($undef,$v) = each($ret)) {
213 echo '<OPTION VALUE=' . $v->bnum
. '>' . $v->sname
. "\n";
217 echo '<INPUT TYPE=hidden NAME=backend VALUE=-1>' . "\n";
222 html_tag( 'td', '', 'left' ) .
224 '<INPUT TYPE=submit VALUE="' . _("Search") . '" NAME=show>' .
225 ' | <INPUT TYPE=submit VALUE="' . _("List all") .
226 '" NAME=listall>' . "\n" .
227 ' | <INPUT TYPE=button VALUE="' . _("Close") .
228 '" onclick="parent.close();">' . "\n" ,
231 '</table></form>' . "\n";
234 /* Show personal addressbook */
235 if ($show == 'blank' && empty($listall)) {
237 if($backend != -1 ||
$show == 'blank') {
238 if ($show == 'blank') {
239 $backend = $abook->localbackend
;
241 $res = $abook->list_addr($backend);
244 usort($res,'alistcmp');
245 display_result($res, false);
247 echo html_tag( 'p', '<strong>' .
248 sprintf(_("Unable to list addresses from %s"),
249 $abook->backends
[$backend]->sname
) . '</strong>' ,
253 $res = $abook->list_addr();
254 usort($res,'alistcmp');
255 display_result($res, true);
259 if( !empty( $listall ) ){
264 if (!empty($query)) {
267 $res = $abook->s_search($query);
269 $res = $abook->s_search($query, $backend);
272 if (!is_array($res)) {
273 echo html_tag( 'p', '<b><br>' .
274 _("Your search failed with the following error(s)") .
275 ':<br>' . $abook->error
. "</b>\n" ,
277 "\n</BODY></HTML>\n";
281 if (sizeof($res) == 0) {
282 echo html_tag( 'p', '<br><b>' .
283 _("No persons matching your search was found") . "</b>\n" ,
285 "\n</BODY></HTML>\n";
289 display_result($res);
295 echo "</BODY></HTML>\n";