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