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 include('../src/validate.php');
20 include('../functions/page_header.php');
21 include('../functions/date.php');
22 include('../functions/smtp.php');
23 include('../functions/display_messages.php');
24 include('../functions/addressbook.php');
25 include('../functions/plugin.php');
26 include('../src/load_prefs.php');
29 function addr_insert_hidden() {
30 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 echo '<input type=hidden value="' . htmlspecialchars($subject)
37 . '" name=subject>' . "\n";
38 echo '<input type=hidden value="' . htmlspecialchars($send_to)
39 . '" name=send_to>' . "\n";
40 echo "<input type=hidden value=\"" . htmlspecialchars($send_to_cc)
41 . '" name=send_to_cc>' . "\n";
42 echo "<input type=hidden value=\"" . htmlspecialchars($send_to_bcc)
43 . '" name=send_to_bcc>' . "\n";
44 echo "<input type=hidden value=\"" . htmlspecialchars($identity)
45 . '" name=identity>' . "\n";
46 echo "<input type=hidden name=mailbox value=\"" .
47 htmlspecialchars($mailbox) . "\">\n";
48 echo "<input type=hidden value=\"true\" name=from_htmladdr_search>\n";
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 echo '<input type=hidden name="html_addr_search_done" value="true">';
64 print "<TABLE BORDER=0 WIDTH=\"98%\" ALIGN=center>";
65 printf("<TR BGCOLOR=\"$color[9]\"><TH ALIGN=left> ".
66 "<TH ALIGN=left> %s<TH ALIGN=left> %s".
67 "<TH ALIGN=left> %s",
68 _("Name"), _("E-mail"), _("Info"));
71 printf("<TH ALIGN=left WIDTH=\"10%%\"> %s", _("Source"));
75 foreach ($res as $row) {
77 if ($line %
2) echo ' bgcolor="' . $color[0] . '"';
78 echo ' nowrap><td nowrap align=center width="5%">';
79 echo '<input type=checkbox name="send_to_search[T' . $line . ']" value = "' .
80 htmlspecialchars($row['email']) . '"> To ';
81 echo '<input type=checkbox name="send_to_search[C' . $line . ']" value = "' .
82 htmlspecialchars($row['email']) . '"> Cc ';
83 echo '<input type=checkbox name="send_to_search[B' . $line . ']" value = "' .
84 htmlspecialchars($row['email']) . '"> Bcc ';
85 echo '</td><td nowrap> ' . $row['name'] . ' </td>';
86 echo '<td nowrap> ' . $row['email'] . ' </td>';
87 echo '<td nowrap> ' . $row['label'] . ' </td>';
89 echo '<td nowrap> ' . $row['source'] . ' </td>';
93 printf('<TR><TD ALIGN=center COLSPAN=%d><INPUT TYPE=submit '.
94 'NAME="addr_search_done" VALUE="%s"></TD></TR>',
95 4 +
($includesource ?
1 : 0),
98 print '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">';
102 // --- End functions ---
105 displayPageHeader($color, $mailbox);
107 // Initialize addressbook
108 $abook = addressbook_init();
113 <table width
=95% align
=center cellpadding
=2 cellspacing
=2 border
=0>
114 <tr
><td bgcolor
="<?php echo $color[0] ?>">
115 <center
><b
><?php
echo _("Address Book Search") ?
></b
></center
>
121 print "<TABLE BORDER=0>\n";
122 print "<TR><TD NOWRAP VALIGN=middle>\n";
123 printf('<FORM METHOD=post NAME=f ACTION="%s?html_addr_search=true">'."\n", $PHP_SELF);
125 printf(" <nobr><STRONG>%s</STRONG>\n", _("Search for"));
126 addr_insert_hidden();
127 if (! isset($addrquery))
129 printf(" <INPUT TYPE=text NAME=addrquery VALUE=\"%s\" SIZE=26>\n",
130 htmlspecialchars($addrquery));
132 // List all backends to allow the user to choose where to search
133 if(!isset($backend)) $backend = "";
134 if($abook->numbackends
> 1) {
135 printf("<STRONG>%s</STRONG> <SELECT NAME=backend>\n",
137 printf("<OPTION VALUE=-1 %s>%s\n",
138 ($backend == -1) ?
"SELECTED" : "",
139 _("All address books"));
140 $ret = $abook->get_backend_list();
141 while(list($undef,$v) = each($ret))
142 printf("<OPTION VALUE=%d %s>%s\n",
144 ($backend == $v->bnum
) ?
"SELECTED" : "",
148 print "<INPUT TYPE=hidden NAME=backend VALUE=-1>\n";
150 printf("<INPUT TYPE=submit VALUE=\"%s\">",
152 printf(" | <INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n",
154 print '</FORM></center>';
156 print "</TD></TR></TABLE>\n";
157 addr_insert_hidden();
159 do_hook('addrbook_html_search_below');
162 // Show personal addressbook
163 if($addrquery == '' ||
!empty($listall)) {
165 if(! isset($backend) ||
$backend != -1 ||
$addrquery == '') {
167 $backend = $abook->localbackend
;
169 //printf("<H3 ALIGN=center>%s</H3>\n", $abook->backends[$backend]->sname);
171 $res = $abook->list_addr($backend);
174 addr_display_result($res, false);
176 printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s").
177 "</STRONG></P>\n", $abook->backends
[$backend]->sname
);
181 $res = $abook->list_addr();
182 addr_display_result($res, true);
189 if(!empty($addrquery) && empty($listall)) {
192 $res = $abook->s_search($addrquery);
194 $res = $abook->s_search($addrquery, $backend);
197 if(!is_array($res)) {
198 printf("<P ALIGN=center><B><BR>%s:<br>%s</B></P>\n</BODY></HTML>\n",
199 _("Your search failed with the following error(s)"),
201 } else if(sizeof($res) == 0) {
202 printf("<P ALIGN=center><BR><B>%s.</B></P>\n</BODY></HTML>\n",
203 _("No persons matching your search was found"));
205 addr_display_result($res);
209 if ($addrquery == '' ||
sizeof($res) == 0) {
210 printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF);
211 addr_insert_hidden();
212 printf("<INPUT TYPE=submit VALUE=\"%s\" NAME=return>\n", _("Return"));
214 print '</center></nobr>';