This commit is contained in:
Sebastian Mendel
2005-12-12 18:56:31 +00:00
parent 39235bf003
commit aa7136b7a6
2 changed files with 114 additions and 177 deletions

View File

@@ -19,6 +19,7 @@ $Source$
- check magic_quotes only once in common.inc.php - check magic_quotes only once in common.inc.php
* css/phpmyadmin.css.php, tbl_properties_operations.php: * css/phpmyadmin.css.php, tbl_properties_operations.php:
styled table operations dialog styled table operations dialog
* db_search.php: revised
2005-12-11 Marc Delisle <lem9@users.sourceforge.net> 2005-12-11 Marc Delisle <lem9@users.sourceforge.net>
* libraries/tbl_properties_links.inc.php: bug #1375752, * libraries/tbl_properties_links.inc.php: bug #1375752,

View File

@@ -16,14 +16,12 @@ if (!$cfg['UseDbSearch']) {
PMA_mysqlDie($strAccessDenied, '', FALSE, $err_url); PMA_mysqlDie($strAccessDenied, '', FALSE, $err_url);
} // end if } // end if
$url_query .= '&amp;goto=db_search.php'; $url_query .= '&amp;goto=db_search.php';
$url_params['goto'] = 'db_search.php';
/** /**
* Get the list of tables from the current database * Get the list of tables from the current database
*/ */
$tables = PMA_DBI_get_tables($db); $tables = PMA_DBI_get_tables($GLOBALS['db']);
$num_tables = count($tables);
/** /**
* Displays top links * Displays top links
@@ -35,7 +33,7 @@ require('./libraries/db_details_links.inc.php');
/** /**
* 1. Main search form has been submitted * 1. Main search form has been submitted
*/ */
if (isset($submit_search)) { if (isset($_REQUEST['submit_search'])) {
/** /**
* Builds the SQL search query * Builds the SQL search query
@@ -127,139 +125,87 @@ if (isset($submit_search)) {
/** /**
* Displays the results * Displays the results
*/ */
if (!empty($search_str) && !empty($search_option)) { if (!empty($_REQUEST['search_str']) && !empty($_REQUEST['search_option'])) {
$original_search_str = $search_str; $original_search_str = $_REQUEST['search_str'];
$search_str = PMA_sqlAddslashes($search_str, TRUE); $search_str = PMA_sqlAddslashes($_REQUEST['search_str'], TRUE);
// Get the true string to display as option's comment // Get the true string to display as option's comment
switch ($search_option) { switch ($_REQUEST['search_option']) {
case 1: case 1:
$option_str = ' (' . $strSearchOption1 . ')'; $option_str = ' (' . $strSearchOption1 . ')';
$search_option = 1;
break; break;
case 2: case 2:
$option_str = ' (' . $strSearchOption2 . ')'; $option_str = ' (' . $strSearchOption2 . ')';
$search_option = 2;
break; break;
case 3: case 3:
$option_str = ' (' . $strSearchOption3 . ')'; $option_str = ' (' . $strSearchOption3 . ')';
$search_option = 3;
break; break;
case 4: case 4:
$option_str = ' (' . $strSearchOption4 . ')'; $option_str = ' (' . $strSearchOption4 . ')';
$search_option = 4;
break; break;
} // end switch } // end switch
// If $table is defined or if there is only one table in $table_select $this_url_params = array(
// set $onetable to the table's name (display is different if there is 'db' => $GLOBALS['db'],
// only one table). 'goto' => 'db_details.php',
// 'pos' => 0,
// Recall: 'is_js_confirmed' => 0,
// $tables is an array with all tables in database $db );
// $num_tables is the size of $tables
if (isset($table)) {
$onetable = $table;
}
else if (isset($table_select)) {
$num_selectedtables = count($table_select);
if ($num_selectedtables == 1) {
$onetable = $table_select[0];
}
}
else if ($num_tables == 1) {
$onetable = $tables[0];
}
else {
for ($i = 0; $i < $num_tables; $i++) {
$table_select[] = $tables[$i];
}
$num_selectedtables = $num_tables;
} // end if... else if... else
?>
<br />
<?php // Displays search string
$url_sql_query = PMA_generate_common_url($db) echo '<br />' . "\n"
. '&amp;goto=db_details.php' .'<table class="data">' . "\n"
. '&amp;pos=0' .'<caption class="tblHeaders">' . "\n"
. '&amp;is_js_confirmed=0'; .sprintf($strSearchResultsFor,
htmlspecialchars($original_search_str), $option_str) . "\n"
.'</caption>' . "\n";
// Only one table defined in an variable $onetable $num_search_result_total = 0;
if (isset($onetable)) { $odd_row = true;
// Displays search string
echo ' ' . sprintf($strSearchResultsFor, htmlspecialchars($original_search_str), $option_str) . "\n";
echo ' <br />' . "\n";
foreach ( $_REQUEST['table_select'] as $each_table ) {
// Gets the SQL statements // Gets the SQL statements
$newsearchsqls = PMA_getSearchSqls($onetable, $search_str, $search_option); $newsearchsqls = PMA_getSearchSqls($each_table,
$search_str, $search_option);
// Executes the "COUNT" statement // Executes the "COUNT" statement
$res = PMA_DBI_query($newsearchsqls['select_count']); $res_cnt = PMA_DBI_fetch_value($newsearchsqls['select_count']);
$res_cnt = PMA_DBI_fetch_assoc($res); $num_search_result_total += $res_cnt;
$res_cnt = $res_cnt['count'];
PMA_DBI_free_result($res);
$num_search_result_total = $res_cnt;
echo ' <!-- Search results in table ' . $onetable . ' (' . $res_cnt . ') -->' . "\n" echo '<tr class="' . ( $odd_row ? 'odd' : 'even' ) . '">'
. ' <br />' . "\n" .'<td>' . sprintf($strNumSearchResultsInTable, $res_cnt,
. ' <table><tr><td>' . sprintf($strNumSearchResultsInTable, $res_cnt, htmlspecialchars($onetable)) . "</td>\n"; htmlspecialchars($each_table)) . "</td>\n";
if ($res_cnt > 0) { if ($res_cnt > 0) {
echo '<td>' . PMA_linkOrButton('sql.php?' . $url_sql_query $this_url_params['sql_query'] = $newsearchsqls['select_fields'];
. '&amp;sql_query=' .urlencode($newsearchsqls['select_fields']), echo '<td>' . PMA_linkOrButton(
$strBrowse, '') . "</td>\n"; 'sql.php' . PMA_generate_common_url($this_url_params),
$strBrowse, '') . "</td>\n";
echo '<td>' . PMA_linkOrButton('sql.php?' . $url_sql_query $this_url_params['sql_query'] = $newsearchsqls['delete'];
. '&amp;sql_query=' .urlencode($newsearchsqls['delete']), echo '<td>' . PMA_linkOrButton(
$strDelete, $newsearchsqls['delete']) . "</td>\n"; 'sql.php' . PMA_generate_common_url($this_url_params),
$strDelete, $newsearchsqls['delete']) . "</td>\n";
} // end if } else {
echo '</tr></table>' . "\n"; echo '<td>&nbsp;</td>' . "\n"
} // end only one table .'<td>&nbsp;</td>' . "\n";
}// end if else
$odd_row = ! $odd_row;
echo '</tr>' . "\n";
} // end for
// Several tables defined in the array $table_select echo '</table>' . "\n";
else if (isset($table_select)) {
// Displays search string
echo ' ' . sprintf($strSearchResultsFor, htmlspecialchars($original_search_str), $option_str) . "\n";
echo ' <ul>' . "\n";
$num_search_result_total = 0; if ( count($_REQUEST['table_select']) > 1 ) {
for ($i = 0; $i < $num_selectedtables; $i++) { echo '<p>' . sprintf($strNumSearchResultsTotal,
// Gets the SQL statements $num_search_result_total) . '</p>' . "\n";
$newsearchsqls = PMA_getSearchSqls($table_select[$i], $search_str, $search_option); }
// Executes the "COUNT" statement
$res = PMA_DBI_query($newsearchsqls['select_count']);
$res_cnt = PMA_DBI_fetch_assoc($res);
$res_cnt = $res_cnt['count'];
PMA_DBI_free_result($res);
unset($res);
$num_search_result_total += $res_cnt;
echo ' <!-- Search results in table ' . $table_select[$i] . ' (' . $res_cnt . ') -->' . "\n"
. ' <li>' . "\n"
. ' <table><tr><td>' . sprintf($strNumSearchResultsInTable, $res_cnt, htmlspecialchars($table_select[$i])) . "</td>\n";
if ($res_cnt > 0) {
echo '<td>' . PMA_linkOrButton('sql.php?' . $url_sql_query
. '&amp;sql_query=' .urlencode($newsearchsqls['select_fields']),
$strBrowse, '') . "</td>\n";
echo '<td>' . PMA_linkOrButton('sql.php?' . $url_sql_query
. '&amp;sql_query=' .urlencode($newsearchsqls['delete']),
$strDelete, $newsearchsqls['delete']) . "</td>\n";
} // end if
echo ' </tr></table></li>' . "\n";
} // end for
echo ' </ul>' . "\n";
echo ' <p>' . sprintf($strNumSearchResultsTotal, $num_search_result_total) . '</p>' . "\n";
} // end several tables
echo "\n";
?>
<hr width="100%">
<?php
} // end if (!empty($search_str) && !empty($search_option)) } // end if (!empty($search_str) && !empty($search_option))
} // end 1. } // end 1.
@@ -276,87 +222,77 @@ if (empty($search_option)) {
$search_option = 1; $search_option = 1;
} }
?> ?>
<!-- Display search form -->
<a name="db_search"></a> <a name="db_search"></a>
<form method="post" action="db_search.php" name="db_search"> <form method="post" action="db_search.php" name="db_search">
<?php echo PMA_generate_common_hidden_inputs($db); ?> <?php echo PMA_generate_common_hidden_inputs($GLOBALS['db']); ?>
<fieldset>
<legend><?php echo $strSearchFormTitle; ?></legend>
<table border="0" cellpadding="3" cellspacing="0"> <table class="formlayout">
<tr> <tr><td><?php echo $strSearchNeedle; ?></td>
<th class="tblHeaders" align="center" colspan="2"><?php echo $strSearchFormTitle; ?></th> <td><input type="text" name="search_str" size="60"
value="<?php echo $searched; ?>" /></td>
</tr> </tr>
<tr><td colspan="2"></td></tr> <tr><td align="right" valign="top">
<tr> <?php echo $strSearchType; ?></td>
<td bgcolor="<?php echo $cfg['BgcolorOne']; ?>"> <td><input type="radio" id="search_option_1" name="search_option"
<?php echo $strSearchNeedle; ?>&nbsp;<br /> value="1"<?php if ($search_option == 1) echo ' checked="checked"'; ?> />
</td> <label for="search_option_1">
<td bgcolor="<?php echo $cfg['BgcolorOne']; ?>"> <?php echo $strSearchOption1; ?></label><sup>1</sup><br />
<input type="text" name="search_str" size="60" value="<?php echo $searched; ?>" /> <input type="radio" id="search_option_2" name="search_option"
</td> value="2"<?php if ($search_option == 2) echo ' checked="checked"'; ?> />
</tr> <label for="search_option_2">
<tr><td colspan="2"></td></tr><tr> <?php echo $strSearchOption2; ?></label><sup>1</sup><br />
<td align="right" valign="top" bgcolor="<?php echo $cfg['BgcolorOne']; ?>"> <input type="radio" id="search_option_3" name="search_option"
<?php echo $strSearchType; ?>&nbsp; value="3"<?php if ($search_option == 3) echo ' checked="checked"'; ?> />
</td> <label for="search_option_3">
<td bgcolor="<?php echo $cfg['BgcolorOne']; ?>"> <?php echo $strSearchOption3; ?></label><br />
<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>&nbsp;*<br /> <input type="radio" id="search_option_4" name="search_option"
<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>&nbsp;*<br /> value="4"<?php if ($search_option == 4) echo ' checked="checked"'; ?> />
<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 /> <label for="search_option_4">
<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 /> <?php echo $strSearchOption4; ?></label>
<?php echo PMA_showMySQLDocu('Regexp', 'Regexp'); ?><br />
<br /> <br />
*&nbsp;<?php echo $strSplitWordsWithSpace . "\n"; ?> <sup>1</sup><?php echo $strSplitWordsWithSpace; ?></td>
</td>
</tr> </tr>
<tr><td colspan="2"></td></tr> <tr><td align="right" valign="top">
<tr> <?php echo $strSearchInTables; ?></td>
<td align="right" valign="top" bgcolor="<?php echo $cfg['BgcolorOne']; ?>"> <td rowspan="2">
<?php echo $strSearchInTables; ?>&nbsp;
</td>
<td rowspan="2" bgcolor="<?php echo $cfg['BgcolorOne']; ?>">
<?php <?php
$strDoSelectAll='&nbsp;'; echo ' <select name="table_select[]" size="6" multiple="multiple">' . "\n";
if ($num_tables > 1) { foreach ( $tables as $each_table ) {
$i = 0; if ( isset($_REQUEST['unselectall'])) {
$is_selected = '';
} elseif ( ! isset($_REQUEST['table_select'])
|| in_array($each_table, $_REQUEST['table_select'])
|| isset($_REQUEST['selectall']) ) {
$is_selected = ' selected="selected"';
} else {
$is_selected = '';
}
echo ' <select name="table_select[]" size="6" multiple="multiple">' . "\n"; echo ' <option value="' . htmlspecialchars($each_table) . '"'
while ($i < $num_tables) { . $is_selected . '>'
if (!empty($unselectall)) { . htmlspecialchars($each_table) . '</option>' . "\n";
$is_selected = ''; } // end while
} echo ' </select>' . "\n";
elseif ( ( isset($table_select) && in_array($tables[$i], $table_select) ) $strDoSelectAll = '<a href="db_search.php?' . $url_query . '&amp;selectall=1#db_search"'
|| ! empty($selectall) . ' onclick="setSelectOptions(\'db_search\', \'table_select[]\', true); return false;">' . $strSelectAll . '</a>'
|| ( isset($onetable) && $onetable == $tables[$i]) ) { . '&nbsp;/&nbsp;'
$is_selected = ' selected="selected"'; . '<a href="db_search.php?' . $url_query . '&amp;unselectall=1#db_search"'
} . ' onclick="setSelectOptions(\'db_search\', \'table_select[]\', false); return false;">' . $strUnselectAll . '</a>';
else {
$is_selected = '';
}
echo ' <option value="' . htmlspecialchars($tables[$i]) . '"' . $is_selected . '>' . htmlspecialchars($tables[$i]) . '</option>' . "\n";
$i++;
} // end while
echo ' </select>' . "\n";
$strDoSelectAll = '<a href="db_search.php?' . $url_query . '&amp;selectall=1#db_search"'
. ' onclick="setSelectOptions(\'db_search\', \'table_select[]\', true); return false;">' . $strSelectAll . '</a>'
. '&nbsp;/&nbsp;'
. '<a href="db_search.php?' . $url_query . '&amp;unselectall=1#db_search"'
. ' onclick="setSelectOptions(\'db_search\', \'table_select[]\', false); return false;">' . $strUnselectAll . '</a>';
}
else {
echo "\n";
echo ' ' . htmlspecialchars($tables[0]) . "\n";
echo ' <input type="hidden" name="table" value="' . htmlspecialchars($tables[0]) . '" />' . "\n";
} // end if... else...
echo"\n";
?> ?>
</td> </td>
</tr><tr><td align="right" valign="bottom" bgcolor="<?php echo $cfg['BgcolorOne']; ?>"><?php echo $strDoSelectAll; ?></td></tr> </tr>
<tr><td colspan="2"></td> <tr><td align="right" valign="bottom">
</tr><tr> <?php echo $strDoSelectAll; ?></td></tr>
<td colspan="2" align="right" class="tblHeaders"><input type="submit" name="submit_search" value="<?php echo $strGo; ?>" id="buttonGo" /></td>
</tr> </tr>
</table> </table>
</fieldset>
<fieldset class="tblFooters">
<input type="submit" name="submit_search" value="<?php echo $strGo; ?>"
id="buttonGo" />
</fieldset>
</form> </form>