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