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 && ( ( isset($selected_db) && !empty($selected_db) )
12 ||
( isset($selected_tbl) && !empty($selected_tbl) )
13 ||
( isset($selected_fld) && !empty($selected_fld) )
14 ||
!empty($rows_to_delete)
16 define('PMA_SUBMIT_MULT', 1);
17 if (isset($selected_db) && !empty($selected_db)) {
18 $selected = $selected_db;
20 } elseif (isset($selected_tbl) && !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 } elseif (isset($selected_fld) && !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 foreach ($selected AS $idx => $sval) {
106 if ($sql_query == '') {
107 $sql_query .= 'SELECT ' . PMA_backquote(urldecode($sval));
109 $sql_query .= ', ' . PMA_backquote(urldecode($sval));
112 $sql_query .= ' FROM ' . PMA_backquote(htmlspecialchars($table));
113 require('./sql.php');
117 $what = 'row_delete';
118 $selected = $rows_to_delete;
124 * Displays the confirmation form if required
126 if ( !empty($submit_mult) && !empty($what)) {
127 $js_to_run = 'functions.js';
129 if (isset($table) && strlen($table)) {
130 require('./libraries/tbl_properties_common.php');
131 $url_query .= '&goto=tbl_properties.php&back=tbl_properties.php';
132 require('./libraries/tbl_properties_table_info.inc.php');
133 } elseif (isset($db) && strlen($db)) {
134 require('./libraries/db_details_common.inc.php');
135 require('./libraries/db_details_db_info.inc.php');
139 if ($what == 'drop_tbl') {
140 $full_query_views = '';
142 $selected_cnt = count($selected);
144 foreach ($selected AS $idx => $sval) {
147 $full_query .= htmlspecialchars(urldecode($sval))
151 $full_query .= 'DROP DATABASE '
152 . PMA_backquote(htmlspecialchars(urldecode($sval)))
158 $current = urldecode($sval);
159 if (!empty($views) && in_array($current, $views)) {
160 $full_query_views .= (empty($full_query_views) ?
'DROP VIEW ' : ', ')
161 . PMA_backquote(htmlspecialchars($current));
163 $full_query .= (empty($full_query) ?
'DROP TABLE ' : ', ')
164 . PMA_backquote(htmlspecialchars($current));
169 if (PMA_MYSQL_INT_VERSION
>= 40000) {
170 $full_query .= 'TRUNCATE ';
172 $full_query .= 'DELETE FROM ';
174 $full_query .= PMA_backquote(htmlspecialchars(urldecode($sval)))
179 if ($full_query == '') {
180 $full_query .= 'ALTER TABLE '
181 . PMA_backquote(htmlspecialchars($table))
182 . '<br /> DROP PRIMARY KEY,'
183 . '<br /> ADD PRIMARY KEY('
184 . '<br /> '
185 . PMA_backquote(htmlspecialchars(urldecode($sval)))
188 $full_query .= '<br /> '
189 . PMA_backquote(htmlspecialchars(urldecode($sval)))
192 if ($i == $selected_cnt-1) {
193 $full_query = preg_replace('@,$@', ');<br />', $full_query);
198 if ($full_query == '') {
199 $full_query .= 'ALTER TABLE '
200 . PMA_backquote(htmlspecialchars($table))
201 . '<br /> DROP '
202 . PMA_backquote(htmlspecialchars(urldecode($sval)))
205 $full_query .= '<br /> DROP '
206 . PMA_backquote(htmlspecialchars(urldecode($sval)))
209 if ($i == $selected_cnt-1) {
210 $full_query = preg_replace('@,$@', ';<br />', $full_query);
216 if ($what == 'drop_tbl') {
217 if (!empty($full_query)) {
218 $full_query .= ';<br />' . "\n";
220 if (!empty($full_query_views)) {
221 $full_query .= $full_query_views . ';<br />' . "\n";
223 unset($full_query_views);
228 <!-- Do it really ?
-->
229 <form action
="<?php echo $action; ?>" method
="post">
230 <input type
="hidden" name
="query_type" value
="<?php echo $what; ?>" />
232 if (strpos(' ' . $action, 'db_details') == 1) {
233 echo PMA_generate_common_hidden_inputs($db);
234 } elseif (strpos(' ' . $action, 'tbl_properties') == 1
235 ||
$what == 'row_delete') {
236 echo PMA_generate_common_hidden_inputs($db, $table);
238 echo PMA_generate_common_hidden_inputs();
241 <input type
="hidden" name
="reload" value
="<?php echo isset($reload) ? PMA_sanitize($reload) : 0; ?>" />
243 foreach ($selected AS $idx => $sval) {
244 echo '<input type="hidden" name="selected[]" value="' . htmlspecialchars($sval) . '" />' . "\n";
246 if ($what == 'drop_tbl' && !empty($views)) {
247 foreach ($views as $current) {
248 echo '<input type="hidden" name="views[]" value="' . htmlspecialchars($current) . '" />' . "\n";
251 if ($what == 'row_delete') {
252 echo '<input type="hidden" name="original_sql_query" value="' . htmlspecialchars($original_sql_query) . '" />' . "\n";
253 echo '<input type="hidden" name="original_pos" value="' . $original_pos . '" />' . "\n";
254 echo '<input type="hidden" name="original_url_query" value="' . htmlspecialchars($original_url_query) . '" />' . "\n";
255 echo '<input type="hidden" name="disp_direction" value="' . $disp_direction . '" />' . "\n";
256 echo '<input type="hidden" name="repeat_cells" value="' . $repeat_cells . '" />' . "\n";
257 echo '<input type="hidden" name="dontlimitchars" value="' . $dontlimitchars . '" />' . "\n";
258 echo '<input type="hidden" name="pos" value="' . ( isset( $pos ) ?
$pos : 0 ) . '" />' . "\n";
259 echo '<input type="hidden" name="session_max_rows" value="' . $session_max_rows . '" />' . "\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 for ($i = 0; $i < $selected_cnt; $i++
) {
307 switch ($query_type) {
309 $a_query = urldecode($selected[$i]);
314 PMA_relationsCleanupDatabase($selected[$i]);
315 $a_query = 'DROP DATABASE '
316 . PMA_backquote(urldecode($selected[$i]));
322 PMA_relationsCleanupTable($db, $selected[$i]);
323 $current = urldecode($selected[$i]);
324 if (!empty($views) && in_array($current, $views)) {
325 $sql_query_views .= (empty($sql_query_views) ?
'DROP VIEW ' : ', ')
326 . PMA_backquote($current);
328 $sql_query .= (empty($sql_query) ?
'DROP TABLE ' : ', ')
329 . PMA_backquote($current);
335 $sql_query .= (empty($sql_query) ?
'CHECK TABLE ' : ', ')
336 . PMA_backquote(urldecode($selected[$i]));
341 $sql_query .= (empty($sql_query) ?
'OPTIMIZE TABLE ' : ', ')
342 . PMA_backquote(urldecode($selected[$i]));
347 $sql_query .= (empty($sql_query) ?
'ANALYZE TABLE ' : ', ')
348 . PMA_backquote(urldecode($selected[$i]));
353 $sql_query .= (empty($sql_query) ?
'REPAIR TABLE ' : ', ')
354 . PMA_backquote(urldecode($selected[$i]));
359 if (PMA_MYSQL_INT_VERSION
>= 40000) {
360 $a_query = 'TRUNCATE ';
362 $a_query = 'DELETE FROM ';
364 $a_query .= PMA_backquote(htmlspecialchars(urldecode($selected[$i])));
369 PMA_relationsCleanupColumn($db, $table, $selected[$i]);
370 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) : ',')
371 . ' DROP ' . PMA_backquote(urldecode($selected[$i]))
372 . (($i == $selected_cnt-1) ?
';' : '');
376 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . ( empty($primary) ?
'' : ' DROP PRIMARY KEY,') . ' ADD PRIMARY KEY( ' : ', ')
377 . PMA_backquote(urldecode($selected[$i]))
378 . (($i == $selected_cnt-1) ?
');' : '');
382 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . ' ADD INDEX( ' : ', ')
383 . PMA_backquote(urldecode($selected[$i]))
384 . (($i == $selected_cnt-1) ?
');' : '');
388 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . ' ADD UNIQUE( ' : ', ')
389 . PMA_backquote(urldecode($selected[$i]))
390 . (($i == $selected_cnt-1) ?
');' : '');
394 $sql_query .= (empty($sql_query) ?
'ALTER TABLE ' . PMA_backquote($table) . ' ADD FULLTEXT( ' : ', ')
395 . PMA_backquote(urldecode($selected[$i]))
396 . (($i == $selected_cnt-1) ?
');' : '');
400 // All "DROP TABLE", "DROP FIELD", "OPTIMIZE TABLE" and "REPAIR TABLE"
401 // statements will be run at once below
403 $sql_query .= $a_query . ';' . "\n";
404 if ($query_type != 'drop_db') {
405 PMA_DBI_select_db($db);
407 $result = @PMA_DBI_query
($a_query) or PMA_mysqlDie('', $a_query, FALSE, $err_url);
411 if ($query_type == 'drop_tbl') {
412 if (!empty($sql_query)) {
414 } elseif (!empty($sql_query_views)) {
415 $sql_query = $sql_query_views . ';';
416 unset($sql_query_views);
421 require('./sql.php');
422 } elseif (!$run_parts) {
423 PMA_DBI_select_db($db);
424 $result = PMA_DBI_query($sql_query);
425 if (!empty($sql_query_views)) {
426 $sql_query .= ' ' . $sql_query_views . ';';
427 PMA_DBI_query($sql_query_views);
428 unset($sql_query_views);