5100704d |
1 | <?php |
2 | /** |
3 | ** addrbook_search.php |
4 | ** |
5 | ** Handle addressbook searching in the popup window. |
6 | ** |
7 | **/ |
8 | |
9 | if(!isset($logged_in)) { |
138f26f6 |
10 | echo _("You must login first."); |
5100704d |
11 | exit; |
12 | } |
13 | if(!isset($username) || !isset($key)) { |
14 | echo _("You need a valid user and password to access this page!"); |
15 | exit; |
16 | } |
17 | |
18 | if (!isset($config_php)) |
19 | include("../config/config.php"); |
20 | if (!isset($array_php)) |
21 | include("../functions/array.php"); |
22 | if (!isset($strings_php)) |
23 | include("../functions/strings.php"); |
24 | if (!isset($imap_php)) |
25 | include("../functions/imap.php"); |
26 | if (!isset($page_header_php)) |
27 | include("../functions/page_header.php"); |
28 | if (!isset($addressbook_php)) |
29 | include("../functions/addressbook.php"); |
30 | |
31 | // Authenticate user and load prefs |
32 | $imapConnection = sqimap_login($username, $key, |
33 | $imapServerAddress, $imapPort, 10); |
34 | include("../src/load_prefs.php"); |
35 | sqimap_logout ($imapConnection); |
36 | |
37 | ?> |
38 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
39 | |
40 | <HTML> |
41 | <HEAD> |
42 | <TITLE><?php |
43 | printf("%s: %s", $org_title, _("Address Book")); |
44 | ?></TITLE> |
45 | </HEAD> |
46 | |
47 | <?php |
48 | // Choose correct colors for top and bottom frame |
49 | if($show == "form") { |
50 | echo "<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" "; |
51 | echo "LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\" "; |
52 | echo "OnLoad=\"document.sform.query.focus();\">"; |
53 | } else { |
54 | echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" "; |
55 | echo "LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n"; |
56 | } |
57 | |
58 | // Just make a blank page and exit |
59 | if(($show == "blank") || (empty($query) && empty($show))) { |
60 | printf("<P ALIGN=center><BR>%s</P>\n</BODY></HTML>\n", |
61 | _("Search results will display here")); |
62 | exit; |
63 | } |
64 | |
65 | // Create search form |
66 | if($show == "form") { |
67 | printf("<FORM NAME=sform TARGET=abookres ACTION=\"%s\" METHOD=GET>\n", |
68 | $PHP_SELF); |
69 | printf("<TABLE BORDER=0 WIDTH=\"100%%\" HEIGHT=\"100%%\">"); |
70 | printf("<TR><TD NOWRAP VALIGN=middle>\n"); |
71 | printf(" <STRONG>%s:</STRONG>\n</TD><TD VALIGN=middle>\n", |
72 | _("Search for")); |
73 | printf(" <INPUT TYPE=text NAME=query VALUE=\"%s\" SIZE=30>\n", |
74 | htmlspecialchars($query)); |
75 | printf("</TD><TD VALIGN=middle>\n"); |
76 | printf(" <INPUT TYPE=submit VALUE=\"%s\">", |
77 | _("Search")); |
78 | printf("</TD><TD WIDTH=\"50%%\" VALIGN=middle ALIGN=right>\n"); |
79 | printf("<INPUT TYPE=button VALUE=\"%s\" onclick=\"parent.close();\">\n", |
80 | _("Close window")); |
81 | printf("</TD></TR></TABLE></FORM>\n"); |
82 | } |
83 | |
84 | // Include JavaScript code if this is search results |
85 | if(!empty($query)) { |
86 | ?> |
87 | <SCRIPT LANGUAGE="Javascript"><!-- |
88 | |
89 | function to_address($addr) { |
90 | var prefix = ""; |
91 | var pwintype = typeof parent.opener.document.compose; |
92 | |
dfadb553 |
93 | $addr = $addr.replace(/ {1,35}$/, ""); |
94 | |
5100704d |
95 | if(pwintype != "undefined" ) { |
96 | if ( parent.opener.document.compose.send_to.value ) { |
97 | prefix = ", "; |
98 | parent.opener.document.compose.send_to.value = |
dfadb553 |
99 | parent.opener.document.compose.send_to.value + ", " + $addr; |
100 | |
5100704d |
101 | } else { |
102 | parent.opener.document.compose.send_to.value = $addr; |
103 | } |
104 | } |
105 | } |
106 | |
107 | function cc_address($addr) { |
108 | var prefix = ""; |
109 | var pwintype = typeof parent.opener.document.compose; |
110 | |
dfadb553 |
111 | $addr = $addr.replace(/ {1,35}$/, ""); |
112 | |
5100704d |
113 | if(pwintype != "undefined" ) { |
114 | if ( parent.opener.document.compose.send_to_cc.value ) { |
115 | prefix = ", "; |
116 | parent.opener.document.compose.send_to_cc.value = |
117 | parent.opener.document.compose.send_to_cc.value + ", " + $addr; |
118 | } else { |
119 | parent.opener.document.compose.send_to_cc.value = $addr; |
120 | } |
121 | } |
122 | } |
123 | |
124 | function bcc_address($addr) { |
125 | var prefix = ""; |
126 | var pwintype = typeof parent.opener.document.compose; |
dfadb553 |
127 | |
128 | $addr = $addr.replace(/ {1,35}$/, ""); |
5100704d |
129 | |
130 | if(pwintype != "undefined" ) { |
131 | if ( parent.opener.document.compose.bcc.value ) { |
132 | prefix = ", "; |
133 | parent.opener.document.compose.bcc.value = |
134 | parent.opener.document.compose.bcc.value + ", " + $addr; |
135 | } else { |
136 | parent.opener.document.compose.bcc.value = $addr; |
137 | } |
138 | } |
139 | } |
140 | |
141 | // --></SCRIPT> |
142 | |
143 | <?php |
144 | } // End of included JavaScript code |
145 | |
146 | // Do the search |
147 | if(!empty($query)) { |
148 | $abook = addressbook_init(); |
149 | $res = $abook->s_search($query); |
150 | |
151 | if(!is_array($res)) { |
a51f9f4b |
152 | printf("<P ALIGN=center><BR>%s:<br>%s</P>\n</BODY></HTML>\n", |
153 | _("Your search failed with the following error(s)"), |
154 | $abook->error); |
155 | exit; |
156 | } |
157 | |
158 | if(sizeof($res) == 0) { |
5100704d |
159 | printf("<P ALIGN=center><BR>%s.</P>\n</BODY></HTML>\n", |
160 | _("No persons matching your search was found")); |
161 | exit; |
162 | } |
163 | |
164 | // List search results |
165 | $line = 0; |
a51f9f4b |
166 | print "<table border=0 width=\"98%\" align=center>"; |
a16d133d |
167 | printf("<tr bgcolor=\"$color[9]\"><TH align=left> ". |
a51f9f4b |
168 | "<TH align=left> %s<TH align=left> %s". |
169 | "<TH align=left> %s<TH align=left width=\"10%%\">". |
170 | " %s</tr>\n", |
a16d133d |
171 | _("Name"), _("E-mail"), _("Info"), _("Source")); |
5100704d |
172 | |
173 | while(list($key, $row) = each($res)) { |
a51f9f4b |
174 | printf("<tr%s nowrap><td nowrap align=center width=\"5%%\">". |
175 | "<a href=\"javascript:to_address('%s');\">To</A> | ". |
176 | "<a href=\"javascript:cc_address('%s');\">Cc</A>". |
177 | "<td nowrap> %s <td nowrap> %s ". |
178 | "<td nowrap> %s <td nowrap> %s</tr>\n", |
5100704d |
179 | ($line % 2) ? " bgcolor=\"$color[0]\"" : "", $row["email"], |
180 | $row["email"], $row["name"], $row["email"], $row["label"], |
181 | $row["source"]); |
182 | $line++; |
183 | } |
184 | print "</TABLE>"; |
185 | } |
186 | ?> |
187 | |
188 | </BODY></HTML> |