diff --git a/js/sql.js b/js/sql.js index 593cbe7de..a7a16c9e8 100644 --- a/js/sql.js +++ b/js/sql.js @@ -74,6 +74,7 @@ function appendInlineAnchor() { $cloned_tr.find('td') .addClass('inline_edit_anchor') + .find('span.sep, a:last').remove().end() .find('a').attr('href', '#') .find('span') .text(' ' + PMA_messages['strInlineEdit']) @@ -98,6 +99,7 @@ function appendInlineAnchor() { $img_object.attr('src', img_src); $cloned_anchor.addClass('inline_edit_anchor') + .find('span.sep, a:last').remove().end() .find('a').attr('href', '#') .find('span') .text(' ' + PMA_messages['strInlineEdit']) diff --git a/libraries/display_tbl.lib.php b/libraries/display_tbl.lib.php index 7d0299ccf..2831fdf51 100644 --- a/libraries/display_tbl.lib.php +++ b/libraries/display_tbl.lib.php @@ -1158,7 +1158,8 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { 'sql_query' => $url_sql_query, 'goto' => 'sql.php', ); - $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params); + $edit_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'update')); + $copy_url = 'tbl_change.php' . PMA_generate_common_url($_url_params + array('default_action' => 'insert')); $edit_str = PMA_getIcon('b_edit.png', __('Edit'), true); @@ -1224,7 +1225,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { if (! isset($js_conf)) { $js_conf = ''; } - echo PMA_generateCheckboxAndLinks('left', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, 'l', $edit_url, $edit_anchor_class, $edit_str, $del_str, $js_conf); + echo PMA_generateCheckboxAndLinks('left', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, 'l', $edit_url, $copy_url, $edit_anchor_class, $edit_str, $del_str, $js_conf); } // end if (1.3) } // end if (1) @@ -1439,7 +1440,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { if (! isset($js_conf)) { $js_conf = ''; } - echo PMA_generateCheckboxAndLinks('right', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, 'r', $edit_url, $edit_anchor_class, $edit_str, $del_str, $js_conf); + echo PMA_generateCheckboxAndLinks('right', $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, 'r', $edit_url, $copy_url, $edit_anchor_class, $edit_str, $del_str, $js_conf); } // end if (3) if ($_SESSION['tmp_user_values']['disp_direction'] == 'horizontal' @@ -1471,7 +1472,7 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { } if (isset($edit_url)) { - $vertical_display['edit'][$row_no] .= PMA_generateEditLink($edit_url, $alternating_color_class . ' ' . $edit_anchor_class . $vertical_class, $edit_str, $where_clause, $where_clause_html); + $vertical_display['edit'][$row_no] .= PMA_generateEditLink($edit_url, $copy_url, $alternating_color_class . ' ' . $edit_anchor_class . $vertical_class, $edit_str, $where_clause, $where_clause_html); } else { unset($vertical_display['edit'][$row_no]); } @@ -2481,17 +2482,19 @@ function PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_cla * * @uses PMA_linkOrButton() * @param string $edit_url + * @param string $copy_url * @param string $class * @param string $edit_str * @param string $where_clause * @param string $where_clause_html * @return string the generated HTML */ -function PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html) { +function PMA_generateEditLink($edit_url, $copy_url, $class, $edit_str, $where_clause, $where_clause_html) { $ret = ''; if (! empty($edit_url)) { - $ret .= '' - . PMA_linkOrButton($edit_url, $edit_str, array(), FALSE); + $ret .= '' + . PMA_linkOrButton($edit_url, $edit_str, array(), FALSE) . ' | ' + . PMA_linkOrButton($copy_url, __('Copy'), array(), FALSE); /* * Where clause for selecting this row uniquely is provided as * a hidden input. Used by jQuery scripts for handling inline editing @@ -2499,7 +2502,7 @@ function PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $wher if(! empty($where_clause)) { $ret .= ''; } - $ret .= ''; + $ret .= ''; } return $ret; } @@ -2543,26 +2546,27 @@ function PMA_generateDeleteLink($del_url, $del_str, $js_conf, $class) { * @param string $del_query * @param string $id_suffix * @param string $edit_url + * @param string $copy_url * @param string $class * @param string $edit_str * @param string $del_str * @param string $js_conf * @return string the generated HTML */ -function PMA_generateCheckboxAndLinks($position, $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, $id_suffix, $edit_url, $class, $edit_str, $del_str, $js_conf) { +function PMA_generateCheckboxAndLinks($position, $del_url, $is_display, $row_no, $where_clause, $where_clause_html, $del_query, $id_suffix, $edit_url, $copy_url, $class, $edit_str, $del_str, $js_conf) { $ret = ''; if ($position == 'left') { $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_left', '', '', ''); - $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, ''); + $ret .= PMA_generateEditLink($edit_url, $copy_url, $class, $edit_str, $where_clause, $where_clause_html, ''); $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', ''); } elseif ($position == 'right') { $ret .= PMA_generateDeleteLink($del_url, $del_str, $js_conf, '', ''); - $ret .= PMA_generateEditLink($edit_url, $class, $edit_str, $where_clause, $where_clause_html, ''); + $ret .= PMA_generateEditLink($edit_url, $copy_url, $class, $edit_str, $where_clause, $where_clause_html, ''); $ret .= PMA_generateCheckboxForMulti($del_url, $is_display, $row_no, $where_clause_html, $del_query, $id_suffix='_right', '', '', ''); } diff --git a/tbl_change.php b/tbl_change.php index d77ae864d..d18f59d9c 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -43,6 +43,9 @@ if (isset($_REQUEST['ShowFunctionFields'])) { if (isset($_REQUEST['ShowFieldTypesInDataEditView'])) { $cfg['ShowFieldTypesInDataEditView'] = $_REQUEST['ShowFieldTypesInDataEditView']; } +if (isset($_REQUEST['default_action'])) { + $default_action = $_REQUEST['default_action']; +} /** * file listing @@ -184,6 +187,7 @@ if (isset($where_clause)) { } unset($unique_condition, $tmp_clause_is_unique); } + } } else { // no primary key given, just load first row - but what happens if table is empty? @@ -192,6 +196,11 @@ if (isset($where_clause)) { $rows = array_fill(0, $cfg['InsertRows'], false); } +// Copying a row - fetched data will be inserted as a new row, therefore the where clause is needless. +if (isset($default_action) && $default_action === 'insert') { + unset($where_clause, $where_clauses); +} + // retrieve keys into foreign fields, if any $foreigners = PMA_getForeigners($db, $table); @@ -488,6 +497,13 @@ foreach ($rows as $row_id => $vrow) { $data = $vrow[$field['Field']]; } // end if... else... + + //when copying row, it is useful to empty auto-increment column to prevent duplicate key error + if (isset($default_action) && $default_action === 'insert') { + if ($field['Key'] === 'PRI' && strpos($field['Extra'], 'auto_increment') !== FALSE) { + $data = $special_chars_encoded = $special_chars = NULL; + } + } // If a timestamp field value is not included in an update // statement MySQL auto-update it to the current timestamp; // however, things have changed since MySQL 4.1, so