| 1 | <?php |
| 2 | /** |
| 3 | ** addrbook_search.php |
| 4 | ** |
| 5 | ** Handle addressbook searching in the popup window. |
| 6 | ** |
| 7 | **/ |
| 8 | |
| 9 | // Function to include JavaScript code |
| 10 | function insert_javascript() { |
| 11 | ?> |
| 12 | <SCRIPT LANGUAGE="Javascript"><!-- |
| 13 | |
| 14 | function to_and_close($addr) { |
| 15 | to_address($addr); |
| 16 | parent.close(); |
| 17 | } |
| 18 | |
| 19 | function to_address($addr) { |
| 20 | var prefix = ""; |
| 21 | var pwintype = typeof parent.opener.document.compose; |
| 22 | |
| 23 | $addr = $addr.replace(/ {1,35}$/, ""); |
| 24 | |
| 25 | if(pwintype != "undefined" ) { |
| 26 | if ( parent.opener.document.compose.send_to.value ) { |
| 27 | prefix = ", "; |
| 28 | parent.opener.document.compose.send_to.value = |
| 29 | parent.opener.document.compose.send_to.value + ", " + $addr; |
| 30 | |
| 31 | } else { |
| 32 | parent.opener.document.compose.send_to.value = $addr; |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | function cc_address($addr) { |
| 38 | var prefix = ""; |
| 39 | var pwintype = typeof parent.opener.document.compose; |
| 40 | |
| 41 | $addr = $addr.replace(/ {1,35}$/, ""); |
| 42 | |
| 43 | if(pwintype != "undefined" ) { |
| 44 | if ( parent.opener.document.compose.send_to_cc.value ) { |
| 45 | prefix = ", "; |
| 46 | parent.opener.document.compose.send_to_cc.value = |
| 47 | parent.opener.document.compose.send_to_cc.value + ", " + $addr; |
| 48 | } else { |
| 49 | parent.opener.document.compose.send_to_cc.value = $addr; |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | function bcc_address($addr) { |
| 55 | var prefix = ""; |
| 56 | var pwintype = typeof parent.opener.document.compose; |
| 57 | |
| 58 | $addr = $addr.replace(/ {1,35}$/, ""); |
| 59 | |
| 60 | if(pwintype != "undefined" ) { |
| 61 | if ( parent.opener.document.compose.send_to_bcc.value ) { |
| 62 | prefix = ", "; |
| 63 | parent.opener.document.compose.send_to_bcc.value = |
| 64 | parent.opener.document.compose.send_to_bcc.value + ", " + $addr; |
| 65 | } else { |
| 66 | parent.opener.document.compose.send_to_bcc.value = $addr; |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | // --></SCRIPT> |
| 72 | |
| 73 | <?php |
| 74 | } // End of included JavaScript |
| 75 | |
| 76 | |
| 77 | // List search results |
| 78 | function display_result($res, $includesource = true) { |
| 79 | global $color; |
| 80 | |
| 81 | if(sizeof($res) <= 0) return; |
| 82 | |
| 83 | insert_javascript(); |
| 84 | |
| 85 | $line = 0; |
| 86 | print "<TABLE BORDER=0 WIDTH=\"98%\" ALIGN=center>"; |
| 87 | printf("<TR BGCOLOR=\"$color[9]\"><TH ALIGN=left> ". |
| 88 | "<TH ALIGN=left> %s<TH ALIGN=left> %s". |
| 89 | "<TH ALIGN=left> %s", |
| 90 | _("Name"), _("E-mail"), _("Info")); |
| 91 | |
| 92 | if($includesource) |
| 93 | printf("<TH ALIGN=left WIDTH=\"10%%\"> %s", _("Source")); |
| 94 | |
| 95 | print "</TR>\n"; |
| 96 | |
| 97 | while(list($key, $row) = each($res)) { |
| 98 | printf("<tr%s nowrap><td nowrap align=center width=\"5%%\">". |
| 99 | "<small><a href=\"javascript:to_address('%s');\">To</A> | ". |
| 100 | "<a href=\"javascript:cc_address('%s');\">Cc</A> | ". |
| 101 | "<a href=\"javascript:bcc_address('%s');\">Bcc</A></small>". |
| 102 | "<td nowrap> %s <td nowrap> ". |
| 103 | "<a href=\"javascript:to_and_close('%s');\">%s</A> ". |
| 104 | "<td nowrap> %s ", |
| 105 | ($line % 2) ? " bgcolor=\"$color[0]\"" : "", |
| 106 | $row["email"], $row["email"], $row["email"], |
| 107 | $row["name"], $row["email"], $row["email"], |
| 108 | $row["label"]); |
| 109 | |
| 110 | if($includesource) |
| 111 | printf("<td nowrap> %s", $row["source"]); |
| 112 | |
| 113 | print "</TR>\n"; |
| 114 | $line++; |
| 115 | } |
| 116 | print "</TABLE>"; |
| 117 | } |
| 118 | |
| 119 | /* ================= End of functions ================= */ |
| 120 | |
| 121 | session_start(); |
| 122 | |
| 123 | if(!isset($logged_in)) { |
| 124 | echo _("You must login first."); |
| 125 | exit; |
| 126 | } |
| 127 | if(!isset($username) || !isset($key)) { |
| 128 | echo _("You need a valid user and password to access this page!"); |
| 129 | exit; |
| 130 | } |
| 131 | |
| 132 | if (!isset($config_php)) |
| 133 | include("../config/config.php"); |
| 134 | if (!isset($array_php)) |
| 135 | include("../functions/array.php"); |
| 136 | if (!isset($strings_php)) |
| 137 | include("../functions/strings.php"); |
| 138 | if (!isset($imap_php)) |
| 139 | include("../functions/imap.php"); |
| 140 | if (!isset($page_header_php)) |
| 141 | include("../functions/page_header.php"); |
| 142 | if (!isset($addressbook_php)) |
| 143 | include("../functions/addressbook.php"); |
| 144 | |
| 145 | // Authenticate user and load prefs |
| 146 | $imapConnection = sqimap_login($username, $key, |
| 147 | $imapServerAddress, $imapPort, 10); |
| 148 | include("../src/load_prefs.php"); |
| 149 | sqimap_logout ($imapConnection); |
| 150 | |
| 151 | displayHtmlHeader(); |
| 152 | |
| 153 | // Choose correct colors for top and bottom frame |
| 154 | if($show == "form") { |
| 155 | echo "<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" "; |
| 156 | echo "LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\" "; |
| 157 | echo "OnLoad=\"document.sform.query.focus();\">"; |
| 158 | } else { |
| 159 | echo "<BODY TEXT=\"$color[8]\" BGCOLOR=\"$color[4]\" "; |
| 160 | echo "LINK=\"$color[7]\" VLINK=\"$color[7]\" ALINK=\"$color[7]\">\n"; |
| 161 | } |
| 162 | |
| 163 | // Empty search |
| 164 | if(empty($query) && empty($show) && empty($listall)) { |
| 165 | printf("<P ALIGN=center><BR>%s</P>\n</BODY></HTML>\n", |
| 166 | _("No persons matching your search was found")); |
| 167 | exit; |
| 168 | } |
| 169 | |
| 170 | // Initialize addressbook |
| 171 | $abook = addressbook_init(); |
| 172 | |
| 173 | // Create search form |
| 174 | if($show == "form") { |
| 175 | printf("<FORM NAME=sform TARGET=abookres ACTION=\"%s\" METHOD=\"POST\">\n", |
| 176 | $PHP_SELF); |
| 177 | printf("<TABLE BORDER=0 WIDTH=\"100%%\" HEIGHT=\"100%%\">"); |
| 178 | printf("<TR><TD NOWRAP VALIGN=middle NOWRAP>\n"); |
| 179 | printf(" <STRONG>%s</STRONG>\n", _("Search for")); |
| 180 | printf(" <INPUT TYPE=text NAME=query VALUE=\"%s\" SIZE=26>\n", |
| 181 | htmlspecialchars($query)); |
| 182 | |
| 183 | // List all backends to allow the user to choose where to search |
| 184 | if($abook->numbackends > 1) { |
| 185 | printf("<STRONG>%s</STRONG> <SELECT NAME=backend>\n", |
| 186 | _("in")); |
| 187 | printf("<OPTION VALUE=-1 SELECTED>%s\n", |
| 188 | _("All address books")); |
| 189 | $ret = $abook->get_backend_list(); |
| 190 | while(list($k,$v) = each($ret)) |
| 191 | printf("<OPTION VALUE=%d SELECTED>%s\n", $v->bnum, $v->sname); |
| 192 | printf("</SELECT>\n"); |
| 193 | } else { |
| 194 | printf("<INPUT TYPE=hidden NAME=backend VALUE=-1>\n"); |
| 195 | } |
| 196 | |
| 197 | printf("<INPUT TYPE=submit VALUE=\"%s\">", |
| 198 | _("Search")); |
| 199 | printf(" | <INPUT TYPE=submit VALUE=\"%s\" NAME=listall>\n", |
| 200 | _("List all")); |
| 201 | printf("</TD><TD ALIGN=right>\n"); |
| 202 | printf("<INPUT TYPE=button VALUE=\"%s\" onclick=\"parent.close();\">\n", |
| 203 | _("Close window")); |
| 204 | printf("</TD></TR></TABLE></FORM>\n"); |
| 205 | } else |
| 206 | |
| 207 | // Show personal addressbook |
| 208 | if($show == "blank" || !empty($listall)) { |
| 209 | |
| 210 | if($backend != -1 || $show == "blank") { |
| 211 | if($show == "blank") |
| 212 | $backend = $abook->localbackend; |
| 213 | |
| 214 | //printf("<H3 ALIGN=center>%s</H3>\n", $abook->backends[$backend]->sname); |
| 215 | |
| 216 | $res = $abook->list_addr($backend); |
| 217 | |
| 218 | if(is_array($res)) { |
| 219 | display_result($res, false); |
| 220 | } else { |
| 221 | printf("<P ALIGN=center><STRONG>"._("Unable to list addresses from %s"). |
| 222 | "</STRONG></P>\n", $abook->backends[$backend]->sname); |
| 223 | } |
| 224 | |
| 225 | } else { |
| 226 | $res = $abook->list_addr(); |
| 227 | display_result($res, true); |
| 228 | } |
| 229 | |
| 230 | } else |
| 231 | |
| 232 | // Do the search |
| 233 | if(!empty($query) && empty($listall)) { |
| 234 | |
| 235 | if($backend == -1) { |
| 236 | $res = $abook->s_search($query); |
| 237 | } else { |
| 238 | $res = $abook->s_search($query, $backend); |
| 239 | } |
| 240 | |
| 241 | if(!is_array($res)) { |
| 242 | printf("<P ALIGN=center><BR>%s:<br>%s</P>\n</BODY></HTML>\n", |
| 243 | _("Your search failed with the following error(s)"), |
| 244 | $abook->error); |
| 245 | exit; |
| 246 | } |
| 247 | |
| 248 | if(sizeof($res) == 0) { |
| 249 | printf("<P ALIGN=center><BR>%s.</P>\n</BODY></HTML>\n", |
| 250 | _("No persons matching your search was found")); |
| 251 | exit; |
| 252 | } |
| 253 | |
| 254 | display_result($res); |
| 255 | } |
| 256 | ?> |
| 257 | |
| 258 | </BODY></HTML> |