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