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