Merge commit '7a87b4df33301107c62a01ecb7ea73774381cd7f'
This commit is contained in:
commit
75e283ab9c
@ -59,25 +59,16 @@ if (empty($_REQUEST['criteriaSearchType'])
|
||||
unset($_REQUEST['submit_search']);
|
||||
} else {
|
||||
$criteriaSearchType = (int) $_REQUEST['criteriaSearchType'];
|
||||
$option_str = $searchTypes[$_REQUEST['criteriaSearchType']];
|
||||
$searchTypeDescription = $searchTypes[$_REQUEST['criteriaSearchType']];
|
||||
}
|
||||
|
||||
if (empty($_REQUEST['criteriaSearchString'])
|
||||
|| ! is_string($_REQUEST['criteriaSearchString'])
|
||||
) {
|
||||
$criteriaSearchString = '';
|
||||
unset($_REQUEST['submit_search']);
|
||||
$searched = '';
|
||||
} else {
|
||||
$searched = htmlspecialchars($_REQUEST['criteriaSearchString']);
|
||||
// For "as regular expression" (search option 4), we should not treat
|
||||
// this as an expression that contains a LIKE (second parameter of
|
||||
// sqlAddSlashes()).
|
||||
//
|
||||
// Usage example: If user is seaching for a literal $ in a regexp search,
|
||||
// he should enter \$ as the value.
|
||||
$criteriaSearchString = $common_functions->sqlAddSlashes(
|
||||
$_REQUEST['criteriaSearchString'], ($criteriaSearchType == 4 ? false : true)
|
||||
);
|
||||
$criteriaSearchString = $_REQUEST['criteriaSearchString'];
|
||||
}
|
||||
|
||||
$criteriaTables = array();
|
||||
@ -121,8 +112,8 @@ if ( $GLOBALS['is_ajax_request'] != true) {
|
||||
if (isset($_REQUEST['submit_search'])) {
|
||||
$response->addHTML(
|
||||
PMA_dbSearchGetSearchResults(
|
||||
$criteriaTables, $searched, $option_str,
|
||||
$criteriaSearchString, $criteriaSearchType,
|
||||
$criteriaTables, $searchTypeDescription,
|
||||
$criteriaSearchString, $criteriaSearchType,
|
||||
(! empty($criteriaColumnName) ? $criteriaColumnName : '')
|
||||
)
|
||||
);
|
||||
@ -140,8 +131,9 @@ if ($GLOBALS['is_ajax_request'] == true) {
|
||||
// Add search form
|
||||
$response->addHTML(
|
||||
PMA_dbSearchGetSelectionForm(
|
||||
$searched, $criteriaSearchType, $tables_names_only, $criteriaTables,
|
||||
$url_params, (! empty($criteriaColumnName) ? $criteriaColumnName : '')
|
||||
$criteriaSearchString, $criteriaSearchType, $tables_names_only,
|
||||
$criteriaTables, $url_params,
|
||||
(! empty($criteriaColumnName) ? $criteriaColumnName : '')
|
||||
)
|
||||
);
|
||||
?>
|
||||
|
||||
@ -14,7 +14,7 @@ if (! defined('PHPMYADMIN')) {
|
||||
*
|
||||
* @param string $table The table name
|
||||
* @param string $criteriaColumnName Restrict the search to this column
|
||||
* @param string $criteriaSearchString The string to search
|
||||
* @param string $criteriaSearchString The search word/phrase/regexp to be searched
|
||||
* @param integer $criteriaSearchType Type of search
|
||||
* (1 -> 1 word at least, 2 -> all words,
|
||||
* 3 -> exact string, 4 -> regexp)
|
||||
@ -33,24 +33,18 @@ if (! defined('PHPMYADMIN')) {
|
||||
function PMA_getSearchSqls($table, $criteriaColumnName, $criteriaSearchString,
|
||||
$criteriaSearchType
|
||||
) {
|
||||
$common_functions = PMA_CommonFunctions::getInstance();
|
||||
// Statement types
|
||||
$sqlstr_select = 'SELECT';
|
||||
$sqlstr_delete = 'DELETE';
|
||||
// Table to use
|
||||
$sqlstr_from = ' FROM '
|
||||
. PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($table);
|
||||
// Search words or pattern
|
||||
$search_words = (($criteriaSearchType > 2)
|
||||
? array($criteriaSearchString) : explode(' ', $criteriaSearchString));
|
||||
|
||||
$like_or_regex = (($criteriaSearchType == 4) ? 'REGEXP' : 'LIKE');
|
||||
$automatic_wildcard = (($criteriaSearchType < 3) ? '%' : '');
|
||||
|
||||
. $common_functions->backquote($GLOBALS['db']) . '.'
|
||||
. $common_functions->backquote($table);
|
||||
// Gets where clause for the query
|
||||
$where_clause = PMA_dbSearchGetWhereClause(
|
||||
$table, $search_words, $criteriaSearchType, $criteriaColumnName,
|
||||
$like_or_regex, $automatic_wildcard
|
||||
$table, $criteriaSearchString, $criteriaSearchType, $criteriaColumnName
|
||||
);
|
||||
|
||||
// Builds complete queries
|
||||
$sql['select_columns'] = $sqlstr_select . ' * ' . $sqlstr_from . $where_clause;
|
||||
// here, I think we need to still use the COUNT clause, even for
|
||||
@ -65,24 +59,35 @@ function PMA_getSearchSqls($table, $criteriaColumnName, $criteriaSearchString,
|
||||
/**
|
||||
* Provides where clause for bulding SQL query
|
||||
*
|
||||
* @param string $table the table name
|
||||
* @param integer $search_words Search words or pattern
|
||||
* @param integer $criteriaSearchType Type of search
|
||||
* (1 -> 1 word at least, 2 -> all words,
|
||||
* 3 -> exact string, 4 -> regexp)
|
||||
* @param string $criteriaColumnName Restrict the search to this column
|
||||
* @param string $like_or_regex Whether to use 'LIKE' or 'REGEXP'
|
||||
* @param string $automatic_wildcard Use automatic wildcard
|
||||
* @param string $table The table name
|
||||
* @param integer $criteriaSearchString The search word/phrase/regexp to be searched
|
||||
* @param integer $criteriaSearchType Type of search
|
||||
* (1 -> 1 word at least, 2 -> all words,
|
||||
* 3 -> exact string, 4 -> regexp)
|
||||
* @param string $criteriaColumnName Restrict the search to this column
|
||||
*
|
||||
* @return string The generated where clause
|
||||
*/
|
||||
function PMA_dbSearchGetWhereClause($table, $search_words, $criteriaSearchType,
|
||||
$criteriaColumnName, $like_or_regex, $automatic_wildcard
|
||||
function PMA_dbSearchGetWhereClause($table, $criteriaSearchString,
|
||||
$criteriaSearchType, $criteriaColumnName
|
||||
) {
|
||||
$common_functions = PMA_CommonFunctions::getInstance();
|
||||
$where_clause = '';
|
||||
// Columns to select
|
||||
$allColumns = PMA_DBI_get_columns($GLOBALS['db'], $table);
|
||||
$likeClauses = array();
|
||||
// Based on search type, decide like/regex & '%'/''
|
||||
$like_or_regex = (($criteriaSearchType == 4) ? 'REGEXP' : 'LIKE');
|
||||
$automatic_wildcard = (($criteriaSearchType < 3) ? '%' : '');
|
||||
// For "as regular expression" (search option 4), LIKE won't be used
|
||||
// Usage example: If user is seaching for a literal $ in a regexp search,
|
||||
// he should enter \$ as the value.
|
||||
$criteriaSearchString = $common_functions->sqlAddSlashes(
|
||||
$criteriaSearchString, ($criteriaSearchType == 4 ? false : true)
|
||||
);
|
||||
// Extract search words or pattern
|
||||
$search_words = (($criteriaSearchType > 2)
|
||||
? array($criteriaSearchString) : explode(' ', $criteriaSearchString));
|
||||
|
||||
foreach ($search_words as $search_word) {
|
||||
// Eliminates empty values
|
||||
@ -98,8 +103,9 @@ function PMA_dbSearchGetWhereClause($table, $search_words, $criteriaSearchType,
|
||||
) {
|
||||
// Drizzle has no CONVERT and all text columns are UTF-8
|
||||
$column = ((PMA_DRIZZLE)
|
||||
? PMA_backquote($column['Field'])
|
||||
: 'CONVERT(' . PMA_backquote($column['Field']) . ' USING utf8)');
|
||||
? $common_functions->backquote($column['Field'])
|
||||
: 'CONVERT(' . $common_functions->backquote($column['Field'])
|
||||
. ' USING utf8)');
|
||||
$likeClausesPerColumn[] = $column . ' ' . $like_or_regex . ' '
|
||||
. "'"
|
||||
. $automatic_wildcard . $search_word . $automatic_wildcard
|
||||
@ -110,14 +116,16 @@ function PMA_dbSearchGetWhereClause($table, $search_words, $criteriaSearchType,
|
||||
$likeClauses[] = implode(' OR ', $likeClausesPerColumn);
|
||||
}
|
||||
} // end for
|
||||
|
||||
// Use 'OR' if 'at least one word' is to be searched, else use 'AND'
|
||||
$implode_str = ($criteriaSearchType == 1 ? ' OR ' : ' AND ');
|
||||
if ( empty($likeClauses)) {
|
||||
// this could happen when the "inside column" does not exist
|
||||
// in any selected tables
|
||||
$where_clause = ' WHERE FALSE';
|
||||
} else {
|
||||
$where_clause = ' WHERE (' . implode(') ' . $implode_str . ' (', $likeClauses) . ')';
|
||||
$where_clause = ' WHERE ('
|
||||
. implode(') ' . $implode_str . ' (', $likeClauses)
|
||||
. ')';
|
||||
}
|
||||
return $where_clause;
|
||||
}
|
||||
@ -125,18 +133,17 @@ function PMA_dbSearchGetWhereClause($table, $search_words, $criteriaSearchType,
|
||||
/**
|
||||
* Displays database search results
|
||||
*
|
||||
* @param array $criteriaTables Tables on which search is to be performed
|
||||
* @param string $searched The search word/phrase/regexp
|
||||
* @param string $option_str Type of search
|
||||
* @param string $criteriaSearchString The string to search
|
||||
* @param integer $criteriaSearchType Type of search
|
||||
* (1 -> 1 word at least, 2 -> all words,
|
||||
* 3 -> exact string, 4 -> regexp)
|
||||
* @param string $criteriaColumnName Restrict the search to this column
|
||||
* @param array $criteriaTables Tables on which search is to be performed
|
||||
* @param string $searchTypeDescription Description for search type
|
||||
* @param string $criteriaSearchString The search word/phrase/regexp to be searched
|
||||
* @param integer $criteriaSearchType Type of search
|
||||
* (1 -> 1 word at least, 2 -> all words,
|
||||
* 3 -> exact string, 4 -> regexp)
|
||||
* @param string $criteriaColumnName Restrict the search to this column
|
||||
*
|
||||
* @return string HTML for search results
|
||||
*/
|
||||
function PMA_dbSearchGetSearchResults($criteriaTables, $searched, $option_str,
|
||||
function PMA_dbSearchGetSearchResults($criteriaTables, $searchTypeDescription,
|
||||
$criteriaSearchString, $criteriaSearchType, $criteriaColumnName = null
|
||||
) {
|
||||
$html_output = '';
|
||||
@ -146,7 +153,7 @@ function PMA_dbSearchGetSearchResults($criteriaTables, $searched, $option_str,
|
||||
. '<caption class="tblHeaders">'
|
||||
. sprintf(
|
||||
__('Search results for "<i>%s</i>" %s:'),
|
||||
$searched, $option_str
|
||||
htmlspecialchars($criteriaSearchString), $searchTypeDescription
|
||||
)
|
||||
. '</caption>';
|
||||
|
||||
@ -162,13 +169,14 @@ function PMA_dbSearchGetSearchResults($criteriaTables, $searched, $option_str,
|
||||
// Executes the "COUNT" statement
|
||||
$res_cnt = PMA_DBI_fetch_value($newsearchsqls['select_count']);
|
||||
$num_search_result_total += $res_cnt;
|
||||
// Gets the result row's HTML for a table
|
||||
$html_output .= PMA_dbSearchGetResultsRow(
|
||||
$each_table, $newsearchsqls, $odd_row
|
||||
);
|
||||
$odd_row = ! $odd_row;
|
||||
} // end for
|
||||
$html_output .= '</table>';
|
||||
|
||||
// Displays total number of matches
|
||||
if (count($criteriaTables) > 1) {
|
||||
$html_output .= '<p>';
|
||||
$html_output .= sprintf(
|
||||
@ -205,6 +213,7 @@ function PMA_dbSearchGetResultsRow($each_table, $newsearchsqls, $odd_row)
|
||||
$res_cnt = PMA_DBI_fetch_value($newsearchsqls['select_count']);
|
||||
// Start forming search results row
|
||||
$html_output = '<tr class="noclick ' . ($odd_row ? 'odd' : 'even') . '">';
|
||||
// Displays results count for a table
|
||||
$html_output .= '<td>';
|
||||
$html_output .= sprintf(
|
||||
_ngettext(
|
||||
@ -214,7 +223,7 @@ function PMA_dbSearchGetResultsRow($each_table, $newsearchsqls, $odd_row)
|
||||
$res_cnt, htmlspecialchars($each_table)
|
||||
);
|
||||
$html_output .= '</td>';
|
||||
|
||||
// Displays browse/delete link if result count > 0
|
||||
if ($res_cnt > 0) {
|
||||
$this_url_params['sql_query'] = $newsearchsqls['select_columns'];
|
||||
$browse_result_path = 'sql.php' . PMA_generate_common_url($this_url_params);
|
||||
@ -246,18 +255,19 @@ function PMA_dbSearchGetResultsRow($each_table, $newsearchsqls, $odd_row)
|
||||
/**
|
||||
* Provides the main search form's html
|
||||
*
|
||||
* @param string $searched Keyword/Regular expression to be searched
|
||||
* @param integer $criteriaSearchType Type of search (one word, phrase etc.)
|
||||
* @param array $tables_names_only Names of all tables
|
||||
* @param array $criteriaTables Tables on which search is to be performed
|
||||
* @param array $url_params URL parameters
|
||||
* @param string $criteriaColumnName Restrict the search to this column
|
||||
* @param string $criteriaSearchString Keyword/Regular expression earlier entered
|
||||
* @param integer $criteriaSearchType Type of search (one word, phrase etc.)
|
||||
* @param array $tables_names_only Names of all tables
|
||||
* @param array $criteriaTables Tables on which search is to be performed
|
||||
* @param array $url_params URL parameters
|
||||
* @param string $criteriaColumnName Restrict the search to this column
|
||||
*
|
||||
* @return string HTML for selection form
|
||||
*/
|
||||
function PMA_dbSearchGetSelectionForm($searched, $criteriaSearchType,
|
||||
function PMA_dbSearchGetSelectionForm($criteriaSearchString, $criteriaSearchType,
|
||||
$tables_names_only, $criteriaTables, $url_params, $criteriaColumnName = null
|
||||
) {
|
||||
$common_functions = PMA_CommonFunctions::getInstance();
|
||||
$html_output = '<a id="db_search"></a>';
|
||||
$html_output .= '<form id="db_search_form"'
|
||||
. ($GLOBALS['cfg']['AjaxEnable'] ? ' class="ajax"' : '')
|
||||
@ -272,22 +282,29 @@ function PMA_dbSearchGetSelectionForm($searched, $criteriaSearchType,
|
||||
$html_output .= '<td>' . __('Words or values to search for (wildcard: "%"):')
|
||||
. '</td>';
|
||||
$html_output .= '<td><input type="text" name="criteriaSearchString" size="60"'
|
||||
. ' value="' . $searched . '" /></td>';
|
||||
. ' value="' . htmlspecialchars($criteriaSearchString) . '" /></td>';
|
||||
$html_output .= '</tr>';
|
||||
// choices for types of search
|
||||
$html_output .= '<tr>';
|
||||
$html_output .= '<td class="right vtop">' . __('Find:') . '</td>';
|
||||
$html_output .= '<td>';
|
||||
$choices = array(
|
||||
'1' => __('at least one of the words') . PMA_showHint(__('Words are separated by a space character (" ").')),
|
||||
'2' => __('all words') . PMA_showHint(__('Words are separated by a space character (" ").')),
|
||||
'1' => __('at least one of the words')
|
||||
. $common_functions->showHint(
|
||||
__('Words are separated by a space character (" ").')
|
||||
),
|
||||
'2' => __('all words')
|
||||
. $common_functions->showHint(
|
||||
__('Words are separated by a space character (" ").')
|
||||
),
|
||||
'3' => __('the exact phrase'),
|
||||
'4' => __('as regular expression') . ' ' . PMA_showMySQLDocu('Regexp', 'Regexp')
|
||||
'4' => __('as regular expression')
|
||||
. ' ' . $common_functions->showMySQLDocu('Regexp', 'Regexp')
|
||||
);
|
||||
// 4th parameter set to true to add line breaks
|
||||
// 5th parameter set to false to avoid htmlspecialchars() escaping in the label
|
||||
// since we have some HTML in some labels
|
||||
$html_output .= PMA_getRadioFields(
|
||||
$html_output .= $common_functions->getRadioFields(
|
||||
'criteriaSearchType', $choices, $criteriaSearchType, true, false
|
||||
);
|
||||
$html_output .= '</td></tr>';
|
||||
@ -308,18 +325,27 @@ function PMA_dbSearchGetSelectionForm($searched, $criteriaSearchType,
|
||||
. '</option>';
|
||||
} // end for
|
||||
$html_output .= '</select>';
|
||||
$alter_select
|
||||
= '<a href="db_search.php' . PMA_generate_common_url(array_merge($url_params, array('selectall' => 1))) . '#db_search"'
|
||||
. ' onclick="setSelectOptions(\'db_search\', \'criteriaTables[]\', true); return false;">' . __('Select All') . '</a>'
|
||||
. ' / '
|
||||
. '<a href="db_search.php' . PMA_generate_common_url(array_merge($url_params, array('unselectall' => 1))) . '#db_search"'
|
||||
. ' onclick="setSelectOptions(\'db_search\', \'criteriaTables[]\', false); return false;">' . __('Unselect All') . '</a>';
|
||||
$html_output .= '</td></tr>';
|
||||
// Displays 'select all' and 'unselect all' links
|
||||
$alter_select = '<a href="db_search.php'
|
||||
. PMA_generate_common_url(
|
||||
array_merge($url_params, array('selectall' => 1))
|
||||
)
|
||||
. '#db_search" onclick="setSelectOptions(\'db_search\', \'criteriaTables[]\', true); return false;">'
|
||||
. __('Select All') . '</a> / ';
|
||||
$alter_select .= '<a href="db_search.php'
|
||||
. PMA_generate_common_url(
|
||||
array_merge($url_params, array('unselectall' => 1))
|
||||
)
|
||||
. '#db_search" onclick="setSelectOptions(\'db_search\', \'criteriaTables[]\', false); return false;">'
|
||||
. __('Unselect All') . '</a>';
|
||||
$html_output .= '<tr><td class="right vbottom">' . $alter_select . '</td></tr>';
|
||||
// Inputbox for column name entry
|
||||
$html_output .= '<tr>';
|
||||
$html_output .= '<td class="right">' . __('Inside column:') . '</td>';
|
||||
$html_output .= '<td><input type="text" name="criteriaColumnName" size="60"'
|
||||
. 'value="' . (! empty($criteriaColumnName) ? htmlspecialchars($criteriaColumnName) : '')
|
||||
. 'value="'
|
||||
. (! empty($criteriaColumnName) ? htmlspecialchars($criteriaColumnName) : '')
|
||||
. '" /></td>';
|
||||
$html_output .= '</tr>';
|
||||
$html_output .= '</table>';
|
||||
@ -348,8 +374,8 @@ function getResultDivs()
|
||||
$html_output .= '</div>';
|
||||
// div for browsing results
|
||||
$html_output .= '<div id="browse-results">';
|
||||
$html_output .= '<!-- this browse-results div is used to load the browse and delete'
|
||||
. ' results in the db search -->';
|
||||
$html_output .= '<!-- this browse-results div is used to load the browse'
|
||||
. ' and delete results in the db search -->';
|
||||
$html_output .= '</div>';
|
||||
$html_output .= '<br class="clearfloat" />';
|
||||
$html_output .= '<div id="sqlqueryform">';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user