added buttons to run multiple "DROP/DELETE/ALTER" statements

This commit is contained in:
Loïc Chapeaux
2001-09-02 22:29:33 +00:00
parent f0cb71a4fe
commit 53fd79880c
3 changed files with 267 additions and 35 deletions

View File

@@ -26,6 +26,15 @@ window.parent.frames['nav'].location.replace('./left.php3?lang=<?php echo $lang;
}
/**
* Drop/delete mutliple tables if required
*/
if (!empty($submit_mult) || isset($btnDrop)) {
$action = 'db_details.php3';
include('./mult_drops.inc.php3');
}
/**
* Displays an html table with all the tables contained into the current
* database
@@ -97,9 +106,15 @@ else if (MYSQL_INT_VERSION >= 32300 && isset($tbl_cache)) {
<!-- TABLE LIST -->
<form action="db_details.php3">
<input type="hidden" name="lang" value="<?php echo $lang; ?>" />
<input type="hidden" name="server" value="<?php echo $server; ?>" />
<input type="hidden" name="db" value="<?php echo $db; ?>" />
<table border="<?php echo $cfgBorder; ?>">
<tr>
<th><?php echo ucfirst($strTable); ?></th>
<td></td>
<th>&nbsp;<?php echo ucfirst($strTable); ?>&nbsp;</th>
<th colspan="6"><?php echo ucfirst($strAction); ?></th>
<th><?php echo ucfirst($strRecords); ?></th>
<th><?php echo ucfirst($strSize); ?></th>
@@ -118,8 +133,11 @@ else if (MYSQL_INT_VERSION >= 32300 && isset($tbl_cache)) {
echo "\n";
?>
<tr bgcolor="<?php echo $bgcolor; ?>">
<td align="center">
<input type="checkbox" name="selected_tbl[]" value="<?php echo urlencode($table); ?>" />
</td>
<td nowrap="nowrap">
<b><?php echo htmlspecialchars($table); ?>&nbsp;</b>
&nbsp;<b><?php echo htmlspecialchars($table); ?>&nbsp;</b>&nbsp;
</td>
<td>
<a href="sql.php3?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('SELECT * FROM ' . backquote($table)); ?>&pos=0">
@@ -218,21 +236,34 @@ else if (MYSQL_INT_VERSION >= 32300 && isset($tbl_cache)) {
list($sum_formated,$unit) = format_byte_down($sum_size,3,1);
echo "\n";
?>
<tr bgcolor="<?php echo $cfgThBgcolor; ?>">
<td align="center">
<b><?php echo sprintf($strTables, number_format($num_tables, 0, $number_decimal_separator, $number_thousands_separator)); ?></b>
</td>
<td colspan="6" align="center">
<tr>
<td></td>
<th align="center">
&nbsp;<b><?php echo sprintf($strTables, number_format($num_tables, 0, $number_decimal_separator, $number_thousands_separator)); ?></b>&nbsp;
</th>
<th colspan="6" align="center">
<b><?php echo $strSum; ?></b>
</td>
<td align="right" nowrap="nowrap">
</th>
<th align="right" nowrap="nowrap">
<b><?php echo number_format($sum_entries, 0, $number_decimal_separator, $number_thousands_separator); ?></b>
</td>
<td align="right" nowrap="nowrap">
</th>
<th align="right" nowrap="nowrap">
<b><?php echo $sum_formated . ' '. $unit; ?></b>
</td>
</th>
</tr>
<tr>
<td colspan="10">
<img src="./images/arrow.gif" border="0" width="38" height="22" alt="<?php echo $strWithChecked; ?>" />
<i><?php echo $strWithChecked; ?></i>&nbsp;&nbsp;
<input type="submit" name="submit_mult" value="<?php echo $strDrop; ?>" />
&nbsp;<i><?php echo $strOr; ?></i>&nbsp;
<input type="submit" name="submit_mult" value="<?php echo $strEmpty; ?>" />
</td>
<tr>
</table>
</form>
<?php
} // end case mysql >= 3.23
@@ -245,9 +276,15 @@ else {
<!-- TABLE LIST -->
<form action="db_details.php3">
<input type="hidden" name="lang" value="<?php echo $lang; ?>" />
<input type="hidden" name="server" value="<?php echo $server; ?>" />
<input type="hidden" name="db" value="<?php echo $db; ?>" />
<table border="<?php echo $cfgBorder; ?>">
<tr>
<th><?php echo ucfirst($strTable); ?></th>
<td></td>
<th>&nbsp;<?php echo ucfirst($strTable); ?>&nbsp;</th>
<th colspan="6"><?php echo ucfirst($strAction); ?></th>
<th><?php echo ucfirst($strRecords); ?></th>
</tr>
@@ -264,8 +301,11 @@ else {
echo "\n";
?>
<tr bgcolor="<?php echo $bgcolor; ?>">
<td align="center">
<input type="checkbox" name="selected_tbl[]" value="<?php echo urlencode($table); ?>" />
</td>
<td class="data">
<b><?php echo $table; ?></b>
<b>&nbsp;<?php echo $table; ?>&nbsp;</b>
</td>
<td>
<a href="sql.php3?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('SELECT * FROM ' . backquote($table)); ?>&pos=0"><?php echo $strBrowse; ?></a>
@@ -294,7 +334,19 @@ else {
}
echo "\n";
?>
<tr>
<td colspan="9">
<img src="./images/arrow.gif" border="0" width="38" height="22" alt="<?php echo $strWithChecked; ?>" />
<i><?php echo $strWithChecked; ?></i>&nbsp;&nbsp;
<input type="submit" name="submit_mult" value="<?php echo $strDrop; ?>" />
&nbsp;<?php $strOr . "\n"; ?>&nbsp;
<input type="submit" name="submit_mult" value="<?php echo $strEmpty; ?>" />
</td>
<tr>
</table>
</form>
<?php
} // end case mysql < 3.23
@@ -345,10 +397,10 @@ if ($num_tables > 0) {
<form method="post" action="db_readdump.php3" enctype="multipart/form-data"
onsubmit="return checkSqlQuery(this)">
<input type="hidden" name="is_js_confirmed" value="0" />
<input type="hidden" name="server" value="<?php echo $server; ?>" />
<input type="hidden" name="lang" value="<?php echo $lang; ?>" />
<input type="hidden" name="pos" value="0" />
<input type="hidden" name="server" value="<?php echo $server; ?>" />
<input type="hidden" name="db" value="<?php echo $db; ?>" />
<input type="hidden" name="pos" value="0" />
<input type="hidden" name="goto" value="db_details.php3" />
<input type="hidden" name="zero_rows" value="<?php echo htmlspecialchars($strSuccess); ?>" />
<input type="hidden" name="prev_sql_query" value="<?php echo ((!empty($query_to_display)) ? urlencode($query_to_display) : ''); ?>" />

133
mult_drops.inc.php3 Normal file
View File

@@ -0,0 +1,133 @@
<?php
/* $Id$ */
/**
* Confirmation form
*/
if (!empty($submit_mult)
&& (!empty($selected_db) || !empty($selected_tbl) || !empty($selected_fld))) {
if (get_magic_quotes_gpc()) {
$submit_mult = stripslashes($submit_mult);
}
if (!empty($selected_db)) {
$what = 'drop_db';
$selected = $selected_db;
} else if (!empty($selected_tbl)) {
$what = (($submit_mult == $strDrop) ? 'drop_tbl' : 'empty_tbl');
$selected = $selected_tbl;
} else {
$what = 'drop_fld';
$selected = $selected_fld;
}
// Builds the query
$full_query = '';
$selected_cnt = count($selected);
for ($i = 0; $i < $selected_cnt; $i++) {
switch ($what) {
case 'drop_db':
$full_query .= 'DROP DATABASE '
. backquote(htmlspecialchars(urldecode($selected[$i])))
. ';<br />';
break;
case 'drop_tbl':
$full_query .= 'DROP TABLE '
. backquote(htmlspecialchars(urldecode($selected[$i])))
. ';<br />';
break;
case 'empty_tbl':
$full_query .= 'DELETE FROM '
. backquote(htmlspecialchars(urldecode($selected[$i])))
. ';<br />';
break;
case 'drop_fld':
$full_query .= 'ALTER TABLE '
. backquote(htmlspecialchars($table))
. ' DROP '
. backquote(htmlspecialchars(urldecode($selected[$i])))
. ';<br />';
break;
} // end switch
}
// Displays the form
echo $strDoYouReally . '&nbsp;:<br />' . "\n";
echo '<tt>' . $full_query . '</tt>&nbsp;?<br/>' . "\n";
?>
<form action="<?php echo $action; ?>" method="post">
<input type="hidden" name="lang" value="<?php echo $lang; ?>" />
<input type="hidden" name="server" value="<?php echo $server; ?>" />
<?php
echo "\n";
if ($action == 'db_details.php3') {
echo ' <input type="hidden" name="db" value="' . $db . '" />' . "\n";
} else if ($action == 'tbl_properties.php3') {
echo ' <input type="hidden" name="db" value="' . $db . '" />' . "\n";
echo ' <input type="hidden" name="table" value="' . $table . '" />' . "\n";
}
for ($i = 0; $i < $selected_cnt; $i++) {
echo ' <input type="hidden" name="selected[]" value="' . $selected[$i] . '" />' . "\n";
}
?>
<input type="hidden" name="query_type" value="<?php echo $what; ?>" />
<input type="submit" name="btnDrop" value="<?php echo $strYes; ?>" />
<input type="submit" name="btnDrop" value="<?php echo $strNo; ?>" />
</form>
<?php
echo"\n";
include('./footer.inc.php3');
exit();
}
/**
* Executes the query
*/
else if ((get_magic_quotes_gpc() && stripslashes($btnDrop) == $strYes)
|| $btnDrop == $strYes) {
$sql_query = '';
$selected_cnt = count($selected);
for ($i = 0; $i < $selected_cnt; $i++) {
switch ($query_type) {
case 'drop_db':
$a_query = 'DROP DATABASE '
. backquote(urldecode($selected[$i]));
$reload = 'true';
break;
case 'drop_tbl':
$a_query = 'DROP TABLE '
. backquote(urldecode($selected[$i]));
$reload = 'true';
break;
case 'empty_tbl':
$a_query = 'DELETE FROM '
. backquote(urldecode($selected[$i]));
break;
case 'drop_fld':
$a_query = 'ALTER TABLE '
. backquote($table)
. ' DROP '
. backquote(urldecode($selected[$i]));
break;
} // end switch
$sql_query .= $a_query . ';' . "\n";
if ($query_type != 'drop_db') {
mysql_select_db($db);
}
$result = @mysql_query($a_query) or mysql_die('', $a_query, FALSE);
} // end for
show_message($strSuccess);
}
?>

