Translated using Weblate (Turkish)
[phpmyadmin.git] / db_designer.php
blob064b4b2bef009273608cb993b8c995631be30152
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 $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') {
86 $success,
87 $message,
88 ] = $designerCommon->saveDisplayField(
89 $_POST['db'],
90 $_POST['table'],
91 $_POST['field']
93 $response->setRequestStatus($success);
94 $response->addJSON('message', $message);
95 } elseif ($_POST['operation'] == 'addNewRelation') {
96 list($success, $message) = $designerCommon->addNewRelation(
97 $_POST['db'],
98 $_POST['T1'],
99 $_POST['F1'],
100 $_POST['T2'],
101 $_POST['F2'],
102 $_POST['on_delete'],
103 $_POST['on_update'],
104 $_POST['DB1'],
105 $_POST['DB2']
107 $response->setRequestStatus($success);
108 $response->addJSON('message', $message);
109 } elseif ($_POST['operation'] == 'removeRelation') {
110 list($success, $message) = $designerCommon->removeRelation(
111 $_POST['T1'],
112 $_POST['F1'],
113 $_POST['T2'],
114 $_POST['F2']
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);
123 return;
126 require ROOT_PATH . 'libraries/db_common.inc.php';
128 $script_display_field = $designerCommon->getTablesInfo();
130 $display_page = -1;
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'];
137 } else {
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');
188 list(
189 $tables,
190 $num_tables,
191 $total_num_tables,
192 $sub_part,
193 $is_show_stats,
194 $db_is_system_schema,
195 $tooltip_truename,
196 $tooltip_aliasname,
197 $pos
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.
202 $response->addHTML(
203 $databaseDesigner->getHtmlForMain(
204 $db,
205 $_GET['db'],
206 $script_display_field,
207 $script_tables,
208 $script_contr,
209 $script_display_field,
210 $display_page,
211 isset($_GET['query']),
212 $selected_page,
213 $classes_side_menu,
214 $tab_pos,
215 $tab_column,
216 $tables_all_keys,
217 $tables_pk_or_unique_keys
221 $response->addHTML('<div id="PMA_disable_floating_menubar"></div>');