* To reduce on errors, I moved the includes for config.php and strings.php
[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/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');
27
28 // Insert hidden data
29 function addr_insert_hidden() {
30 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc;
31
32 echo '<input type=hidden value="';
33 if (substr($body, 0, 1) == "\r")
34 echo "\n";
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=\"true\" name=from_htmladdr_search>\n";
45 }
46
47
48 // List search results
49 function addr_display_result($res, $includesource = true) {
50 global $color, $PHP_SELF;
51
52 if(sizeof($res) <= 0) return;
53
54 echo '<form method=post action="' . $PHP_SELF . "\">\n";
55 echo '<input type=hidden name="html_addr_search_done" value="true">';
56 echo "\n";
57 addr_insert_hidden();
58 $line = 0;
59
60 print "<TABLE BORDER=0 WIDTH=\"98%\" ALIGN=center>";
61 printf("<TR BGCOLOR=\"$color[9]\"><TH ALIGN=left>&nbsp;".
62 "<TH ALIGN=left>&nbsp;%s<TH ALIGN=left>&nbsp;%s".
63 "<TH ALIGN=left>&nbsp;%s",
64 _("Name"), _("E-mail"), _("Info"));
65
66 if($includesource)
67 printf("<TH ALIGN=left WIDTH=\"10%%\">&nbsp;%s", _("Source"));
68
69 print "</TR>\n";
70
71 foreach ($res as $row) {
72 echo '<tr';
73 if ($line % 2) echo ' bgcolor="' . $color[0] . '"';
74 echo ' nowrap><td nowrap align=center width="5%">';
75 echo '<input type=checkbox name="send_to_search[T' . $line . ']" value = "' .
76 htmlspecialchars($row['email']) . '">&nbsp;To&nbsp;';
77 echo '<input type=checkbox name="send_to_search[C' . $line . ']" value = "' .
78 htmlspecialchars($row['email']) . '">&nbsp;Cc&nbsp;';
79 echo '<input type=checkbox name="send_to_search[B' . $line . ']" value = "' .
80 htmlspecialchars($row['email']) . '">&nbsp;Bcc&nbsp;';
81 echo '</td><td nowrap>&nbsp;' . $row['name'] . '&nbsp;</td>';
82 echo '<td nowrap>&nbsp;' . $row['email'] . '&nbsp;</td>';
83 echo '<td nowrap>&nbsp;' . $row['label'] . '&nbsp;</td>';
84 if($includesource)
85 echo '<td nowrap>&nbsp;' . $row['source'] . '&nbsp;</td>';
86 echo "</tr>\n";
87 $line ++;
88 }
89 printf('<TR><TD ALIGN=center COLSPAN=%d><INPUT TYPE=submit '.
90 'NAME="addr_search_done" VALUE="%s"></TD></TR>',
91 4 + ($includesource ? 1 : 0),
92 _("Use Addresses"));
93 print '</TABLE>';
94 print '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">';
95 print '</FORM>';
96 }
97
98 // --- End functions ---
99
100 displayPageHeader($color, 'None');
101
102 // Initialize addressbook
103 $abook = addressbook_init();
104
105 ?>
106
107 <br>
108 <table width=95% align=center cellpadding=2 cellspacing=2 border=0>
109 <tr><td bgcolor="<?php echo $color[0] ?>">
110 <center><b><?php echo _("Address Book Search") ?></b></center>
111 </td></tr></table>
112
113 <?php
114 // Search form
115 print "<CENTER>\n";
116 print "<TABLE BORDER=0>\n";
117 print "<TR><TD NOWRAP VALIGN=middle>\n";
118 printf('<FORM METHOD=post NAME=f ACTION="%s?html_addr_search=true">'."\n", $PHP_SELF);
119 print "<CENTER>\n";
120 printf(" <nobr><STRONG>%s</STRONG>\n", _("Search for"));
121 addr_insert_hidden();
122 if (! isset($addrquery))
123 $addrquery = '';
124 printf(" <INPUT TYPE=text NAME=addrquery VALUE=\"%s\" SIZE=26>\n",
125 htmlspecialchars($addrquery));
126
127 // List all backends to allow the user to choose where to search
128 if(!isset($backend)) $backend = "";
129 if($abook->numbackends > 1) {
130 printf("<STRONG>%s</STRONG>&nbsp;<SELECT NAME=backend>\n",
131 _("in"));
132 printf("<OPTION VALUE=-1 %s>%s\n",
133 ($backend == -1) ? "SELECTED" : "",
134 _("All address books"));
135 $ret = $abook->get_backend_list();
136 while(list($undef,$v) = each($ret))
137 printf("<OPTION VALUE=%d %s>%s\n",
138 $v->bnum,
139 ($backend == $v->bnum) ? "SELECTED" : "",
140 $v->sname);
141 print "</SELECT>\n";
142 } else {
143 print "<INPUT TYPE=hidden NAME=backend VALUE=-1>\n";
144 }
145 printf("<INPUT TYPE=submit VALUE=\"%s\">",
146 _("Search"));
147 printf("&nbsp;|&nbsp;<INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n",
148 _("List all"));
149 print '</FORM></center>';
150
151 print "</TD></TR></TABLE>\n";
152 addr_insert_hidden();
153 print "</CENTER>";
154 do_hook('addrbook_html_search_below');
155 // End search form
156
157 // Show personal addressbook
158 if($addrquery == '' || !empty($listall)) {
159
160 if(! isset($backend) || $backend != -1 || $addrquery == '') {
161 if($addrquery == '')
162 $backend = $abook->localbackend;
163
164 //printf("<H3 ALIGN=center>%s</H3>\n", $abook->backends[$backend]->sname);
165
166 $res = $abook->list_addr($backend);
167
168 if(is_array($res)) {
169 addr_display_result($res, false);
170 } else {
171 printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s").
172 "</STRONG></P>\n", $abook->backends[$backend]->sname);
173 }
174
175 } else {
176 $res = $abook->list_addr();
177 addr_display_result($res, true);
178 }
179 exit;
180
181 } else
182
183 // Do the search
184 if(!empty($addrquery) && empty($listall)) {
185
186 if($backend == -1) {
187 $res = $abook->s_search($addrquery);
188 } else {
189 $res = $abook->s_search($addrquery, $backend);
190 }
191
192 if(!is_array($res)) {
193 printf("<P ALIGN=center><B><BR>%s:<br>%s</B></P>\n</BODY></HTML>\n",
194 _("Your search failed with the following error(s)"),
195 $abook->error);
196 } else if(sizeof($res) == 0) {
197 printf("<P ALIGN=center><BR><B>%s.</B></P>\n</BODY></HTML>\n",
198 _("No persons matching your search was found"));
199 } else {
200 addr_display_result($res);
201 }
202 }
203
204 if ($addrquery == '' || sizeof($res) == 0) {
205 printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF);
206 addr_insert_hidden();
207 printf("<INPUT TYPE=submit VALUE=\"%s\" NAME=return>\n", _("Return"));
208 print '</form>';
209 print '</center></nobr>';
210 }
211
212 ?>
213 </body></html>