Fix some bugs with strange table and database names

- Fix export
- Fix split on . to have db and table
- Replace some $_REQUEST occurences
- Add translations to "add tables from another database" : "None" > strNone
- Refactor the ugly code that used globals to use an object "DesignerTable"
- Fix save a new added table
- Fix delete page items
- Fix more bugs

Fixes: #15446
Fixes: #13370
Fixes: #14945
Closes: #15438

Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2019-08-22 18:35:10 +02:00
parent 5940d11e72
commit a23f2ba51a
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889
10 changed files with 313 additions and 214 deletions

View File

@ -19,33 +19,25 @@ $designerCommon = new Common();
if (isset($_POST['dialog'])) {
if ($_POST['dialog'] == 'edit') {
$html = $databaseDesigner->getHtmlForEditOrDeletePages($GLOBALS['db'], 'editPage');
$html = $databaseDesigner->getHtmlForEditOrDeletePages($_POST['db'], 'editPage');
} elseif ($_POST['dialog'] == 'delete') {
$html = $databaseDesigner->getHtmlForEditOrDeletePages($GLOBALS['db'], 'deletePage');
$html = $databaseDesigner->getHtmlForEditOrDeletePages($_POST['db'], 'deletePage');
} elseif ($_POST['dialog'] == 'save_as') {
$html = $databaseDesigner->getHtmlForPageSaveAs($GLOBALS['db']);
$html = $databaseDesigner->getHtmlForPageSaveAs($_POST['db']);
} elseif ($_POST['dialog'] == 'export') {
$html = $databaseDesigner->getHtmlForSchemaExport(
$GLOBALS['db'], $_POST['selected_page']
$_POST['db'], $_POST['selected_page']
);
} elseif ($_POST['dialog'] == 'add_table') {
$script_display_field = $designerCommon->getTablesInfo();
$required = $GLOBALS['db'] . '.' . $GLOBALS['table'];
$tab_column = $designerCommon->getColumnsInfo();
$tables_all_keys = $designerCommon->getAllKeys();
$tables_pk_or_unique_keys = $designerCommon->getPkOrUniqueKeys();
$req_key = array_search($required, $GLOBALS['designer']['TABLE_NAME']);
$GLOBALS['designer']['TABLE_NAME'] = array($GLOBALS['designer']['TABLE_NAME'][$req_key]);
$GLOBALS['designer_url']['TABLE_NAME'] = array($GLOBALS['designer_url']['TABLE_NAME'][$req_key]);
$GLOBALS['designer_url']['TABLE_NAME_SMALL'] = array($GLOBALS['designer_url']['TABLE_NAME_SMALL'][$req_key]);
$GLOBALS['designer']['TABLE_NAME_SMALL'] = array($GLOBALS['designer']['TABLE_NAME_SMALL'][$req_key]);
$GLOBALS['designer_out']['TABLE_NAME_SMALL'] = array($GLOBALS['designer_out']['TABLE_NAME_SMALL'][$req_key]);
$GLOBALS['designer']['TABLE_TYPE'] = array($GLOBALS['designer_url']['TABLE_TYPE'][$req_key]);
$GLOBALS['designer_out']['OWNER'] = array($GLOBALS['designer_out']['OWNER'][$req_key]);
// Pass the db and table to the getTablesInfo so we only have the table we asked for
$script_display_field = $designerCommon->getTablesInfo($_POST['db'], $_POST['table']);
$tab_column = $designerCommon->getColumnsInfo($script_display_field);
$tables_all_keys = $designerCommon->getAllKeys($script_display_field);
$tables_pk_or_unique_keys = $designerCommon->getPkOrUniqueKeys($script_display_field);
$html = $databaseDesigner->getDatabaseTables(
$_POST['db'],
$script_display_field,
array(), -1, $tab_column,
$tables_all_keys, $tables_pk_or_unique_keys
);
@ -66,7 +58,7 @@ if (isset($_POST['operation'])) {
if ($_POST['save_page'] == 'same') {
$page = $_POST['selected_page'];
} else { // new
$page = $designerCommon->createNewPage($_POST['selected_value'], $GLOBALS['db']);
$page = $designerCommon->createNewPage($_POST['selected_value'], $_POST['db']);
$response->addJSON('id', $page);
}
$success = $designerCommon->saveTablePositions($page);
@ -110,11 +102,6 @@ if (isset($_POST['operation'])) {
require 'libraries/db_common.inc.php';
$script_display_field = $designerCommon->getTablesInfo();
$tab_column = $designerCommon->getColumnsInfo();
$script_tables = $designerCommon->getScriptTabs();
$tables_pk_or_unique_keys = $designerCommon->getPkOrUniqueKeys();
$tables_all_keys = $designerCommon->getAllKeys();
$classes_side_menu = $databaseDesigner->returnClassNamesFromMenuButtons();
$display_page = -1;
$selected_page = null;
@ -132,7 +119,30 @@ if ($display_page != -1) {
$selected_page = $designerCommon->getPageName($display_page);
}
$tab_pos = $designerCommon->getTablePositions($display_page);
$script_contr = $designerCommon->getScriptContr();
$fullTableNames = [];
foreach($script_display_field as $designerTable) {
$fullTableNames[] = $designerTable->getDbTableString();
}
foreach($tab_pos as $position) {
if (! in_array($position['dbName'] . '.' . $position['tableName'], $fullTableNames)) {
foreach($designerCommon->getTablesInfo($position['dbName'], $position['tableName']) as $designerTable) {
$script_display_field[] = $designerTable;
}
}
}
$tab_column = $designerCommon->getColumnsInfo($script_display_field);
$script_tables = $designerCommon->getScriptTabs($script_display_field);
$tables_pk_or_unique_keys = $designerCommon->getPkOrUniqueKeys($script_display_field);
$tables_all_keys = $designerCommon->getAllKeys($script_display_field);
$classes_side_menu = $databaseDesigner->returnClassNamesFromMenuButtons();
$script_contr = $designerCommon->getScriptContr($script_display_field);
$params = array('lang' => $GLOBALS['lang']);
if (isset($_GET['db'])) {
@ -192,6 +202,8 @@ $response->addHTML($databaseDesigner->getHtmlTableList());
$response->addHTML(
$databaseDesigner->getDatabaseTables(
$_GET['db'],
$script_display_field,
$tab_pos, $display_page, $tab_column,
$tables_all_keys, $tables_pk_or_unique_keys
)

View File

@ -549,25 +549,25 @@ function Toggle_fullscreen () {
saveValueInConfig('full_screen', value_sent);
}
function addTableToTablesList(index, table_dom) {
function addTableToTablesList (index, table_dom) {
var db = $(table_dom).find('.small_tab_pref').attr('db');
var table = $(table_dom).find('.small_tab_pref').attr('table_name_small');
var db_encoded = encodeURIComponent(db);
var table_encoded = encodeURIComponent(table);
var table = $(table_dom).find('.small_tab_pref').attr('table_name');
var db_encoded = $(table_dom).find('.small_tab_pref').attr('db_url');
var table_encoded = $(table_dom).find('.small_tab_pref').attr('table_name_url');
var $new_table_line = $('<tr>' +
' <td title="' + PMA_messages.strStructure + '"' +
' width="1px"' +
' class="L_butt2_1">' +
' <img alt=""' +
' db="' + db + '"' +
' table_name="' + table + '"' +
' db="' + db_encoded + '"' +
' table_name="' + table_encoded + '"' +
' class="scroll_tab_struct"' +
' src="' + pmaThemeImage + 'designer/exec.png"/>' +
' </td>' +
' <td width="1px">' +
' <input class="scroll_tab_checkbox"' +
' title="' + PMA_messages.strHide + '"' +
' id="check_vis_' + encodeURI(db) + '.' + table_encoded + '"' +
' id="check_vis_' + db_encoded + '.' + table_encoded + '"' +
' style="margin:0;"' +
' type="checkbox"' +
' value="' + db_encoded + '.' + table_encoded + '"' +
@ -597,7 +597,7 @@ function Add_Other_db_tables () {
var db = $('#add_table_from').val();
var table = $('#add_table').val();
//Check if table already imported or not.
// Check if table already imported or not.
var $table = $('[id="' + encodeURIComponent(db) + '.' + encodeURIComponent(table) + '"]');
if ($table.length !== 0) {
PMA_ajaxShowMessage(
@ -615,11 +615,14 @@ function Add_Other_db_tables () {
'table' : table,
'server': PMA_commonParams.get('server')
}, function (data) {
var $new_table_dom = $(data.message);
$new_table_dom.find('a').first().remove();
$('#container-form').append($new_table_dom);
enableTableEvents(null, $new_table_dom);
addTableToTablesList(null, $new_table_dom);
var $newTableDom = $(data.message);
$newTableDom.find('a').first().remove();
$('#container-form').append($newTableDom);
enableTableEvents(null, $newTableDom);
addTableToTablesList(null, $newTableDom);
var dbEncoded = $($newTableDom).find('.small_tab_pref').attr('db_url');
var tableEncoded = $($newTableDom).find('.small_tab_pref').attr('table_name_url');
j_tabs[dbEncoded + '.' + tableEncoded] = 1;
});
$(this).dialog('close');
};
@ -628,10 +631,10 @@ function Add_Other_db_tables () {
};
var $select_db = $('<select id="add_table_from"></select>');
$select_db.append('<option value="">None</option>');
$select_db.append('<option value="">' + PMA_messages.strNone + '</option>');
var $select_table = $('<select id="add_table"></select>');
$select_table.append('<option value="">None</option>');
$select_table.append('<option value="">' + PMA_messages.strNone + '</option>');
$.post('sql.php', {
'ajax_request' : true,
@ -670,7 +673,11 @@ function Add_Other_db_tables () {
'server': PMA_commonParams.get('server')
}, function (data) {
$select_table.html('');
$(data.message).find('table.table_results.data.ajax').find('td.data').each(function () {
var rows = $(data.message).find('table.table_results.data.ajax').find('td.data');
if (rows.length === 0) {
$select_table.append('<option value="">' + PMA_messages.strNone + '</option>');
}
rows.each(function () {
var val = $(this)[0].innerHTML;
$select_table.append('<option value="' + val + '">' + val + '</option>');
});
@ -705,11 +712,15 @@ function Get_url_pos (forceString) {
if (designer_tables_enabled || forceString) {
var poststr = '';
var argsep = PMA_commonParams.get('arg_separator');
var i = 1;
for (var key in j_tabs) {
poststr += argsep + 't_x[' + decodeURIComponent(key) + ']=' + parseInt(document.getElementById(key).style.left, 10);
poststr += argsep + 't_y[' + decodeURIComponent(key) + ']=' + parseInt(document.getElementById(key).style.top, 10);
poststr += argsep + 't_v[' + decodeURIComponent(key) + ']=' + (document.getElementById('id_tbody_' + key).style.display === 'none' ? 0 : 1);
poststr += argsep + 't_h[' + decodeURIComponent(key) + ']=' + (document.getElementById('check_vis_' + key).checked ? 1 : 0);
poststr += argsep + 't_x[' + i + ']=' + parseInt(document.getElementById(key).style.left, 10);
poststr += argsep + 't_y[' + i + ']=' + parseInt(document.getElementById(key).style.top, 10);
poststr += argsep + 't_v[' + i + ']=' + (document.getElementById('id_tbody_' + key).style.display === 'none' ? 0 : 1);
poststr += argsep + 't_h[' + i + ']=' + (document.getElementById('check_vis_' + key).checked ? 1 : 0);
poststr += argsep + 't_db[' + i + ']=' + $(document.getElementById(key)).attr('db_url');
poststr += argsep + 't_tbl[' + i + ']=' + $(document.getElementById(key)).attr('table_name_url');
i++;
}
return poststr;
} else {
@ -718,7 +729,10 @@ function Get_url_pos (forceString) {
if (document.getElementById('check_vis_' + key).checked) {
var x = parseInt(document.getElementById(key).style.left, 10);
var y = parseInt(document.getElementById(key).style.top, 10);
var tbCoords = new TableCoordinate(db, key.split('.')[1], -1, x, y);
var tbCoords = new TableCoordinate(
$(document.getElementById(key)).attr('db_url'),
$(document.getElementById(key)).attr('table_name_url'),
-1, x, y);
coords.push(tbCoords);
}
}
@ -729,8 +743,8 @@ function Get_url_pos (forceString) {
function Save2 (callback) {
if (designer_tables_enabled) {
var argsep = PMA_commonParams.get('arg_separator');
var poststr = argsep + 'operation=savePage' + argsep + 'save_page=same' + argsep + 'ajax_request=true';
poststr += argsep + 'server=' + server + argsep + 'db=' + db + argsep + 'selected_page=' + selected_page;
var poststr = 'operation=savePage' + argsep + 'save_page=same' + argsep + 'ajax_request=true';
poststr += argsep + 'server=' + server + argsep + 'db=' + encodeURIComponent(db) + argsep + 'selected_page=' + selected_page;
poststr += Get_url_pos();
var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
@ -1176,7 +1190,7 @@ function Load_page (page) {
if (page !== null) {
param_page = argsep + 'page=' + page;
}
$('<a href="db_designer.php?server=' + server + argsep + 'db=' + encodeURI(db) + param_page + '"></a>')
$('<a href="db_designer.php?server=' + server + argsep + 'db=' + encodeURIComponent(db) + param_page + '"></a>')
.appendTo($('#page_content'))
.click();
} else {

View File

@ -291,22 +291,25 @@ class Designer
{
return Template::get('database/designer/table_list')->render([
'theme' => $GLOBALS['PMA_Theme'],
'table_names' => $GLOBALS['designer']['TABLE_NAME'],
]);
}
/**
* Get HTML to display tables on designer page
*
* @param array $tab_pos tables positions
* @param int $display_page page number of the selected page
* @param array $tab_column table column info
* @param array $tables_all_keys all indices
* @param array $tables_pk_or_unique_keys unique or primary indices
* @param string $db The database name from the request
* @param array $designerTables The designer tables
* @param array $tab_pos tables positions
* @param int $display_page page number of the selected page
* @param array $tab_column table column info
* @param array $tables_all_keys all indices
* @param array $tables_pk_or_unique_keys unique or primary indices
*
* @return string html
*/
public function getDatabaseTables(
$db,
array $designerTables,
array $tab_pos,
$display_page,
array $tab_column,
@ -315,20 +318,14 @@ class Designer
) {
return Template::get('database/designer/database_tables')->render([
'db' => $GLOBALS['db'],
'get_db' => $_GET['db'],
'get_db' => $db,
'has_query' => isset($_REQUEST['query']),
'tab_pos' => $tab_pos,
'display_page' => $display_page,
'tab_column' => $tab_column,
'tables_all_keys' => $tables_all_keys,
'tables_pk_or_unique_keys' => $tables_pk_or_unique_keys,
'table_names' => $GLOBALS['designer']['TABLE_NAME'],
'table_names_url' => $GLOBALS['designer_url']['TABLE_NAME'],
'table_names_small' => $GLOBALS['designer']['TABLE_NAME_SMALL'],
'table_names_small_url' => $GLOBALS['designer_url']['TABLE_NAME_SMALL'],
'table_names_small_out' => $GLOBALS['designer_out']['TABLE_NAME_SMALL'],
'table_types' => $GLOBALS['designer']['TABLE_TYPE'],
'owner_out' => $GLOBALS['designer_out']['OWNER'],
'tables' => $designerTables,
'theme' => $GLOBALS['PMA_Theme'],
]);
}

View File

@ -12,6 +12,7 @@ use PhpMyAdmin\Index;
use PhpMyAdmin\Relation;
use PhpMyAdmin\Table;
use PhpMyAdmin\Util;
use PhpMyAdmin\Database\Designer\DesignerTable;
/**
* Common functions for Designer
@ -34,109 +35,84 @@ class Common
}
/**
* Retrieves table info and stores it in $GLOBALS['designer']
* Retrieves table info and returns it
*
* @return array with table info
* @param string $db (optional) Filter only a DB ($table is required if you use $db)
* @param string $table (optional) Filter only a table ($db is now required)
* @return DesignerTable[] with table info
*/
public function getTablesInfo()
public function getTablesInfo($db = null, $table = null)
{
$retval = array();
$GLOBALS['designer']['TABLE_NAME'] = array();// that foreach no error
$GLOBALS['designer']['OWNER'] = array();
$GLOBALS['designer']['TABLE_NAME_SMALL'] = array();
$GLOBALS['designer']['TABLE_TYPE'] = array();
$GLOBALS['designer_url']['TABLE_NAME'] = array();
$GLOBALS['designer_url']['OWNER'] = array();
$GLOBALS['designer_url']['TABLE_NAME_SMALL'] = array();
$GLOBALS['designer_out']['TABLE_NAME'] = array();
$GLOBALS['designer_out']['OWNER'] = array();
$GLOBALS['designer_out']['TABLE_NAME_SMALL'] = array();
$tables = $GLOBALS['dbi']->getTablesFull($GLOBALS['db']);
$designerTables = array();
$db = ($db === null) ? $GLOBALS['db'] : $db;
// seems to be needed later
$GLOBALS['dbi']->selectDb($GLOBALS['db']);
$i = 0;
foreach ($tables as $one_table) {
$GLOBALS['designer']['TABLE_NAME'][$i]
= $GLOBALS['db'] . "." . $one_table['TABLE_NAME'];
$GLOBALS['designer']['OWNER'][$i] = $GLOBALS['db'];
$GLOBALS['designer']['TABLE_NAME_SMALL'][$i] = htmlspecialchars(
$one_table['TABLE_NAME'], ENT_QUOTES
);
$GLOBALS['designer_url']['TABLE_NAME'][$i]
= $GLOBALS['db'] . "." . $one_table['TABLE_NAME'];
$GLOBALS['designer_url']['OWNER'][$i] = $GLOBALS['db'];
$GLOBALS['designer_url']['TABLE_NAME_SMALL'][$i]
= $one_table['TABLE_NAME'];
$GLOBALS['designer_out']['TABLE_NAME'][$i] = htmlspecialchars(
$GLOBALS['db'] . "." . $one_table['TABLE_NAME'], ENT_QUOTES
);
$GLOBALS['designer_out']['OWNER'][$i] = htmlspecialchars(
$GLOBALS['db'], ENT_QUOTES
);
$GLOBALS['designer_out']['TABLE_NAME_SMALL'][$i] = htmlspecialchars(
$one_table['TABLE_NAME'], ENT_QUOTES
);
$GLOBALS['designer']['TABLE_TYPE'][$i] = mb_strtoupper(
$one_table['ENGINE']
);
$DF = $this->relation->getDisplayField($GLOBALS['db'], $one_table['TABLE_NAME']);
if ($DF != '') {
$DF = rawurlencode((string)$DF);
$retval[rawurlencode($GLOBALS['designer_url']["TABLE_NAME_SMALL"][$i])] = $DF;
}
$i++;
$GLOBALS['dbi']->selectDb($db);
if ($db === null && $table === null) {
$tables = $GLOBALS['dbi']->getTablesFull($db);
} else {
$tables = $GLOBALS['dbi']->getTablesFull($db, $table);
}
return $retval;
foreach ($tables as $one_table) {
$DF = $this->relation->getDisplayField($db, $one_table['TABLE_NAME']);
$DF = ($DF !== '') ? $DF : null;
$designerTables[] = new DesignerTable(
$db,
$one_table['TABLE_NAME'],
$one_table['ENGINE'],
$DF
);
}
return $designerTables;
}
/**
* Retrieves table column info
*
* @return array table column nfo
* @param DesignerTable[] $designerTables The designer tables
* @return array table column nfo
*/
public function getColumnsInfo()
public function getColumnsInfo($designerTables)
{
$GLOBALS['dbi']->selectDb($GLOBALS['db']);
$tab_column = array();
for ($i = 0, $cnt = count($GLOBALS['designer']["TABLE_NAME"]); $i < $cnt; $i++) {
$fields_rs = $GLOBALS['dbi']->query(
//$GLOBALS['dbi']->selectDb($GLOBALS['db']);
$tabColumn = array();
foreach($designerTables as $designerTable) {
$fieldsRs = $GLOBALS['dbi']->query(
$GLOBALS['dbi']->getColumnsSql(
$GLOBALS['db'],
$GLOBALS['designer_url']["TABLE_NAME_SMALL"][$i],
$designerTable->getDatabaseName(),
$designerTable->getTableName(),
null,
true
),
DatabaseInterface::CONNECT_USER,
DatabaseInterface::QUERY_STORE
);
$tbl_name_i = $GLOBALS['designer']['TABLE_NAME'][$i];
$j = 0;
while ($row = $GLOBALS['dbi']->fetchAssoc($fields_rs)) {
$tab_column[$tbl_name_i]['COLUMN_ID'][$j] = $j;
$tab_column[$tbl_name_i]['COLUMN_NAME'][$j] = $row['Field'];
$tab_column[$tbl_name_i]['TYPE'][$j] = $row['Type'];
$tab_column[$tbl_name_i]['NULLABLE'][$j] = $row['Null'];
while ($row = $GLOBALS['dbi']->fetchAssoc($fieldsRs)) {
if (! isset($tabColumn[$designerTable->getDbTableString()])) {
$tabColumn[$designerTable->getDbTableString()] = [];
}
$tabColumn[$designerTable->getDbTableString()]['COLUMN_ID'][$j] = $j;
$tabColumn[$designerTable->getDbTableString()]['COLUMN_NAME'][$j] = $row['Field'];
$tabColumn[$designerTable->getDbTableString()]['TYPE'][$j] = $row['Type'];
$tabColumn[$designerTable->getDbTableString()]['NULLABLE'][$j] = $row['Null'];
$j++;
}
}
return $tab_column;
return $tabColumn;
}
/**
* Returns JavaScript code for initializing vars
*
* @param DesignerTable[] $designerTables The designer tables
* @return string JavaScript code
*/
public function getScriptContr()
public function getScriptContr($designerTables)
{
$GLOBALS['dbi']->selectDb($GLOBALS['db']);
$con = array();
@ -183,6 +159,11 @@ class Common
}
}
$tableDbNames = [];
foreach($designerTables as $designerTable) {
$tableDbNames[] = $designerTable->getDbTableString();
}
$ti = 0;
$retval = array();
for ($i = 0, $cnt = count($con["C_NAME"]); $i < $cnt; $i++) {
@ -190,9 +171,7 @@ class Common
$dtn_i = $con['DTN'][$i];
$retval[$ti] = array();
$retval[$ti][$c_name_i] = array();
if (in_array(rawurldecode($dtn_i), $GLOBALS['designer_url']["TABLE_NAME"])
&& in_array(rawurldecode($con['STN'][$i]), $GLOBALS['designer_url']["TABLE_NAME"])
) {
if (in_array($dtn_i, $tableDbNames) && in_array($con['STN'][$i], $tableDbNames)) {
$retval[$ti][$c_name_i][$dtn_i] = array();
$retval[$ti][$c_name_i][$dtn_i][$con['DCN'][$i]] = array(
0 => $con['STN'][$i],
@ -207,34 +186,36 @@ class Common
/**
* Returns UNIQUE and PRIMARY indices
*
* @param DesignerTable[] $designerTables The designer tables
* @return array unique or primary indices
*/
public function getPkOrUniqueKeys()
public function getPkOrUniqueKeys($designerTables)
{
return $this->getAllKeys(true);
return $this->getAllKeys($designerTables, true);
}
/**
* Returns all indices
*
* @param DesignerTable[] $designerTables The designer tables
* @param bool $unique_only whether to include only unique ones
*
* @return array indices
*/
public function getAllKeys($unique_only = false)
public function getAllKeys($designerTables, $unique_only = false)
{
$keys = array();
foreach ($GLOBALS['designer']['TABLE_NAME_SMALL'] as $I => $table) {
$schema = $GLOBALS['designer']['OWNER'][$I];
foreach ($designerTables as $designerTable) {
$schema = $designerTable->getDatabaseName();
// for now, take into account only the first index segment
foreach (Index::getFromTable($table, $schema) as $index) {
foreach (Index::getFromTable($designerTable->getTableName(), $schema) as $index) {
if ($unique_only && ! $index->isUnique()) {
continue;
}
$columns = $index->getColumns();
foreach ($columns as $column_name => $dummy) {
$keys[$schema . '.' . $table . '.' . $column_name] = 1;
$keys[$schema . '.' . $designerTable->getTableName() . '.' . $column_name] = 1;
}
}
}
@ -242,25 +223,24 @@ class Common
}
/**
* Return script to create j_tab and h_tab arrays
* Return j_tab and h_tab arrays
*
* @return string
* @param DesignerTable[] $designerTables The designer tables
* @return array
*/
public function getScriptTabs()
public function getScriptTabs($designerTables)
{
$retval = array(
'j_tabs' => array(),
'h_tabs' => array()
);
for ($i = 0, $cnt = count($GLOBALS['designer']['TABLE_NAME']); $i < $cnt; $i++) {
$j = 0;
if (Util::isForeignKeySupported($GLOBALS['designer']['TABLE_TYPE'][$i])) {
$j = 1;
}
$retval['j_tabs'][\rawurlencode($GLOBALS['designer_url']['TABLE_NAME'][$i])] = $j;
$retval['h_tabs'][\rawurlencode($GLOBALS['designer_url']['TABLE_NAME'][$i])] = 1;
foreach($designerTables as $designerTable) {
$key = rawurlencode($designerTable->getDbTableString());
$retval['j_tabs'][$key] = $designerTable->supportsForeignkeys() ? 1 : 0;
$retval['h_tabs'][$key] = 1;
}
return $retval;
}
@ -280,6 +260,7 @@ class Common
$query = "
SELECT CONCAT_WS('.', `db_name`, `table_name`) AS `name`,
`db_name` as `dbName`, `table_name` as `tableName`,
`x` AS `X`,
`y` AS `Y`,
1 AS `V`,
@ -465,6 +446,10 @@ class Common
*/
public function saveTablePositions($pg)
{
$pageId = $GLOBALS['dbi']->escapeString($pg);
$db = $GLOBALS['dbi']->escapeString($_POST['db']);
$cfgRelation = $this->relation->getRelationsParam();
if (! $cfgRelation['pdfwork']) {
return false;
@ -475,10 +460,7 @@ class Common
. "." . Util::backquote(
$GLOBALS['cfgRelation']['table_coords']
)
. " WHERE `db_name` = '" . $GLOBALS['dbi']->escapeString($_REQUEST['db'])
. "'"
. " AND `pdf_page_number` = '" . $GLOBALS['dbi']->escapeString($pg)
. "'";
. " WHERE `pdf_page_number` = '" . $pageId . "'";
$res = $this->relation->queryAsControlUser(
$query,
@ -490,8 +472,9 @@ class Common
return (boolean)$res;
}
foreach ($_REQUEST['t_h'] as $key => $value) {
list($DB, $TAB) = explode(".", $key);
foreach ($_POST['t_h'] as $key => $value) {
$DB = $_POST['t_db'][$key];
$TAB = $_POST['t_tbl'][$key];
if (!$value) {
continue;
}
@ -503,9 +486,9 @@ class Common
. " VALUES ("
. "'" . $GLOBALS['dbi']->escapeString($DB) . "', "
. "'" . $GLOBALS['dbi']->escapeString($TAB) . "', "
. "'" . $GLOBALS['dbi']->escapeString($pg) . "', "
. "'" . $GLOBALS['dbi']->escapeString($_REQUEST['t_x'][$key]) . "', "
. "'" . $GLOBALS['dbi']->escapeString($_REQUEST['t_y'][$key]) . "')";
. "'" . $pageId . "', "
. "'" . $GLOBALS['dbi']->escapeString($_POST['t_x'][$key]) . "', "
. "'" . $GLOBALS['dbi']->escapeString($_POST['t_y'][$key]) . "')";
$res = $this->relation->queryAsControlUser(
$query, true, DatabaseInterface::QUERY_STORE

View File

@ -0,0 +1,88 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Holds the PhpMyAdmin\Database\Designer\DesignerTable class
*
* @package PhpMyAdmin-Designer
*/
namespace PhpMyAdmin\Database\Designer;
use PhpMyAdmin\Util;
/**
* Common functions for Designer
*
* @package PhpMyAdmin-Designer
*/
class DesignerTable
{
private $tableName;
private $databaseName;
private $tableEngine;
private $displayField;
/**
* Create a new DesignerTable
*
* @param string $databaseName The database name
* @param string $tableName The table name
* @param string $tableEngine The table engine
* @param string|null $displayField The display field if available
*/
public function __construct(
$databaseName,
$tableName,
$tableEngine,
$displayField
) {
$this->databaseName = $databaseName;
$this->tableName = $tableName;
$this->tableEngine = $tableEngine;
$this->displayField = $displayField;
}
/**
* The table engine supports or not foreign keys
*
* @return bool
*/
public function supportsForeignkeys() {
return Util::isForeignKeySupported($this->tableEngine);
}
/**
* Get the database name
*
* @return string
*/
public function getDatabaseName() {
return $this->databaseName;
}
/**
* Get the table name
*
* @return string
*/
public function getTableName() {
return $this->tableName;
}
/**
* Get the table engine
*
* @return string
*/
public function getTableEngine() {
return $this->tableEngine;
}
/**
* Get the db and table speparated with a dot
*
* @return string
*/
public function getDbTableString() {
return $this->databaseName . '.' . $this->tableName;
}
}

View File

@ -1095,7 +1095,7 @@ class Export
Core::fatalError(__('Bad type!'));
}
$GLOBALS['dbi']->selectDb($GLOBALS['db']);
$export_plugin->exportSchema($GLOBALS['db']);
$GLOBALS['dbi']->selectDb($_POST['db']);
$export_plugin->exportSchema($_POST['db']);
}
}

View File

@ -245,14 +245,12 @@ class ExportRelationSchema
*/
protected function getTablesFromRequest()
{
$tables = array();
$dbLength = mb_strlen($this->db);
foreach ($_REQUEST['t_h'] as $key => $value) {
if ($value) {
$tables[] = mb_substr($key, $dbLength + 1);
$tables = [];
if (isset($_POST['t_tbl'])) {
foreach($_POST['t_tbl'] as $table) {
$tables[] = rawurldecode($table);
}
}
return $tables;
}
@ -301,7 +299,7 @@ class ExportRelationSchema
echo ' ' , $error_message , "\n";
echo '</p>' , "\n";
echo '<a href="db_designer.php'
, Url::getCommon(array('db' => $GLOBALS['db']))
, Url::getCommon(array('db' => $GLOBALS['db'], 'server' => $GLOBALS['server']))
, '&page=' . htmlspecialchars($pageNumber) , '">' , __('Back') , '</a>';
echo "\n";
exit;

View File

@ -130,11 +130,15 @@ abstract class TableStats
*/
protected function loadCoordinates()
{
foreach ($_REQUEST['t_h'] as $key => $value) {
if ($this->db . '.' . $this->tableName == $key) {
$this->x = (double) $_REQUEST['t_x'][$key];
$this->y = (double) $_REQUEST['t_y'][$key];
break;
if (isset($_POST['t_h'])) {
foreach ($_POST['t_h'] as $key => $value) {
$db = rawurldecode($_POST['t_db'][$key]);
$tbl = rawurldecode($_POST['t_tbl'][$key]);
if ($this->db . '.' . $this->tableName === $db . '.' . $tbl) {
$this->x = (double) $_POST['t_x'][$key];
$this->y = (double) $_POST['t_y'][$key];
break;
}
}
}
}

View File

@ -22,7 +22,7 @@ require_once 'libraries/common.inc.php';
$relation = new Relation();
$cfgRelation = $relation->getRelationsParam();
if (! isset($_REQUEST['export_type'])) {
if (! isset($_POST['export_type'])) {
Util::checkParameters(array('export_type'));
}
@ -30,4 +30,4 @@ if (! isset($_REQUEST['export_type'])) {
* Include the appropriate Schema Class depending on $export_type
* default is PDF
*/
Export::processExportSchema($_REQUEST['export_type']);
Export::processExportSchema($_POST['export_type']);

View File

@ -1,11 +1,14 @@
{% for t_n in table_names %}
{% for designerTable in tables %}
{% set i = loop.index0 %}
{% set t_n_url = table_names_url[i] %}
<input name="t_x[{{ t_n_url|url_encode }}]" type="hidden" id="t_x_{{ t_n_url|url_encode }}_" />
<input name="t_y[{{ t_n_url|url_encode }}]" type="hidden" id="t_y_{{ t_n_url|url_encode }}_" />
<input name="t_v[{{ t_n_url|url_encode }}]" type="hidden" id="t_v_{{ t_n_url|url_encode }}_" />
<input name="t_h[{{ t_n_url|url_encode }}]" type="hidden" id="t_h_{{ t_n_url|url_encode }}_" />
<table id="{{ t_n_url|url_encode }}"
{% set t_n_url = designerTable.getDbTableString()|escape('url') %}
{% set t_n = designerTable.getDbTableString() %}
<input name="t_x[{{ t_n_url }}]" type="hidden" id="t_x_{{ t_n_url }}_" />
<input name="t_y[{{ t_n_url }}]" type="hidden" id="t_y_{{ t_n_url }}_" />
<input name="t_v[{{ t_n_url }}]" type="hidden" id="t_v_{{ t_n_url }}_" />
<input name="t_h[{{ t_n_url }}]" type="hidden" id="t_h_{{ t_n_url }}_" />
<table id="{{ t_n_url }}"
db_url="{{ designerTable.getDatabaseName()|escape('url') }}"
table_name_url="{{ designerTable.getTableName()|escape('url') }}"
cellpadding="0"
cellspacing="0"
class="designer_tab"
@ -20,50 +23,50 @@
<input class="select_all_1"
type="checkbox"
style="margin: 0;"
value="select_all_{{ t_n_url|url_encode }}"
id="select_all_{{ t_n_url|url_encode }}"
value="select_all_{{ t_n_url }}"
id="select_all_{{ t_n_url }}"
title="select all"
designer_url_table_name="{{ t_n_url|url_encode }}"
designer_out_owner="{{ owner_out[i]|raw }}">
designer_url_table_name="{{ t_n_url }}"
designer_out_owner="{{ designerTable.getDatabaseName() }}">
</td>
{% endif %}
<td class="small_tab"
title="{% trans 'Show/hide columns' %}"
id="id_hide_tbody_{{ t_n_url|url_encode }}"
table_name="{{ t_n_url|url_encode }}">{{ tab_pos[t_n] is not defined or tab_pos[t_n]['V'] is not empty ? 'v' : '&gt;' }}</td>
id="id_hide_tbody_{{ t_n_url }}"
table_name="{{ t_n_url }}">{{ tab_pos[t_n] is not defined or tab_pos[t_n]['V'] is not empty ? 'v' : '&gt;' }}</td>
<td class="small_tab_pref small_tab_pref_1"
db="{{ db }}"
table_name_small="{{ table_names_small_url[i] }}">
db="{{ designerTable.getDatabaseName() }}"
db_url="{{ designerTable.getDatabaseName()|escape('url') }}"
table_name="{{ designerTable.getTableName() }}"
table_name_url="{{ designerTable.getTableName()|escape('url') }}">
<img src="{{ theme.getImgPath('designer/exec_small.png') }}"
title="{% trans 'See table structure' %}" />
</td>
<td id="id_zag_{{ t_n_url|url_encode }}"
<td id="id_zag_{{ t_n_url }}"
class="tab_zag nowrap tab_zag_noquery"
table_name="{{ t_n_url|url_encode }}"
table_name="{{ t_n_url }}"
query_set="{{ has_query ? 1 : 0 }}">
<span class="owner">
{{ owner_out[i]|raw }}
</span>
{{ table_names_small_out[i]|raw }}
<span class="owner">{{ designerTable.getDatabaseName() }}</span>
{{ designerTable.getTableName()|raw }}
</td>
{% if has_query %}
<td class="tab_zag tab_zag_query"
id="id_zag_{{ t_n_url|url_encode }}_2"
table_name="{{ t_n_url|url_encode }}">
id="id_zag_{{ t_n_url }}_2"
table_name="{{ t_n_url }}">
</td>
{% endif %}
</tr>
</thead>
<tbody id="id_tbody_{{ t_n_url|url_encode }}"
<tbody id="id_tbody_{{ t_n_url }}"
{{- tab_pos[t_n] is defined and tab_pos[t_n]['V'] is empty ? ' style="display: none"' }}>
{% set display_field = Relation_getDisplayField(get_db, table_names_small[i]) %}
{% set display_field = Relation_getDisplayField(get_db, t_n) %}
{% for j in 0..tab_column[t_n]['COLUMN_ID']|length - 1 %}
{% set tmp_column = t_n ~ '.' ~ tab_column[t_n]['COLUMN_NAME'][j] %}
{% set click_field_param = [
table_names_small_url[i],
t_n,
tab_column[t_n]['COLUMN_NAME'][j]|url_encode
] %}
{% if not Util_isForeignKeySupported(table_types[i]) %}
{% if not designerTable.supportsForeignkeys() %}
{% set click_field_param = click_field_param|merge([tables_pk_or_unique_keys[tmp_column] is defined ? 1 : 0]) %}
{% else %}
{# if foreign keys are supported, it's not necessary that the
@ -71,23 +74,23 @@
{% set click_field_param = click_field_param|merge([tables_all_keys[tmp_column] is defined ? 1 : 0]) %}
{% endif %}
{% set click_field_param = click_field_param|merge([db]) %}
<tr id="id_tr_{{ table_names_small_url[i] }}.{{ tab_column[t_n]['COLUMN_NAME'][j] }}" class="tab_field
<tr id="id_tr_{{ t_n }}.{{ tab_column[t_n]['COLUMN_NAME'][j] }}" class="tab_field
{{- display_field == tab_column[t_n]['COLUMN_NAME'][j] ? '_3' }}" click_field_param="
{{- click_field_param|join(',') }}">
{% if has_query %}
<td class="select_all">
<input class="select_all_store_col"
value="{{ t_n_url|url_encode }}{{ tab_column[t_n]['COLUMN_NAME'][j]|url_encode }}"
value="{{ t_n_url }}{{ tab_column[t_n]['COLUMN_NAME'][j]|url_encode }}"
type="checkbox"
id="select_{{ t_n_url|url_encode }}._{{ tab_column[t_n]['COLUMN_NAME'][j]|url_encode }}"
id="select_{{ t_n_url }}._{{ tab_column[t_n]['COLUMN_NAME'][j]|url_encode }}"
style="margin: 0;"
title="select_{{ tab_column[t_n]['COLUMN_NAME'][j]|url_encode }}"
store_column_param="{{ table_names_small_out[i]|url_encode }},
store_column_param="{{ t_n_url }},
{{- owner_out[i] }},
{{- tab_column[t_n]['COLUMN_NAME'][j]|url_encode }}">
</td>
{% endif %}
<td width="10px" colspan="3" id="{{ t_n_url|url_encode }}.
<td width="10px" colspan="3" id="{{ t_n_url }}.
{{- tab_column[t_n]['COLUMN_NAME'][j]|url_encode }}">
<div class="nowrap">
{% if tables_pk_or_unique_keys[t_n ~ '.' ~ tab_column[t_n]['COLUMN_NAME'][j]] is defined %}
@ -116,7 +119,7 @@
<td class="small_tab_pref small_tab_pref_click_opt"
click_option_param="designer_optionse,
{{- tab_column[t_n]['COLUMN_NAME'][j]|url_encode }},
{{- table_names_small_out[i] }}">
{{- t_n }}">
<img src="{{ theme.getImgPath('designer/exec_small.png') }}" title="options" />
</td>
{% endif %}