4 * addrbook_search_html.php
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 with pure html.
11 * This file is included from compose.php
13 * NOTE: A lot of this code is similar to the code in
14 * addrbook_search.html -- If you change one, change
20 require_once('../src/validate.php');
21 require_once('../functions/date.php');
22 require_once('../functions/smtp.php');
23 require_once('../functions/display_messages.php');
24 require_once('../functions/addressbook.php');
25 require_once('../functions/plugin.php');
27 /* Insert hidden data */
28 function addr_insert_hidden() {
29 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox,
32 echo '<input type=hidden value="';
33 if (substr($body, 0, 1) == "\r")
35 echo htmlspecialchars($body) . '" name=body>' . "\n" .
36 '<input type=hidden value="' . htmlspecialchars($subject) .
37 '" name=subject>' . "\n" .
38 '<input type=hidden value="' . htmlspecialchars($send_to) .
39 '" name=send_to>' . "\n" .
40 '<input type=hidden value="' . htmlspecialchars($send_to_cc) .
41 '" name=send_to_cc>' . "\n" .
42 '<input type=hidden value="' . htmlspecialchars($send_to_bcc) .
43 '" name=send_to_bcc>' . "\n" .
44 '<input type=hidden value="' . htmlspecialchars($identity) .
45 '" name=identity>' . "\n" .
46 '<input type=hidden name=mailbox value="' . htmlspecialchars($mailbox) .
47 "\">\n" . '<input type=hidden value="true" name=from_htmladdr_search>' .
52 /* List search results */
53 function addr_display_result($res, $includesource = true) {
54 global $color, $PHP_SELF;
56 if (sizeof($res) <= 0) return;
58 echo '<form method=post action="' . $PHP_SELF . "\">\n" .
59 '<input type=hidden name="html_addr_search_done" value="true">' . "\n";
63 echo '<TABLE BORDER=0 WIDTH="98%" ALIGN=center>' .
64 '<TR BGCOLOR="' . $color[9] . '"><TH ALIGN=left> ' .
65 '<TH ALIGN=left> ' . _("Name") .
66 '<TH ALIGN=left> ' . _("E-mail") .
67 '<TH ALIGN=left> ' . _("Info");
70 echo '<TH ALIGN=left WIDTH="10%"> ' . _("Source");
75 foreach ($res as $row) {
77 if ($line %
2) { echo ' bgcolor="' . $color[0] . '"'; }
78 echo ' nowrap><td nowrap align=center width="5%">' .
79 '<input type=checkbox name="send_to_search[T' . $line . ']" value = "' .
80 htmlspecialchars($row['email']) . '"> To ' .
81 '<input type=checkbox name="send_to_search[C' . $line . ']" value = "' .
82 htmlspecialchars($row['email']) . '"> Cc ' .
83 '<input type=checkbox name="send_to_search[B' . $line . ']" value = "' .
84 htmlspecialchars($row['email']) . '"> Bcc ' .
85 '</td><td nowrap> ' . $row['name'] . ' </td>' .
86 '<td nowrap> ' . $row['email'] . ' </td>' .
87 '<td nowrap> ' . $row['label'] . ' </td>';
89 echo '<td nowrap> ' . $row['source'] . ' </td>';
94 echo '<TR><TD ALIGN=center COLSPAN=';
95 if ($includesource) { echo '4'; } else { echo '5'; }
96 echo '><INPUT TYPE=submit NAME="addr_search_done" VALUE="' .
97 _("Use Addresses") . '"></TD></TR>' .
99 '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">' .
103 /* --- End functions --- */
106 displayPageHeader($color, $mailbox);
108 /* Initialize addressbook */
109 $abook = addressbook_init();
114 <table width
="95%" align
=center cellpadding
=2 cellspacing
=2 border
=0>
115 <tr
><td bgcolor
="<?php echo $color[0] ?>">
116 <center
><b
><?php
echo _("Address Book Search") ?
></b
></center
>
122 echo "<CENTER>\n<TABLE BORDER=0><TR><TD NOWRAP VALIGN=middle>\n" .
123 '<FORM METHOD=post NAME=f ACTION="' . $PHP_SELF .
124 '?html_addr_search=true">' . "\n<CENTER>\n" .
125 ' <nobr><STRONG>' . _("Search for") . "</STRONG>\n";
126 addr_insert_hidden();
127 if (! isset($addrquery))
129 echo ' <INPUT TYPE=text NAME=addrquery VALUE="' .
130 htmlspecialchars($addrquery) . "\" SIZE=26>\n";
132 /* List all backends to allow the user to choose where to search */
133 if (!isset($backend)) { $backend = ''; }
134 if ($abook->numbackends
> 1) {
135 echo '<STRONG>' . _("in") . '</STRONG> <SELECT NAME=backend>' . "\n" .
137 if ($backend == -1) { echo ' SELECTED'; }
138 echo '>' . _("All address books") . "\n";
139 $ret = $abook->get_backend_list();
140 while (list($undef,$v) = each($ret)) {
141 echo '<OPTION VALUE=' . $v->bnum
;
142 if ($backend == $v->bnum
) { echo ' SELECTED'; }
143 echo '>' . $v->sname
. "\n";
147 echo '<INPUT TYPE=hidden NAME=backend VALUE=-1>' . "\n";
149 echo '<INPUT TYPE=submit VALUE="' . _("Search") . '">' .
150 ' | <INPUT TYPE=submit VALUE="' . _("List all") .
151 '" NAME=listall>' . "\n" .
152 '</FORM></center></TD></TR></TABLE>' . "\n";
153 addr_insert_hidden();
155 do_hook('addrbook_html_search_below');
156 /* End search form */
158 /* Show personal addressbook */
159 if ($addrquery == '' ||
!empty($listall)) {
161 if (! isset($backend) ||
$backend != -1 ||
$addrquery == '') {
162 if ($addrquery == '') {
163 $backend = $abook->localbackend
;
166 /* echo '<H3 ALIGN=center>' . $abook->backends[$backend]->sname) . "</H3>\n"; */
168 $res = $abook->list_addr($backend);
170 if (is_array($res)) {
171 usort($res,'alistcmp');
172 addr_display_result($res, false);
174 echo '<P ALIGN=center><STRONG>' .
175 sprintf(_("Unable to list addresses from %s"),
176 $abook->backends
[$backend]->sname
) .
181 $res = $abook->list_addr();
182 usort($res,'alistcmp');
183 addr_display_result($res, true);
190 if (!empty($addrquery) && empty($listall)) {
192 if ($backend == -1) {
193 $res = $abook->s_search($addrquery);
195 $res = $abook->s_search($addrquery, $backend);
198 if (!is_array($res)) {
199 echo '<P ALIGN=center><B><BR>' .
200 _("Your search failed with the following error(s)") . ':<br>' .
201 $abook->error
. "</B></P>\n</BODY></HTML>\n";
203 if (sizeof($res) == 0) {
204 echo '<P ALIGN=center><BR><B>' .
205 _("No persons matching your search was found") .
206 ".</B></P>\n</BODY></HTML>\n";
208 addr_display_result($res);
214 if ($addrquery == '' ||
sizeof($res) == 0) {
215 /* printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF); */
216 echo '<center><FORM METHOD=post NAME=k ACTION="compose.php">' . "\n";
217 addr_insert_hidden();
218 echo '<INPUT TYPE=submit VALUE="' . _("Return") . '" NAME=return>' . "\n" .
219 '</form></center></nobr>';