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