Translated using Weblate (Estonian)
[phpmyadmin.git] / libraries / mult_submits.inc.php
blobff8a402fe45d55d87ada95cdbbe0f90a2c45c4f9
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Helper for multi submit forms
6 * @package PhpMyAdmin
7 */
8 use PMA\libraries\Message;
9 use PMA\libraries\Response;
11 if (! defined('PHPMYADMIN')) {
12 exit;
15 require_once 'libraries/transformations.lib.php';
16 require_once 'libraries/sql.lib.php';
17 require_once 'libraries/mult_submits.lib.php';
19 $request_params = array(
20 'clause_is_unique',
21 'from_prefix',
22 'goto',
23 'mult_btn',
24 'original_sql_query',
25 'query_type',
26 'reload',
27 'selected',
28 'selected_fld',
29 'selected_recent_table',
30 'sql_query',
31 'submit_mult',
32 'table_type',
33 'to_prefix',
34 'url_query'
37 foreach ($request_params as $one_request_param) {
38 if (isset($_REQUEST[$one_request_param])) {
39 $GLOBALS[$one_request_param] = $_REQUEST[$one_request_param];
42 $response = Response::getInstance();
44 global $db, $table, $clause_is_unique, $from_prefix, $goto,
45 $mult_btn, $original_sql_query, $query_type, $reload,
46 $selected, $selected_fld, $selected_recent_table, $sql_query,
47 $submit_mult, $table_type, $to_prefix, $url_query, $pmaThemeImage;
49 /**
50 * Prepares the work and runs some other scripts if required
52 if (! empty($submit_mult)
53 && $submit_mult != __('With selected:')
54 && (! empty($_REQUEST['selected_dbs'])
55 || ! empty($_POST['selected_tbl'])
56 || ! empty($selected_fld)
57 || ! empty($_REQUEST['rows_to_delete']))
58 ) {
59 define('PMA_SUBMIT_MULT', 1);
60 if (! empty($_REQUEST['selected_dbs'])) {
61 // coming from server database view - do something with
62 // selected databases
63 $selected = $_REQUEST['selected_dbs'];
64 $query_type = 'drop_db';
65 } elseif (! empty($_POST['selected_tbl'])) {
66 // coming from database structure view - do something with
67 // selected tables
68 $selected = $_POST['selected_tbl'];
69 switch ($submit_mult) {
70 case 'add_prefix_tbl':
71 case 'replace_prefix_tbl':
72 case 'copy_tbl_change_prefix':
73 case 'drop_db':
74 case 'drop_tbl':
75 case 'empty_tbl':
76 $what = $submit_mult;
77 break;
78 case 'check_tbl':
79 case 'optimize_tbl':
80 case 'repair_tbl':
81 case 'analyze_tbl':
82 case 'checksum_tbl':
83 $query_type = $submit_mult;
84 unset($submit_mult);
85 $mult_btn = __('Yes');
86 break;
87 case 'export':
88 unset($submit_mult);
89 include 'db_export.php';
90 exit;
91 case 'copy_tbl':
92 $views = $GLOBALS['dbi']->getVirtualTables($db);
93 list($full_query, $reload, $full_query_views)
94 = PMA_getQueryFromSelected(
95 $submit_mult, $table, $selected, $views
97 $_url_params = PMA_getUrlParams(
98 $submit_mult, $reload, $action, $db, $table, $selected, $views,
99 isset($original_sql_query)? $original_sql_query : null,
100 isset($original_url_query)? $original_url_query : null
102 $response->disable();
103 $response->addHTML(
104 PMA_getHtmlForCopyMultipleTables($action, $_url_params)
106 exit;
107 case 'show_create':
108 $show_create = PMA\libraries\Template::get(
109 'database/structure/show_create'
111 ->render(
112 array(
113 'db' => $GLOBALS['db'],
114 'db_objects' => $selected,
117 // Send response to client.
118 $response->addJSON('message', $show_create);
119 exit;
120 case 'sync_unique_columns_central_list':
121 include_once 'libraries/central_columns.lib.php';
122 $centralColsError = PMA_syncUniqueColumns($selected);
123 break;
124 case 'delete_unique_columns_central_list':
125 include_once 'libraries/central_columns.lib.php';
126 $centralColsError = PMA_deleteColumnsFromList($selected);
127 break;
128 case 'make_consistent_with_central_list':
129 include_once 'libraries/central_columns.lib.php';
130 $centralColsError = PMA_makeConsistentWithList(
131 $GLOBALS['db'],
132 $selected
134 break;
135 } // end switch
136 } elseif (isset($selected_fld) && !empty($selected_fld)) {
137 // coming from table structure view - do something with
138 // selected columns
139 // handled in StructrueController
140 } else {
141 // coming from browsing - do something with selected rows
142 $what = 'row_delete';
143 $selected = $_REQUEST['rows_to_delete'];
145 } // end if
147 if (empty($db)) {
148 $db = '';
150 if (empty($table)) {
151 $table = '';
153 $views = $GLOBALS['dbi']->getVirtualTables($db);
156 * Displays the confirmation form if required
158 if (!empty($submit_mult) && !empty($what)) {
159 unset($message);
161 if (strlen($table) > 0) {
162 include './libraries/tbl_common.inc.php';
163 $url_query .= '&amp;goto=tbl_sql.php&amp;back=tbl_sql.php';
164 include './libraries/tbl_info.inc.php';
165 } elseif (strlen($db) > 0) {
166 include './libraries/db_common.inc.php';
168 list(
169 $tables,
170 $num_tables,
171 $total_num_tables,
172 $sub_part,
173 $is_show_stats,
174 $db_is_system_schema,
175 $tooltip_truename,
176 $tooltip_aliasname,
177 $pos
178 ) = PMA\libraries\Util::getDbInfo($db, isset($sub_part) ? $sub_part : '');
180 } else {
181 include_once './libraries/server_common.inc.php';
184 // Builds the query
185 list($full_query, $reload, $full_query_views)
186 = PMA_getQueryFromSelected(
187 $what, $table, $selected, $views
190 // Displays the confirmation form
191 $_url_params = PMA_getUrlParams(
192 $what, $reload, $action, $db, $table, $selected, $views,
193 isset($original_sql_query)? $original_sql_query : null,
194 isset($original_url_query)? $original_url_query : null
198 if ($what == 'replace_prefix_tbl' || $what == 'copy_tbl_change_prefix') {
199 $response->disable();
200 $response->addHTML(
201 PMA_getHtmlForReplacePrefixTable($action, $_url_params)
203 } elseif ($what == 'add_prefix_tbl') {
204 $response->disable();
205 $response->addHTML(PMA_getHtmlForAddPrefixTable($action, $_url_params));
206 } else {
207 $response->addHTML(
208 PMA_getHtmlForOtherActions($what, $action, $_url_params, $full_query)
211 exit;
213 } elseif (! empty($mult_btn) && $mult_btn == __('Yes')) {
215 * Executes the query - dropping rows, columns/fields, tables or dbs
217 if ($query_type == 'drop_db'
218 || $query_type == 'drop_tbl'
219 || $query_type == 'drop_fld'
221 include_once './libraries/relation_cleanup.lib.php';
224 if ($query_type == 'primary_fld') {
225 // Gets table primary key
226 $GLOBALS['dbi']->selectDb($db);
227 $result = $GLOBALS['dbi']->query(
228 'SHOW KEYS FROM ' . PMA\libraries\Util::backquote($table) . ';'
230 $primary = '';
231 while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
232 // Backups the list of primary keys
233 if ($row['Key_name'] == 'PRIMARY') {
234 $primary .= $row['Column_name'] . ', ';
236 } // end while
237 $GLOBALS['dbi']->freeResult($result);
240 if ($query_type == 'drop_tbl'
241 || $query_type == 'empty_tbl'
242 || $query_type == 'row_delete'
244 $default_fk_check_value = PMA\libraries\Util::handleDisableFKCheckInit();
247 list(
248 $result, $rebuild_database_list, $reload_ret,
249 $run_parts, $execute_query_later, $sql_query, $sql_query_views
250 ) = PMA_buildOrExecuteQueryForMulti(
251 $query_type, $selected, $db, $table, $views,
252 isset($primary) ? $primary : null,
253 isset($from_prefix) ? $from_prefix : null,
254 isset($to_prefix) ? $to_prefix : null
256 //update the existed variable
257 if (isset($reload_ret)) {
258 $reload = $reload_ret;
261 if ($query_type == 'drop_tbl') {
262 if (!empty($sql_query)) {
263 $sql_query .= ';';
264 } elseif (!empty($sql_query_views)) {
265 $sql_query = $sql_query_views . ';';
266 unset($sql_query_views);
270 if ($execute_query_later) {
271 PMA_executeQueryAndSendQueryResponse(
272 null, // analyzed_sql_results
273 false, // is_gotofile
274 $db, // db
275 $table, // table
276 null, // find_real_end
277 null, // sql_query_for_bookmark
278 null, // extra_data
279 null, // message_to_show
280 null, // message
281 null, // sql_data
282 $goto, // goto
283 $pmaThemeImage, // pmaThemeImage
284 null, // disp_query
285 null, // disp_message
286 $query_type, // query_type
287 $sql_query, // sql_query
288 $selected, // selectedTables
289 null // complete_query
291 } elseif (!$run_parts) {
292 $GLOBALS['dbi']->selectDb($db);
293 $result = $GLOBALS['dbi']->tryQuery($sql_query);
294 if ($result && !empty($sql_query_views)) {
295 $sql_query .= ' ' . $sql_query_views . ';';
296 $result = $GLOBALS['dbi']->tryQuery($sql_query_views);
297 unset($sql_query_views);
300 if (! $result) {
301 $message = Message::error($GLOBALS['dbi']->getError());
304 if ($query_type == 'drop_tbl'
305 || $query_type == 'empty_tbl'
306 || $query_type == 'row_delete'
308 PMA\libraries\Util::handleDisableFKCheckCleanup($default_fk_check_value);
310 if ($rebuild_database_list) {
311 // avoid a problem with the database list navigator
312 // when dropping a db from server_databases
313 $GLOBALS['dblist']->databases->build();
315 } else {
316 if (isset($submit_mult)
317 && ($submit_mult == 'sync_unique_columns_central_list'
318 || $submit_mult == 'delete_unique_columns_central_list'
319 || $submit_mult == 'add_to_central_columns'
320 || $submit_mult == 'remove_from_central_columns'
321 || $submit_mult == 'make_consistent_with_central_list')
323 if (isset($centralColsError) && $centralColsError !== true) {
324 $message = $centralColsError;
325 } else {
326 $message = Message::success(__('Success!'));
328 } else {
329 $message = Message::success(__('No change'));