diff --git a/ChangeLog b/ChangeLog index cf2ec854c6..e8f00a4d45 100644 --- a/ChangeLog +++ b/ChangeLog @@ -15,6 +15,7 @@ phpMyAdmin - ChangeLog + rfe #1145 Preview SQL instead of executing it + rfe #759 Use aliases in SQL export for tables and columns - bug #4450 Query is duplicated on Ctrl+Enter ++ rfe #755 Export with table/column name changes 4.2.4.0 (not yet released) - bug #4449 Mediawiki export does not produce table header row; also fix related PHP warnings diff --git a/export.php b/export.php index 215d494032..b1c80789bc 100644 --- a/export.php +++ b/export.php @@ -126,6 +126,7 @@ if (!defined('TESTSUITE')) { 'sql_hex_for_binary', 'sql_utc_time', 'sql_drop_database', + 'sql_views_as_tables', 'csv_separator', 'csv_enclosed', 'csv_escaped', @@ -147,7 +148,8 @@ if (!defined('TESTSUITE')) { 'latex_data_caption', 'latex_data_continued_caption', 'latex_data_label', - 'latex_null' + 'latex_null', + 'aliases' ); foreach ($post_params as $one_post_param) { @@ -241,6 +243,18 @@ if (!defined('TESTSUITE')) { PMA_fatalError(__('Bad parameters!')); } + // Merge SQL Query aliases with Export aliases from + // export page, Export page aliases are given more + // preference over SQL Query aliases. + if (!empty($_REQUEST['aliases'])) { + $aliases = PMA_mergeAliases( + PMA_SQP_getAliasesFromQuery($sql_query, $db), + $_REQUEST['aliases'] + ); + } else { + $aliases = PMA_SQP_getAliasesFromQuery($sql_query, $db); + } + /** * Increase time limit for script execution and initializes some variables */ @@ -370,12 +384,14 @@ if (!defined('TESTSUITE')) { } PMA_exportServer( $db_select, $whatStrucOrData, $export_plugin, $crlf, $err_url, - $export_type, $do_relation, $do_comments, $do_mime, $do_dates + $export_type, $do_relation, $do_comments, $do_mime, $do_dates, + $aliases ); } elseif ($export_type == 'database') { PMA_exportDatabase( $db, $tables, $whatStrucOrData, $export_plugin, $crlf, $err_url, - $export_type, $do_relation, $do_comments, $do_mime, $do_dates + $export_type, $do_relation, $do_comments, $do_mime, $do_dates, + $aliases ); } else { // We export just one table @@ -392,8 +408,7 @@ if (!defined('TESTSUITE')) { PMA_exportTable( $db, $table, $whatStrucOrData, $export_plugin, $crlf, $err_url, $export_type, $do_relation, $do_comments, $do_mime, $do_dates, - $allrows, $limit_to, $limit_from, $sql_query, - PMA_SQP_getAliasesFromQuery($sql_query, $db) + $allrows, $limit_to, $limit_from, $sql_query, $aliases ); } if (! $export_plugin->exportFooter()) { diff --git a/js/export.js b/js/export.js index 2f80e1518b..012d618069 100644 --- a/js/export.js +++ b/js/export.js @@ -42,6 +42,9 @@ AJAX.registerTeardown('export.js', function () { $("#plugins").unbind('change'); $("input[type='radio'][name='quick_or_custom']").unbind('change'); $("input[type='radio'][name='allrows']").unbind('change'); + $('#btn_alias_config').off('click'); + $('#db_alias_select').off('change'); + $('.table_alias_select').off('change'); }); AJAX.registerOnload('export.js', function () { @@ -246,6 +249,73 @@ function check_time_out(time_limit) }, time_limit * 1000); } + +/** + * Handler for Database/table alias select + * + * @param object event the event object + * + * @return void + */ +function aliasSelectHandler(event) { + var sel = event.data.sel; + var type = event.data.type; + var inputId = $(this).val(); + var $label = $(this).next('label'); + $('input#' + $label.attr('for')).addClass('hide'); + $('input#' + inputId).removeClass('hide'); + $label.attr('for', inputId); + //alert('#' + $label.attr('for')); + $('#alias_modal ' + sel + '[id$=' + type + ']:visible').addClass('hide'); + $('#alias_modal ' + sel + '#' + inputId + type).removeClass('hide'); + $("#alias_modal").dialog("option", "position", "center"); +} + +/** + * Handler for Alias dialog box + * + * @param object event the event object + * + * @return void + */ + function createAliasModal(event) { + event.preventDefault(); + $('#alias_modal').dialog({ + width: Math.min($(window).width() - 100, 700), + modal: true, + dialogClass: "alias-dialog", + buttons: { + 'Reset All': function() { + $(this).find('input[type="text"]').val(''); + }, + 'Reset': function() { + $(this).find('input[type="text"]:visible').val(''); + }, + 'Save & Close': function() { + $(this).dialog("close"); + $('#alias_modal').parent().appendTo($('form[name="dump"]')); + } + }, + create: function() { + $(this).css('maxHeight', $(window).height() - 150); + $('.alias-dialog .ui-dialog-titlebar-close').remove(); + }, + close: function() { + var isEmpty = true; + $(this).find('input[type="text"]').each(function() { + // trim input fields on close + $(this).val($(this).val().trim()); + // check if non empty field present + if ($(this).val()) { + isEmpty = false; + } + }); + $('input#btn_alias_config').attr('checked', !isEmpty); + }, + position: 'center' + }); + } + AJAX.registerOnload('export.js', function () { $("input[type='radio'][name='quick_or_custom']").change(toggle_quick_or_custom); @@ -278,4 +348,21 @@ AJAX.registerOnload('export.js', function () { disable_dump_some_rows_sub_options(); } }); + + // Open Alias Modal Dialog on click + $('#btn_alias_config').on('click', createAliasModal); + + // Database alias select on change event + $('#db_alias_select').on( + 'change', + {sel: 'span', type: '_tables'}, + aliasSelectHandler + ); + + // Table alias select on change event + $('.table_alias_select').on( + 'change', + {sel: 'table', type: '_cols'}, + aliasSelectHandler + ); }); diff --git a/libraries/display_export.lib.php b/libraries/display_export.lib.php index 01dee658ae..9b48b886df 100644 --- a/libraries/display_export.lib.php +++ b/libraries/display_export.lib.php @@ -634,6 +634,10 @@ function PMA_getHtmlForExportOptionsOutput($export_type) $html = '
'; $html .= '

' . __('Output:') . '

'; $html .= '