778c52e2688de90f8cc8ad4cd569cdc56d77fabf
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');
26 require_once('../functions/strings.php');
28 /* Insert hidden data */
29 function addr_insert_hidden() {
30 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox,
33 echo '<input type=hidden value="';
34 if (substr($body, 0, 1) == "\r")
36 echo htmlspecialchars($body) . '" name=body>' . "\n" .
37 '<input type=hidden value="' . htmlspecialchars($subject) .
38 '" name=subject>' . "\n" .
39 '<input type=hidden value="' . htmlspecialchars($send_to) .
40 '" name=send_to>' . "\n" .
41 '<input type=hidden value="' . htmlspecialchars($send_to_cc) .
42 '" name=send_to_cc>' . "\n" .
43 '<input type=hidden value="' . htmlspecialchars($send_to_bcc) .
44 '" name=send_to_bcc>' . "\n" .
45 '<input type=hidden value="' . htmlspecialchars($identity) .
46 '" name=identity>' . "\n" .
47 '<input type=hidden name=mailbox value="' . htmlspecialchars($mailbox) .
48 "\">\n" . '<input type=hidden value="true" name=from_htmladdr_search>' .
53 /* List search results */
54 function addr_display_result($res, $includesource = true) {
55 global $color, $PHP_SELF;
57 if (sizeof($res) <= 0) return;
59 echo '<form method=post action="' . $PHP_SELF . "\">\n" .
60 '<input type=hidden name="html_addr_search_done" value="true">' . "\n";
64 echo '<TABLE BORDER=0 WIDTH="98%" ALIGN=center>' .
65 '<TR BGCOLOR="' . $color[9] . '"><TH ALIGN=left> ' .
66 '<TH ALIGN=left> ' . _("Name") .
67 '<TH ALIGN=left> ' . _("E-mail") .
68 '<TH ALIGN=left> ' . _("Info");
71 echo '<TH ALIGN=left WIDTH="10%"> ' . _("Source");
76 foreach ($res as $row) {
78 if ($line %
2) { echo ' bgcolor="' . $color[0] . '"'; }
79 echo ' nowrap><td nowrap align=center width="5%">' .
80 '<input type=checkbox name="send_to_search[T' . $line . ']" value = "' .
81 htmlspecialchars($row['email']) . '"> To ' .
82 '<input type=checkbox name="send_to_search[C' . $line . ']" value = "' .
83 htmlspecialchars($row['email']) . '"> Cc ' .
84 '<input type=checkbox name="send_to_search[B' . $line . ']" value = "' .
85 htmlspecialchars($row['email']) . '"> Bcc ' .
86 '</td><td nowrap> ' . $row['name'] . ' </td>' .
87 '<td nowrap> ' . $row['email'] . ' </td>' .
88 '<td nowrap> ' . $row['label'] . ' </td>';
90 echo '<td nowrap> ' . $row['source'] . ' </td>';
95 echo '<TR><TD ALIGN=center COLSPAN=';
96 if ($includesource) { echo '4'; } else { echo '5'; }
97 echo '><INPUT TYPE=submit NAME="addr_search_done" VALUE="' .
98 _("Use Addresses") . '"></TD></TR>' .
100 '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">' .
104 /* --- End functions --- */
107 displayPageHeader($color, $mailbox);
109 /* Initialize addressbook */
110 $abook = addressbook_init();
115 <table width
="95%" align
=center cellpadding
=2 cellspacing
=2 border
=0>
116 <tr
><td bgcolor
="<?php echo $color[0] ?>">
117 <center
><b
><?php
echo _("Address Book Search") ?
></b
></center
>
123 echo "<CENTER>\n<TABLE BORDER=0><TR><TD NOWRAP VALIGN=middle>\n" .
124 '<FORM METHOD=post NAME=f ACTION="' . $PHP_SELF .
125 '?html_addr_search=true">' . "\n<CENTER>\n" .
126 ' <nobr><STRONG>' . _("Search for") . "</STRONG>\n";
127 addr_insert_hidden();
128 if (! isset($addrquery))
130 echo ' <INPUT TYPE=text NAME=addrquery VALUE="' .
131 htmlspecialchars($addrquery) . "\" SIZE=26>\n";
133 /* List all backends to allow the user to choose where to search */
134 if (!isset($backend)) { $backend = ''; }
135 if ($abook->numbackends
> 1) {
136 echo '<STRONG>' . _("in") . '</STRONG> <SELECT NAME=backend>' . "\n" .
138 if ($backend == -1) { echo ' SELECTED'; }
139 echo '>' . _("All address books") . "\n";
140 $ret = $abook->get_backend_list();
141 while (list($undef,$v) = each($ret)) {
142 echo '<OPTION VALUE=' . $v->bnum
;
143 if ($backend == $v->bnum
) { echo ' SELECTED'; }
144 echo '>' . $v->sname
. "\n";
148 echo '<INPUT TYPE=hidden NAME=backend VALUE=-1>' . "\n";
150 echo '<INPUT TYPE=submit VALUE="' . _("Search") . '">' .
151 ' | <INPUT TYPE=submit VALUE="' . _("List all") .
152 '" NAME=listall>' . "\n" .
153 '</FORM></center></TD></TR></TABLE>' . "\n";
154 addr_insert_hidden();
156 do_hook('addrbook_html_search_below');
157 /* End search form */
159 /* Show personal addressbook */
160 if ($addrquery == '' ||
!empty($listall)) {
162 if (! isset($backend) ||
$backend != -1 ||
$addrquery == '') {
163 if ($addrquery == '') {
164 $backend = $abook->localbackend
;
167 /* echo '<H3 ALIGN=center>' . $abook->backends[$backend]->sname) . "</H3>\n"; */
169 $res = $abook->list_addr($backend);
171 if (is_array($res)) {
172 usort($res,'alistcmp');
173 addr_display_result($res, false);
175 echo '<P ALIGN=center><STRONG>' .
176 sprintf(_("Unable to list addresses from %s"),
177 $abook->backends
[$backend]->sname
) .
182 $res = $abook->list_addr();
183 usort($res,'alistcmp');
184 addr_display_result($res, true);
188 if ( !empty( $listall ) ){
194 if (!empty($addrquery)) {
196 if ($backend == -1) {
197 $res = $abook->s_search($addrquery);
199 $res = $abook->s_search($addrquery, $backend);
202 if (!is_array($res)) {
203 echo '<P ALIGN=center><B><BR>' .
204 _("Your search failed with the following error(s)") . ':<br>' .
205 $abook->error
. "</B></P>\n</BODY></HTML>\n";
207 if (sizeof($res) == 0) {
208 echo '<P ALIGN=center><BR><B>' .
209 _("No persons matching your search was found") .
210 ".</B></P>\n</BODY></HTML>\n";
212 addr_display_result($res);
218 if ($addrquery == '' ||
sizeof($res) == 0) {
219 /* printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF); */
220 echo '<center><FORM METHOD=post NAME=k ACTION="compose.php">' . "\n";
221 addr_insert_hidden();
222 echo '<INPUT TYPE=submit VALUE="' . _("Return") . '" NAME=return>' . "\n" .
223 '</form></center></nobr>';