2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Helper for multi submit forms
8 use PMA\libraries\Message
;
9 use PMA\libraries\Response
;
11 if (! defined('PHPMYADMIN')) {
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(
29 'selected_recent_table',
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;
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']))
59 define('PMA_SUBMIT_MULT', 1);
60 if (! empty($_REQUEST['selected_dbs'])) {
61 // coming from server database view - do something with
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
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':
83 $query_type = $submit_mult;
85 $mult_btn = __('Yes');
89 include 'db_export.php';
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();
104 PMA_getHtmlForCopyMultipleTables($action, $_url_params)
108 $show_create = PMA\libraries\Template
::get(
109 'database/structure/show_create'
113 'db' => $GLOBALS['db'],
114 'db_objects' => $selected,
117 // Send response to client.
118 $response->addJSON('message', $show_create);
120 case 'sync_unique_columns_central_list':
121 include_once 'libraries/central_columns.lib.php';
122 $centralColsError = PMA_syncUniqueColumns($selected);
124 case 'delete_unique_columns_central_list':
125 include_once 'libraries/central_columns.lib.php';
126 $centralColsError = PMA_deleteColumnsFromList($selected);
128 case 'make_consistent_with_central_list':
129 include_once 'libraries/central_columns.lib.php';
130 $centralColsError = PMA_makeConsistentWithList(
136 } elseif (isset($selected_fld) && !empty($selected_fld)) {
137 // coming from table structure view - do something with
139 // handled in StructrueController
141 // coming from browsing - do something with selected rows
142 $what = 'row_delete';
143 $selected = $_REQUEST['rows_to_delete'];
153 $views = $GLOBALS['dbi']->getVirtualTables($db);
156 * Displays the confirmation form if required
158 if (!empty($submit_mult) && !empty($what)) {
161 if (strlen($table) > 0) {
162 include './libraries/tbl_common.inc.php';
163 $url_query .= '&goto=tbl_sql.php&back=tbl_sql.php';
164 include './libraries/tbl_info.inc.php';
165 } elseif (strlen($db) > 0) {
166 include './libraries/db_common.inc.php';
174 $db_is_system_schema,
178 ) = PMA\libraries\Util
::getDbInfo($db, isset($sub_part) ?
$sub_part : '');
181 include_once './libraries/server_common.inc.php';
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();
201 PMA_getHtmlForReplacePrefixTable($action, $_url_params)
203 } elseif ($what == 'add_prefix_tbl') {
204 $response->disable();
205 $response->addHTML(PMA_getHtmlForAddPrefixTable($action, $_url_params));
208 PMA_getHtmlForOtherActions($what, $action, $_url_params, $full_query)
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) . ';'
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'] . ', ';
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();
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)) {
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
276 null, // find_real_end
277 null, // sql_query_for_bookmark
279 null, // message_to_show
283 $pmaThemeImage, // pmaThemeImage
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);
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();
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;
326 $message = Message
::success(__('Success!'));
329 $message = Message
::success(__('No change'));