Translated using Weblate (Portuguese)
[phpmyadmin.git] / db_designer.php
blob0dc2c022fb1d35f31688eb9d9c42012acbb75b6b
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($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(
44 $db,
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(
64 [],
65 -1,
66 $tab_column,
67 $tables_all_keys,
68 $tables_pk_or_unique_keys
72 if (! empty($html)) {
73 $response->addHTML($html);
75 return;
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'];
85 } else { // new
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(
93 $_POST['db'],
94 $_POST['table'],
95 $_POST['field']
97 $response->setRequestStatus(true);
98 } elseif ($_POST['operation'] == 'addNewRelation') {
99 list($success, $message) = $designerCommon->addNewRelation(
100 $_POST['db'],
101 $_POST['T1'],
102 $_POST['F1'],
103 $_POST['T2'],
104 $_POST['F2'],
105 $_POST['on_delete'],
106 $_POST['on_update'],
107 $_POST['DB1'],
108 $_POST['DB2']
110 $response->setRequestStatus($success);
111 $response->addJSON('message', $message);
112 } elseif ($_POST['operation'] == 'removeRelation') {
113 list($success, $message) = $designerCommon->removeRelation(
114 $_POST['T1'],
115 $_POST['F1'],
116 $_POST['T2'],
117 $_POST['F2']
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);
126 return;
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();
138 $display_page = -1;
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'];
145 } else {
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');
173 list(
174 $tables,
175 $num_tables,
176 $total_num_tables,
177 $sub_part,
178 $is_show_stats,
179 $db_is_system_schema,
180 $tooltip_truename,
181 $tooltip_aliasname,
182 $pos
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.
187 $response->addHTML(
188 $databaseDesigner->getHtmlForMain(
189 $db,
190 $_GET['db'],
191 $script_tables,
192 $script_contr,
193 $script_display_field,
194 $display_page,
195 isset($_GET['query']),
196 $selected_page,
197 $classes_side_menu,
198 $tab_pos,
199 $tab_column,
200 $tables_all_keys,
201 $tables_pk_or_unique_keys
205 $response->addHTML('<div id="PMA_disable_floating_menubar"></div>');