| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * addrbook_search_html.php |
| 5 | * |
| 6 | * Copyright (c) 1999-2003 The SquirrelMail Project Team |
| 7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
| 8 | * |
| 9 | * Handle addressbook searching with pure html. |
| 10 | * |
| 11 | * This file is included from compose.php |
| 12 | * |
| 13 | * $Id$ |
| 14 | */ |
| 15 | |
| 16 | /* Path for SquirrelMail required files. */ |
| 17 | if (! defined('SM_PATH') ) { |
| 18 | define('SM_PATH','../'); |
| 19 | } |
| 20 | |
| 21 | /* SquirrelMail required files. */ |
| 22 | require_once(SM_PATH . 'include/validate.php'); |
| 23 | require_once(SM_PATH . 'functions/global.php'); |
| 24 | require_once(SM_PATH . 'functions/date.php'); |
| 25 | require_once(SM_PATH . 'functions/display_messages.php'); |
| 26 | require_once(SM_PATH . 'functions/addressbook.php'); |
| 27 | require_once(SM_PATH . 'functions/plugin.php'); |
| 28 | require_once(SM_PATH . 'functions/strings.php'); |
| 29 | require_once(SM_PATH . 'functions/html.php'); |
| 30 | |
| 31 | sqgetGlobalVar('session', $session, SQ_POST); |
| 32 | sqgetGlobalVar('mailbox', $mailbox, SQ_POST); |
| 33 | sqgetGlobalVar('addrquery', $addrquery, SQ_POST); |
| 34 | sqgetGlobalVar('listall', $listall, SQ_POST); |
| 35 | sqgetGlobalVar('backend', $backend, SQ_POST); |
| 36 | |
| 37 | /* Insert hidden data */ |
| 38 | function addr_insert_hidden() { |
| 39 | global $body, $subject, $send_to, $send_to_cc, $send_to_bcc, $mailbox, |
| 40 | $identity, $session; |
| 41 | |
| 42 | echo '<input type=hidden value="'; |
| 43 | if (substr($body, 0, 1) == "\r") { |
| 44 | echo "\n"; |
| 45 | } |
| 46 | echo htmlspecialchars($body) . '" name=body>' . "\n" . |
| 47 | '<input type=hidden value="' . $session . '" name=session>' . "\n" . |
| 48 | '<input type=hidden value="' . htmlspecialchars($subject) . |
| 49 | '" name=subject>' . "\n" . |
| 50 | '<input type=hidden value="' . htmlspecialchars($send_to) . |
| 51 | '" name=send_to>' . "\n" . |
| 52 | '<input type=hidden value="' . htmlspecialchars($send_to_cc) . |
| 53 | '" name=send_to_cc>' . "\n" . |
| 54 | '<input type=hidden value="' . htmlspecialchars($send_to_bcc) . |
| 55 | '" name=send_to_bcc>' . "\n" . |
| 56 | '<input type=hidden value="' . htmlspecialchars($identity) . |
| 57 | '" name=identity>' . "\n" . |
| 58 | '<input type=hidden name=mailbox value="' . htmlspecialchars($mailbox) . |
| 59 | "\">\n" . '<input type=hidden value="true" name=from_htmladdr_search>' . |
| 60 | "\n"; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | /* List search results */ |
| 65 | function addr_display_result($res, $includesource = true) { |
| 66 | global $color, $javascript_on, $PHP_SELF, $squirrelmail_language; |
| 67 | |
| 68 | if (sizeof($res) <= 0) return; |
| 69 | |
| 70 | echo '<form method=post action="' . $PHP_SELF . '" name="addrbook">'."\n" . |
| 71 | '<input type=hidden name="html_addr_search_done" value="true">' . "\n"; |
| 72 | addr_insert_hidden(); |
| 73 | $line = 0; |
| 74 | |
| 75 | if ($javascript_on) { |
| 76 | print |
| 77 | '<script language="JavaScript" type="text/javascript">' . |
| 78 | "\n<!-- \n" . |
| 79 | "function CheckAll(ch) {\n" . |
| 80 | " for (var i = 0; i < document.addrbook.elements.length; i++) {\n" . |
| 81 | " if( document.addrbook.elements[i].type == 'checkbox' &&\n" . |
| 82 | " document.addrbook.elements[i].name.substr(0,16) == 'send_to_search['+ch ) {\n" . |
| 83 | " document.addrbook.elements[i].checked = !(document.addrbook.elements[i].checked);\n". |
| 84 | " }\n" . |
| 85 | " }\n" . |
| 86 | "}\n" . |
| 87 | "//-->\n" . |
| 88 | "</script>\n"; |
| 89 | $chk_all = '<a href="#" onClick="CheckAll(\'T\');">' . _("All") . '</a> <font color="'.$color[9].'">To</font>'. |
| 90 | ' '. |
| 91 | '<a href="#" onClick="CheckAll(\'C\');">' . _("All") . '</a> <font color="'.$color[9].'">Cc</font>'. |
| 92 | ' '. |
| 93 | '<a href="#" onClick="CheckAll(\'B\');">' . _("All") . '</a>'; |
| 94 | } |
| 95 | echo html_tag( 'table', '', 'center', '', 'border="0" width="98%"' ) . |
| 96 | html_tag( 'tr', '', '', $color[9] ) . |
| 97 | html_tag( 'th', ' ' . $chk_all, 'left' ) . |
| 98 | html_tag( 'th', ' ' . _("Name"), 'left' ) . |
| 99 | html_tag( 'th', ' ' . _("E-mail"), 'left' ) . |
| 100 | html_tag( 'th', ' ' . _("Info"), 'left' ); |
| 101 | |
| 102 | if ($includesource) { |
| 103 | echo html_tag( 'th', ' ' . _("Source"), 'left', '', 'width="10%"' ); |
| 104 | } |
| 105 | |
| 106 | echo "</tr>\n"; |
| 107 | |
| 108 | foreach ($res as $row) { |
| 109 | $tr_bgcolor = ''; |
| 110 | $email = AddressBook::full_address($row); |
| 111 | if ($line % 2) { $tr_bgcolor = $color[0]; } |
| 112 | if ($squirrelmail_language == 'ja_JP') |
| 113 | { |
| 114 | echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) . |
| 115 | html_tag( 'td', |
| 116 | '<input type=checkbox name="send_to_search[T' . $line . ']" value = "' . |
| 117 | htmlspecialchars($email) . '"> ' . _("To") . ' ' . |
| 118 | '<input type=checkbox name="send_to_search[C' . $line . ']" value = "' . |
| 119 | htmlspecialchars($email) . '"> ' . _("Cc") . ' ' . |
| 120 | '<input type=checkbox name="send_to_search[B' . $line . ']" value = "' . |
| 121 | htmlspecialchars($email) . '"> ' . _("Bcc") . ' ' , |
| 122 | 'center', '', 'width="5%" nowrap' ) . |
| 123 | html_tag( 'td', ' ' . htmlspecialchars($row['lastname']) . ' ' . htmlspecialchars($row['firstname']) . ' ', 'left', '', 'nowrap' ) . |
| 124 | html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'nowrap' ) . |
| 125 | html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'nowrap' ); |
| 126 | } else { |
| 127 | echo html_tag( 'tr', '', '', $tr_bgcolor, 'nowrap' ) . |
| 128 | html_tag( 'td', |
| 129 | '<input type=checkbox name="send_to_search[T' . $line . ']" value = "' . |
| 130 | htmlspecialchars($email) . '"> ' . _("To") . ' ' . |
| 131 | '<input type=checkbox name="send_to_search[C' . $line . ']" value = "' . |
| 132 | htmlspecialchars($email) . '"> ' . _("Cc") . ' ' . |
| 133 | '<input type=checkbox name="send_to_search[B' . $line . ']" value = "' . |
| 134 | htmlspecialchars($email) . '"> ' . _("Bcc") . ' ' , |
| 135 | 'center', '', 'width="5%" nowrap' ) . |
| 136 | html_tag( 'td', ' ' . htmlspecialchars($row['name']) . ' ', 'left', '', 'nowrap' ) . |
| 137 | html_tag( 'td', ' ' . htmlspecialchars($row['email']) . ' ', 'left', '', 'nowrap' ) . |
| 138 | html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'nowrap' ); |
| 139 | } |
| 140 | |
| 141 | if ($includesource) { |
| 142 | echo html_tag( 'td', ' ' . $row['source'] . ' ', 'left', '', 'nowrap' ); |
| 143 | } |
| 144 | echo "</tr>\n"; |
| 145 | $line ++; |
| 146 | } |
| 147 | if ($includesource) { $td_colspan = '5'; } else { $td_colspan = '4'; } |
| 148 | echo html_tag( 'tr', |
| 149 | html_tag( 'td', |
| 150 | '<INPUT TYPE=submit NAME="addr_search_done" VALUE="' . |
| 151 | _("Use Addresses") . '">' , |
| 152 | 'center', '', 'colspan="'. $td_colspan .'"' ) |
| 153 | ) . |
| 154 | '</TABLE>' . |
| 155 | '<INPUT TYPE=hidden VALUE=1 NAME="html_addr_search_done">' . |
| 156 | '</FORM>'; |
| 157 | } |
| 158 | |
| 159 | /* --- End functions --- */ |
| 160 | |
| 161 | if ($compose_new_win == '1') { |
| 162 | compose_Header($color, $mailbox); |
| 163 | } |
| 164 | else { |
| 165 | displayPageHeader($color, $mailbox); |
| 166 | } |
| 167 | /* Initialize addressbook */ |
| 168 | $abook = addressbook_init(); |
| 169 | |
| 170 | |
| 171 | echo '<br>' . |
| 172 | html_tag( 'table', |
| 173 | html_tag( 'tr', |
| 174 | html_tag( 'td', '<b>' . _("Address Book Search") . '</b>', 'center', $color[0] ) |
| 175 | ) , |
| 176 | 'center', '', 'width="95%" cellpadding="2" cellspacing="2" border="0"' ); |
| 177 | |
| 178 | |
| 179 | /* Search form */ |
| 180 | echo '<center>' . |
| 181 | html_tag( 'table', '', 'center', '', 'border="0"' ) . |
| 182 | html_tag( 'tr' ) . |
| 183 | html_tag( 'td', '', 'left', '', 'nowrap valign="middle"' ) . "\n" . |
| 184 | '<FORM METHOD=post NAME=f ACTION="' . $PHP_SELF . |
| 185 | '?html_addr_search=true">' . "\n<CENTER>\n" . |
| 186 | ' <nobr><STRONG>' . _("Search for") . "</STRONG>\n"; |
| 187 | addr_insert_hidden(); |
| 188 | if (! isset($addrquery)) |
| 189 | $addrquery = ''; |
| 190 | echo ' <INPUT TYPE=text NAME=addrquery VALUE="' . |
| 191 | htmlspecialchars($addrquery) . "\" SIZE=26>\n"; |
| 192 | |
| 193 | /* List all backends to allow the user to choose where to search */ |
| 194 | if (!isset($backend)) { $backend = ''; } |
| 195 | if ($abook->numbackends > 1) { |
| 196 | echo '<STRONG>' . _("in") . '</STRONG> <SELECT NAME=backend>' . "\n" . |
| 197 | '<OPTION VALUE=-1'; |
| 198 | if ($backend == -1) { echo ' SELECTED'; } |
| 199 | echo '>' . _("All address books") . "\n"; |
| 200 | $ret = $abook->get_backend_list(); |
| 201 | while (list($undef,$v) = each($ret)) { |
| 202 | echo '<OPTION VALUE=' . $v->bnum; |
| 203 | if ($backend == $v->bnum) { echo ' SELECTED'; } |
| 204 | echo '>' . $v->sname . "\n"; |
| 205 | } |
| 206 | echo "</SELECT>\n"; |
| 207 | } else { |
| 208 | echo '<INPUT TYPE=hidden NAME=backend VALUE=-1>' . "\n"; |
| 209 | } |
| 210 | if (isset($session)) { |
| 211 | echo "<input type=hidden name=\"session\" value=\"$session\">"; |
| 212 | } |
| 213 | |
| 214 | echo '<INPUT TYPE=submit VALUE="' . _("Search") . '">' . |
| 215 | ' | <INPUT TYPE=submit VALUE="' . _("List all") . |
| 216 | '" NAME=listall>' . "\n" . |
| 217 | '</FORM></center></TD></TR></TABLE>' . "\n"; |
| 218 | addr_insert_hidden(); |
| 219 | echo '</center>'; |
| 220 | do_hook('addrbook_html_search_below'); |
| 221 | /* End search form */ |
| 222 | |
| 223 | /* Show personal addressbook */ |
| 224 | |
| 225 | if ( !empty( $listall ) ){ |
| 226 | $addrquery = '*'; |
| 227 | } |
| 228 | |
| 229 | if ($addrquery == '' && empty($listall)) { |
| 230 | |
| 231 | if (! isset($backend) || $backend != -1 || $addrquery == '') { |
| 232 | if ($addrquery == '') { |
| 233 | $backend = $abook->localbackend; |
| 234 | } |
| 235 | |
| 236 | /* echo '<H3 ALIGN=center>' . $abook->backends[$backend]->sname) . "</H3>\n"; */ |
| 237 | |
| 238 | $res = $abook->list_addr($backend); |
| 239 | |
| 240 | if (is_array($res)) { |
| 241 | usort($res,'alistcmp'); |
| 242 | addr_display_result($res, false); |
| 243 | } else { |
| 244 | echo html_tag( 'p', '<strong><br>' . |
| 245 | sprintf(_("Unable to list addresses from %s"), |
| 246 | $abook->backends[$backend]->sname) . "</strong>\n" , |
| 247 | 'center' ); |
| 248 | } |
| 249 | |
| 250 | } else { |
| 251 | $res = $abook->list_addr(); |
| 252 | usort($res,'alistcmp'); |
| 253 | addr_display_result($res, true); |
| 254 | } |
| 255 | exit; |
| 256 | } |
| 257 | else { |
| 258 | |
| 259 | /* Do the search */ |
| 260 | if (!empty($addrquery)) { |
| 261 | |
| 262 | if ($backend == -1) { |
| 263 | $res = $abook->s_search($addrquery); |
| 264 | } else { |
| 265 | $res = $abook->s_search($addrquery, $backend); |
| 266 | } |
| 267 | |
| 268 | if (!is_array($res)) { |
| 269 | echo html_tag( 'p', '<b><br>' . |
| 270 | _("Your search failed with the following error(s)") . |
| 271 | ':<br>' . $abook->error . "</b>\n" , |
| 272 | 'center' ) . |
| 273 | "\n</BODY></HTML>\n"; |
| 274 | } else { |
| 275 | if (sizeof($res) == 0) { |
| 276 | echo html_tag( 'p', '<br><b>' . |
| 277 | _("No persons matching your search was found") . "</b>\n" , |
| 278 | 'center' ) . |
| 279 | "\n</BODY></HTML>\n"; |
| 280 | } else { |
| 281 | addr_display_result($res); |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | if ($addrquery == '' || sizeof($res) == 0) { |
| 288 | /* printf('<center><FORM METHOD=post NAME=k ACTION="compose.php">'."\n", $PHP_SELF); */ |
| 289 | echo '<center><FORM METHOD=post NAME=k ACTION="compose.php">' . "\n"; |
| 290 | addr_insert_hidden(); |
| 291 | echo '<INPUT TYPE=submit VALUE="' . _("Return") . '" NAME=return>' . "\n" . |
| 292 | '</form></center></nobr>'; |
| 293 | } |
| 294 | |
| 295 | ?> |
| 296 | </body></html> |