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