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