2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Helper for multi submit forms
8 if (! defined('PHPMYADMIN')) {
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(
27 'selected_recent_table',
35 foreach ($request_params as $one_request_param) {
36 if (isset($_REQUEST[$one_request_param])) {
37 $GLOBALS[$one_request_param] = $_REQUEST[$one_request_param];
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']))
51 define('PMA_SUBMIT_MULT', 1);
52 if (isset($selected_db) && !empty($selected_db)) {
53 // coming from server database view - do something with
55 $selected = $selected_db;
57 } elseif (! empty($_POST['selected_tbl'])) {
58 // coming from database structure view - do something with
60 if ($submit_mult == 'print') {
61 include './tbl_printview.php';
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':
78 $query_type = $submit_mult;
80 $mult_btn = __('Yes');
84 include 'db_export.php';
88 $show_create = PMA_getHtmlShowCreate($GLOBALS['db'], $selected);
89 // Send response to client.
90 $response = PMA_Response
::getInstance();
91 $response->addJSON('message', $show_create);
93 case 'sync_unique_columns_central_list':
94 include_once 'libraries/central_columns.lib.php';
95 $centralColsError = PMA_syncUniqueColumns($selected);
97 case 'delete_unique_columns_central_list':
98 include_once 'libraries/central_columns.lib.php';
99 $centralColsError = PMA_deleteColumnsFromList($selected);
101 case 'make_consistent_with_central_list':
102 include_once 'libraries/central_columns.lib.php';
103 $centralColsError = PMA_makeConsistentWithList(
110 } elseif (isset($selected_fld) && !empty($selected_fld)) {
111 // coming from table structure view - do something with
113 $selected = $selected_fld;
115 $what_ret, $query_type_ret, $is_unset_submit_mult, $mult_btn_ret,
118 = PMA_getDataForSubmitMult(
119 $submit_mult, $GLOBALS['db'], $table,
122 //update the existing variables
123 if (isset($what_ret)) {
126 if (isset($query_type_ret)) {
127 $query_type = $query_type_ret;
129 if ($is_unset_submit_mult) {
132 if (isset($mult_btn_ret)) {
133 $mult_btn = $mult_btn_ret;
136 // coming from browsing - do something with selected rows
137 $what = 'row_delete';
138 $selected = $_REQUEST['rows_to_delete'];
148 $views = $GLOBALS['dbi']->getVirtualTables($db);
151 * Displays the confirmation form if required
153 if (!empty($submit_mult) && !empty($what)) {
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 .= '&goto=tbl_sql.php&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';
166 include_once './libraries/server_common.inc.php';
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));
189 $response->addHTML(PMA_getHtmlForOtherActions($what, $action, $_url_params, $full_query));
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) . ';'
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'] . ', ';
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
229 // for disabling foreign key checks while dropping tables
230 $GLOBALS['dbi']->query('SET FOREIGN_KEY_CHECKS = 0;');
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)) {
250 } elseif (!empty($sql_query_views)) {
251 $sql_query = $sql_query_views . ';';
252 unset($sql_query_views);
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);
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();
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;
304 $message = PMA_Message
::success(__('Success!'));
307 $message = PMA_Message
::success(__('No change'));