00001 <?php
00002
00003
00012 require('./db_details_common.php');
00013
00014 if (!$cfg['UseDbSearch']) {
00015 PMA_mysqlDie($strAccessDenied, '', FALSE, $err_url);
00016 }
00017 $url_query .= '&goto=db_search.php';
00018
00019
00023 $tables = PMA_DBI_get_tables($db);
00024 $num_tables = count($tables);
00025
00026
00030 $sub_part = '';
00031 require('./db_details_links.php');
00032
00033
00037 if (isset($submit_search)) {
00038
00051 function PMA_getSearchSqls($table, $search_str, $search_option)
00052 {
00053 global $err_url, $charset_connection;
00054
00055
00056 $sqlstr_select = 'SELECT';
00057 $sqlstr_delete = 'DELETE';
00058
00059
00060 $res = PMA_DBI_query('SHOW ' . (PMA_MYSQL_INT_VERSION >= 40100 ? 'FULL ' : '') . 'FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($GLOBALS['db']) . ';');
00061 while ($current = PMA_DBI_fetch_assoc($res)) {
00062 if (PMA_MYSQL_INT_VERSION >= 40100) {
00063 list($current['Charset']) = explode('_', $current['Collation']);
00064 }
00065 $current['Field'] = PMA_backquote($current['Field']);
00066 $tblfields[] = $current;
00067 }
00068 PMA_DBI_free_result($res);
00069 unset($current, $res);
00070 $tblfields_cnt = count($tblfields);
00071
00072
00073 $sqlstr_from = ' FROM ' . PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($table);
00074
00075
00076 $sqlstr_where = ' WHERE';
00077
00078 $search_words = (($search_option > 2) ? array($search_str) : explode(' ', $search_str));
00079 $search_wds_cnt = count($search_words);
00080
00081 $like_or_regex = (($search_option == 4) ? 'REGEXP' : 'LIKE');
00082 $automatic_wildcard = (($search_option <3) ? '%' : '');
00083
00084 for ($i = 0; $i < $search_wds_cnt; $i++) {
00085
00086
00087
00088 if (!empty($search_words[$i])) {
00089 for ($j = 0; $j < $tblfields_cnt; $j++) {
00090 if (PMA_MYSQL_INT_VERSION >= 40100 && $tblfields[$j]['Charset'] != $charset_connection && $tblfields[$j]['Charset'] != 'NULL' && $tblfields[$j]['Charset'] != '') {
00091 $prefix = 'CONVERT(_utf8 ';
00092 $suffix = ' USING ' . $tblfields[$j]['Charset'] . ') COLLATE ' . $tblfields[$j]['Collation'];
00093 } else {
00094 $prefix = $suffix = '';
00095 }
00096 $thefieldlikevalue[] = $tblfields[$j]['Field']
00097 . ' ' . $like_or_regex . ' '
00098 . $prefix
00099 . '\''
00100 . $automatic_wildcard
00101 . $search_words[$i]
00102 . $automatic_wildcard . '\''
00103 . $suffix;
00104 }
00105
00106 $fieldslikevalues[] = ($search_wds_cnt > 1)
00107 ? '(' . implode(' OR ', $thefieldlikevalue) . ')'
00108 : implode(' OR ', $thefieldlikevalue);
00109 unset($thefieldlikevalue);
00110 }
00111 }
00112
00113 $implode_str = ($search_option == 1 ? ' OR ' : ' AND ');
00114 $sqlstr_where .= ' ' . implode($implode_str, $fieldslikevalues);
00115 unset($fieldslikevalues);
00116
00117
00118 $sql['select_fields'] = $sqlstr_select . ' * ' . $sqlstr_from . $sqlstr_where;
00119 $sql['select_count'] = $sqlstr_select . ' COUNT(*) AS count' . $sqlstr_from . $sqlstr_where;
00120 $sql['delete'] = $sqlstr_delete . $sqlstr_from . $sqlstr_where;
00121
00122 return $sql;
00123 }
00124
00125
00129 if (!empty($search_str) && !empty($search_option)) {
00130
00131 $original_search_str = $search_str;
00132 $search_str = PMA_sqlAddslashes($search_str, TRUE);
00133
00134
00135 switch ($search_option) {
00136 case 1:
00137 $option_str = ' (' . $strSearchOption1 . ')';
00138 break;
00139 case 2:
00140 $option_str = ' (' . $strSearchOption2 . ')';
00141 break;
00142 case 3:
00143 $option_str = ' (' . $strSearchOption3 . ')';
00144 break;
00145 case 4:
00146 $option_str = ' (' . $strSearchOption4 . ')';
00147 break;
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157 if (isset($table)) {
00158 $onetable = $table;
00159 }
00160 else if (isset($table_select)) {
00161 $num_selectedtables = count($table_select);
00162 if ($num_selectedtables == 1) {
00163 $onetable = $table_select[0];
00164 }
00165 }
00166 else if ($num_tables == 1) {
00167 $onetable = $tables[0];
00168 }
00169 else {
00170 for ($i = 0; $i < $num_tables; $i++) {
00171 $table_select[] = $tables[$i];
00172 }
00173 $num_selectedtables = $num_tables;
00174 }
00175 ?>
00176 <br />
00177
00178 <?php
00179 $url_sql_query = PMA_generate_common_url($db)
00180 . '&goto=db_details.php'
00181 . '&pos=0'
00182 . '&is_js_confirmed=0';
00183
00184
00185 if (isset($onetable)) {
00186
00187 echo ' ' . sprintf($strSearchResultsFor, htmlspecialchars($original_search_str), $option_str) . "\n";
00188 echo ' <br />' . "\n";
00189
00190
00191 $newsearchsqls = PMA_getSearchSqls($onetable, $search_str, $search_option);
00192
00193
00194 $res = PMA_DBI_query($newsearchsqls['select_count']);
00195 $res_cnt = PMA_DBI_fetch_assoc($res);
00196 $res_cnt = $res_cnt['count'];
00197 PMA_DBI_free_result($res);
00198 $num_search_result_total = $res_cnt;
00199
00200 echo ' <!-- Search results in table ' . $onetable . ' (' . $res_cnt . ') -->' . "\n"
00201 . ' <br />' . "\n"
00202 . ' <table><tr><td>' . sprintf($strNumSearchResultsInTable, $res_cnt, htmlspecialchars($onetable)) . "</td>\n";
00203
00204 if ($res_cnt > 0) {
00205 echo '<td>' . PMA_linkOrButton('sql.php?' . $url_sql_query
00206 . '&sql_query=' .urlencode($newsearchsqls['select_fields']),
00207 $strBrowse, '') . "</td>\n";
00208
00209 echo '<td>' . PMA_linkOrButton('sql.php?' . $url_sql_query
00210 . '&sql_query=' .urlencode($newsearchsqls['delete']),
00211 $strDelete, $newsearchsqls['delete']) . "</td>\n";
00212
00213 }
00214 echo '</tr></table>' . "\n";
00215 }
00216
00217
00218 else if (isset($table_select)) {
00219
00220 echo ' ' . sprintf($strSearchResultsFor, htmlspecialchars($original_search_str), $option_str) . "\n";
00221 echo ' <ul>' . "\n";
00222
00223 $num_search_result_total = 0;
00224 for ($i = 0; $i < $num_selectedtables; $i++) {
00225
00226 $newsearchsqls = PMA_getSearchSqls($table_select[$i], $search_str, $search_option);
00227
00228
00229 $res = PMA_DBI_query($newsearchsqls['select_count']);
00230 $res_cnt = PMA_DBI_fetch_assoc($res);
00231 $res_cnt = $res_cnt['count'];
00232 PMA_DBI_free_result($res);
00233 unset($res);
00234 $num_search_result_total += $res_cnt;
00235
00236 echo ' <!-- Search results in table ' . $table_select[$i] . ' (' . $res_cnt . ') -->' . "\n"
00237 . ' <li>' . "\n"
00238 . ' <table><tr><td>' . sprintf($strNumSearchResultsInTable, $res_cnt, htmlspecialchars($table_select[$i])) . "</td>\n";
00239
00240 if ($res_cnt > 0) {
00241 echo '<td>' . PMA_linkOrButton('sql.php?' . $url_sql_query
00242 . '&sql_query=' .urlencode($newsearchsqls['select_fields']),
00243 $strBrowse, '') . "</td>\n";
00244
00245 echo '<td>' . PMA_linkOrButton('sql.php?' . $url_sql_query
00246 . '&sql_query=' .urlencode($newsearchsqls['delete']),
00247 $strDelete, $newsearchsqls['delete']) . "</td>\n";
00248
00249 }
00250
00251 echo ' </tr></table></li>' . "\n";
00252 }
00253
00254 echo ' </ul>' . "\n";
00255 echo ' <p>' . sprintf($strNumSearchResultsTotal, $num_search_result_total) . '</p>' . "\n";
00256 }
00257
00258 echo "\n";
00259 ?>
00260 <hr width="100%">
00261 <?php
00262 }
00263
00264 }
00265
00266
00270 echo "\n";
00271 $searched = (isset($original_search_str))
00272 ? htmlspecialchars($original_search_str)
00273 : '';
00274 if (empty($search_option)) {
00275 $search_option = 1;
00276 }
00277 ?>
00278 <!-- Display search form -->
00279 <a name="db_search"></a>
00280 <form method="post" action="db_search.php" name="db_search">
00281 <?php echo PMA_generate_common_hidden_inputs($db); ?>
00282
00283 <table border="0" cellpadding="3" cellspacing="0">
00284 <tr>
00285 <th class="tblHeaders" align="center" colspan="2"><?php echo $strSearchFormTitle; ?></th>
00286 </tr>
00287 <tr><td colspan="2"></td></tr>
00288 <tr>
00289 <td bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
00290 <?php echo $strSearchNeedle; ?> <br />
00291 </td>
00292 <td bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
00293 <input type="text" name="search_str" size="60" value="<?php echo $searched; ?>" />
00294 </td>
00295 </tr>
00296 <tr><td colspan="2"></td></tr><tr>
00297 <td align="right" valign="top" bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
00298 <?php echo $strSearchType; ?>
00299 </td>
00300 <td bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
00301 <input type="radio" id="search_option_1" name="search_option" value="1"<?php if ($search_option == 1) echo ' checked="checked"'; ?> /><label for="search_option_1"><?php echo $strSearchOption1; ?></label> *<br />
00302 <input type="radio" id="search_option_2" name="search_option" value="2"<?php if ($search_option == 2) echo ' checked="checked"'; ?> /><label for="search_option_2"><?php echo $strSearchOption2; ?></label> *<br />
00303 <input type="radio" id="search_option_3" name="search_option" value="3"<?php if ($search_option == 3) echo ' checked="checked"'; ?> /><label for="search_option_3"><?php echo $strSearchOption3; ?></label><br />
00304 <input type="radio" id="search_option_4" name="search_option" value="4"<?php if ($search_option == 4) echo ' checked="checked"'; ?> /><label for="search_option_4"><?php echo $strSearchOption4; ?></label><?php echo PMA_showMySQLDocu('Regexp', 'Regexp'); ?><br />
00305 <br />
00306 * <?php echo $strSplitWordsWithSpace . "\n"; ?>
00307 </td>
00308 </tr>
00309 <tr><td colspan="2"></td></tr>
00310 <tr>
00311 <td align="right" valign="top" bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
00312 <?php echo $strSearchInTables; ?>
00313 </td>
00314 <td rowspan="2" bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
00315 <?php
00316 $strDoSelectAll=' ';
00317 if ($num_tables > 1) {
00318 $i = 0;
00319
00320 echo ' <select name="table_select[]" size="6" multiple="multiple">' . "\n";
00321 while ($i < $num_tables) {
00322 if (!empty($unselectall)) {
00323 $is_selected = '';
00324 }
00325 else if ((isset($table_select) && PMA_isInto($tables[$i], $table_select) != -1)
00326 || (!empty($selectall))
00327 || (isset($onetable) && $onetable == $tables[$i])) {
00328 $is_selected = ' selected="selected"';
00329 }
00330 else {
00331 $is_selected = '';
00332 }
00333
00334 echo ' <option value="' . htmlspecialchars($tables[$i]) . '"' . $is_selected . '>' . htmlspecialchars($tables[$i]) . '</option>' . "\n";
00335 $i++;
00336 }
00337 echo ' </select>' . "\n";
00338 $strDoSelectAll = '<a href="db_search.php?' . $url_query . '&selectall=1#db_search"'
00339 . ' onclick="setSelectOptions(\'db_search\', \'table_select[]\', true); return false;">' . $strSelectAll . '</a>'
00340 . ' / '
00341 . '<a href="db_search.php?' . $url_query . '&unselectall=1#db_search"'
00342 . ' onclick="setSelectOptions(\'db_search\', \'table_select[]\', false); return false;">' . $strUnselectAll . '</a>';
00343 }
00344 else {
00345 echo "\n";
00346 echo ' ' . htmlspecialchars($tables[0]) . "\n";
00347 echo ' <input type="hidden" name="table" value="' . htmlspecialchars($tables[0]) . '" />' . "\n";
00348 }
00349
00350 echo"\n";
00351 ?>
00352 </td>
00353 </tr><tr><td align="right" valign="bottom" bgcolor="<?php echo $cfg['BgcolorOne']; ?>"><?php echo $strDoSelectAll; ?></td></tr>
00354 <tr><td colspan="2"></td>
00355 </tr><tr>
00356 <td colspan="2" align="right" class="tblHeaders"><input type="submit" name="submit_search" value="<?php echo $strGo; ?>" id="buttonGo" /></td>
00357 </tr>
00358 </table>
00359 </form>
00360
00361
00362 <?php
00366 echo "\n";
00367 require_once('./footer.inc.php');
00368 ?>