diff --git a/htdocs/sql/js/functions.js b/htdocs/sql/js/functions.js deleted file mode 100755 --- a/htdocs/sql/js/functions.js +++ /dev/null @@ -1,1219 +0,0 @@ -/* vim: set expandtab sw=4 ts=4 sts=4: */ -/** - * general function, usally for data manipulation pages - * - * @version $Id: functions.js 10964 2007-12-05 17:01:48Z lem9 $ - */ - -/** - * @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('^\\s*DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE|PROCEDURE)\\s', 'i'); - var do_confirm_re_1 = new RegExp('^\\s*ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s', 'i'); - var do_confirm_re_2 = new RegExp('^\\s*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()' function - - -function 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 0 ) { - unique_id = this.id; - } else { - return; - } - - if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) { - marked_row[unique_id] = true; - } else { - marked_row[unique_id] = false; - } - - if ( marked_row[unique_id] ) { - this.className += ' marked'; - } else { - this.className = this.className.replace(' marked', ''); - } - - if ( checkbox && checkbox.disabled == false ) { - checkbox.checked = marked_row[unique_id]; - } - } - - // ... and disable label ... - var labeltag = rows[i].getElementsByTagName('label')[0]; - if ( labeltag ) { - labeltag.onclick = function() { - return false; - } - } - // .. and checkbox clicks - var checkbox = rows[i].getElementsByTagName('input')[0]; - if ( checkbox ) { - checkbox.onclick = function() { - // opera does not recognize return false; - this.checked = ! this.checked; - } - } - } -} -window.onload=PMA_markRowsInit; - -/** - * marks all rows and selects its first checkbox inside the given element - * the given element is usaly a table or a div containing the table or tables - * - * @param container DOM element - */ -function markAllRows( container_id ) { - var rows = document.getElementById(container_id).getElementsByTagName('tr'); - var unique_id; - var checkbox; - - for ( var i = 0; i < rows.length; i++ ) { - - checkbox = rows[i].getElementsByTagName( 'input' )[0]; - - if ( checkbox && checkbox.type == 'checkbox' ) { - unique_id = checkbox.name + checkbox.value; - if ( checkbox.disabled == false ) { - checkbox.checked = true; - if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) { - rows[i].className += ' marked'; - marked_row[unique_id] = true; - } - } - } - } - - return true; -} - -/** - * marks all rows and selects its first checkbox inside the given element - * the given element is usaly a table or a div containing the table or tables - * - * @param container DOM element - */ -function unMarkAllRows( container_id ) { - var rows = document.getElementById(container_id).getElementsByTagName('tr'); - var unique_id; - var checkbox; - - for ( var i = 0; i < rows.length; i++ ) { - - checkbox = rows[i].getElementsByTagName( 'input' )[0]; - - if ( checkbox && checkbox.type == 'checkbox' ) { - unique_id = checkbox.name + checkbox.value; - checkbox.checked = false; - rows[i].className = rows[i].className.replace(' marked', ''); - marked_row[unique_id] = false; - } - } - - return true; -} - -/** - * Sets/unsets the pointer and marker in browse mode - * - * @param object the table row - * @param integer the row number - * @param string the action calling this script (over, out or click) - * @param string the default background color - * @param string the color to use for mouseover - * @param string the color to use for marking a row - * - * @return boolean whether pointer is set or not - */ -function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor) -{ - var theCells = null; - - // 1. Pointer and mark feature are disabled or the browser can't get the - // row -> exits - if ((thePointerColor == '' && theMarkColor == '') - || typeof(theRow.style) == 'undefined') { - return false; - } - - // 1.1 Sets the mouse pointer to pointer on mouseover and back to normal otherwise. - if (theAction == "over" || theAction == "click") { - theRow.style.cursor='pointer'; - } else { - theRow.style.cursor='default'; - } - - // 2. Gets the current row and exits if the browser can't get it - if (typeof(document.getElementsByTagName) != 'undefined') { - theCells = theRow.getElementsByTagName('td'); - } - else if (typeof(theRow.cells) != 'undefined') { - theCells = theRow.cells; - } - else { - return false; - } - - // 3. Gets the current color... - var rowCellsCnt = theCells.length; - var domDetect = null; - var currentColor = null; - var newColor = null; - // 3.1 ... with DOM compatible browsers except Opera that does not return - // valid values with "getAttribute" - if (typeof(window.opera) == 'undefined' - && typeof(theCells[0].getAttribute) != 'undefined') { - currentColor = theCells[0].getAttribute('bgcolor'); - domDetect = true; - } - // 3.2 ... with other browsers - else { - currentColor = theCells[0].style.backgroundColor; - domDetect = false; - } // end 3 - - // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it - if (currentColor.indexOf("rgb") >= 0) - { - var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1, - currentColor.indexOf(')')); - var rgbValues = rgbStr.split(","); - currentColor = "#"; - var hexChars = "0123456789ABCDEF"; - for (var i = 0; i < 3; i++) - { - var v = rgbValues[i].valueOf(); - currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16); - } - } - - // 4. Defines the new color - // 4.1 Current color is the default one - if (currentColor == '' - || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) { - if (theAction == 'over' && thePointerColor != '') { - newColor = thePointerColor; - } - else if (theAction == 'click' && theMarkColor != '') { - newColor = theMarkColor; - marked_row[theRowNum] = true; - // Garvin: deactivated onclick marking of the checkbox because it's also executed - // when an action (like edit/delete) on a single item is performed. Then the checkbox - // would get deactived, even though we need it activated. Maybe there is a way - // to detect if the row was clicked, and not an item therein... - // document.getElementById('id_rows_to_delete' + theRowNum).checked = true; - } - } - // 4.1.2 Current color is the pointer one - else if (currentColor.toLowerCase() == thePointerColor.toLowerCase() - && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) { - if (theAction == 'out') { - newColor = theDefaultColor; - } - else if (theAction == 'click' && theMarkColor != '') { - newColor = theMarkColor; - marked_row[theRowNum] = true; - // document.getElementById('id_rows_to_delete' + theRowNum).checked = true; - } - } - // 4.1.3 Current color is the marker one - else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) { - if (theAction == 'click') { - newColor = (thePointerColor != '') - ? thePointerColor - : theDefaultColor; - marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum]) - ? true - : null; - // document.getElementById('id_rows_to_delete' + theRowNum).checked = false; - } - } // end 4 - - // 5. Sets the new color... - if (newColor) { - var c = null; - // 5.1 ... with DOM compatible browsers except Opera - if (domDetect) { - for (c = 0; c < rowCellsCnt; c++) { - theCells[c].setAttribute('bgcolor', newColor, 0); - } // end for - } - // 5.2 ... with other browsers - else { - for (c = 0; c < rowCellsCnt; c++) { - theCells[c].style.backgroundColor = newColor; - } - } - } // end 5 - - return true; -} // end of the 'setPointer()' function - -/* - * Sets/unsets the pointer and marker in vertical browse mode - * - * @param object the table row - * @param integer the column number - * @param string the action calling this script (over, out or click) - * @param string the default background Class - * @param string the Class to use for mouseover - * @param string the Class to use for marking a row - * - * @return boolean whether pointer is set or not - * - * @author Garvin Hicking (rewrite of setPointer.) - */ -function setVerticalPointer(theRow, theColNum, theAction, theDefaultClass1, theDefaultClass2, thePointerClass, theMarkClass) { - // 1. Pointer and mark feature are disabled or the browser can't get the - // row -> exits - if ((thePointerClass == '' && theMarkClass == '') - || typeof(theRow.style) == 'undefined') { - return false; - } - - var tagSwitch = null; - - // 2. Gets the current row and exits if the browser can't get it - if (typeof(document.getElementsByTagName) != 'undefined') { - tagSwitch = 'tag'; - } else if (typeof(document.getElementById('table_results')) != 'undefined') { - tagSwitch = 'cells'; - } else { - return false; - } - - var theCells = null; - - if (tagSwitch == 'tag') { - theRows = document.getElementById('table_results').getElementsByTagName('tr'); - theCells = theRows[1].getElementsByTagName('td'); - } else if (tagSwitch == 'cells') { - theRows = document.getElementById('table_results').rows; - theCells = theRows[1].cells; - } - - // 3. Gets the current Class... - var currentClass = null; - var newClass = null; - - // 3.1 ... with DOM compatible browsers except Opera that does not return - // valid values with "getAttribute" - if (typeof(window.opera) == 'undefined' - && typeof(theCells[theColNum].getAttribute) != 'undefined') { - currentClass = theCells[theColNum].className; - } // end 3 - - // 4. Defines the new Class - // 4.1 Current Class is the default one - if (currentClass == '' - || currentClass.toLowerCase() == theDefaultClass1.toLowerCase() - || currentClass.toLowerCase() == theDefaultClass2.toLowerCase()) { - if (theAction == 'over' && thePointerClass != '') { - newClass = thePointerClass; - } else if (theAction == 'click' && theMarkClass != '') { - newClass = theMarkClass; - marked_row[theColNum] = true; - } - } - // 4.1.2 Current Class is the pointer one - else if (currentClass.toLowerCase() == thePointerClass.toLowerCase() && - (typeof(marked_row[theColNum]) == 'undefined' || !marked_row[theColNum]) || marked_row[theColNum] == false) { - if (theAction == 'out') { - if (theColNum % 2) { - newClass = theDefaultClass1; - } else { - newClass = theDefaultClass2; - } - } - else if (theAction == 'click' && theMarkClass != '') { - newClass = theMarkClass; - marked_row[theColNum] = true; - } - } - // 4.1.3 Current Class is the marker one - else if (currentClass.toLowerCase() == theMarkClass.toLowerCase()) { - if (theAction == 'click') { - newClass = (thePointerClass != '') - ? thePointerClass - : ((theColNum % 2) ? theDefaultClass2 : theDefaultClass1); - marked_row[theColNum] = false; - } - } // end 4 - - // 5 ... with DOM compatible browsers except Opera - - if (newClass) { - var c = null; - var rowCnt = theRows.length; - for (c = 0; c < rowCnt; c++) { - if (tagSwitch == 'tag') { - Cells = theRows[c].getElementsByTagName('td'); - } else if (tagSwitch == 'cells') { - Cells = theRows[c].cells; - } - - Cell = Cells[theColNum]; - - // 5.1 Sets the new Class... - Cell.className = Cell.className.replace(currentClass, newClass); - } // end for - } // end 5 - - return true; - } // end of the 'setVerticalPointer()' function - -/** - * Checks/unchecks all checkbox in given conainer (f.e. a form, fieldset or div) - * - * @param string container_id the container id - * @param boolean state new value for checkbox (true or false) - * @return boolean always true - */ -function setCheckboxes( container_id, state ) { - var checkboxes = document.getElementById(container_id).getElementsByTagName('input'); - - for ( var i = 0; i < checkboxes.length; i++ ) { - if ( checkboxes[i].type == 'checkbox' ) { - checkboxes[i].checked = state; - } - } - - return true; -} // end of the 'setCheckboxes()' function - - -// added 2004-05-08 by Michael Keck -// copy the checked from left to right or from right to left -// so it's easier for users to see, if $cfg['ModifyAtRight']=true, what they've checked ;) -function copyCheckboxesRange(the_form, the_name, the_clicked) -{ - if (typeof(document.forms[the_form].elements[the_name]) != 'undefined' && typeof(document.forms[the_form].elements[the_name + 'r']) != 'undefined') { - if (the_clicked !== 'r') { - if (document.forms[the_form].elements[the_name].checked == true) { - document.forms[the_form].elements[the_name + 'r'].checked = true; - }else { - document.forms[the_form].elements[the_name + 'r'].checked = false; - } - } else if (the_clicked == 'r') { - if (document.forms[the_form].elements[the_name + 'r'].checked == true) { - document.forms[the_form].elements[the_name].checked = true; - }else { - document.forms[the_form].elements[the_name].checked = false; - } - } - } -} - - -// added 2004-05-08 by Michael Keck -// - this was directly written to each td, so why not a function ;) -// setCheckboxColumn(\'id_rows_to_delete' . $row_no . ''\'); -function setCheckboxColumn(theCheckbox){ - if (document.getElementById(theCheckbox)) { - document.getElementById(theCheckbox).checked = (document.getElementById(theCheckbox).checked ? false : true); - if (document.getElementById(theCheckbox + 'r')) { - document.getElementById(theCheckbox + 'r').checked = document.getElementById(theCheckbox).checked; - } - } else { - if (document.getElementById(theCheckbox + 'r')) { - document.getElementById(theCheckbox + 'r').checked = (document.getElementById(theCheckbox +'r').checked ? false : true); - if (document.getElementById(theCheckbox)) { - document.getElementById(theCheckbox).checked = document.getElementById(theCheckbox + 'r').checked; - } - } - } -} - - -/** - * Checks/unchecks all options of a