From 709a63d55fdeb3b8b1056e3295f7bd422cc60ae7 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sun, 29 Apr 2012 10:05:07 -0400 Subject: [PATCH 1/5] Incorrect level for unique key verification --- libraries/export/htmlword.php | 41 ++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/libraries/export/htmlword.php b/libraries/export/htmlword.php index d3b0940cfd..97bc7bc7d4 100644 --- a/libraries/export/htmlword.php +++ b/libraries/export/htmlword.php @@ -201,10 +201,20 @@ if (isset($plugin_list)) { $schema_insert .= '' . __('Default') . ''; $schema_insert .= ''; + /** + * Get the unique keys in the table + */ + $unique_keys = array(); + $keys = PMA_DBI_get_table_indexes($db, $table); + foreach ($keys as $key) { + if ($key['Non_unique'] == 0) { + $unique_keys[] = $key['Column_name']; + } + } $columns = PMA_DBI_get_columns($db, $view); foreach ($columns as $column) { - $schema_insert .= PMA_formatOneColumnDefinition($column); + $schema_insert .= PMA_formatOneColumnDefinition($column, $unique_keys); $schema_insert .= ''; } @@ -295,8 +305,18 @@ if (isset($plugin_list)) { $schema_insert .= ''; $columns = PMA_DBI_get_columns($db, $table); + /** + * Get the unique keys in the table + */ + $unique_keys = array(); + $keys = PMA_DBI_get_table_indexes($db, $table); + foreach ($keys as $key) { + if ($key['Non_unique'] == 0) { + $unique_keys[] = $key['Column_name']; + } + } foreach ($columns as $column) { - $schema_insert .= PMA_formatOneColumnDefinition($column); + $schema_insert .= PMA_formatOneColumnDefinition($column, $unique_keys); $field_name = $column['Field']; if ($do_relation && $have_rel) { @@ -407,28 +427,15 @@ if (isset($plugin_list)) { * Formats the definition for one column * * @param array $column info about this column + * @param array $unique_keys unique keys of the table * * @return string Formatted column definition * * @access public */ function PMA_formatOneColumnDefinition( - $column + $column, $unique_keys ) { - /** - * Get the unique keys in the table - */ - $unique_keys = array(); - $keys = PMA_DBI_get_table_indexes($db, $table); - foreach ($keys as $key) { - if ($key['Non_unique'] == 0) { - $unique_keys[] = $key['Column_name']; - } - } - - /** - * Formats the definition - */ $definition = ''; $extracted_columnspec = PMA_extractColumnSpec($column['Type']); $type = htmlspecialchars($extracted_columnspec['print_type']); From b2424d2555b8f694522a34d2e29b3aedb9396a96 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sun, 29 Apr 2012 10:18:54 -0400 Subject: [PATCH 2/5] Fix duplicate code --- libraries/export/texytext.php | 108 +++++++++++++++------------------- 1 file changed, 47 insertions(+), 61 deletions(-) diff --git a/libraries/export/texytext.php b/libraries/export/texytext.php index 0017a96bf1..5982482bae 100644 --- a/libraries/export/texytext.php +++ b/libraries/export/texytext.php @@ -177,7 +177,7 @@ if (isset($plugin_list)) { * Get the unique keys in the table */ $unique_keys = array(); - $keys = PMA_DBI_get_table_indexes($db, $table); + $keys = PMA_DBI_get_table_indexes($db, $view); foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; @@ -202,39 +202,11 @@ if (isset($plugin_list)) { $text_output .= '|' . __('Default'); $text_output .= "\n|------\n"; - $columns = PMA_DBI_get_columns($db, $table); + $columns = PMA_DBI_get_columns($db, $view); foreach ($columns as $column) { - - $extracted_columnspec = PMA_extractColumnSpec($column['Type']); - $type = $extracted_columnspec['print_type']; - if (empty($type)) { - $type = ' '; - } - - if (! isset($column['Default'])) { - if ($column['Null'] != 'NO') { - $column['Default'] = 'NULL'; - } - } - - $fmt_pre = ''; - $fmt_post = ''; - if (in_array($column['Field'], $unique_keys)) { - $fmt_pre = '**' . $fmt_pre; - $fmt_post = $fmt_post . '**'; - } - if ($column['Key']=='PRI') { - $fmt_pre = '//' . $fmt_pre; - $fmt_post = $fmt_post . '//'; - } - $text_output .= '|' . $fmt_pre . htmlspecialchars($column['Field']) . $fmt_post; - $text_output .= '|' . htmlspecialchars($type); - $text_output .= '|' . (($column['Null'] == '' || $column['Null'] == 'NO') ? __('No') : __('Yes')); - $text_output .= '|' . htmlspecialchars(isset($column['Default']) ? $column['Default'] : ''); - - $field_name = $column['Field']; + $text_output .= PMA_formatOneColumnDefinition($column, $unique_keys); $text_output .= "\n"; - } // end while + } // end foreach return $text_output; } @@ -333,34 +305,7 @@ if (isset($plugin_list)) { $columns = PMA_DBI_get_columns($db, $table); foreach ($columns as $column) { - - $extracted_columnspec = PMA_extractColumnSpec($column['Type']); - $type = $extracted_columnspec['print_type']; - if (empty($type)) { - $type = ' '; - } - - if (! isset($column['Default'])) { - if ($column['Null'] != 'NO') { - $column['Default'] = 'NULL'; - } - } - - $fmt_pre = ''; - $fmt_post = ''; - if (in_array($column['Field'], $unique_keys)) { - $fmt_pre = '**' . $fmt_pre; - $fmt_post = $fmt_post . '**'; - } - if ($column['Key']=='PRI') { - $fmt_pre = '//' . $fmt_pre; - $fmt_post = $fmt_post . '//'; - } - $text_output .= '|' . $fmt_pre . htmlspecialchars($column['Field']) . $fmt_post; - $text_output .= '|' . htmlspecialchars($type); - $text_output .= '|' . (($column['Null'] == '' || $column['Null'] == 'NO') ? __('No') : __('Yes')); - $text_output .= '|' . htmlspecialchars(isset($column['Default']) ? $column['Default'] : ''); - + $text_output .= PMA_formatOneColumnDefinition($column, $unique_keys); $field_name = $column['Field']; if ($do_relation && $have_rel) { @@ -374,7 +319,7 @@ if (isset($plugin_list)) { } $text_output .= "\n"; - } // end while + } // end foreach return $text_output; } // end of the 'PMA_getTableDef()' function @@ -465,5 +410,46 @@ if (isset($plugin_list)) { return PMA_exportOutputHandler($dump); } + /** + * Formats the definition for one column + * + * @param array $column info about this column + * @param array $unique_keys unique keys for this table + * + * @return string Formatted column definition + * + * @access public + */ + function PMA_formatOneColumnDefinition( + $column, $unique_keys + ) { + $extracted_columnspec = PMA_extractColumnSpec($column['Type']); + $type = $extracted_columnspec['print_type']; + if (empty($type)) { + $type = ' '; + } + + if (! isset($column['Default'])) { + if ($column['Null'] != 'NO') { + $column['Default'] = 'NULL'; + } + } + + $fmt_pre = ''; + $fmt_post = ''; + if (in_array($column['Field'], $unique_keys)) { + $fmt_pre = '**' . $fmt_pre; + $fmt_post = $fmt_post . '**'; + } + if ($column['Key']=='PRI') { + $fmt_pre = '//' . $fmt_pre; + $fmt_post = $fmt_post . '//'; + } + $definition = '|' . $fmt_pre . htmlspecialchars($column['Field']) . $fmt_post; + $definition .= '|' . htmlspecialchars($type); + $definition .= '|' . (($column['Null'] == '' || $column['Null'] == 'NO') ? __('No') : __('Yes')); + $definition .= '|' . htmlspecialchars(isset($column['Default']) ? $column['Default'] : ''); + return $definition; + } } ?> From e51c55fc3bf2b5b6a7933d16f0b295241333d1db Mon Sep 17 00:00:00 2001 From: Jo Michael Date: Sun, 29 Apr 2012 18:25:17 +0200 Subject: [PATCH 3/5] Move, edit columns: Don't remove Loading message until fields table is reloaded --- js/tbl_structure.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/js/tbl_structure.js b/js/tbl_structure.js index 44c0d28883..49afd99734 100644 --- a/js/tbl_structure.js +++ b/js/tbl_structure.js @@ -403,8 +403,7 @@ $(function() { buttons: button_options_error }); // end dialog options } else { - PMA_ajaxShowMessage(data.message); - reloadFieldForm(); + reloadFieldForm(data.message); $this.dialog('close'); } }); @@ -619,6 +618,7 @@ $(function() { if ($form.hasClass('ajax')) { PMA_prepareForAjaxRequest($form); //User wants to submit the form + PMA_ajaxShowMessage(); $.post($form.attr('action'), $form.serialize()+"&do_save_data=Save", function(data) { if ($("#sqlqueryresults").length != 0) { $("#sqlqueryresults").remove(); @@ -626,7 +626,6 @@ $(function() { $(".error").remove(); } if (data.success == true) { - PMA_ajaxShowMessage(data.message); $("
").insertAfter("#floating_menubar"); $("#sqlqueryresults").html(data.sql_query); $("#result_query .notice").remove(); @@ -637,7 +636,7 @@ $(function() { $("#add_columns").dialog("close").remove(); } /*Reload the field form*/ - reloadFieldForm(); + reloadFieldForm(data.message); } else { var $temp_div = $("
").append(data); var $error = $temp_div.find(".error code").addClass("error"); @@ -657,7 +656,7 @@ $(function() { /** * Reload fields table */ -function reloadFieldForm() { +function reloadFieldForm(message) { $.post($("#fieldsForm").attr('action'), $("#fieldsForm").serialize()+"&ajax_request=true", function(form_data) { var $temp_div = $("
").append(form_data); $("#fieldsForm").replaceWith($temp_div.find("#fieldsForm")); @@ -668,6 +667,9 @@ function reloadFieldForm() { $table_clone = false; $("div.replace_in_more").hide(); // fix "more" dropdown moreOptsMenuResize(); + setTimeout(function() { + PMA_ajaxShowMessage(message); + }, 500); }); } From f77906d67b2d8f85d98c9f89959a165357055ae3 Mon Sep 17 00:00:00 2001 From: Jo Michael Date: Sun, 29 Apr 2012 19:07:01 +0200 Subject: [PATCH 4/5] Sort fields table with JS after moving columns instead of 2nd ajax --- js/tbl_structure.js | 26 +++++++++++++++++++++++++- tbl_alter.php | 10 ++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/js/tbl_structure.js b/js/tbl_structure.js index 49afd99734..1f6980864c 100644 --- a/js/tbl_structure.js +++ b/js/tbl_structure.js @@ -403,7 +403,31 @@ $(function() { buttons: button_options_error }); // end dialog options } else { - reloadFieldForm(data.message); + // sort the fields table + var $fields_table = $("table#tablestructure tbody"); + // remove all existing rows and remember them + var $rows = $fields_table.find("tr").remove(); + // loop through the correct order + for (var i in data.columns) { + var the_column = data.columns[i]; + var $the_row + = $rows + .find("input:checkbox[value=" + the_column + "]") + .closest("tr"); + // append the row for this column to the table + $fields_table.append($the_row); + } + var $firstrow = $fields_table.find("tr").eq(0); + // Adjust the row numbers and colors + for (var $row = $firstrow; $row.length > 0; $row = $row.next()) { + $row + .find('td:nth-child(2)') + .text($row.index() + 1) + .end() + .removeClass("odd even") + .addClass($row.index() % 2 == 0 ? "odd" : "even"); + } + PMA_ajaxShowMessage(data.message); $this.dialog('close'); } }); diff --git a/tbl_alter.php b/tbl_alter.php index 219e820f09..7c658b332b 100644 --- a/tbl_alter.php +++ b/tbl_alter.php @@ -39,7 +39,7 @@ $err_url = 'tbl_structure.php?' . PMA_generate_common_url($db, $table); /** * Moving columns */ -if (isset($_REQUEST['move_columns']) +if (isset($_REQUEST['move_columns']) && is_array($_REQUEST['move_columns']) && $GLOBALS['is_ajax_request']) { /* @@ -127,7 +127,13 @@ if (isset($_REQUEST['move_columns']) if ($tmp_error) { PMA_ajaxResponse(PMA_Message::error($tmp_error), false); } - PMA_ajaxResponse(PMA_Message::success(__('The columns have been moved successfully.')), true); + PMA_ajaxResponse( + PMA_Message::success(__('The columns have been moved successfully.')), + true, + array( + 'columns' => $column_names + ) + ); } /** From afaa480f49245ed3e37afdc966d9d9ea12c5fec9 Mon Sep 17 00:00:00 2001 From: Jo Michael Date: Sun, 29 Apr 2012 19:14:51 +0200 Subject: [PATCH 5/5] Fix missing parameters 13 and 14 when tbl_create:112 calls PMA_Table::generateFieldSpec --- tbl_create.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tbl_create.php b/tbl_create.php index 978c83a742..588dbeb675 100644 --- a/tbl_create.php +++ b/tbl_create.php @@ -108,7 +108,9 @@ if (isset($_REQUEST['do_save_data'])) { ? $_REQUEST['field_comments'][$i] : '', $field_primary, - $i + $i, + '', + '' ); $query .= ', ';