Translated using Weblate (French)
[phpmyadmin.git] / db_designer.php
blob00731675c45433c6e3b978dfbd7318957b50e87a
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * phpMyAdmin designer general code
6 * @package PhpMyAdmin-Designer
7 */
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']
30 if (! empty($html)) {
31 $response->addHTML($html);
33 return;
36 if (isset($_REQUEST['operation'])) {
38 if ($_REQUEST['operation'] == 'deletePage') {
39 $result = PMA_deletePage($_REQUEST['selected_page']);
40 if ($result) {
41 $response->isSuccess(true);
42 } else {
43 $response->isSuccess(false);
45 } elseif ($_REQUEST['operation'] == 'savePage') {
46 if ($_REQUEST['save_page'] == 'same') {
47 $page = $_REQUEST['selected_page'];
48 } else { // new
49 $page = PMA_createNewPage($_REQUEST['selected_value'], $GLOBALS['db']);
50 $response->addJSON('id', $page);
52 if (PMA_saveTablePositions($page)) {
53 $response->isSuccess(true);
54 } else {
55 $response->isSuccess(false);
57 } elseif ($_REQUEST['operation'] == 'setDisplayField') {
58 PMA_saveDisplayField(
59 $_REQUEST['db'], $_REQUEST['table'], $_REQUEST['field']
61 $response->isSuccess(true);
62 } elseif ($_REQUEST['operation'] == 'addNewRelation') {
63 list($success, $message) = PMA_addNewRelation(
64 $_REQUEST['db'],
65 $_REQUEST['T1'],
66 $_REQUEST['F1'],
67 $_REQUEST['T2'],
68 $_REQUEST['F2'],
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(
76 $_REQUEST['T1'],
77 $_REQUEST['F1'],
78 $_REQUEST['T2'],
79 $_REQUEST['F2']
81 $response->isSuccess($success);
82 $response->addJSON('message', $message);
83 } elseif ($_REQUEST['operation'] == 'save_setting_value') {
84 $cfgRelation = PMA_getRelationsParam();
86 $cfgDesigner = array(
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']
95 ) {
96 $orig_data_query = 'SELECT ' . PMA_Util::backquote('settings_data')
97 . ' FROM `' . $cfgDesigner['db'] . '`.`' . $cfgDesigner['table']
98 . '` WHERE ' . PMA_Util::backquote('username') . ' = "'
99 . $cfgDesigner['user'] . '"';
101 $orig_data = $GLOBALS['dbi']->fetchSingleRow($orig_data_query);
103 $success = false;
105 if (isset($orig_data)
106 && ! empty($orig_data)
107 && $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);
120 } else {
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 . '", \''
127 . PMA_Util::sqlAddSlashes(json_encode($save_data)) . '\');';
129 $success = $GLOBALS['dbi']->query($query);
132 $response->isSuccess($success);
136 return;
139 $script_display_field = PMA_getTablesInfo();
140 $tab_column = PMA_getColumnsInfo();
141 $script_tables = PMA_getScriptTabs();
142 $tables_pk_or_unique_keys = PMA_getPKOrUniqueKeys();
143 $tables_all_keys = PMA_getAllKeys();
144 $classes_side_menu = PMA_returnClassNamesFromMenuButtons();
146 $display_page = -1;
147 $selected_page = null;
149 if (isset($_REQUEST['query'])) {
150 $display_page = PMA_getDefaultPage($_REQUEST['db']);
151 } else {
152 if (! empty($_REQUEST['page'])) {
153 $display_page = $_REQUEST['page'];
154 } else {
155 $display_page = PMA_getLoadingPage($_REQUEST['db']);
158 if ($display_page != -1) {
159 $selected_page = PMA_getPageName($display_page);
161 $tab_pos = PMA_getTablePositions($display_page);
162 $script_contr = PMA_getScriptContr();
164 $params = array('lang' => $GLOBALS['lang']);
165 if (isset($_GET['db'])) {
166 $params['db'] = $_GET['db'];
169 $response = PMA_Response::getInstance();
170 $response->getFooter()->setMinimal();
171 $header = $response->getHeader();
172 $header->setBodyId('pmd_body');
174 $scripts = $header->getScripts();
175 $scripts->addFile('jquery/jquery.fullscreen.js');
176 $scripts->addFile('pmd/designer_db.js');
177 $scripts->addFile('pmd/designer_objects.js');
178 $scripts->addFile('pmd/designer_page.js');
179 $scripts->addFile('pmd/history.js');
180 $scripts->addFile('pmd/move.js');
181 $scripts->addFile('pmd/iecanvas.js', true);
182 $scripts->addFile('pmd/init.js');
184 require 'libraries/db_common.inc.php';
185 require 'libraries/db_info.inc.php';
187 // Embed some data into HTML, later it will be read
188 // by pmd/init.js and converted to JS variables.
189 $response->addHTML(
190 PMA_getHtmlForJSFields(
191 $script_tables, $script_contr, $script_display_field, $display_page
194 $response->addHTML(
195 PMA_getDesignerPageMenu(isset($_REQUEST['query']), $selected_page, $classes_side_menu)
200 $response->addHTML('<div id="canvas_outer">');
201 $response->addHTML(
202 '<form action="" id="container-form" method="post" name="form1">'
205 $response->addHTML(PMA_getHTMLCanvas());
206 $response->addHTML(PMA_getHTMLTableList($tab_pos, $display_page));
208 $response->addHTML(
209 PMA_getDatabaseTables(
210 $tab_pos, $display_page, $tab_column,
211 $tables_all_keys, $tables_pk_or_unique_keys
214 $response->addHTML('</form>');
215 $response->addHTML('</div>'); // end canvas_outer
217 $response->addHTML('<div id="pmd_hint"></div>');
219 $response->addHTML(PMA_getNewRelationPanel());
220 $response->addHTML(PMA_getDeleteRelationPanel());
222 if (isset($_REQUEST['query'])) {
223 $response->addHTML(PMA_getOptionsPanel());
224 $response->addHTML(PMA_getRenameToPanel());
225 $response->addHTML(PMA_getHavingQueryPanel());
226 $response->addHTML(PMA_getAggregateQueryPanel());
227 $response->addHTML(PMA_getWhereQueryPanel());
228 $response->addHTML(PMA_getQueryDetails());
231 $response->addHTML('<div id="PMA_disable_floating_menubar"></div>');