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 != __('With selected:')
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 == __('Print view')) {
28 require './tbl_printview.php';
30 $selected = $selected_tbl;
31 switch ($submit_mult) {
41 case __('Check table'):
43 $query_type = 'check_tbl';
44 $mult_btn = __('Yes');
46 case __('Optimize table'):
48 $query_type = 'optimize_tbl';
49 $mult_btn = __('Yes');
51 case __('Repair table'):
53 $query_type = 'repair_tbl';
54 $mult_btn = __('Yes');
56 case __('Analyze table'):
58 $query_type = 'analyze_tbl';
59 $mult_btn = __('Yes');
63 require('db_export.php');
68 } elseif (isset($selected_fld) && !empty($selected_fld)) {
69 // coming from table structure view - do something with selected columns/fileds
70 $selected = $selected_fld;
71 switch ($submit_mult) {
76 // Gets table primary key
77 PMA_DBI_select_db($db);
78 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
80 while ($row = PMA_DBI_fetch_assoc($result)) {
81 // Backups the list of primary keys
82 if ($row['Key_name'] == 'PRIMARY') {
83 $primary .= $row['Column_name'] . ', ';
86 PMA_DBI_free_result($result);
87 if (empty($primary)) {
88 // no primary key, so we can safely create new
90 $query_type = 'primary_fld';
91 $mult_btn = __('Yes');
93 // primary key exists, so lets as user
94 $what = 'primary_fld';
99 $query_type = 'index_fld';
100 $mult_btn = __('Yes');
104 $query_type = 'unique_fld';
105 $mult_btn = __('Yes');
109 $query_type = 'fulltext_fld';
110 $mult_btn = __('Yes');
113 require './tbl_alter.php';
116 // this should already be handled by tbl_structure.php
119 // coming from borwsing - do something with selected rows
120 $what = 'row_delete';
121 $selected = $rows_to_delete;
127 * Displays the confirmation form if required
129 if (!empty($submit_mult) && !empty($what)) {
132 require_once './libraries/header.inc.php';
133 if (strlen($table)) {
134 require './libraries/tbl_common.php';
135 $url_query .= '&goto=tbl_sql.php&back=tbl_sql.php';
136 require './libraries/tbl_info.inc.php';
137 require_once './libraries/tbl_links.inc.php';
138 } elseif (strlen($db)) {
139 require './libraries/db_common.inc.php';
140 require './libraries/db_info.inc.php';
142 require_once './libraries/server_common.inc.php';
143 require_once './libraries/server_links.inc.php';
148 if ($what == 'drop_tbl') {
149 $full_query_views = '';
151 $selected_cnt = count($selected);
153 foreach ($selected AS $idx => $sval) {
156 $full_query .= htmlspecialchars($sval)
160 $full_query .= 'DROP DATABASE '
161 . PMA_backquote(htmlspecialchars($sval))
168 if (!empty($views) && in_array($current, $views)) {
169 $full_query_views .= (empty($full_query_views) ?
'DROP VIEW ' : ', ')
170 . PMA_backquote(htmlspecialchars($current));
172 $full_query .= (empty($full_query) ?
'DROP TABLE ' : ', ')
173 . PMA_backquote(htmlspecialchars($current));
178 $full_query .= 'TRUNCATE ';
179 $full_query .= PMA_backquote(htmlspecialchars($sval))
184 if ($full_query == '') {
185 $full_query .= 'ALTER TABLE '
186 . PMA_backquote(htmlspecialchars($table))
187 . '<br /> DROP PRIMARY KEY,'
188 . '<br /> ADD PRIMARY KEY('
189 . '<br /> '
190 . PMA_backquote(htmlspecialchars($sval))
193 $full_query .= '<br /> '
194 . PMA_backquote(htmlspecialchars($sval))
197 if ($i == $selected_cnt-1) {
198 $full_query = preg_replace('@,$@', ');<br />', $full_query);
203 if ($full_query == '') {
204 $full_query .= 'ALTER TABLE '
205 . PMA_backquote(htmlspecialchars($table));
207 $full_query .= '<br /> DROP '
208 . PMA_backquote(htmlspecialchars($sval))
210 if ($i == $selected_cnt - 1) {
211 $full_query = preg_replace('@,$@', ';<br />', $full_query);
217 if ($what == 'drop_tbl') {
218 if (!empty($full_query)) {
219 $full_query .= ';<br />' . "\n";
221 if (!empty($full_query_views)) {
222 $full_query .= $full_query_views . ';<br />' . "\n";
224 unset($full_query_views);
227 // Displays the confirmation form
228 $_url_params = array(
229 'query_type' => $what,
230 'reload' => (! empty($reload) ?
1 : 0),
232 if (strpos(' ' . $action, 'db_') == 1) {
233 $_url_params['db']= $db;
234 } elseif (strpos(' ' . $action, 'tbl_') == 1 ||
$what == 'row_delete') {
235 $_url_params['db']= $db;
236 $_url_params['table']= $table;
238 foreach ($selected as $idx => $sval) {
239 $_url_params['selected'][] = $sval;
241 if ($what == 'drop_tbl' && !empty($views)) {
242 foreach ($views as $current) {
243 $_url_params['views'][] = $current;
246 if ($what == 'row_delete') {
247 $_url_params['original_sql_query'] = $original_sql_query;
248 if (! empty($original_url_query)) {
249 $_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' ?
__('You are about to DESTROY a complete database!') . ' ' : '') . __('Do you really want to '); ?
>:</legend
>
259 <tt
><?php
echo $full_query; ?
></tt
>
261 <fieldset
class="tblFooters">
262 <input type
="submit" name
="mult_btn" value
="<?php echo __('Yes'); ?>" id
="buttonYes" />
263 <input type
="submit" name
="mult_btn" value
="<?php echo __('No'); ?>" id
="buttonNo" />
266 require './libraries/footer.inc.php';
271 * Executes the query - dropping rows, columns/fields, tables or dbs
273 elseif ($mult_btn == __('Yes')) {
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(__('No change'));