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