Fixed typo.
[squirrelmail.git] / src / addrbook_search_html.php
CommitLineData
c1e15177 1<?php
895905c0 2
35586184 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 */
c1e15177 19
35586184 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
36require_once('../src/validate.php');
37require_once('../functions/date.php');
38require_once('../functions/smtp.php');
39require_once('../functions/display_messages.php');
40require_once('../functions/addressbook.php');
41require_once('../functions/plugin.php');
c1e15177 42
14f1b90b 43 // Insert hidden data
44 function addr_insert_hidden() {
5a6f29a6 45 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox,
46 $identity;
4c8ac648 47
c9e9b23c 48 echo '<input type=hidden value="';
441f2d33 49 if (substr($body, 0, 1) == "\r")
50 echo "\n";
b897ac2e 51 echo htmlspecialchars($body) . '" name=body>' . "\n";
c9e9b23c 52 echo '<input type=hidden value="' . htmlspecialchars($subject)
b897ac2e 53 . '" name=subject>' . "\n";
c9e9b23c 54 echo '<input type=hidden value="' . htmlspecialchars($send_to)
b897ac2e 55 . '" name=send_to>' . "\n";
441f2d33 56 echo "<input type=hidden value=\"" . htmlspecialchars($send_to_cc)
b897ac2e 57 . '" name=send_to_cc>' . "\n";
441f2d33 58 echo "<input type=hidden value=\"" . htmlspecialchars($send_to_bcc)
b897ac2e 59 . '" name=send_to_bcc>' . "\n";
aaf9abef 60 echo "<input type=hidden value=\"" . htmlspecialchars($identity)
61 . '" name=identity>' . "\n";
eeb44e40 62 echo "<input type=hidden name=mailbox value=\"" .
63 htmlspecialchars($mailbox) . "\">\n";
441f2d33 64 echo "<input type=hidden value=\"true\" name=from_htmladdr_search>\n";
14f1b90b 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
b8796881 74 echo '<form method=post action="' . $PHP_SELF . "\">\n";
75 echo '<input type=hidden name="html_addr_search_done" value="true">';
76 echo "\n";
14f1b90b 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;".
6e79bfe2 82 "<TH ALIGN=left>&nbsp;%s<TH ALIGN=left>&nbsp;%s".
83 "<TH ALIGN=left>&nbsp;%s",
84 _("Name"), _("E-mail"), _("Info"));
14f1b90b 85
86 if($includesource)
6e79bfe2 87 printf("<TH ALIGN=left WIDTH=\"10%%\">&nbsp;%s", _("Source"));
14f1b90b 88
89 print "</TR>\n";
4c8ac648 90
b8796881 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>';
6e79bfe2 104 if($includesource)
b8796881 105 echo '<td nowrap>&nbsp;' . $row['source'] . '&nbsp;</td>';
106 echo "</tr>\n";
107 $line ++;
14f1b90b 108 }
109 printf('<TR><TD ALIGN=center COLSPAN=%d><INPUT TYPE=submit '.
6e79bfe2 110 'NAME="addr_search_done" VALUE="%s"></TD></TR>',
4c8ac648 111 4 + ($includesource ? 1 : 0),
6e79bfe2 112 _("Use Addresses"));
c9e9b23c 113 print '</TABLE>';
14f1b90b 114 print '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">';
c9e9b23c 115 print '</FORM>';
14f1b90b 116 }
117
118 // --- End functions ---
119
eeb44e40 120 global $mailbox;
121 displayPageHeader($color, $mailbox);
4c8ac648 122
14f1b90b 123 // Initialize addressbook
124 $abook = addressbook_init();
c1e15177 125
6e79bfe2 126?>
14f1b90b 127
6e79bfe2 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>
14f1b90b 133
6e79bfe2 134<?php
14f1b90b 135 // Search form
136 print "<CENTER>\n";
14f1b90b 137 print "<TABLE BORDER=0>\n";
c9e9b23c 138 print "<TR><TD NOWRAP VALIGN=middle>\n";
6e79bfe2 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();
245a6892 143 if (! isset($addrquery))
507832e7 144 $addrquery = '';
14f1b90b 145 printf(" <INPUT TYPE=text NAME=addrquery VALUE=\"%s\" SIZE=26>\n",
6e79bfe2 146 htmlspecialchars($addrquery));
14f1b90b 147
148 // List all backends to allow the user to choose where to search
12b4ef8b 149 if(!isset($backend)) $backend = "";
14f1b90b 150 if($abook->numbackends > 1) {
4c8ac648 151 printf("<STRONG>%s</STRONG>&nbsp;<SELECT NAME=backend>\n",
6e79bfe2 152 _("in"));
4c8ac648 153 printf("<OPTION VALUE=-1 %s>%s\n",
6e79bfe2 154 ($backend == -1) ? "SELECTED" : "",
155 _("All address books"));
14f1b90b 156 $ret = $abook->get_backend_list();
4c8ac648 157 while(list($undef,$v) = each($ret))
158 printf("<OPTION VALUE=%d %s>%s\n",
159 $v->bnum,
6e79bfe2 160 ($backend == $v->bnum) ? "SELECTED" : "",
161 $v->sname);
c9e9b23c 162 print "</SELECT>\n";
14f1b90b 163 } else {
c9e9b23c 164 print "<INPUT TYPE=hidden NAME=backend VALUE=-1>\n";
14f1b90b 165 }
166 printf("<INPUT TYPE=submit VALUE=\"%s\">",
6e79bfe2 167 _("Search"));
14f1b90b 168 printf("&nbsp;|&nbsp;<INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n",
6e79bfe2 169 _("List all"));
c9e9b23c 170 print '</FORM></center>';
6e79bfe2 171
c9e9b23c 172 print "</TD></TR></TABLE>\n";
14f1b90b 173 addr_insert_hidden();
14f1b90b 174 print "</CENTER>";
c9e9b23c 175 do_hook('addrbook_html_search_below');
14f1b90b 176 // End search form
177
178 // Show personal addressbook
507832e7 179 if($addrquery == '' || !empty($listall)) {
14f1b90b 180
507832e7 181 if(! isset($backend) || $backend != -1 || $addrquery == '') {
182 if($addrquery == '')
6e79bfe2 183 $backend = $abook->localbackend;
14f1b90b 184
6e79bfe2 185 //printf("<H3 ALIGN=center>%s</H3>\n", $abook->backends[$backend]->sname);
14f1b90b 186
6e79bfe2 187 $res = $abook->list_addr($backend);
14f1b90b 188
6e79bfe2 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 }
14f1b90b 195
196 } else {
6e79bfe2 197 $res = $abook->list_addr();
198 addr_display_result($res, true);
14f1b90b 199 }
6e79bfe2 200 exit;
14f1b90b 201
202 } else
203
204 // Do the search
205 if(!empty($addrquery) && empty($listall)) {
206
207 if($backend == -1) {
6e79bfe2 208 $res = $abook->s_search($addrquery);
14f1b90b 209 } else {
6e79bfe2 210 $res = $abook->s_search($addrquery, $backend);
14f1b90b 211 }
c1e15177 212
213 if(!is_array($res)) {
6e79bfe2 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);
c1e15177 222 }
c1e15177 223 }
224
4c8ac648 225 if ($addrquery == '' || sizeof($res) == 0) {
6e79bfe2 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"));
c9e9b23c 229 print '</form>';
230 print '</center></nobr>';
4c8ac648 231 }
6e79bfe2 232
c1e15177 233?>
d7d3c4d4 234</body></html>