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 if ($designerCommon->getPageExists($_POST['selected_value'])) {
82 /* l10n: The user tries to save a page with an existing name in Designer */
85 "There already exists a page named \"%s\" please rename it to something else.",
86 htmlspecialchars($_POST['selected_value'])
90 $response->setRequestStatus(false);
93 $page = $designerCommon->createNewPage($_POST['selected_value'], $_POST['db']);
94 $response->addJSON('id', $page);
97 $success = $designerCommon->saveTablePositions($page);
98 $response->setRequestStatus($success);
99 } elseif ($_POST['operation'] == 'setDisplayField') {
103 ] = $designerCommon->saveDisplayField(
108 $response->setRequestStatus($success);
109 $response->addJSON('message', $message);
110 } elseif ($_POST['operation'] == 'addNewRelation') {
111 list($success, $message) = $designerCommon->addNewRelation(
122 $response->setRequestStatus($success);
123 $response->addJSON('message', $message);
124 } elseif ($_POST['operation'] == 'removeRelation') {
125 list($success, $message) = $designerCommon->removeRelation(
131 $response->setRequestStatus($success);
132 $response->addJSON('message', $message);
133 } elseif ($_POST['operation'] == 'save_setting_value') {
134 $success = $designerCommon->saveSetting($_POST['index'], $_POST['value']);
135 $response->setRequestStatus($success);
141 require ROOT_PATH
. 'libraries/db_common.inc.php';
143 $script_display_field = $designerCommon->getTablesInfo();
146 $selected_page = null;
148 if (isset($_GET['query'])) {
149 $display_page = $designerCommon->getDefaultPage($_GET['db']);
150 } elseif (! empty($_GET['page'])) {
151 $display_page = $_GET['page'];
153 $display_page = $designerCommon->getLoadingPage($_GET['db']);
155 if ($display_page != -1) {
156 $selected_page = $designerCommon->getPageName($display_page);
158 $tab_pos = $designerCommon->getTablePositions($display_page);
160 $fullTableNames = [];
162 foreach ($script_display_field as $designerTable) {
163 $fullTableNames[] = $designerTable->getDbTableString();
166 foreach ($tab_pos as $position) {
167 if (! in_array($position['dbName'] . '.' . $position['tableName'], $fullTableNames)) {
168 foreach ($designerCommon->getTablesInfo($position['dbName'], $position['tableName']) as $designerTable) {
169 $script_display_field[] = $designerTable;
175 $tab_column = $designerCommon->getColumnsInfo($script_display_field);
176 $script_tables = $designerCommon->getScriptTabs($script_display_field);
177 $tables_pk_or_unique_keys = $designerCommon->getPkOrUniqueKeys($script_display_field);
178 $tables_all_keys = $designerCommon->getAllKeys($script_display_field);
179 $classes_side_menu = $databaseDesigner->returnClassNamesFromMenuButtons();
182 $script_contr = $designerCommon->getScriptContr($script_display_field);
184 $params = ['lang' => $GLOBALS['lang']];
185 if (isset($_GET['db'])) {
186 $params['db'] = $_GET['db'];
189 $response = Response
::getInstance();
190 $response->getFooter()->setMinimal();
191 $header = $response->getHeader();
192 $header->setBodyId('designer_body');
194 $scripts = $header->getScripts();
195 $scripts->addFile('vendor/jquery/jquery.fullscreen.js');
196 $scripts->addFile('designer/database.js');
197 $scripts->addFile('designer/objects.js');
198 $scripts->addFile('designer/page.js');
199 $scripts->addFile('designer/history.js');
200 $scripts->addFile('designer/move.js');
201 $scripts->addFile('designer/init.js');
209 $db_is_system_schema,
213 ) = PhpMyAdmin\Util
::getDbInfo($db, isset($sub_part) ?
$sub_part : '');
215 // Embed some data into HTML, later it will be read
216 // by designer/init.js and converted to JS variables.
218 $databaseDesigner->getHtmlForMain(
221 $script_display_field,
224 $script_display_field,
226 isset($_GET['query']),
232 $tables_pk_or_unique_keys
236 $response->addHTML('<div id="PMA_disable_floating_menubar"></div>');