2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * phpMyAdmin designer general code
6 * @package PhpMyAdmin-Designer
8 use PhpMyAdmin\Database\Designer
;
9 use PhpMyAdmin\Database\Designer\Common
;
10 use PhpMyAdmin\Response
;
12 require_once 'libraries/common.inc.php';
14 $response = Response
::getInstance();
16 $databaseDesigner = new Designer();
17 $designerCommon = new Common();
19 if (isset($_POST['dialog'])) {
21 if ($_POST['dialog'] == 'edit') {
22 $html = $databaseDesigner->getHtmlForEditOrDeletePages($_POST['db'], 'editPage');
23 } elseif ($_POST['dialog'] == 'delete') {
24 $html = $databaseDesigner->getHtmlForEditOrDeletePages($_POST['db'], 'deletePage');
25 } elseif ($_POST['dialog'] == 'save_as') {
26 $html = $databaseDesigner->getHtmlForPageSaveAs($_POST['db']);
27 } elseif ($_POST['dialog'] == 'export') {
28 $html = $databaseDesigner->getHtmlForSchemaExport(
29 $_POST['db'], $_POST['selected_page']
31 } elseif ($_POST['dialog'] == 'add_table') {
32 // Pass the db and table to the getTablesInfo so we only have the table we asked for
33 $script_display_field = $designerCommon->getTablesInfo($_POST['db'], $_POST['table']);
34 $tab_column = $designerCommon->getColumnsInfo($script_display_field);
35 $tables_all_keys = $designerCommon->getAllKeys($script_display_field);
36 $tables_pk_or_unique_keys = $designerCommon->getPkOrUniqueKeys($script_display_field);
38 $html = $databaseDesigner->getDatabaseTables(
40 $script_display_field,
41 array(), -1, $tab_column,
42 $tables_all_keys, $tables_pk_or_unique_keys
47 $response->addHTML($html);
52 if (isset($_POST['operation'])) {
54 if ($_POST['operation'] == 'deletePage') {
55 $success = $designerCommon->deletePage($_POST['selected_page']);
56 $response->setRequestStatus($success);
57 } elseif ($_POST['operation'] == 'savePage') {
58 if ($_POST['save_page'] == 'same') {
59 $page = $_POST['selected_page'];
61 $page = $designerCommon->createNewPage($_POST['selected_value'], $_POST['db']);
62 $response->addJSON('id', $page);
64 $success = $designerCommon->saveTablePositions($page);
65 $response->setRequestStatus($success);
66 } elseif ($_POST['operation'] == 'setDisplayField') {
67 $designerCommon->saveDisplayField(
68 $_POST['db'], $_POST['table'], $_POST['field']
70 $response->setRequestStatus(true);
71 } elseif ($_POST['operation'] == 'addNewRelation') {
72 list($success, $message) = $designerCommon->addNewRelation(
83 $response->setRequestStatus($success);
84 $response->addJSON('message', $message);
85 } elseif ($_POST['operation'] == 'removeRelation') {
86 list($success, $message) = $designerCommon->removeRelation(
92 $response->setRequestStatus($success);
93 $response->addJSON('message', $message);
94 } elseif ($_POST['operation'] == 'save_setting_value') {
95 $success = $designerCommon->saveSetting($_POST['index'], $_POST['value']);
96 $response->setRequestStatus($success);
102 require 'libraries/db_common.inc.php';
104 $script_display_field = $designerCommon->getTablesInfo();
107 $selected_page = null;
109 if (isset($_GET['query'])) {
110 $display_page = $designerCommon->getDefaultPage($_GET['db']);
112 if (! empty($_GET['page'])) {
113 $display_page = $_GET['page'];
115 $display_page = $designerCommon->getLoadingPage($_GET['db']);
118 if ($display_page != -1) {
119 $selected_page = $designerCommon->getPageName($display_page);
121 $tab_pos = $designerCommon->getTablePositions($display_page);
123 $fullTableNames = [];
125 foreach($script_display_field as $designerTable) {
126 $fullTableNames[] = $designerTable->getDbTableString();
129 foreach($tab_pos as $position) {
130 if (! in_array($position['dbName'] . '.' . $position['tableName'], $fullTableNames)) {
131 foreach($designerCommon->getTablesInfo($position['dbName'], $position['tableName']) as $designerTable) {
132 $script_display_field[] = $designerTable;
138 $tab_column = $designerCommon->getColumnsInfo($script_display_field);
139 $script_tables = $designerCommon->getScriptTabs($script_display_field);
140 $tables_pk_or_unique_keys = $designerCommon->getPkOrUniqueKeys($script_display_field);
141 $tables_all_keys = $designerCommon->getAllKeys($script_display_field);
142 $classes_side_menu = $databaseDesigner->returnClassNamesFromMenuButtons();
145 $script_contr = $designerCommon->getScriptContr($script_display_field);
147 $params = array('lang' => $GLOBALS['lang']);
148 if (isset($_GET['db'])) {
149 $params['db'] = $_GET['db'];
152 $response = Response
::getInstance();
153 $response->getFooter()->setMinimal();
154 $header = $response->getHeader();
155 $header->setBodyId('designer_body');
157 $scripts = $header->getScripts();
158 $scripts->addFile('vendor/jquery/jquery.fullscreen.js');
159 $scripts->addFile('designer/database.js');
160 $scripts->addFile('designer/objects.js');
161 $scripts->addFile('designer/page.js');
162 $scripts->addFile('designer/history.js');
163 $scripts->addFile('designer/move.js');
164 $scripts->addFile('designer/init.js');
172 $db_is_system_schema,
176 ) = PhpMyAdmin\Util
::getDbInfo($db, isset($sub_part) ?
$sub_part : '');
178 // Embed some data into HTML, later it will be read
179 // by designer/init.js and converted to JS variables.
181 $databaseDesigner->getHtmlForJsFields(
182 $script_tables, $script_contr, $script_display_field, $display_page
186 $databaseDesigner->getPageMenu(
187 isset($_GET['query']),
195 $response->addHTML('<div id="canvas_outer">');
197 '<form action="" id="container-form" method="post" name="form1">'
200 $response->addHTML($databaseDesigner->getHtmlCanvas());
201 $response->addHTML($databaseDesigner->getHtmlTableList());
204 $databaseDesigner->getDatabaseTables(
206 $script_display_field,
207 $tab_pos, $display_page, $tab_column,
208 $tables_all_keys, $tables_pk_or_unique_keys
211 $response->addHTML('</form>');
212 $response->addHTML('</div>'); // end canvas_outer
214 $response->addHTML('<div id="designer_hint"></div>');
216 $response->addHTML($databaseDesigner->getNewRelationPanel());
217 $response->addHTML($databaseDesigner->getDeleteRelationPanel());
219 if (isset($_GET['query'])) {
220 $response->addHTML($databaseDesigner->getOptionsPanel());
221 $response->addHTML($databaseDesigner->getRenameToPanel());
222 $response->addHTML($databaseDesigner->getHavingQueryPanel());
223 $response->addHTML($databaseDesigner->getAggregateQueryPanel());
224 $response->addHTML($databaseDesigner->getWhereQueryPanel());
225 $response->addHTML($databaseDesigner->getQueryDetails($_GET['db']));
228 $response->addHTML('<div id="PMA_disable_floating_menubar"></div>');