2 /* vim: set expandtab sw=4 ts=4 sts=4: */
7 if (! defined('PHPMYADMIN')) {
12 * Prepares the work and runs some other scripts if required
14 if (! empty($submit_mult)
15 && $submit_mult != $strWithChecked
16 && (! empty($selected_db)
17 ||
! empty($selected_tbl)
18 ||
! empty($selected_fld)
19 ||
! empty($rows_to_delete))) {
20 define('PMA_SUBMIT_MULT', 1);
21 if (isset($selected_db) && !empty($selected_db)) {
22 // coming from server database view - do something with selected databases
23 $selected = $selected_db;
25 } elseif (isset($selected_tbl) && !empty($selected_tbl)) {
26 // coming from database structure view - do something with selected tables
27 if ($submit_mult == $strPrintView) {
28 require './tbl_printview.php';
30 $selected = $selected_tbl;
31 switch ($submit_mult) {
43 $query_type = 'check_tbl';
46 case $strOptimizeTable:
48 $query_type = 'optimize_tbl';
53 $query_type = 'repair_tbl';
56 case $strAnalyzeTable:
58 $query_type = 'analyze_tbl';
63 } elseif (isset($selected_fld) && !empty($selected_fld)) {
64 // coming from table structure view - do something with selected columns/fileds
65 $selected = $selected_fld;
66 switch ($submit_mult) {
71 // Gets table primary key
72 PMA_DBI_select_db($db);
73 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
75 while ($row = PMA_DBI_fetch_assoc($result)) {
76 // Backups the list of primary keys
77 if ($row['Key_name'] == 'PRIMARY') {
78 $primary .= $row['Column_name'] . ', ';
81 PMA_DBI_free_result($result);
82 if (empty($primary)) {
83 // no primary key, so we can safely create new
85 $query_type = 'primary_fld';
88 // primary key exists, so lets as user
89 $what = 'primary_fld';
94 $query_type = 'index_fld';
99 $query_type = 'unique_fld';
102 case $strIdxFulltext:
104 $query_type = 'fulltext_fld';
108 require './tbl_alter.php';
111 // this should already be handled by tbl_structure.php
114 // coming from borwsing - do something with selected rows
115 $what = 'row_delete';
116 $selected = $rows_to_delete;
122 * Displays the confirmation form if required
124 if (!empty($submit_mult) && !empty($what)) {
125 $GLOBALS['js_include'][] = 'functions.js';
128 require_once './libraries/header.inc.php';
129 if (strlen($table)) {
130 require './libraries/tbl_common.php';
131 $url_query .= '&goto=tbl_sql.php&back=tbl_sql.php';
132 require './libraries/tbl_info.inc.php';
133 require_once './libraries/tbl_links.inc.php';
134 } elseif (strlen($db)) {
135 require './libraries/db_common.inc.php';
136 require './libraries/db_info.inc.php';
138 require_once './libraries/server_common.inc.php';
139 require_once './libraries/server_links.inc.php';
144 if ($what == 'drop_tbl') {
145 $full_query_views = '';
147 $selected_cnt = count($selected);
149 foreach ($selected AS $idx => $sval) {
152 $full_query .= htmlspecialchars($sval)
156 $full_query .= 'DROP DATABASE '
157 . PMA_backquote(htmlspecialchars($sval))
164 if (!empty($views) && in_array($current, $views)) {
165 $full_query_views .= (empty($full_query_views) ?
'DROP VIEW ' : ', ')
166 . PMA_backquote(htmlspecialchars($current));
168 $full_query .= (empty($full_query) ?
'DROP TABLE ' : ', ')
169 . PMA_backquote(htmlspecialchars($current));
174 $full_query .= 'TRUNCATE ';
175 $full_query .= PMA_backquote(htmlspecialchars($sval))
180 if ($full_query == '') {
181 $full_query .= 'ALTER TABLE '
182 . PMA_backquote(htmlspecialchars($table))
183 . '<br /> DROP PRIMARY KEY,'
184 . '<br /> ADD PRIMARY KEY('
185 . '<br /> '
186 . PMA_backquote(htmlspecialchars($sval))
189 $full_query .= '<br /> '
190 . PMA_backquote(htmlspecialchars($sval))
193 if ($i == $selected_cnt-1) {
194 $full_query = preg_replace('@,$@', ');<br />', $full_query);
199 if ($full_query == '') {
200 $full_query .= 'ALTER TABLE '
201 . PMA_backquote(htmlspecialchars($table));
203 $full_query .= '<br /> DROP '
204 . PMA_backquote(htmlspecialchars($sval))
206 if ($i == $selected_cnt - 1) {
207 $full_query = preg_replace('@,$@', ';<br />', $full_query);
213 if ($what == 'drop_tbl') {
214 if (!empty($full_query)) {
215 $full_query .= ';<br />' . "\n";
217 if (!empty($full_query_views)) {
218 $full_query .= $full_query_views . ';<br />' . "\n";
220 unset($full_query_views);
223 // Displays the confirmation form
224 $_url_params = array(
225 'query_type' => $what,
226 'reload' => (! empty($reload) ?
1 : 0),
228 if (strpos(' ' . $action, 'db_') == 1) {
229 $_url_params['db']= $db;
230 } elseif (strpos(' ' . $action, 'tbl_') == 1 ||
$what == 'row_delete') {
231 $_url_params['db']= $db;
232 $_url_params['table']= $table;
234 foreach ($selected as $idx => $sval) {
235 $_url_params['selected'][] = $sval;
237 if ($what == 'drop_tbl' && !empty($views)) {
238 foreach ($views as $current) {
239 $_url_params['views'][] = $current;
242 if ($what == 'row_delete') {
243 $_url_params['original_sql_query'] = $original_sql_query;
244 $_url_params['original_url_query'] = $original_url_query;
247 <form action
="<?php echo $action; ?>" method
="post">
249 echo PMA_generate_common_hidden_inputs($_url_params);
251 <fieldset
class="confirmation">
252 <legend
><?php
echo ($what == 'drop_db' ?
$strDropDatabaseStrongWarning . ' ' : '') . $strDoYouReally; ?
>:</legend
>
253 <tt
><?php
echo $full_query; ?
></tt
>
255 <fieldset
class="tblFooters">
256 <input type
="submit" name
="mult_btn" value
="<?php echo $strYes; ?>" id
="buttonYes" />
257 <input type
="submit" name
="mult_btn" value
="<?php echo $strNo; ?>" id
="buttonNo" />
260 require_once './libraries/footer.inc.php';
265 * Executes the query - dropping rows, columns/fields, tables or dbs
267 elseif ($mult_btn == $strYes) {
269 if ($query_type == 'drop_db' ||
$query_type == 'drop_tbl' ||
$query_type == 'drop_fld') {
270 require_once './libraries/relation_cleanup.lib.php';
274 if ($query_type == 'drop_tbl') {
275 $sql_query_views = '';
277 $selected_cnt = count($selected);
278 $run_parts = FALSE; // whether to run query after each pass
279 $use_sql = FALSE; // whether to include sql.php at the end (to display results)
281 if ($query_type == 'primary_fld') {
282 // Gets table primary key
283 PMA_DBI_select_db($db);
284 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
286 while ($row = PMA_DBI_fetch_assoc($result)) {
287 // Backups the list of primary keys
288 if ($row['Key_name'] == 'PRIMARY') {
289 $primary .= $row['Column_name'] . ', ';
292 PMA_DBI_free_result($result);
295 $rebuild_database_list = false;
297 for ($i = 0; $i < $selected_cnt; $i++
) {
298 switch ($query_type) {
300 $a_query = $selected[$i];
305 PMA_relationsCleanupDatabase($selected[$i]);
306 $a_query = 'DROP DATABASE '
307 . PMA_backquote($selected[$i]);
310 $rebuild_database_list = true;
314 PMA_relationsCleanupTable($db, $selected[$i]);
315 $current = $selected[$i];
316 if (!empty($views) && in_array($current, $views)) {
317 $sql_query_views .= (empty($sql_query_views) ?
'DROP VIEW ' : ', ')
318 . PMA_backquote($current);
320 $sql_query .= (empty($sql_query) ?
'DROP TABLE ' : ', ')
321 . PMA_backquote($current);
327 $sql_query .= (empty($sql_query) ?
'CHECK TABLE ' : ', ')
328 . PMA_backquote($selected[$i]);
333 $sql_query .= (empty($sql_query) ?
'OPTIMIZE TABLE ' : ', ')
334 . PMA_backquote($selected[$i]);
339 $sql_query .= (empty($sql_query) ?
'ANALYZE TABLE ' : ', ')
340 . PMA_backquote($selected[$i]);
345 $sql_query .= (empty($sql_query) ?
'REPAIR TABLE ' : ', ')
346 . PMA_backquote($selected[$i]);
351 $a_query = 'TRUNCATE ';
352 $a_query .= PMA_backquote(htmlspecialchars($selected[$i]));
357 PMA_relationsCleanupColumn($db, $table, $selected[$i]);
358 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) : ',')
359 . ' DROP ' . PMA_backquote($selected[$i])
360 . (($i == $selected_cnt-1) ?
';' : '');
364 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . (empty($primary) ?
'' : ' DROP PRIMARY KEY,') . ' ADD PRIMARY KEY( ' : ', ')
365 . PMA_backquote($selected[$i])
366 . (($i == $selected_cnt-1) ?
');' : '');
370 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . ' ADD INDEX( ' : ', ')
371 . PMA_backquote($selected[$i])
372 . (($i == $selected_cnt-1) ?
');' : '');
376 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . ' ADD UNIQUE( ' : ', ')
377 . PMA_backquote($selected[$i])
378 . (($i == $selected_cnt-1) ?
');' : '');
382 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . ' ADD FULLTEXT( ' : ', ')
383 . PMA_backquote($selected[$i])
384 . (($i == $selected_cnt-1) ?
');' : '');
388 // All "DROP TABLE", "DROP FIELD", "OPTIMIZE TABLE" and "REPAIR TABLE"
389 // statements will be run at once below
391 $sql_query .= $a_query . ';' . "\n";
392 if ($query_type != 'drop_db') {
393 PMA_DBI_select_db($db);
395 $result = PMA_DBI_query($a_query);
399 if ($query_type == 'drop_tbl') {
400 if (!empty($sql_query)) {
402 } elseif (!empty($sql_query_views)) {
403 $sql_query = $sql_query_views . ';';
404 unset($sql_query_views);
410 } elseif (!$run_parts) {
411 PMA_DBI_select_db($db);
412 $result = PMA_DBI_try_query($sql_query);
413 if ($result && !empty($sql_query_views)) {
414 $sql_query .= ' ' . $sql_query_views . ';';
415 $result = PMA_DBI_try_query($sql_query_views);
416 unset($sql_query_views);
420 $message = PMA_Message
::error(PMA_DBI_getError());
423 if ($rebuild_database_list) {
424 // avoid a problem with the database list navigator
425 // when dropping a db from server_databases
426 $GLOBALS['pma']->databases
->build();
429 $message = PMA_Message
::success('strNoModification');