View File

@@ -15,6 +15,15 @@ if (!isset($message)) {
}
/**
* Drop/delete mutliple tables if required
*/
if (!empty($submit_mult) || isset($btnDrop)) {
$action = 'tbl_properties.php3';
include('./mult_drops.inc.php3');
}
/**
* Defines the query to be displayed in the query textarea
*/
@@ -177,22 +186,36 @@ $result = mysql_query($local_query) or mysql_die('', $local_query);
<!-- TABLE INFORMATIONS -->
<?php
// Drop button if there is at least two fields
if (mysql_num_rows($result) > 1) {
?>
<form action="tbl_properties.php3">
<input type="hidden" name="lang" value="<?php echo $lang; ?>" />
<input type="hidden" name="server" value="<?php echo $server; ?>" />
<input type="hidden" name="db" value="<?php echo $db; ?>" />
<input type="hidden" name="table" value="<?php echo $table; ?>" />
<?php
}
echo "\n";
?>
<table border="<?php echo $cfgBorder; ?>">
<tr>
<th><?php echo ucfirst($strField); ?></th>
<?php
// Drop button if there is at least two fields
if (mysql_num_rows($result) > 1) {
echo ' <td></td>' . "\n";
}
?>
<th>&nbsp;<?php echo ucfirst($strField); ?>&nbsp;</th>
<th><?php echo ucfirst($strType); ?></th>
<th><?php echo ucfirst($strAttr); ?></th>
<th><?php echo ucfirst($strNull); ?></th>
<th><?php echo ucfirst($strDefault); ?></th>
<th><?php echo ucfirst($strExtra); ?></th>
<?php
if (empty($printer_friendly)) {
?>
<th colspan="5"><?php echo ucfirst($strAction); ?></th>
<?php
}
echo "\n";
?>
</tr>
<?php
@@ -245,16 +268,23 @@ while ($row = mysql_fetch_array($result)) {
echo "\n";
?>
<tr bgcolor="<?php echo $bgcolor; ?>">
<?php
// Drop button if there is at least two fields
if (mysql_num_rows($result) > 1) {
?>
<td align="center">
<input type="checkbox" name="selected_fld[]" value="<?php echo urlencode($row['Field']); ?>" />
</td>
<?php
}
echo "\n";
?>
<td nowrap="nowrap"><?php echo htmlspecialchars($row['Field']); ?>&nbsp;</td>
<td<?php echo $type_nowrap; ?>><?php echo $type; ?></td>
<td nowrap="nowrap"><?php echo $strAttribute; ?></td>
<td><?php echo (($row['Null'] == '') ? $strNo : $strYes); ?>&nbsp;</td>
<td nowrap="nowrap"><?php if (isset($row['Default'])) echo $row['Default']; ?>&nbsp;</td>
<td nowrap="nowrap"><?php echo $row['Extra']; ?>&nbsp;</td>
<?php
if (empty($printer_friendly)) {
echo "\n";
?>
<td>
<a href="tbl_alter.php3?<?php echo $url_query; ?>&field=<?php echo urlencode($row['Field']); ?>">
<?php echo $strChange; ?></a>
@@ -288,16 +318,33 @@ while ($row = mysql_fetch_array($result)) {
<a href="sql.php3?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('ALTER TABLE ' . backquote($table) . ' ADD UNIQUE(' . backquote($row['Field']) . ')'); ?>&zero_rows=<?php echo urlencode($strAnIndex . ' ' . htmlspecialchars($row['Field'])); ?>">
<?php echo $strUnique; ?></a>
</td>
<?php
}
echo "\n";
?>
</tr>
<?php
} // end while
echo "\n";
?>
// Drop button if there is at least two fields
if (mysql_num_rows($result) > 1) {
?>
<tr>
<td colspan="12">
<img src="./images/arrow.gif" border="0" width="38" height="22" alt="<?php echo $strWithChecked; ?>" />
<i><?php echo $strWithChecked; ?></i>&nbsp;&nbsp;
<input type="submit" name="submit_mult" value="<?php echo $strDrop; ?>" />
</td>
<tr>
</table>
</form>
<?php
} else {
echo "\n"
?>
</table>
<?php
}
echo "\n";
?>
<br />
@@ -582,11 +629,11 @@ echo "\n";
<form method="post" action="db_readdump.php3"
onsubmit="return checkSqlQuery(this)">
<input type="hidden" name="is_js_confirmed" value="0" />
<input type="hidden" name="server" value="<?php echo $server; ?>" />
<input type="hidden" name="lang" value="<?php echo $lang; ?>" />
<input type="hidden" name="pos" value="0" />
<input type="hidden" name="server" value="<?php echo $server; ?>" />
<input type="hidden" name="db" value="<?php echo $db; ?>" />
<input type="hidden" name="table" value="<?php echo $table; ?>" />
<input type="hidden" name="pos" value="0" />
<input type="hidden" name="goto" value="tbl_properties.php3" />
<input type="hidden" name="zero_rows" value="<?php echo $strSuccess; ?>" />
<input type="hidden" name="prev_sql_query" value="<?php echo ((!empty($query_to_display)) ? urlencode($query_to_display) : ''); ?>" />