2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * phpMyAdmin designer general code
6 * @package PhpMyAdmin-Designer
8 declare(strict_types
=1);
10 use PhpMyAdmin\Database\Designer
;
11 use PhpMyAdmin\Database\Designer\Common
;
12 use PhpMyAdmin\DatabaseInterface
;
13 use PhpMyAdmin\Response
;
15 if (! defined('ROOT_PATH')) {
16 define('ROOT_PATH', __DIR__
. DIRECTORY_SEPARATOR
);
21 require_once ROOT_PATH
. 'libraries/common.inc.php';
23 /** @var Response $response */
24 $response = $containerBuilder->get(Response
::class);
26 /** @var DatabaseInterface $dbi */
27 $dbi = $containerBuilder->get(DatabaseInterface
::class);
29 /** @var Designer $databaseDesigner */
30 $databaseDesigner = $containerBuilder->get('designer');
32 /** @var Common $designerCommon */
33 $designerCommon = $containerBuilder->get('designer_common');
35 if (isset($_POST['dialog'])) {
36 if ($_POST['dialog'] == 'edit') {
37 $html = $databaseDesigner->getHtmlForEditOrDeletePages($_POST['db'], 'editPage');
38 } elseif ($_POST['dialog'] == 'delete') {
39 $html = $databaseDesigner->getHtmlForEditOrDeletePages($_POST['db'], 'deletePage');
40 } elseif ($_POST['dialog'] == 'save_as') {
41 $html = $databaseDesigner->getHtmlForPageSaveAs($_POST['db']);
42 } elseif ($_POST['dialog'] == 'export') {
43 $html = $databaseDesigner->getHtmlForSchemaExport(
45 $_POST['selected_page']
47 } elseif ($_POST['dialog'] == 'add_table') {
48 // Pass the db and table to the getTablesInfo so we only have the table we asked for
49 $script_display_field = $designerCommon->getTablesInfo($_POST['db'], $_POST['table']);
50 $tab_column = $designerCommon->getColumnsInfo($script_display_field);
51 $tables_all_keys = $designerCommon->getAllKeys($script_display_field);
52 $tables_pk_or_unique_keys = $designerCommon->getPkOrUniqueKeys($script_display_field);
54 $html = $databaseDesigner->getDatabaseTables(
56 $script_display_field,
61 $tables_pk_or_unique_keys
66 $response->addHTML($html);
71 if (isset($_POST['operation'])) {
72 if ($_POST['operation'] == 'deletePage') {
73 $success = $designerCommon->deletePage($_POST['selected_page']);
74 $response->setRequestStatus($success);
75 } elseif ($_POST['operation'] == 'savePage') {
76 if ($_POST['save_page'] == 'same') {
77 $page = $_POST['selected_page'];
79 $page = $designerCommon->createNewPage($_POST['selected_value'], $_POST['db']);
80 $response->addJSON('id', $page);
82 $success = $designerCommon->saveTablePositions($page);
83 $response->setRequestStatus($success);
84 } elseif ($_POST['operation'] == 'setDisplayField') {
88 ] = $designerCommon->saveDisplayField(
93 $response->setRequestStatus($success);
94 $response->addJSON('message', $message);
95 } elseif ($_POST['operation'] == 'addNewRelation') {
96 list($success, $message) = $designerCommon->addNewRelation(
107 $response->setRequestStatus($success);
108 $response->addJSON('message', $message);
109 } elseif ($_POST['operation'] == 'removeRelation') {
110 list($success, $message) = $designerCommon->removeRelation(
116 $response->setRequestStatus($success);
117 $response->addJSON('message', $message);
118 } elseif ($_POST['operation'] == 'save_setting_value') {
119 $success = $designerCommon->saveSetting($_POST['index'], $_POST['value']);
120 $response->setRequestStatus($success);
126 require ROOT_PATH
. 'libraries/db_common.inc.php';
128 $script_display_field = $designerCommon->getTablesInfo();
131 $selected_page = null;
133 if (isset($_GET['query'])) {
134 $display_page = $designerCommon->getDefaultPage($_GET['db']);
135 } elseif (! empty($_GET['page'])) {
136 $display_page = $_GET['page'];
138 $display_page = $designerCommon->getLoadingPage($_GET['db']);
140 if ($display_page != -1) {
141 $selected_page = $designerCommon->getPageName($display_page);
143 $tab_pos = $designerCommon->getTablePositions($display_page);
145 $fullTableNames = [];
147 foreach ($script_display_field as $designerTable) {
148 $fullTableNames[] = $designerTable->getDbTableString();
151 foreach ($tab_pos as $position) {
152 if (! in_array($position['dbName'] . '.' . $position['tableName'], $fullTableNames)) {
153 foreach ($designerCommon->getTablesInfo($position['dbName'], $position['tableName']) as $designerTable) {
154 $script_display_field[] = $designerTable;
160 $tab_column = $designerCommon->getColumnsInfo($script_display_field);
161 $script_tables = $designerCommon->getScriptTabs($script_display_field);
162 $tables_pk_or_unique_keys = $designerCommon->getPkOrUniqueKeys($script_display_field);
163 $tables_all_keys = $designerCommon->getAllKeys($script_display_field);
164 $classes_side_menu = $databaseDesigner->returnClassNamesFromMenuButtons();
167 $script_contr = $designerCommon->getScriptContr($script_display_field);
169 $params = ['lang' => $GLOBALS['lang']];
170 if (isset($_GET['db'])) {
171 $params['db'] = $_GET['db'];
174 $response = Response
::getInstance();
175 $response->getFooter()->setMinimal();
176 $header = $response->getHeader();
177 $header->setBodyId('designer_body');
179 $scripts = $header->getScripts();
180 $scripts->addFile('vendor/jquery/jquery.fullscreen.js');
181 $scripts->addFile('designer/database.js');
182 $scripts->addFile('designer/objects.js');
183 $scripts->addFile('designer/page.js');
184 $scripts->addFile('designer/history.js');
185 $scripts->addFile('designer/move.js');
186 $scripts->addFile('designer/init.js');
194 $db_is_system_schema,
198 ) = PhpMyAdmin\Util
::getDbInfo($db, isset($sub_part) ?
$sub_part : '');
200 // Embed some data into HTML, later it will be read
201 // by designer/init.js and converted to JS variables.
203 $databaseDesigner->getHtmlForMain(
206 $script_display_field,
209 $script_display_field,
211 isset($_GET['query']),
217 $tables_pk_or_unique_keys
221 $response->addHTML('<div id="PMA_disable_floating_menubar"></div>');