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(
28 'selected_recent_table',
36 foreach ($request_params as $one_request_param) {
37 if (isset($_REQUEST[$one_request_param])) {
38 $GLOBALS[$one_request_param] = $_REQUEST[$one_request_param];
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))
52 define('PMA_SUBMIT_MULT', 1);
53 if (isset($selected_db) && !empty($selected_db)) {
54 // coming from server database view - do something with
56 $selected = $selected_db;
58 } elseif (! empty($_POST['selected_tbl'])) {
59 // coming from database structure view - do something with
61 if ($submit_mult == 'print') {
62 include './tbl_printview.php';
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':
78 $query_type = $submit_mult;
80 $mult_btn = __('Yes');
84 include 'db_export.php';
89 } elseif (isset($selected_fld) && !empty($selected_fld)) {
90 // coming from table structure view - do something with
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,
98 //update the existing variables
99 if (isset($what_ret)) {
102 if (isset($query_type_ret)) {
103 $query_type = $query_type_ret;
105 if ($is_unset_submit_mult) {
108 if (isset($mult_btn_ret)) {
109 $mult_btn = $mult_btn_ret;
112 // coming from browsing - do something with selected rows
113 $what = 'row_delete';
114 $selected = $rows_to_delete;
118 $views = $GLOBALS['dbi']->getVirtualTables($db);
121 * Displays the confirmation form if required
123 if (!empty($submit_mult) && !empty($what)) {
126 if (strlen($table)) {
127 include './libraries/tbl_common.inc.php';
128 $url_query .= '&goto=tbl_sql.php&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';
134 include_once './libraries/server_common.inc.php';
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);
155 echo PMA_getHtmlForOtherActions($what, $action, $_url_params, $full_query);
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) . ';'
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'] . ', ';
183 $GLOBALS['dbi']->freeResult($result);
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
204 if (!empty($sql_query)) {
206 } elseif (!empty($sql_query_views)) {
207 $sql_query = $sql_query_views . ';';
208 unset($sql_query_views);
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);
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();
252 $message = PMA_Message
::success(__('No change'));