Translated using Weblate (Danish)
[phpmyadmin.git] / libraries / mult_submits.inc.php
blobb52087feee6008e7ee05862c2c5a1ffd4addc34c
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 'rows_to_delete',
26 'selected',
27 'selected_fld',
28 'selected_recent_table',
29 'sql_query',
30 'submit_mult',
31 'table_type',
32 'to_prefix',
33 'url_query'
36 foreach ($request_params as $one_request_param) {
37 if (isset($_REQUEST[$one_request_param])) {
38 $GLOBALS[$one_request_param] = $_REQUEST[$one_request_param];
42 /**
43 * Prepares the work and runs some other scripts if required
45 if (! empty($submit_mult)
46 && $submit_mult != __('With selected:')
47 && (! empty($selected_db)
48 || ! empty($_POST['selected_tbl'])
49 || ! empty($selected_fld)
50 || ! empty($rows_to_delete))
51 ) {
52 define('PMA_SUBMIT_MULT', 1);
53 if (isset($selected_db) && !empty($selected_db)) {
54 // coming from server database view - do something with
55 // selected databases
56 $selected = $selected_db;
57 $what = 'drop_db';
58 } elseif (! empty($_POST['selected_tbl'])) {
59 // coming from database structure view - do something with
60 // selected tables
61 if ($submit_mult == 'print') {
62 include './tbl_printview.php';
63 } else {
64 $selected = $_POST['selected_tbl'];
65 switch ($submit_mult) {
66 case 'add_prefix_tbl':
67 case 'replace_prefix_tbl':
68 case 'copy_tbl_change_prefix':
69 case 'drop_db':
70 case 'drop_tbl':
71 case 'empty_tbl':
72 $what = $submit_mult;
73 break;
74 case 'check_tbl':
75 case 'optimize_tbl':
76 case 'repair_tbl':
77 case 'analyze_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 } // end switch
89 } elseif (isset($selected_fld) && !empty($selected_fld)) {
90 // coming from table structure view - do something with
91 // selected columns
92 $selected = $selected_fld;
93 list($what_ret, $query_type_ret, $is_unset_submit_mult, $mult_btn_ret)
94 = PMA_getDataForSubmitMult(
95 $submit_mult, $db, $table,
96 $selected, $action
98 //update the existing variables
99 if (isset($what_ret)) {
100 $what = $what_ret;
102 if (isset($query_type_ret)) {
103 $query_type = $query_type_ret;
105 if ($is_unset_submit_mult) {
106 unset($submit_mult);
108 if (isset($mult_btn_ret)) {
109 $mult_btn = $mult_btn_ret;
111 } else {
112 // coming from browsing - do something with selected rows
113 $what = 'row_delete';
114 $selected = $rows_to_delete;
116 } // end if
118 $views = $GLOBALS['dbi']->getVirtualTables($db);
121 * Displays the confirmation form if required
123 if (!empty($submit_mult) && !empty($what)) {
124 unset($message);
126 if (strlen($table)) {
127 include './libraries/tbl_common.inc.php';
128 $url_query .= '&amp;goto=tbl_sql.php&amp;back=tbl_sql.php';
129 include './libraries/tbl_info.inc.php';
130 } elseif (strlen($db)) {
131 include './libraries/db_common.inc.php';
132 include './libraries/db_info.inc.php';
133 } else {
134 include_once './libraries/server_common.inc.php';
137 // Builds the query
138 list($full_query, $reload, $full_query_views)
139 = PMA_getQueryFromSelected(
140 $what, $db, $table, $selected, $action, $views
143 // Displays the confirmation form
144 $_url_params = PMA_getUrlParams(
145 $what, $reload, $action, $db, $table, $selected, $views,
146 isset($original_sql_query)? $original_sql_query : null,
147 isset($original_url_query)? $original_url_query : null
150 if ($what == 'replace_prefix_tbl' || $what == 'copy_tbl_change_prefix') {
151 echo PMA_getHtmlForReplacePrefixTable($what, $action, $_url_params);
152 } elseif ($what == 'add_prefix_tbl') {
153 echo PMA_getHtmlForAddPrefixTable($action, $_url_params);
154 } else {
155 echo PMA_getHtmlForOtherActions($what, $action, $_url_params, $full_query);
157 exit;
159 } elseif (! empty($mult_btn) && $mult_btn == __('Yes')) {
161 * Executes the query - dropping rows, columns/fields, tables or dbs
163 if ($query_type == 'drop_db'
164 || $query_type == 'drop_tbl'
165 || $query_type == 'drop_fld'
167 include_once './libraries/relation_cleanup.lib.php';
170 if ($query_type == 'primary_fld') {
171 // Gets table primary key
172 $GLOBALS['dbi']->selectDb($db);
173 $result = $GLOBALS['dbi']->query(
174 'SHOW KEYS FROM ' . PMA_Util::backquote($table) . ';'
176 $primary = '';
177 while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
178 // Backups the list of primary keys
179 if ($row['Key_name'] == 'PRIMARY') {
180 $primary .= $row['Column_name'] . ', ';
182 } // end while
183 $GLOBALS['dbi']->freeResult($result);
186 list(
187 $result, $rebuild_database_list, $reload_ret,
188 $run_parts, $use_sql, $sql_query, $sql_query_views
189 ) = PMA_getQueryStrFromSelected(
190 $query_type, $selected, $db, $table, $views,
191 isset($primary) ? $primary : null,
192 isset($from_prefix) ? $from_prefix : null,
193 isset($to_prefix) ? $to_prefix : null
195 //update the existed variable
196 if (isset($reload_ret)) {
197 $reload = $reload_ret;
200 if ($query_type == 'drop_tbl') {
201 $default_fk_check_value = $GLOBALS['dbi']->fetchValue(
202 'SHOW VARIABLES LIKE \'foreign_key_checks\';', 0, 1
203 ) == 'ON';
204 if (!empty($sql_query)) {
205 $sql_query .= ';';
206 } elseif (!empty($sql_query_views)) {
207 $sql_query = $sql_query_views . ';';
208 unset($sql_query_views);
212 if ($use_sql) {
214 * Parse and analyze the query
216 include_once 'libraries/parse_analyze.inc.php';
218 PMA_executeQueryAndSendQueryResponse(
219 $analyzed_sql_results, false, $db, $table, null, null, null,
220 false, null, null, null, null, $goto, $pmaThemeImage, null, null,
221 $query_type, $sql_query, $selected, null
223 } elseif (!$run_parts) {
224 $GLOBALS['dbi']->selectDb($db);
225 // for disabling foreign key checks while dropping tables
226 if (! isset($_REQUEST['fk_check']) && $query_type == 'drop_tbl') {
227 $GLOBALS['dbi']->query('SET FOREIGN_KEY_CHECKS = 0;');
229 $result = $GLOBALS['dbi']->tryQuery($sql_query);
230 if (! isset($_REQUEST['fk_check'])
231 && $query_type == 'drop_tbl'
232 && $default_fk_check_value
234 $GLOBALS['dbi']->query('SET FOREIGN_KEY_CHECKS = 1;');
236 if ($result && !empty($sql_query_views)) {
237 $sql_query .= ' ' . $sql_query_views . ';';
238 $result = $GLOBALS['dbi']->tryQuery($sql_query_views);
239 unset($sql_query_views);
242 if (! $result) {
243 $message = PMA_Message::error($GLOBALS['dbi']->getError());
246 if ($rebuild_database_list) {
247 // avoid a problem with the database list navigator
248 // when dropping a db from server_databases
249 $GLOBALS['pma']->databases->build();
251 } else {
252 $message = PMA_Message::success(__('No change'));