3 // vim: expandtab sw=4 ts=4 sts=4:
7 * Prepares the work and runs some other scripts if required
9 if (!empty($submit_mult)
10 && ($submit_mult != $strWithChecked)
11 && ( !empty($selected_db)
12 ||
!empty($selected_tbl)
13 ||
!empty($selected_fld)
14 ||
!empty($rows_to_delete)
17 if (!empty($selected_db)) {
18 $selected = $selected_db;
20 } else if (!empty($selected_tbl)) {
21 if ($submit_mult == $strPrintView) {
22 require('./tbl_printview.php');
24 $selected = $selected_tbl;
25 switch ($submit_mult) {
37 $query_type = 'check_tbl';
40 case $strOptimizeTable:
42 $query_type = 'optimize_tbl';
47 $query_type = 'repair_tbl';
50 case $strAnalyzeTable:
52 $query_type = 'analyze_tbl';
57 } else if (!empty($selected_fld)) {
58 $selected = $selected_fld;
59 switch ($submit_mult) {
64 // Gets table primary key
65 PMA_DBI_select_db($db);
66 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
68 while ($row = PMA_DBI_fetch_assoc($result)) {
69 // Backups the list of primary keys
70 if ($row['Key_name'] == 'PRIMARY') {
71 $primary .= $row['Column_name'] . ', ';
74 PMA_DBI_free_result($result);
75 if (empty($primary)) {
76 // no primary key, so we can safely create new
78 $query_type = 'primary_fld';
81 // primary key exists, so lets as user
82 $what = 'primary_fld';
87 $query_type = 'index_fld';
92 $query_type = 'unique_fld';
97 $query_type = 'fulltext_fld';
101 require('./tbl_alter.php');
105 $what = 'row_delete';
106 $selected = $rows_to_delete;
112 * Displays the confirmation form if required
114 if (!empty($submit_mult) && !empty($what)) {
115 $js_to_run = 'functions.js';
117 if (!empty($table)) {
118 require('./tbl_properties_common.php');
119 $url_query .= '&goto=tbl_properties.php&back=tbl_properties.php';
120 require('./tbl_properties_table_info.php');
122 elseif (!empty($db)) {
123 require('./db_details_common.php');
124 require('./db_details_db_info.php');
128 if ($what == 'drop_tbl') {
129 $full_query_views = '';
131 $selected_cnt = count($selected);
133 foreach ($selected AS $idx => $sval) {
136 $full_query .= htmlspecialchars(urldecode($sval))
140 $full_query .= 'DROP DATABASE '
141 . PMA_backquote(htmlspecialchars(urldecode($sval)))
146 $current = urldecode($sval);
147 if (!empty($views) && in_array($current, $views)) {
148 $full_query_views .= (empty($full_query_views) ?
'DROP VIEW ' : ', ')
149 . PMA_backquote(htmlspecialchars($current));
151 $full_query .= (empty($full_query) ?
'DROP TABLE ' : ', ')
152 . PMA_backquote(htmlspecialchars($current));
157 if (PMA_MYSQL_INT_VERSION
>= 40000) {
158 $full_query .= 'TRUNCATE ';
160 $full_query .= 'DELETE FROM ';
162 $full_query .= PMA_backquote(htmlspecialchars(urldecode($sval)))
167 if ($full_query == '') {
168 $full_query .= 'ALTER TABLE '
169 . PMA_backquote(htmlspecialchars($table))
170 . '<br /> DROP PRIMARY KEY,'
171 . '<br /> ADD PRIMARY KEY('
172 . '<br /> '
173 . PMA_backquote(htmlspecialchars(urldecode($sval)))
176 $full_query .= '<br /> '
177 . PMA_backquote(htmlspecialchars(urldecode($sval)))
180 if ($i == $selected_cnt-1) {
181 $full_query = preg_replace('@,$@', ');<br />', $full_query);
186 if ($full_query == '') {
187 $full_query .= 'ALTER TABLE '
188 . PMA_backquote(htmlspecialchars($table))
189 . '<br /> DROP '
190 . PMA_backquote(htmlspecialchars(urldecode($sval)))
193 $full_query .= '<br /> DROP '
194 . PMA_backquote(htmlspecialchars(urldecode($sval)))
197 if ($i == $selected_cnt-1) {
198 $full_query = preg_replace('@,$@', ';<br />', $full_query);
204 if ($what == 'drop_tbl') {
205 if (!empty($full_query)) {
206 $full_query .= ';<br />' . "\n";
208 if (!empty($full_query_views)) {
209 $full_query .= $full_query_views . ';<br />' . "\n";
211 unset($full_query_views);
216 <!-- Do it really ?
-->
217 <table border
="0" cellpadding
="3" cellspacing
="0">
219 <th
class="tblHeadError" align
="left">
221 echo ($GLOBALS['cfg']['ErrorIconic'] ?
'<img src="' . $GLOBALS['pmaThemeImage'] . 's_really.png" border="0" hspace="2" width="11" height="11" valign="middle" />' : '');
222 echo $strDoYouReally . ': ' . "\n";
227 <td bgcolor
="<?php echo $GLOBALS['cfg']['BgcolorOne']; ?>">
229 echo '<tt>' . $full_query . '</tt> ?<br/>' . "\n";
234 <td align
="right" nowrap
="nowrap">
235 <form action
="<?php echo $action; ?>" method
="post">
238 if (strpos(' ' . $action, 'db_details') == 1) {
239 echo PMA_generate_common_hidden_inputs($db);
240 } else if (strpos(' ' . $action, 'tbl_properties') == 1
241 ||
$what == 'row_delete') {
242 echo PMA_generate_common_hidden_inputs($db,$table);
244 echo PMA_generate_common_hidden_inputs();
246 foreach ($selected AS $idx => $sval) {
247 echo ' <input type="hidden" name="selected[]" value="' . htmlspecialchars($sval) . '" />' . "\n";
249 if ($what == 'drop_tbl' && !empty($views)) {
250 foreach ($views as $current) {
251 echo ' <input type="hidden" name="views[]" value="' . htmlspecialchars($current) . '" />' . "\n";
255 <input type
="hidden" name
="query_type" value
="<?php echo $what; ?>" />
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_pos" value="' . $original_pos . '" />' . "\n";
260 echo '<input type="hidden" name="original_url_query" value="' . htmlspecialchars($original_url_query) . '" />' . "\n";
261 echo '<input type="hidden" name="disp_direction" value="' . $disp_direction . '" />' . "\n";
262 echo '<input type="hidden" name="repeat_cells" value="' . $repeat_cells . '" />' . "\n";
263 echo '<input type="hidden" name="dontlimitchars" value="' . $dontlimitchars . '" />' . "\n";
264 echo '<input type="hidden" name="pos" value="' . $pos . '" />' . "\n";
265 echo '<input type="hidden" name="session_max_rows" value="' . $session_max_rows . '" />' . "\n";
268 <input type
="submit" name
="mult_btn" value
="<?php echo $strYes; ?>" id
="buttonYes" />
269 <input type
="submit" name
="mult_btn" value
="<?php echo $strNo; ?>" id
="buttonNo" />
277 require_once('./footer.inc.php');
284 else if ($mult_btn == $strYes) {
286 if ($query_type == 'drop_db' ||
$query_type == 'drop_tbl' ||
$query_type == 'drop_fld') {
287 require_once('./libraries/relation_cleanup.lib.php');
291 if ($query_type == 'drop_tbl') {
292 $sql_query_views = '';
294 $selected_cnt = count($selected);
295 $run_parts = FALSE; // whether to run query after each pass
296 $use_sql = FALSE; // whether to include sql.php at the end (to display results)
298 if ($query_type == 'primary_fld') {
299 // Gets table primary key
300 PMA_DBI_select_db($db);
301 $result = PMA_DBI_query('SHOW KEYS FROM ' . PMA_backquote($table) . ';');
303 while ($row = PMA_DBI_fetch_assoc($result)) {
304 // Backups the list of primary keys
305 if ($row['Key_name'] == 'PRIMARY') {
306 $primary .= $row['Column_name'] . ', ';
309 PMA_DBI_free_result($result);
312 for ($i = 0; $i < $selected_cnt; $i++
) {
313 switch ($query_type) {
315 $a_query = urldecode($selected[$i]);
320 PMA_relationsCleanupDatabase($selected[$i]);
321 $a_query = 'DROP DATABASE '
322 . PMA_backquote(urldecode($selected[$i]));
328 PMA_relationsCleanupTable($db, $selected[$i]);
329 $current = urldecode($selected[$i]);
330 if (!empty($views) && in_array($current, $views)) {
331 $sql_query_views .= (empty($sql_query_views) ?
'DROP VIEW ' : ', ')
332 . PMA_backquote($current);
334 $sql_query .= (empty($sql_query) ?
'DROP TABLE ' : ', ')
335 . PMA_backquote($current);
341 $sql_query .= (empty($sql_query) ?
'CHECK TABLE ' : ', ')
342 . PMA_backquote(urldecode($selected[$i]));
347 $sql_query .= (empty($sql_query) ?
'OPTIMIZE TABLE ' : ', ')
348 . PMA_backquote(urldecode($selected[$i]));
353 $sql_query .= (empty($sql_query) ?
'ANALYZE TABLE ' : ', ')
354 . PMA_backquote(urldecode($selected[$i]));
359 $sql_query .= (empty($sql_query) ?
'REPAIR TABLE ' : ', ')
360 . PMA_backquote(urldecode($selected[$i]));
365 if (PMA_MYSQL_INT_VERSION
>= 40000) {
366 $a_query = 'TRUNCATE ';
368 $a_query = 'DELETE FROM ';
370 $a_query .= PMA_backquote(htmlspecialchars(urldecode($selected[$i])));
375 PMA_relationsCleanupColumn($db, $table, $selected[$i]);
376 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) : ',')
377 . ' DROP ' . PMA_backquote(urldecode($selected[$i]))
378 . (($i == $selected_cnt-1) ?
';' : '');
382 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . ( empty($primary) ?
'' : ' DROP PRIMARY KEY,') . ' ADD PRIMARY KEY( ' : ', ')
383 . PMA_backquote(urldecode($selected[$i]))
384 . (($i == $selected_cnt-1) ?
');' : '');
388 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . ' ADD INDEX( ' : ', ')
389 . PMA_backquote(urldecode($selected[$i]))
390 . (($i == $selected_cnt-1) ?
');' : '');
394 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . ' ADD UNIQUE( ' : ', ')
395 . PMA_backquote(urldecode($selected[$i]))
396 . (($i == $selected_cnt-1) ?
');' : '');
400 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . ' ADD FULLTEXT( ' : ', ')
401 . PMA_backquote(urldecode($selected[$i]))
402 . (($i == $selected_cnt-1) ?
');' : '');
406 // All "DROP TABLE","DROP FIELD", "OPTIMIZE TABLE" and "REPAIR TABLE"
407 // statements will be run at once below
409 $sql_query .= $a_query . ';' . "\n";
410 if ($query_type != 'drop_db') {
411 PMA_DBI_select_db($db);
413 $result = @PMA_DBI_query
($a_query) or PMA_mysqlDie('', $a_query, FALSE, $err_url);
417 if ($query_type == 'drop_tbl') {
418 if (!empty($sql_query)) {
420 } else if (!empty($sql_query_views)) {
421 $sql_query = $sql_query_views . ';';
422 unset($sql_query_views);
427 require('./sql.php');
428 } elseif (!$run_parts) {
429 PMA_DBI_select_db($db);
430 $result = PMA_DBI_query($sql_query);
431 if (!empty($sql_query_views)) {
432 $sql_query .= ' ' . $sql_query_views . ';';
433 PMA_DBI_query($sql_query_views);
434 unset($sql_query_views);