Merge pull request #14825 from williamdes/issue-14478-export-stream
[phpmyadmin.git] / db_designer.php
blobdf9a866a2383bdebfc48c02e9f5533ca73b26bb9
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * phpMyAdmin designer general code
6 * @package PhpMyAdmin-Designer
7 */
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($_REQUEST['dialog'])) {
21 if ($_GET['dialog'] == 'edit') {
22 $html = $databaseDesigner->getHtmlForEditOrDeletePages($GLOBALS['db'], 'editPage');
23 } elseif ($_GET['dialog'] == 'delete') {
24 $html = $databaseDesigner->getHtmlForEditOrDeletePages($GLOBALS['db'], 'deletePage');
25 } elseif ($_GET['dialog'] == 'save_as') {
26 $html = $databaseDesigner->getHtmlForPageSaveAs($GLOBALS['db']);
27 } elseif ($_GET['dialog'] == 'export') {
28 $html = $databaseDesigner->getHtmlForSchemaExport(
29 $GLOBALS['db'], $_GET['selected_page']
31 } elseif ($_POST['dialog'] == 'add_table') {
32 $script_display_field = $designerCommon->getTablesInfo();
33 $required = $GLOBALS['db'] . '.' . $GLOBALS['table'];
34 $tab_column = $designerCommon->getColumnsInfo();
35 $tables_all_keys = $designerCommon->getAllKeys();
36 $tables_pk_or_unique_keys = $designerCommon->getPkOrUniqueKeys();
38 $req_key = array_search($required, $GLOBALS['designer']['TABLE_NAME']);
40 $GLOBALS['designer']['TABLE_NAME'] = array($GLOBALS['designer']['TABLE_NAME'][$req_key]);
41 $GLOBALS['designer_url']['TABLE_NAME_SMALL'] = array($GLOBALS['designer_url']['TABLE_NAME_SMALL'][$req_key]);
42 $GLOBALS['designer']['TABLE_NAME_SMALL'] = array($GLOBALS['designer']['TABLE_NAME_SMALL'][$req_key]);
43 $GLOBALS['designer_out']['TABLE_NAME_SMALL'] = array($GLOBALS['designer_out']['TABLE_NAME_SMALL'][$req_key]);
44 $GLOBALS['designer']['TABLE_TYPE'] = array($GLOBALS['designer_url']['TABLE_TYPE'][$req_key]);
45 $GLOBALS['designer_out']['OWNER'] = array($GLOBALS['designer_out']['OWNER'][$req_key]);
47 $html = $databaseDesigner->getDatabaseTables(
48 array(), -1, $tab_column,
49 $tables_all_keys, $tables_pk_or_unique_keys
53 if (! empty($html)) {
54 $response->addHTML($html);
56 return;
59 if (isset($_POST['operation'])) {
61 if ($_POST['operation'] == 'deletePage') {
62 $success = $designerCommon->deletePage($_POST['selected_page']);
63 $response->setRequestStatus($success);
64 } elseif ($_POST['operation'] == 'savePage') {
65 if ($_POST['save_page'] == 'same') {
66 $page = $_POST['selected_page'];
67 } else { // new
68 $page = $designerCommon->createNewPage($_POST['selected_value'], $GLOBALS['db']);
69 $response->addJSON('id', $page);
71 $success = $designerCommon->saveTablePositions($page);
72 $response->setRequestStatus($success);
73 } elseif ($_POST['operation'] == 'setDisplayField') {
74 $designerCommon->saveDisplayField(
75 $_POST['db'], $_POST['table'], $_POST['field']
77 $response->setRequestStatus(true);
78 } elseif ($_POST['operation'] == 'addNewRelation') {
79 list($success, $message) = $designerCommon->addNewRelation(
80 $_POST['db'],
81 $_POST['T1'],
82 $_POST['F1'],
83 $_POST['T2'],
84 $_POST['F2'],
85 $_POST['on_delete'],
86 $_POST['on_update'],
87 $_POST['DB1'],
88 $_POST['DB2']
90 $response->setRequestStatus($success);
91 $response->addJSON('message', $message);
92 } elseif ($_POST['operation'] == 'removeRelation') {
93 list($success, $message) = $designerCommon->removeRelation(
94 $_POST['T1'],
95 $_POST['F1'],
96 $_POST['T2'],
97 $_POST['F2']
99 $response->setRequestStatus($success);
100 $response->addJSON('message', $message);
101 } elseif ($_POST['operation'] == 'save_setting_value') {
102 $success = $designerCommon->saveSetting($_POST['index'], $_POST['value']);
103 $response->setRequestStatus($success);
106 return;
109 require 'libraries/db_common.inc.php';
111 $script_display_field = $designerCommon->getTablesInfo();
112 $tab_column = $designerCommon->getColumnsInfo();
113 $script_tables = $designerCommon->getScriptTabs();
114 $tables_pk_or_unique_keys = $designerCommon->getPkOrUniqueKeys();
115 $tables_all_keys = $designerCommon->getAllKeys();
116 $classes_side_menu = $databaseDesigner->returnClassNamesFromMenuButtons();
118 $display_page = -1;
119 $selected_page = null;
121 if (isset($_GET['query'])) {
122 $display_page = $designerCommon->getDefaultPage($_GET['db']);
123 } else {
124 if (! empty($_GET['page'])) {
125 $display_page = $_GET['page'];
126 } else {
127 $display_page = $designerCommon->getLoadingPage($_GET['db']);
130 if ($display_page != -1) {
131 $selected_page = $designerCommon->getPageName($display_page);
133 $tab_pos = $designerCommon->getTablePositions($display_page);
134 $script_contr = $designerCommon->getScriptContr();
136 $params = array('lang' => $GLOBALS['lang']);
137 if (isset($_GET['db'])) {
138 $params['db'] = $_GET['db'];
141 $response = Response::getInstance();
142 $response->getFooter()->setMinimal();
143 $header = $response->getHeader();
144 $header->setBodyId('designer_body');
146 $scripts = $header->getScripts();
147 $scripts->addFile('vendor/jquery/jquery.fullscreen.js');
148 $scripts->addFile('designer/database.js');
149 $scripts->addFile('designer/objects.js');
150 $scripts->addFile('designer/page.js');
151 $scripts->addFile('designer/history.js');
152 $scripts->addFile('designer/move.js');
153 $scripts->addFile('designer/init.js');
155 list(
156 $tables,
157 $num_tables,
158 $total_num_tables,
159 $sub_part,
160 $is_show_stats,
161 $db_is_system_schema,
162 $tooltip_truename,
163 $tooltip_aliasname,
164 $pos
165 ) = PhpMyAdmin\Util::getDbInfo($db, isset($sub_part) ? $sub_part : '');
167 // Embed some data into HTML, later it will be read
168 // by designer/init.js and converted to JS variables.
169 $response->addHTML(
170 $databaseDesigner->getHtmlForJsFields(
171 $script_tables, $script_contr, $script_display_field, $display_page
174 $response->addHTML(
175 $databaseDesigner->getPageMenu(
176 isset($_GET['query']),
177 $selected_page,
178 $classes_side_menu
184 $response->addHTML('<div id="canvas_outer">');
185 $response->addHTML(
186 '<form action="" id="container-form" method="post" name="form1">'
189 $response->addHTML($databaseDesigner->getHtmlCanvas());
190 $response->addHTML($databaseDesigner->getHtmlTableList($tab_pos, $display_page));
192 $response->addHTML(
193 $databaseDesigner->getDatabaseTables(
194 $tab_pos, $display_page, $tab_column,
195 $tables_all_keys, $tables_pk_or_unique_keys
198 $response->addHTML('</form>');
199 $response->addHTML('</div>'); // end canvas_outer
201 $response->addHTML('<div id="designer_hint"></div>');
203 $response->addHTML($databaseDesigner->getNewRelationPanel());
204 $response->addHTML($databaseDesigner->getDeleteRelationPanel());
206 if (isset($_GET['query'])) {
207 $response->addHTML($databaseDesigner->getOptionsPanel());
208 $response->addHTML($databaseDesigner->getRenameToPanel());
209 $response->addHTML($databaseDesigner->getHavingQueryPanel());
210 $response->addHTML($databaseDesigner->getAggregateQueryPanel());
211 $response->addHTML($databaseDesigner->getWhereQueryPanel());
212 $response->addHTML($databaseDesigner->getQueryDetails($_GET['db']));
215 $response->addHTML('<div id="PMA_disable_floating_menubar"></div>');