Translated using Weblate (Norwegian Bokmål)
[phpmyadmin.git] / libraries / mult_submits.inc.php
blob9a8db27bd675711b245973138086b64b99714d41
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Helper for multi submit forms
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 require_once 'libraries/transformations.lib.php';
13 require_once 'libraries/bookmark.lib.php';
14 require_once 'libraries/sql.lib.php';
15 require_once 'libraries/mult_submits.lib.php';
17 $request_params = array(
18 'clause_is_unique',
19 'from_prefix',
20 'goto',
21 'mult_btn',
22 'original_sql_query',
23 'query_type',
24 'reload',
25 'selected',
26 'selected_fld',
27 'selected_recent_table',
28 'sql_query',
29 'submit_mult',
30 'table_type',
31 'to_prefix',
32 'url_query'
35 foreach ($request_params as $one_request_param) {
36 if (isset($_REQUEST[$one_request_param])) {
37 $GLOBALS[$one_request_param] = $_REQUEST[$one_request_param];
41 /**
42 * Prepares the work and runs some other scripts if required
44 if (! empty($submit_mult)
45 && $submit_mult != __('With selected:')
46 && (! empty($selected_db)
47 || ! empty($_POST['selected_tbl'])
48 || ! empty($selected_fld)
49 || ! empty($_REQUEST['rows_to_delete']))
50 ) {
51 define('PMA_SUBMIT_MULT', 1);
52 if (isset($selected_db) && !empty($selected_db)) {
53 // coming from server database view - do something with
54 // selected databases
55 $selected = $selected_db;
56 $what = 'drop_db';
57 } elseif (! empty($_POST['selected_tbl'])) {
58 // coming from database structure view - do something with
59 // selected tables
60 if ($submit_mult == 'print') {
61 include './tbl_printview.php';
62 } else {
63 $selected = $_POST['selected_tbl'];
64 switch ($submit_mult) {
65 case 'add_prefix_tbl':
66 case 'replace_prefix_tbl':
67 case 'copy_tbl_change_prefix':
68 case 'drop_db':
69 case 'drop_tbl':
70 case 'empty_tbl':
71 $what = $submit_mult;
72 break;
73 case 'check_tbl':
74 case 'optimize_tbl':
75 case 'repair_tbl':
76 case 'analyze_tbl':
77 case 'checksum_tbl':
78 $query_type = $submit_mult;
79 unset($submit_mult);
80 $mult_btn = __('Yes');
81 break;
82 case 'export':
83 unset($submit_mult);
84 include 'db_export.php';
85 exit;
86 break;
87 case 'show_create':
88 $show_create = PMA_getHtmlShowCreate($GLOBALS['db'], $selected);
89 // Send response to client.
90 $response = PMA_Response::getInstance();
91 $response->addJSON('message', $show_create);
92 exit;
93 case 'sync_unique_columns_central_list':
94 include_once 'libraries/central_columns.lib.php';
95 $centralColsError = PMA_syncUniqueColumns($selected);
96 break;
97 case 'delete_unique_columns_central_list':
98 include_once 'libraries/central_columns.lib.php';
99 $centralColsError = PMA_deleteColumnsFromList($selected);
100 break;
101 case 'make_consistent_with_central_list':
102 include_once 'libraries/central_columns.lib.php';
103 $centralColsError = PMA_makeConsistentWithList(
104 $GLOBALS['db'],
105 $selected
107 break;
108 } // end switch
110 } elseif (isset($selected_fld) && !empty($selected_fld)) {
111 // coming from table structure view - do something with
112 // selected columns
113 $selected = $selected_fld;
114 list(
115 $what_ret, $query_type_ret, $is_unset_submit_mult, $mult_btn_ret,
116 $centralColsError
118 = PMA_getDataForSubmitMult(
119 $submit_mult, $GLOBALS['db'], $table,
120 $selected, $action
122 //update the existing variables
123 if (isset($what_ret)) {
124 $what = $what_ret;
126 if (isset($query_type_ret)) {
127 $query_type = $query_type_ret;
129 if ($is_unset_submit_mult) {
130 unset($submit_mult);
132 if (isset($mult_btn_ret)) {
133 $mult_btn = $mult_btn_ret;
135 } else {
136 // coming from browsing - do something with selected rows
137 $what = 'row_delete';
138 $selected = $_REQUEST['rows_to_delete'];
140 } // end if
142 if (empty($db)) {
143 $db = '';
145 if (empty($table)) {
146 $table = '';
148 $views = $GLOBALS['dbi']->getVirtualTables($db);
151 * Displays the confirmation form if required
153 if (!empty($submit_mult) && !empty($what)) {
154 unset($message);
156 /** @var PMA_String $pmaString */
157 $pmaString = $GLOBALS['PMA_String'];
158 if (/*overload*/mb_strlen($table)) {
159 include './libraries/tbl_common.inc.php';
160 $url_query .= '&amp;goto=tbl_sql.php&amp;back=tbl_sql.php';
161 include './libraries/tbl_info.inc.php';
162 } elseif (/*overload*/mb_strlen($db)) {
163 include './libraries/db_common.inc.php';
164 include './libraries/db_info.inc.php';
165 } else {
166 include_once './libraries/server_common.inc.php';
169 // Builds the query
170 list($full_query, $reload, $full_query_views)
171 = PMA_getQueryFromSelected(
172 $what, $db, $table, $selected, $views
175 // Displays the confirmation form
176 $_url_params = PMA_getUrlParams(
177 $what, $reload, $action, $db, $table, $selected, $views,
178 isset($original_sql_query)? $original_sql_query : null,
179 isset($original_url_query)? $original_url_query : null
182 $response = PMA_Response::getInstance();
184 if ($what == 'replace_prefix_tbl' || $what == 'copy_tbl_change_prefix') {
185 $response->addHTML(PMA_getHtmlForReplacePrefixTable($what, $action, $_url_params));
186 } elseif ($what == 'add_prefix_tbl') {
187 $response->addHTML(PMA_getHtmlForAddPrefixTable($action, $_url_params));
188 } else {
189 $response->addHTML(PMA_getHtmlForOtherActions($what, $action, $_url_params, $full_query));
191 exit;
193 } elseif (! empty($mult_btn) && $mult_btn == __('Yes')) {
195 * Executes the query - dropping rows, columns/fields, tables or dbs
197 if ($query_type == 'drop_db'
198 || $query_type == 'drop_tbl'
199 || $query_type == 'drop_fld'
201 include_once './libraries/relation_cleanup.lib.php';
204 if ($query_type == 'primary_fld') {
205 // Gets table primary key
206 $GLOBALS['dbi']->selectDb($db);
207 $result = $GLOBALS['dbi']->query(
208 'SHOW KEYS FROM ' . PMA_Util::backquote($table) . ';'
210 $primary = '';
211 while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
212 // Backups the list of primary keys
213 if ($row['Key_name'] == 'PRIMARY') {
214 $primary .= $row['Column_name'] . ', ';
216 } // end while
217 $GLOBALS['dbi']->freeResult($result);
220 if (! isset($_REQUEST['fk_check'])
221 && ($query_type == 'drop_tbl'
222 || $query_type == 'empty_tbl'
223 || $query_type == 'row_delete')
225 $default_fk_check_value = $GLOBALS['dbi']->fetchValue(
226 'SHOW VARIABLES LIKE \'foreign_key_checks\';', 0, 1
227 ) == 'ON';
229 // for disabling foreign key checks while dropping tables
230 $GLOBALS['dbi']->query('SET FOREIGN_KEY_CHECKS = 0;');
233 list(
234 $result, $rebuild_database_list, $reload_ret,
235 $run_parts, $use_sql, $sql_query, $sql_query_views
236 ) = PMA_getQueryStrFromSelected(
237 $query_type, $selected, $db, $table, $views,
238 isset($primary) ? $primary : null,
239 isset($from_prefix) ? $from_prefix : null,
240 isset($to_prefix) ? $to_prefix : null
242 //update the existed variable
243 if (isset($reload_ret)) {
244 $reload = $reload_ret;
247 if ($query_type == 'drop_tbl') {
248 if (!empty($sql_query)) {
249 $sql_query .= ';';
250 } elseif (!empty($sql_query_views)) {
251 $sql_query = $sql_query_views . ';';
252 unset($sql_query_views);
256 if ($use_sql) {
258 * Parse and analyze the query
260 include_once 'libraries/parse_analyze.inc.php';
262 PMA_executeQueryAndSendQueryResponse(
263 $analyzed_sql_results, false, $db, $table, null, null, null,
264 false, null, null, null, $goto, $pmaThemeImage, null, null,
265 $query_type, $sql_query, $selected, null
267 } elseif (!$run_parts) {
268 $GLOBALS['dbi']->selectDb($db);
269 $result = $GLOBALS['dbi']->tryQuery($sql_query);
270 if ($result && !empty($sql_query_views)) {
271 $sql_query .= ' ' . $sql_query_views . ';';
272 $result = $GLOBALS['dbi']->tryQuery($sql_query_views);
273 unset($sql_query_views);
276 if (! $result) {
277 $message = PMA_Message::error($GLOBALS['dbi']->getError());
280 if (! isset($_REQUEST['fk_check'])
281 && ($query_type == 'drop_tbl'
282 || $query_type == 'empty_tbl'
283 || $query_type == 'row_delete')
284 && $default_fk_check_value
286 $GLOBALS['dbi']->query('SET FOREIGN_KEY_CHECKS = 1;');
288 if ($rebuild_database_list) {
289 // avoid a problem with the database list navigator
290 // when dropping a db from server_databases
291 $GLOBALS['pma']->databases->build();
293 } else {
294 if (isset($submit_mult)
295 && ($submit_mult == 'sync_unique_columns_central_list'
296 || $submit_mult == 'delete_unique_columns_central_list'
297 || $submit_mult == 'add_to_central_columns'
298 || $submit_mult == 'remove_from_central_columns'
299 || $submit_mult == 'make_consistent_with_central_list')
301 if (isset($centralColsError) && $centralColsError !== true) {
302 $message = $centralColsError;
303 } else {
304 $message = PMA_Message::success(__('Success!'));
306 } else {
307 $message = PMA_Message::success(__('No change'));