added js confirm message for links

This commit is contained in:
Loïc Chapeaux
2001-08-31 22:54:38 +00:00
parent b17756d9c8
commit 1370e7c725
5 changed files with 86 additions and 13 deletions

View File

@@ -138,11 +138,13 @@ else if (MYSQL_INT_VERSION >= 32300 && isset($tbl_cache)) {
<?php echo $strProperties; ?></a>
</td>
<td>
<a href="sql.php3?<?php echo $url_query; ?>&reload=true&sql_query=<?php echo urlencode('DROP TABLE ' . backquote($table)); ?>&zero_rows=<?php echo urlencode($strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenDropped); ?>">
<a href="sql.php3?<?php echo $url_query; ?>&reload=true&sql_query=<?php echo urlencode('DROP TABLE ' . backquote($table)); ?>&zero_rows=<?php echo urlencode($strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenDropped); ?>"
onclick="return confirmLink(this, 'DROP TABLE <?php echo js_format($table); ?>')">
<?php echo $strDrop; ?></a>
</td>
<td>
<a href="sql.php3?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('DELETE FROM ' . backquote($table)); ?>&zero_rows=<?php echo urlencode($strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenEmptied); ?>">
<a href="sql.php3?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('DELETE FROM ' . backquote($table)); ?>&zero_rows=<?php echo urlencode($strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenEmptied); ?>"
onclick="return confirmLink(this, 'DELETE FROM <?php echo js_format($table); ?>')">
<?php echo $strEmpty; ?></a>
</td>
<?php
@@ -548,7 +550,8 @@ if ($cfgAllowUserDropDatabase || $is_superuser) {
?>
<!-- Drop database -->
<li>
<a href="sql.php3?server=<?php echo $server; ?>&lang=<?php echo $lang; ?>&db=<?php echo urlencode($db); ?>&sql_query=<?php echo urlencode('DROP DATABASE ' . backquote($db)); ?>&zero_rows=<?php echo urlencode($strDatabase . ' ' . htmlspecialchars(backquote($db)) . ' ' . $strHasBeenDropped); ?>&goto=main.php3&back=db_details.php3&reload=true">
<a href="sql.php3?server=<?php echo $server; ?>&lang=<?php echo $lang; ?>&db=<?php echo urlencode($db); ?>&sql_query=<?php echo urlencode('DROP DATABASE ' . backquote($db)); ?>&zero_rows=<?php echo urlencode($strDatabase . ' ' . htmlspecialchars(backquote($db)) . ' ' . $strHasBeenDropped); ?>&goto=main.php3&back=db_details.php3&reload=true"
onclick="return confirmLink(this, 'DROP DATABASE <?php echo js_format($db); ?>')">
<?php echo $strDropDB . ' ' . htmlspecialchars($db); ?></a>
<?php echo show_docu('manual_Reference.html#DROP_DATABASE') . "\n"; ?>
</li>

View File

@@ -1,6 +1,31 @@
/* $Id$ */
/**
* Displays an confirmation box beforme to submit a "DROP/DELETE/ALTER" query.
* This function is called while clicking links
*
* @param object the link
* @param object the sql query to submit
*
* @return boolean whether to run the query or not
*/
function confirmLink(theLink, theSqlQuery)
{
// Confirmation is not required in the configuration file
if (confirmMsg == '') {
return true;
}
var is_confirmed = confirm(confirmMsg + ' :\n' + theSqlQuery);
if (is_confirmed) {
theLink.href += '&is_js_confirmed=1';
}
return is_confirmed;
} // end of the 'confirmLink()' function
/**
* Displays an error message if a "DROP DATABASE" statement is submitted
* while it isn't allowed, else confirms a "DROP/DELETE/ALTER" query before
@@ -16,8 +41,13 @@
*/
function confirmQuery(theForm1, sqlQuery1)
{
// Confirmation is not required in the configuration file
if (confirmMsg == '') {
return true;
}
// The replace function (js1.2) isn't supported
if (typeof(sqlQuery1.value.replace) == 'undefined') {
else if (typeof(sqlQuery1.value.replace) == 'undefined') {
return true;
}

View File

@@ -66,7 +66,7 @@ var errorMsg0 = '<?php echo str_replace('\'', '\\\'', $strFormEmpty); ?>';
var errorMsg1 = '<?php echo str_replace('\'', '\\\'', $strNotNumber); ?>';
var errorMsg2 = '<?php echo str_replace('\'', '\\\'', $strNotValidNumber); ?>';
var noDropDbMsg = '<?php echo((!$cfgAllowUserDropDatabase) ? str_replace('\'', '\\\'', $strNoDropDatabases) : ''); ?>';
var confirmMsg = '<?php echo str_replace('\'', '\\\'', $strDoYouReally); ?>';
var confirmMsg = '<?php echo(($cfgConfirm) ? str_replace('\'', '\\\'', $strDoYouReally) : ''); ?>';
//-->
</script>
<script src="functions.js" type="text/javascript" language="javascript"></script>

