2018-04-14 09:18:00 +00:00
|
|
|
<?php
|
|
|
|
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
|
|
|
/**
|
|
|
|
* phpMyAdmin designer general code
|
|
|
|
*
|
|
|
|
* @package PhpMyAdmin-Designer
|
|
|
|
*/
|
|
|
|
use PhpMyAdmin\Database\Designer;
|
|
|
|
use PhpMyAdmin\Database\Designer\Common;
|
|
|
|
use PhpMyAdmin\Response;
|
|
|
|
|
|
|
|
require_once 'libraries/common.inc.php';
|
|
|
|
|
|
|
|
$response = Response::getInstance();
|
|
|
|
|
|
|
|
$databaseDesigner = new Designer();
|
|
|
|
$designerCommon = new Common();
|
|
|
|
|
2019-12-08 07:14:01 +00:00
|
|
|
if (isset($_POST['dialog'])) {
|
|
|
|
|
|
|
|
if ($_POST['dialog'] == 'edit') {
|
|
|
|
$html = $databaseDesigner->getHtmlForEditOrDeletePages($_POST['db'], 'editPage');
|
|
|
|
} elseif ($_POST['dialog'] == 'delete') {
|
|
|
|
$html = $databaseDesigner->getHtmlForEditOrDeletePages($_POST['db'], 'deletePage');
|
|
|
|
} elseif ($_POST['dialog'] == 'save_as') {
|
|
|
|
$html = $databaseDesigner->getHtmlForPageSaveAs($_POST['db']);
|
|
|
|
} elseif ($_POST['dialog'] == 'export') {
|
2018-04-14 09:18:00 +00:00
|
|
|
$html = $databaseDesigner->getHtmlForSchemaExport(
|
2019-12-08 07:14:01 +00:00
|
|
|
$_POST['db'], $_POST['selected_page']
|
2018-04-14 09:18:00 +00:00
|
|
|
);
|
2018-12-16 14:31:03 +00:00
|
|
|
} elseif ($_POST['dialog'] == 'add_table') {
|
2019-12-08 07:14:01 +00:00
|
|
|
// 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);
|
2018-04-14 09:18:00 +00:00
|
|
|
|
|
|
|
$html = $databaseDesigner->getDatabaseTables(
|
2019-12-08 07:14:01 +00:00
|
|
|
$_POST['db'],
|
|
|
|
$script_display_field,
|
2018-04-14 09:18:00 +00:00
|
|
|
array(), -1, $tab_column,
|
|
|
|
$tables_all_keys, $tables_pk_or_unique_keys
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! empty($html)) {
|
|
|
|
$response->addHTML($html);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-16 14:31:03 +00:00
|
|
|
if (isset($_POST['operation'])) {
|
2018-04-14 09:18:00 +00:00
|
|
|
|
2018-12-16 14:31:03 +00:00
|
|
|
if ($_POST['operation'] == 'deletePage') {
|
|
|
|
$success = $designerCommon->deletePage($_POST['selected_page']);
|
2018-04-14 09:18:00 +00:00
|
|
|
$response->setRequestStatus($success);
|
2018-12-16 14:31:03 +00:00
|
|
|
} elseif ($_POST['operation'] == 'savePage') {
|
|
|
|
if ($_POST['save_page'] == 'same') {
|
|
|
|
$page = $_POST['selected_page'];
|
2018-04-14 09:18:00 +00:00
|
|
|
} else { // new
|
2019-12-08 07:14:01 +00:00
|
|
|
$page = $designerCommon->createNewPage($_POST['selected_value'], $_POST['db']);
|
2018-04-14 09:18:00 +00:00
|
|
|
$response->addJSON('id', $page);
|
|
|
|
}
|
|
|
|
$success = $designerCommon->saveTablePositions($page);
|
|
|
|
$response->setRequestStatus($success);
|
2018-12-16 14:31:03 +00:00
|
|
|
} elseif ($_POST['operation'] == 'setDisplayField') {
|
2019-12-08 07:14:01 +00:00
|
|
|
[
|
|
|
|
$success,
|
|
|
|
$message,
|
|
|
|
] = $designerCommon->saveDisplayField(
|
|
|
|
$_POST['db'],
|
|
|
|
$_POST['table'],
|
|
|
|
$_POST['field']
|
2018-04-14 09:18:00 +00:00
|
|
|
);
|
2019-12-08 07:14:01 +00:00
|
|
|
$response->setRequestStatus($success);
|
|
|
|
$response->addJSON('message', $message);
|
2018-12-16 14:31:03 +00:00
|
|
|
} elseif ($_POST['operation'] == 'addNewRelation') {
|
2018-04-14 09:18:00 +00:00
|
|
|
list($success, $message) = $designerCommon->addNewRelation(
|
2018-12-16 14:31:03 +00:00
|
|
|
$_POST['db'],
|
|
|
|
$_POST['T1'],
|
|
|
|
$_POST['F1'],
|
|
|
|
$_POST['T2'],
|
|
|
|
$_POST['F2'],
|
|
|
|
$_POST['on_delete'],
|
|
|
|
$_POST['on_update'],
|
|
|
|
$_POST['DB1'],
|
|
|
|
$_POST['DB2']
|
2018-04-14 09:18:00 +00:00
|
|
|
);
|
|
|
|
$response->setRequestStatus($success);
|
|
|
|
$response->addJSON('message', $message);
|
2018-12-16 14:31:03 +00:00
|
|
|
} elseif ($_POST['operation'] == 'removeRelation') {
|
2018-04-14 09:18:00 +00:00
|
|
|
list($success, $message) = $designerCommon->removeRelation(
|
2018-12-16 14:31:03 +00:00
|
|
|
$_POST['T1'],
|
|
|
|
$_POST['F1'],
|
|
|
|
$_POST['T2'],
|
|
|
|
$_POST['F2']
|
2018-04-14 09:18:00 +00:00
|
|
|
);
|
|
|
|
$response->setRequestStatus($success);
|
|
|
|
$response->addJSON('message', $message);
|
2018-12-16 14:31:03 +00:00
|
|
|
} elseif ($_POST['operation'] == 'save_setting_value') {
|
|
|
|
$success = $designerCommon->saveSetting($_POST['index'], $_POST['value']);
|
2018-04-14 09:18:00 +00:00
|
|
|
$response->setRequestStatus($success);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
require 'libraries/db_common.inc.php';
|
|
|
|
|
|
|
|
$script_display_field = $designerCommon->getTablesInfo();
|
|
|
|
|
|
|
|
$display_page = -1;
|
|
|
|
$selected_page = null;
|
|
|
|
|
2018-12-16 14:31:03 +00:00
|
|
|
if (isset($_GET['query'])) {
|
|
|
|
$display_page = $designerCommon->getDefaultPage($_GET['db']);
|
2018-04-14 09:18:00 +00:00
|
|
|
} else {
|
2018-12-16 14:31:03 +00:00
|
|
|
if (! empty($_GET['page'])) {
|
|
|
|
$display_page = $_GET['page'];
|
2018-04-14 09:18:00 +00:00
|
|
|
} else {
|
2018-12-16 14:31:03 +00:00
|
|
|
$display_page = $designerCommon->getLoadingPage($_GET['db']);
|
2018-04-14 09:18:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($display_page != -1) {
|
|
|
|
$selected_page = $designerCommon->getPageName($display_page);
|
|
|
|
}
|
|
|
|
$tab_pos = $designerCommon->getTablePositions($display_page);
|
2019-12-08 07:14:01 +00:00
|
|
|
|
|
|
|
$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);
|
2018-04-14 09:18:00 +00:00
|
|
|
|
|
|
|
$params = array('lang' => $GLOBALS['lang']);
|
|
|
|
if (isset($_GET['db'])) {
|
|
|
|
$params['db'] = $_GET['db'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$response = Response::getInstance();
|
|
|
|
$response->getFooter()->setMinimal();
|
|
|
|
$header = $response->getHeader();
|
|
|
|
$header->setBodyId('designer_body');
|
|
|
|
|
|
|
|
$scripts = $header->getScripts();
|
|
|
|
$scripts->addFile('vendor/jquery/jquery.fullscreen.js');
|
|
|
|
$scripts->addFile('designer/database.js');
|
|
|
|
$scripts->addFile('designer/objects.js');
|
|
|
|
$scripts->addFile('designer/page.js');
|
|
|
|
$scripts->addFile('designer/history.js');
|
|
|
|
$scripts->addFile('designer/move.js');
|
|
|
|
$scripts->addFile('designer/init.js');
|
|
|
|
|
|
|
|
list(
|
|
|
|
$tables,
|
|
|
|
$num_tables,
|
|
|
|
$total_num_tables,
|
|
|
|
$sub_part,
|
|
|
|
$is_show_stats,
|
|
|
|
$db_is_system_schema,
|
|
|
|
$tooltip_truename,
|
|
|
|
$tooltip_aliasname,
|
|
|
|
$pos
|
|
|
|
) = PhpMyAdmin\Util::getDbInfo($db, isset($sub_part) ? $sub_part : '');
|
|
|
|
|
|
|
|
// Embed some data into HTML, later it will be read
|
|
|
|
// by designer/init.js and converted to JS variables.
|
|
|
|
$response->addHTML(
|
|
|
|
$databaseDesigner->getHtmlForJsFields(
|
|
|
|
$script_tables, $script_contr, $script_display_field, $display_page
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$response->addHTML(
|
|
|
|
$databaseDesigner->getPageMenu(
|
2018-12-16 14:31:03 +00:00
|
|
|
isset($_GET['query']),
|
2018-04-14 09:18:00 +00:00
|
|
|
$selected_page,
|
|
|
|
$classes_side_menu
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$response->addHTML('<div id="canvas_outer">');
|
|
|
|
$response->addHTML(
|
2019-12-08 07:14:01 +00:00
|
|
|
'<form action="" id="container-form" method="post">'
|
2018-04-14 09:18:00 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$response->addHTML($databaseDesigner->getHtmlCanvas());
|
2019-12-08 07:14:01 +00:00
|
|
|
$response->addHTML($databaseDesigner->getHtmlTableList());
|
2018-04-14 09:18:00 +00:00
|
|
|
|
|
|
|
$response->addHTML(
|
|
|
|
$databaseDesigner->getDatabaseTables(
|
2019-12-08 07:14:01 +00:00
|
|
|
$_GET['db'],
|
|
|
|
$script_display_field,
|
2018-04-14 09:18:00 +00:00
|
|
|
$tab_pos, $display_page, $tab_column,
|
|
|
|
$tables_all_keys, $tables_pk_or_unique_keys
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$response->addHTML('</form>');
|
|
|
|
$response->addHTML('</div>'); // end canvas_outer
|
|
|
|
|
|
|
|
$response->addHTML('<div id="designer_hint"></div>');
|
|
|
|
|
|
|
|
$response->addHTML($databaseDesigner->getNewRelationPanel());
|
|
|
|
$response->addHTML($databaseDesigner->getDeleteRelationPanel());
|
|
|
|
|
2018-12-16 14:31:03 +00:00
|
|
|
if (isset($_GET['query'])) {
|
2018-04-14 09:18:00 +00:00
|
|
|
$response->addHTML($databaseDesigner->getOptionsPanel());
|
|
|
|
$response->addHTML($databaseDesigner->getRenameToPanel());
|
|
|
|
$response->addHTML($databaseDesigner->getHavingQueryPanel());
|
|
|
|
$response->addHTML($databaseDesigner->getAggregateQueryPanel());
|
|
|
|
$response->addHTML($databaseDesigner->getWhereQueryPanel());
|
|
|
|
$response->addHTML($databaseDesigner->getQueryDetails($_GET['db']));
|
|
|
|
}
|
|
|
|
|
|
|
|
$response->addHTML('<div id="PMA_disable_floating_menubar"></div>');
|