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 /*****************************************************************/
19 /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
20 /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
21 /*** + Base level indent should begin at left margin, as ***/
22 /*** the require_once below looks. ***/
23 /*** + All identation should consist of four space blocks ***/
24 /*** + Tab characters are evil. ***/
25 /*** + all comments should use "slash-star ... star-slash" ***/
26 /*** style -- no pound characters, no slash-slash style ***/
27 /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
28 /*** ALWAYS USE { AND } CHARACTERS!!! ***/
29 /*** + Please use ' instead of ", when possible. Note " ***/
30 /*** should always be used in _( ) function calls. ***/
31 /*** Thank you for your help making the SM code more readable. ***/
32 /*****************************************************************/
34 require_once('../src/validate.php');
36 /* Function to include JavaScript code */
37 function insert_javascript() {
39 <SCRIPT LANGUAGE
="Javascript"><!--
41 function to_and_close($addr) {
46 function to_address($addr) {
48 var pwintype
= typeof parent
.opener
.document
.compose
;
50 $addr = $addr.replace(/ {1,35}$
/, "");
52 if (pwintype
!= "undefined") {
53 if (parent
.opener
.document
.compose
.send_to
.value
) {
55 parent
.opener
.document
.compose
.send_to
.value
=
56 parent
.opener
.document
.compose
.send_to
.value +
", " +
$addr;
58 parent
.opener
.document
.compose
.send_to
.value
= $addr;
63 function cc_address($addr) {
65 var pwintype
= typeof parent
.opener
.document
.compose
;
67 $addr = $addr.replace(/ {1,35}$
/, "");
69 if (pwintype
!= "undefined") {
70 if (parent
.opener
.document
.compose
.send_to_cc
.value
) {
72 parent
.opener
.document
.compose
.send_to_cc
.value
=
73 parent
.opener
.document
.compose
.send_to_cc
.value +
", " +
$addr;
75 parent
.opener
.document
.compose
.send_to_cc
.value
= $addr;
80 function bcc_address($addr) {
82 var pwintype
= typeof parent
.opener
.document
.compose
;
84 $addr = $addr.replace(/ {1,35}$
/, "");
86 if (pwintype
!= "undefined") {
87 if (parent
.opener
.document
.compose
.send_to_bcc
.value
) {
89 parent
.opener
.document
.compose
.send_to_bcc
.value
=
90 parent
.opener
.document
.compose
.send_to_bcc
.value +
", " +
$addr;
92 parent
.opener
.document
.compose
.send_to_bcc
.value
= $addr;
99 } /* End of included JavaScript */
102 /* List search results */
103 function display_result($res, $includesource = true) {
106 if(sizeof($res) <= 0) return;
111 echo '<TABLE BORDER="0" WIDTH="98%" ALIGN=center>' .
112 '<TR BGCOLOR="' . $color[9] . '"><TH ALIGN=left> ' .
113 '<TH ALIGN=left> ' . _("Name") .
114 '<TH ALIGN=left> ' . _("E-mail") .
115 '<TH ALIGN=left> ' . _("Info");
117 if ($includesource) {
118 echo '<TH ALIGN=left WIDTH="10%"> ' . _("Source");
122 while (list($undef, $row) = each($res)) {
123 echo '<tr' . (($line %
2) ?
" bgcolor=\"$color[0]\"" : '') .
124 ' nowrap><td valign=top nowrap align=center width="5%">' .
125 '<small><a href="javascript:to_address(' .
126 "'" . $row['email'] . "');\">To</A> | " .
127 '<a href="javascript:cc_address(' .
128 "'" . $row["email'] . "');\">Cc</A> | " .
129 '<a href
="javascript:bcc_address(' .
130 "'" . $row["email'] . "');\">Bcc</A></small>" .
131 '<td nowrap valign=top> ' .
132 $row['name'] . ' <td nowrap valign=top>' .
133 ' <a href="javascript:to_and_close(' .
134 "'" . $row["email'] . "');\">" . $row["email'] . '</A> ' .
135 '<td valign=top> ' . $row['label'] . ' ';
136 if ($includesource) {
137 echo '<td nowrap valign=top> ' . $row['source'];
146 /* ================= End of functions ================= */
148 require_once('../functions/array.php');
149 require_once('../functions/strings.php');
150 require_once('../functions/addressbook.php');
154 /* Initialize vars */
155 if (!isset($query)) { $query = ''; }
156 if (!isset($show)) { $show = ''; }
158 /* Choose correct colors for top and bottom frame */
159 if ($show == 'form') {
160 echo '<BODY TEXT="' . $color[6] . '" BGCOLOR="' . $color[3] . '" ' .
161 'LINK="' . $color[6] . '" VLINK="' . $color[6] . '" ' .
162 'ALINK="' . $color[6] . '" ' .
163 'OnLoad="document.sform.query.focus();">';
165 echo '<BODY TEXT="' . $color[8] . '" BGCOLOR="' . $color[4] . '" ' .
166 'LINK="' . $color[7] . '" VLINK="' . $color[7] . '" ' .
167 'ALINK="' . $color[7] . "\">\n";
171 if (empty($query) && empty($show) && empty($listall)) {
172 echo '<P ALIGN=center><BR>' .
173 _("No persons matching your search was found") .
174 "</P>\n</BODY></HTML>\n",
178 /* Initialize addressbook */
179 $abook = addressbook_init();
181 /* Create search form */
182 if ($show == 'form') {
183 echo '<FORM NAME=sform TARGET=abookres ACTION="' . $PHP_SELF .
184 '" METHOD="POST">' . "\n" .
185 '<TABLE BORDER="0" WIDTH="100%" HEIGHT="100%">' .
186 '<TR><TD NOWRAP VALIGN=middle>' . "\n" .
187 ' <STRONG>' . _("Search for") . "</STRONG>\n" .
188 ' <INPUT TYPE=text NAME=query VALUE="' . htmlspecialchars($query) .
191 /* List all backends to allow the user to choose where to search */
192 if ($abook->numbackends
> 1) {
193 echo '<STRONG>' . _("in") . '</STRONG> <SELECT NAME=backend>'."\n".
194 '<OPTION VALUE=-1 SELECTED>' . _("All address books") . "\n";
195 $ret = $abook->get_backend_list();
196 while (list($undef,$v) = each($ret)) {
197 echo '<OPTION VALUE=' . $v->bnum
. '>' . $v->sname
. "\n";
201 echo '<INPUT TYPE=hidden NAME=backend VALUE=-1>' . "\n";
204 echo '<INPUT TYPE=submit VALUE="' . _("Search") . '">' .
205 ' | <INPUT TYPE=submit VALUE="' . _("List all") .
206 '" NAME=listall>' . "\n" .
207 '</TD><TD ALIGN=right>' . "\n" .
208 '<INPUT TYPE=button VALUE=" . _("Close window") .
209 '" onclick="parent
.close();">' . "\n
" .
210 '</TD></TR></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 display_result($res, false);
225 echo '<P ALIGN=center><STRONG>' .
226 sprintf(_("Unable to
list addresses from %s
"),
227 $abook->backends[$backend]->sname) .
228 '</STRONG></P>' . "\n
";
231 $res = $abook->list_addr();
232 display_result($res, true);
238 if (!empty($query) && empty($listall)) {
241 $res = $abook->s_search($query);
243 $res = $abook->s_search($query, $backend);
246 if (!is_array($res)) {
247 echo '<P ALIGN=center><B><BR>' .
248 _("Your search failed with the following
error(s
)") .
249 ':<br>' . $abook->error . "</B
></P
>\n</BODY
></HTML
>\n";
253 if (sizeof($res) == 0) {
254 echo '<P ALIGN=center><BR><B>' .
255 _("No persons matching your search was found
") .
256 ".</B
></P
>\n</BODY
></HTML
>\n";
260 display_result($res);
266 echo "</BODY
></HTML
>\n";