/phpMyAdmin/js/functions.js
JavaScript | 4109 lines | 3226 code | 209 blank | 674 comment | 555 complexity | 1e78695f2b6be61a252a53e7e7049f0f MD5 | raw file
Possible License(s): GPL-2.0, LGPL-3.0
Large files files are truncated, but you can click here to view the full file
- /* vim: set expandtab sw=4 ts=4 sts=4: */
- /**
- * general function, usually for data manipulation pages
- *
- */
- /**
- * @var $table_clone reference to the action links on the tbl_structure page
- */
- var $table_clone = false;
- /**
- * @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 = [];
- /**
- * @var int ajax_message_count Number of AJAX messages shown since page load
- */
- var ajax_message_count = 0;
- /**
- * @var codemirror_editor object containing CodeMirror editor of the query editor in SQL tab
- */
- var codemirror_editor = false;
- /**
- * @var codemirror_editor object containing CodeMirror editor of the inline query editor
- */
- var codemirror_inline_editor = false;
- /**
- * @var chart_activeTimeouts object active timeouts that refresh the charts. When disabling a realtime chart, this can be used to stop the continuous ajax requests
- */
- var chart_activeTimeouts = {};
- /**
- * Make sure that ajax requests will not be cached
- * by appending a random variable to their parameters
- */
- $.ajaxPrefilter(function (options, originalOptions, jqXHR) {
- var nocache = new Date().getTime() + "" + Math.floor(Math.random() * 1000000);
- if (typeof options.data == "string") {
- options.data += "&_nocache=" + nocache;
- } else if (typeof options.data == "object") {
- options.data = $.extend(originalOptions.data, {'_nocache' : nocache});
- }
- });
- /**
- * Add a hidden field to the form to indicate that this will be an
- * Ajax request (only if this hidden field does not exist)
- *
- * @param object the form
- */
- function PMA_prepareForAjaxRequest($form)
- {
- if (! $form.find('input:hidden').is('#ajax_request_hidden')) {
- $form.append('<input type="hidden" id="ajax_request_hidden" name="ajax_request" value="true" />');
- }
- }
- /**
- * Generate a new password and copy it to the password input areas
- *
- * @param object the form that holds the password fields
- *
- * @return boolean always true
- */
- function suggestPassword(passwd_form)
- {
- // restrict the password to just letters and numbers to avoid problems:
- // "editors and viewers regard the password as multiple words and
- // things like double click no longer work"
- var pwchars = "abcdefhjmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWYXZ";
- var passwordlength = 16; // do we want that to be dynamic? no, keep it simple :)
- var passwd = passwd_form.generated_pw;
- passwd.value = '';
- for (var i = 0; i < passwordlength; i++) {
- passwd.value += pwchars.charAt(Math.floor(Math.random() * pwchars.length));
- }
- passwd_form.text_pma_pw.value = passwd.value;
- passwd_form.text_pma_pw2.value = passwd.value;
- return true;
- }
- /**
- * Version string to integer conversion.
- */
- function parseVersionString(str)
- {
- if (typeof(str) != 'string') { return false; }
- var add = 0;
- // Parse possible alpha/beta/rc/
- var state = str.split('-');
- if (state.length >= 2) {
- if (state[1].substr(0, 2) == 'rc') {
- add = - 20 - parseInt(state[1].substr(2), 10);
- } else if (state[1].substr(0, 4) == 'beta') {
- add = - 40 - parseInt(state[1].substr(4), 10);
- } else if (state[1].substr(0, 5) == 'alpha') {
- add = - 60 - parseInt(state[1].substr(5), 10);
- } else if (state[1].substr(0, 3) == 'dev') {
- /* We don't handle dev, it's git snapshot */
- add = 0;
- }
- }
- // Parse version
- var x = str.split('.');
- // Use 0 for non existing parts
- var maj = parseInt(x[0], 10) || 0;
- var min = parseInt(x[1], 10) || 0;
- var pat = parseInt(x[2], 10) || 0;
- var hotfix = parseInt(x[3], 10) || 0;
- return maj * 100000000 + min * 1000000 + pat * 10000 + hotfix * 100 + add;
- }
- /**
- * Indicates current available version on main page.
- */
- function PMA_current_version(data)
- {
- if (data && data.version && data.date) {
- var current = parseVersionString(pmaversion);
- var latest = parseVersionString(data.version);
- var version_information_message = '<span>'
- + PMA_messages.strLatestAvailable
- + ' ' + escapeHtml(data.version)
- + '</span>';
- if (latest > current) {
- var message = $.sprintf(
- PMA_messages.strNewerVersion,
- escapeHtml(data.version),
- escapeHtml(data.date)
- );
- var htmlClass = 'notice';
- if (Math.floor(latest / 10000) === Math.floor(current / 10000)) {
- /* Security update */
- htmlClass = 'error';
- }
- $('#maincontainer').after('<div class="' + htmlClass + '">' + message + '</div>');
- }
- if (latest === current) {
- version_information_message = ' (' + PMA_messages.strUpToDate + ')';
- }
- $('#li_pma_version span').remove();
- $('#li_pma_version').append(version_information_message);
- }
- }
- /**
- * Loads Git revision data from ajax for index.php
- */
- function PMA_display_git_revision()
- {
- $('#is_git_revision').remove();
- $('#li_pma_version_git').remove();
- $.get(
- "index.php",
- {
- "server": PMA_commonParams.get('server'),
- "token": PMA_commonParams.get('token'),
- "git_revision": true,
- "ajax_request": true
- },
- function (data) {
- if (data.success === true) {
- $(data.message).insertAfter('#li_pma_version');
- }
- }
- );
- }
- /**
- * for libraries/display_change_password.lib.php
- * libraries/user_password.php
- *
- */
- function displayPasswordGenerateButton()
- {
- $('#tr_element_before_generate_password').parent().append('<tr class="vmiddle"><td>' + PMA_messages.strGeneratePassword + '</td><td><input type="button" class="button" id="button_generate_password" value="' + PMA_messages.strGenerate + '" onclick="suggestPassword(this.form)" /><input type="text" name="generated_pw" id="generated_pw" /></td></tr>');
- $('#div_element_before_generate_password').parent().append('<div class="item"><label for="button_generate_password">' + PMA_messages.strGeneratePassword + ':</label><span class="options"><input type="button" class="button" id="button_generate_password" value="' + PMA_messages.strGenerate + '" onclick="suggestPassword(this.form)" /></span><input type="text" name="generated_pw" id="generated_pw" /></div>');
- }
- /*
- * Adds a date/time picker to an element
- *
- * @param object $this_element a jQuery object pointing to the element
- */
- function PMA_addDatepicker($this_element, options)
- {
- var showTimeOption = false;
- if ($this_element.is('.datetimefield')) {
- showTimeOption = true;
- }
- var defaultOptions = {
- showOn: 'button',
- buttonImage: themeCalendarImage, // defined in js/messages.php
- buttonImageOnly: true,
- stepMinutes: 1,
- stepHours: 1,
- showSecond: true,
- showMillisec: true,
- showMicrosec: true,
- showTimepicker: showTimeOption,
- showButtonPanel: false,
- dateFormat: 'yy-mm-dd', // yy means year with four digits
- timeFormat: 'HH:mm:ss.lc',
- constrainInput: false,
- altFieldTimeOnly: false,
- showAnim: '',
- beforeShow: function (input, inst) {
- // Remember that we came from the datepicker; this is used
- // in tbl_change.js by verificationsAfterFieldChange()
- $this_element.data('comes_from', 'datepicker');
- // Fix wrong timepicker z-index, doesn't work without timeout
- setTimeout(function () {
- $('#ui-timepicker-div').css('z-index', $('#ui-datepicker-div').css('z-index'));
- }, 0);
- },
- onClose: function (dateText, dp_inst) {
- // The value is no more from the date picker
- $this_element.data('comes_from', '');
- }
- };
- if (showTimeOption || (typeof(options) != 'undefined' && options.showTimepicker)) {
- $this_element.datetimepicker($.extend(defaultOptions, options));
- } else {
- $this_element.datepicker($.extend(defaultOptions, options));
- }
- }
- /**
- * 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 a confirmation box before submitting 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 (PMA_messages.strDoYouReally === '' || typeof(window.opera) != 'undefined') {
- return true;
- }
- var is_confirmed = confirm($.sprintf(PMA_messages.strDoYouReally, theSqlQuery));
- if (is_confirmed) {
- if ($(theLink).hasClass('formLinkSubmit')) {
- var name = 'is_js_confirmed';
- if ($(theLink).attr('href').indexOf('usesubform') != -1) {
- name = 'subform[' + $(theLink).attr('href').substr('#').match(/usesubform\[(\d+)\]/i)[1] + '][is_js_confirmed]';
- }
- $(theLink).parents('form').append('<input type="hidden" name="' + name + '" value="1" />');
- } else 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 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 (PMA_messages.strDoYouReally === '') {
- return true;
- }
- // "DROP DATABASE" statement isn't allowed
- 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(PMA_messages.strNoDropDatabases);
- theForm1.reset();
- sqlQuery1.focus();
- return false;
- } // end if
- } // end if
- // Confirms a "DROP/DELETE/ALTER/TRUNCATE" 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');
- var do_confirm_re_3 = new RegExp('^\\s*TRUNCATE\\s', 'i');
- if (do_confirm_re_0.test(sqlQuery1.value) ||
- do_confirm_re_1.test(sqlQuery1.value) ||
- do_confirm_re_2.test(sqlQuery1.value) ||
- do_confirm_re_3.test(sqlQuery1.value)) {
- var message;
- if (sqlQuery1.value.length > 100) {
- message = sqlQuery1.value.substr(0, 100) + '\n ...';
- } else {
- message = sqlQuery1.value;
- }
- var is_confirmed = confirm($.sprintf(PMA_messages.strDoYouReally, message));
- // 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;
- }
- // 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)
- 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)
- {
- // get the textarea element containing the query
- if (codemirror_editor) {
- codemirror_editor.save();
- var sqlQuery = codemirror_editor.display.input;
- sqlQuery.value = codemirror_editor.getValue();
- } else {
- var sqlQuery = theForm.elements['sql_query'];
- }
- var isEmpty = 1;
- 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(PMA_messages.strFormEmpty);
- sqlQuery.focus();
- return false;
- }
- return true;
- } // end of the 'checkSqlQuery()' function
- /**
- * Check if a form's element is empty.
- * An element containing only spaces is also considered empty
- *
- * @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 theField = theForm.elements[theFieldName];
- var space_re = new RegExp('\\s+');
- return (theField.value.replace(space_re, '') === '') ? 1 : 0;
- } // end of the 'emptyCheckTheField()' function
- /**
- * Check whether a form field is empty or not
- *
- * @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);
- return isEmpty;
- } // 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, 10);
- 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(PMA_messages.strEnterValidNumber);
- 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($.sprintf(message, 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 < fieldsCnt; i++) {
- id = "#field_" + i + "_2";
- elm = $(id);
- val = elm.val();
- if (val == 'VARCHAR' || val == 'CHAR' || val == 'BIT' || val == 'VARBINARY' || val == 'BINARY') {
- elm2 = $("#field_" + i + "_3");
- val = parseInt(elm2.val(), 10);
- elm3 = $("#field_" + i + "_1");
- if (isNaN(val) && elm3.val() !== "") {
- elm2.select();
- alert(PMA_messages.strEnterValidLength);
- 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(PMA_messages.strFormEmpty);
- theField.focus();
- return false;
- }
- // at least this section is under jQuery
- if ($("input.textfield[name='table']").val() === "") {
- alert(PMA_messages.strFormEmpty);
- $("input.textfield[name='table']").focus();
- return false;
- }
- return true;
- } // enf of the 'checkTableEditForm()' function
- /**
- * Unbind all event handlers before tearing down a page
- */
- AJAX.registerTeardown('functions.js', function () {
- $('input:checkbox.checkall').die('click');
- });
- AJAX.registerOnload('functions.js', function () {
- /**
- * Row marking in horizontal mode (use "live" so that it works also for
- * next pages reached via AJAX); a tr may have the class noclick to remove
- * this behavior.
- */
- $('input:checkbox.checkall').live('click', function (e) {
- var $tr = $(this).closest('tr');
- // make the table unselectable (to prevent default highlighting when shift+click)
- //$tr.parents('table').noSelect();
- if (!e.shiftKey || last_clicked_row == -1) {
- // usual click
- // XXX: FF fires two click events for <label> (label and checkbox), so we need to handle this differently
- var $checkbox = $tr.find(':checkbox');
- if ($checkbox.length) {
- // checkbox in a row, add or remove class depending on checkbox state
- var checked = $checkbox.prop('checked');
- if (!$(e.target).is(':checkbox, label')) {
- checked = !checked;
- $checkbox.prop('checked', checked).trigger('change');
- }
- if (checked) {
- $tr.addClass('marked');
- } else {
- $tr.removeClass('marked');
- }
- last_click_checked = checked;
- } else {
- // normal data table, just toggle class
- $tr.toggleClass('marked');
- last_click_checked = false;
- }
- // remember the last clicked row
- last_clicked_row = last_click_checked ? $('tr.odd:not(.noclick), tr.even:not(.noclick)').index($tr) : -1;
- last_shift_clicked_row = -1;
- } else {
- // handle the shift click
- PMA_clearSelection();
- var start, end;
- // clear last shift click result
- if (last_shift_clicked_row >= 0) {
- if (last_shift_clicked_row >= last_clicked_row) {
- start = last_clicked_row;
- end = last_shift_clicked_row;
- } else {
- start = last_shift_clicked_row;
- end = last_clicked_row;
- }
- $tr.parent().find('tr.odd:not(.noclick), tr.even:not(.noclick)')
- .slice(start, end + 1)
- .removeClass('marked')
- .find(':checkbox')
- .prop('checked', false)
- .trigger('change');
- }
- // handle new shift click
- var curr_row = $('tr.odd:not(.noclick), tr.even:not(.noclick)').index($tr);
- if (curr_row >= last_clicked_row) {
- start = last_clicked_row;
- end = curr_row;
- } else {
- start = curr_row;
- end = last_clicked_row;
- }
- $tr.parent().find('tr.odd:not(.noclick), tr.even:not(.noclick)')
- .slice(start, end + 1)
- .addClass('marked')
- .find(':checkbox')
- .prop('checked', true)
- .trigger('change');
- // remember the last shift clicked row
- last_shift_clicked_row = curr_row;
- }
- });
- addDateTimePicker();
- /**
- * Add attribute to text boxes for iOS devices (based on bugID: 3508912)
- */
- if (navigator.userAgent.match(/(iphone|ipod|ipad)/i)) {
- $('input[type=text]').attr('autocapitalize', 'off').attr('autocorrect', 'off');
- }
- });
- /**
- * True if last click is to check a row.
- */
- var last_click_checked = false;
- /**
- * Zero-based index of last clicked row.
- * Used to handle the shift + click event in the code above.
- */
- var last_clicked_row = -1;
- /**
- * Zero-based index of last shift clicked row.
- */
- var last_shift_clicked_row = -1;
- /**
- * Row highlighting in horizontal mode (use "live"
- * so that it works also for pages reached via AJAX)
- */
- /*AJAX.registerOnload('functions.js', function () {
- $('tr.odd, tr.even').live('hover',function (event) {
- var $tr = $(this);
- $tr.toggleClass('hover',event.type=='mouseover');
- $tr.children().toggleClass('hover',event.type=='mouseover');
- });
- })*/
- /**
- * This array is used to remember mark status of rows in browse mode
- */
- var marked_row = [];
- /**
- * 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)
- {
- $("#" + container_id).find("input:checkbox:enabled").prop('checked', true)
- .trigger("change")
- .parents("tr").addClass("marked");
- 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)
- {
- $("#" + container_id).find("input:checkbox:enabled").prop('checked', false)
- .trigger("change")
- .parents("tr").removeClass("marked");
- return true;
- }
- /**
- * 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)
- {
- $("#" + container_id).find("input:checkbox").prop('checked', state);
- return true;
- } // end of the 'setCheckboxes()' function
- /**
- * Checks/unchecks all options of a <select> element
- *
- * @param string the form name
- * @param string the element name
- * @param boolean whether to check or to uncheck options
- *
- * @return boolean always true
- */
- function setSelectOptions(the_form, the_select, do_check)
- {
- $("form[name='" + the_form + "'] select[name='" + the_select + "']").find("option").prop('selected', do_check);
- return true;
- } // end of the 'setSelectOptions()' function
- /**
- * Sets current value for query box.
- */
- function setQuery(query)
- {
- if (codemirror_editor) {
- codemirror_editor.setValue(query);
- codemirror_editor.focus();
- } else {
- document.sqlform.sql_query.value = query;
- document.sqlform.sql_query.focus();
- }
- }
- /**
- * Create quick sql statements.
- *
- */
- function insertQuery(queryType)
- {
- if (queryType == "clear") {
- setQuery('');
- return;
- }
- var query = "";
- var myListBox = document.sqlform.dummy;
- var table = document.sqlform.table.value;
- if (myListBox.options.length > 0) {
- sql_box_locked = true;
- var chaineAj = "";
- var valDis = "";
- var editDis = "";
- var NbSelect = 0;
- for (var i = 0; i < myListBox.options.length; i++) {
- NbSelect++;
- if (NbSelect > 1) {
- chaineAj += ", ";
- valDis += ",";
- editDis += ",";
- }
- chaineAj += myListBox.options[i].value;
- valDis += "[value-" + NbSelect + "]";
- editDis += myListBox.options[i].value + "=[value-" + NbSelect + "]";
- }
- if (queryType == "selectall") {
- query = "SELECT * FROM `" + table + "` WHERE 1";
- } else if (queryType == "select") {
- query = "SELECT " + chaineAj + " FROM `" + table + "` WHERE 1";
- } else if (queryType == "insert") {
- query = "INSERT INTO `" + table + "`(" + chaineAj + ") VALUES (" + valDis + ")";
- } else if (queryType == "update") {
- query = "UPDATE `" + table + "` SET " + editDis + " WHERE 1";
- } else if (queryType == "delete") {
- query = "DELETE FROM `" + table + "` WHERE 1";
- }
- setQuery(query);
- sql_box_locked = false;
- }
- }
- /**
- * Inserts multiple fields.
- *
- */
- function insertValueQuery()
- {
- var myQuery = document.sqlform.sql_query;
- var myListBox = document.sqlform.dummy;
- if (myListBox.options.length > 0) {
- sql_box_locked = true;
- var chaineAj = "";
- var NbSelect = 0;
- for (var i = 0; i < myListBox.options.length; i++) {
- if (myListBox.options[i].selected) {
- NbSelect++;
- if (NbSelect > 1) {
- chaineAj += ", ";
- }
- chaineAj += myListBox.options[i].value;
- }
- }
- /* CodeMirror support */
- if (codemirror_editor) {
- codemirror_editor.replaceSelection(chaineAj);
- //IE support
- } else if (document.selection) {
- myQuery.focus();
- var sel = document.selection.createRange();
- sel.text = chaineAj;
- document.sqlform.insert.focus();
- }
- //MOZILLA/NETSCAPE support
- else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart == "0") {
- var startPos = document.sqlform.sql_query.selectionStart;
- var endPos = document.sqlform.sql_query.selectionEnd;
- var chaineSql = document.sqlform.sql_query.value;
- myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
- } else {
- myQuery.value += chaineAj;
- }
- sql_box_locked = false;
- }
- }
- /**
- * Add a date/time picker to each element that needs it
- * (only when jquery-ui-timepicker-addon.js is loaded)
- */
- function addDateTimePicker() {
- if ($.timepicker !== undefined) {
- $('input.datefield, input.datetimefield').each(function () {
- no_decimals = $(this).parent().data('decimals');
- var showMillisec = false;
- var showMicrosec = false;
- var timeFormat = 'HH:mm:ss';
- // check for decimal places of seconds
- if (($(this).parent().data('decimals') > 0) && ($(this).parent().data('type').indexOf('time') != -1)){
- showMillisec = true;
- timeFormat = 'HH:mm:ss.lc';
- if ($(this).parent().data('decimals') > 3) {
- showMicrosec = true;
- }
- }
- PMA_addDatepicker($(this), {
- showMillisec: showMillisec,
- showMicrosec: showMicrosec,
- timeFormat: timeFormat,
- });
- })
- }
- }
- /**
- * Refresh/resize the WYSIWYG scratchboard
- */
- function refreshLayout()
- {
- var $elm = $('#pdflayout');
- var orientation = $('#orientation_opt').val();
- var paper = 'A4';
- if ($('#paper_opt').length == 1) {
- paper = $('#paper_opt').val();
- }
- var posa = 'y';
- var posb = 'x';
- if (orientation == 'P') {
- posa = 'x';
- posb = 'y';
- }
- $elm.css('width', pdfPaperSize(paper, posa) + 'px');
- $elm.css('height', pdfPaperSize(paper, posb) + 'px');
- }
- /**
- * Initializes positions of elements.
- */
- function TableDragInit() {
- $('.pdflayout_table').each(function () {
- var $this = $(this);
- var number = $this.data('number');
- var x = $('#c_table_' + number + '_x').val();
- var y = $('#c_table_' + number + '_y').val();
- $this.css('left', x + 'px');
- $this.css('top', y + 'px');
- /* Make elements draggable */
- $this.draggable({
- containment: "parent",
- drag: function (evt, ui) {
- var number = $this.data('number');
- $('#c_table_' + number + '_x').val(parseInt(ui.position.left, 10));
- $('#c_table_' + number + '_y').val(parseInt(ui.position.top, 10));
- }
- });
- });
- }
- /**
- * Resets drag and drop positions.
- */
- function resetDrag() {
- $('.pdflayout_table').each(function () {
- var $this = $(this);
- var x = $this.data('x');
- var y = $this.data('y');
- $this.css('left', x + 'px');
- $this.css('top', y + 'px');
- });
- }
- /**
- * User schema handlers.
- */
- $(function () {
- /* Move in scratchboard on manual change */
- $('.position-change').live('change', function () {
- var $this = $(this);
- var $elm = $('#table_' + $this.data('number'));
- $elm.css($this.data('axis'), $this.val() + 'px');
- });
- /* Refresh on paper size/orientation change */
- $('.paper-change').live('change', function () {
- var $elm = $('#pdflayout');
- if ($elm.css('visibility') == 'visible') {
- refreshLayout();
- TableDragInit();
- }
- });
- /* Show/hide the WYSIWYG scratchboard */
- $('#toggle-dragdrop').live('click', function () {
- var $elm = $('#pdflayout');
- if ($elm.css('visibility') == 'hidden') {
- refreshLayout();
- TableDragInit();
- $elm.css('visibility', 'visible');
- $elm.css('display', 'block');
- $('#showwysiwyg').val('1');
- } else {
- $elm.css('visibility', 'hidden');
- $elm.css('display', 'none');
- $('#showwysiwyg').val('0');
- }
- });
- /* Reset scratchboard */
- $('#reset-dragdrop').live('click', function () {
- resetDrag();
- });
- });
- /**
- * Returns paper sizes for a given format
- */
- function pdfPaperSize(format, axis)
- {
- switch (format.toUpperCase()) {
- case '4A0':
- if (axis == 'x') {
- return 4767.87;
- } else {
- return 6740.79;
- }
- break;
- case '2A0':
- if (axis == 'x') {
- return 3370.39;
- } else {
- return 4767.87;
- }
- break;
- case 'A0':
- if (axis == 'x') {
- return 2383.94;
- } else {
- return 3370.39;
- }
- break;
- case 'A1':
- if (axis == 'x') {
- return 1683.78;
- } else {
- return 2383.94;
- }
- break;
- case 'A2':
- if (axis == 'x') {
- return 1190.55;
- } else {
- return 1683.78;
- }
- break;
- case 'A3':
- if (axis == 'x') {
- return 841.89;
- } else {
- return 1190.55;
- }
- break;
- case 'A4':
- if (axis == 'x') {
- return 595.28;
- } else {
- return 841.89;
- }
- break;
- case 'A5':
- if (axis == 'x') {
- return 419.53;
- } else {
- return 595.28;
- }
- break;
- case 'A6':
- if (axis == 'x') {
- return 297.64;
- } else {
- return 419.53;
- }
- break;
- case 'A7':
- if (axis == 'x') {
- return 209.76;
- } else {
- return 297.64;
- }
- break;
- case 'A8':
- if (axis == 'x') {
- return 147.40;
- } else {
- return 209.76;
- }
- break;
- case 'A9':
- if (axis == 'x') {
- return 104.88;
- } else {
- return 147.40;
- }
- break;
- case 'A10':
- if (axis == 'x') {
- return 73.70;
- } else {
- return 104.88;
- }
- break;
- case 'B0':
- if (axis == 'x') {
- return 2834.65;
- } else {
- return 4008.19;
- }
- break;
- case 'B1':
- if (axis == 'x') {
- return 2004.09;
- } else {
- return 2834.65;
- }
- break;
- case 'B2':
- if (axis == 'x') {
- return 1417.32;
- } else {
- return 2004.09;
- }
- break;
- case 'B3':
- if (axis == 'x') {
- return 1000.63;
- } else {
- return 1417.32;
- }
- break;
- case 'B4':
- if (axis == 'x') {
- return 708.66;
- } else {
- return 1000.63;
- }
- break;
- case 'B5':
- if (axis == 'x') {
- return 498.90;
- } else {
- return 708.66;
- }
- break;
- case 'B6':
- if (axis == 'x') {
- return 354.33;
- } else {
- return 498.90;
- }
- break;
- case 'B7':
- if (axis == 'x') {
- return 249.45;
- } else {
- return 354.33;
- }
- break;
- case 'B8':
- if (axis == 'x') {
- return 175.75;
- } else {
- return 249.45;
- }
- break;
- case 'B9':
- if (axis == 'x') {
- return 124.72;
- } else {
- return 175.75;
- }
- break;
- case 'B10':
- if (axis == 'x') {
- return 87.87;
- } else {
- return 124.72;
- }
- break;
- case 'C0':
- if (axis == 'x') {
- return 2599.37;
- } else {
- return 3676.54;
- }
- break;
- case 'C1':
- if (axis == 'x') {
- return 1836.85;
- } else {
- return 2599.37;
- }
- break;
- case 'C2':
- if (axis == 'x') {
- return 1298.27;
- } else {
- return 1836.85;
- }
- break;
- case 'C3':
- if (axis == 'x') {
- return 918.43;
- } else {
- return 1298.27;
- }
- break;
- case 'C4':
- if (axis == 'x') {
- return 649.13;
- } else {
- return 918.43;
- }
- break;
- case 'C5':
- if (axis == 'x') {
- return 459.21;
- } else {
- return 649.13;
- }
- break;
- case 'C6':
- if (axis == 'x') {
- return 323.15;
- } else {
- return 459.21;
- }
- break;
- case 'C7':
- if (axis == 'x') {
- return 229.61;
- } else {
- return 323.15;
- }
- break;
- case 'C8':
- if (axis == 'x') {
- return 161.57;
- } else {
- return 229.61;
- }
- break;
- case 'C9':
- if (axis == 'x') {
- return 113.39;
- } else {
- return 161.57;
- }
- break;
- case 'C10':
- if (axis == 'x') {
- return 79.37;
- } else {
- return 113.39;
- }
- break;
- case 'RA0':
- if (axis == 'x') {
- return 2437.80;
- } else {
- return 3458.27;
- }
- break;
- case 'RA1':
- if (axis == 'x') {
- return 1729.13;
- } else {
- return 2437.80;
- }
- break;
- case 'RA2':
- if (axis == 'x') {
- return 1218.90;
- } else {
- return 1729.13;
- }
- break;
- case 'RA3':
- if (axis == 'x') {
- return 864.57;
- } else {
- return 1218.90;
- }
- break;
- case 'RA4':
- if (axis == 'x') {
- return 609.45;
- } else {
- return 864.57;
- }
- break;
- case 'SRA0':
- if (axis == 'x') {
- return 2551.18;
- } else {
- return 3628.35;
- }
- break;
- case 'SRA1':
- if (axis == 'x') {
- return 1814.17;
- } else {
- return 2551.18;
- }
- break;
- case 'SRA2':
- if (axis == 'x') {
- return 1275.59;
- } else {
- return 1814.17;
- }
- break;
- case 'SRA3':
- if (axis == 'x') {
- return 907.09;
- } else {
- return 1275.59;
- }
- break;
- case 'SRA4':
- if (axis == 'x') {
- return 637.80;
- } else {
- return 907.09;
- }
- break;
- case 'LETTER':
- if (axis == 'x') {
- return 612.00;
- } else {
- return 792.00;
- }
- break;
- case 'LEGAL':
- if (axis == 'x') {
- return 612.00;
- } else {
- return 1008.00;
- }
- break;
- case 'EXECUTIVE':
- if (axis == 'x') {
- return 521.86;
- } else {
- return 756.00;
- }
- break;
- case 'FOLIO':
- if (axis == 'x') {
- return 612.00;
- } else {
- return 936.00;
- }
- break;
- } // end switch
- return 0;
- }
- /**
- * Unbind all event handlers before tearing down a page
- */
- AJAX.registerTeardown('functions.js', function () {
- $("a.inline_edit_sql").die('click');
- $("input#sql_query_edit_save").die('click');
- $("input#sql_query_edit_discard").die('click');
- $('input.sqlbutton').unbind('click');
- $("#export_type").unbind('change');
- $('#sqlquery').unbind('keydown');
- $('#sql_query_edit').unbind('keydown');
- if (codemirror_inline_editor) {
- // Copy the sql query to the text area to preserve it.
- $('#sql_query_edit').text(codemirror_inline_editor.getValue());
- $(codemirror_inline_editor.getWrapperElement()).unbind('keydown');
- codemirror_inline_editor.toTextArea();
- codemirror_inline_editor = false;
- }
- if (codemirror_editor) {
- $(codemirror_editor.getWrapperElement()).unbind('keydown');
- }
- });
- /**
- * Jquery Coding for inline editing SQL_QUERY
- */
- AJAX.registerOnload('functions.js', function () {
- // If we are coming back to the page by clicking forward button
- // of the browser, bind the code mirror to inline query editor.
- bindCodeMirrorToInlineEditor();
- $("a.inline_edit_sql").live('click', function () {
- if ($('#sql_query_edit').length) {
- // An inline query editor is already open,
- // we don't want another copy of it
- return false;
- }
- var $form = $(this).prev('form');
- var sql_query = $form.find("input[name='sql_query']").val();
- var $inner_sql = $(this).parent().prev().find('code.sql');
- var old_text = $inner_sql.html();
- var new_content = "<textarea name=\"sql_query_edit\" id=\"sql_query_edit\">" + sql_query + "</textarea>\n";
- new_content += "<input type=\"submit\" id=\"sql_query_edit_save\" class=\"button btnSave\" value=\"" + PMA_messages.strGo + "\"/>\n";
- new_content += "<input type=\"button\" id=\"sql_query_edit_discard\" class=\"button btnDiscard\" value=\"" + PMA_messages.strCancel + "\"/>\n";
- var $editor_area = $('div#inline_editor');
- if ($editor_area.length === 0) {
- $editor_area = $('<div id="inline_editor_outer"></div>');
- $editor_area.insertBefore($inner_sql);
- }
- $editor_area.html(new_content);
- $inner_sql.hide();
- bindCodeMirrorToInlineEditor();
- return false;
- });
- $("input#sql_query_edit_save").live('click', function () {
- $(".success").hide();
- //hide already existing success message
- var sql_query;
- if (codemirror_inline_editor) {
- codemirror_inline_editor.save();
- sql_query = codemirror_inline_editor.getValue();
- } else {
- sql_query = $(this).prev().val();
- }
- var $form = $("a.inline_edit_sql").prev('form');
- var $fake_form = $('<form>', {action: 'import.php', method: 'post'})
- .append($form.find("input[name=server], input[name=db], input[name=table], input[name=token]").clone())
- .append($('<input/>', {type: 'hidden', name: 'show_query', value: 1}))
- .append($('<input/>', {type: 'hidden', name: 'is_js_confirmed', value: 0}))
- .append($('<input/>', {type: 'hidden', name: 'sql_query', value: sql_query}));
- if (! checkSqlQuery($fake_form[0])) {
- return false;
- }
- $fake_form.appendTo($('body')).submit();
- });
- $("input#sql_query_edit_discard").live('click', function () {
- $('div#inline_editor_outer').siblings('code.sql').show();
- $('div#inline_editor_outer').remove();
- });
- $('input.sqlbutton').click(function (evt) {
- insertQuery(evt.target.id);
- return false;
- });
- $("#export_type").change(function () {
- if ($("#export_type").val() == 'svg') {
- $("#show_grid_opt").prop("disabled", true);
- $("#orientation_opt").prop("disabled", true);
- $("#with_doc").prop("disabled", true);
- $("#show_table_dim_opt").removeProp("disabled");
- $("#all_tables_same_width").removeProp("disabled");
- $("#paper_opt").removeProp("disabled");
- $("#show_color_opt").removeProp("disabled");
- //$(this).css("background-color","yellow");
- } else if ($("#export_type").val() == 'dia') {
- $("#show_grid_opt").prop("disabled", true);
- $("#with_doc").prop("disabled", true);
- $("#show_table_dim_opt").prop("disabled", true);
- $("#all_tables_same_width").prop("disabled", true);
- $("#paper_opt").removeProp("disabled");
- $("#show_color_opt").removeProp("disabled");
- $("#orientation_opt").removeProp("disabled");
- } else if ($("#export_type").val() == 'eps') {
- $("#show_grid_opt").prop("disabled", true);
- $("#orientation_opt").removeProp("disabled");
- $("#with_doc").prop("disabled", true);
- $("#show_table_dim_opt").prop("disabled", true);
- $("#all_tables_same_width").prop("disabled", true);
- $("#paper_opt").prop("disabled", true);
- $("#show_color_opt").prop("disabled", true);
- } else if ($("#export_type").val() == 'pdf') {
- $("#show_grid_opt").removeProp("disabled");
- $("#orientation_opt").removeProp("disabled");
- $("#with_doc").removeProp("disabled");
- $("#show_table_dim_opt").removeProp("disabled");
- $("#all_tables_same_width").removeProp("disabled");
- $("#paper_opt").removeProp("disabled");
- $("#show_color_opt").removeProp("disabled");
- } else {
- // nothing
- }
- });
- if ($('#input_username')) {
- if ($('#input_username').val() === '') {
- $('#input_username').focus();
- } else {
- $('#input_password').focus();
- }
- }
- });
- /**
- * Binds the CodeMirror to the text area used to inline edit a query.
- */
- function bindCodeMirrorToInlineEditor() {
- var $inline_editor = $('#sql_query_edit');
- if ($inline_editor.length > 0) {
- if (typeof CodeMirror !== 'undefined') {
- var height = $('#sql_query_edit').css('height');
- codemirror_inline_editor = CodeMirror.fromTextArea($inline_editor[0], {
- lineNumbers: true,
- matchBrackets: true,
- indentUnit: 4,
- mode: "text/x-mysql",
- lineWrapping: true
- });
- codemirror_inline_editor.getScrollerElement().style.height = height;
- codemirror_inline_editor.refresh();
- codemirror_inline_editor.focus();
- $(codemirror_inline_editor.getWrapperElement()).bind(
- 'keydown',
- catchKeypressesFromSqlTextboxes
- );
- } else {
- $inline_editor.focus().bind(
- 'keydown',
- catchKeypressesFromSqlTextboxes
- );
- }
- }
- }
- function catchKeypressesFromSqlTextboxes(event) {
- // ctrl-enter is 10 in chrome and ie, but 13 in ff
- if (event.ctrlKey && (event.keyCode == 13 || event.keyCode == 10)) {
- if ($('#sql_query_edit').length > 0) {
- $("#sql_query_edit_save").trigger('click');
- } else if ($('#sqlquery').length > 0) {
- $("#button_submit_query").trigger('click');
- }
- }
- }
- /**
- * Adds doc link to single highlighted SQL element
- */
- function PMA_doc_add($elm, params)
- {
- var url = $.sprintf(
- mysql_doc_template,
- params[0]
- );
- if (params.length > 1) {
- url += '#' + params[1];
- }
- var content = $elm.text();
- $elm.text('');
- $elm.append('<a target="mysql_doc" class="cm-sql-doc" href="' + url + '">' + content + '</a>');
- }
- /**
- * Generates doc links for keywords inside highlighted SQL
- */
- function PMA_doc_keyword(idx, elm)
- {
- var $elm = $(elm);
- /* Skip already processed ones */
- if ($elm.find('a').length > 0) {
- return;
- }
- var keyword = $elm.text().toUpperCase();
- var $next = $elm.next('.cm-keyword');
- if ($next) {
- var next_keyword = $next.text().toUpperCase();
- var full = keyword + ' ' + next_keyword;
- var $next2 = $next.next('.cm-keyword');
- if ($next2) {
- var next2_keyword = $next2.text().toUpperCase();
- var full2 = full + ' ' + next2_keyword;
- if (full2 in mysql_doc_keyword) {
- PMA_doc_add($elm, mysql_doc_keyword[full2]);
- PMA_doc_add($next, mysql_doc_keyword[full2]);
- PMA_doc_add($next2, mysql_doc_keyword[full2]);
- return;
- }
- }
- if (full in mysql_doc_keyword) {
- PMA_doc_add($elm, mysql_doc_keyword[full]);
- PMA_doc_add($next, mysql_doc_keyword[full]);
- return;
- }
- }
- if (keyword in mysql_doc_keyword) {
- PMA_doc_add($elm, mysql_doc_keyword[keyword]);
- }
- }
- /**
- * Generates doc links for builtins inside highlighted SQL
- */
- function PMA_doc_builtin(idx, elm)
- {
- var $elm = $(elm);
- var builtin = $elm.text().toUpperCase();
- if (builtin in mysql_doc_builtin) {
- PMA_doc_add($elm, mysql_doc_builtin[builtin]);
- }
- }
- /**
- * Higlights SQL using CodeMirror.
- */
- function PMA_highlightSQL(base)
- {
- var $elm = base.find('code.sql');
- $elm.each(function () {
- var $sql = $(this);
- var $pre = $sql.find('pre');
- /* We only care about visible elements to avoid double processing */
- if ($pre.is(":visible")) {
- var $highlight = $('<div class="sql-highlight cm-s-default"></div>');
- $sql.append($highlight);
- if (typeof CodeMirror != 'undefined') {
- CodeMirror.runMode($sql.text(), 'text/x-mysql', $highlight[0]);
- $pre.hide();
- $highlight.find('.cm-keyword').each(PMA_doc_keyword);
- $highlight.find('.cm-builtin').each(PMA_doc_builtin);
- }
- }
- });
- }
- /**
- * Show a message on the top of the page for an Ajax request
- *
- * Sample usage:
- *
- * 1) var $msg = PMA_ajaxShowMessage();
- * This will show a message that reads "Loading...". Such a message will not
- * disappear automatically and cannot be dismissed by the user. To remove this
- * message either the PMA_ajaxRemoveMessage($msg) function must be called or
- * another message must be show with PMA_ajaxShowMessage() function.
- *
- * 2) var $msg = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
- * This is a special case. The behaviour is same as above,
- * just with a different message
- *
- * 3) var $msg = PMA_ajaxShowMessage('The operation was successful');
- * This will show a message that will disappear automatically and it can also
- * be dismissed by the user.
- *
- * 4) var $msg = PMA_ajaxShowMessage('Some error', false);
- * This will show a message that will not disappear automatically, but it
- * can be dismissed by the user after he has finished reading it.
- *
- * @param string message string containing the message to be shown.
- * optional, defaults to 'Loading...'
- * @param mixed timeout numb…
Large files files are truncated, but you can click here to view the full file