📄 functions.js
字号:
/* $Id: functions.js 8985 2006-04-27 11:35:54Z nijel $ *//** * @var sql_box_locked lock for the sqlbox textarea in the querybox/querywindow */var sql_box_locked = false;/** * @var array holds elements which content should only selected once */var only_once_elements = new Array();/** * selects the content of a given object, f.e. a textarea * * @param object element element of which the content will be selected * @param var lock variable which holds the lock for this element * or true, if no lock exists * @param boolean only_once if true this is only done once * f.e. only on first focus */function selectContent( element, lock, only_once ) { if ( only_once && only_once_elements[element.name] ) { return; } only_once_elements[element.name] = true; if ( lock ) { return; } element.select();}/** * Displays an confirmation box before to submit a "DROP DATABASE" 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 confirmLinkDropDB(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(confirmMsgDropDB + '\n' + confirmMsg + ' :\n' + theSqlQuery); if (is_confirmed) { theLink.href += '&is_js_confirmed=1'; } return is_confirmed;} // end of the 'confirmLinkDropDB()' function/** * Displays an confirmation box before 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) { if ( typeof(theLink.href) != 'undefined' ) { theLink.href += '&is_js_confirmed=1'; } else if ( typeof(theLink.form) != 'undefined' ) { theLink.form.action += '?is_js_confirmed=1'; } } return is_confirmed;} // end of the 'confirmLink()' function/** * Displays an confirmation box before doing some action * * @param object the message to display * * @return boolean whether to run the query or not */function confirmAction(theMessage){ // TODO: Confirmation is not required in the configuration file // or browser is Opera (crappy js implementation) if (typeof(window.opera) != 'undefined') { return true; } var is_confirmed = confirm(theMessage); return is_confirmed;} // end of the 'confirmAction()' 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('(^|;)\\s*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 // // TODO: find a way (if possible) to use the parser-analyser // for this kind of verification // For now, I just added a ^ to check for the statement at // beginning of expression 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['sql_localfile']) != 'undefined') { isEmpty = (theForm.elements['sql_localfile'].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+'); if (typeof(theForm.elements['sql_file']) != 'undefined' && theForm.elements['sql_file'].value.replace(space_re, '') != '') { return true; } if (typeof(theForm.elements['sql_localfile']) != 'undefined' && theForm.elements['sql_localfile'].value.replace(space_re, '') != '') { return true; } if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined' && (theForm.elements['id_bookmark'].value != null || theForm.elements['id_bookmark'].value != '') && theForm.elements['id_bookmark'].selectedIndex != 0 ) { return true; } // Checks for "DROP/DELETE/ALTER" statements if (sqlQuery.value.replace(space_re, '') != '') { if (confirmQuery(theForm, sqlQuery)) { return true; } else { return false; } } theForm.reset(); isEmpty = 1; } if (isEmpty) { sqlQuery.select(); alert(errorMsg0); sqlQuery.focus(); return false; } return true;} // end of the 'checkSqlQuery()' function/** * Check if a form's element is empty * 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 emptyCheckTheField(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; } return isEmpty;} // end of the 'emptyCheckTheField()' 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 theField = theForm.elements[theFieldName]; var isEmpty = emptyCheckTheField(theForm, theFieldName); 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, message, 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(message.replace('%d', val)); theField.focus(); return false; } // It's a valid number else { theField.value = val; } return true;} // end of the 'checkFormElementInRange()' functionfunction checkTableEditForm(theForm, fieldsCnt){ // TODO: avoid sending a message if user just wants to add a line // on the form but has not completed at least one field name var atLeastOneField = 0; var i, elm, elm2, elm3, val, id; for (i=0; i<fieldsCnt; i++) { id = "field_" + i + "_2"; elm = getElement(id); if (elm.value == 'VARCHAR' || elm.value == 'CHAR') { elm2 = getElement("field_" + i + "_3"); val = parseInt(elm2.value); elm3 = getElement("field_" + i + "_1"); if (isNaN(val) && elm3.value != "") { elm2.select(); alert(errorMsg1); elm2.focus(); return false; } } if (atLeastOneField == 0) { id = "field_" + i + "_1"; if (!emptyCheckTheField(theForm, id)) { atLeastOneField = 1; } } } if (atLeastOneField == 0) { var theField = theForm.elements["field_0_1"]; alert(errorMsg0); theField.focus(); return false; } return true;} // enf of the 'checkTableEditForm()' 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)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -