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