ad41bfefa0b50e08634bd5cfd8aabd299b67c530
[squirrelmail.git] / src / addrbook_search.php
1 <?php
2 /**
3 ** addrbook_search.php
4 **
5 ** Handle addressbook searching in the popup window.
6 **
7 **/
8
9 session_start();
10
11 if(!isset($logged_in)) {
12 echo _("You must login first.");
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
39 displayHtmlHeader();
40
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") {
60 printf("<FORM NAME=sform TARGET=abookres ACTION=\"%s\" METHOD=\"POST\">\n",
61 $PHP_SELF);
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
82 function to_and_close($addr) {
83 to_address($addr);
84 parent.close();
85 }
86
87 function to_address($addr) {
88 var prefix = "";
89 var pwintype = typeof parent.opener.document.compose;
90
91 $addr = $addr.replace(/ {1,35}$/, "");
92
93 if(pwintype != "undefined" ) {
94 if ( parent.opener.document.compose.send_to.value ) {
95 prefix = ", ";
96 parent.opener.document.compose.send_to.value =
97 parent.opener.document.compose.send_to.value + ", " + $addr;
98
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
109 $addr = $addr.replace(/ {1,35}$/, "");
110
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;
125
126 $addr = $addr.replace(/ {1,35}$/, "");
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)) {
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) {
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;
164 print "<table border=0 width=\"98%\" align=center>";
165 printf("<tr bgcolor=\"$color[9]\"><TH align=left>&nbsp;".
166 "<TH align=left>&nbsp;%s<TH align=left>&nbsp;%s".
167 "<TH align=left>&nbsp;%s<TH align=left width=\"10%%\">".
168 "&nbsp;%s</tr>\n",
169 _("Name"), _("E-mail"), _("Info"), _("Source"));
170
171 while(list($key, $row) = each($res)) {
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>".
175 "<td nowrap>&nbsp;%s&nbsp;<td nowrap>&nbsp;".
176 "<a href=\"javascript:to_and_close('%s');\">%s</A>&nbsp;".
177 "<td nowrap>&nbsp;%s&nbsp;<td nowrap>&nbsp;%s</tr>\n",
178 ($line % 2) ? " bgcolor=\"$color[0]\"" : "", $row["email"],
179 $row["email"], $row["name"], $row["email"], $row["email"],
180 $row["label"], $row["source"]);
181 $line++;
182 }
183 print "</TABLE>";
184 }
185 ?>
186
187 </BODY></HTML>