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($db, 'editPage');
38 } elseif ($_POST['dialog'] == 'delete') {
39 $html = $databaseDesigner->getHtmlForEditOrDeletePages($db, 'deletePage');
40 } elseif ($_POST['dialog'] == 'save_as') {
41 $html = $databaseDesigner->getHtmlForPageSaveAs($db);
42 } elseif ($_POST['dialog'] == 'export') {
43 $html = $databaseDesigner->getHtmlForSchemaExport(
45 $_POST['selected_page']
47 } elseif ($_POST['dialog'] == 'add_table') {
48 $script_display_field = $designerCommon->getTablesInfo();
49 $required = $db . '.' . $GLOBALS['table'];
50 $tab_column = $designerCommon->getColumnsInfo();
51 $tables_all_keys = $designerCommon->getAllKeys();
52 $tables_pk_or_unique_keys = $designerCommon->getPkOrUniqueKeys();
54 $req_key = array_search($required, $GLOBALS['designer']['TABLE_NAME']);
56 $GLOBALS['designer']['TABLE_NAME'] = [$GLOBALS['designer']['TABLE_NAME'][$req_key]];
57 $GLOBALS['designer_url']['TABLE_NAME_SMALL'] = [$GLOBALS['designer_url']['TABLE_NAME_SMALL'][$req_key]];
58 $GLOBALS['designer']['TABLE_NAME_SMALL'] = [$GLOBALS['designer']['TABLE_NAME_SMALL'][$req_key]];
59 $GLOBALS['designer_out']['TABLE_NAME_SMALL'] = [$GLOBALS['designer_out']['TABLE_NAME_SMALL'][$req_key]];
60 $GLOBALS['designer']['TABLE_TYPE'] = [$GLOBALS['designer_url']['TABLE_TYPE'][$req_key]];
61 $GLOBALS['designer_out']['OWNER'] = [$GLOBALS['designer_out']['OWNER'][$req_key]];
63 $html = $databaseDesigner->getDatabaseTables(
68 $tables_pk_or_unique_keys
73 $response->addHTML($html);
78 if (isset($_POST['operation'])) {
79 if ($_POST['operation'] == 'deletePage') {
80 $success = $designerCommon->deletePage($_POST['selected_page']);
81 $response->setRequestStatus($success);
82 } elseif ($_POST['operation'] == 'savePage') {
83 if ($_POST['save_page'] == 'same') {
84 $page = $_POST['selected_page'];
86 $page = $designerCommon->createNewPage($_POST['selected_value'], $db);
87 $response->addJSON('id', $page);
89 $success = $designerCommon->saveTablePositions($page);
90 $response->setRequestStatus($success);
91 } elseif ($_POST['operation'] == 'setDisplayField') {
92 $designerCommon->saveDisplayField(
97 $response->setRequestStatus(true);
98 } elseif ($_POST['operation'] == 'addNewRelation') {
99 list($success, $message) = $designerCommon->addNewRelation(
110 $response->setRequestStatus($success);
111 $response->addJSON('message', $message);
112 } elseif ($_POST['operation'] == 'removeRelation') {
113 list($success, $message) = $designerCommon->removeRelation(
119 $response->setRequestStatus($success);
120 $response->addJSON('message', $message);
121 } elseif ($_POST['operation'] == 'save_setting_value') {
122 $success = $designerCommon->saveSetting($_POST['index'], $_POST['value']);
123 $response->setRequestStatus($success);
129 require ROOT_PATH
. 'libraries/db_common.inc.php';
131 $script_display_field = $designerCommon->getTablesInfo();
132 $tab_column = $designerCommon->getColumnsInfo();
133 $script_tables = $designerCommon->getScriptTabs();
134 $tables_pk_or_unique_keys = $designerCommon->getPkOrUniqueKeys();
135 $tables_all_keys = $designerCommon->getAllKeys();
136 $classes_side_menu = $databaseDesigner->returnClassNamesFromMenuButtons();
139 $selected_page = null;
141 if (isset($_GET['query'])) {
142 $display_page = $designerCommon->getDefaultPage($_GET['db']);
143 } elseif (! empty($_GET['page'])) {
144 $display_page = $_GET['page'];
146 $display_page = $designerCommon->getLoadingPage($_GET['db']);
148 if ($display_page != -1) {
149 $selected_page = $designerCommon->getPageName($display_page);
151 $tab_pos = $designerCommon->getTablePositions($display_page);
152 $script_contr = $designerCommon->getScriptContr();
154 $params = ['lang' => $GLOBALS['lang']];
155 if (isset($_GET['db'])) {
156 $params['db'] = $_GET['db'];
159 $response = Response
::getInstance();
160 $response->getFooter()->setMinimal();
161 $header = $response->getHeader();
162 $header->setBodyId('designer_body');
164 $scripts = $header->getScripts();
165 $scripts->addFile('vendor/jquery/jquery.fullscreen.js');
166 $scripts->addFile('designer/database.js');
167 $scripts->addFile('designer/objects.js');
168 $scripts->addFile('designer/page.js');
169 $scripts->addFile('designer/history.js');
170 $scripts->addFile('designer/move.js');
171 $scripts->addFile('designer/init.js');
179 $db_is_system_schema,
183 ) = PhpMyAdmin\Util
::getDbInfo($db, isset($sub_part) ?
$sub_part : '');
185 // Embed some data into HTML, later it will be read
186 // by designer/init.js and converted to JS variables.
188 $databaseDesigner->getHtmlForMain(
193 $script_display_field,
195 isset($_GET['query']),
201 $tables_pk_or_unique_keys
205 $response->addHTML('<div id="PMA_disable_floating_menubar"></div>');