2 /* vim: set expandtab sw=4 ts=4 sts=4: */
8 if (! defined('PHPMYADMIN')) {
13 * Prepares the work and runs some other scripts if required
15 if (! empty($submit_mult)
16 && $submit_mult != $strWithChecked
17 && (! empty($selected_db)
18 ||
! empty($selected_tbl)
19 ||
! empty($selected_fld)
20 ||
! empty($rows_to_delete))) {
21 define('PMA_SUBMIT_MULT', 1);
22 if (isset($selected_db) && !empty($selected_db)) {
23 // coming from server database view - do something with selected databases
24 $selected = $selected_db;
26 } elseif (isset($selected_tbl) && !empty($selected_tbl)) {
27 // coming from database structure view - do something with selected tables
28 if ($submit_mult == $strPrintView) {
29 require './tbl_printview.php';
31 $selected = $selected_tbl;
32 switch ($submit_mult) {
44 $query_type = 'check_tbl';
47 case $strOptimizeTable:
49 $query_type = 'optimize_tbl';
54 $query_type = 'repair_tbl';
57 case $strAnalyzeTable:
59 $query_type = 'analyze_tbl';
64 require('db_export.php');
69 } elseif (isset($selected_fld) && !empty($selected_fld)) {
70 // coming from table structure view - do something with selected columns/fileds
71 $selected = $selected_fld;
72 switch ($submit_mult) {
77 // Gets table primary key
78 PMA_DBI_select_db($db);
79 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
81 while ($row = PMA_DBI_fetch_assoc($result)) {
82 // Backups the list of primary keys
83 if ($row['Key_name'] == 'PRIMARY') {
84 $primary .= $row['Column_name'] . ', ';
87 PMA_DBI_free_result($result);
88 if (empty($primary)) {
89 // no primary key, so we can safely create new
91 $query_type = 'primary_fld';
94 // primary key exists, so lets as user
95 $what = 'primary_fld';
100 $query_type = 'index_fld';
105 $query_type = 'unique_fld';
108 case $strIdxFulltext:
110 $query_type = 'fulltext_fld';
114 require './tbl_alter.php';
117 // this should already be handled by tbl_structure.php
120 // coming from borwsing - do something with selected rows
121 $what = 'row_delete';
122 $selected = $rows_to_delete;
128 * Displays the confirmation form if required
130 if (!empty($submit_mult) && !empty($what)) {
131 $GLOBALS['js_include'][] = 'functions.js';
134 require_once './libraries/header.inc.php';
135 if (strlen($table)) {
136 require './libraries/tbl_common.php';
137 $url_query .= '&goto=tbl_sql.php&back=tbl_sql.php';
138 require './libraries/tbl_info.inc.php';
139 require_once './libraries/tbl_links.inc.php';
140 } elseif (strlen($db)) {
141 require './libraries/db_common.inc.php';
142 require './libraries/db_info.inc.php';
144 require_once './libraries/server_common.inc.php';
145 require_once './libraries/server_links.inc.php';
150 if ($what == 'drop_tbl') {
151 $full_query_views = '';
153 $selected_cnt = count($selected);
155 foreach ($selected AS $idx => $sval) {
158 $full_query .= htmlspecialchars($sval)
162 $full_query .= 'DROP DATABASE '
163 . PMA_backquote(htmlspecialchars($sval))
170 if (!empty($views) && in_array($current, $views)) {
171 $full_query_views .= (empty($full_query_views) ?
'DROP VIEW ' : ', ')
172 . PMA_backquote(htmlspecialchars($current));
174 $full_query .= (empty($full_query) ?
'DROP TABLE ' : ', ')
175 . PMA_backquote(htmlspecialchars($current));
180 $full_query .= 'TRUNCATE ';
181 $full_query .= PMA_backquote(htmlspecialchars($sval))
186 if ($full_query == '') {
187 $full_query .= 'ALTER TABLE '
188 . PMA_backquote(htmlspecialchars($table))
189 . '<br /> DROP PRIMARY KEY,'
190 . '<br /> ADD PRIMARY KEY('
191 . '<br /> '
192 . PMA_backquote(htmlspecialchars($sval))
195 $full_query .= '<br /> '
196 . PMA_backquote(htmlspecialchars($sval))
199 if ($i == $selected_cnt-1) {
200 $full_query = preg_replace('@,$@', ');<br />', $full_query);
205 if ($full_query == '') {
206 $full_query .= 'ALTER TABLE '
207 . PMA_backquote(htmlspecialchars($table));
209 $full_query .= '<br /> DROP '
210 . PMA_backquote(htmlspecialchars($sval))
212 if ($i == $selected_cnt - 1) {
213 $full_query = preg_replace('@,$@', ';<br />', $full_query);
219 if ($what == 'drop_tbl') {
220 if (!empty($full_query)) {
221 $full_query .= ';<br />' . "\n";
223 if (!empty($full_query_views)) {
224 $full_query .= $full_query_views . ';<br />' . "\n";
226 unset($full_query_views);
229 // Displays the confirmation form
230 $_url_params = array(
231 'query_type' => $what,
232 'reload' => (! empty($reload) ?
1 : 0),
234 if (strpos(' ' . $action, 'db_') == 1) {
235 $_url_params['db']= $db;
236 } elseif (strpos(' ' . $action, 'tbl_') == 1 ||
$what == 'row_delete') {
237 $_url_params['db']= $db;
238 $_url_params['table']= $table;
240 foreach ($selected as $idx => $sval) {
241 $_url_params['selected'][] = $sval;
243 if ($what == 'drop_tbl' && !empty($views)) {
244 foreach ($views as $current) {
245 $_url_params['views'][] = $current;
248 if ($what == 'row_delete') {
249 $_url_params['original_sql_query'] = $original_sql_query;
250 $_url_params['original_url_query'] = $original_url_query;
253 <form action
="<?php echo $action; ?>" method
="post">
255 echo PMA_generate_common_hidden_inputs($_url_params);
257 <fieldset
class="confirmation">
258 <legend
><?php
echo ($what == 'drop_db' ?
$strDropDatabaseStrongWarning . ' ' : '') . $strDoYouReally; ?
>:</legend
>
259 <tt
><?php
echo $full_query; ?
></tt
>
261 <fieldset
class="tblFooters">
262 <input type
="submit" name
="mult_btn" value
="<?php echo $strYes; ?>" id
="buttonYes" />
263 <input type
="submit" name
="mult_btn" value
="<?php echo $strNo; ?>" id
="buttonNo" />
266 require_once './libraries/footer.inc.php';
271 * Executes the query - dropping rows, columns/fields, tables or dbs
273 elseif ($mult_btn == $strYes) {
275 if ($query_type == 'drop_db' ||
$query_type == 'drop_tbl' ||
$query_type == 'drop_fld') {
276 require_once './libraries/relation_cleanup.lib.php';
280 if ($query_type == 'drop_tbl') {
281 $sql_query_views = '';
283 $selected_cnt = count($selected);
284 $run_parts = FALSE; // whether to run query after each pass
285 $use_sql = FALSE; // whether to include sql.php at the end (to display results)
287 if ($query_type == 'primary_fld') {
288 // Gets table primary key
289 PMA_DBI_select_db($db);
290 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
292 while ($row = PMA_DBI_fetch_assoc($result)) {
293 // Backups the list of primary keys
294 if ($row['Key_name'] == 'PRIMARY') {
295 $primary .= $row['Column_name'] . ', ';
298 PMA_DBI_free_result($result);
301 $rebuild_database_list = false;
303 for ($i = 0; $i < $selected_cnt; $i++
) {
304 switch ($query_type) {
306 $a_query = $selected[$i];
311 PMA_relationsCleanupDatabase($selected[$i]);
312 $a_query = 'DROP DATABASE '
313 . PMA_backquote($selected[$i]);
316 $rebuild_database_list = true;
320 PMA_relationsCleanupTable($db, $selected[$i]);
321 $current = $selected[$i];
322 if (!empty($views) && in_array($current, $views)) {
323 $sql_query_views .= (empty($sql_query_views) ?
'DROP VIEW ' : ', ')
324 . PMA_backquote($current);
326 $sql_query .= (empty($sql_query) ?
'DROP TABLE ' : ', ')
327 . PMA_backquote($current);
333 $sql_query .= (empty($sql_query) ?
'CHECK TABLE ' : ', ')
334 . PMA_backquote($selected[$i]);
339 $sql_query .= (empty($sql_query) ?
'OPTIMIZE TABLE ' : ', ')
340 . PMA_backquote($selected[$i]);
345 $sql_query .= (empty($sql_query) ?
'ANALYZE TABLE ' : ', ')
346 . PMA_backquote($selected[$i]);
351 $sql_query .= (empty($sql_query) ?
'REPAIR TABLE ' : ', ')
352 . PMA_backquote($selected[$i]);
357 $a_query = 'TRUNCATE ';
358 $a_query .= PMA_backquote(htmlspecialchars($selected[$i]));
363 PMA_relationsCleanupColumn($db, $table, $selected[$i]);
364 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) : ',')
365 . ' DROP ' . PMA_backquote($selected[$i])
366 . (($i == $selected_cnt-1) ?
';' : '');
370 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . (empty($primary) ?
'' : ' DROP PRIMARY KEY,') . ' ADD PRIMARY KEY( ' : ', ')
371 . PMA_backquote($selected[$i])
372 . (($i == $selected_cnt-1) ?
');' : '');
376 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . ' ADD INDEX( ' : ', ')
377 . PMA_backquote($selected[$i])
378 . (($i == $selected_cnt-1) ?
');' : '');
382 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . ' ADD UNIQUE( ' : ', ')
383 . PMA_backquote($selected[$i])
384 . (($i == $selected_cnt-1) ?
');' : '');
388 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . ' ADD FULLTEXT( ' : ', ')
389 . PMA_backquote($selected[$i])
390 . (($i == $selected_cnt-1) ?
');' : '');
394 // All "DROP TABLE", "DROP FIELD", "OPTIMIZE TABLE" and "REPAIR TABLE"
395 // statements will be run at once below
397 $sql_query .= $a_query . ';' . "\n";
398 if ($query_type != 'drop_db') {
399 PMA_DBI_select_db($db);
401 $result = PMA_DBI_query($a_query);
405 if ($query_type == 'drop_tbl') {
406 if (!empty($sql_query)) {
408 } elseif (!empty($sql_query_views)) {
409 $sql_query = $sql_query_views . ';';
410 unset($sql_query_views);
416 } elseif (!$run_parts) {
417 PMA_DBI_select_db($db);
418 $result = PMA_DBI_try_query($sql_query);
419 if ($result && !empty($sql_query_views)) {
420 $sql_query .= ' ' . $sql_query_views . ';';
421 $result = PMA_DBI_try_query($sql_query_views);
422 unset($sql_query_views);
426 $message = PMA_Message
::error(PMA_DBI_getError());
429 if ($rebuild_database_list) {
430 // avoid a problem with the database list navigator
431 // when dropping a db from server_databases
432 $GLOBALS['pma']->databases
->build();
435 $message = PMA_Message
::success('strNoModification');