Use PMA_DBQbe in db_qbe.php
This commit is contained in:
parent
389c6a17a3
commit
6fcbbb72d7
143
db_qbe.php
143
db_qbe.php
@ -10,7 +10,10 @@
|
||||
* requirements
|
||||
*/
|
||||
require_once 'libraries/common.inc.php';
|
||||
require_once 'libraries/db_qbe.lib.php';
|
||||
require_once 'libraries/DbQbe.class.php';
|
||||
$response = PMA_Response::getInstance();
|
||||
$header = $response->getHeader();
|
||||
$scripts = $header->getScripts();
|
||||
|
||||
/**
|
||||
* Sets globals from $_POST patterns, for Or* variables
|
||||
@ -27,138 +30,9 @@ foreach (array_keys($_POST) as $post_key) {
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Initialize some more global variables
|
||||
*/
|
||||
$GLOBALS['curField'] = array();
|
||||
$GLOBALS['curSort'] = array();
|
||||
$GLOBALS['curShow'] = array();
|
||||
$GLOBALS['curCriteria'] = array();
|
||||
$GLOBALS['curAndOrRow'] = array();
|
||||
$GLOBALS['curAndOrCol'] = array();
|
||||
|
||||
/**
|
||||
* Gets the relation settings
|
||||
*/
|
||||
$cfgRelation = PMA_getRelationsParam();
|
||||
|
||||
$common_functions = PMA_CommonFunctions::getInstance();
|
||||
|
||||
/**
|
||||
* A query has been submitted -> (maybe) execute it
|
||||
*/
|
||||
$message_to_display = false;
|
||||
if (isset($_REQUEST['submit_sql']) && ! empty($sql_query)) {
|
||||
if (! preg_match('@^SELECT@i', $sql_query)) {
|
||||
$message_to_display = true;
|
||||
} else {
|
||||
$goto = 'db_sql.php';
|
||||
include 'sql.php';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$sub_part = '_qbe';
|
||||
require 'libraries/db_common.inc.php';
|
||||
$url_query .= '&goto=db_qbe.php';
|
||||
$url_params['goto'] = 'db_qbe.php';
|
||||
require 'libraries/db_info.inc.php';
|
||||
|
||||
if ($message_to_display) {
|
||||
PMA_Message::error(__('You have to choose at least one column to display'))->display();
|
||||
}
|
||||
unset($message_to_display);
|
||||
|
||||
/**
|
||||
* Initialize some variables
|
||||
*/
|
||||
$criteriaColumnCount = PMA_ifSetOr($_REQUEST['criteriaColumnCount'], 3, 'numeric');
|
||||
$criteriaColumnAdd = PMA_ifSetOr($_REQUEST['criteriaColumnAdd'], 0, 'numeric');
|
||||
$criteriaRowAdd = PMA_ifSetOr($_REQUEST['criteriaRowAdd'], 0, 'numeric');
|
||||
|
||||
$rows = PMA_ifSetOr($_REQUEST['rows'], 0, 'numeric');
|
||||
$criteriaColumnInsert = PMA_ifSetOr($_REQUEST['criteriaColumnInsert'], null, 'array');
|
||||
$criteriaColumnDelete = PMA_ifSetOr($_REQUEST['criteriaColumnDelete'], null, 'array');
|
||||
|
||||
$prev_criteria = isset($_REQUEST['prev_criteria'])
|
||||
? $_REQUEST['prev_criteria']
|
||||
: array();
|
||||
$criteria = isset($_REQUEST['criteria'])
|
||||
? $_REQUEST['criteria']
|
||||
: array_fill(0, $criteriaColumnCount, '');
|
||||
|
||||
$criteriaRowInsert = isset($_REQUEST['criteriaRowInsert'])
|
||||
? $_REQUEST['criteriaRowInsert']
|
||||
: array_fill(0, $criteriaColumnCount, '');
|
||||
$criteriaRowDelete = isset($_REQUEST['criteriaRowDelete'])
|
||||
? $_REQUEST['criteriaRowDelete']
|
||||
: array_fill(0, $criteriaColumnCount, '');
|
||||
$criteriaAndOrRow = isset($_REQUEST['criteriaAndOrRow'])
|
||||
? $_REQUEST['criteriaAndOrRow']
|
||||
: array_fill(0, $criteriaColumnCount, '');
|
||||
$criteriaAndOrColumn = isset($_REQUEST['criteriaAndOrColumn'])
|
||||
? $_REQUEST['criteriaAndOrColumn']
|
||||
: array_fill(0, $criteriaColumnCount, '');
|
||||
|
||||
// minimum width
|
||||
$form_column_width = 12;
|
||||
$criteria_column_count = max($criteriaColumnCount + $criteriaColumnAdd, 0);
|
||||
$criteria_row_count = max($rows + $criteriaRowAdd, 0);
|
||||
|
||||
|
||||
// The tables list sent by a previously submitted form
|
||||
if (PMA_isValid($_REQUEST['TableList'], 'array')) {
|
||||
foreach ($_REQUEST['TableList'] as $each_table) {
|
||||
$criteriaTables[$each_table] = ' selected="selected"';
|
||||
}
|
||||
} // end if
|
||||
|
||||
|
||||
// this was a work in progress, deactivated for now
|
||||
//$columns = PMA_DBI_get_columns_full($GLOBALS['db']);
|
||||
//$tables = PMA_DBI_get_columns_full($GLOBALS['db']);
|
||||
|
||||
|
||||
/**
|
||||
* Prepares the form
|
||||
*/
|
||||
$all_tables = PMA_DBI_query(
|
||||
'SHOW TABLES FROM ' . $common_functions->backquote($db) . ';',
|
||||
null, PMA_DBI_QUERY_STORE
|
||||
);
|
||||
$all_tables_count = PMA_DBI_num_rows($all_tables);
|
||||
if (0 == $all_tables_count) {
|
||||
PMA_Message::error(__('No tables found in database.'))->display();
|
||||
exit;
|
||||
}
|
||||
|
||||
// The tables list gets from MySQL
|
||||
while (list($table) = PMA_DBI_fetch_row($all_tables)) {
|
||||
$columns = PMA_DBI_get_columns($db, $table);
|
||||
|
||||
if (empty($criteriaTables[$table]) && ! empty($_REQUEST['TableList'])) {
|
||||
$criteriaTables[$table] = '';
|
||||
} else {
|
||||
$criteriaTables[$table] = ' selected="selected"';
|
||||
} // end if
|
||||
|
||||
// The fields list per selected tables
|
||||
if ($criteriaTables[$table] == ' selected="selected"') {
|
||||
$each_table = $common_functions->backquote($table);
|
||||
$columnNames[] = $each_table . '.*';
|
||||
foreach ($columns as $each_column) {
|
||||
$each_column = $each_table . '.' . $common_functions->backquote($each_column['Field']);
|
||||
$columnNames[] = $each_column;
|
||||
|
||||
// increase the width if necessary
|
||||
$form_column_width = max(strlen($each_column), $form_column_width);
|
||||
} // end foreach
|
||||
} // end if
|
||||
} // end while
|
||||
PMA_DBI_free_result($all_tables);
|
||||
|
||||
// largest width found
|
||||
$realwidth = $form_column_width . 'ex';
|
||||
// create new qbe search instance
|
||||
$db_qbe = new PMA_DBQbe($GLOBALS['db']);
|
||||
|
||||
/**
|
||||
* Displays the Query by example form
|
||||
@ -179,8 +53,5 @@ if ($cfgRelation['designerwork']) {
|
||||
)
|
||||
)->display();
|
||||
}
|
||||
echo PMA_dbQbeGetSelectionForm($db, $criteriaTables, $columnNames, $criteria_column_count, $criteria_row_count,
|
||||
$criteriaColumnInsert, $criteriaColumnDelete, $realwidth, $criteria, $prev_criteria,
|
||||
$criteriaAndOrRow, $criteriaAndOrColumn, $cfgRelation
|
||||
);
|
||||
$response->addHTML($db_qbe->getSelectionForm($cfgRelation));
|
||||
?>
|
||||
|
||||
@ -283,19 +283,18 @@ class PMA_DbQbe
|
||||
/**
|
||||
* Provides select options list containing column names
|
||||
*
|
||||
* @param array $columns All Column Names
|
||||
* @param integer $column_number Column Number (0,1,2) or more
|
||||
* @param string $selected Selected criteria column name
|
||||
*
|
||||
* @return HTML for select options
|
||||
*/
|
||||
private function _showColumnSelectCell($columns, $column_number, $selected = '')
|
||||
private function _showColumnSelectCell($column_number, $selected = '')
|
||||
{
|
||||
$html_output = '';
|
||||
$html_output .= '<td class="center">';
|
||||
$html_output .= '<select name="criteriaColumn[' . $column_number . ']" size="1">';
|
||||
$html_output .= '<option value=""> </option>';
|
||||
foreach ($columns as $column) {
|
||||
foreach ($this->_columnNames as $column) {
|
||||
$html_output .= '<option value="' . htmlspecialchars($column) . '"'
|
||||
. (($column === $selected) ? ' selected="selected"' : '') . '>'
|
||||
. str_replace(' ', ' ', htmlspecialchars($column)) . '</option>';
|
||||
@ -333,11 +332,9 @@ class PMA_DbQbe
|
||||
/**
|
||||
* Provides search form's row containing column select options
|
||||
*
|
||||
* @param integer $columns All column names
|
||||
*
|
||||
* @return HTML for search table's row
|
||||
*/
|
||||
private function _getColumnNamesRow($columns)
|
||||
private function _getColumnNamesRow()
|
||||
{
|
||||
$html_output = '<tr class="odd noclick">';
|
||||
$html_output .= '<th>' . __('Column') . ':</th>';
|
||||
@ -347,7 +344,7 @@ class PMA_DbQbe
|
||||
if (isset($this->_criteriaColumnInsert[$column_index])
|
||||
&& $this->_criteriaColumnInsert[$column_index] == 'on'
|
||||
) {
|
||||
$html_output .= showColumnSelectCell($columns, $new_column_count);
|
||||
$html_output .= showColumnSelectCell($new_column_count);
|
||||
$new_column_count++;
|
||||
}
|
||||
if (! empty($this->_criteriaColumnDelete)
|
||||
@ -361,7 +358,7 @@ class PMA_DbQbe
|
||||
$selected = $_REQUEST['criteriaColumn'][$column_index];
|
||||
$this->_curField[$new_column_count] = $_REQUEST['criteriaColumn'][$column_index];
|
||||
}
|
||||
$html_output .= $this->_showColumnSelectCell($columns, $new_column_count, $selected);
|
||||
$html_output .= $this->_showColumnSelectCell($new_column_count, $selected);
|
||||
$new_column_count++;
|
||||
} // end for
|
||||
$html_output .= '</tr>';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user