View File

@@ -510,6 +510,24 @@ if (!defined('__LIB_INC__')){
} // end of the 'sql_addslashes()' function
/**
* Format db/table/filed name so they can be passed to a javascript
* function.
* This function is used to displays a javascript confirmation box for
* "DROP/DELETE/ALTER" queries.
*
* @param string the string to format
*
* @return string the formated string
*/
function js_format($a_string = '')
{
$a_string = str_replace('"', '&quot;', $a_string);
$a_string = addslashes($a_string);
return backquote($a_string);
} // end of the 'sql_addslashes()' function
/**
* Defines the <CR><LF> value depending on the user OS that may be grabbed
* from the 'HTTP_USER_AGENT' variable.

View File

@@ -109,9 +109,11 @@ if (MYSQL_INT_VERSION >= 32303) {
<b><?php echo $strSelect; ?></b></a> ]&nbsp;&nbsp;&nbsp;
[ <a href="tbl_change.php3?<?php echo $url_query; ?>">
<b><?php echo $strInsert; ?></b></a> ]&nbsp;&nbsp;&nbsp;
[ <a href="sql.php3?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('DELETE FROM ' . backquote($table)); ?>&zero_rows=<?php echo urlencode($strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenEmptied); ?>">
[ <a href="sql.php3?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('DELETE FROM ' . backquote($table)); ?>&zero_rows=<?php echo urlencode($strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenEmptied); ?>"
onclick="return confirmLink(this, 'DELETE FROM <?php echo js_format($table); ?>')">
<b><?php echo $strEmpty; ?></b></a> ]&nbsp;&nbsp;&nbsp;
[ <a href="sql.php3?<?php echo ereg_replace('tbl_properties.php3$', 'db_details.php3', $url_query); ?>&back=tbl_properties.php3&reload=true&sql_query=<?php echo urlencode('DROP TABLE ' . backquote($table)); ?>&zero_rows=<?php echo urlencode($strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenDropped); ?>">
[ <a href="sql.php3?<?php echo ereg_replace('tbl_properties.php3$', 'db_details.php3', $url_query); ?>&back=tbl_properties.php3&reload=true&sql_query=<?php echo urlencode('DROP TABLE ' . backquote($table)); ?>&zero_rows=<?php echo urlencode($strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenDropped); ?>"
onclick="return confirmLink(this, 'DROP TABLE <?php echo js_format($table); ?>')">
<b><?php echo $strDrop; ?></b></a> ]
</p>
<?php
@@ -125,7 +127,8 @@ if (MYSQL_INT_VERSION >= 32303) {
[ <a href="tbl_change.php3?<?php echo $url_query; ?>">
<b><?php echo $strInsert; ?></b></a> ]&nbsp;&nbsp;&nbsp;
[ <b><?php echo $strEmpty; ?></b> ]&nbsp;&nbsp;&nbsp;
[ <a href="sql.php3?<?php echo ereg_replace('tbl_properties.php3$', 'db_details.php3', $url_query); ?>&back=tbl_properties.php3&reload=true&sql_query=<?php echo urlencode('DROP TABLE ' . backquote($table)); ?>&zero_rows=<?php echo urlencode($strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenDropped); ?>">
[ <a href="sql.php3?<?php echo ereg_replace('tbl_properties.php3$', 'db_details.php3', $url_query); ?>&back=tbl_properties.php3&reload=true&sql_query=<?php echo urlencode('DROP TABLE ' . backquote($table)); ?>&zero_rows=<?php echo urlencode($strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenDropped); ?>"
onclick="return confirmLink(this, 'DROP TABLE <?php echo js_format($table); ?>')">
<b><?php echo $strDrop; ?></b></a> ]
</p>
<?php
@@ -257,11 +260,24 @@ while ($row = mysql_fetch_array($result)) {
<?php echo $strChange; ?></a>
</td>
<td>
<a href="sql.php3?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('ALTER TABLE ' . backquote($table) . ' DROP ' . backquote($row['Field'])); ?>&zero_rows=<?php echo urlencode(htmlspecialchars($row['Field']) . ' ' . $strHasBeenDropped); ?>">
<?php
// loic1: Drop field only if there is more than one field in the table
if (mysql_num_rows($result) > 1) {
echo "\n";
?>
<a href="sql.php3?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('ALTER TABLE ' . backquote($table) . ' DROP ' . backquote($row['Field'])); ?>&zero_rows=<?php echo urlencode(htmlspecialchars($row['Field']) . ' ' . $strHasBeenDropped); ?>"
onclick="return confirmLink(this, 'ALTER TABLE <?php echo js_format($table); ?> DROP <?php echo js_format($row['Field']); ?>')">
<?php echo $strDrop; ?></a>
<?
} else {
echo "\n" . ' ' . $strDrop;
}
echo "\n";
?>
</td>
<td>
<a href="sql.php3?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('ALTER TABLE ' . backquote($table) . ' DROP PRIMARY KEY, ADD PRIMARY KEY(' . $primary . backquote($row['Field']) . ')'); ?>&zero_rows=<?php echo urlencode($strAPrimaryKey . ' ' . htmlspecialchars($row['Field'])); ?>">
<a href="sql.php3?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('ALTER TABLE ' . backquote($table) . ' DROP PRIMARY KEY, ADD PRIMARY KEY(' . $primary . backquote($row['Field']) . ')'); ?>&zero_rows=<?php echo urlencode($strAPrimaryKey . ' ' . htmlspecialchars($row['Field'])); ?>"
onclick="return confirmLink(this, 'ALTER TABLE <?php echo js_format($table); ?> DROP PRIMARY KEY, ADD PRIMARY KEY(<?php echo js_format($row['Field']); ?>)')">
<?php echo $strPrimary; ?></a>
</td>
<td>
@@ -315,9 +331,11 @@ if ($index_count > 0) {
$row = $ret_keys[$i];
if ($row['Key_name'] == 'PRIMARY') {
$sql_query = urlencode('ALTER TABLE ' . backquote($table) . ' DROP PRIMARY KEY');
$js_msg = 'ALTER TABLE ' . js_format($table) . ' DROP PRIMARY KEY';
$zero_rows = urlencode($strPrimaryKey . ' ' . $strHasBeenDropped);
} else {
$sql_query = urlencode('ALTER TABLE ' . backquote($table) . ' DROP INDEX ' . backquote($row['Key_name']));
$js_msg = 'ALTER TABLE ' . js_format($table) . ' DROP INDEX ' . js_format($row['Key_name']);
$zero_rows = urlencode($strIndex . ' ' . htmlspecialchars($row['Key_name']) . ' ' . $strHasBeenDropped);
}
echo "\n";
@@ -327,7 +345,9 @@ if ($index_count > 0) {
<td><?php echo (($row['Non_unique'] == '0') ? $strYes : $strNo) . "\n"; ?></td>
<td><?php echo htmlspecialchars($row['Column_name']) . "\n"; ?></td>
<td>
<?php echo "<a href=\"sql.php3?$url_query&sql_query=$sql_query&zero_rows=$zero_rows\">$strDrop</a>\n"; ?>
<a href="sql.php3?<?php echo "$url_query&sql_query=$sql_query&zero_rows=$zero_rows\n"; ?>"
onclick="return confirmLink(this, '<?php echo $js_msg; ?>')">
<?php echo $strDrop; ?></a>
</td>
</tr>
<?php
@@ -615,7 +635,8 @@ if ($cfgBookmark['db'] && $cfgBookmark['table']) {
<b><?php echo $strSelect; ?></b></a>&nbsp;-&nbsp;
<a href="tbl_change.php3?<?php echo $url_query; ?>">
<b><?php echo $strInsert; ?></b></a>&nbsp;-&nbsp;
<a href="sql.php3?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('DELETE FROM ' . backquote($table)); ?>&zero_rows=<?php echo urlencode($strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenEmptied); ?>">
<a href="sql.php3?<?php echo $url_query; ?>&sql_query=<?php echo urlencode('DELETE FROM ' . backquote($table)); ?>&zero_rows=<?php echo urlencode($strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenEmptied); ?>"
onclick="return confirmLink(this, 'DELETE FROM <?php echo js_format($table); ?>')">
<b><?php echo $strEmpty; ?></b></a>
<br />
</div>
@@ -1006,7 +1027,8 @@ else { // MySQL < 3.23
<!-- Deletes the table -->
<li>
<a href="sql.php3?<?php echo ereg_replace('tbl_properties.php3$', 'db_details.php3', $url_query); ?>&back=tbl_properties.php3&reload=true&sql_query=<?php echo urlencode('DROP TABLE ' . backquote($table)); ?>&zero_rows=<?php echo urlencode($strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenDropped); ?>">
<a href="sql.php3?<?php echo ereg_replace('tbl_properties.php3$', 'db_details.php3', $url_query); ?>&back=tbl_properties.php3&reload=true&sql_query=<?php echo urlencode('DROP TABLE ' . backquote($table)); ?>&zero_rows=<?php echo urlencode($strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenDropped); ?>"
onclick="return confirmLink(this, 'DROP TABLE <?php echo js_format($table); ?>')">
<?php echo $strDropTable . ' ' . htmlspecialchars($table); ?></a>
</li>