1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Helper for multi submit forms
*
* @package PhpMyAdmin
*/
if (! defined('PHPMYADMIN')) {
exit;
}
require_once 'libraries/transformations.lib.php';
require_once 'libraries/bookmark.lib.php';
require_once 'libraries/sql.lib.php';
require_once 'libraries/mult_submits.lib.php';
$request_params = array(
'clause_is_unique',
'from_prefix',
'goto',
'mult_btn',
'original_sql_query',
'query_type',
'reload',
'rows_to_delete',
'selected',
'selected_fld',
'selected_recent_table',
'sql_query',
'submit_mult',
'table_type',
'to_prefix',
'url_query'
);
foreach ($request_params as $one_request_param) {
if (isset($_REQUEST[$one_request_param])) {
$GLOBALS[$one_request_param] = $_REQUEST[$one_request_param];
}
}
/**
* Prepares the work and runs some other scripts if required
*/
if (! empty($submit_mult)
&& $submit_mult != __('With selected:')
&& (! empty($selected_db)
|| ! empty($_POST['selected_tbl'])
|| ! empty($selected_fld)
|| ! empty($rows_to_delete))
) {
define('PMA_SUBMIT_MULT', 1);
if (isset($selected_db) && !empty($selected_db)) {
// coming from server database view - do something with
// selected databases
$selected = $selected_db;
$what = 'drop_db';
} elseif (! empty($_POST['selected_tbl'])) {
// coming from database structure view - do something with
// selected tables
if ($submit_mult == 'print') {
include './tbl_printview.php';
} else {
$selected = $_POST['selected_tbl'];
switch ($submit_mult) {
case 'add_prefix_tbl':
case 'replace_prefix_tbl':
case 'copy_tbl_change_prefix':
case 'drop_db':
case 'drop_tbl':
case 'empty_tbl':
$what = $submit_mult;
break;
case 'check_tbl':
case 'optimize_tbl':
case 'repair_tbl':
case 'analyze_tbl':
$query_type = $submit_mult;
unset($submit_mult);
$mult_btn = __('Yes');
break;
case 'export':
unset($submit_mult);
include 'db_export.php';
exit;
break;
} // end switch
}
} elseif (isset($selected_fld) && !empty($selected_fld)) {
// coming from table structure view - do something with
// selected columns
$selected = $selected_fld;
list($what_ret, $query_type_ret, $is_unset_submit_mult, $mult_btn_ret)
= PMA_getDataForSubmitMult(
$submit_mult, $db, $table,
$selected, $action
);
//update the existing variables
if (isset($what_ret)) {
$what = $what_ret;
}
if (isset($query_type_ret)) {
$query_type = $query_type_ret;
}
if ($is_unset_submit_mult) {
unset($submit_mult);
}
if (isset($mult_btn_ret)) {
$mult_btn = $mult_btn_ret;
}
} else {
// coming from browsing - do something with selected rows
$what = 'row_delete';
$selected = $rows_to_delete;
}
} // end if
if (empty($db)) {
$db = '';
}
if (empty($table)) {
$table = '';
}
$views = $GLOBALS['dbi']->getVirtualTables($db);
/**
* Displays the confirmation form if required
*/
if (!empty($submit_mult) && !empty($what)) {
unset($message);
if (strlen($table)) {
include './libraries/tbl_common.inc.php';
$url_query .= '&goto=tbl_sql.php&back=tbl_sql.php';
include './libraries/tbl_info.inc.php';
} elseif (strlen($db)) {
include './libraries/db_common.inc.php';
include './libraries/db_info.inc.php';
} else {
include_once './libraries/server_common.inc.php';
}
// Builds the query
list($full_query, $reload, $full_query_views)
= PMA_getQueryFromSelected(
$what, $db, $table, $selected, $action, $views
);
// Displays the confirmation form
$_url_params = PMA_getUrlParams(
$what, $reload, $action, $db, $table, $selected, $views,
isset($original_sql_query)? $original_sql_query : null,
isset($original_url_query)? $original_url_query : null
);
if ($what == 'replace_prefix_tbl' || $what == 'copy_tbl_change_prefix') {
echo PMA_getHtmlForReplacePrefixTable($what, $action, $_url_params);
} elseif ($what == 'add_prefix_tbl') {
echo PMA_getHtmlForAddPrefixTable($action, $_url_params);
} else {
echo PMA_getHtmlForOtherActions($what, $action, $_url_params, $full_query);
}
exit;
} elseif (! empty($mult_btn) && $mult_btn == __('Yes')) {
/**
* Executes the query - dropping rows, columns/fields, tables or dbs
*/
if ($query_type == 'drop_db'
|| $query_type == 'drop_tbl'
|| $query_type == 'drop_fld'
) {
include_once './libraries/relation_cleanup.lib.php';
}
if ($query_type == 'primary_fld') {
// Gets table primary key
$GLOBALS['dbi']->selectDb($db);
$result = $GLOBALS['dbi']->query(
'SHOW KEYS FROM ' . PMA_Util::backquote($table) . ';'
);
$primary = '';
while ($row = $GLOBALS['dbi']->fetchAssoc($result)) {
// Backups the list of primary keys
if ($row['Key_name'] == 'PRIMARY') {
$primary .= $row['Column_name'] . ', ';
}
} // end while
$GLOBALS['dbi']->freeResult($result);
}
list(
$result, $rebuild_database_list, $reload_ret,
$run_parts, $use_sql, $sql_query, $sql_query_views
) = PMA_getQueryStrFromSelected(
$query_type, $selected, $db, $table, $views,
isset($primary) ? $primary : null,
isset($from_prefix) ? $from_prefix : null,
isset($to_prefix) ? $to_prefix : null
);
//update the existed variable
if (isset($reload_ret)) {
$reload = $reload_ret;
}
if ($query_type == 'drop_tbl') {
$default_fk_check_value = $GLOBALS['dbi']->fetchValue(
'SHOW VARIABLES LIKE \'foreign_key_checks\';', 0, 1
) == 'ON';
if (!empty($sql_query)) {
$sql_query .= ';';
} elseif (!empty($sql_query_views)) {
$sql_query = $sql_query_views . ';';
unset($sql_query_views);
}
}
if ($use_sql) {
/**
* Parse and analyze the query
*/
include_once 'libraries/parse_analyze.inc.php';
PMA_executeQueryAndSendQueryResponse(
$analyzed_sql_results, false, $db, $table, null, null, null,
false, null, null, null, null, $goto, $pmaThemeImage, null, null,
$query_type, $sql_query, $selected, null
);
} elseif (!$run_parts) {
$GLOBALS['dbi']->selectDb($db);
// for disabling foreign key checks while dropping tables
if (! isset($_REQUEST['fk_check']) && $query_type == 'drop_tbl') {
$GLOBALS['dbi']->query('SET FOREIGN_KEY_CHECKS = 0;');
}
$result = $GLOBALS['dbi']->tryQuery($sql_query);
if (! isset($_REQUEST['fk_check'])
&& $query_type == 'drop_tbl'
&& $default_fk_check_value
) {
$GLOBALS['dbi']->query('SET FOREIGN_KEY_CHECKS = 1;');
}
if ($result && !empty($sql_query_views)) {
$sql_query .= ' ' . $sql_query_views . ';';
$result = $GLOBALS['dbi']->tryQuery($sql_query_views);
unset($sql_query_views);
}
if (! $result) {
$message = PMA_Message::error($GLOBALS['dbi']->getError());
}
}
if ($rebuild_database_list) {
// avoid a problem with the database list navigator
// when dropping a db from server_databases
$GLOBALS['pma']->databases->build();
}
} else {
$message = PMA_Message::success(__('No change'));
}
?>
|