Translated using Weblate (Czech)
[phpmyadmin.git] / db_designer.php
blobab889adbe2f3a760db10c4131f1dcc0cbdafda8a
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * phpMyAdmin designer general code
6 * @package PhpMyAdmin-Designer
7 */
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);
19 global $db;
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(
44 $_POST['db'],
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(
55 $_POST['db'],
56 $script_display_field,
57 [],
58 -1,
59 $tab_column,
60 $tables_all_keys,
61 $tables_pk_or_unique_keys
65 if (! empty($html)) {
66 $response->addHTML($html);
68 return;
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'];
78 } else { // new
79 if ($designerCommon->getPageExists($_POST['selected_value'])) {
80 $response->addJSON(
81 'message',
82 /* l10n: The user tries to save a page with an existing name in Designer */
83 __(
84 sprintf(
85 "There already exists a page named \"%s\" please rename it to something else.",
86 htmlspecialchars($_POST['selected_value'])
90 $response->setRequestStatus(false);
91 return;
92 } else {
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') {
101 $success,
102 $message,
103 ] = $designerCommon->saveDisplayField(
104 $_POST['db'],
105 $_POST['table'],
106 $_POST['field']
108 $response->setRequestStatus($success);
109 $response->addJSON('message', $message);
110 } elseif ($_POST['operation'] == 'addNewRelation') {
111 list($success, $message) = $designerCommon->addNewRelation(
112 $_POST['db'],
113 $_POST['T1'],
114 $_POST['F1'],
115 $_POST['T2'],
116 $_POST['F2'],
117 $_POST['on_delete'],
118 $_POST['on_update'],
119 $_POST['DB1'],
120 $_POST['DB2']
122 $response->setRequestStatus($success);
123 $response->addJSON('message', $message);
124 } elseif ($_POST['operation'] == 'removeRelation') {
125 list($success, $message) = $designerCommon->removeRelation(
126 $_POST['T1'],
127 $_POST['F1'],
128 $_POST['T2'],
129 $_POST['F2']
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);
138 return;
141 require ROOT_PATH . 'libraries/db_common.inc.php';
143 $script_display_field = $designerCommon->getTablesInfo();
145 $display_page = -1;
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'];
152 } else {
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');
203 list(
204 $tables,
205 $num_tables,
206 $total_num_tables,
207 $sub_part,
208 $is_show_stats,
209 $db_is_system_schema,
210 $tooltip_truename,
211 $tooltip_aliasname,
212 $pos
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.
217 $response->addHTML(
218 $databaseDesigner->getHtmlForMain(
219 $db,
220 $_GET['db'],
221 $script_display_field,
222 $script_tables,
223 $script_contr,
224 $script_display_field,
225 $display_page,
226 isset($_GET['query']),
227 $selected_page,
228 $classes_side_menu,
229 $tab_pos,
230 $tab_column,
231 $tables_all_keys,
232 $tables_pk_or_unique_keys
236 $response->addHTML('<div id="PMA_disable_floating_menubar"></div>');