Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
e93d8c9c11
@ -7,8 +7,7 @@
|
||||
*/
|
||||
namespace PhpMyAdmin\Database;
|
||||
|
||||
use PhpMyAdmin\Sanitize;
|
||||
use PhpMyAdmin\Url;
|
||||
use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Util;
|
||||
|
||||
/**
|
||||
@ -24,56 +23,63 @@ class Search
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
private $_db;
|
||||
private $db;
|
||||
|
||||
/**
|
||||
* Table Names
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
private $_tables_names_only;
|
||||
private $tablesNamesOnly;
|
||||
|
||||
/**
|
||||
* Type of search
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
private $_searchTypes;
|
||||
private $searchTypes;
|
||||
|
||||
/**
|
||||
* Already set search type
|
||||
*
|
||||
* @access private
|
||||
* @var integer
|
||||
*/
|
||||
private $_criteriaSearchType;
|
||||
private $criteriaSearchType;
|
||||
|
||||
/**
|
||||
* Already set search type's description
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
private $_searchTypeDescription;
|
||||
private $searchTypeDescription;
|
||||
|
||||
/**
|
||||
* Search string/regexp
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
private $_criteriaSearchString;
|
||||
private $criteriaSearchString;
|
||||
|
||||
/**
|
||||
* Criteria Tables to search in
|
||||
*
|
||||
* @access private
|
||||
* @var array
|
||||
*/
|
||||
private $_criteriaTables;
|
||||
private $criteriaTables;
|
||||
|
||||
/**
|
||||
* Restrict the search to this column
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
private $_criteriaColumnName;
|
||||
private $criteriaColumnName;
|
||||
|
||||
/**
|
||||
* Public Constructor
|
||||
@ -82,8 +88,8 @@ class Search
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->_db = $db;
|
||||
$this->_searchTypes = array(
|
||||
$this->db = $db;
|
||||
$this->searchTypes = array(
|
||||
'1' => __('at least one of the words'),
|
||||
'2' => __('all of the words'),
|
||||
'3' => __('the exact phrase as substring'),
|
||||
@ -91,7 +97,7 @@ class Search
|
||||
'5' => __('as regular expression'),
|
||||
);
|
||||
// Sets criteria parameters
|
||||
$this->_setSearchParams();
|
||||
$this->setSearchParams();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -99,51 +105,51 @@ class Search
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _setSearchParams()
|
||||
private function setSearchParams()
|
||||
{
|
||||
$this->_tables_names_only = $GLOBALS['dbi']->getTables($this->_db);
|
||||
$this->tablesNamesOnly = $GLOBALS['dbi']->getTables($this->db);
|
||||
|
||||
if (empty($_REQUEST['criteriaSearchType'])
|
||||
|| ! is_string($_REQUEST['criteriaSearchType'])
|
||||
|| ! array_key_exists(
|
||||
$_REQUEST['criteriaSearchType'],
|
||||
$this->_searchTypes
|
||||
$this->searchTypes
|
||||
)
|
||||
) {
|
||||
$this->_criteriaSearchType = 1;
|
||||
$this->criteriaSearchType = 1;
|
||||
unset($_REQUEST['submit_search']);
|
||||
} else {
|
||||
$this->_criteriaSearchType = (int) $_REQUEST['criteriaSearchType'];
|
||||
$this->_searchTypeDescription
|
||||
= $this->_searchTypes[$_REQUEST['criteriaSearchType']];
|
||||
$this->criteriaSearchType = (int) $_REQUEST['criteriaSearchType'];
|
||||
$this->searchTypeDescription
|
||||
= $this->searchTypes[$_REQUEST['criteriaSearchType']];
|
||||
}
|
||||
|
||||
if (empty($_REQUEST['criteriaSearchString'])
|
||||
|| ! is_string($_REQUEST['criteriaSearchString'])
|
||||
) {
|
||||
$this->_criteriaSearchString = '';
|
||||
$this->criteriaSearchString = '';
|
||||
unset($_REQUEST['submit_search']);
|
||||
} else {
|
||||
$this->_criteriaSearchString = $_REQUEST['criteriaSearchString'];
|
||||
$this->criteriaSearchString = $_REQUEST['criteriaSearchString'];
|
||||
}
|
||||
|
||||
$this->_criteriaTables = array();
|
||||
$this->criteriaTables = array();
|
||||
if (empty($_REQUEST['criteriaTables'])
|
||||
|| ! is_array($_REQUEST['criteriaTables'])
|
||||
) {
|
||||
unset($_REQUEST['submit_search']);
|
||||
} else {
|
||||
$this->_criteriaTables = array_intersect(
|
||||
$_REQUEST['criteriaTables'], $this->_tables_names_only
|
||||
$this->criteriaTables = array_intersect(
|
||||
$_REQUEST['criteriaTables'], $this->tablesNamesOnly
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($_REQUEST['criteriaColumnName'])
|
||||
|| ! is_string($_REQUEST['criteriaColumnName'])
|
||||
) {
|
||||
unset($this->_criteriaColumnName);
|
||||
unset($this->criteriaColumnName);
|
||||
} else {
|
||||
$this->_criteriaColumnName = $GLOBALS['dbi']->escapeString(
|
||||
$this->criteriaColumnName = $GLOBALS['dbi']->escapeString(
|
||||
$_REQUEST['criteriaColumnName']
|
||||
);
|
||||
}
|
||||
@ -165,7 +171,7 @@ class Search
|
||||
* count
|
||||
* strlen
|
||||
*/
|
||||
private function _getSearchSqls($table)
|
||||
private function getSearchSqls($table)
|
||||
{
|
||||
// Statement types
|
||||
$sqlstr_select = 'SELECT';
|
||||
@ -175,7 +181,7 @@ class Search
|
||||
. Util::backquote($GLOBALS['db']) . '.'
|
||||
. Util::backquote($table);
|
||||
// Gets where clause for the query
|
||||
$where_clause = $this->_getWhereClause($table);
|
||||
$where_clause = $this->getWhereClause($table);
|
||||
// Builds complete queries
|
||||
$sql = array();
|
||||
$sql['select_columns'] = $sqlstr_select . ' * ' . $sqlstr_from
|
||||
@ -196,22 +202,22 @@ class Search
|
||||
*
|
||||
* @return string The generated where clause
|
||||
*/
|
||||
private function _getWhereClause($table)
|
||||
private function getWhereClause($table)
|
||||
{
|
||||
// Columns to select
|
||||
$allColumns = $GLOBALS['dbi']->getColumns($GLOBALS['db'], $table);
|
||||
$likeClauses = array();
|
||||
// Based on search type, decide like/regex & '%'/''
|
||||
$like_or_regex = (($this->_criteriaSearchType == 5) ? 'REGEXP' : 'LIKE');
|
||||
$automatic_wildcard = (($this->_criteriaSearchType < 4) ? '%' : '');
|
||||
$like_or_regex = (($this->criteriaSearchType == 5) ? 'REGEXP' : 'LIKE');
|
||||
$automatic_wildcard = (($this->criteriaSearchType < 4) ? '%' : '');
|
||||
// For "as regular expression" (search option 5), LIKE won't be used
|
||||
// Usage example: If user is searching for a literal $ in a regexp search,
|
||||
// he should enter \$ as the value.
|
||||
$criteriaSearchStringEscaped = $GLOBALS['dbi']->escapeString(
|
||||
$this->_criteriaSearchString
|
||||
$this->criteriaSearchString
|
||||
);
|
||||
// Extract search words or pattern
|
||||
$search_words = (($this->_criteriaSearchType > 2)
|
||||
$search_words = (($this->criteriaSearchType > 2)
|
||||
? array($criteriaSearchStringEscaped)
|
||||
: explode(' ', $criteriaSearchStringEscaped));
|
||||
|
||||
@ -223,9 +229,9 @@ class Search
|
||||
$likeClausesPerColumn = array();
|
||||
// for each column in the table
|
||||
foreach ($allColumns as $column) {
|
||||
if (! isset($this->_criteriaColumnName)
|
||||
|| strlen($this->_criteriaColumnName) === 0
|
||||
|| $column['Field'] == $this->_criteriaColumnName
|
||||
if (! isset($this->criteriaColumnName)
|
||||
|| strlen($this->criteriaColumnName) === 0
|
||||
|| $column['Field'] == $this->criteriaColumnName
|
||||
) {
|
||||
$column = 'CONVERT(' . Util::backquote($column['Field'])
|
||||
. ' USING utf8)';
|
||||
@ -240,7 +246,7 @@ class Search
|
||||
}
|
||||
} // end for
|
||||
// Use 'OR' if 'at least one word' is to be searched, else use 'AND'
|
||||
$implode_str = ($this->_criteriaSearchType == 1 ? ' OR ' : ' AND ');
|
||||
$implode_str = ($this->criteriaSearchType == 1 ? ' OR ' : ' AND ');
|
||||
if (empty($likeClauses)) {
|
||||
// this could happen when the "inside column" does not exist
|
||||
// in any selected tables
|
||||
@ -260,104 +266,33 @@ class Search
|
||||
*/
|
||||
public function getSearchResults()
|
||||
{
|
||||
$html_output = '';
|
||||
// Displays search string
|
||||
$html_output .= '<br />'
|
||||
. '<table class="data">'
|
||||
. '<caption class="tblHeaders">'
|
||||
. sprintf(
|
||||
__('Search results for "<i>%s</i>" %s:'),
|
||||
htmlspecialchars($this->_criteriaSearchString),
|
||||
$this->_searchTypeDescription
|
||||
)
|
||||
. '</caption>';
|
||||
|
||||
$num_search_result_total = 0;
|
||||
$resultTotal = 0;
|
||||
$rows = [];
|
||||
// For each table selected as search criteria
|
||||
foreach ($this->_criteriaTables as $each_table) {
|
||||
foreach ($this->criteriaTables as $eachTable) {
|
||||
// Gets the SQL statements
|
||||
$newsearchsqls = $this->_getSearchSqls($each_table);
|
||||
$newSearchSqls = $this->getSearchSqls($eachTable);
|
||||
// Executes the "COUNT" statement
|
||||
$res_cnt = intval($GLOBALS['dbi']->fetchValue($newsearchsqls['select_count']));
|
||||
$num_search_result_total += $res_cnt;
|
||||
$resultCount = intval($GLOBALS['dbi']->fetchValue(
|
||||
$newSearchSqls['select_count']
|
||||
));
|
||||
$resultTotal += $resultCount;
|
||||
// Gets the result row's HTML for a table
|
||||
$html_output .= $this->_getResultsRow(
|
||||
$each_table, $newsearchsqls, $res_cnt
|
||||
);
|
||||
} // end for
|
||||
$html_output .= '</table>';
|
||||
// Displays total number of matches
|
||||
if (count($this->_criteriaTables) > 1) {
|
||||
$html_output .= '<p>';
|
||||
$html_output .= sprintf(
|
||||
_ngettext(
|
||||
'<b>Total:</b> <i>%s</i> match',
|
||||
'<b>Total:</b> <i>%s</i> matches',
|
||||
$num_search_result_total
|
||||
),
|
||||
$num_search_result_total
|
||||
);
|
||||
$html_output .= '</p>';
|
||||
$rows[] = [
|
||||
'table' => $eachTable,
|
||||
'new_search_sqls' => $newSearchSqls,
|
||||
'result_count' => $resultCount,
|
||||
];
|
||||
}
|
||||
return $html_output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides search results row with browse/delete links.
|
||||
* (for a table)
|
||||
*
|
||||
* @param string $each_table One of the tables on which search was performed
|
||||
* @param array $newsearchsqls Contains SQL queries
|
||||
* @param integer $res_cnt Number of results found
|
||||
*
|
||||
* @return string HTML row
|
||||
*/
|
||||
private function _getResultsRow($each_table, array $newsearchsqls, $res_cnt)
|
||||
{
|
||||
$this_url_params = array(
|
||||
'db' => $GLOBALS['db'],
|
||||
'table' => $each_table,
|
||||
'goto' => 'db_sql.php',
|
||||
'pos' => 0,
|
||||
'is_js_confirmed' => 0,
|
||||
);
|
||||
// Start forming search results row
|
||||
$html_output = '<tr class="noclick">';
|
||||
// Displays results count for a table
|
||||
$html_output .= '<td>';
|
||||
$html_output .= sprintf(
|
||||
_ngettext(
|
||||
'%1$s match in <strong>%2$s</strong>',
|
||||
'%1$s matches in <strong>%2$s</strong>', $res_cnt
|
||||
),
|
||||
$res_cnt, htmlspecialchars($each_table)
|
||||
);
|
||||
$html_output .= '</td>';
|
||||
// Displays browse/delete link if result count > 0
|
||||
if ($res_cnt > 0) {
|
||||
$this_url_params['db'] = htmlspecialchars($GLOBALS['db']);
|
||||
$this_url_params['table'] = htmlspecialchars($each_table);
|
||||
$browse_result_path = 'sql.php' . Url::getCommon($this_url_params);
|
||||
$html_output .= '<td><a name="browse_search" '
|
||||
. ' class="ajax browse_results" href="'
|
||||
. $browse_result_path . '" '
|
||||
. 'data-browse-sql="'
|
||||
. htmlspecialchars($newsearchsqls['select_columns']). '" '
|
||||
. 'data-table-name="' . htmlspecialchars($each_table) . '" >'
|
||||
. __('Browse') . '</a></td>';
|
||||
|
||||
$delete_result_path = $browse_result_path;
|
||||
$html_output .= '<td><a name="delete_search" class="ajax delete_results"'
|
||||
. ' href="' . $delete_result_path . '"'
|
||||
. ' data-delete-sql="' . htmlspecialchars($newsearchsqls['delete']) . '"'
|
||||
. ' data-table-name="' . htmlspecialchars($each_table) . '" >'
|
||||
. __('Delete') . '</a></td>';
|
||||
} else {
|
||||
$html_output .= '<td> </td>'
|
||||
. '<td> </td>';
|
||||
}// end if else
|
||||
$html_output .= '</tr>';
|
||||
return $html_output;
|
||||
return Template::get('database/search/results')->render([
|
||||
'db' => $this->db,
|
||||
'rows' => $rows,
|
||||
'result_total' => $resultTotal,
|
||||
'criteria_tables' => $this->criteriaTables,
|
||||
'criteria_search_string' => $this->criteriaSearchString,
|
||||
'search_type_description' => $this->searchTypeDescription,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -367,100 +302,29 @@ class Search
|
||||
*/
|
||||
public function getSelectionForm()
|
||||
{
|
||||
$html_output = '<a id="db_search"></a>';
|
||||
$html_output .= '<form id="db_search_form"'
|
||||
. ' class="ajax lock-page"'
|
||||
. ' method="post" action="db_search.php" name="db_search">';
|
||||
$html_output .= Url::getHiddenInputs($GLOBALS['db']);
|
||||
$html_output .= '<fieldset>';
|
||||
// set legend caption
|
||||
$html_output .= '<legend>' . __('Search in database') . '</legend>';
|
||||
$html_output .= '<table class="formlayout all100">';
|
||||
// inputbox for search phrase
|
||||
$html_output .= '<tr>';
|
||||
$html_output .= '<td class="right">' . __('Words or values to search for (wildcard: "%"):')
|
||||
. '</td>';
|
||||
$html_output .= '<td><input type="text"'
|
||||
. ' name="criteriaSearchString" class="all85"'
|
||||
. ' value="' . htmlspecialchars($this->_criteriaSearchString) . '" />';
|
||||
$html_output .= '</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' => $this->_searchTypes[1] . ' '
|
||||
'1' => $this->searchTypes[1] . ' '
|
||||
. Util::showHint(
|
||||
__('Words are separated by a space character (" ").')
|
||||
),
|
||||
'2' => $this->_searchTypes[2] . ' '
|
||||
'2' => $this->searchTypes[2] . ' '
|
||||
. Util::showHint(
|
||||
__('Words are separated by a space character (" ").')
|
||||
),
|
||||
'3' => $this->_searchTypes[3],
|
||||
'4' => $this->_searchTypes[4],
|
||||
'5' => $this->_searchTypes[5] . ' '
|
||||
. Util::showMySQLDocu('Regexp')
|
||||
'3' => $this->searchTypes[3],
|
||||
'4' => $this->searchTypes[4],
|
||||
'5' => $this->searchTypes[5] . ' ' . Util::showMySQLDocu('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 .= Util::getRadioFields(
|
||||
'criteriaSearchType', $choices, $this->_criteriaSearchType, true, false
|
||||
);
|
||||
$html_output .= '</td></tr>';
|
||||
// displays table names as select options
|
||||
$html_output .= '<tr>';
|
||||
$html_output .= '<td class="right vtop">' . __('Inside tables:') . '</td>';
|
||||
$html_output .= '<td rowspan="2">';
|
||||
$html_output .= '<select name="criteriaTables[]" class="all85"'
|
||||
. ' multiple="multiple">';
|
||||
foreach ($this->_tables_names_only as $each_table) {
|
||||
if (in_array($each_table, $this->_criteriaTables)) {
|
||||
$is_selected = ' selected="selected"';
|
||||
} else {
|
||||
$is_selected = '';
|
||||
}
|
||||
$html_output .= '<option value="' . htmlspecialchars($each_table) . '"'
|
||||
. $is_selected . '>'
|
||||
. str_replace(' ', ' ', htmlspecialchars($each_table))
|
||||
. '</option>';
|
||||
} // end for
|
||||
$html_output .= '</select>';
|
||||
$html_output .= '</td></tr>';
|
||||
// Displays 'select all' and 'unselect all' links
|
||||
$alter_select = '<a href="#" '
|
||||
. 'onclick="setSelectOptions(\'db_search\','
|
||||
. ' \'criteriaTables[]\', true); return false;">'
|
||||
. __('Select all') . '</a> / ';
|
||||
$alter_select .= '<a href="#" '
|
||||
. '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" class="all85"'
|
||||
. 'value="'
|
||||
. (! empty($this->_criteriaColumnName)
|
||||
? htmlspecialchars($this->_criteriaColumnName)
|
||||
: '')
|
||||
. '" /></td>';
|
||||
$html_output .= '</tr>';
|
||||
$html_output .= '</table>';
|
||||
$html_output .= '</fieldset>';
|
||||
$html_output .= '<fieldset class="tblFooters">';
|
||||
$html_output .= '<input type="submit" name="submit_search" value="'
|
||||
. __('Go') . '" id="buttonGo" />';
|
||||
$html_output .= '</fieldset>';
|
||||
$html_output .= '</form>';
|
||||
$html_output .= '<div id="togglesearchformdiv">'
|
||||
. '<a id="togglesearchformlink"></a></div>';
|
||||
|
||||
return $html_output;
|
||||
return Template::get('database/search/selection_form')->render([
|
||||
'db' => $this->db,
|
||||
'choices' => $choices,
|
||||
'criteria_search_string' => $this->criteriaSearchString,
|
||||
'criteria_search_type' => $this->criteriaSearchType,
|
||||
'criteria_tables' => $this->criteriaTables,
|
||||
'tables_names_only' => $this->tablesNamesOnly,
|
||||
'criteria_column_name' => isset($this->criteriaColumnName)
|
||||
? $this->criteriaColumnName : null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -470,23 +334,6 @@ class Search
|
||||
*/
|
||||
public function getResultDivs()
|
||||
{
|
||||
$html_output = '<!-- These two table-image and table-link elements display'
|
||||
. ' the table name in browse search results -->';
|
||||
$html_output .= '<div id="table-info">';
|
||||
$html_output .= '<a class="item" id="table-link" ></a>';
|
||||
$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 .= '</div>';
|
||||
$html_output .= '<br class="clearfloat" />';
|
||||
$html_output .= '<div id="sqlqueryform">';
|
||||
$html_output .= '<!-- this sqlqueryform div is used to load the delete'
|
||||
. ' form in the db search -->';
|
||||
$html_output .= '</div>';
|
||||
$html_output .= '<!-- toggle query box link-->';
|
||||
$html_output .= '<a id="togglequerybox"></a>';
|
||||
return $html_output;
|
||||
return Template::get('database/search/result_divs')->render();
|
||||
}
|
||||
}
|
||||
|
||||
13
templates/database/search/result_divs.twig
Normal file
13
templates/database/search/result_divs.twig
Normal file
@ -0,0 +1,13 @@
|
||||
{# These two table-image and table-link elements display the table name in browse search results #}
|
||||
<div id="table-info">
|
||||
<a id="table-link" class="item"></a>
|
||||
</div>
|
||||
{# Div for browsing results #}
|
||||
<div id="browse-results">
|
||||
{# This browse-results div is used to load the browse and delete results in the db search #}
|
||||
</div>
|
||||
<div id="sqlqueryform" class="clearfloat">
|
||||
{# This sqlqueryform div is used to load the delete form in the db search #}
|
||||
</div>
|
||||
{# Toggle query box link #}
|
||||
<a id="togglequerybox"></a>
|
||||
62
templates/database/search/results.twig
Normal file
62
templates/database/search/results.twig
Normal file
@ -0,0 +1,62 @@
|
||||
<table class="data">
|
||||
<caption class="tblHeaders">
|
||||
{{ 'Search results for "<em>%s</em>" %s:'|format(
|
||||
criteria_search_string,
|
||||
search_type_description
|
||||
)|raw }}
|
||||
</caption>
|
||||
{% for row in rows %}
|
||||
<tr class="noclick">
|
||||
<td>
|
||||
{% set result_message %}
|
||||
{% trans %}
|
||||
%1$s match in <strong>%2$s</strong>
|
||||
{% plural row.result_count %}
|
||||
%1$s matches in <strong>%2$s</strong>
|
||||
{% endtrans %}
|
||||
{% endset %}
|
||||
{{ result_message|format(row.result_count, row.table)|raw }}
|
||||
</td>
|
||||
{% if row.result_count > 0 %}
|
||||
{% set url_params = {
|
||||
'db': db,
|
||||
'table': row.table,
|
||||
'goto': 'db_sql.php',
|
||||
'pos': 0,
|
||||
'is_js_confirmed': 0
|
||||
} %}
|
||||
<td>
|
||||
<a name="browse_search"
|
||||
class="ajax browse_results"
|
||||
href="sql.php{{ Url_getCommon(url_params) }}"
|
||||
data-browse-sql="{{ row.new_search_sqls.select_columns }}"
|
||||
data-table-name="{{ row.table }}">
|
||||
{% trans 'Browse' %}
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a name="delete_search"
|
||||
class="ajax delete_results"
|
||||
href="sql.php{{ Url_getCommon(url_params) }}"
|
||||
data-delete-sql="{{ row.new_search_sqls.delete }}"
|
||||
data-table-name="{{ row.table }}">
|
||||
{% trans 'Delete' %}
|
||||
</a>
|
||||
</td>
|
||||
{% else %}
|
||||
<td></td>
|
||||
<td></td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
{% if criteria_tables|length > 1 %}
|
||||
<p>
|
||||
{% trans %}
|
||||
<strong>Total:</strong> <em>{{ count }}</em> match
|
||||
{% plural result_total %}
|
||||
<strong>Total:</strong> <em>{{ count }}</em> matches
|
||||
{% endtrans %}
|
||||
</p>
|
||||
{% endif %}
|
||||
70
templates/database/search/selection_form.twig
Normal file
70
templates/database/search/selection_form.twig
Normal file
@ -0,0 +1,70 @@
|
||||
<a id="db_search"></a>
|
||||
<form id="db_search_form" method="post" action="db_search.php" name="db_search" class="ajax lock-page">
|
||||
{{ Url_getHiddenInputs(db) }}
|
||||
<fieldset>
|
||||
<legend>{% trans 'Search in database' %}</legend>
|
||||
<table class="formlayout all100">
|
||||
<tr>
|
||||
<td class="right">
|
||||
{% trans 'Words or values to search for (wildcard: "%"):' %}
|
||||
</td>
|
||||
<td>
|
||||
<input type="text" name="criteriaSearchString" class="all85" value="
|
||||
{{- criteria_search_string }}">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="right vtop">{% trans 'Find:' %}</td>
|
||||
<td>
|
||||
{# 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 #}
|
||||
{{ Util_getRadioFields(
|
||||
'criteriaSearchType',
|
||||
choices,
|
||||
criteria_search_type,
|
||||
true,
|
||||
false
|
||||
) }}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="right vtop">{% trans 'Inside tables:' %}</td>
|
||||
<td rowspan="2">
|
||||
<select name="criteriaTables[]" class="all85" multiple="multiple">
|
||||
{% for each_table in tables_names_only %}
|
||||
<option value="{{ each_table }}"
|
||||
{{- each_table in criteria_tables ? ' selected="selected"' }}>
|
||||
{{ each_table }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="right vbottom">
|
||||
<a href="#" onclick="setSelectOptions('db_search', 'criteriaTables[]', true); return false;">
|
||||
{% trans 'Select all' %}
|
||||
</a> /
|
||||
<a href="#" onclick="setSelectOptions('db_search', 'criteriaTables[]', false); return false;">
|
||||
{% trans 'Unselect all' %}
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{# Inputbox for column name entry #}
|
||||
<tr>
|
||||
<td class="right">{% trans 'Inside column:' %}</td>
|
||||
<td>
|
||||
<input type="text" name="criteriaColumnName" class="all85" value="
|
||||
{{- criteria_column_name is not empty ? criteria_column_name }}">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</fieldset>
|
||||
<fieldset class="tblFooters">
|
||||
<input type="submit" name="submit_search" value="{% trans 'Go' %}" id="buttonGo">
|
||||
</fieldset>
|
||||
</form>
|
||||
<div id="togglesearchformdiv">
|
||||
<a id="togglesearchformlink"></a>
|
||||
</div>
|
||||
@ -76,7 +76,7 @@ class SearchTest extends PmaTestCase
|
||||
*
|
||||
* @return the output from the protected method.
|
||||
*/
|
||||
private function _callProtectedFunction($name, $params)
|
||||
private function callProtectedFunction($name, $params)
|
||||
{
|
||||
$class = new ReflectionClass(Search::class);
|
||||
$method = $class->getMethod($name);
|
||||
@ -97,8 +97,8 @@ class SearchTest extends PmaTestCase
|
||||
$this->object = new Search('pma_test');
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$this->_callProtectedFunction(
|
||||
'_getWhereClause',
|
||||
$this->callProtectedFunction(
|
||||
'getWhereClause',
|
||||
array('table1')
|
||||
)
|
||||
);
|
||||
@ -149,8 +149,8 @@ class SearchTest extends PmaTestCase
|
||||
'WHERE FALSE',
|
||||
'delete' => 'DELETE FROM `pma`.`table1` WHERE FALSE'
|
||||
),
|
||||
$this->_callProtectedFunction(
|
||||
'_getSearchSqls',
|
||||
$this->callProtectedFunction(
|
||||
'getSearchSqls',
|
||||
array('table1')
|
||||
)
|
||||
);
|
||||
@ -163,72 +163,12 @@ class SearchTest extends PmaTestCase
|
||||
*/
|
||||
public function testGetSearchResults()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<br /><table class="data"><caption class="tblHeaders">Search results '
|
||||
. 'for "<i></i>" :</caption></table>',
|
||||
$this->assertContains(
|
||||
'Search results for "<em></em>" :',
|
||||
$this->object->getSearchResults()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for _getResultsRow
|
||||
*
|
||||
* @param string $each_table Tables on which search is to be performed
|
||||
* @param array $newsearchsqls Contains SQL queries
|
||||
* @param string $output Expected HTML output
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @dataProvider providerForTestGetResultsRow
|
||||
*/
|
||||
public function testGetResultsRow(
|
||||
$each_table, $newsearchsqls, $output
|
||||
) {
|
||||
|
||||
$this->assertEquals(
|
||||
$output,
|
||||
$this->_callProtectedFunction(
|
||||
'_getResultsRow',
|
||||
array($each_table, $newsearchsqls, 2)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetResultRow
|
||||
*
|
||||
* @return array provider for testGetResultsRow
|
||||
*/
|
||||
public function providerForTestGetResultsRow()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'table1',
|
||||
array(
|
||||
'SELECT * FROM `pma`.`table1` WHERE FALSE',
|
||||
'SELECT COUNT(*) AS `count` FROM `pma`.`table1` WHERE FALSE',
|
||||
'select_count' => 2,
|
||||
'select_columns' => 'column1',
|
||||
'delete' => 'column2'
|
||||
),
|
||||
'<tr class="noclick"><td>2 matches in <strong>table1</strong>'
|
||||
. '</td><td><a name="browse_search" class="ajax browse_results" '
|
||||
. 'href="sql.php?db=pma&table'
|
||||
. '=table1&goto=db_sql.php&pos=0&is_js_confirmed=0&'
|
||||
. 'server=0&lang=en" '
|
||||
. 'data-browse-sql="column1" data-table-name="table1" '
|
||||
. '>Browse</a></td><td>'
|
||||
. '<a name="delete_search" class="ajax delete_results" href'
|
||||
. '="sql.php?db=pma&table=table1&goto=db_sql.php&pos=0'
|
||||
. '&is_js_confirmed=0&server=0&'
|
||||
. 'lang=en" '
|
||||
. 'data-delete-sql="column2" '
|
||||
. 'data-table-name="table1" '
|
||||
. '>Delete</a></td></tr>'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getSelectionForm
|
||||
*
|
||||
@ -249,20 +189,29 @@ class SearchTest extends PmaTestCase
|
||||
*/
|
||||
public function testGetResultDivs()
|
||||
{
|
||||
$this->assertEquals(
|
||||
'<!-- These two table-image and table-link elements display the '
|
||||
. 'table name in browse search results --><div id="table-info">'
|
||||
. '<a class="item" id="table-link" ></a></div><div id="browse-results">'
|
||||
. '<!-- this browse-results div is used to load the browse and delete '
|
||||
. 'results in the db search --></div><br class="clearfloat" />'
|
||||
. '<div id="sqlqueryform"><!-- this sqlqueryform div is used to load the'
|
||||
. ' delete form in the db search --></div><!-- toggle query box link-->'
|
||||
. '<a id="togglequerybox"></a>',
|
||||
$this->_callProtectedFunction(
|
||||
'getResultDivs',
|
||||
array()
|
||||
)
|
||||
$actual = $this->callProtectedFunction(
|
||||
'getResultDivs',
|
||||
array()
|
||||
);
|
||||
$this->assertContains(
|
||||
'<div id="table-info"',
|
||||
$actual
|
||||
);
|
||||
$this->assertContains(
|
||||
'<a id="table-link"',
|
||||
$actual
|
||||
);
|
||||
$this->assertContains(
|
||||
'<div id="browse-results"',
|
||||
$actual
|
||||
);
|
||||
$this->assertContains(
|
||||
'<div id="sqlqueryform"',
|
||||
$actual
|
||||
);
|
||||
$this->assertContains(
|
||||
'<a id="togglequerybox"',
|
||||
$actual
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user