* Finally fixed that weird To/Cc/Bcc bug (it might be with PHP or browsers
[squirrelmail.git] / src / addrbook_search_html.php
1 <?php
2 /**
3 ** addrbook_search.php
4 **
5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 **
8 ** Handle addressbook searching with pure html.
9 **
10 ** This file is included from compose.php
11 **
12 ** NOTE: A lot of this code is similar to the code in
13 ** addrbook_search.html -- If you change one, change
14 ** the other one too!
15 **
16 ** $Id$
17 **/
18
19 include('../src/validate.php');
20 include('../functions/strings.php');
21 include('../config/config.php');
22 include('../functions/page_header.php');
23 include('../functions/date.php');
24 include('../functions/smtp.php');
25 include('../functions/display_messages.php');
26 include('../functions/addressbook.php');
27 include('../functions/plugin.php');
28 include('../src/load_prefs.php');
29
30 // Insert hidden data
31 function addr_insert_hidden() {
32 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc;
33
34 echo '<input type=hidden value="';
35 if (substr($body, 0, 1) == "\r")
36 echo "\n";
37 echo htmlspecialchars($body) . '" name=body>' . "\n";
38 echo '<input type=hidden value="' . htmlspecialchars($subject)
39 . '" name=subject>' . "\n";
40 echo '<input type=hidden value="' . htmlspecialchars($send_to)
41 . '" name=send_to>' . "\n";
42 echo "<input type=hidden value=\"" . htmlspecialchars($send_to_cc)
43 . '" name=send_to_cc>' . "\n";
44 echo "<input type=hidden value=\"" . htmlspecialchars($send_to_bcc)
45 . '" name=send_to_bcc>' . "\n";
46 echo "<input type=hidden value=\"true\" name=from_htmladdr_search>\n";
47 }
48
49
50 // List search results
51 function addr_display_result($res, $includesource = true) {
52 global $color, $PHP_SELF;
53
54 if(sizeof($res) <= 0) return;
55
56 echo '<form method=post action="' . $PHP_SELF . "\">\n";
57 echo '<input type=hidden name="html_addr_search_done" value="true">';
58 echo "\n";
59 addr_insert_hidden();
60 $line = 0;
61
62 print "<TABLE BORDER=0 WIDTH=\"98%\" ALIGN=center>";
63 printf("<TR BGCOLOR=\"$color[9]\"><TH ALIGN=left>&nbsp;".
64 "<TH ALIGN=left>&nbsp;%s<TH ALIGN=left>&nbsp;%s".
65 "<TH ALIGN=left>&nbsp;%s",
66 _("Name"), _("E-mail"), _("Info"));
67
68 if($includesource)
69 printf("<TH ALIGN=left WIDTH=\"10%%\">&nbsp;%s", _("Source"));
70
71 print "</TR>\n";
72
73 foreach ($res as $row) {
74 echo '<tr';
75 if ($line % 2) echo ' bgcolor="' . $color[0] . '"';
76 echo ' nowrap><td nowrap align=center width="5%">';
77 echo '<input type=checkbox name="send_to_search[T' . $line . ']" value = "' .
78 htmlspecialchars($row['email']) . '">&nbsp;To&nbsp;';
79 echo '<input type=checkbox name="send_to_search[C' . $line . ']" value = "' .
80 htmlspecialchars($row['email']) . '">&nbsp;Cc&nbsp;';
81 echo '<input type=checkbox name="send_to_search[B' . $line . ']" value = "' .
82 htmlspecialchars($row['email']) . '">&nbsp;Bcc&nbsp;';
83 echo '</td><td nowrap>&nbsp;' . $row['name'] . '&nbsp;</td>';
84 echo '<td nowrap>&nbsp;' . $row['email'] . '&nbsp;</td>';
85 echo '<td nowrap>&nbsp;' . $row['label'] . '&nbsp;</td>';
86 if($includesource)
87 echo '<td nowrap>&nbsp;' . $row['source'] . '&nbsp;</td>';
88 echo "</tr>\n";
89 $line ++;
90 }
91 printf('<TR><TD ALIGN=center COLSPAN=%d><INPUT TYPE=submit '.
92 'NAME="addr_search_done" VALUE="%s"></TD></TR>',
93 4 + ($includesource ? 1 : 0),
94 _("Use Addresses"));
95 print '</TABLE>';
96 print '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">';
97 print '</FORM>';
98 }
99
100 // --- End functions ---
101
102 displayPageHeader($color, 'None');
103
104 // Initialize addressbook
105 $abook = addressbook_init();
106
107 ?>
108
109 <br>
110 <table width=95% align=center cellpadding=2 cellspacing=2 border=0>
111 <tr><td bgcolor="<?php echo $color[0] ?>">
112 <center><b><?php echo _("Address Book Search") ?></b></center>
113 </td></tr></table>
114
115 <?php
116 // Search form
117 print "<CENTER>\n";
118 print "<TABLE BORDER=0>\n";
119 print "<TR><TD NOWRAP VALIGN=middle>\n";
120 printf('<FORM METHOD=post NAME=f ACTION="%s?html_addr_search=true">'."\n", $PHP_SELF);
121 print "<CENTER>\n";
122 printf(" <nobr><STRONG>%s</STRONG>\n", _("Search for"));
123 addr_insert_hidden();
124 if (! isset($addrquery))
125 $addrquery = '';
126 printf(" <INPUT TYPE=text NAME=addrquery VALUE=\"%s\" SIZE=26>\n",
127 htmlspecialchars($addrquery));
128
129 // List all backends to allow the user to choose where to search
130 if(!isset($backend)) $backend = "";
131 if($abook->numbackends > 1) {
132 printf("<STRONG>%s</STRONG>&nbsp;<SELECT NAME=backend>\n",
133 _("in"));
134 printf("<OPTION VALUE=-1 %s>%s\n",
135 ($backend == -1) ? "SELECTED" : "",
136 _("All address books"));
137 $ret = $abook->get_backend_list();
138 while(list($undef,$v) = each($ret))
139 printf("<OPTION VALUE=%d %s>%s\n",
140 $v->bnum,
141 ($backend == $v->bnum) ? "SELECTED" : "",
142 $v->sname);
143 print "</SELECT>\n";
144 } else {
145 print "<INPUT TYPE=hidden NAME=backend VALUE=-1>\n";
146 }
147 printf("<INPUT TYPE=submit VALUE=\"%s\">",
148 _("Search"));
149 printf("&nbsp;|&nbsp;<INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n",
150 _("List all"));
151 print '</FORM></center>';
152
153 print "</TD></TR></TABLE>\n";
154 addr_insert_hidden();
155 print "</CENTER>";
156 do_hook('addrbook_html_search_below');
157 // End search form
158
159 // Show personal addressbook
160 if($addrquery == '' || !empty($listall)) {
161
162 if(! isset($backend) || $backend != -1 || $addrquery == '') {
163 if($addrquery == '')
164 $backend = $abook->localbackend;
165
166 //printf("<H3 ALIGN=center>%s</H3>\n", $abook->backends[$backend]->sname);
167
168 $res = $abook->list_addr($backend);
169
170 if(is_array($res)) {
171 addr_display_result($res, false);
172 } else {
173 printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s").
174 "</STRONG></P>\n", $abook->backends[$backend]->sname);
175 }
176
177 } else {
178 $res = $abook->list_addr();
179 addr_display_result($res, true);
180 }
181 exit;
182
183 } else
184
185 // Do the search
186 if(!empty($addrquery) && empty($listall)) {
187
188 if($backend == -1) {
189 $res = $abook->s_search($addrquery);
190 } else {
191 $res = $abook->s_search($addrquery, $backend);
192 }
193
194 if(!is_array($res)) {
195 printf("<P ALIGN=center><B><BR>%s:<br>%s</B></P>\n</BODY></HTML>\n",
196 _("Your search failed with the following error(s)"),
197 $abook->error);
198 } else if(sizeof($res) == 0) {
199 printf("<P ALIGN=center><BR><B>%s.</B></P>\n</BODY></HTML>\n",
200 _("No persons matching your search was found"));
201 } else {
202 addr_display_result($res);
203 }
204 }
205
206 if ($addrquery == '' || sizeof($res) == 0) {
207 printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF);
208 addr_insert_hidden();
209 printf("<INPUT TYPE=submit VALUE=\"%s\" NAME=return>\n", _("Return"));
210 print '</form>';
211 print '</center></nobr>';
212 }
213
214 ?>
215 </body></html>