use array for JavaScript messages

This commit is contained in:
Sebastian Mendel
2007-10-04 15:03:44 +00:00
parent 27fd48d8fa
commit ba662b78f6
5 changed files with 83 additions and 77 deletions

View File

@@ -51,11 +51,11 @@ function confirmLinkDropDB(theLink, theSqlQuery)
{
// Confirmation is not required in the configuration file
// or browser is Opera (crappy js implementation)
if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
if (PMA_messages['strDoYouReally'] == '' || typeof(window.opera) != 'undefined') {
return true;
}
var is_confirmed = confirm(confirmMsgDropDB + '\n' + confirmMsg + ' :\n' + theSqlQuery);
var is_confirmed = confirm(PMA_messages['strDropDatabaseStrongWarning'] + '\n' + PMA_messages['strDoYouReally'] + ' :\n' + theSqlQuery);
if (is_confirmed) {
theLink.href += '&is_js_confirmed=1';
}
@@ -76,11 +76,11 @@ function confirmLink(theLink, theSqlQuery)
{
// Confirmation is not required in the configuration file
// or browser is Opera (crappy js implementation)
if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
if (PMA_messages['strDoYouReally'] == '' || typeof(window.opera) != 'undefined') {
return true;
}
var is_confirmed = confirm(confirmMsg + ' :\n' + theSqlQuery);
var is_confirmed = confirm(PMA_messages['strDoYouReally'] + ' :\n' + theSqlQuery);
if (is_confirmed) {
if ( typeof(theLink.href) != 'undefined' ) {
theLink.href += '&is_js_confirmed=1';
@@ -130,7 +130,7 @@ function confirmAction(theMessage)
function confirmQuery(theForm1, sqlQuery1)
{
// Confirmation is not required in the configuration file
if (confirmMsg == '') {
if (PMA_messages['strDoYouReally'] == '') {
return true;
}
@@ -142,10 +142,10 @@ function confirmQuery(theForm1, sqlQuery1)
// js1.2+ -> validation with regular expressions
else {
// "DROP DATABASE" statement isn't allowed
if (noDropDbMsg != '') {
if (PMA_messages['strNoDropDatabases'] != '') {
var drop_re = new RegExp('(^|;)\\s*DROP\\s+(IF EXISTS\\s+)?DATABASE\\s', 'i');
if (drop_re.test(sqlQuery1.value)) {
alert(noDropDbMsg);
alert(PMA_messages['strNoDropDatabases']);
theForm1.reset();
sqlQuery1.focus();
return false;
@@ -168,7 +168,7 @@ function confirmQuery(theForm1, sqlQuery1)
var message = (sqlQuery1.value.length > 100)
? sqlQuery1.value.substr(0, 100) + '\n ...'
: sqlQuery1.value;
var is_confirmed = confirm(confirmMsg + ' :\n' + message);
var is_confirmed = confirm(PMA_messages['strDoYouReally'] + ' :\n' + message);
// drop/delete/alter statement is confirmed -> update the
// "is_js_confirmed" form field so the confirm test won't be
// run on the server side and allows to submit the form
@@ -249,7 +249,7 @@ function checkSqlQuery(theForm)
if (isEmpty) {
sqlQuery.select();
alert(errorMsg0);
alert(PMA_messages['strFormEmpty']);
sqlQuery.focus();
return false;
}
@@ -302,7 +302,7 @@ function emptyFormElements(theForm, theFieldName)
if (isEmpty) {
theForm.reset();
theField.select();
alert(errorMsg0);
alert(PMA_messages['strFormEmpty']);
theField.focus();
return false;
}
@@ -336,7 +336,7 @@ function checkFormElementInRange(theForm, theFieldName, message, min, max)
// It's not a number
if (isNaN(val)) {
theField.select();
alert(errorMsg1);
alert(PMA_messages['strNotNumber']);
theField.focus();
return false;
}
@@ -374,7 +374,7 @@ function checkTableEditForm(theForm, fieldsCnt)
elm3 = getElement("field_" + i + "_1");
if (isNaN(val) && elm3.value != "") {
elm2.select();
alert(errorMsg1);
alert(PMA_messages['strNotNumber']);
elm2.focus();
return false;
}
@@ -389,7 +389,7 @@ function checkTableEditForm(theForm, fieldsCnt)
}
if (atLeastOneField == 0) {
var theField = theForm.elements["field_0_1"];
alert(errorMsg0);
alert(PMA_messages['strFormEmpty']);
theField.focus();
return false;
}

View File

@@ -30,7 +30,7 @@ function checkFormElementInRange(theForm, theFieldName, message, min, max)
// It's not a number
if (isNaN(val)) {
theField.select();
alert(errorMsg1);
alert(PMA_messages['strNotNumber']);
theField.focus();
return false;
}

View File

@@ -8,8 +8,8 @@
/**
* Validates the password field in a form
*
* @uses jsPasswordEmpty
* @uses jsPasswordNotSame
* @uses PMA_messages['strPasswordEmpty']
* @uses PMA_messages['strPasswordNotSame']
* @param object the form
* @return boolean whether the field value is valid or not
*/
@@ -30,9 +30,9 @@ function checkPassword(the_form)
var alert_msg = false;
if (password.value == '') {
alert_msg = jsPasswordEmpty;
alert_msg = PMA_messages['strPasswordEmpty'];
} else if (password.value != password_repeat.value) {
alert_msg = jsPasswordNotSame;
alert_msg = PMA_messages['strPasswordNotSame'];
}
if (alert_msg) {
@@ -55,13 +55,13 @@ function checkPassword(the_form)
function checkAddUser(the_form)
{
if (the_form.elements['pred_hostname'].value == 'userdefined' && the_form.elements['hostname'].value == '') {
alert(jsHostEmpty);
alert(PMA_messages['strHostEmpty']);
the_form.elements['hostname'].focus();
return false;
}
if (the_form.elements['pred_username'].value == 'userdefined' && the_form.elements['username'].value == '') {
alert(jsUserEmpty);
alert(PMA_messages['strUserEmpty']);
the_form.elements['username'].focus();
return false;
}

View File

@@ -53,6 +53,37 @@ if (empty($GLOBALS['is_header_sent'])) {
);
// here, the function does not exist with this configuration: $cfg['ServerDefault'] = 0;
$is_superuser = function_exists('PMA_isSuperuser') && PMA_isSuperuser();
if (in_array('functions.js', $GLOBALS['js_include'])) {
$js_messages['strFormEmpty'] = $GLOBALS['strFormEmpty'];
$js_messages['strNotNumber'] = $GLOBALS['strNotNumber'];
if (!$is_superuser && !$GLOBALS['cfg']['AllowUserDropDatabase']) {
$js_messages['strNoDropDatabases'] = $GLOBALS['strNoDropDatabases'];
} else {
$js_messages['strNoDropDatabases'] = '';
}
if ($GLOBALS['cfg']['Confirm']) {
$js_messages['strDoYouReally'] = $GLOBALS['strDoYouReally'];
$js_messages['strDropDatabaseStrongWarning'] = $GLOBALS['strDropDatabaseStrongWarning'];
} else {
$js_messages['strDoYouReally'] = '';
$js_messages['strDropDatabaseStrongWarning'] = '';
}
} elseif (in_array('indexes.js', $GLOBALS['js_include'])) {
$js_messages['strFormEmpty'] = $GLOBALS['strFormEmpty'];
$js_messages['strNotNumber'] = $GLOBALS['strNotNumber'];
}
if (in_array('server_privileges.js', $GLOBALS['js_include'])) {
$js_messages['strHostEmpty'] = $GLOBALS['strHostEmpty'];
$js_messages['strUserEmpty'] = $GLOBALS['strUserEmpty'];
$js_messages['strPasswordEmpty'] = $GLOBALS['strPasswordEmpty'];
$js_messages['strPasswordNotSame'] = $GLOBALS['strPasswordNotSame'];
}
$GLOBALS['js_include'][] = 'tooltip.js';
?>
<script type="text/javascript">
// <![CDATA[
@@ -62,42 +93,16 @@ if (empty($GLOBALS['is_header_sent'])) {
parent.document.title = '<?php echo PMA_sanitize(PMA_escapeJsString($title)); ?>';
}
var PMA_messages = new Array();
<?php
// Add some javascript instructions if required
if (in_array('functions.js', $GLOBALS['js_include'])) {
?>
// js form validation stuff
var errorMsg0 = '<?php echo PMA_escapeJsString($GLOBALS['strFormEmpty']); ?>';
var errorMsg1 = '<?php echo PMA_escapeJsString($GLOBALS['strNotNumber']); ?>';
var noDropDbMsg = '<?php echo (!$is_superuser && !$GLOBALS['cfg']['AllowUserDropDatabase'])
? PMA_escapeJsString($GLOBALS['strNoDropDatabases']) : ''; ?>';
var confirmMsg = '<?php echo(($GLOBALS['cfg']['Confirm']) ? PMA_escapeJsString($GLOBALS['strDoYouReally']) : ''); ?>';
var confirmMsgDropDB = '<?php echo(($GLOBALS['cfg']['Confirm']) ? PMA_escapeJsString($GLOBALS['strDropDatabaseStrongWarning']) : ''); ?>';
<?php
} elseif (in_array('indexes.js', $GLOBALS['js_include'])) {
?>
// js index validation stuff
var errorMsg0 = '<?php echo PMA_escapeJsString($GLOBALS['strFormEmpty']); ?>';
var errorMsg1 = '<?php echo PMA_escapeJsString($GLOBALS['strNotNumber']); ?>';
<?php
foreach ($js_messages as $name => $js_message) {
echo "PMA_messages['" . $name . "'] = '" . PMA_escapeJsString($js_message) . "';\n";
}
if (in_array('server_privileges.js', $GLOBALS['js_include'])) {
?>
// js form validation stuff
var jsHostEmpty = '<?php echo PMA_escapeJsString($GLOBALS['strHostEmpty']); ?>';
var jsUserEmpty = '<?php echo PMA_escapeJsString($GLOBALS['strUserEmpty']); ?>';
var jsPasswordEmpty = '<?php echo PMA_escapeJsString($GLOBALS['strPasswordEmpty']); ?>';
var jsPasswordNotSame = '<?php echo PMA_escapeJsString($GLOBALS['strPasswordNotSame']); ?>';
<?php
}
?>
// ]]>
</script>
<?php
$GLOBALS['js_include'][] = 'tooltip.js';
foreach ($GLOBALS['js_include'] as $js_script_file) {
echo '<script src="./js/' . $js_script_file . '" type="text/javascript"></script>' . "\n";
}

View File

@@ -170,11 +170,12 @@ require_once './libraries/header_meta_style.inc.php';
?>
<script type="text/javascript">
//<![CDATA[
var errorMsg0 = '<?php echo PMA_escapeJsString($GLOBALS['strFormEmpty']); ?>';
var errorMsg1 = '<?php echo PMA_escapeJsString($GLOBALS['strNotNumber']); ?>';
var noDropDbMsg = '<?php echo (!$is_superuser && !$GLOBALS['cfg']['AllowUserDropDatabase'])
var PMA_messages = new Array();
PMA_messages['strFormEmpty'] = '<?php echo PMA_escapeJsString($GLOBALS['strFormEmpty']); ?>';
PMA_messages['strNotNumber'] = '<?php echo PMA_escapeJsString($GLOBALS['strNotNumber']); ?>';
PMA_messages['strNoDropDatabases'] = '<?php echo (!$is_superuser && !$GLOBALS['cfg']['AllowUserDropDatabase'])
? PMA_escapeJsString($GLOBALS['strNoDropDatabases']) : ''; ?>';
var confirmMsg = '<?php echo $GLOBALS['cfg']['Confirm']
PMA_messages['strDoYouReally'] = '<?php echo $GLOBALS['cfg']['Confirm']
? PMA_escapeJsString($GLOBALS['strDoYouReally']) : ''; ?>';
function PMA_queryAutoCommit() {