* Further optimization
[squirrelmail.git] / src / addrbook_search_html.php
CommitLineData
c1e15177 1<?php
2 /**
3 ** addrbook_search.php
4 **
ef870322 5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
4d859bbb 7 **
14f1b90b 8 ** Handle addressbook searching with pure html.
4d859bbb 9 **
14f1b90b 10 ** This file is included from compose.php
c1e15177 11 **
14f1b90b 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!
245a6892 15 **
16 ** $Id$
c1e15177 17 **/
18
f740c049 19 include('../src/validate.php');
f740c049 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');
c9e9b23c 26 include('../src/load_prefs.php');
c1e15177 27
14f1b90b 28 // Insert hidden data
29 function addr_insert_hidden() {
eeb44e40 30 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox;
441f2d33 31
c9e9b23c 32 echo '<input type=hidden value="';
441f2d33 33 if (substr($body, 0, 1) == "\r")
34 echo "\n";
b897ac2e 35 echo htmlspecialchars($body) . '" name=body>' . "\n";
c9e9b23c 36 echo '<input type=hidden value="' . htmlspecialchars($subject)
b897ac2e 37 . '" name=subject>' . "\n";
c9e9b23c 38 echo '<input type=hidden value="' . htmlspecialchars($send_to)
b897ac2e 39 . '" name=send_to>' . "\n";
441f2d33 40 echo "<input type=hidden value=\"" . htmlspecialchars($send_to_cc)
b897ac2e 41 . '" name=send_to_cc>' . "\n";
441f2d33 42 echo "<input type=hidden value=\"" . htmlspecialchars($send_to_bcc)
b897ac2e 43 . '" name=send_to_bcc>' . "\n";
eeb44e40 44 echo "<input type=hidden name=mailbox value=\"" .
45 htmlspecialchars($mailbox) . "\">\n";
441f2d33 46 echo "<input type=hidden value=\"true\" name=from_htmladdr_search>\n";
14f1b90b 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
b8796881 56 echo '<form method=post action="' . $PHP_SELF . "\">\n";
57 echo '<input type=hidden name="html_addr_search_done" value="true">';
58 echo "\n";
14f1b90b 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;".
6e79bfe2 64 "<TH ALIGN=left>&nbsp;%s<TH ALIGN=left>&nbsp;%s".
65 "<TH ALIGN=left>&nbsp;%s",
66 _("Name"), _("E-mail"), _("Info"));
14f1b90b 67
68 if($includesource)
6e79bfe2 69 printf("<TH ALIGN=left WIDTH=\"10%%\">&nbsp;%s", _("Source"));
14f1b90b 70
71 print "</TR>\n";
72
b8796881 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>';
6e79bfe2 86 if($includesource)
b8796881 87 echo '<td nowrap>&nbsp;' . $row['source'] . '&nbsp;</td>';
88 echo "</tr>\n";
89 $line ++;
14f1b90b 90 }
91 printf('<TR><TD ALIGN=center COLSPAN=%d><INPUT TYPE=submit '.
6e79bfe2 92 'NAME="addr_search_done" VALUE="%s"></TD></TR>',
93 4 + ($includesource ? 1 : 0),
94 _("Use Addresses"));
c9e9b23c 95 print '</TABLE>';
14f1b90b 96 print '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">';
c9e9b23c 97 print '</FORM>';
14f1b90b 98 }
99
100 // --- End functions ---
101
eeb44e40 102 global $mailbox;
103 displayPageHeader($color, $mailbox);
507832e7 104
14f1b90b 105 // Initialize addressbook
106 $abook = addressbook_init();
c1e15177 107
6e79bfe2 108?>
14f1b90b 109
6e79bfe2 110<br>
111<table width=95% align=center cellpadding=2 cellspacing=2 border=0>
112<tr><td bgcolor="<?php echo $color[0] ?>">
113 <center><b><?php echo _("Address Book Search") ?></b></center>
114</td></tr></table>
14f1b90b 115
6e79bfe2 116<?php
14f1b90b 117 // Search form
118 print "<CENTER>\n";
14f1b90b 119 print "<TABLE BORDER=0>\n";
c9e9b23c 120 print "<TR><TD NOWRAP VALIGN=middle>\n";
6e79bfe2 121 printf('<FORM METHOD=post NAME=f ACTION="%s?html_addr_search=true">'."\n", $PHP_SELF);
122 print "<CENTER>\n";
123 printf(" <nobr><STRONG>%s</STRONG>\n", _("Search for"));
124 addr_insert_hidden();
245a6892 125 if (! isset($addrquery))
507832e7 126 $addrquery = '';
14f1b90b 127 printf(" <INPUT TYPE=text NAME=addrquery VALUE=\"%s\" SIZE=26>\n",
6e79bfe2 128 htmlspecialchars($addrquery));
14f1b90b 129
130 // List all backends to allow the user to choose where to search
12b4ef8b 131 if(!isset($backend)) $backend = "";
14f1b90b 132 if($abook->numbackends > 1) {
133 printf("<STRONG>%s</STRONG>&nbsp;<SELECT NAME=backend>\n",
6e79bfe2 134 _("in"));
14f1b90b 135 printf("<OPTION VALUE=-1 %s>%s\n",
6e79bfe2 136 ($backend == -1) ? "SELECTED" : "",
137 _("All address books"));
14f1b90b 138 $ret = $abook->get_backend_list();
fb16d219 139 while(list($undef,$v) = each($ret))
6e79bfe2 140 printf("<OPTION VALUE=%d %s>%s\n",
141 $v->bnum,
142 ($backend == $v->bnum) ? "SELECTED" : "",
143 $v->sname);
c9e9b23c 144 print "</SELECT>\n";
14f1b90b 145 } else {
c9e9b23c 146 print "<INPUT TYPE=hidden NAME=backend VALUE=-1>\n";
14f1b90b 147 }
148 printf("<INPUT TYPE=submit VALUE=\"%s\">",
6e79bfe2 149 _("Search"));
14f1b90b 150 printf("&nbsp;|&nbsp;<INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n",
6e79bfe2 151 _("List all"));
c9e9b23c 152 print '</FORM></center>';
6e79bfe2 153
c9e9b23c 154 print "</TD></TR></TABLE>\n";
14f1b90b 155 addr_insert_hidden();
14f1b90b 156 print "</CENTER>";
c9e9b23c 157 do_hook('addrbook_html_search_below');
14f1b90b 158 // End search form
159
160 // Show personal addressbook
507832e7 161 if($addrquery == '' || !empty($listall)) {
14f1b90b 162
507832e7 163 if(! isset($backend) || $backend != -1 || $addrquery == '') {
164 if($addrquery == '')
6e79bfe2 165 $backend = $abook->localbackend;
14f1b90b 166
6e79bfe2 167 //printf("<H3 ALIGN=center>%s</H3>\n", $abook->backends[$backend]->sname);
14f1b90b 168
6e79bfe2 169 $res = $abook->list_addr($backend);
14f1b90b 170
6e79bfe2 171 if(is_array($res)) {
172 addr_display_result($res, false);
173 } else {
174 printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s").
175 "</STRONG></P>\n", $abook->backends[$backend]->sname);
176 }
14f1b90b 177
178 } else {
6e79bfe2 179 $res = $abook->list_addr();
180 addr_display_result($res, true);
14f1b90b 181 }
6e79bfe2 182 exit;
14f1b90b 183
184 } else
185
186 // Do the search
187 if(!empty($addrquery) && empty($listall)) {
188
189 if($backend == -1) {
6e79bfe2 190 $res = $abook->s_search($addrquery);
14f1b90b 191 } else {
6e79bfe2 192 $res = $abook->s_search($addrquery, $backend);
14f1b90b 193 }
c1e15177 194
195 if(!is_array($res)) {
6e79bfe2 196 printf("<P ALIGN=center><B><BR>%s:<br>%s</B></P>\n</BODY></HTML>\n",
197 _("Your search failed with the following error(s)"),
198 $abook->error);
199 } else if(sizeof($res) == 0) {
200 printf("<P ALIGN=center><BR><B>%s.</B></P>\n</BODY></HTML>\n",
201 _("No persons matching your search was found"));
202 } else {
203 addr_display_result($res);
c1e15177 204 }
c1e15177 205 }
206
507832e7 207 if ($addrquery == '' || sizeof($res) == 0) {
6e79bfe2 208 printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF);
209 addr_insert_hidden();
210 printf("<INPUT TYPE=submit VALUE=\"%s\" NAME=return>\n", _("Return"));
c9e9b23c 211 print '</form>';
212 print '</center></nobr>';
6e79bfe2 213 }
214
c1e15177 215?>
d7d3c4d4 216</body></html>