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 $selected = $selected_db;
24 } elseif (isset($selected_tbl) && !empty($selected_tbl)) {
25 if ($submit_mult == $strPrintView) {
26 require './tbl_printview.php';
28 $selected = $selected_tbl;
29 switch ($submit_mult) {
41 $query_type = 'check_tbl';
44 case $strOptimizeTable:
46 $query_type = 'optimize_tbl';
51 $query_type = 'repair_tbl';
54 case $strAnalyzeTable:
56 $query_type = 'analyze_tbl';
61 } elseif (isset($selected_fld) && !empty($selected_fld)) {
62 $selected = $selected_fld;
63 switch ($submit_mult) {
68 // Gets table primary key
69 PMA_DBI_select_db($db);
70 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
72 while ($row = PMA_DBI_fetch_assoc($result)) {
73 // Backups the list of primary keys
74 if ($row['Key_name'] == 'PRIMARY') {
75 $primary .= $row['Column_name'] . ', ';
78 PMA_DBI_free_result($result);
79 if (empty($primary)) {
80 // no primary key, so we can safely create new
82 $query_type = 'primary_fld';
85 // primary key exists, so lets as user
86 $what = 'primary_fld';
91 $query_type = 'index_fld';
96 $query_type = 'unique_fld';
101 $query_type = 'fulltext_fld';
105 require './tbl_alter.php';
109 foreach ($selected AS $idx => $sval) {
110 if ($sql_query == '') {
111 $sql_query .= 'SELECT ' . PMA_backquote(urldecode($sval));
113 $sql_query .= ', ' . PMA_backquote(urldecode($sval));
116 $sql_query .= ' FROM ' . PMA_backquote(htmlspecialchars($table));
121 $what = 'row_delete';
122 $selected = $rows_to_delete;
128 * Displays the confirmation form if required
130 if (!empty($submit_mult) && !empty($what)) {
131 $js_to_run = 'functions.js';
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 } elseif (strlen($db)) {
138 require './libraries/db_common.inc.php';
139 require './libraries/db_info.inc.php';
143 if ($what == 'drop_tbl') {
144 $full_query_views = '';
146 $selected_cnt = count($selected);
148 foreach ($selected AS $idx => $sval) {
151 $full_query .= htmlspecialchars(urldecode($sval))
155 $full_query .= 'DROP DATABASE '
156 . PMA_backquote(htmlspecialchars(urldecode($sval)))
162 $current = urldecode($sval);
163 // here we must compare with the value before urldecode()
164 // because $views has been treated with htmlspecialchars()
165 if (!empty($views) && in_array($sval, $views)) {
166 $full_query_views .= (empty($full_query_views) ?
'DROP VIEW ' : ', ')
167 . PMA_backquote(htmlspecialchars($current));
169 $full_query .= (empty($full_query) ?
'DROP TABLE ' : ', ')
170 . PMA_backquote(htmlspecialchars($current));
175 if (PMA_MYSQL_INT_VERSION
>= 40000) {
176 $full_query .= 'TRUNCATE ';
178 $full_query .= 'DELETE FROM ';
180 $full_query .= PMA_backquote(htmlspecialchars(urldecode($sval)))
185 if ($full_query == '') {
186 $full_query .= 'ALTER TABLE '
187 . PMA_backquote(htmlspecialchars($table))
188 . '<br /> DROP PRIMARY KEY,'
189 . '<br /> ADD PRIMARY KEY('
190 . '<br /> '
191 . PMA_backquote(htmlspecialchars(urldecode($sval)))
194 $full_query .= '<br /> '
195 . PMA_backquote(htmlspecialchars(urldecode($sval)))
198 if ($i == $selected_cnt-1) {
199 $full_query = preg_replace('@,$@', ');<br />', $full_query);
204 if ($full_query == '') {
205 $full_query .= 'ALTER TABLE '
206 . PMA_backquote(htmlspecialchars($table))
207 . '<br /> DROP '
208 . PMA_backquote(htmlspecialchars(urldecode($sval)))
211 $full_query .= '<br /> DROP '
212 . PMA_backquote(htmlspecialchars(urldecode($sval)))
215 if ($i == $selected_cnt-1) {
216 $full_query = preg_replace('@,$@', ';<br />', $full_query);
222 if ($what == 'drop_tbl') {
223 if (!empty($full_query)) {
224 $full_query .= ';<br />' . "\n";
226 if (!empty($full_query_views)) {
227 $full_query .= $full_query_views . ';<br />' . "\n";
229 unset($full_query_views);
234 <!-- Do it really ?
-->
235 <form action
="<?php echo $action; ?>" method
="post">
236 <input type
="hidden" name
="query_type" value
="<?php echo $what; ?>" />
238 if (strpos(' ' . $action, 'db_') == 1) {
239 echo PMA_generate_common_hidden_inputs($db);
240 } elseif (strpos(' ' . $action, 'tbl_') == 1
241 ||
$what == 'row_delete') {
242 echo PMA_generate_common_hidden_inputs($db, $table);
244 echo PMA_generate_common_hidden_inputs();
247 <input type
="hidden" name
="reload" value
="<?php echo isset($reload) ? PMA_sanitize($reload) : 0; ?>" />
249 foreach ($selected as $idx => $sval) {
250 echo '<input type="hidden" name="selected[]" value="' . htmlspecialchars($sval) . '" />' . "\n";
252 if ($what == 'drop_tbl' && !empty($views)) {
253 foreach ($views as $current) {
254 echo '<input type="hidden" name="views[]" value="' . htmlspecialchars($current) . '" />' . "\n";
257 if ($what == 'row_delete') {
258 echo '<input type="hidden" name="original_sql_query" value="' . htmlspecialchars($original_sql_query) . '" />' . "\n";
259 echo '<input type="hidden" name="original_url_query" value="' . htmlspecialchars($original_url_query) . '" />' . "\n";
262 <fieldset
class="confirmation">
263 <legend
><?php
echo ($what == 'drop_db' ?
$strDropDatabaseStrongWarning . ' ' : '') . $strDoYouReally; ?
>:</legend
>
264 <tt
><?php
echo $full_query; ?
></tt
>
266 <fieldset
class="tblFooters">
267 <input type
="submit" name
="mult_btn" value
="<?php echo $strYes; ?>" id
="buttonYes" />
268 <input type
="submit" name
="mult_btn" value
="<?php echo $strNo; ?>" id
="buttonNo" />
271 require_once './libraries/footer.inc.php';
278 elseif ($mult_btn == $strYes) {
280 if ($query_type == 'drop_db' ||
$query_type == 'drop_tbl' ||
$query_type == 'drop_fld') {
281 require_once './libraries/relation_cleanup.lib.php';
285 if ($query_type == 'drop_tbl') {
286 $sql_query_views = '';
288 $selected_cnt = count($selected);
289 $run_parts = FALSE; // whether to run query after each pass
290 $use_sql = FALSE; // whether to include sql.php at the end (to display results)
292 if ($query_type == 'primary_fld') {
293 // Gets table primary key
294 PMA_DBI_select_db($db);
295 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
297 while ($row = PMA_DBI_fetch_assoc($result)) {
298 // Backups the list of primary keys
299 if ($row['Key_name'] == 'PRIMARY') {
300 $primary .= $row['Column_name'] . ', ';
303 PMA_DBI_free_result($result);
306 $rebuild_database_list = false;
308 for ($i = 0; $i < $selected_cnt; $i++
) {
309 switch ($query_type) {
311 $a_query = urldecode($selected[$i]);
316 PMA_relationsCleanupDatabase($selected[$i]);
317 $a_query = 'DROP DATABASE '
318 . PMA_backquote(urldecode($selected[$i]));
321 $rebuild_database_list = true;
325 PMA_relationsCleanupTable($db, $selected[$i]);
326 $current = urldecode($selected[$i]);
327 // here we must compare with the value before urldecode()
328 // because $views has been treated with htmlspecialchars()
329 if (!empty($views) && in_array($selected[$i], $views)) {
330 $sql_query_views .= (empty($sql_query_views) ?
'DROP VIEW ' : ', ')
331 . PMA_backquote($current);
333 $sql_query .= (empty($sql_query) ?
'DROP TABLE ' : ', ')
334 . PMA_backquote($current);
340 $sql_query .= (empty($sql_query) ?
'CHECK TABLE ' : ', ')
341 . PMA_backquote(urldecode($selected[$i]));
346 $sql_query .= (empty($sql_query) ?
'OPTIMIZE TABLE ' : ', ')
347 . PMA_backquote(urldecode($selected[$i]));
352 $sql_query .= (empty($sql_query) ?
'ANALYZE TABLE ' : ', ')
353 . PMA_backquote(urldecode($selected[$i]));
358 $sql_query .= (empty($sql_query) ?
'REPAIR TABLE ' : ', ')
359 . PMA_backquote(urldecode($selected[$i]));
364 if (PMA_MYSQL_INT_VERSION
>= 40000) {
365 $a_query = 'TRUNCATE ';
367 $a_query = 'DELETE FROM ';
369 $a_query .= PMA_backquote(htmlspecialchars(urldecode($selected[$i])));
374 PMA_relationsCleanupColumn($db, $table, $selected[$i]);
375 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) : ',')
376 . ' DROP ' . PMA_backquote(urldecode($selected[$i]))
377 . (($i == $selected_cnt-1) ?
';' : '');
381 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . (empty($primary) ?
'' : ' DROP PRIMARY KEY,') . ' ADD PRIMARY KEY( ' : ', ')
382 . PMA_backquote(urldecode($selected[$i]))
383 . (($i == $selected_cnt-1) ?
');' : '');
387 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . ' ADD INDEX( ' : ', ')
388 . PMA_backquote(urldecode($selected[$i]))
389 . (($i == $selected_cnt-1) ?
');' : '');
393 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . ' ADD UNIQUE( ' : ', ')
394 . PMA_backquote(urldecode($selected[$i]))
395 . (($i == $selected_cnt-1) ?
');' : '');
399 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . ' ADD FULLTEXT( ' : ', ')
400 . PMA_backquote(urldecode($selected[$i]))
401 . (($i == $selected_cnt-1) ?
');' : '');
405 // All "DROP TABLE", "DROP FIELD", "OPTIMIZE TABLE" and "REPAIR TABLE"
406 // statements will be run at once below
408 $sql_query .= $a_query . ';' . "\n";
409 if ($query_type != 'drop_db') {
410 PMA_DBI_select_db($db);
412 $result = @PMA_DBI_query
($a_query) or PMA_mysqlDie('', $a_query, FALSE, $err_url);
416 if ($query_type == 'drop_tbl') {
417 if (!empty($sql_query)) {
419 } elseif (!empty($sql_query_views)) {
420 $sql_query = $sql_query_views . ';';
421 unset($sql_query_views);
427 } elseif (!$run_parts) {
428 PMA_DBI_select_db($db);
429 $result = PMA_DBI_query($sql_query);
430 if (!empty($sql_query_views)) {
431 $sql_query .= ' ' . $sql_query_views . ';';
432 PMA_DBI_query($sql_query_views);
433 unset($sql_query_views);
436 if ($rebuild_database_list) {
437 // avoid a problem with the database list navigator
438 // when dropping a db from server_databases
439 $GLOBALS['PMA_List_Database']->build();