2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * phpMyAdmin designer general code
6 * @package PhpMyAdmin-Designer
9 require_once 'libraries/common.inc.php';
10 require_once 'libraries/pmd_common.php';
11 require_once 'libraries/db_designer.lib.php';
13 $response = PMA_Response
::getInstance();
15 if (isset($_REQUEST['dialog'])) {
17 if ($_REQUEST['dialog'] == 'edit') {
18 $html = PMA_getHtmlForEditOrDeletePages($GLOBALS['db'], 'editPage');
19 } else if ($_REQUEST['dialog'] == 'delete') {
20 $html = PMA_getHtmlForEditOrDeletePages($GLOBALS['db'], 'deletePage');
21 } else if ($_REQUEST['dialog'] == 'save_as') {
22 $html = PMA_getHtmlForPageSaveAs($GLOBALS['db']);
23 } else if ($_REQUEST['dialog'] == 'export') {
24 include_once 'libraries/plugin_interface.lib.php';
25 $html = PMA_getHtmlForSchemaExport(
26 $GLOBALS['db'], $_REQUEST['selected_page']
31 $response->addHTML($html);
36 if (isset($_REQUEST['operation'])) {
38 if ($_REQUEST['operation'] == 'deletePage') {
39 $result = PMA_deletePage($_REQUEST['selected_page']);
41 $response->isSuccess(true);
43 $response->isSuccess(false);
45 } elseif ($_REQUEST['operation'] == 'savePage') {
46 if ($_REQUEST['save_page'] == 'same') {
47 $page = $_REQUEST['selected_page'];
49 $page = PMA_createNewPage($_REQUEST['selected_value'], $GLOBALS['db']);
50 $response->addJSON('id', $page);
52 if (PMA_saveTablePositions($page)) {
53 $response->isSuccess(true);
55 $response->isSuccess(false);
57 } elseif ($_REQUEST['operation'] == 'setDisplayField') {
59 $_REQUEST['db'], $_REQUEST['table'], $_REQUEST['field']
61 $response->isSuccess(true);
62 } elseif ($_REQUEST['operation'] == 'addNewRelation') {
63 list($success, $message) = PMA_addNewRelation(
69 $_REQUEST['on_delete'],
70 $_REQUEST['on_update']
72 $response->isSuccess($success);
73 $response->addJSON('message', $message);
74 } elseif ($_REQUEST['operation'] == 'removeRelation') {
75 list($success, $message) = PMA_removeRelation(
81 $response->isSuccess($success);
82 $response->addJSON('message', $message);
83 } elseif ($_REQUEST['operation'] == 'save_setting_value') {
84 $cfgRelation = PMA_getRelationsParam();
87 'user' => $GLOBALS['cfg']['Server']['user'],
88 'db' => $cfgRelation['db'],
89 'table' => $cfgRelation['designer_settings']
91 if (! empty($cfgDesigner['user'])
92 && ! empty($cfgDesigner['db'])
93 && ! empty($cfgDesigner['table'])
94 && $GLOBALS['cfgRelation']['designersettingswork']
96 $orig_data_query = 'SELECT ' . PMA_Util
::backquote('settings_data')
97 . ' FROM `' . $cfgDesigner['db'] . '`.`' . $cfgDesigner['table'] . '` WHERE '
98 . PMA_Util
::backquote('username') . ' = "'
99 . $cfgDesigner['user'] . '"';
101 $orig_data = $GLOBALS['dbi']->fetchSingleRow($orig_data_query);
105 if (isset($orig_data)
106 && ! empty($orig_data)
109 $orig_data = json_decode($orig_data['settings_data'], true);
110 $orig_data[$_REQUEST['index']] = $_REQUEST['value'];
111 $orig_data = json_encode($orig_data);
113 $save_query = 'UPDATE `' . $cfgDesigner['db'] . '`.`'
114 . $cfgDesigner['table'] . '` SET '
115 . PMA_Util
::backquote('settings_data') . ' = \''
116 . $orig_data . '\' WHERE ' . PMA_Util
::backquote('username') . ' = "'
117 . $cfgDesigner['user'] . '";';
119 $success = $GLOBALS['dbi']->query($save_query);
121 $save_data = array($_REQUEST['index'] => $_REQUEST['value']);
123 $query = 'INSERT INTO ' . PMA_Util
::backquote($cfgDesigner['db'])
124 . '.' . PMA_Util
::backquote($cfgDesigner['table'])
125 . ' VALUES("' . PMA_Util
::sqlAddSlashes($cfgDesigner['user']) . '", \''
126 . PMA_Util
::sqlAddSlashes(json_encode($save_data)) . '\');';
128 $success = $GLOBALS['dbi']->query($query);
131 $response->isSuccess($success);
138 $script_display_field = PMA_getTablesInfo();
139 $tab_column = PMA_getColumnsInfo();
140 $script_tables = PMA_getScriptTabs();
141 $tables_pk_or_unique_keys = PMA_getPKOrUniqueKeys();
142 $tables_all_keys = PMA_getAllKeys();
143 $classes_side_menu = PMA_returnClassNamesFromMenuButtons();
146 $selected_page = null;
148 if (isset($_REQUEST['query'])) {
149 $display_page = PMA_getDefaultPage($_REQUEST['db']);
151 if (! empty($_REQUEST['page'])) {
152 $display_page = $_REQUEST['page'];
154 $display_page = PMA_getLoadingPage($_REQUEST['db']);
157 if ($display_page != -1) {
158 $selected_page = PMA_getPageName($display_page);
160 $tab_pos = PMA_getTablePositions($display_page);
161 $script_contr = PMA_getScriptContr();
163 $params = array('lang' => $GLOBALS['lang']);
164 if (isset($_GET['db'])) {
165 $params['db'] = $_GET['db'];
168 $response = PMA_Response
::getInstance();
169 $response->getFooter()->setMinimal();
170 $header = $response->getHeader();
171 $header->setBodyId('pmd_body');
173 $scripts = $header->getScripts();
174 $scripts->addFile('jquery/jquery.fullscreen.js');
175 $scripts->addFile('pmd/designer_db.js');
176 $scripts->addFile('pmd/designer_objects.js');
177 $scripts->addFile('pmd/designer_page.js');
178 $scripts->addFile('pmd/history.js');
179 $scripts->addFile('pmd/move.js');
180 $scripts->addFile('pmd/iecanvas.js', true);
181 $scripts->addFile('pmd/init.js');
183 require 'libraries/db_common.inc.php';
184 require 'libraries/db_info.inc.php';
186 // Embed some data into HTML, later it will be read
187 // by pmd/init.js and converted to JS variables.
189 PMA_getHtmlForJSFields(
190 $script_tables, $script_contr, $script_display_field, $display_page
194 PMA_getDesignerPageMenu(isset($_REQUEST['query']), $selected_page, $classes_side_menu)
199 $response->addHTML('<div id="canvas_outer">');
201 '<form action="" id="container-form" method="post" name="form1">'
204 $response->addHTML(PMA_getHTMLCanvas());
205 $response->addHTML(PMA_getHTMLTableList($tab_pos, $display_page));
208 PMA_getDatabaseTables(
209 $tab_pos, $display_page, $tab_column,
210 $tables_all_keys, $tables_pk_or_unique_keys
213 $response->addHTML('</form>');
214 $response->addHTML('</div>'); // end canvas_outer
216 $response->addHTML('<div id="pmd_hint"></div>');
218 $response->addHTML(PMA_getNewRelationPanel());
219 $response->addHTML(PMA_getDeleteRelationPanel());
221 if (isset($_REQUEST['query'])) {
222 $response->addHTML(PMA_getOptionsPanel());
223 $response->addHTML(PMA_getRenameToPanel());
224 $response->addHTML(PMA_getHavingQueryPanel());
225 $response->addHTML(PMA_getAggregateQueryPanel());
226 $response->addHTML(PMA_getWhereQueryPanel());
227 $response->addHTML(PMA_getQueryDetails());
230 $response->addHTML('<div id="PMA_disable_floating_menubar"></div>');