Merge branch 'QA_4_7'
[phpmyadmin.git] / db_designer.php
blob269b4bef9c302ca032996abdfa3f99bf9c548e49
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\Response;
10 require_once 'libraries/common.inc.php';
11 require_once 'libraries/pmd_common.php';
12 require_once 'libraries/db_designer.lib.php';
14 $response = Response::getInstance();
16 if (isset($_REQUEST['dialog'])) {
18 if ($_REQUEST['dialog'] == 'edit') {
19 $html = PMA_getHtmlForEditOrDeletePages($GLOBALS['db'], 'editPage');
20 } else if ($_REQUEST['dialog'] == 'delete') {
21 $html = PMA_getHtmlForEditOrDeletePages($GLOBALS['db'], 'deletePage');
22 } else if ($_REQUEST['dialog'] == 'save_as') {
23 $html = PMA_getHtmlForPageSaveAs($GLOBALS['db']);
24 } else if ($_REQUEST['dialog'] == 'export') {
25 include_once 'libraries/plugin_interface.lib.php';
26 $html = PMA_getHtmlForSchemaExport(
27 $GLOBALS['db'], $_REQUEST['selected_page']
29 } else if ($_REQUEST['dialog'] == 'add_table') {
30 $script_display_field = PMA_getTablesInfo();
31 $required = $GLOBALS['db'] . '.' . $GLOBALS['table'];
32 $tab_column = PMA_getColumnsInfo();
33 $tables_all_keys = PMA_getAllKeys();
34 $tables_pk_or_unique_keys = PMA_getPKOrUniqueKeys();
36 $req_key = array_search($required, $GLOBALS['PMD']['TABLE_NAME']);
38 $GLOBALS['PMD']['TABLE_NAME'] = array($GLOBALS['PMD']['TABLE_NAME'][$req_key]);
39 $GLOBALS['PMD_URL']['TABLE_NAME_SMALL'] = array($GLOBALS['PMD_URL']['TABLE_NAME_SMALL'][$req_key]);
40 $GLOBALS['PMD']['TABLE_NAME_SMALL'] = array($GLOBALS['PMD']['TABLE_NAME_SMALL'][$req_key]);
41 $GLOBALS['PMD_OUT']['TABLE_NAME_SMALL'] = array($GLOBALS['PMD_OUT']['TABLE_NAME_SMALL'][$req_key]);
42 $GLOBALS['PMD']['TABLE_TYPE'] = array($GLOBALS['PMD_URL']['TABLE_TYPE'][$req_key]);
43 $GLOBALS['PMD_OUT']['OWNER'] = array($GLOBALS['PMD_OUT']['OWNER'][$req_key]);
45 $html = PMA_getDatabaseTables(
46 array(), -1, $tab_column,
47 $tables_all_keys, $tables_pk_or_unique_keys
51 if (! empty($html)) {
52 $response->addHTML($html);
54 return;
57 if (isset($_REQUEST['operation'])) {
59 if ($_REQUEST['operation'] == 'deletePage') {
60 $success = PMA_deletePage($_REQUEST['selected_page']);
61 $response->setRequestStatus($success);
62 } elseif ($_REQUEST['operation'] == 'savePage') {
63 if ($_REQUEST['save_page'] == 'same') {
64 $page = $_REQUEST['selected_page'];
65 } else { // new
66 $page = PMA_createNewPage($_REQUEST['selected_value'], $GLOBALS['db']);
67 $response->addJSON('id', $page);
69 $success = PMA_saveTablePositions($page);
70 $response->setRequestStatus($success);
71 } elseif ($_REQUEST['operation'] == 'setDisplayField') {
72 PMA_saveDisplayField(
73 $_REQUEST['db'], $_REQUEST['table'], $_REQUEST['field']
75 $response->setRequestStatus(true);
76 } elseif ($_REQUEST['operation'] == 'addNewRelation') {
77 list($success, $message) = PMA_addNewRelation(
78 $_REQUEST['db'],
79 $_REQUEST['T1'],
80 $_REQUEST['F1'],
81 $_REQUEST['T2'],
82 $_REQUEST['F2'],
83 $_REQUEST['on_delete'],
84 $_REQUEST['on_update'],
85 $_REQUEST['DB1'],
86 $_REQUEST['DB2']
88 $response->setRequestStatus($success);
89 $response->addJSON('message', $message);
90 } elseif ($_REQUEST['operation'] == 'removeRelation') {
91 list($success, $message) = PMA_removeRelation(
92 $_REQUEST['T1'],
93 $_REQUEST['F1'],
94 $_REQUEST['T2'],
95 $_REQUEST['F2']
97 $response->setRequestStatus($success);
98 $response->addJSON('message', $message);
99 } elseif ($_REQUEST['operation'] == 'save_setting_value') {
100 $success = PMA_saveDesignerSetting($_REQUEST['index'], $_REQUEST['value']);
101 $response->setRequestStatus($success);
104 return;
107 require 'libraries/db_common.inc.php';
109 $script_display_field = PMA_getTablesInfo();
110 $tab_column = PMA_getColumnsInfo();
111 $script_tables = PMA_getScriptTabs();
112 $tables_pk_or_unique_keys = PMA_getPKOrUniqueKeys();
113 $tables_all_keys = PMA_getAllKeys();
114 $classes_side_menu = PMA_returnClassNamesFromMenuButtons();
116 $display_page = -1;
117 $selected_page = null;
119 if (isset($_REQUEST['query'])) {
120 $display_page = PMA_getDefaultPage($_REQUEST['db']);
121 } else {
122 if (! empty($_REQUEST['page'])) {
123 $display_page = $_REQUEST['page'];
124 } else {
125 $display_page = PMA_getLoadingPage($_REQUEST['db']);
128 if ($display_page != -1) {
129 $selected_page = PMA_getPageName($display_page);
131 $tab_pos = PMA_getTablePositions($display_page);
132 $script_contr = PMA_getScriptContr();
134 $params = array('lang' => $GLOBALS['lang']);
135 if (isset($_GET['db'])) {
136 $params['db'] = $_GET['db'];
139 $response = Response::getInstance();
140 $response->getFooter()->setMinimal();
141 $header = $response->getHeader();
142 $header->setBodyId('pmd_body');
144 $scripts = $header->getScripts();
145 $scripts->addFile('vendor/jquery/jquery.fullscreen.js');
146 $scripts->addFile('pmd/designer_db.js');
147 $scripts->addFile('pmd/designer_objects.js');
148 $scripts->addFile('pmd/designer_page.js');
149 $scripts->addFile('pmd/history.js');
150 $scripts->addFile('pmd/move.js');
151 $scripts->addFile('pmd/init.js');
153 list(
154 $tables,
155 $num_tables,
156 $total_num_tables,
157 $sub_part,
158 $is_show_stats,
159 $db_is_system_schema,
160 $tooltip_truename,
161 $tooltip_aliasname,
162 $pos
163 ) = PhpMyAdmin\Util::getDbInfo($db, isset($sub_part) ? $sub_part : '');
165 // Embed some data into HTML, later it will be read
166 // by pmd/init.js and converted to JS variables.
167 $response->addHTML(
168 PMA_getHtmlForJSFields(
169 $script_tables, $script_contr, $script_display_field, $display_page
172 $response->addHTML(
173 PMA_getDesignerPageMenu(
174 isset($_REQUEST['query']),
175 $selected_page,
176 $classes_side_menu
182 $response->addHTML('<div id="canvas_outer">');
183 $response->addHTML(
184 '<form action="" id="container-form" method="post" name="form1">'
187 $response->addHTML(PMA_getHTMLCanvas());
188 $response->addHTML(PMA_getHTMLTableList($tab_pos, $display_page));
190 $response->addHTML(
191 PMA_getDatabaseTables(
192 $tab_pos, $display_page, $tab_column,
193 $tables_all_keys, $tables_pk_or_unique_keys
196 $response->addHTML('</form>');
197 $response->addHTML('</div>'); // end canvas_outer
199 $response->addHTML('<div id="pmd_hint"></div>');
201 $response->addHTML(PMA_getNewRelationPanel());
202 $response->addHTML(PMA_getDeleteRelationPanel());
204 if (isset($_REQUEST['query'])) {
205 $response->addHTML(PMA_getOptionsPanel());
206 $response->addHTML(PMA_getRenameToPanel());
207 $response->addHTML(PMA_getHavingQueryPanel());
208 $response->addHTML(PMA_getAggregateQueryPanel());
209 $response->addHTML(PMA_getWhereQueryPanel());
210 $response->addHTML(PMA_getQueryDetails());
213 $response->addHTML('<div id="PMA_disable_floating_menubar"></div>');