diff --git a/js/sql.js b/js/sql.js index fcf96de5b..9bc28e343 100644 --- a/js/sql.js +++ b/js/sql.js @@ -244,6 +244,8 @@ $(document).ready(function() { // Collect values of all fields to submit, we don't know which changed var params_to_submit = {}; var relation_fields = new Array(); + var transform_fields = {}; + var transformation_fields = false; $(input_siblings).each(function() { @@ -251,11 +253,20 @@ $(document).ready(function() { var field_name = getFieldName($(this), disp_mode); var this_field_params = {}; + + if($(this).is('.transformed')) { + transformation_fields = true; + } + if($(this).is(":not(.relation, .enum)")) { this_field_params[field_name] = $(this).find('textarea').val(); + if($(this).is('.transformed')) { + $.extend(transform_fields, this_field_params); + } } else { this_field_params[field_name] = $(this).find('select').val(); + if($(this).is('.relation')) { relation_fields.push(field_name); } @@ -277,6 +288,7 @@ $(document).ready(function() { if(relation_fields.length > 0) { rel_fields_list = relation_fields.join(); } + var transform_fields_list = $.param(transform_fields); // Make the Ajax post after setting all parameters var post_params = {'ajax_request' : true, @@ -288,6 +300,8 @@ $(document).ready(function() { 'clause_is_unique' : nonunique, 'where_clause' : where_clause, 'rel_fields_list' : rel_fields_list, + 'do_transformations' : transformation_fields, + 'transform_fields_list' : transform_fields_list, 'goto' : 'sql.php' }; @@ -300,6 +314,18 @@ $(document).ready(function() { // Inline edit post has been successful. if($(this).is(':not(.relation, .enum)')) { var new_html = $(this).find('textarea').val(); + + if($(this).is('.transformed')) { + var field_name = getFieldName($(this), disp_mode); + var this_field = $(this); + + $.each(data.transformations, function(key, value) { + if(key == field_name) { + var new_value = $(this_field).find('textarea').val(); + new_html = $(value).append(new_value); + } + }) + } } else { var new_html = $(this).find('select').val(); diff --git a/sql.php b/sql.php index eb7550407..4bad40020 100755 --- a/sql.php +++ b/sql.php @@ -593,7 +593,7 @@ if (0 == $num_rows || $is_affected) { $map = PMA_getForeigners($db, $table, '', 'both'); - $rel_fields = explode(',', $rel_fields_list); + $rel_fields = explode(',', $_REQUEST['rel_fields_list']); foreach( $rel_fields as $rel_field) { @@ -611,6 +611,36 @@ if (0 == $num_rows || $is_affected) { $extra_data['relations'][$rel_field] .= ''; } } + + if(isset($_REQUEST['do_transformations']) && $_REQUEST['do_transformations'] == true ) { + require_once './libraries/transformations.lib.php'; + //if some posted fields need to be transformed, generate them here. + $mime_map = PMA_getMIME($db, $table); + + $edited_values = array(); + parse_str($_REQUEST['transform_fields_list'], $edited_values); + + foreach($mime_map as $transformation) { + $include_file = $transformation['transformation']; + $column_name = $transformation['column_name']; + $column_data = $edited_values[$column_name]; + + if (file_exists('./libraries/transformations/' . $include_file)) { + $transformfunction_name = str_replace('.inc.php', '', $transformation['transformation']); + + require_once './libraries/transformations/' . $include_file; + + if (function_exists('PMA_transformation_' . $transformfunction_name)) { + $transform_function = 'PMA_transformation_' . $transformfunction_name; + $transform_options = PMA_transformation_getOptions((isset($transformation['transformation_options']) ? $transformation['transformation_options'] : '')); + //$meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']); + } + } + + $extra_data['transformations'][$column_name] = $transform_function($column_data, $transform_options); + } + } + $extra_data['sql_query'] = PMA_showMessage(NULL, $GLOBALS['display_query']); PMA_ajaxResponse($message, $message->isSuccess(), $extra_data);