2016-10-22 14:57:10 +00:00
|
|
|
/* vim: set expandtab sw=4 ts=4 sts=4: */
|
|
|
|
/**
|
|
|
|
* general function, usually for data manipulation pages
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var sql_box_locked lock for the sqlbox textarea in the querybox
|
|
|
|
*/
|
|
|
|
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 sql_autocomplete_in_progress bool shows if Table/Column name autocomplete AJAX is in progress
|
|
|
|
*/
|
|
|
|
var sql_autocomplete_in_progress = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var sql_autocomplete object containing list of columns in each table
|
|
|
|
*/
|
|
|
|
var sql_autocomplete = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var sql_autocomplete_default_table string containing default table to autocomplete columns
|
|
|
|
*/
|
|
|
|
var sql_autocomplete_default_table = '';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var central_column_list array to hold the columns in central list per db.
|
|
|
|
*/
|
|
|
|
var central_column_list = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var primary_indexes array to hold 'Primary' index columns.
|
|
|
|
*/
|
|
|
|
var primary_indexes = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var unique_indexes array to hold 'Unique' index columns.
|
|
|
|
*/
|
|
|
|
var unique_indexes = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var indexes array to hold 'Index' columns.
|
|
|
|
*/
|
|
|
|
var indexes = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var fulltext_indexes array to hold 'Fulltext' columns.
|
|
|
|
*/
|
|
|
|
var fulltext_indexes = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var spatial_indexes array to hold 'Spatial' columns.
|
|
|
|
*/
|
|
|
|
var spatial_indexes = [];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make sure that ajax requests will not be cached
|
|
|
|
* by appending a random variable to their parameters
|
|
|
|
*/
|
|
|
|
$.ajaxPrefilter(function (options, originalOptions, jqXHR) {
|
2018-04-14 09:18:00 +00:00
|
|
|
var nocache = new Date().getTime() + '' + Math.floor(Math.random() * 1000000);
|
|
|
|
if (typeof options.data === 'string') {
|
|
|
|
options.data += '&_nocache=' + nocache + '&token=' + encodeURIComponent(PMA_commonParams.get('token'));
|
|
|
|
} else if (typeof options.data === 'object') {
|
|
|
|
options.data = $.extend(originalOptions.data, { '_nocache' : nocache, 'token': PMA_commonParams.get('token') });
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Adds a date/time picker to an element
|
|
|
|
*
|
|
|
|
* @param object $this_element a jQuery object pointing to the element
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_addDatepicker ($this_element, type, options) {
|
2016-10-22 14:57:10 +00:00
|
|
|
var showTimepicker = true;
|
2018-04-14 09:18:00 +00:00
|
|
|
if (type === 'date') {
|
2016-10-22 14:57:10 +00:00
|
|
|
showTimepicker = false;
|
|
|
|
}
|
|
|
|
|
2019-12-28 19:55:21 +00:00
|
|
|
// Getting the current Date and time
|
|
|
|
var currentDateTime = new Date();
|
|
|
|
|
2016-10-22 14:57:10 +00:00
|
|
|
var defaultOptions = {
|
2019-12-28 19:55:21 +00:00
|
|
|
timeInput : true,
|
|
|
|
hour: currentDateTime.getHours(),
|
|
|
|
minute: currentDateTime.getMinutes(),
|
|
|
|
second: currentDateTime.getSeconds(),
|
2016-10-22 14:57:10 +00:00
|
|
|
showOn: 'button',
|
|
|
|
buttonImage: themeCalendarImage, // defined in js/messages.php
|
|
|
|
buttonImageOnly: true,
|
|
|
|
stepMinutes: 1,
|
|
|
|
stepHours: 1,
|
|
|
|
showSecond: true,
|
|
|
|
showMillisec: true,
|
|
|
|
showMicrosec: true,
|
|
|
|
showTimepicker: showTimepicker,
|
|
|
|
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');
|
|
|
|
if ($(input).closest('.cEdit').length > 0) {
|
|
|
|
setTimeout(function () {
|
|
|
|
inst.dpDiv.css({
|
|
|
|
top: 0,
|
|
|
|
left: 0,
|
|
|
|
position: 'relative'
|
|
|
|
});
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
setTimeout(function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
// Fix wrong timepicker z-index, doesn't work without timeout
|
2016-10-22 14:57:10 +00:00
|
|
|
$('#ui-timepicker-div').css('z-index', $('#ui-datepicker-div').css('z-index'));
|
2018-04-14 09:18:00 +00:00
|
|
|
// Integrate tooltip text into dialog
|
|
|
|
var tooltip = $this_element.tooltip('instance');
|
|
|
|
if (typeof tooltip !== 'undefined') {
|
|
|
|
tooltip.disable();
|
|
|
|
var $note = $('<p class="note"></div>');
|
|
|
|
$note.text(tooltip.option('content'));
|
|
|
|
$('div.ui-datepicker').append($note);
|
|
|
|
}
|
2016-10-22 14:57:10 +00:00
|
|
|
}, 0);
|
|
|
|
},
|
2018-04-14 09:18:00 +00:00
|
|
|
onSelect: function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
$this_element.data('datepicker').inline = true;
|
|
|
|
},
|
|
|
|
onClose: function (dateText, dp_inst) {
|
|
|
|
// The value is no more from the date picker
|
|
|
|
$this_element.data('comes_from', '');
|
|
|
|
if (typeof $this_element.data('datepicker') !== 'undefined') {
|
|
|
|
$this_element.data('datepicker').inline = false;
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
var tooltip = $this_element.tooltip('instance');
|
|
|
|
if (typeof tooltip !== 'undefined') {
|
|
|
|
tooltip.enable();
|
|
|
|
}
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
};
|
2018-12-16 14:31:03 +00:00
|
|
|
if (type == 'time') {
|
2016-10-22 14:57:10 +00:00
|
|
|
$this_element.timepicker($.extend(defaultOptions, options));
|
2017-04-20 10:55:30 +00:00
|
|
|
// Add a tip regarding entering MySQL allowed-values for TIME data-type
|
2018-04-14 09:18:00 +00:00
|
|
|
PMA_tooltip($this_element, 'input', PMA_messages.strMysqlAllowedValuesTipTime);
|
|
|
|
} else {
|
|
|
|
$this_element.datetimepicker($.extend(defaultOptions, options));
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a date/time picker to each element that needs it
|
|
|
|
* (only when jquery-ui-timepicker-addon.js is loaded)
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function addDateTimePicker () {
|
2016-10-22 14:57:10 +00:00
|
|
|
if ($.timepicker !== undefined) {
|
|
|
|
$('input.timefield, input.datefield, input.datetimefield').each(function () {
|
|
|
|
var decimals = $(this).parent().attr('data-decimals');
|
|
|
|
var type = $(this).parent().attr('data-type');
|
|
|
|
|
|
|
|
var showMillisec = false;
|
|
|
|
var showMicrosec = false;
|
|
|
|
var timeFormat = 'HH:mm:ss';
|
2018-04-14 09:18:00 +00:00
|
|
|
var hourMax = 23;
|
2016-10-22 14:57:10 +00:00
|
|
|
// check for decimal places of seconds
|
2018-04-14 09:18:00 +00:00
|
|
|
if (decimals > 0 && type.indexOf('time') !== -1) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (decimals > 3) {
|
|
|
|
showMillisec = true;
|
|
|
|
showMicrosec = true;
|
|
|
|
timeFormat = 'HH:mm:ss.lc';
|
|
|
|
} else {
|
|
|
|
showMillisec = true;
|
|
|
|
timeFormat = 'HH:mm:ss.l';
|
|
|
|
}
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
if (type === 'time') {
|
|
|
|
hourMax = 99;
|
|
|
|
}
|
2016-10-22 14:57:10 +00:00
|
|
|
PMA_addDatepicker($(this), type, {
|
|
|
|
showMillisec: showMillisec,
|
|
|
|
showMicrosec: showMicrosec,
|
2018-04-14 09:18:00 +00:00
|
|
|
timeFormat: timeFormat,
|
|
|
|
hourMax: hourMax
|
2016-10-22 14:57:10 +00:00
|
|
|
});
|
2017-04-20 10:55:30 +00:00
|
|
|
// Add a tip regarding entering MySQL allowed-values
|
|
|
|
// for TIME and DATE data-type
|
|
|
|
if ($(this).hasClass('timefield')) {
|
|
|
|
PMA_tooltip($(this), 'input', PMA_messages.strMysqlAllowedValuesTipTime);
|
|
|
|
} else if ($(this).hasClass('datefield')) {
|
|
|
|
PMA_tooltip($(this), 'input', PMA_messages.strMysqlAllowedValuesTipDate);
|
|
|
|
}
|
2016-10-22 14:57:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle redirect and reload flags sent as part of AJAX requests
|
|
|
|
*
|
|
|
|
* @param data ajax response data
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_handleRedirectAndReload (data) {
|
|
|
|
if (parseInt(data.redirect_flag) === 1) {
|
2016-10-22 14:57:10 +00:00
|
|
|
// add one more GET param to display session expiry msg
|
|
|
|
if (window.location.href.indexOf('?') === -1) {
|
|
|
|
window.location.href += '?session_expired=1';
|
|
|
|
} else {
|
2018-04-14 09:18:00 +00:00
|
|
|
window.location.href += PMA_commonParams.get('arg_separator') + 'session_expired=1';
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
window.location.reload();
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (parseInt(data.reload_flag) === 1) {
|
2016-10-22 14:57:10 +00:00
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an SQL editor which supports auto completing etc.
|
|
|
|
*
|
|
|
|
* @param $textarea jQuery object wrapping the textarea to be made the editor
|
|
|
|
* @param options optional options for CodeMirror
|
|
|
|
* @param resize optional resizing ('vertical', 'horizontal', 'both')
|
|
|
|
* @param lintOptions additional options for lint
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_getSQLEditor ($textarea, options, resize, lintOptions) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if ($textarea.length > 0 && typeof CodeMirror !== 'undefined') {
|
|
|
|
// merge options for CodeMirror
|
|
|
|
var defaults = {
|
|
|
|
lineNumbers: true,
|
|
|
|
matchBrackets: true,
|
2018-04-14 09:18:00 +00:00
|
|
|
extraKeys: { 'Ctrl-Space': 'autocomplete' },
|
|
|
|
hintOptions: { 'completeSingle': false, 'completeOnSingleClick': true },
|
2016-10-22 14:57:10 +00:00
|
|
|
indentUnit: 4,
|
2018-04-14 09:18:00 +00:00
|
|
|
mode: 'text/x-mysql',
|
2016-10-22 14:57:10 +00:00
|
|
|
lineWrapping: true
|
|
|
|
};
|
|
|
|
|
|
|
|
if (CodeMirror.sqlLint) {
|
|
|
|
$.extend(defaults, {
|
2018-04-14 09:18:00 +00:00
|
|
|
gutters: ['CodeMirror-lint-markers'],
|
2016-10-22 14:57:10 +00:00
|
|
|
lint: {
|
2018-04-14 09:18:00 +00:00
|
|
|
'getAnnotations': CodeMirror.sqlLint,
|
|
|
|
'async': true,
|
|
|
|
'lintOptions': lintOptions
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$.extend(true, defaults, options);
|
|
|
|
|
|
|
|
// create CodeMirror editor
|
|
|
|
var codemirrorEditor = CodeMirror.fromTextArea($textarea[0], defaults);
|
|
|
|
// allow resizing
|
|
|
|
if (! resize) {
|
|
|
|
resize = 'vertical';
|
|
|
|
}
|
|
|
|
var handles = '';
|
2018-04-14 09:18:00 +00:00
|
|
|
if (resize === 'vertical') {
|
2016-10-22 14:57:10 +00:00
|
|
|
handles = 's';
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
if (resize === 'both') {
|
2016-10-22 14:57:10 +00:00
|
|
|
handles = 'all';
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
if (resize === 'horizontal') {
|
2016-10-22 14:57:10 +00:00
|
|
|
handles = 'e, w';
|
|
|
|
}
|
|
|
|
$(codemirrorEditor.getWrapperElement())
|
|
|
|
.css('resize', resize)
|
|
|
|
.resizable({
|
|
|
|
handles: handles,
|
2018-04-14 09:18:00 +00:00
|
|
|
resize: function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
codemirrorEditor.setSize($(this).width(), $(this).height());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// enable autocomplete
|
2018-04-14 09:18:00 +00:00
|
|
|
codemirrorEditor.on('inputRead', codemirrorAutocompleteOnInputRead);
|
|
|
|
|
|
|
|
// page locking
|
|
|
|
codemirrorEditor.on('change', function (e) {
|
|
|
|
e.data = {
|
|
|
|
value: 3,
|
|
|
|
content: codemirrorEditor.isClean(),
|
|
|
|
};
|
|
|
|
AJAX.lockPageHandler(e);
|
|
|
|
});
|
2016-10-22 14:57:10 +00:00
|
|
|
|
|
|
|
return codemirrorEditor;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear text selection
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_clearSelection () {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (document.selection && document.selection.empty) {
|
|
|
|
document.selection.empty();
|
|
|
|
} else if (window.getSelection) {
|
|
|
|
var sel = window.getSelection();
|
|
|
|
if (sel.empty) {
|
|
|
|
sel.empty();
|
|
|
|
}
|
|
|
|
if (sel.removeAllRanges) {
|
|
|
|
sel.removeAllRanges();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a jQuery UI tooltip
|
|
|
|
*
|
|
|
|
* @param $elements jQuery object representing the elements
|
|
|
|
* @param item the item
|
2017-04-20 10:55:30 +00:00
|
|
|
* (see https://api.jqueryui.com/tooltip/#option-items)
|
2016-10-22 14:57:10 +00:00
|
|
|
* @param myContent content of the tooltip
|
|
|
|
* @param additionalOptions to override the default options
|
|
|
|
*
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_tooltip ($elements, item, myContent, additionalOptions) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if ($('#no_hint').length > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var defaultOptions = {
|
|
|
|
content: myContent,
|
|
|
|
items: item,
|
2018-04-14 09:18:00 +00:00
|
|
|
tooltipClass: 'tooltip',
|
2016-10-22 14:57:10 +00:00
|
|
|
track: true,
|
|
|
|
show: false,
|
|
|
|
hide: false
|
|
|
|
};
|
|
|
|
|
|
|
|
$elements.tooltip($.extend(true, defaultOptions, additionalOptions));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* HTML escaping
|
|
|
|
*/
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
function escapeHtml (unsafe) {
|
|
|
|
if (typeof(unsafe) !== 'undefined') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return unsafe
|
|
|
|
.toString()
|
2018-04-14 09:18:00 +00:00
|
|
|
.replace(/&/g, '&')
|
|
|
|
.replace(/</g, '<')
|
|
|
|
.replace(/>/g, '>')
|
|
|
|
.replace(/"/g, '"')
|
|
|
|
.replace(/'/g, ''');
|
2016-10-22 14:57:10 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
function escapeJsString (unsafe) {
|
|
|
|
if (typeof(unsafe) !== 'undefined') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return unsafe
|
|
|
|
.toString()
|
2018-04-14 09:18:00 +00:00
|
|
|
.replace('\x00', '')
|
2016-10-22 14:57:10 +00:00
|
|
|
.replace('\\', '\\\\')
|
|
|
|
.replace('\'', '\\\'')
|
2018-04-14 09:18:00 +00:00
|
|
|
.replace(''', '\\\'')
|
2016-10-22 14:57:10 +00:00
|
|
|
.replace('"', '\"')
|
2018-04-14 09:18:00 +00:00
|
|
|
.replace('"', '\"')
|
|
|
|
.replace('\n', '\n')
|
|
|
|
.replace('\r', '\r')
|
|
|
|
.replace(/<\/script/gi, '</\' + \'script');
|
2016-10-22 14:57:10 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 14:31:03 +00:00
|
|
|
|
|
|
|
function escapeBacktick (s) {
|
|
|
|
return s.replace('`', '``');
|
|
|
|
}
|
|
|
|
|
|
|
|
function escapeSingleQuote (s) {
|
|
|
|
return s.replace('\\', '\\\\').replace('\'', '\\\'');
|
|
|
|
}
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_sprintf () {
|
2016-10-22 14:57:10 +00:00
|
|
|
return sprintf.apply(this, arguments);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides/shows the default value input field, depending on the default type
|
|
|
|
* Ticks the NULL checkbox if NULL is chosen as default value.
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_hideShowDefaultValue ($default_type) {
|
|
|
|
if ($default_type.val() === 'USER_DEFINED') {
|
2016-10-22 14:57:10 +00:00
|
|
|
$default_type.siblings('.default_value').show().focus();
|
|
|
|
} else {
|
|
|
|
$default_type.siblings('.default_value').hide();
|
2018-04-14 09:18:00 +00:00
|
|
|
if ($default_type.val() === 'NULL') {
|
2016-10-22 14:57:10 +00:00
|
|
|
var $null_checkbox = $default_type.closest('tr').find('.allow_null');
|
|
|
|
$null_checkbox.prop('checked', true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides/shows the input field for column expression based on whether
|
|
|
|
* VIRTUAL/PERSISTENT is selected
|
|
|
|
*
|
|
|
|
* @param $virtuality virtuality dropdown
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_hideShowExpression ($virtuality) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if ($virtuality.val() === '') {
|
|
|
|
$virtuality.siblings('.expression').hide();
|
|
|
|
} else {
|
|
|
|
$virtuality.siblings('.expression').show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show notices for ENUM columns; add/hide the default value
|
|
|
|
*
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_verifyColumnsProperties () {
|
|
|
|
$('select.column_type').each(function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
PMA_showNoticeForEnum($(this));
|
|
|
|
});
|
2018-04-14 09:18:00 +00:00
|
|
|
$('select.default_type').each(function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
PMA_hideShowDefaultValue($(this));
|
|
|
|
});
|
|
|
|
$('select.virtuality').each(function () {
|
|
|
|
PMA_hideShowExpression($(this));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 $form object the form
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_prepareForAjaxRequest ($form) {
|
2016-10-22 14:57:10 +00:00
|
|
|
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 passwd_form object the form that holds the password fields
|
|
|
|
*
|
|
|
|
* @return boolean always true
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function suggestPassword (passwd_form) {
|
2016-10-22 14:57:10 +00:00
|
|
|
// 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"
|
2018-04-14 09:18:00 +00:00
|
|
|
var pwchars = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWYXZ';
|
2016-10-22 14:57:10 +00:00
|
|
|
var passwordlength = 16; // do we want that to be dynamic? no, keep it simple :)
|
|
|
|
var passwd = passwd_form.generated_pw;
|
|
|
|
var randomWords = new Int32Array(passwordlength);
|
|
|
|
|
|
|
|
passwd.value = '';
|
|
|
|
|
|
|
|
// First we're going to try to use a built-in CSPRNG
|
|
|
|
if (window.crypto && window.crypto.getRandomValues) {
|
|
|
|
window.crypto.getRandomValues(randomWords);
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (window.msCrypto && window.msCrypto.getRandomValues) {
|
|
|
|
// Because of course IE calls it msCrypto instead of being standard
|
2016-10-22 14:57:10 +00:00
|
|
|
window.msCrypto.getRandomValues(randomWords);
|
|
|
|
} else {
|
|
|
|
// Fallback to Math.random
|
|
|
|
for (var i = 0; i < passwordlength; i++) {
|
|
|
|
randomWords[i] = Math.floor(Math.random() * pwchars.length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < passwordlength; i++) {
|
|
|
|
passwd.value += pwchars.charAt(Math.abs(randomWords[i]) % pwchars.length);
|
|
|
|
}
|
|
|
|
|
2017-04-20 10:55:30 +00:00
|
|
|
$jquery_passwd_form = $(passwd_form);
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
passwd_form.elements.pma_pw.value = passwd.value;
|
|
|
|
passwd_form.elements.pma_pw2.value = passwd.value;
|
2017-04-20 10:55:30 +00:00
|
|
|
meter_obj = $jquery_passwd_form.find('meter[name="pw_meter"]').first();
|
|
|
|
meter_obj_label = $jquery_passwd_form.find('span[name="pw_strength"]').first();
|
|
|
|
checkPasswordStrength(passwd.value, meter_obj, meter_obj_label);
|
2016-10-22 14:57:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Version string to integer conversion.
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function parseVersionString (str) {
|
|
|
|
if (typeof(str) !== 'string') {
|
|
|
|
return false;
|
|
|
|
}
|
2016-10-22 14:57:10 +00:00
|
|
|
var add = 0;
|
|
|
|
// Parse possible alpha/beta/rc/
|
|
|
|
var state = str.split('-');
|
|
|
|
if (state.length >= 2) {
|
2018-04-14 09:18:00 +00:00
|
|
|
if (state[1].substr(0, 2) === 'rc') {
|
2016-10-22 14:57:10 +00:00
|
|
|
add = - 20 - parseInt(state[1].substr(2), 10);
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (state[1].substr(0, 4) === 'beta') {
|
2016-10-22 14:57:10 +00:00
|
|
|
add = - 40 - parseInt(state[1].substr(4), 10);
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (state[1].substr(0, 5) === 'alpha') {
|
2016-10-22 14:57:10 +00:00
|
|
|
add = - 60 - parseInt(state[1].substr(5), 10);
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (state[1].substr(0, 3) === 'dev') {
|
2016-10-22 14:57:10 +00:00
|
|
|
/* 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.
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_current_version (data) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (data && data.version && data.date) {
|
|
|
|
var current = parseVersionString($('span.version').text());
|
|
|
|
var latest = parseVersionString(data.version);
|
2018-04-14 09:18:00 +00:00
|
|
|
var url = 'https://www.phpmyadmin.net/files/' + escapeHtml(encodeURIComponent(data.version)) + '/';
|
2017-04-20 10:55:30 +00:00
|
|
|
var version_information_message = document.createElement('span');
|
|
|
|
version_information_message.className = 'latest';
|
|
|
|
var version_information_message_link = document.createElement('a');
|
|
|
|
version_information_message_link.href = url;
|
|
|
|
version_information_message_link.className = 'disableAjax';
|
|
|
|
version_information_message_link_text = document.createTextNode(data.version);
|
|
|
|
version_information_message_link.appendChild(version_information_message_link_text);
|
|
|
|
var prefix_message = document.createTextNode(PMA_messages.strLatestAvailable + ' ');
|
|
|
|
version_information_message.appendChild(prefix_message);
|
|
|
|
version_information_message.appendChild(version_information_message_link);
|
2016-10-22 14:57:10 +00:00
|
|
|
if (latest > current) {
|
|
|
|
var message = PMA_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';
|
|
|
|
}
|
|
|
|
$('#newer_version_notice').remove();
|
2017-04-20 10:55:30 +00:00
|
|
|
var maincontainer_div = document.createElement('div');
|
|
|
|
maincontainer_div.id = 'newer_version_notice';
|
|
|
|
maincontainer_div.className = htmlClass;
|
|
|
|
var maincontainer_div_link = document.createElement('a');
|
|
|
|
maincontainer_div_link.href = url;
|
|
|
|
maincontainer_div_link.className = 'disableAjax';
|
|
|
|
maincontainer_div_link_text = document.createTextNode(message);
|
|
|
|
maincontainer_div_link.appendChild(maincontainer_div_link_text);
|
|
|
|
maincontainer_div.appendChild(maincontainer_div_link);
|
|
|
|
$('#maincontainer').append($(maincontainer_div));
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
if (latest === current) {
|
2017-04-20 10:55:30 +00:00
|
|
|
version_information_message = document.createTextNode(' (' + PMA_messages.strUpToDate + ')');
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
2017-04-20 10:55:30 +00:00
|
|
|
/* Remove extra whitespace */
|
|
|
|
var version_info = $('#li_pma_version').contents().get(2);
|
2019-12-08 07:14:01 +00:00
|
|
|
if (typeof version_info !== 'undefined') {
|
|
|
|
version_info.textContent = $.trim(version_info.textContent);
|
|
|
|
}
|
2016-10-22 14:57:10 +00:00
|
|
|
var $liPmaVersion = $('#li_pma_version');
|
|
|
|
$liPmaVersion.find('span.latest').remove();
|
2017-04-20 10:55:30 +00:00
|
|
|
$liPmaVersion.append($(version_information_message));
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads Git revision data from ajax for index.php
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_display_git_revision () {
|
2016-10-22 14:57:10 +00:00
|
|
|
$('#is_git_revision').remove();
|
|
|
|
$('#li_pma_version_git').remove();
|
|
|
|
$.get(
|
2018-04-14 09:18:00 +00:00
|
|
|
'index.php',
|
2016-10-22 14:57:10 +00:00
|
|
|
{
|
2018-04-14 09:18:00 +00:00
|
|
|
'server': PMA_commonParams.get('server'),
|
|
|
|
'git_revision': true,
|
|
|
|
'ajax_request': true,
|
|
|
|
'no_debug': true
|
2016-10-22 14:57:10 +00:00
|
|
|
},
|
|
|
|
function (data) {
|
|
|
|
if (typeof data !== 'undefined' && data.success === true) {
|
|
|
|
$(data.message).insertAfter('#li_pma_version');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-04-14 09:18:00 +00:00
|
|
|
* for PhpMyAdmin\Display\ChangePassword
|
2016-10-22 14:57:10 +00:00
|
|
|
* libraries/user_password.php
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
function displayPasswordGenerateButton () {
|
|
|
|
var generatePwdRow = $('<tr />').addClass('vmiddle');
|
|
|
|
var titleCell = $('<td />').html(PMA_messages.strGeneratePassword).appendTo(generatePwdRow);
|
|
|
|
var pwdCell = $('<td />').appendTo(generatePwdRow);
|
|
|
|
var pwdButton = $('<input />')
|
|
|
|
.attr({ type: 'button', id: 'button_generate_password', value: PMA_messages.strGenerate })
|
|
|
|
.addClass('button')
|
|
|
|
.on('click', function () {
|
|
|
|
suggestPassword(this.form);
|
|
|
|
});
|
|
|
|
var pwdTextbox = $('<input />')
|
|
|
|
.attr({ type: 'text', name: 'generated_pw', id: 'generated_pw' });
|
|
|
|
pwdCell.append(pwdButton).append(pwdTextbox);
|
|
|
|
|
2019-12-08 07:14:01 +00:00
|
|
|
if (document.getElementById('button_generate_password') === null) {
|
|
|
|
$('#tr_element_before_generate_password').parent().append(generatePwdRow);
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
|
|
|
|
var generatePwdDiv = $('<div />').addClass('item');
|
|
|
|
var titleLabel = $('<label />').attr({ for: 'button_generate_password' })
|
|
|
|
.html(PMA_messages.strGeneratePassword + ':')
|
|
|
|
.appendTo(generatePwdDiv);
|
|
|
|
var optionsSpan = $('<span/>').addClass('options')
|
|
|
|
.appendTo(generatePwdDiv);
|
|
|
|
pwdButton.clone(true).appendTo(optionsSpan);
|
|
|
|
pwdTextbox.clone(true).appendTo(generatePwdDiv);
|
|
|
|
|
2019-12-08 07:14:01 +00:00
|
|
|
if (document.getElementById('button_generate_password') === null) {
|
|
|
|
$('#div_element_before_generate_password').parent().append(generatePwdDiv);
|
|
|
|
}
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* selects the content of a given object, f.e. a textarea
|
|
|
|
*
|
|
|
|
* @param element object element of which the content will be selected
|
|
|
|
* @param lock var variable which holds the lock for this element
|
|
|
|
* or true, if no lock exists
|
|
|
|
* @param only_once boolean if true this is only done once
|
|
|
|
* f.e. only on first focus
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function selectContent (element, lock, only_once) {
|
2016-10-22 14:57:10 +00:00
|
|
|
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 theLink object the link
|
|
|
|
* @param theSqlQuery object the sql query to submit
|
|
|
|
*
|
|
|
|
* @return boolean whether to run the query or not
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function confirmLink (theLink, theSqlQuery) {
|
2016-10-22 14:57:10 +00:00
|
|
|
// Confirmation is not required in the configuration file
|
|
|
|
// or browser is Opera (crappy js implementation)
|
2018-04-14 09:18:00 +00:00
|
|
|
if (PMA_messages.strDoYouReally === '' || typeof(window.opera) !== 'undefined') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
var is_confirmed = confirm(PMA_sprintf(PMA_messages.strDoYouReally, theSqlQuery));
|
|
|
|
if (is_confirmed) {
|
2018-04-14 09:18:00 +00:00
|
|
|
if (typeof(theLink.href) !== 'undefined') {
|
|
|
|
theLink.href += PMA_commonParams.get('arg_separator') + 'is_js_confirmed=1';
|
2018-12-16 14:31:03 +00:00
|
|
|
} else if (typeof(theLink.form) !== 'undefined') {
|
2016-10-22 14:57:10 +00:00
|
|
|
theLink.form.action += '?is_js_confirmed=1';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return is_confirmed;
|
|
|
|
} // end of the 'confirmLink()' function
|
|
|
|
|
|
|
|
/**
|
2017-04-20 10:55:30 +00:00
|
|
|
* Confirms a "DROP/DELETE/ALTER" query before
|
2016-10-22 14:57:10 +00:00
|
|
|
* submitting it if required.
|
|
|
|
* This function is called by the 'checkSqlQuery()' js function.
|
|
|
|
*
|
|
|
|
* @param theForm1 object the form
|
2017-04-20 10:55:30 +00:00
|
|
|
* @param sqlQuery1 string the sql query string
|
2016-10-22 14:57:10 +00:00
|
|
|
*
|
|
|
|
* @return boolean whether to run the query or not
|
|
|
|
*
|
|
|
|
* @see checkSqlQuery()
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function confirmQuery (theForm1, sqlQuery1) {
|
2016-10-22 14:57:10 +00:00
|
|
|
// Confirmation is not required in the configuration file
|
|
|
|
if (PMA_messages.strDoYouReally === '') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2017-04-20 10:55:30 +00:00
|
|
|
var do_confirm_re_0 = new RegExp('^\\s*DROP\\s+(IF EXISTS\\s+)?(TABLE|PROCEDURE)\\s', 'i');
|
2016-10-22 14:57:10 +00:00
|
|
|
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');
|
|
|
|
|
2017-04-20 10:55:30 +00:00
|
|
|
if (do_confirm_re_0.test(sqlQuery1) ||
|
|
|
|
do_confirm_re_1.test(sqlQuery1) ||
|
|
|
|
do_confirm_re_2.test(sqlQuery1) ||
|
|
|
|
do_confirm_re_3.test(sqlQuery1)) {
|
2016-10-22 14:57:10 +00:00
|
|
|
var message;
|
2017-04-20 10:55:30 +00:00
|
|
|
if (sqlQuery1.length > 100) {
|
|
|
|
message = sqlQuery1.substr(0, 100) + '\n ...';
|
2016-10-22 14:57:10 +00:00
|
|
|
} else {
|
2017-04-20 10:55:30 +00:00
|
|
|
message = sqlQuery1;
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
var is_confirmed = confirm(PMA_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;
|
2018-04-14 09:18:00 +00:00
|
|
|
} else {
|
|
|
|
// statement is rejected -> do not submit the form
|
2016-10-22 14:57:10 +00:00
|
|
|
window.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 theForm object the form
|
|
|
|
*
|
|
|
|
* @return boolean always false
|
|
|
|
*
|
|
|
|
* @see confirmQuery()
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function checkSqlQuery (theForm) {
|
2016-10-22 14:57:10 +00:00
|
|
|
// get the textarea element containing the query
|
|
|
|
var sqlQuery;
|
|
|
|
if (codemirror_editor) {
|
|
|
|
codemirror_editor.save();
|
|
|
|
sqlQuery = codemirror_editor.getValue();
|
|
|
|
} else {
|
|
|
|
sqlQuery = theForm.elements.sql_query.value;
|
|
|
|
}
|
|
|
|
var space_re = new RegExp('\\s+');
|
2018-04-14 09:18:00 +00:00
|
|
|
if (typeof(theForm.elements.sql_file) !== 'undefined' &&
|
2016-10-22 14:57:10 +00:00
|
|
|
theForm.elements.sql_file.value.replace(space_re, '') !== '') {
|
|
|
|
return true;
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
if (typeof(theForm.elements.id_bookmark) !== 'undefined' &&
|
2016-10-22 14:57:10 +00:00
|
|
|
(theForm.elements.id_bookmark.value !== null || theForm.elements.id_bookmark.value !== '') &&
|
|
|
|
theForm.elements.id_bookmark.selectedIndex !== 0) {
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-20 10:55:30 +00:00
|
|
|
var result = false;
|
2016-10-22 14:57:10 +00:00
|
|
|
// Checks for "DROP/DELETE/ALTER" statements
|
|
|
|
if (sqlQuery.replace(space_re, '') !== '') {
|
2017-04-20 10:55:30 +00:00
|
|
|
result = confirmQuery(theForm, sqlQuery);
|
|
|
|
} else {
|
|
|
|
alert(PMA_messages.strFormEmpty);
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 10:55:30 +00:00
|
|
|
if (codemirror_editor) {
|
2016-10-22 14:57:10 +00:00
|
|
|
codemirror_editor.focus();
|
2017-04-20 10:55:30 +00:00
|
|
|
} else if (codemirror_inline_editor) {
|
|
|
|
codemirror_inline_editor.focus();
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
2017-04-20 10:55:30 +00:00
|
|
|
return result;
|
2016-10-22 14:57:10 +00:00
|
|
|
} // 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
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function emptyCheckTheField (theForm, theFieldName) {
|
2016-10-22 14:57:10 +00:00
|
|
|
var theField = theForm.elements[theFieldName];
|
|
|
|
var space_re = new RegExp('\\s+');
|
|
|
|
return theField.value.replace(space_re, '') === '';
|
|
|
|
} // end of the 'emptyCheckTheField()' 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
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function checkFormElementInRange (theForm, theFieldName, message, min, max) {
|
2016-10-22 14:57:10 +00:00
|
|
|
var theField = theForm.elements[theFieldName];
|
|
|
|
var val = parseInt(theField.value, 10);
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
if (typeof(min) === 'undefined') {
|
2016-10-22 14:57:10 +00:00
|
|
|
min = 0;
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
if (typeof(max) === 'undefined') {
|
2016-10-22 14:57:10 +00:00
|
|
|
max = Number.MAX_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isNaN(val)) {
|
|
|
|
theField.select();
|
|
|
|
alert(PMA_messages.strEnterValidNumber);
|
|
|
|
theField.focus();
|
|
|
|
return false;
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (val < min || val > max) {
|
2016-10-22 14:57:10 +00:00
|
|
|
theField.select();
|
|
|
|
alert(PMA_sprintf(message, val));
|
|
|
|
theField.focus();
|
|
|
|
return false;
|
2018-04-14 09:18:00 +00:00
|
|
|
} else {
|
2016-10-22 14:57:10 +00:00
|
|
|
theField.value = val;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} // end of the 'checkFormElementInRange()' function
|
|
|
|
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
function checkTableEditForm (theForm, fieldsCnt) {
|
2016-10-22 14:57:10 +00:00
|
|
|
// 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;
|
2018-04-14 09:18:00 +00:00
|
|
|
var i;
|
|
|
|
var elm;
|
|
|
|
var elm2;
|
|
|
|
var elm3;
|
|
|
|
var val;
|
|
|
|
var id;
|
2016-10-22 14:57:10 +00:00
|
|
|
|
|
|
|
for (i = 0; i < fieldsCnt; i++) {
|
2018-04-14 09:18:00 +00:00
|
|
|
id = '#field_' + i + '_2';
|
2016-10-22 14:57:10 +00:00
|
|
|
elm = $(id);
|
|
|
|
val = elm.val();
|
2018-04-14 09:18:00 +00:00
|
|
|
if (val === 'VARCHAR' || val === 'CHAR' || val === 'BIT' || val === 'VARBINARY' || val === 'BINARY') {
|
|
|
|
elm2 = $('#field_' + i + '_3');
|
2016-10-22 14:57:10 +00:00
|
|
|
val = parseInt(elm2.val(), 10);
|
2018-04-14 09:18:00 +00:00
|
|
|
elm3 = $('#field_' + i + '_1');
|
|
|
|
if (isNaN(val) && elm3.val() !== '') {
|
2016-10-22 14:57:10 +00:00
|
|
|
elm2.select();
|
|
|
|
alert(PMA_messages.strEnterValidLength);
|
|
|
|
elm2.focus();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (atLeastOneField === 0) {
|
2018-04-14 09:18:00 +00:00
|
|
|
id = 'field_' + i + '_1';
|
2016-10-22 14:57:10 +00:00
|
|
|
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
|
2018-04-14 09:18:00 +00:00
|
|
|
var $input = $('input.textfield[name=\'table\']');
|
|
|
|
if ($input.val() === '') {
|
2016-10-22 14:57:10 +00:00
|
|
|
alert(PMA_messages.strFormEmpty);
|
|
|
|
$input.focus();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} // enf of the 'checkTableEditForm()' function
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
var _idleSecondsCounter = 0;
|
|
|
|
var IncInterval;
|
|
|
|
var updateTimeout;
|
|
|
|
AJAX.registerTeardown('functions.js', function () {
|
|
|
|
clearTimeout(updateTimeout);
|
|
|
|
clearInterval(IncInterval);
|
|
|
|
$(document).off('mousemove');
|
|
|
|
});
|
|
|
|
|
|
|
|
AJAX.registerOnload('functions.js', function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
document.onclick = function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
_idleSecondsCounter = 0;
|
|
|
|
};
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('mousemove',function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
_idleSecondsCounter = 0;
|
|
|
|
});
|
2018-04-14 09:18:00 +00:00
|
|
|
document.onkeypress = function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
_idleSecondsCounter = 0;
|
|
|
|
};
|
2018-04-14 09:18:00 +00:00
|
|
|
function guid () {
|
|
|
|
function s4 () {
|
2017-04-20 10:55:30 +00:00
|
|
|
return Math.floor((1 + Math.random()) * 0x10000)
|
|
|
|
.toString(16)
|
2018-04-14 09:18:00 +00:00
|
|
|
.substring(1);
|
2017-04-20 10:55:30 +00:00
|
|
|
}
|
|
|
|
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
|
|
|
|
s4() + '-' + s4() + s4() + s4();
|
|
|
|
}
|
2016-10-22 14:57:10 +00:00
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
function SetIdleTime () {
|
2016-10-22 14:57:10 +00:00
|
|
|
_idleSecondsCounter++;
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
function UpdateIdleTime () {
|
2016-10-22 14:57:10 +00:00
|
|
|
var href = 'index.php';
|
2017-04-20 10:55:30 +00:00
|
|
|
var guid = 'default';
|
|
|
|
if (isStorageSupported('sessionStorage')) {
|
|
|
|
guid = window.sessionStorage.guid;
|
|
|
|
}
|
2016-10-22 14:57:10 +00:00
|
|
|
var params = {
|
2018-04-14 09:18:00 +00:00
|
|
|
'ajax_request' : true,
|
|
|
|
'server' : PMA_commonParams.get('server'),
|
|
|
|
'db' : PMA_commonParams.get('db'),
|
|
|
|
'guid': guid,
|
|
|
|
'access_time':_idleSecondsCounter
|
|
|
|
};
|
2016-10-22 14:57:10 +00:00
|
|
|
$.ajax({
|
2018-04-14 09:18:00 +00:00
|
|
|
type: 'POST',
|
|
|
|
url: href,
|
|
|
|
data: params,
|
|
|
|
success: function (data) {
|
|
|
|
if (data.success) {
|
|
|
|
if (PMA_commonParams.get('LoginCookieValidity') - _idleSecondsCounter < 0) {
|
|
|
|
/* There is other active window, let's reset counter */
|
|
|
|
_idleSecondsCounter = 0;
|
|
|
|
}
|
|
|
|
var remaining = Math.min(
|
|
|
|
/* Remaining login validity */
|
|
|
|
PMA_commonParams.get('LoginCookieValidity') - _idleSecondsCounter,
|
|
|
|
/* Remaining time till session GC */
|
|
|
|
PMA_commonParams.get('session_gc_maxlifetime')
|
|
|
|
);
|
|
|
|
var interval = 1000;
|
|
|
|
if (remaining > 5) {
|
|
|
|
// max value for setInterval() function
|
|
|
|
interval = Math.min((remaining - 1) * 1000, Math.pow(2, 31) - 1);
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
updateTimeout = window.setTimeout(UpdateIdleTime, interval);
|
|
|
|
} else { // timeout occurred
|
|
|
|
clearInterval(IncInterval);
|
|
|
|
if (isStorageSupported('sessionStorage')) {
|
|
|
|
window.sessionStorage.clear();
|
|
|
|
}
|
|
|
|
window.location.reload(true);
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
}
|
|
|
|
});
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
2017-04-20 10:55:30 +00:00
|
|
|
if (PMA_commonParams.get('logged_in')) {
|
2016-10-22 14:57:10 +00:00
|
|
|
IncInterval = window.setInterval(SetIdleTime, 1000);
|
2017-04-20 10:55:30 +00:00
|
|
|
var session_timeout = Math.min(
|
|
|
|
PMA_commonParams.get('LoginCookieValidity'),
|
|
|
|
PMA_commonParams.get('session_gc_maxlifetime')
|
|
|
|
);
|
|
|
|
if (isStorageSupported('sessionStorage')) {
|
|
|
|
window.sessionStorage.setItem('guid', guid());
|
|
|
|
}
|
|
|
|
var interval = (session_timeout - 5) * 1000;
|
2016-10-22 14:57:10 +00:00
|
|
|
if (interval > Math.pow(2, 31) - 1) { // max value for setInterval() function
|
|
|
|
interval = Math.pow(2, 31) - 1;
|
|
|
|
}
|
|
|
|
updateTimeout = window.setTimeout(UpdateIdleTime, interval);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
/**
|
|
|
|
* Unbind all event handlers before tearing down a page
|
|
|
|
*/
|
|
|
|
AJAX.registerTeardown('functions.js', function () {
|
|
|
|
$(document).off('click', 'input:checkbox.checkall');
|
|
|
|
});
|
|
|
|
AJAX.registerOnload('functions.js', function () {
|
|
|
|
/**
|
|
|
|
* Row marking in horizontal mode (use "on" so that it works also for
|
|
|
|
* next pages reached via AJAX); a tr may have the class noclick to remove
|
|
|
|
* this behavior.
|
|
|
|
*/
|
|
|
|
|
|
|
|
$(document).on('click', 'input:checkbox.checkall', function (e) {
|
|
|
|
$this = $(this);
|
|
|
|
var $tr = $this.closest('tr');
|
|
|
|
var $table = $this.closest('table');
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
if (!e.shiftKey || last_clicked_row === -1) {
|
2016-10-22 14:57:10 +00:00
|
|
|
// usual click
|
|
|
|
|
|
|
|
var $checkbox = $tr.find(':checkbox.checkall');
|
|
|
|
var checked = $this.prop('checked');
|
|
|
|
$checkbox.prop('checked', checked).trigger('change');
|
|
|
|
if (checked) {
|
|
|
|
$tr.addClass('marked');
|
|
|
|
} else {
|
|
|
|
$tr.removeClass('marked');
|
|
|
|
}
|
|
|
|
last_click_checked = checked;
|
|
|
|
|
|
|
|
// remember the last clicked row
|
2019-12-08 07:14:01 +00:00
|
|
|
last_clicked_row = last_click_checked ? $table.find('tbody tr:not(.noclick)').index($tr) : -1;
|
2016-10-22 14:57:10 +00:00
|
|
|
last_shift_clicked_row = -1;
|
|
|
|
} else {
|
|
|
|
// handle the shift click
|
|
|
|
PMA_clearSelection();
|
2018-04-14 09:18:00 +00:00
|
|
|
var start;
|
|
|
|
var end;
|
2016-10-22 14:57:10 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
2017-04-20 10:55:30 +00:00
|
|
|
$tr.parent().find('tr:not(.noclick)')
|
2016-10-22 14:57:10 +00:00
|
|
|
.slice(start, end + 1)
|
|
|
|
.removeClass('marked')
|
|
|
|
.find(':checkbox')
|
|
|
|
.prop('checked', false)
|
|
|
|
.trigger('change');
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle new shift click
|
2019-12-08 07:14:01 +00:00
|
|
|
var curr_row = $table.find('tbody tr:not(.noclick)').index($tr);
|
2016-10-22 14:57:10 +00:00
|
|
|
if (curr_row >= last_clicked_row) {
|
|
|
|
start = last_clicked_row;
|
|
|
|
end = curr_row;
|
|
|
|
} else {
|
|
|
|
start = curr_row;
|
|
|
|
end = last_clicked_row;
|
|
|
|
}
|
2017-04-20 10:55:30 +00:00
|
|
|
$tr.parent().find('tr:not(.noclick)')
|
2019-12-08 07:14:01 +00:00
|
|
|
.slice(start, end + 1)
|
2016-10-22 14:57:10 +00:00
|
|
|
.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');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function setSelectOptions (the_form, the_select, do_check) {
|
|
|
|
$('form[name=\'' + the_form + '\'] select[name=\'' + the_select + '\']').find('option').prop('selected', do_check);
|
2016-10-22 14:57:10 +00:00
|
|
|
return true;
|
|
|
|
} // end of the 'setSelectOptions()' function
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets current value for query box.
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function setQuery (query) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (codemirror_editor) {
|
|
|
|
codemirror_editor.setValue(query);
|
|
|
|
codemirror_editor.focus();
|
|
|
|
} else {
|
|
|
|
document.sqlform.sql_query.value = query;
|
|
|
|
document.sqlform.sql_query.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles 'Simulate query' button on SQL query box.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_handleSimulateQueryButton () {
|
2016-10-22 14:57:10 +00:00
|
|
|
var update_re = new RegExp('^\\s*UPDATE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+SET\\s', 'i');
|
|
|
|
var delete_re = new RegExp('^\\s*DELETE\\s+FROM\\s', 'i');
|
|
|
|
var query = '';
|
|
|
|
|
|
|
|
if (codemirror_editor) {
|
|
|
|
query = codemirror_editor.getValue();
|
|
|
|
} else {
|
|
|
|
query = $('#sqlquery').val();
|
|
|
|
}
|
|
|
|
|
|
|
|
var $simulateDml = $('#simulate_dml');
|
|
|
|
if (update_re.test(query) || delete_re.test(query)) {
|
|
|
|
if (! $simulateDml.length) {
|
|
|
|
$('#button_submit_query')
|
2018-04-14 09:18:00 +00:00
|
|
|
.before('<input type="button" id="simulate_dml"' +
|
2016-10-22 14:57:10 +00:00
|
|
|
'tabindex="199" value="' +
|
|
|
|
PMA_messages.strSimulateDML +
|
|
|
|
'" />');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($simulateDml.length) {
|
|
|
|
$simulateDml.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create quick sql statements.
|
|
|
|
*
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function insertQuery (queryType) {
|
|
|
|
if (queryType === 'clear') {
|
2016-10-22 14:57:10 +00:00
|
|
|
setQuery('');
|
|
|
|
return;
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (queryType === 'format') {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (codemirror_editor) {
|
|
|
|
$('#querymessage').html(PMA_messages.strFormatting +
|
|
|
|
' <img class="ajaxIcon" src="' +
|
|
|
|
pmaThemeImage + 'ajax_clock_small.gif" alt="">');
|
|
|
|
var href = 'db_sql_format.php';
|
|
|
|
var params = {
|
|
|
|
'ajax_request': true,
|
2019-12-08 07:14:01 +00:00
|
|
|
'sql': codemirror_editor.getValue(),
|
|
|
|
'server': PMA_commonParams.get('server')
|
2016-10-22 14:57:10 +00:00
|
|
|
};
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: href,
|
|
|
|
data: params,
|
|
|
|
success: function (data) {
|
|
|
|
if (data.success) {
|
|
|
|
codemirror_editor.setValue(data.sql);
|
|
|
|
}
|
|
|
|
$('#querymessage').html('');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return;
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (queryType === 'saved') {
|
|
|
|
if (isStorageSupported('localStorage') && typeof window.localStorage.auto_saved_sql !== 'undefined') {
|
2017-04-20 10:55:30 +00:00
|
|
|
setQuery(window.localStorage.auto_saved_sql);
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (Cookies.get('auto_saved_sql')) {
|
|
|
|
setQuery(Cookies.get('auto_saved_sql'));
|
2016-10-22 14:57:10 +00:00
|
|
|
} else {
|
|
|
|
PMA_ajaxShowMessage(PMA_messages.strNoAutoSavedQuery);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
var query = '';
|
2016-10-22 14:57:10 +00:00
|
|
|
var myListBox = document.sqlform.dummy;
|
|
|
|
var table = document.sqlform.table.value;
|
|
|
|
|
|
|
|
if (myListBox.options.length > 0) {
|
|
|
|
sql_box_locked = true;
|
2018-04-14 09:18:00 +00:00
|
|
|
var columnsList = '';
|
|
|
|
var valDis = '';
|
|
|
|
var editDis = '';
|
2016-10-22 14:57:10 +00:00
|
|
|
var NbSelect = 0;
|
|
|
|
for (var i = 0; i < myListBox.options.length; i++) {
|
|
|
|
NbSelect++;
|
|
|
|
if (NbSelect > 1) {
|
2018-04-14 09:18:00 +00:00
|
|
|
columnsList += ', ';
|
|
|
|
valDis += ',';
|
|
|
|
editDis += ',';
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
columnsList += myListBox.options[i].value;
|
2018-04-14 09:18:00 +00:00
|
|
|
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 ' + columnsList + ' FROM `' + table + '` WHERE 1';
|
|
|
|
} else if (queryType === 'insert') {
|
|
|
|
query = 'INSERT INTO `' + table + '`(' + columnsList + ') VALUES (' + valDis + ')';
|
|
|
|
} else if (queryType === 'update') {
|
|
|
|
query = 'UPDATE `' + table + '` SET ' + editDis + ' WHERE 1';
|
|
|
|
} else if (queryType === 'delete') {
|
|
|
|
query = 'DELETE FROM `' + table + '` WHERE 0';
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
setQuery(query);
|
|
|
|
sql_box_locked = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inserts multiple fields.
|
|
|
|
*
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function insertValueQuery () {
|
2016-10-22 14:57:10 +00:00
|
|
|
var myQuery = document.sqlform.sql_query;
|
|
|
|
var myListBox = document.sqlform.dummy;
|
|
|
|
|
|
|
|
if (myListBox.options.length > 0) {
|
|
|
|
sql_box_locked = true;
|
2018-04-14 09:18:00 +00:00
|
|
|
var columnsList = '';
|
2016-10-22 14:57:10 +00:00
|
|
|
var NbSelect = 0;
|
|
|
|
for (var i = 0; i < myListBox.options.length; i++) {
|
|
|
|
if (myListBox.options[i].selected) {
|
|
|
|
NbSelect++;
|
|
|
|
if (NbSelect > 1) {
|
2018-04-14 09:18:00 +00:00
|
|
|
columnsList += ', ';
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
columnsList += myListBox.options[i].value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* CodeMirror support */
|
|
|
|
if (codemirror_editor) {
|
|
|
|
codemirror_editor.replaceSelection(columnsList);
|
2018-04-14 09:18:00 +00:00
|
|
|
codemirror_editor.focus();
|
|
|
|
// IE support
|
2016-10-22 14:57:10 +00:00
|
|
|
} else if (document.selection) {
|
|
|
|
myQuery.focus();
|
|
|
|
var sel = document.selection.createRange();
|
|
|
|
sel.text = columnsList;
|
2018-04-14 09:18:00 +00:00
|
|
|
// MOZILLA/NETSCAPE support
|
|
|
|
} else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart === '0') {
|
2016-10-22 14:57:10 +00:00
|
|
|
var startPos = document.sqlform.sql_query.selectionStart;
|
|
|
|
var endPos = document.sqlform.sql_query.selectionEnd;
|
|
|
|
var SqlString = document.sqlform.sql_query.value;
|
|
|
|
|
|
|
|
myQuery.value = SqlString.substring(0, startPos) + columnsList + SqlString.substring(endPos, SqlString.length);
|
2018-04-14 09:18:00 +00:00
|
|
|
myQuery.focus();
|
2016-10-22 14:57:10 +00:00
|
|
|
} else {
|
|
|
|
myQuery.value += columnsList;
|
|
|
|
}
|
|
|
|
sql_box_locked = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the input fields for the parameters based on the query
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function updateQueryParameters () {
|
2016-10-22 14:57:10 +00:00
|
|
|
if ($('#parameterized').is(':checked')) {
|
|
|
|
var query = codemirror_editor ? codemirror_editor.getValue() : $('#sqlquery').val();
|
|
|
|
|
|
|
|
var allParameters = query.match(/:[a-zA-Z0-9_]+/g);
|
|
|
|
var parameters = [];
|
|
|
|
// get unique parameters
|
|
|
|
if (allParameters) {
|
2018-04-14 09:18:00 +00:00
|
|
|
$.each(allParameters, function (i, parameter) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if ($.inArray(parameter, parameters) === -1) {
|
|
|
|
parameters.push(parameter);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$('#parametersDiv').text(PMA_messages.strNoParam);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var $temp = $('<div />');
|
|
|
|
$temp.append($('#parametersDiv').children());
|
|
|
|
$('#parametersDiv').empty();
|
|
|
|
|
|
|
|
$.each(parameters, function (i, parameter) {
|
|
|
|
var paramName = parameter.substring(1);
|
2018-04-14 09:18:00 +00:00
|
|
|
var $param = $temp.find('#paramSpan_' + paramName);
|
2016-10-22 14:57:10 +00:00
|
|
|
if (! $param.length) {
|
|
|
|
$param = $('<span class="parameter" id="paramSpan_' + paramName + '" />');
|
|
|
|
$('<label for="param_' + paramName + '" />').text(parameter).appendTo($param);
|
|
|
|
$('<input type="text" name="parameters[' + parameter + ']" id="param_' + paramName + '" />').appendTo($param);
|
|
|
|
}
|
|
|
|
$('#parametersDiv').append($param);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
$('#parametersDiv').empty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Refresh/resize the WYSIWYG scratchboard
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function refreshLayout () {
|
2016-10-22 14:57:10 +00:00
|
|
|
var $elm = $('#pdflayout');
|
|
|
|
var orientation = $('#orientation_opt').val();
|
|
|
|
var paper = 'A4';
|
|
|
|
var $paperOpt = $('#paper_opt');
|
2018-04-14 09:18:00 +00:00
|
|
|
if ($paperOpt.length === 1) {
|
2016-10-22 14:57:10 +00:00
|
|
|
paper = $paperOpt.val();
|
|
|
|
}
|
|
|
|
var posa = 'y';
|
|
|
|
var posb = 'x';
|
2018-04-14 09:18:00 +00:00
|
|
|
if (orientation === 'P') {
|
2016-10-22 14:57:10 +00:00
|
|
|
posa = 'x';
|
|
|
|
posb = 'y';
|
|
|
|
}
|
|
|
|
$elm.css('width', pdfPaperSize(paper, posa) + 'px');
|
|
|
|
$elm.css('height', pdfPaperSize(paper, posb) + 'px');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes positions of elements.
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function TableDragInit () {
|
2016-10-22 14:57:10 +00:00
|
|
|
$('.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({
|
2018-04-14 09:18:00 +00:00
|
|
|
containment: 'parent',
|
2016-10-22 14:57:10 +00:00
|
|
|
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.
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function resetDrag () {
|
2016-10-22 14:57:10 +00:00
|
|
|
$('.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 */
|
|
|
|
$(document).on('change', '.position-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 */
|
|
|
|
$(document).on('change', '.paper-change', function () {
|
|
|
|
var $elm = $('#pdflayout');
|
2018-04-14 09:18:00 +00:00
|
|
|
if ($elm.css('visibility') === 'visible') {
|
2016-10-22 14:57:10 +00:00
|
|
|
refreshLayout();
|
|
|
|
TableDragInit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
/* Show/hide the WYSIWYG scratchboard */
|
|
|
|
$(document).on('click', '#toggle-dragdrop', function () {
|
|
|
|
var $elm = $('#pdflayout');
|
2018-04-14 09:18:00 +00:00
|
|
|
if ($elm.css('visibility') === 'hidden') {
|
2016-10-22 14:57:10 +00:00
|
|
|
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 */
|
|
|
|
$(document).on('click', '#reset-dragdrop', function () {
|
|
|
|
resetDrag();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns paper sizes for a given format
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function pdfPaperSize (format, axis) {
|
2016-10-22 14:57:10 +00:00
|
|
|
switch (format.toUpperCase()) {
|
|
|
|
case '4A0':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 4767.87;
|
|
|
|
} else {
|
|
|
|
return 6740.79;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case '2A0':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 3370.39;
|
|
|
|
} else {
|
|
|
|
return 4767.87;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'A0':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 2383.94;
|
|
|
|
} else {
|
|
|
|
return 3370.39;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'A1':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 1683.78;
|
|
|
|
} else {
|
|
|
|
return 2383.94;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'A2':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 1190.55;
|
|
|
|
} else {
|
|
|
|
return 1683.78;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'A3':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 841.89;
|
|
|
|
} else {
|
|
|
|
return 1190.55;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'A4':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 595.28;
|
|
|
|
} else {
|
|
|
|
return 841.89;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'A5':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 419.53;
|
|
|
|
} else {
|
|
|
|
return 595.28;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'A6':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 297.64;
|
|
|
|
} else {
|
|
|
|
return 419.53;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'A7':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 209.76;
|
|
|
|
} else {
|
|
|
|
return 297.64;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'A8':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 147.40;
|
|
|
|
} else {
|
|
|
|
return 209.76;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'A9':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 104.88;
|
|
|
|
} else {
|
|
|
|
return 147.40;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'A10':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 73.70;
|
|
|
|
} else {
|
|
|
|
return 104.88;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'B0':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 2834.65;
|
|
|
|
} else {
|
|
|
|
return 4008.19;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'B1':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 2004.09;
|
|
|
|
} else {
|
|
|
|
return 2834.65;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'B2':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 1417.32;
|
|
|
|
} else {
|
|
|
|
return 2004.09;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'B3':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 1000.63;
|
|
|
|
} else {
|
|
|
|
return 1417.32;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'B4':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 708.66;
|
|
|
|
} else {
|
|
|
|
return 1000.63;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'B5':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 498.90;
|
|
|
|
} else {
|
|
|
|
return 708.66;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'B6':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 354.33;
|
|
|
|
} else {
|
|
|
|
return 498.90;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'B7':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 249.45;
|
|
|
|
} else {
|
|
|
|
return 354.33;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'B8':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 175.75;
|
|
|
|
} else {
|
|
|
|
return 249.45;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'B9':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 124.72;
|
|
|
|
} else {
|
|
|
|
return 175.75;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'B10':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 87.87;
|
|
|
|
} else {
|
|
|
|
return 124.72;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'C0':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 2599.37;
|
|
|
|
} else {
|
|
|
|
return 3676.54;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'C1':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 1836.85;
|
|
|
|
} else {
|
|
|
|
return 2599.37;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'C2':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 1298.27;
|
|
|
|
} else {
|
|
|
|
return 1836.85;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'C3':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 918.43;
|
|
|
|
} else {
|
|
|
|
return 1298.27;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'C4':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 649.13;
|
|
|
|
} else {
|
|
|
|
return 918.43;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'C5':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 459.21;
|
|
|
|
} else {
|
|
|
|
return 649.13;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'C6':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 323.15;
|
|
|
|
} else {
|
|
|
|
return 459.21;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'C7':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 229.61;
|
|
|
|
} else {
|
|
|
|
return 323.15;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'C8':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 161.57;
|
|
|
|
} else {
|
|
|
|
return 229.61;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'C9':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 113.39;
|
|
|
|
} else {
|
|
|
|
return 161.57;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'C10':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 79.37;
|
|
|
|
} else {
|
|
|
|
return 113.39;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'RA0':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 2437.80;
|
|
|
|
} else {
|
|
|
|
return 3458.27;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'RA1':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 1729.13;
|
|
|
|
} else {
|
|
|
|
return 2437.80;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'RA2':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 1218.90;
|
|
|
|
} else {
|
|
|
|
return 1729.13;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'RA3':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 864.57;
|
|
|
|
} else {
|
|
|
|
return 1218.90;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'RA4':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 609.45;
|
|
|
|
} else {
|
|
|
|
return 864.57;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'SRA0':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 2551.18;
|
|
|
|
} else {
|
|
|
|
return 3628.35;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'SRA1':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 1814.17;
|
|
|
|
} else {
|
|
|
|
return 2551.18;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'SRA2':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 1275.59;
|
|
|
|
} else {
|
|
|
|
return 1814.17;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'SRA3':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 907.09;
|
|
|
|
} else {
|
|
|
|
return 1275.59;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'SRA4':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 637.80;
|
|
|
|
} else {
|
|
|
|
return 907.09;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'LETTER':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 612.00;
|
|
|
|
} else {
|
|
|
|
return 792.00;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'LEGAL':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 612.00;
|
|
|
|
} else {
|
|
|
|
return 1008.00;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'EXECUTIVE':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 521.86;
|
|
|
|
} else {
|
|
|
|
return 756.00;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'FOLIO':
|
2018-04-14 09:18:00 +00:00
|
|
|
if (axis === 'x') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return 612.00;
|
|
|
|
} else {
|
|
|
|
return 936.00;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} // end switch
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get checkbox for foreign key checks
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function getForeignKeyCheckboxLoader () {
|
2016-10-22 14:57:10 +00:00
|
|
|
var html = '';
|
|
|
|
html += '<div>';
|
|
|
|
html += '<div class="load-default-fk-check-value">';
|
2018-04-14 09:18:00 +00:00
|
|
|
html += PMA_getImage('ajax_clock_small');
|
2016-10-22 14:57:10 +00:00
|
|
|
html += '</div>';
|
|
|
|
html += '</div>';
|
|
|
|
return html;
|
|
|
|
}
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
function loadForeignKeyCheckbox () {
|
2016-10-22 14:57:10 +00:00
|
|
|
// Load default foreign key check value
|
|
|
|
var params = {
|
|
|
|
'ajax_request': true,
|
|
|
|
'server': PMA_commonParams.get('server'),
|
|
|
|
'get_default_fk_check_value': true
|
|
|
|
};
|
|
|
|
$.get('sql.php', params, function (data) {
|
|
|
|
var html = '<input type="hidden" name="fk_checks" value="0" />' +
|
|
|
|
'<input type="checkbox" name="fk_checks" id="fk_checks"' +
|
|
|
|
(data.default_fk_check_value ? ' checked="checked"' : '') + ' />' +
|
|
|
|
'<label for="fk_checks">' + PMA_messages.strForeignKeyCheck + '</label>';
|
|
|
|
$('.load-default-fk-check-value').replaceWith(html);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
function getJSConfirmCommonParam (elem, params) {
|
|
|
|
var $elem = $(elem);
|
|
|
|
var sep = PMA_commonParams.get('arg_separator');
|
|
|
|
if (params) {
|
|
|
|
// Strip possible leading ?
|
|
|
|
if (params.substring(0,1) == '?') {
|
|
|
|
params = params.substr(1);
|
|
|
|
}
|
|
|
|
params += sep;
|
|
|
|
} else {
|
|
|
|
params = '';
|
|
|
|
}
|
|
|
|
params += 'is_js_confirmed=1' + sep + 'ajax_request=true' + sep + 'fk_checks=' + ($elem.find('#fk_checks').is(':checked') ? 1 : 0);
|
|
|
|
return params;
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbind all event handlers before tearing down a page
|
|
|
|
*/
|
|
|
|
AJAX.registerTeardown('functions.js', function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).off('click', 'a.inline_edit_sql');
|
|
|
|
$(document).off('click', 'input#sql_query_edit_save');
|
|
|
|
$(document).off('click', 'input#sql_query_edit_discard');
|
|
|
|
$('input.sqlbutton').off('click');
|
2016-10-22 14:57:10 +00:00
|
|
|
if (codemirror_editor) {
|
|
|
|
codemirror_editor.off('blur');
|
|
|
|
} else {
|
|
|
|
$(document).off('blur', '#sqlquery');
|
|
|
|
}
|
|
|
|
$(document).off('change', '#parameterized');
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).off('click', 'input.sqlbutton');
|
|
|
|
$('#sqlquery').off('keydown');
|
|
|
|
$('#sql_query_edit').off('keydown');
|
2016-10-22 14:57:10 +00:00
|
|
|
|
|
|
|
if (codemirror_inline_editor) {
|
|
|
|
// Copy the sql query to the text area to preserve it.
|
|
|
|
$('#sql_query_edit').text(codemirror_inline_editor.getValue());
|
2018-04-14 09:18:00 +00:00
|
|
|
$(codemirror_inline_editor.getWrapperElement()).off('keydown');
|
2016-10-22 14:57:10 +00:00
|
|
|
codemirror_inline_editor.toTextArea();
|
|
|
|
codemirror_inline_editor = false;
|
|
|
|
}
|
|
|
|
if (codemirror_editor) {
|
2018-04-14 09:18:00 +00:00
|
|
|
$(codemirror_editor.getWrapperElement()).off('keydown');
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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();
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('click', 'a.inline_edit_sql', function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
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');
|
2018-04-14 09:18:00 +00:00
|
|
|
var sql_query = $form.find('input[name=\'sql_query\']').val().trim();
|
2016-10-22 14:57:10 +00:00
|
|
|
var $inner_sql = $(this).parent().prev().find('code.sql');
|
|
|
|
var old_text = $inner_sql.html();
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
var new_content = '<textarea name="sql_query_edit" id="sql_query_edit">' + escapeHtml(sql_query) + '</textarea>\n';
|
2016-10-22 14:57:10 +00:00
|
|
|
new_content += getForeignKeyCheckboxLoader();
|
2018-04-14 09:18:00 +00:00
|
|
|
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';
|
2016-10-22 14:57:10 +00:00
|
|
|
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);
|
|
|
|
loadForeignKeyCheckbox();
|
|
|
|
$inner_sql.hide();
|
|
|
|
|
|
|
|
bindCodeMirrorToInlineEditor();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('click', 'input#sql_query_edit_save', function () {
|
|
|
|
// hide already existing success message
|
2016-10-22 14:57:10 +00:00
|
|
|
var sql_query;
|
|
|
|
if (codemirror_inline_editor) {
|
|
|
|
codemirror_inline_editor.save();
|
|
|
|
sql_query = codemirror_inline_editor.getValue();
|
|
|
|
} else {
|
|
|
|
sql_query = $(this).parent().find('#sql_query_edit').val();
|
|
|
|
}
|
|
|
|
var fk_check = $(this).parent().find('#fk_checks').is(':checked');
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
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 }))
|
|
|
|
.append($('<input/>', { type: 'hidden', name: 'fk_checks', value: fk_check ? 1 : 0 }));
|
2016-10-22 14:57:10 +00:00
|
|
|
if (! checkSqlQuery($fake_form[0])) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
$('.success').hide();
|
2016-10-22 14:57:10 +00:00
|
|
|
$fake_form.appendTo($('body')).submit();
|
|
|
|
});
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('click', 'input#sql_query_edit_discard', function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
var $divEditor = $('div#inline_editor_outer');
|
|
|
|
$divEditor.siblings('code.sql').show();
|
|
|
|
$divEditor.remove();
|
|
|
|
});
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('click', 'input.sqlbutton', function (evt) {
|
2016-10-22 14:57:10 +00:00
|
|
|
insertQuery(evt.target.id);
|
|
|
|
PMA_handleSimulateQueryButton();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on('change', '#parameterized', updateQueryParameters);
|
|
|
|
|
|
|
|
var $inputUsername = $('#input_username');
|
|
|
|
if ($inputUsername) {
|
|
|
|
if ($inputUsername.val() === '') {
|
2018-04-14 09:18:00 +00:00
|
|
|
$inputUsername.trigger('focus');
|
2016-10-22 14:57:10 +00:00
|
|
|
} else {
|
2018-04-14 09:18:00 +00:00
|
|
|
$('#input_password').trigger('focus');
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "inputRead" event handler for CodeMirror SQL query editors for autocompletion
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function codemirrorAutocompleteOnInputRead (instance) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (!sql_autocomplete_in_progress
|
|
|
|
&& (!instance.options.hintOptions.tables || !sql_autocomplete)) {
|
|
|
|
if (!sql_autocomplete) {
|
|
|
|
// Reset after teardown
|
|
|
|
instance.options.hintOptions.tables = false;
|
|
|
|
instance.options.hintOptions.defaultTable = '';
|
|
|
|
|
|
|
|
sql_autocomplete_in_progress = true;
|
|
|
|
|
|
|
|
var href = 'db_sql_autocomplete.php';
|
|
|
|
var params = {
|
|
|
|
'ajax_request': true,
|
|
|
|
'server': PMA_commonParams.get('server'),
|
|
|
|
'db': PMA_commonParams.get('db'),
|
|
|
|
'no_debug': true
|
|
|
|
};
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
var columnHintRender = function (elem, self, data) {
|
2016-10-22 14:57:10 +00:00
|
|
|
$('<div class="autocomplete-column-name">')
|
|
|
|
.text(data.columnName)
|
|
|
|
.appendTo(elem);
|
|
|
|
$('<div class="autocomplete-column-hint">')
|
|
|
|
.text(data.columnHint)
|
|
|
|
.appendTo(elem);
|
|
|
|
};
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: href,
|
|
|
|
data: params,
|
|
|
|
success: function (data) {
|
|
|
|
if (data.success) {
|
2017-04-20 10:55:30 +00:00
|
|
|
var tables = JSON.parse(data.tables);
|
2016-10-22 14:57:10 +00:00
|
|
|
sql_autocomplete_default_table = PMA_commonParams.get('table');
|
|
|
|
sql_autocomplete = [];
|
|
|
|
for (var table in tables) {
|
|
|
|
if (tables.hasOwnProperty(table)) {
|
|
|
|
var columns = tables[table];
|
|
|
|
table = {
|
|
|
|
text: table,
|
|
|
|
columns: []
|
|
|
|
};
|
|
|
|
for (var column in columns) {
|
|
|
|
if (columns.hasOwnProperty(column)) {
|
|
|
|
var displayText = columns[column].Type;
|
2018-04-14 09:18:00 +00:00
|
|
|
if (columns[column].Key === 'PRI') {
|
2016-10-22 14:57:10 +00:00
|
|
|
displayText += ' | Primary';
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (columns[column].Key === 'UNI') {
|
2016-10-22 14:57:10 +00:00
|
|
|
displayText += ' | Unique';
|
|
|
|
}
|
|
|
|
table.columns.push({
|
|
|
|
text: column,
|
2018-04-14 09:18:00 +00:00
|
|
|
displayText: column + ' | ' + displayText,
|
2016-10-22 14:57:10 +00:00
|
|
|
columnName: column,
|
|
|
|
columnHint: displayText,
|
|
|
|
render: columnHintRender
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sql_autocomplete.push(table);
|
|
|
|
}
|
|
|
|
instance.options.hintOptions.tables = sql_autocomplete;
|
|
|
|
instance.options.hintOptions.defaultTable = sql_autocomplete_default_table;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
complete: function () {
|
|
|
|
sql_autocomplete_in_progress = false;
|
|
|
|
}
|
|
|
|
});
|
2018-04-14 09:18:00 +00:00
|
|
|
} else {
|
2016-10-22 14:57:10 +00:00
|
|
|
instance.options.hintOptions.tables = sql_autocomplete;
|
|
|
|
instance.options.hintOptions.defaultTable = sql_autocomplete_default_table;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (instance.state.completionActive) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var cur = instance.getCursor();
|
|
|
|
var token = instance.getTokenAt(cur);
|
|
|
|
var string = '';
|
|
|
|
if (token.string.match(/^[.`\w@]\w*$/)) {
|
|
|
|
string = token.string;
|
|
|
|
}
|
|
|
|
if (string.length > 0) {
|
|
|
|
CodeMirror.commands.autocomplete(instance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove autocomplete information before tearing down a page
|
|
|
|
*/
|
|
|
|
AJAX.registerTeardown('functions.js', function () {
|
|
|
|
sql_autocomplete = false;
|
|
|
|
sql_autocomplete_default_table = '';
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Binds the CodeMirror to the text area used to inline edit a query.
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function bindCodeMirrorToInlineEditor () {
|
2016-10-22 14:57:10 +00:00
|
|
|
var $inline_editor = $('#sql_query_edit');
|
|
|
|
if ($inline_editor.length > 0) {
|
|
|
|
if (typeof CodeMirror !== 'undefined') {
|
|
|
|
var height = $inline_editor.css('height');
|
|
|
|
codemirror_inline_editor = PMA_getSQLEditor($inline_editor);
|
|
|
|
codemirror_inline_editor.getWrapperElement().style.height = height;
|
|
|
|
codemirror_inline_editor.refresh();
|
|
|
|
codemirror_inline_editor.focus();
|
|
|
|
$(codemirror_inline_editor.getWrapperElement())
|
2018-04-14 09:18:00 +00:00
|
|
|
.on('keydown', catchKeypressesFromSqlInlineEdit);
|
2016-10-22 14:57:10 +00:00
|
|
|
} else {
|
|
|
|
$inline_editor
|
|
|
|
.focus()
|
2018-04-14 09:18:00 +00:00
|
|
|
.on('keydown', catchKeypressesFromSqlInlineEdit);
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
function catchKeypressesFromSqlInlineEdit (event) {
|
2016-10-22 14:57:10 +00:00
|
|
|
// ctrl-enter is 10 in chrome and ie, but 13 in ff
|
2018-04-14 09:18:00 +00:00
|
|
|
if ((event.ctrlKey || event.metaKey) && (event.keyCode === 13 || event.keyCode === 10)) {
|
|
|
|
$('#sql_query_edit_save').trigger('click');
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds doc link to single highlighted SQL element
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_doc_add ($elm, params) {
|
|
|
|
if (typeof mysql_doc_template === 'undefined') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var url = PMA_sprintf(
|
|
|
|
decodeURIComponent(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
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_doc_keyword (idx, elm) {
|
2016-10-22 14:57:10 +00:00
|
|
|
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
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_doc_builtin (idx, elm) {
|
2016-10-22 14:57:10 +00:00
|
|
|
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.
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_highlightSQL ($base) {
|
2016-10-22 14:57:10 +00:00
|
|
|
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 */
|
2018-04-14 09:18:00 +00:00
|
|
|
if ($pre.is(':visible')) {
|
2016-10-22 14:57:10 +00:00
|
|
|
var $highlight = $('<div class="sql-highlight cm-s-default"></div>');
|
|
|
|
$sql.append($highlight);
|
2018-04-14 09:18:00 +00:00
|
|
|
if (typeof CodeMirror !== 'undefined') {
|
2016-10-22 14:57:10 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates an element containing code.
|
|
|
|
*
|
|
|
|
* @param jQuery Object $base base element which contains the raw and the
|
|
|
|
* highlighted code.
|
|
|
|
*
|
|
|
|
* @param string htmlValue code in HTML format, displayed if code cannot be
|
|
|
|
* highlighted
|
|
|
|
*
|
|
|
|
* @param string rawValue raw code, used as a parameter for highlighter
|
|
|
|
*
|
|
|
|
* @return bool whether content was updated or not
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_updateCode ($base, htmlValue, rawValue) {
|
2016-10-22 14:57:10 +00:00
|
|
|
var $code = $base.find('code');
|
|
|
|
if ($code.length === 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determines the type of the content and appropriate CodeMirror mode.
|
2018-04-14 09:18:00 +00:00
|
|
|
var type = '';
|
|
|
|
var mode = '';
|
2016-10-22 14:57:10 +00:00
|
|
|
if ($code.hasClass('json')) {
|
|
|
|
type = 'json';
|
|
|
|
mode = 'application/json';
|
|
|
|
} else if ($code.hasClass('sql')) {
|
|
|
|
type = 'sql';
|
|
|
|
mode = 'text/x-mysql';
|
|
|
|
} else if ($code.hasClass('xml')) {
|
|
|
|
type = 'xml';
|
|
|
|
mode = 'application/xml';
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Element used to display unhighlighted code.
|
|
|
|
var $notHighlighted = $('<pre>' + htmlValue + '</pre>');
|
|
|
|
|
|
|
|
// Tries to highlight code using CodeMirror.
|
2018-04-14 09:18:00 +00:00
|
|
|
if (typeof CodeMirror !== 'undefined') {
|
2016-10-22 14:57:10 +00:00
|
|
|
var $highlighted = $('<div class="' + type + '-highlight cm-s-default"></div>');
|
|
|
|
CodeMirror.runMode(rawValue, mode, $highlighted[0]);
|
|
|
|
$notHighlighted.hide();
|
|
|
|
$code.html('').append($notHighlighted, $highlighted[0]);
|
|
|
|
} else {
|
|
|
|
$code.html('').append($notHighlighted);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 number of milliseconds for the message to be visible
|
|
|
|
* optional, defaults to 5000. If set to 'false', the
|
|
|
|
* notification will never disappear
|
2017-04-20 10:55:30 +00:00
|
|
|
* @param string type string to dictate the type of message shown.
|
|
|
|
* optional, defaults to normal notification.
|
|
|
|
* If set to 'error', the notification will show message
|
|
|
|
* with red background.
|
|
|
|
* If set to 'success', the notification will show with
|
|
|
|
* a green background.
|
2016-10-22 14:57:10 +00:00
|
|
|
* @return jQuery object jQuery Element that holds the message div
|
|
|
|
* this object can be passed to PMA_ajaxRemoveMessage()
|
|
|
|
* to remove the notification
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_ajaxShowMessage (message, timeout, type) {
|
2016-10-22 14:57:10 +00:00
|
|
|
/**
|
|
|
|
* @var self_closing Whether the notification will automatically disappear
|
|
|
|
*/
|
|
|
|
var self_closing = true;
|
|
|
|
/**
|
|
|
|
* @var dismissable Whether the user will be able to remove
|
|
|
|
* the notification by clicking on it
|
|
|
|
*/
|
|
|
|
var dismissable = true;
|
|
|
|
// Handle the case when a empty data.message is passed.
|
|
|
|
// We don't want the empty message
|
|
|
|
if (message === '') {
|
|
|
|
return true;
|
|
|
|
} else if (! message) {
|
|
|
|
// If the message is undefined, show the default
|
|
|
|
message = PMA_messages.strLoading;
|
|
|
|
dismissable = false;
|
|
|
|
self_closing = false;
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (message === PMA_messages.strProcessingRequest) {
|
2016-10-22 14:57:10 +00:00
|
|
|
// This is another case where the message should not disappear
|
|
|
|
dismissable = false;
|
|
|
|
self_closing = false;
|
|
|
|
}
|
|
|
|
// Figure out whether (or after how long) to remove the notification
|
|
|
|
if (timeout === undefined) {
|
|
|
|
timeout = 5000;
|
|
|
|
} else if (timeout === false) {
|
|
|
|
self_closing = false;
|
|
|
|
}
|
2017-04-20 10:55:30 +00:00
|
|
|
// Determine type of message, add styling as required
|
2018-04-14 09:18:00 +00:00
|
|
|
if (type === 'error') {
|
|
|
|
message = '<div class="error">' + message + '</div>';
|
|
|
|
} else if (type === 'success') {
|
|
|
|
message = '<div class="success">' + message + '</div>';
|
2017-04-20 10:55:30 +00:00
|
|
|
}
|
2016-10-22 14:57:10 +00:00
|
|
|
// Create a parent element for the AJAX messages, if necessary
|
|
|
|
if ($('#loading_parent').length === 0) {
|
|
|
|
$('<div id="loading_parent"></div>')
|
2018-04-14 09:18:00 +00:00
|
|
|
.prependTo('#page_content');
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
// Update message count to create distinct message elements every time
|
|
|
|
ajax_message_count++;
|
|
|
|
// Remove all old messages, if any
|
2018-04-14 09:18:00 +00:00
|
|
|
$('span.ajax_notification[id^=ajax_message_num]').remove();
|
2016-10-22 14:57:10 +00:00
|
|
|
/**
|
|
|
|
* @var $retval a jQuery object containing the reference
|
|
|
|
* to the created AJAX message
|
|
|
|
*/
|
|
|
|
var $retval = $(
|
2018-04-14 09:18:00 +00:00
|
|
|
'<span class="ajax_notification" id="ajax_message_num_' +
|
2016-10-22 14:57:10 +00:00
|
|
|
ajax_message_count +
|
|
|
|
'"></span>'
|
|
|
|
)
|
2018-04-14 09:18:00 +00:00
|
|
|
.hide()
|
|
|
|
.appendTo('#loading_parent')
|
|
|
|
.html(message)
|
|
|
|
.show();
|
2016-10-22 14:57:10 +00:00
|
|
|
// If the notification is self-closing we should create a callback to remove it
|
|
|
|
if (self_closing) {
|
|
|
|
$retval
|
2018-04-14 09:18:00 +00:00
|
|
|
.delay(timeout)
|
|
|
|
.fadeOut('medium', function () {
|
|
|
|
if ($(this).is(':data(tooltip)')) {
|
|
|
|
$(this).tooltip('destroy');
|
|
|
|
}
|
|
|
|
// Remove the notification
|
|
|
|
$(this).remove();
|
|
|
|
});
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
// If the notification is dismissable we need to add the relevant class to it
|
|
|
|
// and add a tooltip so that the users know that it can be removed
|
|
|
|
if (dismissable) {
|
|
|
|
$retval.addClass('dismissable').css('cursor', 'pointer');
|
|
|
|
/**
|
|
|
|
* Add a tooltip to the notification to let the user know that (s)he
|
|
|
|
* can dismiss the ajax notification by clicking on it.
|
|
|
|
*/
|
|
|
|
PMA_tooltip(
|
|
|
|
$retval,
|
|
|
|
'span',
|
|
|
|
PMA_messages.strDismiss
|
|
|
|
);
|
|
|
|
}
|
|
|
|
PMA_highlightSQL($retval);
|
|
|
|
|
|
|
|
return $retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the message shown for an Ajax operation when it's completed
|
|
|
|
*
|
|
|
|
* @param jQuery object jQuery Element that holds the notification
|
|
|
|
*
|
|
|
|
* @return nothing
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_ajaxRemoveMessage ($this_msgbox) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if ($this_msgbox !== undefined && $this_msgbox instanceof jQuery) {
|
|
|
|
$this_msgbox
|
2018-04-14 09:18:00 +00:00
|
|
|
.stop(true, true)
|
|
|
|
.fadeOut('medium');
|
2016-10-22 14:57:10 +00:00
|
|
|
if ($this_msgbox.is(':data(tooltip)')) {
|
|
|
|
$this_msgbox.tooltip('destroy');
|
|
|
|
} else {
|
|
|
|
$this_msgbox.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Requests SQL for previewing before executing.
|
|
|
|
*
|
|
|
|
* @param jQuery Object $form Form containing query data
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_previewSQL ($form) {
|
2016-10-22 14:57:10 +00:00
|
|
|
var form_url = $form.attr('action');
|
2018-04-14 09:18:00 +00:00
|
|
|
var sep = PMA_commonParams.get('arg_separator');
|
2016-10-22 14:57:10 +00:00
|
|
|
var form_data = $form.serialize() +
|
2018-04-14 09:18:00 +00:00
|
|
|
sep + 'do_save_data=1' +
|
|
|
|
sep + 'preview_sql=1' +
|
|
|
|
sep + 'ajax_request=1';
|
2016-10-22 14:57:10 +00:00
|
|
|
var $msgbox = PMA_ajaxShowMessage();
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: form_url,
|
|
|
|
data: form_data,
|
|
|
|
success: function (response) {
|
|
|
|
PMA_ajaxRemoveMessage($msgbox);
|
|
|
|
if (response.success) {
|
|
|
|
var $dialog_content = $('<div/>')
|
|
|
|
.append(response.sql_data);
|
|
|
|
var button_options = {};
|
|
|
|
button_options[PMA_messages.strClose] = function () {
|
|
|
|
$(this).dialog('close');
|
|
|
|
};
|
|
|
|
var $response_dialog = $dialog_content.dialog({
|
|
|
|
minWidth: 550,
|
|
|
|
maxHeight: 400,
|
|
|
|
modal: true,
|
|
|
|
buttons: button_options,
|
|
|
|
title: PMA_messages.strPreviewSQL,
|
|
|
|
close: function () {
|
|
|
|
$(this).remove();
|
|
|
|
},
|
|
|
|
open: function () {
|
|
|
|
// Pretty SQL printing.
|
|
|
|
PMA_highlightSQL($(this));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
PMA_ajaxShowMessage(response.message);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: function () {
|
|
|
|
PMA_ajaxShowMessage(PMA_messages.strErrorProcessingRequest);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-12-08 07:14:01 +00:00
|
|
|
/**
|
|
|
|
* Callback called when submit/"OK" is clicked on sql preview/confirm modal
|
|
|
|
*
|
|
|
|
* @callback onSubmitCallback
|
|
|
|
* @param {string} url The url
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {string} sql_data Sql query to preview
|
|
|
|
* @param {string} url Url to be sent to callback
|
|
|
|
* @param {onSubmitCallback} callback On submit callback function
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function PMA_confirmPreviewSQL (sql_data, url, callback) {
|
|
|
|
var $dialog_content = $('<div class="preview_sql"><code class="sql"><pre>'
|
|
|
|
+ sql_data
|
|
|
|
+ '</pre></code></div>'
|
|
|
|
);
|
|
|
|
var button_options = [
|
|
|
|
{
|
|
|
|
text: PMA_messages.strOK,
|
|
|
|
class: 'submitOK',
|
|
|
|
click: function () {
|
|
|
|
callback(url);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: PMA_messages.strCancel,
|
|
|
|
class: 'submitCancel',
|
|
|
|
click: function () {
|
|
|
|
$(this).dialog('close');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
var $response_dialog = $dialog_content.dialog({
|
|
|
|
minWidth: 550,
|
|
|
|
maxHeight: 400,
|
|
|
|
modal: true,
|
|
|
|
buttons: button_options,
|
|
|
|
title: PMA_messages.strPreviewSQL,
|
|
|
|
close: function () {
|
|
|
|
$(this).remove();
|
|
|
|
},
|
|
|
|
open: function () {
|
|
|
|
// Pretty SQL printing.
|
|
|
|
PMA_highlightSQL($(this));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-10-22 14:57:10 +00:00
|
|
|
/**
|
|
|
|
* check for reserved keyword column name
|
|
|
|
*
|
|
|
|
* @param jQuery Object $form Form
|
|
|
|
*
|
|
|
|
* @returns true|false
|
|
|
|
*/
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_checkReservedWordColumns ($form) {
|
2016-10-22 14:57:10 +00:00
|
|
|
var is_confirmed = true;
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
2018-04-14 09:18:00 +00:00
|
|
|
url: 'tbl_structure.php',
|
|
|
|
data: $form.serialize() + PMA_commonParams.get('arg_separator') + 'reserved_word_check=1',
|
2016-10-22 14:57:10 +00:00
|
|
|
success: function (data) {
|
2018-04-14 09:18:00 +00:00
|
|
|
if (typeof data.success !== 'undefined' && data.success === true) {
|
2016-10-22 14:57:10 +00:00
|
|
|
is_confirmed = confirm(data.message);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
async:false
|
|
|
|
});
|
|
|
|
return is_confirmed;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This event only need to be fired once after the initial page load
|
|
|
|
$(function () {
|
|
|
|
/**
|
|
|
|
* Allows the user to dismiss a notification
|
|
|
|
* created with PMA_ajaxShowMessage()
|
|
|
|
*/
|
|
|
|
$(document).on('click', 'span.ajax_notification.dismissable', function () {
|
|
|
|
PMA_ajaxRemoveMessage($(this));
|
|
|
|
});
|
|
|
|
/**
|
|
|
|
* The below two functions hide the "Dismiss notification" tooltip when a user
|
|
|
|
* is hovering a link or button that is inside an ajax message
|
|
|
|
*/
|
|
|
|
$(document).on('mouseover', 'span.ajax_notification a, span.ajax_notification button, span.ajax_notification input', function () {
|
|
|
|
if ($(this).parents('span.ajax_notification').is(':data(tooltip)')) {
|
|
|
|
$(this).parents('span.ajax_notification').tooltip('disable');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$(document).on('mouseout', 'span.ajax_notification a, span.ajax_notification button, span.ajax_notification input', function () {
|
|
|
|
if ($(this).parents('span.ajax_notification').is(':data(tooltip)')) {
|
|
|
|
$(this).parents('span.ajax_notification').tooltip('enable');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides/shows the "Open in ENUM/SET editor" message, depending on the data type of the column currently selected
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_showNoticeForEnum (selectElement) {
|
|
|
|
var enum_notice_id = selectElement.attr('id').split('_')[1];
|
|
|
|
enum_notice_id += '_' + (parseInt(selectElement.attr('id').split('_')[2], 10) + 1);
|
2016-10-22 14:57:10 +00:00
|
|
|
var selectedType = selectElement.val();
|
2018-04-14 09:18:00 +00:00
|
|
|
if (selectedType === 'ENUM' || selectedType === 'SET') {
|
|
|
|
$('p#enum_notice_' + enum_notice_id).show();
|
2016-10-22 14:57:10 +00:00
|
|
|
} else {
|
2018-04-14 09:18:00 +00:00
|
|
|
$('p#enum_notice_' + enum_notice_id).hide();
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a Profiling Chart. Used in sql.js
|
|
|
|
* and in server_status_monitor.js
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_createProfilingChart (target, data) {
|
2016-10-22 14:57:10 +00:00
|
|
|
// create the chart
|
|
|
|
var factory = new JQPlotChartFactory();
|
|
|
|
var chart = factory.createChart(ChartType.PIE, target);
|
|
|
|
|
|
|
|
// create the data table and add columns
|
|
|
|
var dataTable = new DataTable();
|
|
|
|
dataTable.addColumn(ColumnType.STRING, '');
|
|
|
|
dataTable.addColumn(ColumnType.NUMBER, '');
|
|
|
|
dataTable.setData(data);
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
var windowWidth = $(window).width();
|
|
|
|
var location = 's';
|
|
|
|
if (windowWidth > 768) {
|
|
|
|
var location = 'se';
|
|
|
|
}
|
|
|
|
|
2016-10-22 14:57:10 +00:00
|
|
|
// draw the chart and return the chart object
|
|
|
|
chart.draw(dataTable, {
|
|
|
|
seriesDefaults: {
|
|
|
|
rendererOptions: {
|
|
|
|
showDataLabels: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
highlighter: {
|
|
|
|
tooltipLocation: 'se',
|
|
|
|
sizeAdjust: 0,
|
|
|
|
tooltipAxes: 'pieref',
|
|
|
|
formatString: '%s, %.9Ps'
|
|
|
|
},
|
|
|
|
legend: {
|
|
|
|
show: true,
|
2018-04-14 09:18:00 +00:00
|
|
|
location: location,
|
2016-10-22 14:57:10 +00:00
|
|
|
rendererOptions: {
|
|
|
|
numberColumns: 2
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// from http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines#Color_Palette
|
|
|
|
seriesColors: [
|
|
|
|
'#fce94f',
|
|
|
|
'#fcaf3e',
|
|
|
|
'#e9b96e',
|
|
|
|
'#8ae234',
|
|
|
|
'#729fcf',
|
|
|
|
'#ad7fa8',
|
|
|
|
'#ef2929',
|
|
|
|
'#888a85',
|
|
|
|
'#c4a000',
|
|
|
|
'#ce5c00',
|
|
|
|
'#8f5902',
|
|
|
|
'#4e9a06',
|
|
|
|
'#204a87',
|
|
|
|
'#5c3566',
|
|
|
|
'#a40000',
|
|
|
|
'#babdb6',
|
|
|
|
'#2e3436'
|
|
|
|
]
|
|
|
|
});
|
|
|
|
return chart;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats a profiling duration nicely (in us and ms time).
|
|
|
|
* Used in server_status_monitor.js
|
|
|
|
*
|
|
|
|
* @param integer Number to be formatted, should be in the range of microsecond to second
|
|
|
|
* @param integer Accuracy, how many numbers right to the comma should be
|
|
|
|
* @return string The formatted number
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_prettyProfilingNum (num, acc) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (!acc) {
|
|
|
|
acc = 2;
|
|
|
|
}
|
|
|
|
acc = Math.pow(10, acc);
|
|
|
|
if (num * 1000 < 0.1) {
|
|
|
|
num = Math.round(acc * (num * 1000 * 1000)) / acc + 'µ';
|
|
|
|
} else if (num < 0.1) {
|
|
|
|
num = Math.round(acc * (num * 1000)) / acc + 'm';
|
|
|
|
} else {
|
|
|
|
num = Math.round(acc * num) / acc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num + 's';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats a SQL Query nicely with newlines and indentation. Depends on Codemirror and MySQL Mode!
|
|
|
|
*
|
|
|
|
* @param string Query to be formatted
|
|
|
|
* @return string The formatted query
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_SQLPrettyPrint (string) {
|
|
|
|
if (typeof CodeMirror === 'undefined') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return string;
|
|
|
|
}
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
var mode = CodeMirror.getMode({}, 'text/x-mysql');
|
2016-10-22 14:57:10 +00:00
|
|
|
var stream = new CodeMirror.StringStream(string);
|
|
|
|
var state = mode.startState();
|
2018-04-14 09:18:00 +00:00
|
|
|
var token;
|
|
|
|
var tokens = [];
|
2016-10-22 14:57:10 +00:00
|
|
|
var output = '';
|
|
|
|
var tabs = function (cnt) {
|
|
|
|
var ret = '';
|
|
|
|
for (var i = 0; i < 4 * cnt; i++) {
|
2018-04-14 09:18:00 +00:00
|
|
|
ret += ' ';
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
// "root-level" statements
|
|
|
|
var statements = {
|
|
|
|
'select': ['select', 'from', 'on', 'where', 'having', 'limit', 'order by', 'group by'],
|
|
|
|
'update': ['update', 'set', 'where'],
|
|
|
|
'insert into': ['insert into', 'values']
|
|
|
|
};
|
|
|
|
// don't put spaces before these tokens
|
2018-04-14 09:18:00 +00:00
|
|
|
var spaceExceptionsBefore = { ';': true, ',': true, '.': true, '(': true };
|
2016-10-22 14:57:10 +00:00
|
|
|
// don't put spaces after these tokens
|
2018-04-14 09:18:00 +00:00
|
|
|
var spaceExceptionsAfter = { '.': true };
|
2016-10-22 14:57:10 +00:00
|
|
|
|
|
|
|
// Populate tokens array
|
|
|
|
var str = '';
|
|
|
|
while (! stream.eol()) {
|
|
|
|
stream.start = stream.pos;
|
|
|
|
token = mode.token(stream, state);
|
|
|
|
if (token !== null) {
|
|
|
|
tokens.push([token, stream.current().toLowerCase()]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var currentStatement = tokens[0][1];
|
|
|
|
|
|
|
|
if (! statements[currentStatement]) {
|
|
|
|
return string;
|
|
|
|
}
|
|
|
|
// Holds all currently opened code blocks (statement, function or generic)
|
|
|
|
var blockStack = [];
|
|
|
|
// Holds the type of block from last iteration (the current is in blockStack[0])
|
|
|
|
var previousBlock;
|
|
|
|
// If a new code block is found, newBlock contains its type for one iteration and vice versa for endBlock
|
2018-04-14 09:18:00 +00:00
|
|
|
var newBlock;
|
|
|
|
var endBlock;
|
2016-10-22 14:57:10 +00:00
|
|
|
// How much to indent in the current line
|
|
|
|
var indentLevel = 0;
|
|
|
|
// Holds the "root-level" statements
|
2018-04-14 09:18:00 +00:00
|
|
|
var statementPart;
|
|
|
|
var lastStatementPart = statements[currentStatement][0];
|
2016-10-22 14:57:10 +00:00
|
|
|
|
|
|
|
blockStack.unshift('statement');
|
|
|
|
|
|
|
|
// Iterate through every token and format accordingly
|
|
|
|
for (var i = 0; i < tokens.length; i++) {
|
|
|
|
previousBlock = blockStack[0];
|
|
|
|
|
|
|
|
// New block => push to stack
|
2018-04-14 09:18:00 +00:00
|
|
|
if (tokens[i][1] === '(') {
|
|
|
|
if (i < tokens.length - 1 && tokens[i + 1][0] === 'statement-verb') {
|
2016-10-22 14:57:10 +00:00
|
|
|
blockStack.unshift(newBlock = 'statement');
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (i > 0 && tokens[i - 1][0] === 'builtin') {
|
2016-10-22 14:57:10 +00:00
|
|
|
blockStack.unshift(newBlock = 'function');
|
|
|
|
} else {
|
|
|
|
blockStack.unshift(newBlock = 'generic');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
newBlock = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Block end => pop from stack
|
2018-04-14 09:18:00 +00:00
|
|
|
if (tokens[i][1] === ')') {
|
2016-10-22 14:57:10 +00:00
|
|
|
endBlock = blockStack[0];
|
|
|
|
blockStack.shift();
|
|
|
|
} else {
|
|
|
|
endBlock = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A subquery is starting
|
2018-04-14 09:18:00 +00:00
|
|
|
if (i > 0 && newBlock === 'statement') {
|
2016-10-22 14:57:10 +00:00
|
|
|
indentLevel++;
|
2018-04-14 09:18:00 +00:00
|
|
|
output += '\n' + tabs(indentLevel) + tokens[i][1] + ' ' + tokens[i + 1][1].toUpperCase() + '\n' + tabs(indentLevel + 1);
|
2016-10-22 14:57:10 +00:00
|
|
|
currentStatement = tokens[i + 1][1];
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// A subquery is ending
|
2018-04-14 09:18:00 +00:00
|
|
|
if (endBlock === 'statement' && indentLevel > 0) {
|
|
|
|
output += '\n' + tabs(indentLevel);
|
2016-10-22 14:57:10 +00:00
|
|
|
indentLevel--;
|
|
|
|
}
|
|
|
|
|
|
|
|
// One less indentation for statement parts (from, where, order by, etc.) and a newline
|
|
|
|
statementPart = statements[currentStatement].indexOf(tokens[i][1]);
|
2018-04-14 09:18:00 +00:00
|
|
|
if (statementPart !== -1) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (i > 0) {
|
2018-04-14 09:18:00 +00:00
|
|
|
output += '\n';
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
output += tabs(indentLevel) + tokens[i][1].toUpperCase();
|
2018-04-14 09:18:00 +00:00
|
|
|
output += '\n' + tabs(indentLevel + 1);
|
2016-10-22 14:57:10 +00:00
|
|
|
lastStatementPart = tokens[i][1];
|
|
|
|
// Normal indentation and spaces for everything else
|
2018-04-14 09:18:00 +00:00
|
|
|
} else {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (! spaceExceptionsBefore[tokens[i][1]] &&
|
|
|
|
! (i > 0 && spaceExceptionsAfter[tokens[i - 1][1]]) &&
|
2018-04-14 09:18:00 +00:00
|
|
|
output.charAt(output.length - 1) !== ' ') {
|
|
|
|
output += ' ';
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
if (tokens[i][0] === 'keyword') {
|
2016-10-22 14:57:10 +00:00
|
|
|
output += tokens[i][1].toUpperCase();
|
|
|
|
} else {
|
|
|
|
output += tokens[i][1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// split columns in select and 'update set' clauses, but only inside statements blocks
|
2018-04-14 09:18:00 +00:00
|
|
|
if ((lastStatementPart === 'select' || lastStatementPart === 'where' || lastStatementPart === 'set') &&
|
|
|
|
tokens[i][1] === ',' && blockStack[0] === 'statement') {
|
|
|
|
output += '\n' + tabs(indentLevel + 1);
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// split conditions in where clauses, but only inside statements blocks
|
2018-04-14 09:18:00 +00:00
|
|
|
if (lastStatementPart === 'where' &&
|
|
|
|
(tokens[i][1] === 'and' || tokens[i][1] === 'or' || tokens[i][1] === 'xor')) {
|
|
|
|
if (blockStack[0] === 'statement') {
|
|
|
|
output += '\n' + tabs(indentLevel + 1);
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
// Todo: Also split and or blocks in newlines & indentation++
|
2018-04-14 09:18:00 +00:00
|
|
|
// if (blockStack[0] === 'generic')
|
|
|
|
// output += ...
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* jQuery function that uses jQueryUI's dialogs to confirm with user. Does not
|
|
|
|
* return a jQuery object yet and hence cannot be chained
|
|
|
|
*
|
|
|
|
* @param string question
|
|
|
|
* @param string url URL to be passed to the callbackFn to make
|
|
|
|
* an Ajax call to
|
|
|
|
* @param function callbackFn callback to execute after user clicks on OK
|
|
|
|
* @param function openCallback optional callback to run when dialog is shown
|
|
|
|
*/
|
|
|
|
|
|
|
|
jQuery.fn.PMA_confirm = function (question, url, callbackFn, openCallback) {
|
|
|
|
var confirmState = PMA_commonParams.get('confirm');
|
|
|
|
if (! confirmState) {
|
|
|
|
// user does not want to confirm
|
|
|
|
if ($.isFunction(callbackFn)) {
|
|
|
|
callbackFn.call(this, url);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (PMA_messages.strDoYouReally === '') {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var button_options Object that stores the options passed to jQueryUI
|
|
|
|
* dialog
|
|
|
|
*/
|
|
|
|
var button_options = [
|
|
|
|
{
|
|
|
|
text: PMA_messages.strOK,
|
|
|
|
'class': 'submitOK',
|
|
|
|
click: function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
$(this).dialog('close');
|
2016-10-22 14:57:10 +00:00
|
|
|
if ($.isFunction(callbackFn)) {
|
|
|
|
callbackFn.call(this, url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: PMA_messages.strCancel,
|
|
|
|
'class': 'submitCancel',
|
|
|
|
click: function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
$(this).dialog('close');
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
$('<div/>', { 'id': 'confirm_dialog', 'title': PMA_messages.strConfirm })
|
|
|
|
.prepend(question)
|
|
|
|
.dialog({
|
|
|
|
buttons: button_options,
|
|
|
|
close: function () {
|
|
|
|
$(this).remove();
|
|
|
|
},
|
|
|
|
open: openCallback,
|
|
|
|
modal: true
|
|
|
|
});
|
2016-10-22 14:57:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* jQuery function to sort a table's body after a new row has been appended to it.
|
|
|
|
*
|
|
|
|
* @param string text_selector string to select the sortKey's text
|
|
|
|
*
|
|
|
|
* @return jQuery Object for chaining purposes
|
|
|
|
*/
|
|
|
|
jQuery.fn.PMA_sort_table = function (text_selector) {
|
|
|
|
return this.each(function () {
|
|
|
|
/**
|
|
|
|
* @var table_body Object referring to the table's <tbody> element
|
|
|
|
*/
|
|
|
|
var table_body = $(this);
|
|
|
|
/**
|
|
|
|
* @var rows Object referring to the collection of rows in {@link table_body}
|
|
|
|
*/
|
|
|
|
var rows = $(this).find('tr').get();
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
// get the text of the field that we will sort by
|
2016-10-22 14:57:10 +00:00
|
|
|
$.each(rows, function (index, row) {
|
|
|
|
row.sortKey = $.trim($(row).find(text_selector).text().toLowerCase());
|
|
|
|
});
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
// get the sorted order
|
2016-10-22 14:57:10 +00:00
|
|
|
rows.sort(function (a, b) {
|
|
|
|
if (a.sortKey < b.sortKey) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.sortKey > b.sortKey) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
// pull out each row from the table and then append it according to it's order
|
2016-10-22 14:57:10 +00:00
|
|
|
$.each(rows, function (index, row) {
|
|
|
|
$(table_body).append(row);
|
|
|
|
row.sortKey = null;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbind all event handlers before tearing down a page
|
|
|
|
*/
|
|
|
|
AJAX.registerTeardown('functions.js', function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).off('submit', '#create_table_form_minimal.ajax');
|
|
|
|
$(document).off('submit', 'form.create_table_form.ajax');
|
|
|
|
$(document).off('click', 'form.create_table_form.ajax input[name=submit_num_fields]');
|
|
|
|
$(document).off('keyup', 'form.create_table_form.ajax input');
|
|
|
|
$(document).off('change', 'input[name=partition_count],input[name=subpartition_count],select[name=partition_by]');
|
2016-10-22 14:57:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* jQuery coding for 'Create Table'. Used on db_operations.php,
|
|
|
|
* db_structure.php and db_tracking.php (i.e., wherever
|
2018-04-14 09:18:00 +00:00
|
|
|
* PhpMyAdmin\Display\CreateTable is used)
|
2016-10-22 14:57:10 +00:00
|
|
|
*
|
|
|
|
* Attach Ajax Event handlers for Create Table
|
|
|
|
*/
|
|
|
|
AJAX.registerOnload('functions.js', function () {
|
|
|
|
/**
|
|
|
|
* Attach event handler for submission of create table form (save)
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('submit', 'form.create_table_form.ajax', function (event) {
|
2016-10-22 14:57:10 +00:00
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var the_form object referring to the create table form
|
|
|
|
*/
|
|
|
|
var $form = $(this);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First validate the form; if there is a problem, avoid submitting it
|
|
|
|
*
|
|
|
|
* checkTableEditForm() needs a pure element and not a jQuery object,
|
|
|
|
* this is why we pass $form[0] as a parameter (the jQuery object
|
|
|
|
* is actually an array of DOM elements)
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (checkTableEditForm($form[0], $form.find('input[name=orig_num_fields]').val())) {
|
|
|
|
PMA_prepareForAjaxRequest($form);
|
|
|
|
if (PMA_checkReservedWordColumns($form)) {
|
|
|
|
PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
|
2018-04-14 09:18:00 +00:00
|
|
|
// User wants to submit the form
|
|
|
|
$.post($form.attr('action'), $form.serialize() + PMA_commonParams.get('arg_separator') + 'do_save_data=1', function (data) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (typeof data !== 'undefined' && data.success === true) {
|
|
|
|
$('#properties_message')
|
2018-04-14 09:18:00 +00:00
|
|
|
.removeClass('error')
|
|
|
|
.html('');
|
2016-10-22 14:57:10 +00:00
|
|
|
PMA_ajaxShowMessage(data.message);
|
|
|
|
// Only if the create table dialog (distinct panel) exists
|
2018-04-14 09:18:00 +00:00
|
|
|
var $createTableDialog = $('#create_table_dialog');
|
2016-10-22 14:57:10 +00:00
|
|
|
if ($createTableDialog.length > 0) {
|
2018-04-14 09:18:00 +00:00
|
|
|
$createTableDialog.dialog('close').remove();
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
$('#tableslistcontainer').before(data.formatted_sql);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var tables_table Object referring to the <tbody> element that holds the list of tables
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
var tables_table = $('#tablesForm').find('tbody').not('#tbl_summary_row');
|
2016-10-22 14:57:10 +00:00
|
|
|
// this is the first table created in this db
|
|
|
|
if (tables_table.length === 0) {
|
|
|
|
PMA_commonActions.refreshMain(
|
|
|
|
PMA_commonParams.get('opendb_url')
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
/**
|
|
|
|
* @var curr_last_row Object referring to the last <tr> element in {@link tables_table}
|
|
|
|
*/
|
|
|
|
var curr_last_row = $(tables_table).find('tr:last');
|
|
|
|
/**
|
|
|
|
* @var curr_last_row_index_string String containing the index of {@link curr_last_row}
|
|
|
|
*/
|
|
|
|
var curr_last_row_index_string = $(curr_last_row).find('input:checkbox').attr('id').match(/\d+/)[0];
|
|
|
|
/**
|
|
|
|
* @var curr_last_row_index Index of {@link curr_last_row}
|
|
|
|
*/
|
|
|
|
var curr_last_row_index = parseFloat(curr_last_row_index_string);
|
|
|
|
/**
|
|
|
|
* @var new_last_row_index Index of the new row to be appended to {@link tables_table}
|
|
|
|
*/
|
|
|
|
var new_last_row_index = curr_last_row_index + 1;
|
|
|
|
/**
|
|
|
|
* @var new_last_row_id String containing the id of the row to be appended to {@link tables_table}
|
|
|
|
*/
|
|
|
|
var new_last_row_id = 'checkbox_tbl_' + new_last_row_index;
|
|
|
|
|
|
|
|
data.new_table_string = data.new_table_string.replace(/checkbox_tbl_/, new_last_row_id);
|
2018-04-14 09:18:00 +00:00
|
|
|
// append to table
|
2016-10-22 14:57:10 +00:00
|
|
|
$(data.new_table_string)
|
2018-04-14 09:18:00 +00:00
|
|
|
.appendTo(tables_table);
|
2016-10-22 14:57:10 +00:00
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
// Sort the table
|
2016-10-22 14:57:10 +00:00
|
|
|
$(tables_table).PMA_sort_table('th');
|
|
|
|
|
|
|
|
// Adjust summary row
|
|
|
|
PMA_adjustTotals();
|
|
|
|
}
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
// Refresh navigation as a new table has been added
|
2016-10-22 14:57:10 +00:00
|
|
|
PMA_reloadNavigation();
|
|
|
|
// Redirect to table structure page on creation of new table
|
2018-04-14 09:18:00 +00:00
|
|
|
var argsep = PMA_commonParams.get('arg_separator');
|
|
|
|
var params_12 = 'ajax_request=true' + argsep + 'ajax_page_request=true';
|
2016-10-22 14:57:10 +00:00
|
|
|
if (! (history && history.pushState)) {
|
|
|
|
params_12 += PMA_MicroHistory.menus.getRequestParam();
|
|
|
|
}
|
|
|
|
tblStruct_url = 'tbl_structure.php?server=' + data._params.server +
|
2018-04-14 09:18:00 +00:00
|
|
|
argsep + 'db=' + data._params.db + argsep + 'token=' + data._params.token +
|
|
|
|
argsep + 'goto=db_structure.php' + argsep + 'table=' + data._params.table + '';
|
2016-10-22 14:57:10 +00:00
|
|
|
$.get(tblStruct_url, params_12, AJAX.responseHandler);
|
|
|
|
} else {
|
|
|
|
PMA_ajaxShowMessage(
|
|
|
|
'<div class="error">' + data.error + '</div>',
|
|
|
|
false
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}); // end $.post()
|
|
|
|
}
|
|
|
|
} // end if (checkTableEditForm() )
|
|
|
|
}); // end create table form (save)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Submits the intermediate changes in the table creation form
|
|
|
|
* to refresh the UI accordingly
|
|
|
|
*/
|
|
|
|
function submitChangesInCreateTableForm (actionParam) {
|
|
|
|
/**
|
|
|
|
* @var the_form object referring to the create table form
|
|
|
|
*/
|
|
|
|
var $form = $('form.create_table_form.ajax');
|
|
|
|
|
|
|
|
var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
|
|
|
|
PMA_prepareForAjaxRequest($form);
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
// User wants to add more fields to the table
|
|
|
|
$.post($form.attr('action'), $form.serialize() + '&' + actionParam, function (data) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (typeof data !== 'undefined' && data.success) {
|
2018-04-14 09:18:00 +00:00
|
|
|
var $pageContent = $('#page_content');
|
2016-10-22 14:57:10 +00:00
|
|
|
$pageContent.html(data.message);
|
|
|
|
PMA_highlightSQL($pageContent);
|
|
|
|
PMA_verifyColumnsProperties();
|
|
|
|
PMA_hideShowConnection($('.create_table_form select[name=tbl_storage_engine]'));
|
|
|
|
PMA_ajaxRemoveMessage($msgbox);
|
|
|
|
} else {
|
|
|
|
PMA_ajaxShowMessage(data.error);
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
}); // end $.post()
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attach event handler for create table form (add fields)
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('click', 'form.create_table_form.ajax input[name=submit_num_fields]', function (event) {
|
2016-10-22 14:57:10 +00:00
|
|
|
event.preventDefault();
|
|
|
|
submitChangesInCreateTableForm('submit_num_fields=1');
|
|
|
|
}); // end create table form (add fields)
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('keydown', 'form.create_table_form.ajax input[name=added_fields]', function (event) {
|
|
|
|
if (event.keyCode === 13) {
|
2016-10-22 14:57:10 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
$(this)
|
|
|
|
.closest('form')
|
|
|
|
.find('input[name=submit_num_fields]')
|
|
|
|
.click();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attach event handler to manage changes in number of partitions and subpartitions
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('change', 'input[name=partition_count],input[name=subpartition_count],select[name=partition_by]', function (event) {
|
2016-10-22 14:57:10 +00:00
|
|
|
$this = $(this);
|
|
|
|
$form = $this.parents('form');
|
2018-04-14 09:18:00 +00:00
|
|
|
if ($form.is('.create_table_form.ajax')) {
|
2016-10-22 14:57:10 +00:00
|
|
|
submitChangesInCreateTableForm('submit_partition_change=1');
|
|
|
|
} else {
|
|
|
|
$form.submit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('change', 'input[value=AUTO_INCREMENT]', function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (this.checked) {
|
|
|
|
var col = /\d/.exec($(this).attr('name'));
|
|
|
|
col = col[0];
|
|
|
|
var $selectFieldKey = $('select[name="field_key[' + col + ']"]');
|
2018-04-14 09:18:00 +00:00
|
|
|
if ($selectFieldKey.val() === 'none_' + col) {
|
|
|
|
$selectFieldKey.val('primary_' + col).change();
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('body')
|
2018-04-14 09:18:00 +00:00
|
|
|
.off('click', 'input.preview_sql')
|
|
|
|
.on('click', 'input.preview_sql', function () {
|
|
|
|
var $form = $(this).closest('form');
|
|
|
|
PMA_previewSQL($form);
|
|
|
|
});
|
2016-10-22 14:57:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validates the password field in a form
|
|
|
|
*
|
|
|
|
* @see PMA_messages.strPasswordEmpty
|
|
|
|
* @see PMA_messages.strPasswordNotSame
|
|
|
|
* @param object $the_form The form to be validated
|
|
|
|
* @return bool
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_checkPassword ($the_form) {
|
2016-10-22 14:57:10 +00:00
|
|
|
// Did the user select 'no password'?
|
|
|
|
if ($the_form.find('#nopass_1').is(':checked')) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
var $pred = $the_form.find('#select_pred_password');
|
2018-04-14 09:18:00 +00:00
|
|
|
if ($pred.length && ($pred.val() === 'none' || $pred.val() === 'keep')) {
|
2016-10-22 14:57:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var $password = $the_form.find('input[name=pma_pw]');
|
|
|
|
var $password_repeat = $the_form.find('input[name=pma_pw2]');
|
|
|
|
var alert_msg = false;
|
|
|
|
|
|
|
|
if ($password.val() === '') {
|
|
|
|
alert_msg = PMA_messages.strPasswordEmpty;
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if ($password.val() !== $password_repeat.val()) {
|
2016-10-22 14:57:10 +00:00
|
|
|
alert_msg = PMA_messages.strPasswordNotSame;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alert_msg) {
|
|
|
|
alert(alert_msg);
|
|
|
|
$password.val('');
|
|
|
|
$password_repeat.val('');
|
|
|
|
$password.focus();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attach Ajax event handlers for 'Change Password' on index.php
|
|
|
|
*/
|
|
|
|
AJAX.registerOnload('functions.js', function () {
|
|
|
|
/* Handler for hostname type */
|
|
|
|
$(document).on('change', '#select_pred_hostname', function () {
|
|
|
|
var hostname = $('#pma_hostname');
|
2018-04-14 09:18:00 +00:00
|
|
|
if (this.value === 'any') {
|
2016-10-22 14:57:10 +00:00
|
|
|
hostname.val('%');
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (this.value === 'localhost') {
|
2016-10-22 14:57:10 +00:00
|
|
|
hostname.val('localhost');
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (this.value === 'thishost' && $(this).data('thishost')) {
|
2016-10-22 14:57:10 +00:00
|
|
|
hostname.val($(this).data('thishost'));
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (this.value === 'hosttable') {
|
2016-10-22 14:57:10 +00:00
|
|
|
hostname.val('').prop('required', false);
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (this.value === 'userdefined') {
|
2016-10-22 14:57:10 +00:00
|
|
|
hostname.focus().select().prop('required', true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Handler for editing hostname */
|
|
|
|
$(document).on('change', '#pma_hostname', function () {
|
|
|
|
$('#select_pred_hostname').val('userdefined');
|
|
|
|
$('#pma_hostname').prop('required', true);
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Handler for username type */
|
|
|
|
$(document).on('change', '#select_pred_username', function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
if (this.value === 'any') {
|
2016-10-22 14:57:10 +00:00
|
|
|
$('#pma_username').val('').prop('required', false);
|
|
|
|
$('#user_exists_warning').css('display', 'none');
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (this.value === 'userdefined') {
|
2016-10-22 14:57:10 +00:00
|
|
|
$('#pma_username').focus().select().prop('required', true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Handler for editing username */
|
|
|
|
$(document).on('change', '#pma_username', function () {
|
|
|
|
$('#select_pred_username').val('userdefined');
|
|
|
|
$('#pma_username').prop('required', true);
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Handler for password type */
|
|
|
|
$(document).on('change', '#select_pred_password', function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
if (this.value === 'none') {
|
2016-10-22 14:57:10 +00:00
|
|
|
$('#text_pma_pw2').prop('required', false).val('');
|
|
|
|
$('#text_pma_pw').prop('required', false).val('');
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (this.value === 'userdefined') {
|
2016-10-22 14:57:10 +00:00
|
|
|
$('#text_pma_pw2').prop('required', true);
|
|
|
|
$('#text_pma_pw').prop('required', true).focus().select();
|
|
|
|
} else {
|
|
|
|
$('#text_pma_pw2').prop('required', false);
|
|
|
|
$('#text_pma_pw').prop('required', false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Handler for editing password */
|
|
|
|
$(document).on('change', '#text_pma_pw,#text_pma_pw2', function () {
|
|
|
|
$('#select_pred_password').val('userdefined');
|
|
|
|
$('#text_pma_pw2').prop('required', true);
|
|
|
|
$('#text_pma_pw').prop('required', true);
|
|
|
|
});
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
/**
|
|
|
|
* Unbind all event handlers before tearing down a page
|
|
|
|
*/
|
|
|
|
$(document).off('click', '#change_password_anchor.ajax');
|
|
|
|
|
2016-10-22 14:57:10 +00:00
|
|
|
/**
|
|
|
|
* Attach Ajax event handler on the change password anchor
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
|
2016-10-22 14:57:10 +00:00
|
|
|
$(document).on('click', '#change_password_anchor.ajax', function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
var $msgbox = PMA_ajaxShowMessage();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var button_options Object containing options to be passed to jQueryUI's dialog
|
|
|
|
*/
|
|
|
|
var button_options = {};
|
|
|
|
button_options[PMA_messages.strGo] = function () {
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var $the_form Object referring to the change password form
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
var $the_form = $('#change_password_form');
|
2016-10-22 14:57:10 +00:00
|
|
|
|
|
|
|
if (! PMA_checkPassword($the_form)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var this_value String containing the value of the submit button.
|
|
|
|
* Need to append this for the change password form on Server Privileges
|
|
|
|
* page to work
|
|
|
|
*/
|
|
|
|
var this_value = $(this).val();
|
|
|
|
|
|
|
|
var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
|
|
|
|
$the_form.append('<input type="hidden" name="ajax_request" value="true" />');
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
$.post($the_form.attr('action'), $the_form.serialize() + PMA_commonParams.get('arg_separator') + 'change_pw=' + this_value, function (data) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (typeof data === 'undefined' || data.success !== true) {
|
|
|
|
PMA_ajaxShowMessage(data.error, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
var $pageContent = $('#page_content');
|
2016-10-22 14:57:10 +00:00
|
|
|
$pageContent.prepend(data.message);
|
|
|
|
PMA_highlightSQL($pageContent);
|
2018-04-14 09:18:00 +00:00
|
|
|
$('#change_password_dialog').hide().remove();
|
|
|
|
$('#edit_user_dialog').dialog('close').remove();
|
2016-10-22 14:57:10 +00:00
|
|
|
PMA_ajaxRemoveMessage($msgbox);
|
|
|
|
}); // end $.post()
|
|
|
|
};
|
|
|
|
|
|
|
|
button_options[PMA_messages.strCancel] = function () {
|
|
|
|
$(this).dialog('close');
|
|
|
|
};
|
2018-04-14 09:18:00 +00:00
|
|
|
$.get($(this).attr('href'), { 'ajax_request': true }, function (data) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (typeof data === 'undefined' || !data.success) {
|
|
|
|
PMA_ajaxShowMessage(data.error, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-20 10:55:30 +00:00
|
|
|
if (data._scripts) {
|
|
|
|
AJAX.scriptHandler.load(data._scripts);
|
|
|
|
}
|
|
|
|
|
2016-10-22 14:57:10 +00:00
|
|
|
$('<div id="change_password_dialog"></div>')
|
|
|
|
.dialog({
|
|
|
|
title: PMA_messages.strChangePassword,
|
|
|
|
width: 600,
|
|
|
|
close: function (ev, ui) {
|
|
|
|
$(this).remove();
|
|
|
|
},
|
|
|
|
buttons: button_options,
|
|
|
|
modal: true
|
|
|
|
})
|
|
|
|
.append(data.message);
|
|
|
|
// for this dialog, we remove the fieldset wrapping due to double headings
|
2018-04-14 09:18:00 +00:00
|
|
|
$('fieldset#fieldset_change_password')
|
|
|
|
.find('legend').remove().end()
|
|
|
|
.find('table.noclick').unwrap().addClass('some-margin')
|
|
|
|
.find('input#text_pma_pw').focus();
|
2016-10-22 14:57:10 +00:00
|
|
|
$('#fieldset_change_password_footer').hide();
|
|
|
|
PMA_ajaxRemoveMessage($msgbox);
|
2019-12-08 07:14:01 +00:00
|
|
|
displayPasswordGenerateButton();
|
2018-04-14 09:18:00 +00:00
|
|
|
$('#change_password_form').on('submit', function (e) {
|
2016-10-22 14:57:10 +00:00
|
|
|
e.preventDefault();
|
|
|
|
$(this)
|
|
|
|
.closest('.ui-dialog')
|
|
|
|
.find('.ui-dialog-buttonpane .ui-button')
|
|
|
|
.first()
|
|
|
|
.click();
|
|
|
|
});
|
|
|
|
}); // end $.get()
|
|
|
|
}); // end handler for change password anchor
|
|
|
|
}); // end $() for Change Password
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbind all event handlers before tearing down a page
|
|
|
|
*/
|
|
|
|
AJAX.registerTeardown('functions.js', function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).off('change', 'select.column_type');
|
|
|
|
$(document).off('change', 'select.default_type');
|
|
|
|
$(document).off('change', 'select.virtuality');
|
2016-10-22 14:57:10 +00:00
|
|
|
$(document).off('change', 'input.allow_null');
|
|
|
|
$(document).off('change', '.create_table_form select[name=tbl_storage_engine]');
|
|
|
|
});
|
|
|
|
/**
|
|
|
|
* Toggle the hiding/showing of the "Open in ENUM/SET editor" message when
|
|
|
|
* the page loads and when the selected data type changes
|
|
|
|
*/
|
|
|
|
AJAX.registerOnload('functions.js', function () {
|
|
|
|
// is called here for normal page loads and also when opening
|
|
|
|
// the Create table dialog
|
|
|
|
PMA_verifyColumnsProperties();
|
|
|
|
//
|
|
|
|
// needs on() to work also in the Create Table dialog
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('change', 'select.column_type', function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
PMA_showNoticeForEnum($(this));
|
|
|
|
});
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('change', 'select.default_type', function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
PMA_hideShowDefaultValue($(this));
|
|
|
|
});
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('change', 'select.virtuality', function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
PMA_hideShowExpression($(this));
|
|
|
|
});
|
|
|
|
$(document).on('change', 'input.allow_null', function () {
|
|
|
|
PMA_validateDefaultValue($(this));
|
|
|
|
});
|
|
|
|
$(document).on('change', '.create_table_form select[name=tbl_storage_engine]', function () {
|
|
|
|
PMA_hideShowConnection($(this));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the chosen storage engine is FEDERATED show connection field. Hide otherwise
|
|
|
|
*
|
|
|
|
* @param $engine_selector storage engine selector
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_hideShowConnection ($engine_selector) {
|
2016-10-22 14:57:10 +00:00
|
|
|
var $connection = $('.create_table_form input[name=connection]');
|
|
|
|
var index = $connection.parent('td').index() + 1;
|
|
|
|
var $labelTh = $connection.parents('tr').prev('tr').children('th:nth-child(' + index + ')');
|
2018-04-14 09:18:00 +00:00
|
|
|
if ($engine_selector.val() !== 'FEDERATED') {
|
2016-10-22 14:57:10 +00:00
|
|
|
$connection
|
|
|
|
.prop('disabled', true)
|
|
|
|
.parent('td').hide();
|
|
|
|
$labelTh.hide();
|
|
|
|
} else {
|
|
|
|
$connection
|
|
|
|
.prop('disabled', false)
|
|
|
|
.parent('td').show();
|
|
|
|
$labelTh.show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If the column does not allow NULL values, makes sure that default is not NULL
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_validateDefaultValue ($null_checkbox) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (! $null_checkbox.prop('checked')) {
|
|
|
|
var $default = $null_checkbox.closest('tr').find('.default_type');
|
2018-04-14 09:18:00 +00:00
|
|
|
if ($default.val() === 'NULL') {
|
2016-10-22 14:57:10 +00:00
|
|
|
$default.val('NONE');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* function to populate the input fields on picking a column from central list
|
|
|
|
*
|
|
|
|
* @param string input_id input id of the name field for the column to be populated
|
|
|
|
* @param integer offset of the selected column in central list of columns
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function autoPopulate (input_id, offset) {
|
2016-10-22 14:57:10 +00:00
|
|
|
var db = PMA_commonParams.get('db');
|
|
|
|
var table = PMA_commonParams.get('table');
|
|
|
|
input_id = input_id.substring(0, input_id.length - 1);
|
|
|
|
$('#' + input_id + '1').val(central_column_list[db + '_' + table][offset].col_name);
|
|
|
|
var col_type = central_column_list[db + '_' + table][offset].col_type.toUpperCase();
|
|
|
|
$('#' + input_id + '2').val(col_type);
|
|
|
|
var $input3 = $('#' + input_id + '3');
|
|
|
|
$input3.val(central_column_list[db + '_' + table][offset].col_length);
|
2018-04-14 09:18:00 +00:00
|
|
|
if (col_type === 'ENUM' || col_type === 'SET') {
|
2016-10-22 14:57:10 +00:00
|
|
|
$input3.next().show();
|
|
|
|
} else {
|
|
|
|
$input3.next().hide();
|
|
|
|
}
|
|
|
|
var col_default = central_column_list[db + '_' + table][offset].col_default.toUpperCase();
|
|
|
|
var $input4 = $('#' + input_id + '4');
|
2018-12-16 14:31:03 +00:00
|
|
|
if (col_default !== '' && col_default !== 'NULL' && col_default !== 'CURRENT_TIMESTAMP' && col_default !== 'CURRENT_TIMESTAMP()') {
|
2018-04-14 09:18:00 +00:00
|
|
|
$input4.val('USER_DEFINED');
|
2016-10-22 14:57:10 +00:00
|
|
|
$input4.next().next().show();
|
|
|
|
$input4.next().next().val(central_column_list[db + '_' + table][offset].col_default);
|
|
|
|
} else {
|
|
|
|
$input4.val(central_column_list[db + '_' + table][offset].col_default);
|
|
|
|
$input4.next().next().hide();
|
|
|
|
}
|
|
|
|
$('#' + input_id + '5').val(central_column_list[db + '_' + table][offset].col_collation);
|
|
|
|
var $input6 = $('#' + input_id + '6');
|
|
|
|
$input6.val(central_column_list[db + '_' + table][offset].col_attribute);
|
2018-04-14 09:18:00 +00:00
|
|
|
if (central_column_list[db + '_' + table][offset].col_extra === 'on update CURRENT_TIMESTAMP') {
|
2016-10-22 14:57:10 +00:00
|
|
|
$input6.val(central_column_list[db + '_' + table][offset].col_extra);
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
if (central_column_list[db + '_' + table][offset].col_extra.toUpperCase() === 'AUTO_INCREMENT') {
|
|
|
|
$('#' + input_id + '9').prop('checked',true).change();
|
2016-10-22 14:57:10 +00:00
|
|
|
} else {
|
2018-04-14 09:18:00 +00:00
|
|
|
$('#' + input_id + '9').prop('checked',false);
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
if (central_column_list[db + '_' + table][offset].col_isNull !== '0') {
|
|
|
|
$('#' + input_id + '7').prop('checked',true);
|
2016-10-22 14:57:10 +00:00
|
|
|
} else {
|
2018-04-14 09:18:00 +00:00
|
|
|
$('#' + input_id + '7').prop('checked',false);
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbind all event handlers before tearing down a page
|
|
|
|
*/
|
|
|
|
AJAX.registerTeardown('functions.js', function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).off('click', 'a.open_enum_editor');
|
|
|
|
$(document).off('click', 'input.add_value');
|
|
|
|
$(document).off('click', '#enum_editor td.drop');
|
2016-10-22 14:57:10 +00:00
|
|
|
$(document).off('click', 'a.central_columns_dialog');
|
|
|
|
});
|
|
|
|
/**
|
|
|
|
* @var $enum_editor_dialog An object that points to the jQuery
|
|
|
|
* dialog of the ENUM/SET editor
|
|
|
|
*/
|
|
|
|
var $enum_editor_dialog = null;
|
|
|
|
/**
|
|
|
|
* Opens the ENUM/SET editor and controls its functions
|
|
|
|
*/
|
|
|
|
AJAX.registerOnload('functions.js', function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('click', 'a.open_enum_editor', function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
// Get the name of the column that is being edited
|
|
|
|
var colname = $(this).closest('tr').find('input:first').val();
|
|
|
|
var title;
|
|
|
|
var i;
|
|
|
|
// And use it to make up a title for the page
|
|
|
|
if (colname.length < 1) {
|
|
|
|
title = PMA_messages.enum_newColumnVals;
|
|
|
|
} else {
|
|
|
|
title = PMA_messages.enum_columnVals.replace(
|
|
|
|
/%s/,
|
|
|
|
'"' + escapeHtml(decodeURIComponent(colname)) + '"'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// Get the values as a string
|
|
|
|
var inputstring = $(this)
|
|
|
|
.closest('td')
|
2018-04-14 09:18:00 +00:00
|
|
|
.find('input')
|
2016-10-22 14:57:10 +00:00
|
|
|
.val();
|
|
|
|
// Escape html entities
|
|
|
|
inputstring = $('<div/>')
|
|
|
|
.text(inputstring)
|
|
|
|
.html();
|
|
|
|
// Parse the values, escaping quotes and
|
|
|
|
// slashes on the fly, into an array
|
|
|
|
var values = [];
|
|
|
|
var in_string = false;
|
2018-04-14 09:18:00 +00:00
|
|
|
var curr;
|
|
|
|
var next;
|
|
|
|
var buffer = '';
|
2016-10-22 14:57:10 +00:00
|
|
|
for (i = 0; i < inputstring.length; i++) {
|
|
|
|
curr = inputstring.charAt(i);
|
2018-04-14 09:18:00 +00:00
|
|
|
next = i === inputstring.length ? '' : inputstring.charAt(i + 1);
|
|
|
|
if (! in_string && curr === '\'') {
|
2016-10-22 14:57:10 +00:00
|
|
|
in_string = true;
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (in_string && curr === '\\' && next === '\\') {
|
|
|
|
buffer += '\';
|
2016-10-22 14:57:10 +00:00
|
|
|
i++;
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (in_string && next === '\'' && (curr === '\'' || curr === '\\')) {
|
|
|
|
buffer += ''';
|
2016-10-22 14:57:10 +00:00
|
|
|
i++;
|
2018-04-14 09:18:00 +00:00
|
|
|
} else if (in_string && curr === '\'') {
|
2016-10-22 14:57:10 +00:00
|
|
|
in_string = false;
|
|
|
|
values.push(buffer);
|
|
|
|
buffer = '';
|
|
|
|
} else if (in_string) {
|
|
|
|
buffer += curr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (buffer.length > 0) {
|
|
|
|
// The leftovers in the buffer are the last value (if any)
|
|
|
|
values.push(buffer);
|
|
|
|
}
|
|
|
|
var fields = '';
|
|
|
|
// If there are no values, maybe the user is about to make a
|
|
|
|
// new list so we add a few for him/her to get started with.
|
|
|
|
if (values.length === 0) {
|
|
|
|
values.push('', '', '', '');
|
|
|
|
}
|
|
|
|
// Add the parsed values to the editor
|
2018-04-14 09:18:00 +00:00
|
|
|
var drop_icon = PMA_getImage('b_drop');
|
2016-10-22 14:57:10 +00:00
|
|
|
for (i = 0; i < values.length; i++) {
|
2018-04-14 09:18:00 +00:00
|
|
|
fields += '<tr><td>' +
|
|
|
|
'<input type=\'text\' value=\'' + values[i] + '\'/>' +
|
|
|
|
'</td><td class=\'drop\'>' +
|
2016-10-22 14:57:10 +00:00
|
|
|
drop_icon +
|
2018-04-14 09:18:00 +00:00
|
|
|
'</td></tr>';
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @var dialog HTML code for the ENUM/SET dialog
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
var dialog = '<div id=\'enum_editor\'>' +
|
|
|
|
'<fieldset>' +
|
|
|
|
'<legend>' + title + '</legend>' +
|
|
|
|
'<p>' + PMA_getImage('s_notice') +
|
|
|
|
PMA_messages.enum_hint + '</p>' +
|
|
|
|
'<table class=\'values\'>' + fields + '</table>' +
|
|
|
|
'</fieldset><fieldset class=\'tblFooters\'>' +
|
|
|
|
'<table class=\'add\'><tr><td>' +
|
|
|
|
'<div class=\'slider\'></div>' +
|
|
|
|
'</td><td>' +
|
|
|
|
'<form><div><input type=\'submit\' class=\'add_value\' value=\'' +
|
2016-10-22 14:57:10 +00:00
|
|
|
PMA_sprintf(PMA_messages.enum_addValue, 1) +
|
2018-04-14 09:18:00 +00:00
|
|
|
'\'/></div></form>' +
|
|
|
|
'</td></tr></table>' +
|
|
|
|
'<input type=\'hidden\' value=\'' + // So we know which column's data is being edited
|
|
|
|
$(this).closest('td').find('input').attr('id') +
|
|
|
|
'\' />' +
|
|
|
|
'</fieldset>' +
|
|
|
|
'</div>';
|
2016-10-22 14:57:10 +00:00
|
|
|
/**
|
|
|
|
* @var Defines functions to be called when the buttons in
|
|
|
|
* the buttonOptions jQuery dialog bar are pressed
|
|
|
|
*/
|
|
|
|
var buttonOptions = {};
|
|
|
|
buttonOptions[PMA_messages.strGo] = function () {
|
|
|
|
// When the submit button is clicked,
|
|
|
|
// put the data back into the original form
|
|
|
|
var value_array = [];
|
2018-04-14 09:18:00 +00:00
|
|
|
$(this).find('.values input').each(function (index, elm) {
|
|
|
|
var val = elm.value.replace(/\\/g, '\\\\').replace(/'/g, '\'\'');
|
|
|
|
value_array.push('\'' + val + '\'');
|
2016-10-22 14:57:10 +00:00
|
|
|
});
|
|
|
|
// get the Length/Values text field where this value belongs
|
2018-04-14 09:18:00 +00:00
|
|
|
var values_id = $(this).find('input[type=\'hidden\']').val();
|
|
|
|
$('input#' + values_id).val(value_array.join(','));
|
|
|
|
$(this).dialog('close');
|
2016-10-22 14:57:10 +00:00
|
|
|
};
|
|
|
|
buttonOptions[PMA_messages.strClose] = function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
$(this).dialog('close');
|
2016-10-22 14:57:10 +00:00
|
|
|
};
|
|
|
|
// Show the dialog
|
|
|
|
var width = parseInt(
|
|
|
|
(parseInt($('html').css('font-size'), 10) / 13) * 340,
|
|
|
|
10
|
|
|
|
);
|
|
|
|
if (! width) {
|
|
|
|
width = 340;
|
|
|
|
}
|
|
|
|
$enum_editor_dialog = $(dialog).dialog({
|
|
|
|
minWidth: width,
|
|
|
|
maxHeight: 450,
|
|
|
|
modal: true,
|
|
|
|
title: PMA_messages.enum_editor,
|
|
|
|
buttons: buttonOptions,
|
|
|
|
open: function () {
|
|
|
|
// Focus the "Go" button after opening the dialog
|
|
|
|
$(this).closest('.ui-dialog').find('.ui-dialog-buttonpane button:first').focus();
|
|
|
|
},
|
|
|
|
close: function () {
|
|
|
|
$(this).remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// slider for choosing how many fields to add
|
2018-04-14 09:18:00 +00:00
|
|
|
$enum_editor_dialog.find('.slider').slider({
|
2016-10-22 14:57:10 +00:00
|
|
|
animate: true,
|
2018-04-14 09:18:00 +00:00
|
|
|
range: 'min',
|
2016-10-22 14:57:10 +00:00
|
|
|
value: 1,
|
|
|
|
min: 1,
|
|
|
|
max: 9,
|
|
|
|
slide: function (event, ui) {
|
|
|
|
$(this).closest('table').find('input[type=submit]').val(
|
|
|
|
PMA_sprintf(PMA_messages.enum_addValue, ui.value)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Focus the slider, otherwise it looks nearly transparent
|
|
|
|
$('a.ui-slider-handle').addClass('ui-state-focus');
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
$(document).on('click', 'a.central_columns_dialog', function (e) {
|
2018-04-14 09:18:00 +00:00
|
|
|
var href = 'db_central_columns.php';
|
2016-10-22 14:57:10 +00:00
|
|
|
var db = PMA_commonParams.get('db');
|
|
|
|
var table = PMA_commonParams.get('table');
|
|
|
|
var maxRows = $(this).data('maxrows');
|
|
|
|
var pick = $(this).data('pick');
|
|
|
|
if (pick !== false) {
|
|
|
|
pick = true;
|
|
|
|
}
|
|
|
|
var params = {
|
|
|
|
'ajax_request' : true,
|
|
|
|
'server' : PMA_commonParams.get('server'),
|
|
|
|
'db' : PMA_commonParams.get('db'),
|
|
|
|
'cur_table' : PMA_commonParams.get('table'),
|
|
|
|
'getColumnList':true
|
|
|
|
};
|
2018-04-14 09:18:00 +00:00
|
|
|
var colid = $(this).closest('td').find('input').attr('id');
|
2016-10-22 14:57:10 +00:00
|
|
|
var fields = '';
|
|
|
|
if (! (db + '_' + table in central_column_list)) {
|
|
|
|
central_column_list.push(db + '_' + table);
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: href,
|
|
|
|
data: params,
|
|
|
|
success: function (data) {
|
2017-04-20 10:55:30 +00:00
|
|
|
central_column_list[db + '_' + table] = JSON.parse(data.message);
|
2016-10-22 14:57:10 +00:00
|
|
|
},
|
|
|
|
async:false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
var i = 0;
|
|
|
|
var list_size = central_column_list[db + '_' + table].length;
|
|
|
|
var min = (list_size <= maxRows) ? list_size : maxRows;
|
|
|
|
for (i = 0; i < min; i++) {
|
2018-04-14 09:18:00 +00:00
|
|
|
fields += '<tr><td><div><span class="font_weight_bold">' +
|
2016-10-22 14:57:10 +00:00
|
|
|
escapeHtml(central_column_list[db + '_' + table][i].col_name) +
|
2018-04-14 09:18:00 +00:00
|
|
|
'</span><br><span class="color_gray">' + central_column_list[db + '_' + table][i].col_type;
|
2016-10-22 14:57:10 +00:00
|
|
|
|
|
|
|
if (central_column_list[db + '_' + table][i].col_attribute !== '') {
|
|
|
|
fields += '(' + escapeHtml(central_column_list[db + '_' + table][i].col_attribute) + ') ';
|
|
|
|
}
|
|
|
|
if (central_column_list[db + '_' + table][i].col_length !== '') {
|
2018-04-14 09:18:00 +00:00
|
|
|
fields += '(' + escapeHtml(central_column_list[db + '_' + table][i].col_length) + ') ';
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
fields += escapeHtml(central_column_list[db + '_' + table][i].col_extra) + '</span>' +
|
|
|
|
'</div></td>';
|
|
|
|
if (pick) {
|
2018-04-14 09:18:00 +00:00
|
|
|
fields += '<td><input class="pick all100" type="submit" value="' +
|
2016-10-22 14:57:10 +00:00
|
|
|
PMA_messages.pickColumn + '" onclick="autoPopulate(\'' + colid + '\',' + i + ')"/></td>';
|
|
|
|
}
|
|
|
|
fields += '</tr>';
|
|
|
|
}
|
|
|
|
var result_pointer = i;
|
|
|
|
var search_in = '<input type="text" class="filter_rows" placeholder="' + PMA_messages.searchList + '">';
|
|
|
|
if (fields === '') {
|
2018-04-14 09:18:00 +00:00
|
|
|
fields = PMA_sprintf(PMA_messages.strEmptyCentralList, '\'' + escapeHtml(db) + '\'');
|
2016-10-22 14:57:10 +00:00
|
|
|
search_in = '';
|
|
|
|
}
|
|
|
|
var seeMore = '';
|
|
|
|
if (list_size > maxRows) {
|
2018-04-14 09:18:00 +00:00
|
|
|
seeMore = '<fieldset class=\'tblFooters center\' style=\'font-weight:bold\'>' +
|
|
|
|
'<a href=\'#\' id=\'seeMore\'>' + PMA_messages.seeMore + '</a></fieldset>';
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
var central_columns_dialog = '<div style=\'max-height:400px\'>' +
|
|
|
|
'<fieldset>' +
|
2016-10-22 14:57:10 +00:00
|
|
|
search_in +
|
2018-04-14 09:18:00 +00:00
|
|
|
'<table id=\'col_list\' style=\'width:100%\' class=\'values\'>' + fields + '</table>' +
|
|
|
|
'</fieldset>' +
|
2016-10-22 14:57:10 +00:00
|
|
|
seeMore +
|
2018-04-14 09:18:00 +00:00
|
|
|
'</div>';
|
2016-10-22 14:57:10 +00:00
|
|
|
|
|
|
|
var width = parseInt(
|
|
|
|
(parseInt($('html').css('font-size'), 10) / 13) * 500,
|
|
|
|
10
|
|
|
|
);
|
|
|
|
if (! width) {
|
|
|
|
width = 500;
|
|
|
|
}
|
|
|
|
var buttonOptions = {};
|
|
|
|
var $central_columns_dialog = $(central_columns_dialog).dialog({
|
|
|
|
minWidth: width,
|
|
|
|
maxHeight: 450,
|
|
|
|
modal: true,
|
|
|
|
title: PMA_messages.pickColumnTitle,
|
|
|
|
buttons: buttonOptions,
|
|
|
|
open: function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
$('#col_list').on('click', '.pick', function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
$central_columns_dialog.remove();
|
|
|
|
});
|
2018-04-14 09:18:00 +00:00
|
|
|
$('.filter_rows').on('keyup', function () {
|
|
|
|
$.uiTableFilter($('#col_list'), $(this).val());
|
2016-10-22 14:57:10 +00:00
|
|
|
});
|
2018-04-14 09:18:00 +00:00
|
|
|
$('#seeMore').click(function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
fields = '';
|
|
|
|
min = (list_size <= maxRows + result_pointer) ? list_size : maxRows + result_pointer;
|
|
|
|
for (i = result_pointer; i < min; i++) {
|
2018-04-14 09:18:00 +00:00
|
|
|
fields += '<tr><td><div><span class="font_weight_bold">' +
|
2016-10-22 14:57:10 +00:00
|
|
|
central_column_list[db + '_' + table][i].col_name +
|
2018-04-14 09:18:00 +00:00
|
|
|
'</span><br><span class="color_gray">' +
|
2016-10-22 14:57:10 +00:00
|
|
|
central_column_list[db + '_' + table][i].col_type;
|
|
|
|
|
|
|
|
if (central_column_list[db + '_' + table][i].col_attribute !== '') {
|
|
|
|
fields += '(' + central_column_list[db + '_' + table][i].col_attribute + ') ';
|
|
|
|
}
|
|
|
|
if (central_column_list[db + '_' + table][i].col_length !== '') {
|
|
|
|
fields += '(' + central_column_list[db + '_' + table][i].col_length + ') ';
|
|
|
|
}
|
|
|
|
fields += central_column_list[db + '_' + table][i].col_extra + '</span>' +
|
|
|
|
'</div></td>';
|
|
|
|
if (pick) {
|
2018-04-14 09:18:00 +00:00
|
|
|
fields += '<td><input class="pick all100" type="submit" value="' +
|
2016-10-22 14:57:10 +00:00
|
|
|
PMA_messages.pickColumn + '" onclick="autoPopulate(\'' + colid + '\',' + i + ')"/></td>';
|
|
|
|
}
|
|
|
|
fields += '</tr>';
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
$('#col_list').append(fields);
|
2016-10-22 14:57:10 +00:00
|
|
|
result_pointer = i;
|
|
|
|
if (result_pointer === list_size) {
|
|
|
|
$('.tblFooters').hide();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$(this).closest('.ui-dialog').find('.ui-dialog-buttonpane button:first').focus();
|
|
|
|
},
|
|
|
|
close: function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
$('#col_list').off('click', '.pick');
|
|
|
|
$('.filter_rows').off('keyup');
|
2016-10-22 14:57:10 +00:00
|
|
|
$(this).remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
// $(document).on('click', 'a.show_central_list',function(e) {
|
2016-10-22 14:57:10 +00:00
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
// });
|
2016-10-22 14:57:10 +00:00
|
|
|
// When "add a new value" is clicked, append an empty text field
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('click', 'input.add_value', function (e) {
|
2016-10-22 14:57:10 +00:00
|
|
|
e.preventDefault();
|
2018-04-14 09:18:00 +00:00
|
|
|
var num_new_rows = $enum_editor_dialog.find('div.slider').slider('value');
|
2016-10-22 14:57:10 +00:00
|
|
|
while (num_new_rows--) {
|
|
|
|
$enum_editor_dialog.find('.values')
|
|
|
|
.append(
|
2018-04-14 09:18:00 +00:00
|
|
|
'<tr class=\'hide\'><td>' +
|
|
|
|
'<input type=\'text\' />' +
|
|
|
|
'</td><td class=\'drop\'>' +
|
|
|
|
PMA_getImage('b_drop') +
|
|
|
|
'</td></tr>'
|
2016-10-22 14:57:10 +00:00
|
|
|
)
|
|
|
|
.find('tr:last')
|
|
|
|
.show('fast');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Removes the specified row from the enum editor
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('click', '#enum_editor td.drop', function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
$(this).closest('tr').hide('fast', function () {
|
|
|
|
$(this).remove();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensures indexes names are valid according to their type and, for a primary
|
|
|
|
* key, lock index name to 'PRIMARY'
|
|
|
|
* @param string form_id Variable which parses the form name as
|
|
|
|
* the input
|
|
|
|
* @return boolean false if there is no index form, true else
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function checkIndexName (form_id) {
|
|
|
|
if ($('#' + form_id).length === 0) {
|
2016-10-22 14:57:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gets the elements pointers
|
2018-04-14 09:18:00 +00:00
|
|
|
var $the_idx_name = $('#input_index_name');
|
|
|
|
var $the_idx_choice = $('#select_index_choice');
|
2016-10-22 14:57:10 +00:00
|
|
|
|
|
|
|
// Index is a primary key
|
2018-04-14 09:18:00 +00:00
|
|
|
if ($the_idx_choice.find('option:selected').val() === 'PRIMARY') {
|
2016-10-22 14:57:10 +00:00
|
|
|
$the_idx_name.val('PRIMARY');
|
2018-04-14 09:18:00 +00:00
|
|
|
$the_idx_name.prop('disabled', true);
|
|
|
|
} else {
|
|
|
|
if ($the_idx_name.val() === 'PRIMARY') {
|
|
|
|
$the_idx_name.val('');
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
$the_idx_name.prop('disabled', false);
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
} // end of the 'checkIndexName()' function
|
|
|
|
|
|
|
|
AJAX.registerTeardown('functions.js', function () {
|
|
|
|
$(document).off('click', '#index_frm input[type=submit]');
|
|
|
|
});
|
|
|
|
AJAX.registerOnload('functions.js', function () {
|
|
|
|
/**
|
|
|
|
* Handler for adding more columns to an index in the editor
|
|
|
|
*/
|
|
|
|
$(document).on('click', '#index_frm input[type=submit]', function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
var rows_to_add = $(this)
|
|
|
|
.closest('fieldset')
|
|
|
|
.find('.slider')
|
|
|
|
.slider('value');
|
|
|
|
|
|
|
|
var tempEmptyVal = function () {
|
|
|
|
$(this).val('');
|
|
|
|
};
|
|
|
|
|
|
|
|
var tempSetFocus = function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
if ($(this).find('option:selected').val() === '') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
$(this).closest('tr').find('input').focus();
|
2016-10-22 14:57:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
while (rows_to_add--) {
|
|
|
|
var $indexColumns = $('#index_columns');
|
|
|
|
var $newrow = $indexColumns
|
|
|
|
.find('tbody > tr:first')
|
|
|
|
.clone()
|
|
|
|
.appendTo(
|
|
|
|
$indexColumns.find('tbody')
|
|
|
|
);
|
|
|
|
$newrow.find(':input').each(tempEmptyVal);
|
|
|
|
// focus index size input on column picked
|
|
|
|
$newrow.find('select').change(tempSetFocus);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
function indexEditorDialog (url, title, callback_success, callback_failure) {
|
|
|
|
/* Remove the hidden dialogs if there are*/
|
2016-10-22 14:57:10 +00:00
|
|
|
var $editIndexDialog = $('#edit_index_dialog');
|
|
|
|
if ($editIndexDialog.length !== 0) {
|
|
|
|
$editIndexDialog.remove();
|
|
|
|
}
|
|
|
|
var $div = $('<div id="edit_index_dialog"></div>');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var button_options Object that stores the options
|
|
|
|
* passed to jQueryUI dialog
|
|
|
|
*/
|
|
|
|
var button_options = {};
|
|
|
|
button_options[PMA_messages.strGo] = function () {
|
|
|
|
/**
|
|
|
|
* @var the_form object referring to the export form
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
var $form = $('#index_frm');
|
2016-10-22 14:57:10 +00:00
|
|
|
var $msgbox = PMA_ajaxShowMessage(PMA_messages.strProcessingRequest);
|
|
|
|
PMA_prepareForAjaxRequest($form);
|
2018-12-16 14:31:03 +00:00
|
|
|
// User wants to submit the form
|
|
|
|
$.post($form.attr('action'), $form.serialize() + PMA_commonParams.get('arg_separator') + 'do_save_data=1', function (data) {
|
|
|
|
var $sqlqueryresults = $('.sqlqueryresults');
|
2016-10-22 14:57:10 +00:00
|
|
|
if ($sqlqueryresults.length !== 0) {
|
|
|
|
$sqlqueryresults.remove();
|
|
|
|
}
|
|
|
|
if (typeof data !== 'undefined' && data.success === true) {
|
|
|
|
PMA_ajaxShowMessage(data.message);
|
2019-12-08 07:14:01 +00:00
|
|
|
PMA_highlightSQL($('.result_query'));
|
2018-04-14 09:18:00 +00:00
|
|
|
$('.result_query .notice').remove();
|
|
|
|
/* Reload the field form*/
|
|
|
|
$('#table_index').remove();
|
|
|
|
$('<div id=\'temp_div\'><div>')
|
2016-10-22 14:57:10 +00:00
|
|
|
.append(data.index_table)
|
2018-04-14 09:18:00 +00:00
|
|
|
.find('#table_index')
|
|
|
|
.insertAfter('#index_header');
|
|
|
|
var $editIndexDialog = $('#edit_index_dialog');
|
2016-10-22 14:57:10 +00:00
|
|
|
if ($editIndexDialog.length > 0) {
|
2018-04-14 09:18:00 +00:00
|
|
|
$editIndexDialog.dialog('close');
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
$('div.no_indexes_defined').hide();
|
|
|
|
if (callback_success) {
|
|
|
|
callback_success();
|
|
|
|
}
|
|
|
|
PMA_reloadNavigation();
|
|
|
|
} else {
|
2018-04-14 09:18:00 +00:00
|
|
|
var $temp_div = $('<div id=\'temp_div\'><div>').append(data.error);
|
2016-10-22 14:57:10 +00:00
|
|
|
var $error;
|
2018-04-14 09:18:00 +00:00
|
|
|
if ($temp_div.find('.error code').length !== 0) {
|
|
|
|
$error = $temp_div.find('.error code').addClass('error');
|
2016-10-22 14:57:10 +00:00
|
|
|
} else {
|
|
|
|
$error = $temp_div;
|
|
|
|
}
|
|
|
|
if (callback_failure) {
|
|
|
|
callback_failure();
|
|
|
|
}
|
|
|
|
PMA_ajaxShowMessage($error, false);
|
|
|
|
}
|
|
|
|
}); // end $.post()
|
|
|
|
};
|
|
|
|
button_options[PMA_messages.strPreviewSQL] = function () {
|
|
|
|
// Function for Previewing SQL
|
|
|
|
var $form = $('#index_frm');
|
|
|
|
PMA_previewSQL($form);
|
|
|
|
};
|
|
|
|
button_options[PMA_messages.strCancel] = function () {
|
|
|
|
$(this).dialog('close');
|
|
|
|
};
|
|
|
|
var $msgbox = PMA_ajaxShowMessage();
|
2018-12-16 14:31:03 +00:00
|
|
|
$.post('tbl_indexes.php', url, function (data) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (typeof data !== 'undefined' && data.success === false) {
|
2018-04-14 09:18:00 +00:00
|
|
|
// in the case of an error, show the error message returned.
|
2016-10-22 14:57:10 +00:00
|
|
|
PMA_ajaxShowMessage(data.error, false);
|
|
|
|
} else {
|
|
|
|
PMA_ajaxRemoveMessage($msgbox);
|
|
|
|
// Show dialog if the request was successful
|
|
|
|
$div
|
2018-04-14 09:18:00 +00:00
|
|
|
.append(data.message)
|
|
|
|
.dialog({
|
|
|
|
title: title,
|
|
|
|
width: 'auto',
|
|
|
|
open: PMA_verifyColumnsProperties,
|
|
|
|
modal: true,
|
|
|
|
buttons: button_options,
|
|
|
|
close: function () {
|
|
|
|
$(this).remove();
|
|
|
|
}
|
|
|
|
});
|
2016-10-22 14:57:10 +00:00
|
|
|
$div.find('.tblFooters').remove();
|
|
|
|
showIndexEditDialog($div);
|
|
|
|
}
|
|
|
|
}); // end $.get()
|
|
|
|
}
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
function showIndexEditDialog ($outer) {
|
2016-10-22 14:57:10 +00:00
|
|
|
checkIndexType();
|
2018-04-14 09:18:00 +00:00
|
|
|
checkIndexName('index_frm');
|
2016-10-22 14:57:10 +00:00
|
|
|
var $indexColumns = $('#index_columns');
|
|
|
|
$indexColumns.find('td').each(function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
$(this).css('width', $(this).width() + 'px');
|
2016-10-22 14:57:10 +00:00
|
|
|
});
|
|
|
|
$indexColumns.find('tbody').sortable({
|
|
|
|
axis: 'y',
|
2018-04-14 09:18:00 +00:00
|
|
|
containment: $indexColumns.find('tbody'),
|
2016-10-22 14:57:10 +00:00
|
|
|
tolerance: 'pointer'
|
|
|
|
});
|
|
|
|
PMA_showHints($outer);
|
|
|
|
PMA_init_slider();
|
|
|
|
// Add a slider for selecting how many columns to add to the index
|
|
|
|
$outer.find('.slider').slider({
|
|
|
|
animate: true,
|
|
|
|
value: 1,
|
|
|
|
min: 1,
|
|
|
|
max: 16,
|
|
|
|
slide: function (event, ui) {
|
|
|
|
$(this).closest('fieldset').find('input[type=submit]').val(
|
|
|
|
PMA_sprintf(PMA_messages.strAddToIndex, ui.value)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('div.add_fields').removeClass('hide');
|
|
|
|
// focus index size input on column picked
|
|
|
|
$outer.find('table#index_columns select').change(function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
if ($(this).find('option:selected').val() === '') {
|
2016-10-22 14:57:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
$(this).closest('tr').find('input').focus();
|
2016-10-22 14:57:10 +00:00
|
|
|
});
|
|
|
|
// Focus the slider, otherwise it looks nearly transparent
|
|
|
|
$('a.ui-slider-handle').addClass('ui-state-focus');
|
|
|
|
// set focus on index name input, if empty
|
|
|
|
var input = $outer.find('input#input_index_name');
|
|
|
|
if (! input.val()) {
|
|
|
|
input.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to display tooltips that were
|
2018-04-14 09:18:00 +00:00
|
|
|
* generated on the PHP side by PhpMyAdmin\Util::showHint()
|
2016-10-22 14:57:10 +00:00
|
|
|
*
|
|
|
|
* @param object $div a div jquery object which specifies the
|
|
|
|
* domain for searching for tooltips. If we
|
|
|
|
* omit this parameter the function searches
|
|
|
|
* in the whole body
|
|
|
|
**/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_showHints ($div) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if ($div === undefined || ! $div instanceof jQuery || $div.length === 0) {
|
2018-04-14 09:18:00 +00:00
|
|
|
$div = $('body');
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
$div.find('.pma_hint').each(function () {
|
|
|
|
PMA_tooltip(
|
|
|
|
$(this).children('img'),
|
|
|
|
'img',
|
|
|
|
$(this).children('span').html()
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
AJAX.registerOnload('functions.js', function () {
|
|
|
|
PMA_showHints();
|
|
|
|
});
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_mainMenuResizerCallback () {
|
2016-10-22 14:57:10 +00:00
|
|
|
// 5 px margin for jumping menu in Chrome
|
|
|
|
return $(document.body).width() - 5;
|
|
|
|
}
|
|
|
|
// This must be fired only once after the initial page load
|
|
|
|
$(function () {
|
|
|
|
// Initialise the menu resize plugin
|
|
|
|
$('#topmenu').menuResizer(PMA_mainMenuResizerCallback);
|
|
|
|
// register resize event
|
2018-04-14 09:18:00 +00:00
|
|
|
$(window).on('resize', function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
$('#topmenu').menuResizer('resize');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the row number from the classlist (for example, row_1)
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_getRowNumber (classlist) {
|
2016-10-22 14:57:10 +00:00
|
|
|
return parseInt(classlist.split(/\s+row_/)[1], 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes status of slider
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_set_status_label ($element) {
|
2016-10-22 14:57:10 +00:00
|
|
|
var text;
|
2018-04-14 09:18:00 +00:00
|
|
|
if ($element.css('display') === 'none') {
|
2016-10-22 14:57:10 +00:00
|
|
|
text = '+ ';
|
|
|
|
} else {
|
|
|
|
text = '- ';
|
|
|
|
}
|
|
|
|
$element.closest('.slide-wrapper').prev().find('span').text(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* var toggleButton This is a function that creates a toggle
|
|
|
|
* sliding button given a jQuery reference
|
|
|
|
* to the correct DOM element
|
|
|
|
*/
|
|
|
|
var toggleButton = function ($obj) {
|
|
|
|
// In rtl mode the toggle switch is flipped horizontally
|
|
|
|
// so we need to take that into account
|
|
|
|
var right;
|
2018-04-14 09:18:00 +00:00
|
|
|
if ($('span.text_direction', $obj).text() === 'ltr') {
|
2016-10-22 14:57:10 +00:00
|
|
|
right = 'right';
|
|
|
|
} else {
|
|
|
|
right = 'left';
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* var h Height of the button, used to scale the
|
|
|
|
* background image and position the layers
|
|
|
|
*/
|
|
|
|
var h = $obj.height();
|
|
|
|
$('img', $obj).height(h);
|
|
|
|
$('table', $obj).css('bottom', h - 1);
|
|
|
|
/**
|
|
|
|
* var on Width of the "ON" part of the toggle switch
|
|
|
|
* var off Width of the "OFF" part of the toggle switch
|
|
|
|
*/
|
|
|
|
var on = $('td.toggleOn', $obj).width();
|
|
|
|
var off = $('td.toggleOff', $obj).width();
|
|
|
|
// Make the "ON" and "OFF" parts of the switch the same size
|
|
|
|
// + 2 pixels to avoid overflowed
|
|
|
|
$('td.toggleOn > div', $obj).width(Math.max(on, off) + 2);
|
|
|
|
$('td.toggleOff > div', $obj).width(Math.max(on, off) + 2);
|
|
|
|
/**
|
|
|
|
* var w Width of the central part of the switch
|
|
|
|
*/
|
|
|
|
var w = parseInt(($('img', $obj).height() / 16) * 22, 10);
|
|
|
|
// Resize the central part of the switch on the top
|
|
|
|
// layer to match the background
|
|
|
|
$('table td:nth-child(2) > div', $obj).width(w);
|
|
|
|
/**
|
|
|
|
* var imgw Width of the background image
|
|
|
|
* var tblw Width of the foreground layer
|
|
|
|
* var offset By how many pixels to move the background
|
|
|
|
* image, so that it matches the top layer
|
|
|
|
*/
|
|
|
|
var imgw = $('img', $obj).width();
|
|
|
|
var tblw = $('table', $obj).width();
|
|
|
|
var offset = parseInt(((imgw - tblw) / 2), 10);
|
|
|
|
// Move the background to match the layout of the top layer
|
|
|
|
$obj.find('img').css(right, offset);
|
|
|
|
/**
|
|
|
|
* var offw Outer width of the "ON" part of the toggle switch
|
|
|
|
* var btnw Outer width of the central part of the switch
|
|
|
|
*/
|
|
|
|
var offw = $('td.toggleOff', $obj).outerWidth();
|
|
|
|
var btnw = $('table td:nth-child(2)', $obj).outerWidth();
|
|
|
|
// Resize the main div so that exactly one side of
|
|
|
|
// the switch plus the central part fit into it.
|
|
|
|
$obj.width(offw + btnw + 2);
|
|
|
|
/**
|
|
|
|
* var move How many pixels to move the
|
|
|
|
* switch by when toggling
|
|
|
|
*/
|
|
|
|
var move = $('td.toggleOff', $obj).outerWidth();
|
|
|
|
// If the switch is initialized to the
|
|
|
|
// OFF state we need to move it now.
|
|
|
|
if ($('div.container', $obj).hasClass('off')) {
|
2018-04-14 09:18:00 +00:00
|
|
|
if (right === 'right') {
|
|
|
|
$('div.container', $obj).animate({ 'left': '-=' + move + 'px' }, 0);
|
2016-10-22 14:57:10 +00:00
|
|
|
} else {
|
2018-04-14 09:18:00 +00:00
|
|
|
$('div.container', $obj).animate({ 'left': '+=' + move + 'px' }, 0);
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Attach an 'onclick' event to the switch
|
|
|
|
$('div.container', $obj).click(function () {
|
|
|
|
if ($(this).hasClass('isActive')) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
$(this).addClass('isActive');
|
|
|
|
}
|
|
|
|
var $msg = PMA_ajaxShowMessage();
|
|
|
|
var $container = $(this);
|
|
|
|
var callback = $('span.callback', this).text();
|
2018-04-14 09:18:00 +00:00
|
|
|
var operator;
|
|
|
|
var url;
|
|
|
|
var removeClass;
|
|
|
|
var addClass;
|
2016-10-22 14:57:10 +00:00
|
|
|
// Perform the actual toggle
|
|
|
|
if ($(this).hasClass('on')) {
|
2018-04-14 09:18:00 +00:00
|
|
|
if (right === 'right') {
|
2016-10-22 14:57:10 +00:00
|
|
|
operator = '-=';
|
|
|
|
} else {
|
|
|
|
operator = '+=';
|
|
|
|
}
|
|
|
|
url = $(this).find('td.toggleOff > span').text();
|
|
|
|
removeClass = 'on';
|
|
|
|
addClass = 'off';
|
|
|
|
} else {
|
2018-04-14 09:18:00 +00:00
|
|
|
if (right === 'right') {
|
2016-10-22 14:57:10 +00:00
|
|
|
operator = '+=';
|
|
|
|
} else {
|
|
|
|
operator = '-=';
|
|
|
|
}
|
|
|
|
url = $(this).find('td.toggleOn > span').text();
|
|
|
|
removeClass = 'off';
|
|
|
|
addClass = 'on';
|
|
|
|
}
|
2017-04-20 10:55:30 +00:00
|
|
|
|
2018-12-16 14:31:03 +00:00
|
|
|
var parts = url.split('?');
|
|
|
|
$.post(parts[0], parts[1] + '&ajax_request=true', function (data) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (typeof data !== 'undefined' && data.success === true) {
|
|
|
|
PMA_ajaxRemoveMessage($msg);
|
|
|
|
$container
|
2018-04-14 09:18:00 +00:00
|
|
|
.removeClass(removeClass)
|
|
|
|
.addClass(addClass)
|
|
|
|
.animate({ 'left': operator + move + 'px' }, function () {
|
|
|
|
$container.removeClass('isActive');
|
|
|
|
});
|
2016-10-22 14:57:10 +00:00
|
|
|
eval(callback);
|
|
|
|
} else {
|
|
|
|
PMA_ajaxShowMessage(data.error, false);
|
|
|
|
$container.removeClass('isActive');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbind all event handlers before tearing down a page
|
|
|
|
*/
|
|
|
|
AJAX.registerTeardown('functions.js', function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
$('div.container').off('click');
|
2016-10-22 14:57:10 +00:00
|
|
|
});
|
|
|
|
/**
|
|
|
|
* Initialise all toggle buttons
|
|
|
|
*/
|
|
|
|
AJAX.registerOnload('functions.js', function () {
|
|
|
|
$('div.toggleAjax').each(function () {
|
|
|
|
var $button = $(this).show();
|
|
|
|
$button.find('img').each(function () {
|
|
|
|
if (this.complete) {
|
|
|
|
toggleButton($button);
|
|
|
|
} else {
|
|
|
|
$(this).load(function () {
|
|
|
|
toggleButton($button);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbind all event handlers before tearing down a page
|
|
|
|
*/
|
|
|
|
AJAX.registerTeardown('functions.js', function () {
|
|
|
|
$(document).off('change', 'select.pageselector');
|
2018-04-14 09:18:00 +00:00
|
|
|
$('#update_recent_tables').off('ready');
|
|
|
|
$('#sync_favorite_tables').off('ready');
|
2016-10-22 14:57:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
AJAX.registerOnload('functions.js', function () {
|
|
|
|
/**
|
|
|
|
* Autosubmit page selector
|
|
|
|
*/
|
|
|
|
$(document).on('change', 'select.pageselector', function (event) {
|
|
|
|
event.stopPropagation();
|
|
|
|
// Check where to load the new content
|
2018-04-14 09:18:00 +00:00
|
|
|
if ($(this).closest('#pma_navigation').length === 0) {
|
2016-10-22 14:57:10 +00:00
|
|
|
// For the main page we don't need to do anything,
|
2018-04-14 09:18:00 +00:00
|
|
|
$(this).closest('form').submit();
|
2016-10-22 14:57:10 +00:00
|
|
|
} else {
|
|
|
|
// but for the navigation we need to manually replace the content
|
|
|
|
PMA_navigationTreePagination($(this));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load version information asynchronously.
|
|
|
|
*/
|
|
|
|
if ($('li.jsversioncheck').length > 0) {
|
|
|
|
$.ajax({
|
2018-04-14 09:18:00 +00:00
|
|
|
dataType: 'json',
|
2016-10-22 14:57:10 +00:00
|
|
|
url: 'version_check.php',
|
2018-04-14 09:18:00 +00:00
|
|
|
method: 'POST',
|
2016-10-22 14:57:10 +00:00
|
|
|
data: {
|
2018-04-14 09:18:00 +00:00
|
|
|
'server': PMA_commonParams.get('server')
|
2016-10-22 14:57:10 +00:00
|
|
|
},
|
|
|
|
success: PMA_current_version
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($('#is_git_revision').length > 0) {
|
|
|
|
setTimeout(PMA_display_git_revision, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Slider effect.
|
|
|
|
*/
|
|
|
|
PMA_init_slider();
|
|
|
|
|
|
|
|
var $updateRecentTables = $('#update_recent_tables');
|
|
|
|
if ($updateRecentTables.length) {
|
|
|
|
$.get(
|
|
|
|
$updateRecentTables.attr('href'),
|
2018-04-14 09:18:00 +00:00
|
|
|
{ no_debug: true },
|
2016-10-22 14:57:10 +00:00
|
|
|
function (data) {
|
|
|
|
if (typeof data !== 'undefined' && data.success === true) {
|
|
|
|
$('#pma_recent_list').html(data.list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sync favorite tables from localStorage to pmadb.
|
|
|
|
if ($('#sync_favorite_tables').length) {
|
|
|
|
$.ajax({
|
2018-04-14 09:18:00 +00:00
|
|
|
url: $('#sync_favorite_tables').attr('href'),
|
2016-10-22 14:57:10 +00:00
|
|
|
cache: false,
|
|
|
|
type: 'POST',
|
|
|
|
data: {
|
|
|
|
favorite_tables: (isStorageSupported('localStorage') && typeof window.localStorage.favorite_tables !== 'undefined')
|
|
|
|
? window.localStorage.favorite_tables
|
|
|
|
: '',
|
2017-04-20 10:55:30 +00:00
|
|
|
server: PMA_commonParams.get('server'),
|
2016-10-22 14:57:10 +00:00
|
|
|
no_debug: true
|
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
// Update localStorage.
|
|
|
|
if (isStorageSupported('localStorage')) {
|
|
|
|
window.localStorage.favorite_tables = data.favorite_tables;
|
|
|
|
}
|
|
|
|
$('#pma_favorite_list').html(data.list);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}); // end of $()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Submits the form placed in place of a link due to the excessive url length
|
|
|
|
*
|
|
|
|
* @param $link anchor
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function submitFormLink ($link) {
|
|
|
|
if ($link.attr('href').indexOf('=') !== -1) {
|
2016-10-22 14:57:10 +00:00
|
|
|
var data = $link.attr('href').substr($link.attr('href').indexOf('#') + 1).split('=', 2);
|
|
|
|
$link.parents('form').append('<input type="hidden" name="' + data[0] + '" value="' + data[1] + '"/>');
|
|
|
|
}
|
|
|
|
$link.parents('form').submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes slider effect.
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_init_slider () {
|
2016-10-22 14:57:10 +00:00
|
|
|
$('div.pma_auto_slider').each(function () {
|
|
|
|
var $this = $(this);
|
|
|
|
if ($this.data('slider_init_done')) {
|
|
|
|
return;
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
var $wrapper = $('<div>', { 'class': 'slide-wrapper' });
|
2016-10-22 14:57:10 +00:00
|
|
|
$wrapper.toggle($this.is(':visible'));
|
2018-04-14 09:18:00 +00:00
|
|
|
$('<a>', { href: '#' + this.id, 'class': 'ajax' })
|
2016-10-22 14:57:10 +00:00
|
|
|
.text($this.attr('title'))
|
|
|
|
.prepend($('<span>'))
|
|
|
|
.insertBefore($this)
|
|
|
|
.click(function () {
|
|
|
|
var $wrapper = $this.closest('.slide-wrapper');
|
|
|
|
var visible = $this.is(':visible');
|
|
|
|
if (!visible) {
|
|
|
|
$wrapper.show();
|
|
|
|
}
|
|
|
|
$this[visible ? 'hide' : 'show']('blind', function () {
|
|
|
|
$wrapper.toggle(!visible);
|
2018-04-14 09:18:00 +00:00
|
|
|
$wrapper.parent().toggleClass('print_ignore', visible);
|
2016-10-22 14:57:10 +00:00
|
|
|
PMA_set_status_label($this);
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
$this.wrap($wrapper);
|
|
|
|
$this.removeAttr('title');
|
|
|
|
PMA_set_status_label($this);
|
|
|
|
$this.data('slider_init_done', 1);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes slider effect.
|
|
|
|
*/
|
|
|
|
AJAX.registerOnload('functions.js', function () {
|
|
|
|
PMA_init_slider();
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restores sliders to the state they were in before initialisation.
|
|
|
|
*/
|
|
|
|
AJAX.registerTeardown('functions.js', function () {
|
|
|
|
$('div.pma_auto_slider').each(function () {
|
|
|
|
var $this = $(this);
|
|
|
|
$this.removeData();
|
|
|
|
$this.parent().replaceWith($this);
|
|
|
|
$this.parent().children('a').remove();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a message inside an object with a sliding effect
|
|
|
|
*
|
|
|
|
* @param msg A string containing the text to display
|
|
|
|
* @param $obj a jQuery object containing the reference
|
|
|
|
* to the element where to put the message
|
|
|
|
* This is optional, if no element is
|
|
|
|
* provided, one will be created below the
|
|
|
|
* navigation links at the top of the page
|
|
|
|
*
|
|
|
|
* @return bool True on success, false on failure
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_slidingMessage (msg, $obj) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (msg === undefined || msg.length === 0) {
|
|
|
|
// Don't show an empty message
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ($obj === undefined || ! $obj instanceof jQuery || $obj.length === 0) {
|
|
|
|
// If the second argument was not supplied,
|
|
|
|
// we might have to create a new DOM node.
|
|
|
|
if ($('#PMA_slidingMessage').length === 0) {
|
|
|
|
$('#page_content').prepend(
|
|
|
|
'<span id="PMA_slidingMessage" ' +
|
2018-04-14 09:18:00 +00:00
|
|
|
'class="pma_sliding_message"></span>'
|
2016-10-22 14:57:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
$obj = $('#PMA_slidingMessage');
|
|
|
|
}
|
|
|
|
if ($obj.has('div').length > 0) {
|
|
|
|
// If there already is a message inside the
|
|
|
|
// target object, we must get rid of it
|
|
|
|
$obj
|
|
|
|
.find('div')
|
|
|
|
.first()
|
2018-04-14 09:18:00 +00:00
|
|
|
.fadeOut(function () {
|
|
|
|
$obj
|
|
|
|
.children()
|
|
|
|
.remove();
|
|
|
|
$obj
|
|
|
|
.append('<div>' + msg + '</div>');
|
|
|
|
// highlight any sql before taking height;
|
|
|
|
PMA_highlightSQL($obj);
|
|
|
|
$obj.find('div')
|
|
|
|
.first()
|
|
|
|
.hide();
|
|
|
|
$obj
|
|
|
|
.animate({
|
|
|
|
height: $obj.find('div').first().height()
|
|
|
|
})
|
|
|
|
.find('div')
|
|
|
|
.first()
|
|
|
|
.fadeIn();
|
|
|
|
});
|
2016-10-22 14:57:10 +00:00
|
|
|
} else {
|
|
|
|
// Object does not already have a message
|
|
|
|
// inside it, so we simply slide it down
|
|
|
|
$obj.width('100%')
|
|
|
|
.html('<div>' + msg + '</div>');
|
|
|
|
// highlight any sql before taking height;
|
|
|
|
PMA_highlightSQL($obj);
|
|
|
|
var h = $obj
|
|
|
|
.find('div')
|
|
|
|
.first()
|
|
|
|
.hide()
|
|
|
|
.height();
|
|
|
|
$obj
|
2018-04-14 09:18:00 +00:00
|
|
|
.find('div')
|
|
|
|
.first()
|
|
|
|
.css('height', 0)
|
|
|
|
.show()
|
|
|
|
.animate({
|
2016-10-22 14:57:10 +00:00
|
|
|
height: h
|
|
|
|
}, function () {
|
|
|
|
// Set the height of the parent
|
|
|
|
// to the height of the child
|
|
|
|
$obj
|
2018-04-14 09:18:00 +00:00
|
|
|
.height(
|
|
|
|
$obj
|
|
|
|
.find('div')
|
|
|
|
.first()
|
|
|
|
.height()
|
|
|
|
);
|
2016-10-22 14:57:10 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} // end PMA_slidingMessage()
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attach CodeMirror2 editor to SQL edit area.
|
|
|
|
*/
|
|
|
|
AJAX.registerOnload('functions.js', function () {
|
|
|
|
var $elm = $('#sqlquery');
|
|
|
|
if ($elm.length > 0) {
|
2018-04-14 09:18:00 +00:00
|
|
|
if (typeof CodeMirror !== 'undefined') {
|
2016-10-22 14:57:10 +00:00
|
|
|
codemirror_editor = PMA_getSQLEditor($elm);
|
|
|
|
codemirror_editor.focus();
|
2018-04-14 09:18:00 +00:00
|
|
|
codemirror_editor.on('blur', updateQueryParameters);
|
2016-10-22 14:57:10 +00:00
|
|
|
} else {
|
|
|
|
// without codemirror
|
2018-04-14 09:18:00 +00:00
|
|
|
$elm.focus().on('blur', updateQueryParameters);
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
PMA_highlightSQL($('body'));
|
|
|
|
});
|
|
|
|
AJAX.registerTeardown('functions.js', function () {
|
|
|
|
if (codemirror_editor) {
|
|
|
|
$('#sqlquery').text(codemirror_editor.getValue());
|
|
|
|
codemirror_editor.toTextArea();
|
|
|
|
codemirror_editor = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AJAX.registerOnload('functions.js', function () {
|
|
|
|
// initializes all lock-page elements lock-id and
|
|
|
|
// val-hash data property
|
|
|
|
$('#page_content form.lock-page textarea, ' +
|
2018-04-14 09:18:00 +00:00
|
|
|
'#page_content form.lock-page input[type="text"], ' +
|
|
|
|
'#page_content form.lock-page input[type="number"], ' +
|
2016-10-22 14:57:10 +00:00
|
|
|
'#page_content form.lock-page select').each(function (i) {
|
|
|
|
$(this).data('lock-id', i);
|
|
|
|
// val-hash is the hash of default value of the field
|
|
|
|
// so that it can be compared with new value hash
|
|
|
|
// to check whether field was modified or not.
|
|
|
|
$(this).data('val-hash', AJAX.hash($(this).val()));
|
|
|
|
});
|
|
|
|
|
|
|
|
// initializes lock-page elements (input types checkbox and radio buttons)
|
|
|
|
// lock-id and val-hash data property
|
|
|
|
$('#page_content form.lock-page input[type="checkbox"], ' +
|
|
|
|
'#page_content form.lock-page input[type="radio"]').each(function (i) {
|
|
|
|
$(this).data('lock-id', i);
|
2018-04-14 09:18:00 +00:00
|
|
|
$(this).data('val-hash', AJAX.hash($(this).is(':checked')));
|
2016-10-22 14:57:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* jQuery plugin to correctly filter input fields by value, needed
|
|
|
|
* because some nasty values may break selector syntax
|
|
|
|
*/
|
|
|
|
(function ($) {
|
|
|
|
$.fn.filterByValue = function (value) {
|
|
|
|
return this.filter(function () {
|
|
|
|
return $(this).val() === value;
|
|
|
|
});
|
|
|
|
};
|
2018-04-14 09:18:00 +00:00
|
|
|
}(jQuery));
|
2016-10-22 14:57:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return value of a cell in a table.
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_getCellValue (td) {
|
2016-10-22 14:57:10 +00:00
|
|
|
var $td = $(td);
|
|
|
|
if ($td.is('.null')) {
|
|
|
|
return '';
|
|
|
|
} else if ((! $td.is('.to_be_saved')
|
|
|
|
|| $td.is('.set'))
|
|
|
|
&& $td.data('original_data')
|
|
|
|
) {
|
|
|
|
return $td.data('original_data');
|
|
|
|
} else {
|
|
|
|
return $td.text();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$(window).on('popstate', function (event, data) {
|
|
|
|
$('#printcss').attr('media','print');
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbind all event handlers before tearing down a page
|
|
|
|
*/
|
|
|
|
AJAX.registerTeardown('functions.js', function () {
|
|
|
|
$(document).off('click', 'a.themeselect');
|
|
|
|
$(document).off('change', '.autosubmit');
|
2018-04-14 09:18:00 +00:00
|
|
|
$('a.take_theme').off('click');
|
2016-10-22 14:57:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
AJAX.registerOnload('functions.js', function () {
|
|
|
|
/**
|
|
|
|
* Theme selector.
|
|
|
|
*/
|
|
|
|
$(document).on('click', 'a.themeselect', function (e) {
|
|
|
|
window.open(
|
|
|
|
e.target,
|
|
|
|
'themes',
|
|
|
|
'left=10,top=20,width=510,height=350,scrollbars=yes,status=yes,resizable=yes'
|
2018-04-14 09:18:00 +00:00
|
|
|
);
|
2016-10-22 14:57:10 +00:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Automatic form submission on change.
|
|
|
|
*/
|
|
|
|
$(document).on('change', '.autosubmit', function (e) {
|
|
|
|
$(this).closest('form').submit();
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Theme changer.
|
|
|
|
*/
|
|
|
|
$('a.take_theme').click(function (e) {
|
|
|
|
var what = this.name;
|
|
|
|
if (window.opener && window.opener.document.forms.setTheme.elements.set_theme) {
|
|
|
|
window.opener.document.forms.setTheme.elements.set_theme.value = what;
|
|
|
|
window.opener.document.forms.setTheme.submit();
|
|
|
|
window.close();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Produce print preview
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function printPreview () {
|
2016-10-22 14:57:10 +00:00
|
|
|
$('#printcss').attr('media','all');
|
|
|
|
createPrintAndBackButtons();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create print and back buttons in preview page
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function createPrintAndBackButtons () {
|
|
|
|
var back_button = $('<input/>',{
|
2016-10-22 14:57:10 +00:00
|
|
|
type: 'button',
|
|
|
|
value: PMA_messages.back,
|
|
|
|
id: 'back_button_print_view'
|
|
|
|
});
|
|
|
|
back_button.click(removePrintAndBackButton);
|
|
|
|
back_button.appendTo('#page_content');
|
2018-04-14 09:18:00 +00:00
|
|
|
var print_button = $('<input/>',{
|
2016-10-22 14:57:10 +00:00
|
|
|
type: 'button',
|
|
|
|
value: PMA_messages.print,
|
|
|
|
id: 'print_button_print_view'
|
|
|
|
});
|
|
|
|
print_button.click(printPage);
|
|
|
|
print_button.appendTo('#page_content');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove print and back buttons and revert to normal view
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function removePrintAndBackButton () {
|
2016-10-22 14:57:10 +00:00
|
|
|
$('#printcss').attr('media','print');
|
|
|
|
$('#back_button_print_view').remove();
|
|
|
|
$('#print_button_print_view').remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print page
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function printPage () {
|
|
|
|
if (typeof(window.print) !== 'undefined') {
|
2016-10-22 14:57:10 +00:00
|
|
|
window.print();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbind all event handlers before tearing down a page
|
|
|
|
*/
|
|
|
|
AJAX.registerTeardown('functions.js', function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
$('input#print').off('click');
|
2016-10-22 14:57:10 +00:00
|
|
|
$(document).off('click', 'a.create_view.ajax');
|
|
|
|
$(document).off('keydown', '#createViewDialog input, #createViewDialog select');
|
|
|
|
$(document).off('change', '#fkc_checkbox');
|
|
|
|
});
|
|
|
|
|
|
|
|
AJAX.registerOnload('functions.js', function () {
|
|
|
|
$('input#print').click(printPage);
|
2018-04-14 09:18:00 +00:00
|
|
|
$('.logout').click(function () {
|
2017-04-20 10:55:30 +00:00
|
|
|
var form = $(
|
|
|
|
'<form method="POST" action="' + $(this).attr('href') + '" class="disableAjax">' +
|
2018-04-14 09:18:00 +00:00
|
|
|
'<input type="hidden" name="token" value="' + escapeHtml(PMA_commonParams.get('token')) + '"/>' +
|
2017-04-20 10:55:30 +00:00
|
|
|
'</form>'
|
|
|
|
);
|
|
|
|
$('body').append(form);
|
|
|
|
form.submit();
|
|
|
|
return false;
|
|
|
|
});
|
2016-10-22 14:57:10 +00:00
|
|
|
/**
|
|
|
|
* Ajaxification for the "Create View" action
|
|
|
|
*/
|
|
|
|
$(document).on('click', 'a.create_view.ajax', function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
PMA_createViewDialog($(this));
|
|
|
|
});
|
|
|
|
/**
|
|
|
|
* Attach Ajax event handlers for input fields in the editor
|
|
|
|
* and used to submit the Ajax request when the ENTER key is pressed.
|
|
|
|
*/
|
|
|
|
if ($('#createViewDialog').length !== 0) {
|
|
|
|
$(document).on('keydown', '#createViewDialog input, #createViewDialog select', function (e) {
|
|
|
|
if (e.which === 13) { // 13 is the ENTER key
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
// with preventing default, selection by <select> tag
|
|
|
|
// was also prevented in IE
|
|
|
|
$(this).blur();
|
|
|
|
|
|
|
|
$(this).closest('.ui-dialog').find('.ui-button:first').click();
|
|
|
|
}
|
|
|
|
}); // end $(document).on()
|
|
|
|
}
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
if ($('textarea[name="view[as]"]').length !== 0) {
|
|
|
|
codemirror_editor = PMA_getSQLEditor($('textarea[name="view[as]"]'));
|
|
|
|
}
|
2016-10-22 14:57:10 +00:00
|
|
|
});
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_createViewDialog ($this) {
|
2016-10-22 14:57:10 +00:00
|
|
|
var $msg = PMA_ajaxShowMessage();
|
2018-04-14 09:18:00 +00:00
|
|
|
var sep = PMA_commonParams.get('arg_separator');
|
2018-12-16 14:31:03 +00:00
|
|
|
var params = getJSConfirmCommonParam(this, $this.getPostData());
|
|
|
|
params += sep + 'ajax_dialog=1';
|
|
|
|
$.post($this.attr('href'), params, function (data) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (typeof data !== 'undefined' && data.success === true) {
|
|
|
|
PMA_ajaxRemoveMessage($msg);
|
|
|
|
var buttonOptions = {};
|
|
|
|
buttonOptions[PMA_messages.strGo] = function () {
|
|
|
|
if (typeof CodeMirror !== 'undefined') {
|
2018-04-14 09:18:00 +00:00
|
|
|
codemirror_editor.save();
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
$msg = PMA_ajaxShowMessage();
|
|
|
|
$.post('view_create.php', $('#createViewDialog').find('form').serialize(), function (data) {
|
|
|
|
PMA_ajaxRemoveMessage($msg);
|
|
|
|
if (typeof data !== 'undefined' && data.success === true) {
|
2018-04-14 09:18:00 +00:00
|
|
|
$('#createViewDialog').dialog('close');
|
2016-10-22 14:57:10 +00:00
|
|
|
$('.result_query').html(data.message);
|
|
|
|
PMA_reloadNavigation();
|
|
|
|
} else {
|
2019-12-08 07:14:01 +00:00
|
|
|
PMA_ajaxShowMessage(data.error);
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
buttonOptions[PMA_messages.strClose] = function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
$(this).dialog('close');
|
2016-10-22 14:57:10 +00:00
|
|
|
};
|
|
|
|
var $dialog = $('<div/>').attr('id', 'createViewDialog').append(data.message).dialog({
|
|
|
|
width: 600,
|
|
|
|
minWidth: 400,
|
|
|
|
modal: true,
|
|
|
|
buttons: buttonOptions,
|
|
|
|
title: PMA_messages.strCreateView,
|
|
|
|
close: function () {
|
|
|
|
$(this).remove();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Attach syntax highlighted editor
|
2018-04-14 09:18:00 +00:00
|
|
|
codemirror_editor = PMA_getSQLEditor($dialog.find('textarea'));
|
2016-10-22 14:57:10 +00:00
|
|
|
$('input:visible[type=text]', $dialog).first().focus();
|
|
|
|
} else {
|
|
|
|
PMA_ajaxShowMessage(data.error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes the breadcrumbs and the menu bar float at the top of the viewport
|
|
|
|
*/
|
|
|
|
$(function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
if ($('#floating_menubar').length && $('#PMA_disable_floating_menubar').length === 0) {
|
|
|
|
var left = $('html').attr('dir') === 'ltr' ? 'left' : 'right';
|
|
|
|
$('#floating_menubar')
|
2016-10-22 14:57:10 +00:00
|
|
|
.css('margin-' + left, $('#pma_navigation').width() + $('#pma_navigation_resizer').width())
|
|
|
|
.css(left, 0)
|
|
|
|
.css({
|
|
|
|
'position': 'fixed',
|
|
|
|
'top': 0,
|
|
|
|
'width': '100%',
|
|
|
|
'z-index': 99
|
|
|
|
})
|
|
|
|
.append($('#serverinfo'))
|
|
|
|
.append($('#topmenucontainer'));
|
|
|
|
// Allow the DOM to render, then adjust the padding on the body
|
|
|
|
setTimeout(function () {
|
|
|
|
$('body').css(
|
|
|
|
'padding-top',
|
|
|
|
$('#floating_menubar').outerHeight(true)
|
|
|
|
);
|
|
|
|
$('#topmenu').menuResizer('resize');
|
|
|
|
}, 4);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scrolls the page to the top if clicking the serverinfo bar
|
|
|
|
*/
|
|
|
|
$(function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('click', '#serverinfo, #goto_pagetop', function (event) {
|
2016-10-22 14:57:10 +00:00
|
|
|
event.preventDefault();
|
2018-04-14 09:18:00 +00:00
|
|
|
$('html, body').animate({ scrollTop: 0 }, 'fast');
|
2016-10-22 14:57:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
var checkboxes_sel = 'input.checkall:checkbox:enabled';
|
2016-10-22 14:57:10 +00:00
|
|
|
/**
|
|
|
|
* Watches checkboxes in a form to set the checkall box accordingly
|
|
|
|
*/
|
|
|
|
var checkboxes_changed = function () {
|
|
|
|
var $form = $(this.form);
|
|
|
|
// total number of checkboxes in current form
|
|
|
|
var total_boxes = $form.find(checkboxes_sel).length;
|
|
|
|
// number of checkboxes checked in current form
|
2018-04-14 09:18:00 +00:00
|
|
|
var checked_boxes = $form.find(checkboxes_sel + ':checked').length;
|
|
|
|
var $checkall = $form.find('input.checkall_box');
|
|
|
|
if (total_boxes === checked_boxes) {
|
|
|
|
$checkall.prop({ checked: true, indeterminate: false });
|
|
|
|
} else if (checked_boxes > 0) {
|
|
|
|
$checkall.prop({ checked: true, indeterminate: true });
|
|
|
|
} else {
|
|
|
|
$checkall.prop({ checked: false, indeterminate: false });
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
};
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('change', checkboxes_sel, checkboxes_changed);
|
|
|
|
|
|
|
|
$(document).on('change', 'input.checkall_box', function () {
|
|
|
|
var is_checked = $(this).is(':checked');
|
|
|
|
$(this.form).find(checkboxes_sel).not('.row-hidden').prop('checked', is_checked)
|
|
|
|
.parents('tr').toggleClass('marked', is_checked);
|
|
|
|
});
|
2016-10-22 14:57:10 +00:00
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('click', '.checkall-filter', function () {
|
|
|
|
var $this = $(this);
|
|
|
|
var selector = $this.data('checkall-selector');
|
|
|
|
$('input.checkall_box').prop('checked', false);
|
|
|
|
$this.parents('form').find(checkboxes_sel).filter(selector).prop('checked', true).trigger('change')
|
|
|
|
.parents('tr').toggleClass('marked', true);
|
|
|
|
return false;
|
2016-10-22 14:57:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Watches checkboxes in a sub form to set the sub checkall box accordingly
|
|
|
|
*/
|
|
|
|
var sub_checkboxes_changed = function () {
|
|
|
|
var $form = $(this).parent().parent();
|
|
|
|
// total number of checkboxes in current sub form
|
|
|
|
var total_boxes = $form.find(checkboxes_sel).length;
|
|
|
|
// number of checkboxes checked in current sub form
|
2018-04-14 09:18:00 +00:00
|
|
|
var checked_boxes = $form.find(checkboxes_sel + ':checked').length;
|
|
|
|
var $checkall = $form.find('input.sub_checkall_box');
|
|
|
|
if (total_boxes === checked_boxes) {
|
|
|
|
$checkall.prop({ checked: true, indeterminate: false });
|
|
|
|
} else if (checked_boxes > 0) {
|
|
|
|
$checkall.prop({ checked: true, indeterminate: true });
|
|
|
|
} else {
|
|
|
|
$checkall.prop({ checked: false, indeterminate: false });
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
};
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('change', checkboxes_sel + ', input.checkall_box:checkbox:enabled', sub_checkboxes_changed);
|
2016-10-22 14:57:10 +00:00
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('change', 'input.sub_checkall_box', function () {
|
|
|
|
var is_checked = $(this).is(':checked');
|
2016-10-22 14:57:10 +00:00
|
|
|
var $form = $(this).parent().parent();
|
2018-04-14 09:18:00 +00:00
|
|
|
$form.find(checkboxes_sel).prop('checked', is_checked)
|
|
|
|
.parents('tr').toggleClass('marked', is_checked);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rows filtering
|
|
|
|
*
|
|
|
|
* - rows to filter are identified by data-filter-row attribute
|
|
|
|
* which contains uppercase string to filter
|
|
|
|
* - it is simple substring case insensitive search
|
|
|
|
* - optionally number of matching rows is written to element with
|
|
|
|
* id filter-rows-count
|
|
|
|
*/
|
|
|
|
$(document).on('keyup', '#filterText', function () {
|
|
|
|
var filterInput = $(this).val().toUpperCase();
|
|
|
|
var count = 0;
|
|
|
|
$('[data-filter-row]').each(function () {
|
|
|
|
var $row = $(this);
|
|
|
|
/* Can not use data() here as it does magic conversion to int for numeric values */
|
|
|
|
if ($row.attr('data-filter-row').indexOf(filterInput) > -1) {
|
|
|
|
count += 1;
|
|
|
|
$row.show();
|
2018-12-16 14:31:03 +00:00
|
|
|
$row.find('input.checkall').removeClass('row-hidden');
|
2018-04-14 09:18:00 +00:00
|
|
|
} else {
|
|
|
|
$row.hide();
|
2018-12-16 14:31:03 +00:00
|
|
|
$row.find('input.checkall').addClass('row-hidden').prop('checked', false);
|
2018-04-14 09:18:00 +00:00
|
|
|
$row.removeClass('marked');
|
|
|
|
}
|
|
|
|
});
|
2018-12-16 14:31:03 +00:00
|
|
|
setTimeout(function () {
|
|
|
|
$(checkboxes_sel).trigger('change');
|
|
|
|
}, 300);
|
2018-04-14 09:18:00 +00:00
|
|
|
$('#filter-rows-count').html(count);
|
|
|
|
});
|
|
|
|
AJAX.registerOnload('functions.js', function () {
|
|
|
|
/* Trigger filtering of the list based on incoming database name */
|
|
|
|
var $filter = $('#filterText');
|
|
|
|
if ($filter.val()) {
|
|
|
|
$filter.trigger('keyup').select();
|
|
|
|
}
|
2016-10-22 14:57:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats a byte number to human-readable form
|
|
|
|
*
|
|
|
|
* @param bytes the bytes to format
|
|
|
|
* @param optional subdecimals the number of digits after the point
|
|
|
|
* @param optional pointchar the char to use as decimal point
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function formatBytes (bytes, subdecimals, pointchar) {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (!subdecimals) {
|
|
|
|
subdecimals = 0;
|
|
|
|
}
|
|
|
|
if (!pointchar) {
|
|
|
|
pointchar = '.';
|
|
|
|
}
|
|
|
|
var units = ['B', 'KiB', 'MiB', 'GiB'];
|
|
|
|
for (var i = 0; bytes > 1024 && i < units.length; i++) {
|
|
|
|
bytes /= 1024;
|
|
|
|
}
|
|
|
|
var factor = Math.pow(10, subdecimals);
|
|
|
|
bytes = Math.round(bytes * factor) / factor;
|
|
|
|
bytes = bytes.toString().split('.').join(pointchar);
|
|
|
|
return bytes + ' ' + units[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
AJAX.registerOnload('functions.js', function () {
|
|
|
|
/**
|
|
|
|
* Reveal the login form to users with JS enabled
|
|
|
|
* and focus the appropriate input field
|
|
|
|
*/
|
|
|
|
var $loginform = $('#loginform');
|
|
|
|
if ($loginform.length) {
|
|
|
|
$loginform.find('.js-show').show();
|
|
|
|
if ($('#input_username').val()) {
|
2018-04-14 09:18:00 +00:00
|
|
|
$('#input_password').trigger('focus');
|
2016-10-22 14:57:10 +00:00
|
|
|
} else {
|
2018-04-14 09:18:00 +00:00
|
|
|
$('#input_username').trigger('focus');
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
var $https_warning = $('#js-https-mismatch');
|
|
|
|
if ($https_warning.length) {
|
|
|
|
if ((window.location.protocol === 'https:') !== PMA_commonParams.get('is_https')) {
|
|
|
|
$https_warning.show();
|
2016-10-22 14:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
});
|
2016-10-22 14:57:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Formats timestamp for display
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_formatDateTime (date, seconds) {
|
2016-10-22 14:57:10 +00:00
|
|
|
var result = $.datepicker.formatDate('yy-mm-dd', date);
|
|
|
|
var timefmt = 'HH:mm';
|
|
|
|
if (seconds) {
|
|
|
|
timefmt = 'HH:mm:ss';
|
|
|
|
}
|
|
|
|
return result + ' ' + $.datepicker.formatTime(
|
|
|
|
timefmt, {
|
|
|
|
hour: date.getHours(),
|
|
|
|
minute: date.getMinutes(),
|
|
|
|
second: date.getSeconds()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check than forms have less fields than max allowed by PHP.
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function checkNumberOfFields () {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (typeof maxInputVars === 'undefined') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (false === maxInputVars) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
$('form').each(function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
var nbInputs = $(this).find(':input').length;
|
|
|
|
if (nbInputs > maxInputVars) {
|
|
|
|
var warning = PMA_sprintf(PMA_messages.strTooManyInputs, maxInputVars);
|
|
|
|
PMA_ajaxShowMessage(warning);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ignore the displayed php errors.
|
|
|
|
* Simply removes the displayed errors.
|
|
|
|
*
|
|
|
|
* @param clearPrevErrors whether to clear errors stored
|
|
|
|
* in $_SESSION['prev_errors'] at server
|
|
|
|
*
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function PMA_ignorePhpErrors (clearPrevErrors) {
|
|
|
|
if (typeof(clearPrevErrors) === 'undefined' ||
|
2016-10-22 14:57:10 +00:00
|
|
|
clearPrevErrors === null
|
|
|
|
) {
|
|
|
|
str = false;
|
|
|
|
}
|
|
|
|
// send AJAX request to error_report.php with send_error_report=0, exception_type=php & token.
|
|
|
|
// It clears the prev_errors stored in session.
|
2018-04-14 09:18:00 +00:00
|
|
|
if (clearPrevErrors) {
|
2016-10-22 14:57:10 +00:00
|
|
|
var $pmaReportErrorsForm = $('#pma_report_errors_form');
|
|
|
|
$pmaReportErrorsForm.find('input[name="send_error_report"]').val(0); // change send_error_report to '0'
|
|
|
|
$pmaReportErrorsForm.submit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove displayed errors
|
|
|
|
var $pmaErrors = $('#pma_errors');
|
2018-04-14 09:18:00 +00:00
|
|
|
$pmaErrors.fadeOut('slow');
|
2016-10-22 14:57:10 +00:00
|
|
|
$pmaErrors.remove();
|
|
|
|
}
|
|
|
|
|
2017-04-20 10:55:30 +00:00
|
|
|
/**
|
|
|
|
* Toggle the Datetimepicker UI if the date value entered
|
|
|
|
* by the user in the 'text box' is not going to be accepted
|
|
|
|
* by the Datetimepicker plugin (but is accepted by MySQL)
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
function toggleDatepickerIfInvalid ($td, $input_field) {
|
2017-04-20 10:55:30 +00:00
|
|
|
// Regex allowed by the Datetimepicker UI
|
|
|
|
var dtexpDate = new RegExp(['^([0-9]{4})',
|
|
|
|
'-(((01|03|05|07|08|10|12)-((0[1-9])|([1-2][0-9])|(3[0-1])))|((02|04|06|09|11)',
|
|
|
|
'-((0[1-9])|([1-2][0-9])|30)))$'].join(''));
|
|
|
|
var dtexpTime = new RegExp(['^(([0-1][0-9])|(2[0-3]))',
|
|
|
|
':((0[0-9])|([1-5][0-9]))',
|
|
|
|
':((0[0-9])|([1-5][0-9]))(\.[0-9]{1,6}){0,1}$'].join(''));
|
|
|
|
|
|
|
|
// If key-ed in Time or Date values are unsupported by the UI, close it
|
|
|
|
if ($td.attr('data-type') === 'date' && ! dtexpDate.test($input_field.val())) {
|
|
|
|
$input_field.datepicker('hide');
|
|
|
|
} else if ($td.attr('data-type') === 'time' && ! dtexpTime.test($input_field.val())) {
|
|
|
|
$input_field.datepicker('hide');
|
|
|
|
} else {
|
|
|
|
$input_field.datepicker('show');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
/*
|
|
|
|
* Function to submit the login form after validation is done.
|
|
|
|
*/
|
|
|
|
function recaptchaCallback () {
|
|
|
|
$('#login_form').submit();
|
|
|
|
}
|
|
|
|
|
2016-10-22 14:57:10 +00:00
|
|
|
/**
|
|
|
|
* Unbind all event handlers before tearing down a page
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
AJAX.registerTeardown('functions.js', function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
$(document).off('keydown', 'form input, form textarea, form select');
|
|
|
|
});
|
|
|
|
|
|
|
|
AJAX.registerOnload('functions.js', function () {
|
|
|
|
/**
|
|
|
|
* Handle 'Ctrl/Alt + Enter' form submits
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
$('form input, form textarea, form select').on('keydown', function (e) {
|
|
|
|
if ((e.ctrlKey && e.which === 13) || (e.altKey && e.which === 13)) {
|
2016-10-22 14:57:10 +00:00
|
|
|
$form = $(this).closest('form');
|
2019-12-08 07:14:01 +00:00
|
|
|
|
|
|
|
// There could be multiple submit buttons on the same form,
|
|
|
|
// we assume all of them behave identical and just click one.
|
|
|
|
if (! $form.find('input[type="submit"]:first') ||
|
|
|
|
! $form.find('input[type="submit"]:first').trigger('click')
|
2016-10-22 14:57:10 +00:00
|
|
|
) {
|
|
|
|
$form.submit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbind all event handlers before tearing down a page
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
AJAX.registerTeardown('functions.js', function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
$(document).off('change', 'input[type=radio][name="pw_hash"]');
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).off('mouseover', '.sortlink');
|
|
|
|
$(document).off('mouseout', '.sortlink');
|
2016-10-22 14:57:10 +00:00
|
|
|
});
|
|
|
|
|
2018-04-14 09:18:00 +00:00
|
|
|
AJAX.registerOnload('functions.js', function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
/*
|
|
|
|
* Display warning regarding SSL when sha256_password
|
|
|
|
* method is selected
|
|
|
|
* Used in user_password.php (Change Password link on index.php)
|
|
|
|
*/
|
2018-04-14 09:18:00 +00:00
|
|
|
$(document).on('change', 'select#select_authentication_plugin_cp', function () {
|
2016-10-22 14:57:10 +00:00
|
|
|
if (this.value === 'sha256_password') {
|
|
|
|
$('#ssl_reqd_warning_cp').show();
|
|
|
|
} else {
|
|
|
|
$('#ssl_reqd_warning_cp').hide();
|
|
|
|
}
|
|
|
|
});
|
2018-04-14 09:18:00 +00:00
|
|
|
|
|
|
|
Cookies.defaults.path = PMA_commonParams.get('rootPath');
|
|
|
|
|
|
|
|
// Bind event handlers for toggling sort icons
|
|
|
|
$(document).on('mouseover', '.sortlink', function () {
|
|
|
|
$(this).find('.soimg').toggle();
|
|
|
|
});
|
|
|
|
$(document).on('mouseout', '.sortlink', function () {
|
|
|
|
$(this).find('.soimg').toggle();
|
|
|
|
});
|
2016-10-22 14:57:10 +00:00
|
|
|
});
|
2018-04-14 09:18:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an HTML IMG tag for a particular image from a theme,
|
|
|
|
* which may be an actual file or an icon from a sprite
|
|
|
|
*
|
|
|
|
* @param string image The name of the file to get
|
|
|
|
* @param string alternate Used to set 'alt' and 'title' attributes of the image
|
|
|
|
* @param object attributes An associative array of other attributes
|
|
|
|
*
|
|
|
|
* @return Object The requested image, this object has two methods:
|
|
|
|
* .toString() - Returns the IMG tag for the requested image
|
|
|
|
* .attr(name) - Returns a particular attribute of the IMG
|
|
|
|
* tag given it's name
|
|
|
|
* .attr(name, value) - Sets a particular attribute of the IMG
|
|
|
|
* tag to the given value
|
|
|
|
*/
|
2018-12-16 14:31:03 +00:00
|
|
|
function PMA_getImage (image, alternate, attributes) {
|
2018-04-14 09:18:00 +00:00
|
|
|
// custom image object, it will eventually be returned by this functions
|
|
|
|
var retval = {
|
|
|
|
data: {
|
|
|
|
// this is private
|
|
|
|
alt: '',
|
|
|
|
title: '',
|
|
|
|
src: 'themes/dot.gif',
|
|
|
|
},
|
|
|
|
attr: function (name, value) {
|
|
|
|
if (value == undefined) {
|
|
|
|
if (this.data[name] == undefined) {
|
|
|
|
return '';
|
|
|
|
} else {
|
|
|
|
return this.data[name];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.data[name] = value;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
toString: function () {
|
|
|
|
var retval = '<' + 'img';
|
|
|
|
for (var i in this.data) {
|
|
|
|
retval += ' ' + i + '="' + this.data[i] + '"';
|
|
|
|
}
|
|
|
|
retval += ' /' + '>';
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
// initialise missing parameters
|
|
|
|
if (attributes == undefined) {
|
|
|
|
attributes = {};
|
|
|
|
}
|
|
|
|
if (alternate == undefined) {
|
|
|
|
alternate = '';
|
|
|
|
}
|
|
|
|
// set alt
|
|
|
|
if (attributes.alt != undefined) {
|
|
|
|
retval.attr('alt', escapeHtml(attributes.alt));
|
|
|
|
} else {
|
|
|
|
retval.attr('alt', escapeHtml(alternate));
|
|
|
|
}
|
|
|
|
// set title
|
|
|
|
if (attributes.title != undefined) {
|
|
|
|
retval.attr('title', escapeHtml(attributes.title));
|
|
|
|
} else {
|
|
|
|
retval.attr('title', escapeHtml(alternate));
|
|
|
|
}
|
|
|
|
// set css classes
|
|
|
|
retval.attr('class', 'icon ic_' + image);
|
|
|
|
// set all other attrubutes
|
|
|
|
for (var i in attributes) {
|
|
|
|
if (i == 'src') {
|
|
|
|
// do not allow to override the 'src' attribute
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval.attr(i, attributes[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a configuration value.
|
|
|
|
*
|
|
|
|
* A configuration value may be set in both browser's local storage and
|
|
|
|
* remotely in server's configuration table.
|
|
|
|
*
|
|
|
|
* If the `only_local` argument is `true`, the value is store is stored only in
|
|
|
|
* browser's local storage and may be lost if the user resets his browser's
|
|
|
|
* settings.
|
|
|
|
*
|
|
|
|
* NOTE: Depending on server's configuration, the configuration table may be or
|
|
|
|
* not persistent.
|
|
|
|
*
|
|
|
|
* @param {string} key Configuration key.
|
|
|
|
* @param {object} value Configuration value.
|
|
|
|
* @param {boolean} only_local Configuration type.
|
|
|
|
*/
|
2018-12-16 14:31:03 +00:00
|
|
|
function configSet (key, value, only_local) {
|
2018-04-14 09:18:00 +00:00
|
|
|
only_local = (typeof only_local !== 'undefined') ? only_local : false;
|
|
|
|
var serialized = JSON.stringify(value);
|
|
|
|
localStorage.setItem(key, serialized);
|
|
|
|
$.ajax({
|
2018-12-16 14:31:03 +00:00
|
|
|
url: 'ajax.php',
|
|
|
|
type: 'POST',
|
|
|
|
dataType: 'json',
|
2018-04-14 09:18:00 +00:00
|
|
|
data: {
|
|
|
|
key: key,
|
2018-12-16 14:31:03 +00:00
|
|
|
type: 'config-set',
|
2018-04-14 09:18:00 +00:00
|
|
|
server: PMA_commonParams.get('server'),
|
|
|
|
value: serialized,
|
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
// Updating value in local storage.
|
|
|
|
if (! data.success) {
|
2019-12-08 07:14:01 +00:00
|
|
|
if (data.error) {
|
|
|
|
PMA_ajaxShowMessage(data.error);
|
|
|
|
} else {
|
|
|
|
PMA_ajaxShowMessage(data.message);
|
|
|
|
}
|
2018-04-14 09:18:00 +00:00
|
|
|
}
|
|
|
|
// Eventually, call callback.
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets a configuration value. A configuration value will be searched in
|
|
|
|
* browser's local storage first and if not found, a call to the server will be
|
|
|
|
* made.
|
|
|
|
*
|
|
|
|
* If value should not be cached and the up-to-date configuration value from
|
|
|
|
* right from the server is required, the third parameter should be `false`.
|
|
|
|
*
|
|
|
|
* @param {string} key Configuration key.
|
|
|
|
* @param {boolean} cached Configuration type.
|
|
|
|
*
|
|
|
|
* @return {object} Configuration value.
|
|
|
|
*/
|
2018-12-16 14:31:03 +00:00
|
|
|
function configGet (key, cached) {
|
2018-04-14 09:18:00 +00:00
|
|
|
cached = (typeof cached !== 'undefined') ? cached : true;
|
|
|
|
var value = localStorage.getItem(key);
|
|
|
|
if (cached && value !== undefined && value !== null) {
|
|
|
|
return JSON.parse(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Result not found in local storage or ignored.
|
|
|
|
// Hitting the server.
|
|
|
|
$.ajax({
|
|
|
|
// TODO: This is ugly, but usually when a configuration is needed,
|
|
|
|
// processing cannot continue until that value is found.
|
|
|
|
// Another solution is to provide a callback as a parameter.
|
|
|
|
async: false,
|
2018-12-16 14:31:03 +00:00
|
|
|
url: 'ajax.php',
|
|
|
|
type: 'POST',
|
|
|
|
dataType: 'json',
|
2018-04-14 09:18:00 +00:00
|
|
|
data: {
|
2018-12-16 14:31:03 +00:00
|
|
|
type: 'config-get',
|
2018-04-14 09:18:00 +00:00
|
|
|
server: PMA_commonParams.get('server'),
|
|
|
|
key: key
|
|
|
|
},
|
|
|
|
success: function (data) {
|
|
|
|
// Updating value in local storage.
|
|
|
|
if (data.success) {
|
|
|
|
localStorage.setItem(key, JSON.stringify(data.value));
|
|
|
|
} else {
|
|
|
|
PMA_ajaxShowMessage(data.message);
|
|
|
|
}
|
|
|
|
// Eventually, call callback.
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return JSON.parse(localStorage.getItem(key));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return POST data as stored by Util::linkOrButton
|
|
|
|
*/
|
2018-12-16 14:31:03 +00:00
|
|
|
jQuery.fn.getPostData = function () {
|
2018-04-14 09:18:00 +00:00
|
|
|
var dataPost = this.attr('data-post');
|
|
|
|
// Strip possible leading ?
|
|
|
|
if (dataPost !== undefined && dataPost.substring(0,1) == '?') {
|
|
|
|
dataPost = dataPost.substr(1);
|
|
|
|
}
|
|
|
|
return dataPost;
|
|
|
|
};
|