fixed some quoting problems in searching and message highlighting
[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
17 session_start();
18
19 if (!isset($config_php))
20 include("../config/config.php");
21 if (!isset($strings_php))
22 include("../functions/strings.php");
23 if (!isset($auth_php))
24 include("../functions/auth.php");
25 if (!isset($page_header_php))
26 include("../functions/page_header.php");
27 if (!isset($date_php))
28 include("../functions/date.php");
29 if (!isset($smtp_php))
30 include("../functions/smtp.php");
31 if (!isset($display_messages_php))
32 include("../functions/display_messages.php");
33 if (!isset($addressbook_php))
34 include("../functions/addressbook.php");
35
36 include("../src/load_prefs.php");
37
38 // Insert hidden data
39 function addr_insert_hidden() {
40 global $body, $subject, $send_to, $send_to_cc, $send_to_bcc;
41 printf("<input type=hidden value=\"%s\" name=body>\n",
42 htmlspecialchars($body));
43 printf("<input type=hidden value=\"%s\" name=subject>\n",
44 htmlspecialchars($subject));
45 printf("<input type=hidden value=\"%s\" name=send_to>\n",
46 htmlspecialchars($send_to));
47 printf("<input type=hidden value=\"%s\" name=send_to_cc>\n",
48 htmlspecialchars($send_to_cc));
49 printf("<input type=hidden value=\"%s\" name=send_to_bcc>\n",
50 htmlspecialchars($send_to_bcc));
51 }
52
53
54 // List search results
55 function addr_display_result($res, $includesource = true) {
56 global $color, $PHP_SELF;
57
58 if(sizeof($res) <= 0) return;
59
60 printf('<FORM METHOD=post ACTION="%s?html_addr_search_done=true">'."\n",
61 $PHP_SELF);
62 addr_insert_hidden();
63 $line = 0;
64
65 print "<TABLE BORDER=0 WIDTH=\"98%\" ALIGN=center>";
66 printf("<TR BGCOLOR=\"$color[9]\"><TH ALIGN=left>&nbsp;".
67 "<TH ALIGN=left>&nbsp;%s<TH ALIGN=left>&nbsp;%s".
68 "<TH ALIGN=left>&nbsp;%s",
69 _("Name"), _("E-mail"), _("Info"));
70
71 if($includesource)
72 printf("<TH ALIGN=left WIDTH=\"10%%\">&nbsp;%s", _("Source"));
73
74 print "</TR>\n";
75
76 while(list($key, $row) = each($res)) {
77 printf("<tr%s nowrap><td nowrap align=center width=\"5%%\">".
78 "<input type=checkbox name=\"send_to_search[]\" value=\"%s\">&nbsp;To".
79 "<input type=checkbox name=\"send_to_cc_search[]\" value=\"%s\">&nbsp;Cc&nbsp;".
80 "<td nowrap>&nbsp;%s&nbsp;<td nowrap>&nbsp;".
81 "%s".
82 "<td nowrap>&nbsp;%s&nbsp;",
83 ($line % 2) ? " bgcolor=\"$color[0]\"" : "",
84 htmlspecialchars($row["email"]), htmlspecialchars($row["email"]),
85 $row["name"], $row["email"], $row["label"]);
86 if($includesource)
87 printf("<td nowrap>&nbsp;%s", $row["source"]);
88
89 print "</TR>\n";
90 $line++;
91 }
92 printf('<TR><TD ALIGN=center COLSPAN=%d><INPUT TYPE=submit '.
93 'NAME="addr_search_done" VALUE="%s"></TD></TR>',
94 4 + ($includesource ? 1 : 0),
95 _("Use Addresses"));
96 print "</TABLE>";
97 print '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">';
98 print "</FORM>";
99 }
100
101 // --- End functions ---
102
103 displayPageHeader($color, "None");
104
105 // Initialize addressbook
106 $abook = addressbook_init();
107
108 $body = stripslashes($body);
109 $send_to = stripslashes($send_to);
110 $send_to_cc = stripslashes($send_to_cc);
111 $send_to_bcc = stripslashes($send_to_bcc);
112 $subject = stripslashes($subject);
113
114
115 // Header
116 print "<TABLE BORDER=0 WIDTH=100% COLS=1 ALIGN=CENTER>\n";
117 printf('<TR><TD BGCOLOR="%s" ALIGN=CENTER><STRONG>%s</STRONG></TD></TR>',
118 $color[0], _("Address Book Search"));
119 print "</TABLE>\n";
120
121 // Search form
122 print "<CENTER>\n";
123 printf('<FORM METHOD=post ACTION="%s?html_addr_search=true">'."\n",
124 $PHP_SELF);
125 print "<TABLE BORDER=0>\n";
126 printf("<TR><TD NOWRAP VALIGN=middle>\n");
127 printf(" <STRONG>%s</STRONG>\n", _("Search for"));
128 printf(" <INPUT TYPE=text NAME=addrquery VALUE=\"%s\" SIZE=26>\n",
129 htmlspecialchars($addrquery));
130
131 // List all backends to allow the user to choose where to search
132 if($abook->numbackends > 1) {
133 printf("<STRONG>%s</STRONG>&nbsp;<SELECT NAME=backend>\n",
134 _("in"));
135 printf("<OPTION VALUE=-1 %s>%s\n",
136 ($backend == -1) ? "SELECTED" : "",
137 _("All address books"));
138 $ret = $abook->get_backend_list();
139 while(list($k,$v) = each($ret))
140 printf("<OPTION VALUE=%d %s>%s\n",
141 $v->bnum,
142 ($backend == $v->bnum) ? "SELECTED" : "",
143 $v->sname);
144 printf("</SELECT>\n");
145 } else {
146 printf("<INPUT TYPE=hidden NAME=backend VALUE=-1>\n");
147 }
148 printf("<INPUT TYPE=submit VALUE=\"%s\">",
149 _("Search"));
150 printf("&nbsp;|&nbsp;<INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n",
151 _("List all"));
152 printf("</TD></TR></TABLE>\n");
153 addr_insert_hidden();
154 print "</FORM>";
155 print "</CENTER>";
156 // End search form
157
158 // Show personal addressbook
159 if(!isset($addrquery) || !empty($listall)) {
160
161 if($backend != -1 || !isset($addrquery)) {
162 if(!isset($addrquery))
163 $backend = $abook->localbackend;
164
165 //printf("<H3 ALIGN=center>%s</H3>\n", $abook->backends[$backend]->sname);
166
167 $res = $abook->list_addr($backend);
168
169 if(is_array($res)) {
170 addr_display_result($res, false);
171 } else {
172 printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s").
173 "</STRONG></P>\n", $abook->backends[$backend]->sname);
174 }
175
176 } else {
177 $res = $abook->list_addr();
178 addr_display_result($res, true);
179 }
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 exit;
197 }
198
199 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 exit;
203 }
204
205 addr_display_result($res);
206 }
207
208 ?>