Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAris Feryanto <aris_feryanto@yahoo.com>2011-07-28 12:46:51 +0400
committerAris Feryanto <aris_feryanto@yahoo.com>2011-07-28 12:46:51 +0400
commit0e55c083a9583b013b8a5c8c97743b5b9f8a9152 (patch)
treebde956b8eab379e4c8dbab5d8896241490e28dfa /tbl_replace.php
parenta6850dd0892b7144e70af6b847066de7ca085465 (diff)
Grid edit: update relation and transformation correctly
Diffstat (limited to 'tbl_replace.php')
-rw-r--r--tbl_replace.php121
1 files changed, 121 insertions, 0 deletions
diff --git a/tbl_replace.php b/tbl_replace.php
index 48d01fc6de..75d041d81d 100644
--- a/tbl_replace.php
+++ b/tbl_replace.php
@@ -405,6 +405,127 @@ if (! empty($error_messages)) {
unset($error_messages, $warning_messages, $total_affected_rows, $last_messages, $last_message);
if ($GLOBALS['is_ajax_request'] == true) {
+ /**
+ * If we are in grid editing, we need to process the relational and
+ * transformed fields, if they were edited. After that, output the correct
+ * link/transformed value and exit
+ *
+ * Logic taken from libraries/display_tbl.lib.php
+ */
+
+ if (isset($_REQUEST['rel_fields_list']) && $_REQUEST['rel_fields_list'] != '') {
+ //handle relations work here for updated row.
+ require_once './libraries/relation.lib.php';
+
+ $map = PMA_getForeigners($db, $table, '', 'both');
+
+ $rel_fields = array();
+ parse_str($_REQUEST['rel_fields_list'], $rel_fields);
+
+ // loop for each relation cell
+ foreach ( $rel_fields as $cell_index => $curr_cell_rel_field) {
+
+ foreach ( $curr_cell_rel_field as $rel_field => $rel_field_value) {
+
+ $where_comparison = "='" . $rel_field_value . "'";
+ $display_field = PMA_getDisplayField($map[$rel_field]['foreign_db'], $map[$rel_field]['foreign_table']);
+
+ // Field to display from the foreign table?
+ if (isset($display_field) && strlen($display_field)) {
+ $dispsql = 'SELECT ' . PMA_backquote($display_field)
+ . ' FROM ' . PMA_backquote($map[$rel_field]['foreign_db'])
+ . '.' . PMA_backquote($map[$rel_field]['foreign_table'])
+ . ' WHERE ' . PMA_backquote($map[$rel_field]['foreign_field'])
+ . $where_comparison;
+ $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
+ if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
+ list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
+ } else {
+ //$dispval = __('Link not found');
+ }
+ @PMA_DBI_free_result($dispresult);
+ } else {
+ $dispval = '';
+ } // end if... else...
+
+ if ('K' == $_SESSION['tmp_user_values']['relational_display']) {
+ // user chose "relational key" in the display options, so
+ // the title contains the display field
+ $title = (! empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
+ } else {
+ $title = ' title="' . htmlspecialchars($rel_field_value) . '"';
+ }
+
+ $_url_params = array(
+ 'db' => $map[$rel_field]['foreign_db'],
+ 'table' => $map[$rel_field]['foreign_table'],
+ 'pos' => '0',
+ 'sql_query' => 'SELECT * FROM '
+ . PMA_backquote($map[$rel_field]['foreign_db']) . '.' . PMA_backquote($map[$rel_field]['foreign_table'])
+ . ' WHERE ' . PMA_backquote($map[$rel_field]['foreign_field'])
+ . $where_comparison
+ );
+ $output = '<a href="sql.php' . PMA_generate_common_url($_url_params) . '"' . $title . '>';
+
+ if ('D' == $_SESSION['tmp_user_values']['relational_display']) {
+ // user chose "relational display field" in the
+ // display options, so show display field in the cell
+ $output .= (!empty($dispval)) ? htmlspecialchars($dispval) : '';
+ } else {
+ // otherwise display data in the cell
+ $output .= htmlspecialchars($rel_field_value);
+ }
+ $output .= '</a>';
+ $extra_data['relations'][$cell_index] = $output;
+ }
+ } // end of loop for each relation cell
+ }
+
+ 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);
+
+ if ($mime_map === false) {
+ $mime_map = array();
+ }
+
+ $edited_values = array();
+ parse_str($_REQUEST['transform_fields_list'], $edited_values);
+
+ foreach($mime_map as $transformation) {
+ $include_file = PMA_securePath($transformation['transformation']);
+ $column_name = $transformation['column_name'];
+
+ foreach ($edited_values as $cell_index => $curr_cell_edited_values) {
+ if (isset($curr_cell_edited_values[$column_name])) {
+ $column_data = $curr_cell_edited_values[$column_name];
+
+ $_url_params = array(
+ 'db' => $db,
+ 'table' => $table,
+ 'where_clause' => $_REQUEST['where_clause'],
+ 'transform_key' => $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'] : ''));
+ $transform_options['wrapper_link'] = PMA_generate_common_url($_url_params);
+ }
+ }
+
+ $extra_data['transformations'][$cell_index] = $transform_function($column_data, $transform_options);
+ }
+ } // end of loop for each transformation cell
+ } // end of loop for each $mime_map
+ }
+
/**Get the total row count of the table*/
$extra_data['row_count'] = PMA_Table::countRecords($_REQUEST['db'],$_REQUEST['table']);
$extra_data['sql_query'] = PMA_showMessage(NULL, $GLOBALS['display_query']);