5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
8 ** Handle addressbook searching with pure html.
10 ** This file is included from compose.php
12 ** NOTE: A lot of this code is similar to the code in
13 ** addrbook_search.html -- If you change one, change
19 require_once('../src/validate.php');
20 require_once('../functions/date.php');
21 require_once('../functions/smtp.php');
22 require_once('../functions/display_messages.php');
23 require_once('../functions/addressbook.php');
24 require_once('../functions/plugin.php');
27 function addr_insert_hidden() {
28 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox,
31 echo '<input type=hidden value="';
32 if (substr($body, 0, 1) == "\r")
34 echo htmlspecialchars($body) . '" name=body>' . "\n";
35 echo '<input type=hidden value="' . htmlspecialchars($subject)
36 . '" name=subject>' . "\n";
37 echo '<input type=hidden value="' . htmlspecialchars($send_to)
38 . '" name=send_to>' . "\n";
39 echo "<input type=hidden value=\"" . htmlspecialchars($send_to_cc)
40 . '" name=send_to_cc>' . "\n";
41 echo "<input type=hidden value=\"" . htmlspecialchars($send_to_bcc)
42 . '" name=send_to_bcc>' . "\n";
43 echo "<input type=hidden value=\"" . htmlspecialchars($identity)
44 . '" name=identity>' . "\n";
45 echo "<input type=hidden name=mailbox value=\"" .
46 htmlspecialchars($mailbox) . "\">\n";
47 echo "<input type=hidden value=\"true\" name=from_htmladdr_search>\n";
51 // List search results
52 function addr_display_result($res, $includesource = true) {
53 global $color, $PHP_SELF;
55 if(sizeof($res) <= 0) return;
57 echo '<form method=post action="' . $PHP_SELF . "\">\n";
58 echo '<input type=hidden name="html_addr_search_done" value="true">';
63 print "<TABLE BORDER=0 WIDTH=\"98%\" ALIGN=center>";
64 printf("<TR BGCOLOR=\"$color[9]\"><TH ALIGN=left> ".
65 "<TH ALIGN=left> %s<TH ALIGN=left> %s".
66 "<TH ALIGN=left> %s",
67 _("Name"), _("E-mail"), _("Info"));
70 printf("<TH ALIGN=left WIDTH=\"10%%\"> %s", _("Source"));
74 foreach ($res as $row) {
76 if ($line %
2) echo ' bgcolor="' . $color[0] . '"';
77 echo ' nowrap><td nowrap align=center width="5%">';
78 echo '<input type=checkbox name="send_to_search[T' . $line . ']" value = "' .
79 htmlspecialchars($row['email']) . '"> To ';
80 echo '<input type=checkbox name="send_to_search[C' . $line . ']" value = "' .
81 htmlspecialchars($row['email']) . '"> Cc ';
82 echo '<input type=checkbox name="send_to_search[B' . $line . ']" value = "' .
83 htmlspecialchars($row['email']) . '"> Bcc ';
84 echo '</td><td nowrap> ' . $row['name'] . ' </td>';
85 echo '<td nowrap> ' . $row['email'] . ' </td>';
86 echo '<td nowrap> ' . $row['label'] . ' </td>';
88 echo '<td nowrap> ' . $row['source'] . ' </td>';
92 printf('<TR><TD ALIGN=center COLSPAN=%d><INPUT TYPE=submit '.
93 'NAME="addr_search_done" VALUE="%s"></TD></TR>',
94 4 +
($includesource ?
1 : 0),
97 print '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">';
101 // --- End functions ---
104 displayPageHeader($color, $mailbox);
106 // Initialize addressbook
107 $abook = addressbook_init();
112 <table width
=95% align
=center cellpadding
=2 cellspacing
=2 border
=0>
113 <tr
><td bgcolor
="<?php echo $color[0] ?>">
114 <center
><b
><?php
echo _("Address Book Search") ?
></b
></center
>
120 print "<TABLE BORDER=0>\n";
121 print "<TR><TD NOWRAP VALIGN=middle>\n";
122 printf('<FORM METHOD=post NAME=f ACTION="%s?html_addr_search=true">'."\n", $PHP_SELF);
124 printf(" <nobr><STRONG>%s</STRONG>\n", _("Search for"));
125 addr_insert_hidden();
126 if (! isset($addrquery))
128 printf(" <INPUT TYPE=text NAME=addrquery VALUE=\"%s\" SIZE=26>\n",
129 htmlspecialchars($addrquery));
131 // List all backends to allow the user to choose where to search
132 if(!isset($backend)) $backend = "";
133 if($abook->numbackends
> 1) {
134 printf("<STRONG>%s</STRONG> <SELECT NAME=backend>\n",
136 printf("<OPTION VALUE=-1 %s>%s\n",
137 ($backend == -1) ?
"SELECTED" : "",
138 _("All address books"));
139 $ret = $abook->get_backend_list();
140 while(list($undef,$v) = each($ret))
141 printf("<OPTION VALUE=%d %s>%s\n",
143 ($backend == $v->bnum
) ?
"SELECTED" : "",
147 print "<INPUT TYPE=hidden NAME=backend VALUE=-1>\n";
149 printf("<INPUT TYPE=submit VALUE=\"%s\">",
151 printf(" | <INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n",
153 print '</FORM></center>';
155 print "</TD></TR></TABLE>\n";
156 addr_insert_hidden();
158 do_hook('addrbook_html_search_below');
161 // Show personal addressbook
162 if($addrquery == '' ||
!empty($listall)) {
164 if(! isset($backend) ||
$backend != -1 ||
$addrquery == '') {
166 $backend = $abook->localbackend
;
168 //printf("<H3 ALIGN=center>%s</H3>\n", $abook->backends[$backend]->sname);
170 $res = $abook->list_addr($backend);
173 addr_display_result($res, false);
175 printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s").
176 "</STRONG></P>\n", $abook->backends
[$backend]->sname
);
180 $res = $abook->list_addr();
181 addr_display_result($res, true);
188 if(!empty($addrquery) && empty($listall)) {
191 $res = $abook->s_search($addrquery);
193 $res = $abook->s_search($addrquery, $backend);
196 if(!is_array($res)) {
197 printf("<P ALIGN=center><B><BR>%s:<br>%s</B></P>\n</BODY></HTML>\n",
198 _("Your search failed with the following error(s)"),
200 } else if(sizeof($res) == 0) {
201 printf("<P ALIGN=center><BR><B>%s.</B></P>\n</BODY></HTML>\n",
202 _("No persons matching your search was found"));
204 addr_display_result($res);
208 if ($addrquery == '' ||
sizeof($res) == 0) {
209 printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF);
210 addr_insert_hidden();
211 printf("<INPUT TYPE=submit VALUE=\"%s\" NAME=return>\n", _("Return"));
213 print '</center></nobr>';