/* $Id: functions.js,v 1.24 2002/05/24 09:28:14 loic1 Exp $ */
/**
* 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
// or browser is Opera (crappy js implementation)
if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
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
* sumitting it if required.
* This function is called by the 'checkSqlQuery()' js function.
*
* @param object the form
* @param object the sql query textarea
*
* @return boolean whether to run the query or not
*
* @see checkSqlQuery()
*/
function confirmQuery(theForm1, sqlQuery1)
{
// Confirmation is not required in the configuration file
if (confirmMsg == '') {
return true;
}
// The replace function (js1.2) isn't supported
else if (typeof(sqlQuery1.value.replace) == 'undefined') {
return true;
}
// js1.2+ -> validation with regular expressions
else {
// "DROP DATABASE" statement isn't allowed
if (noDropDbMsg != '') {
var drop_re = new RegExp('DROP\\s+(IF EXISTS\\s+)?DATABASE\\s', 'i');
if (drop_re.test(sqlQuery1.value)) {
alert(noDropDbMsg);
theForm1.reset();
sqlQuery1.focus();
return false;
} // end if
} // end if
// Confirms a "DROP/DELETE/ALTER" statement
var do_confirm_re_0 = new RegExp('DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE)\\s', 'i');
var do_confirm_re_1 = new RegExp('ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s', 'i');
var do_confirm_re_2 = new RegExp('DELETE\\s+FROM\\s', 'i');
if (do_confirm_re_0.test(sqlQuery1.value)
|| do_confirm_re_1.test(sqlQuery1.value)
|| do_confirm_re_2.test(sqlQuery1.value)) {
var message = (sqlQuery1.value.length > 100)
? sqlQuery1.value.substr(0, 100) + '\n ...'
: sqlQuery1.value;
var is_confirmed = confirm(confirmMsg + ' :\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
if (is_confirmed) {
theForm1.elements['is_js_confirmed'].value = 1;
return true;
}
// "DROP/DELETE/ALTER" statement is rejected -> do not submit
// the form
else {
window.focus();
sqlQuery1.focus();
return false;
} // end if (handle confirm box result)
} // end if (display confirm box)
} // end confirmation stuff
return true;
} // end of the 'confirmQuery()' function
/**
* Displays an error message if the user submitted the sql query form with no
* sql query, else checks for "DROP/DELETE/ALTER" statements
*
* @param object the form
*
* @return boolean always false
*
* @see confirmQuery()
*/
function checkSqlQuery(theForm)
{
var sqlQuery = theForm.elements['sql_query'];
var isEmpty = 1;
// The replace function (js1.2) isn't supported -> basic tests
if (typeof(sqlQuery.value.replace) == 'undefined') {
isEmpty = (sqlQuery.value == '') ? 1 : 0;
if (isEmpty && typeof(theForm.elements['sql_file']) != 'undefined') {
isEmpty = (theForm.elements['sql_file'].value == '') ? 1 : 0;
}
if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {
isEmpty = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');
}
}
// js1.2+ -> validation with regular expressions
else {
var space_re = new RegExp('\\s+');
isEmpty = (sqlQuery.value.replace(space_re, '') == '') ? 1 : 0;
// Checks for "DROP/DELETE/ALTER" statements
if (!isEmpty && !confirmQuery(theForm, sqlQuery)) {
return false;
}
if (isEmpty && typeof(theForm.elements['sql_file']) != 'undefined') {
isEmpty = (theForm.elements['sql_file'].value.replace(space_re, '') == '') ? 1 : 0;
}
if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {
isEmpty = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');
isEmpty = (theForm.elements['id_bookmark'].selectedIndex == 0);
}
if (isEmpty) {
theForm.reset();
}
}
if (isEmpty) {
sqlQuery.select();
alert(errorMsg0);
sqlQuery.focus();
return false;
}
return true;
} // end of the 'checkSqlQuery()' function
/**
* Displays an error message if an element of a form hasn't been completed and
* should be
*
* @param object the form
* @param string the name of the form field to put the focus on
*
* @return boolean whether the form field is empty or not
*/
function emptyFormElements(theForm, theFieldName)
{
var isEmpty = 1;
var theField = theForm.elements[theFieldName];
// Whether the replace function (js1.2) is supported or not
var isRegExp = (typeof(theField.value.replace) != 'undefined');
if (!isRegExp) {
isEmpty = (theField.value == '') ? 1 : 0;
} else {
var space_re = new RegExp('\\s+');
isEmpty = (theField.value.replace(space_re, '') == '') ? 1 : 0;
}
if (isEmpty) {
theForm.reset();
theField.select();
alert(errorMsg0);
theField.focus();
return false;
}
return true;
} // end of the 'emptyFormElements()' function
/**
* Ensures a value submitted in a form is numeric and is in a range
*
* @param object the form
* @param string the name of the form field to check
* @param integer the minimum authorized value
* @param integer the maximum authorized value
*
* @return boolean whether a valid number has been submitted or not
*/
function checkFormElementInRange(theForm, theFieldName, min, max)
{
var theField = theForm.elements[theFieldName];
var val = parseInt(theField.value);
if (typeof(min) == 'undefined') {
min = 0;
}
if (typeof(max) == 'undefined') {
max = Number.MAX_VALUE;
}
// It's not a number
if (isNaN(val)) {
theField.select();
alert(errorMsg1);
theField.focus();
return false;
}
// It's a number but it is not between min and max
else if (val < min || val > max) {
theField.select();
alert(val + errorMsg2);
theField.focus();
return false;
}
// It's a valid number
else {
theField.value = val;
}
return true;
} // end of the 'checkFormElementInRange()' function
/**
* Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
* checkboxes is consistant
*
* @param object the form
* @param string a code for the action that causes this function to be run
*
* @return boolean always true
*/
function checkTransmitDump(theForm, theAction)
{
var formElts = theForm.elements;
// 'zipped' option has been checked
if (theAction == 'zip' && formElts['zip'].
stat_vss.rar_stat_vss
版权申诉
181 浏览量
2022-09-23
23:34:54
上传
评论
收藏 11KB RAR 举报
小波思基
- 粉丝: 70
- 资源: 1万+
最新资源
- 笔记实验六,spark,大数据分析
- ####蓝桥杯python的详细的信息介绍
- 电子万年历软件仿真(经过多次修改,保证正确性)
- Unity XR 手势射击控制脚本(适用于任何可手势识别的设备)
- 机械设计全自动电表(NB和IC卡表)控制和上壳装配线sw16可编辑非常好的设计图纸100%好用.zip
- 基于matlab的EAN-13条形码识别系统GUI界面.zip代码53
- matlab基于bp神经网络交通信号标志识别GUI界面13个标志.zip代码54
- 电子万年历答辩实物展示视频mp4格式
- 基于python实现的程序,包括哈希感知算法cvHash,图像切割cvsplit,固定目标检测cvRec(附文档ppt)等
- 计算0-10000之间所有偶数的和
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