diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index 10d2e60e87..3643e40de0 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -2,7 +2,7 @@ /* vim: set expandtab sw=4 ts=4 sts=4: */ /** * set of functions with the insert/edit features in pma - * + * * @package PhpMyAdmin */ @@ -12,23 +12,23 @@ if (! defined('PHPMYADMIN')) { /** * Retrieve form parameters for insert/edit form - * - * @param string $db name of the database - * @param string $table name of the table - * @param array $where_clauses where clauses - * @param array $where_clause_array array of where clauses - * @param string $err_url error url - * - * @return array $_form_params array of insert/edit form parameters + * + * @param string $db name of the database + * @param string $table name of the table + * @param array $where_clauses where clauses + * @param array $where_clause_array array of where clauses + * @param string $err_url error url + * + * @return array $_form_params array of insert/edit form parameters */ function PMA_getFormParametersForInsertForm($db, $table, $where_clauses, $where_clause_array, $err_url) { $_form_params = array( - 'db' => $db, - 'table' => $table, - 'goto' => $GLOBALS['goto'], - 'err_url' => $err_url, - 'sql_query' => $_REQUEST['sql_query'], + 'db' => $db, + 'table' => $table, + 'goto' => $GLOBALS['goto'], + 'err_url' => $err_url, + 'sql_query' => $_REQUEST['sql_query'], ); if (isset($where_clauses)) { foreach ($where_clause_array as $key_id => $where_clause) { @@ -43,15 +43,15 @@ function PMA_getFormParametersForInsertForm($db, $table, $where_clauses, $where_ /** * Retrieve the values for pma edit mode - * - * @param type $where_clause where clauses - * @param type $table name of the table - * @param type $db name of the database - * + * + * @param type $where_clause where clauses + * @param type $table name of the table + * @param type $db name of the database + * * @return type containing insert_mode,whereClauses, result array - * where_clauses_array and found_unique_key boolean value + * where_clauses_array and found_unique_key boolean value */ -function PMA_getValuesForEditMode($where_clause, $table, $db) +function PMA_getStuffForEditMode($where_clause, $table, $db) { $found_unique_key = false; if (isset($where_clause)) { @@ -67,11 +67,11 @@ function PMA_getValuesForEditMode($where_clause, $table, $db) /** * - * @return whereClauseArray array of where clauses + * @return whereClauseArray array of where clauses */ function PMA_getWhereClauseArray($where_clause) { - if(isset ($where_clause)) { + if (isset ($where_clause)) { if (is_array($where_clause)) { return $where_clause; } else { @@ -82,12 +82,12 @@ function PMA_getWhereClauseArray($where_clause) /** * Analysing where cluases array - * + * * @param array $where_clause_array array of where clauses * @param string $table name of the table * @param string $db name of the database * @param boolean $found_unique_key boolean variable for unique key - * + * * @return array $where_clauses, $result, $rows */ function PMA_analyzeWhereClauses($where_clause_array, $table, $db, $found_unique_key) @@ -108,15 +108,15 @@ function PMA_analyzeWhereClauses($where_clause_array, $table, $db, $found_unique } /** - * Show message for empty reult or set the unique_condition - * + * Show message for empty reult or set the unique_condition + * * @param array $rows * @param string $key_id * @param array $where_clause_array * @param string $local_query * @param array $result * @param boolean $found_unique_key - * + * * @return boolean $found_unique_key */ function PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id, @@ -128,7 +128,7 @@ function PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id, PMA_showMessage(__('MySQL returned an empty result set (i.e. zero rows).'), $local_query); echo "\n"; include 'libraries/footer.inc.php'; - } else {// end if (no row returned) + } else {// end if (no row returned) $meta = PMA_DBI_get_fields_meta($result[$key_id]); list($unique_condition, $tmp_clause_is_unique) = PMA_getUniqueCondition($result[$key_id], count($meta), $meta, $rows[$key_id], true); @@ -142,10 +142,10 @@ function PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id, /** * No primary key given, just load first row - * + * * @param string $table name of the table * @param string $db name of the database - * + * * @return array containing $result and $rows arrays */ function PMA_loadFirstRowInEditMode($table, $db) @@ -161,16 +161,18 @@ function PMA_loadFirstRowInEditMode($table, $db) /** * Add some url parameters - * + * * @param array $url_params containing $db and $table as url parameters - * + * * @return array Add some url parameters to $url_params array * and return it */ -function PMA_urlParamsInEditMode($url_params) +function PMA_urlParamsInEditMode($url_params, $where_clause_array, $where_clause) { - if (isset($_REQUEST['where_clause'])) { - $url_params['where_clause'] = trim($_REQUEST['where_clause']); + if (isset($where_clause)) { + foreach ($where_clause_array as $key_id => $where_clause) { + $url_params['where_clause'] = trim($where_clause); + } } if (! empty($_REQUEST['sql_query'])) { $url_params['sql_query'] = $_REQUEST['sql_query']; @@ -180,15 +182,15 @@ function PMA_urlParamsInEditMode($url_params) /** * Show function fields in data edit view in pma - * + * * @param array $url_params containing url parameters - * + * * @return string an html snippet */ function PMA_showFunctionFieldsInEditMode($url_params, $showFuncFields) { $params = array(); - if(! $showFuncFields) { + if (! $showFuncFields) { $params['ShowFunctionFields'] = 1; } else { $params['ShowFunctionFields'] = 0; @@ -196,7 +198,7 @@ function PMA_showFunctionFieldsInEditMode($url_params, $showFuncFields) $params['ShowFieldTypesInDataEditView'] = $GLOBALS['cfg']['ShowFieldTypesInDataEditView']; $params['goto'] = 'sql.php'; $this_url_params = array_merge($url_params, $params); - if(! $showFuncFields) { + if (! $showFuncFields) { return ' : ' . __('Function') . '' . "\n"; } return ' ' . __('Function') . '' . "\n"; @@ -204,15 +206,15 @@ function PMA_showFunctionFieldsInEditMode($url_params, $showFuncFields) /** * Show field types in data edit view in pma - * + * * @param array $url_params containing url parameters - * + * * @return stirng an html snippet */ function PMA_showColumnTypesInDataEditView($url_params, $showColumnType ) { $params = array(); - if(! $showColumnType) { + if (! $showColumnType) { $params['ShowFieldTypesInDataEditView'] = 1; } else { $params['ShowFieldTypesInDataEditView'] = 0; @@ -220,17 +222,17 @@ function PMA_showColumnTypesInDataEditView($url_params, $showColumnType ) $params['ShowFunctionFields'] = $GLOBALS['cfg']['ShowFunctionFields']; $params['goto'] = 'sql.php'; $this_other_url_params = array_merge($url_params, $params); - if(! $showColumnType) { + if (! $showColumnType) { return ' : ' . __('Type') . '' . "\n"; } return ' ' . __('Type') . '' . "\n"; - + } /** * Retrieve the default for datetime data type - * + * * @param array $column containing column type, Default and null */ function PMA_getDefaultForDatetime($column) @@ -258,14 +260,14 @@ function PMA_getDefaultForDatetime($column) $column['Default'] = null; } } - + /** * Analyze the table column array - * + * * @param array $column description of column in given table * @param array $comments_map comments for every column that has a comment - * @param integer $timestamp_seen 0 interger - * + * @param integer $timestamp_seen 0 interger + * * @return array description of column in given table */ function PMA_analyzeTableColumnsArray($column, $comments_map, $timestamp_seen) @@ -280,18 +282,18 @@ function PMA_analyzeTableColumnsArray($column, $comments_map, $timestamp_seen) $column['is_binary'] = PMA_isColumnBinary($column); $column['is_blob'] = PMA_isColumnBlob($column); $column['is_char'] = PMA_isColumnChar($column); - list($column['pma_type'], $column['wrap'], $column['first_timestamp']) = + list($column['pma_type'], $column['wrap'], $column['first_timestamp']) = PMA_getEnumSetAndTimestampColumns($column, $timestamp_seen); - + return $column; } - + /** * Retrieve the column title - * + * * @param array $column description of column in given table * @param array $comments_map comments for every column that has a comment - * + * * @return string column title */ function PMA_getColumnTitle($column, $comments_map) @@ -304,12 +306,12 @@ function PMA_getColumnTitle($column, $comments_map) return $column['Field_html']; } } - + /** * check whether the column is a bainary - * + * * @param array $column description of column in given table - * + * * @return boolean If check to ensure types such as "enum('one','two','binary',..)" or * "enum('one','two','varbinary',..)" are not categorized as binary. */ @@ -324,14 +326,14 @@ function PMA_isColumnBinary($column) } else { return false; } - + } - + /** * check whether the column is a blob - * + * * @param array $column description of column in given table - * + * * @return boolean If check to ensure types such as "enum('one','two','blob',..)" or * "enum('one','two','tinyblob',..)" etc. are not categorized as blob. */ @@ -350,9 +352,9 @@ function PMA_isColumnBlob($column) /** * check is table column char - * + * * @param array $column description of column in given table - * + * * @return boolean If check to ensure types such as "enum('one','two','char',..)" or * "enum('one','two','varchar',..)" are not categorized as char. */ @@ -368,10 +370,10 @@ function PMA_isColumnChar($column) } /** * Retieve set, enum, timestamp table columns - * + * * @param array $column description of column in given table * @param int $timestamp_seen 0 interger - * + * * return array $column['pma_type'], $column['wrap'], $column['first_timestamp'] */ function PMA_getEnumSetAndTimestampColumns($column, $timestamp_seen) @@ -408,7 +410,7 @@ function PMA_getEnumSetAndTimestampColumns($column, $timestamp_seen) * We don't want binary data to be destroyed * Note: from the MySQL manual: "BINARY doesn't affect how the column is * stored or retrieved" so it does not mean that the contents is binary - * + * * @param array $column description of column in given table * @param boolean $is_upload upload or no * @param string $column_name_appendix the name atttibute @@ -418,13 +420,13 @@ function PMA_getEnumSetAndTimestampColumns($column, $timestamp_seen) * @param integer $tabindex tab index * @param integer $idindex id index * @param boolean $insert_mode insert mode or edit mode - * + * * @return string an html sippet */ function PMA_getFunctionColumn($column, $is_upload, $column_name_appendix, $unnullify_trigger, $no_support_types, $tabindex_for_function, $tabindex, $idindex, $insert_mode -) { +) { $html_output = ''; if (($GLOBALS['cfg']['ProtectBinary'] && $column['is_blob'] && !$is_upload) || ($GLOBALS['cfg']['ProtectBinary'] == 'all' && $column['is_binary']) @@ -438,7 +440,7 @@ function PMA_getFunctionColumn($column, $is_upload, $column_name_appendix, $html_output .= ' --' . "\n"; } else { $html_output .= '' . "\n"; - $html_output .= '' . "\n"; @@ -449,7 +451,7 @@ function PMA_getFunctionColumn($column, $is_upload, $column_name_appendix, /** * The null column - * + * * @param array $column description of column in given table * @param string $column_name_appendix the name atttibute * @param array $real_null_value is column value null or not null @@ -457,9 +459,9 @@ function PMA_getFunctionColumn($column, $is_upload, $column_name_appendix, * @param integer $tabindex_for_null +6000 * @param integer $idindex id index * @param array $vkey [multi_edit]['row_id'] - * @param array $foreigners keys into foreign fields - * @param array $foreignData data about the foreign keys - * + * @param array $foreigners keys into foreign fields + * @param array $foreignData data about the foreign keys + * * @return string an html snippet */ function PMA_getNullColumn($column, $column_name_appendix, $real_null_value, @@ -498,11 +500,11 @@ function PMA_getNullColumn($column, $column_name_appendix, $real_null_value, /** * Retrieve the nullify code for the null column - * + * * @param array $column description of column in given table - * @param array $foreigners keys into foreign fields + * @param array $foreigners keys into foreign fields * @param array $foreignData data about the foreign keys - * + * * @return integer $nullify_code */ function PMA_getNullifyCodeForNullColumn($column, $foreigners, $foreignData) @@ -529,7 +531,7 @@ function PMA_getNullifyCodeForNullColumn($column, $foreigners, $foreignData) /** * Get the HTML elements for value column in inert form - * + * * @param array $column description of column in given table * @param string $backup_field hidden input field * @param string $column_name_appendix the name atttibute @@ -544,16 +546,16 @@ function PMA_getNullifyCodeForNullColumn($column, $foreigners, $foreignData) * @param array $rownumber_param &rownumber=row_id * @param array $titles An HTML IMG tag for a particular icon from a theme, * which may be an actual file or an icon from a sprite - * @param array $text_dir + * @param array $text_dir * @param string $special_chars_encoded replaced char if the string starts - * with a \r\n pair (0x0d0a) add an extra \n + * with a \r\n pair (0x0d0a) add an extra \n * @param integer $biggest_max_file_size 0 intger * @param string $default_char_editing default char editing mode which is stroe * in the config.inc.php script * @param array $no_support_types list of datatypes that are not (yet) handled by PMA * @param array $gis_data_types list of GIS data types - * - * @return string an html snippet + * + * @return string an html snippet */ function PMA_getValueColumn($column, $backup_field, $column_name_appendix, $unnullify_trigger,$tabindex, $tabindex_for_value, $idindex, $data, @@ -562,18 +564,18 @@ function PMA_getValueColumn($column, $backup_field, $column_name_appendix, $default_char_editing, $no_support_types, $gis_data_types, $extracted_columnspec ) { $html_output = ''; - + if ($foreignData['foreign_link'] == true) { $html_output .= PMA_getForeignLink($column, $backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data, $paramTableDbArray, $rownumber_param, $titles ); - + } elseif (is_array($foreignData['disp_row'])) { $html_output .= PMA_dispRowForeignData($backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data, $foreignData ); - + } elseif ($GLOBALS['cfg']['LongtextDoubleTextarea'] && strstr($column['pma_type'], 'longtext')) { $html_output = ' '; $html_output .= ''; @@ -582,7 +584,7 @@ function PMA_getValueColumn($column, $backup_field, $column_name_appendix, $html_output .= PMA_getTextarea($column,$backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded ); - + } elseif (strstr($column['pma_type'], 'text')) { $html_output .= PMA_getTextarea($column,$backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded @@ -592,35 +594,35 @@ function PMA_getValueColumn($column, $backup_field, $column_name_appendix, $html_output .= " \n"; $html_output .= ' ' . __('Because of its length,
this column might not be editable'); } - + } elseif ($column['pma_type'] == 'enum') { $html_output .= PMA_getPmaTypeEnum($paramsArrayForColumns, $column,$extracted_columnspec); - + } elseif ($column['pma_type'] == 'set') { $html_output .= PMA_getPmaTypeSet($column,$extracted_columnspec, $backup_field, $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex); - + } elseif ($column['is_binary'] || $column['is_blob']) { $html_output .= PMA_getBinaryAndBlobColumn($column, $data, $special_chars,$biggest_max_file_size, $backup_field,$column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded, $vkey, $is_upload); - + } elseif (! in_array($column['pma_type'], $no_support_types)) { $html_output .= PMA_getNoSupportTypes($column, $default_char_editing,$backup_field, $column_name_appendix, $unnullify_trigger,$tabindex,$special_chars, - $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded, $data, $extracted_columnspec); + $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded, $data, $extracted_columnspec); } - + if (in_array($column['pma_type'], $gis_data_types)) { $html_output .= PMA_getHTMLforGisDataTypes($current_row, $column); } - + return $html_output; } /** * Get HTML for foreign link in insert form - * + * * @param array $column description of column in given table * @param string $backup_field hidden input field * @param string $column_name_appendix the name atttibute @@ -633,7 +635,7 @@ function PMA_getValueColumn($column, $backup_field, $column_name_appendix, * @param array $rownumber_param &rownumber=row_id * @param array $titles An HTML IMG tag for a particular icon from a theme, * which may be an actual file or an icon from a sprite - * + * * @return string an html snippet */ function PMA_getForeignLink($column, $backup_field, $column_name_appendix, @@ -659,7 +661,7 @@ function PMA_getForeignLink($column, $backup_field, $column_name_appendix, /** * Get HTML to display foreign data - * + * * @param string $backup_field hidden input field * @param string $column_name_appendix the name atttibute * @param string $unnullify_trigger validation string @@ -668,7 +670,7 @@ function PMA_getForeignLink($column, $backup_field, $column_name_appendix, * @param integer $idindex id index * @param array $data * @param array $foreignData data about the foreign keys - * + * * @return string an html snippet */ function PMA_dispRowForeignData($backup_field, $column_name_appendix, @@ -684,13 +686,13 @@ function PMA_dispRowForeignData($backup_field, $column_name_appendix, . PMA_foreignDropdown($foreignData['disp_row'], $foreignData['foreign_field'], $foreignData['foreign_display'], $data, $GLOBALS['cfg']['ForeignKeyMaxLimit']) . ''; - + return $html_output; } /** * Get HTML textarea for insert form - * + * * @param string $backup_field hidden input field * @param string $column_name_appendix the name atttibute * @param string $unnullify_trigger validation string @@ -700,7 +702,7 @@ function PMA_dispRowForeignData($backup_field, $column_name_appendix, * @param array $text_dir * @param array $special_chars_encoded replaced char if the string starts * with a \r\n pair (0x0d0a) add an extra \n - * + * * @return string an html snippet */ function PMA_getTextarea($column, $backup_field, $column_name_appendix, $unnullify_trigger, @@ -709,12 +711,12 @@ function PMA_getTextarea($column, $backup_field, $column_name_appendix, $unnulli $the_class = ''; $textAreaRows = $GLOBALS['cfg']['TextareaRows']; $textareaCols = $GLOBALS['cfg']['TextareaCols']; - - if($column['is_char']) { + + if ($column['is_char']) { $the_class = 'char'; $textAreaRows = $GLOBALS['cfg']['CharTextareaRows']; $textareaCols = $GLOBALS['cfg']['CharTextareaCols']; - } elseif(($GLOBALS['cfg']['LongtextDoubleTextarea'] && strstr($column['pma_type'], 'longtext'))) { + } elseif (($GLOBALS['cfg']['LongtextDoubleTextarea'] && strstr($column['pma_type'], 'longtext'))) { $textAreaRows = $GLOBALS['cfg']['TextareaRows']*2; $textareaCols = $GLOBALS['cfg']['TextareaCols']*2; } @@ -729,26 +731,26 @@ function PMA_getTextarea($column, $backup_field, $column_name_appendix, $unnulli . 'tabindex="' . ($tabindex + $tabindex_for_value) . '">' . $special_chars_encoded . ''; - + return $html_output; } /** * Get HTML for enum type - * + * * @param array $column description of column in given table * @param string $backup_field hidden input field * @param string $column_name_appendix the name atttibute * @param array $extracted_columnspec associative array containing type, spec_in_brackets * and possibly enum_set_values (another array) - * + * * @return string an html snippet */ function PMA_getPmaTypeEnum($column, $backup_field, $column_name_appendix, $extracted_columnspec) { - $html_output = ''; + $html_output = ''; if (! isset($column['values'])) { - $column['values'] = PMA_getColumnEnumValues($column, $extracted_columnspec); + $column['values'] = PMA_getColumnEnumValues($column, $extracted_columnspec); } $column_enum_values = $column['values']; $html_output .= ''; @@ -768,11 +770,11 @@ function PMA_getPmaTypeEnum($column, $backup_field, $column_name_appendix, $extr /** * Get column values - * + * * @param array $column description of column in given table * @param array $extracted_columnspec associative array containing type, spec_in_brackets * and possibly enum_set_values (another array) - * + * * @return array column values as an associative array */ function PMA_getColumnEnumValues($column, $extracted_columnspec) @@ -791,7 +793,7 @@ function PMA_getColumnEnumValues($column, $extracted_columnspec) /** * Get HTML drop down for more than 20 string length - * + * * @param array $column description of column in given table * @param string $column_name_appendix the name atttibute * @param string $unnullify_trigger validation string @@ -800,7 +802,7 @@ function PMA_getColumnEnumValues($column, $extracted_columnspec) * @param integer $idindex id index * @param array $data * @param array $column_enum_values $column['values'] - * + * * @return string an html snippet */ function PMA_getDropDownDependingOnLength($column, $column_name_appendix, $unnullify_trigger, @@ -812,7 +814,7 @@ function PMA_getDropDownDependingOnLength($column, $column_name_appendix, $unnul . 'tabindex="' . ($tabindex + $tabindex_for_value) . '"' . 'id="field_' . ($idindex) . '_3">' . '' . "\n"; - + foreach ($column_enum_values as $enum_value) { $html_output .= ' '; $html_output .= ''; } @@ -1312,12 +1315,12 @@ function PMA_getSubmitTypeDropDown($where_clause, $tabindex, $tabindex_for_value /** * Get HTML drop down for after insert - * + * * @param array $where_clause where clause * @param string $after_insert insert mode, e.g. new_insert, same_insert * @param string $after_insert a request parameter it can be 'edit_text', 'back' * @param boolean $found_unique_key boolean variable for unique key - * + * * @return string an html snippet */ function PMA_getAfterInsertDropDown($where_clause, $after_insert, $found_unique_key) @@ -1327,39 +1330,43 @@ function PMA_getAfterInsertDropDown($where_clause, $after_insert, $found_unique_ . __('Go back to previous page') . '' . ''; - + if (isset($where_clause)) { $html_output .= ''; - + // If we have just numeric primary key, we can also edit next // in 2.8.2, we were looking for `field_name` = numeric_value //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) { // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value $is_numeric = false; - for($i = 0; $i < count($where_clause); $i++) { - $is_numeric = preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause[$i]); - if ($is_numeric == true) { - break; + if(!is_array($where_clause)) { + $is_numeric = $found_unique_key && preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause); + } else { + for ($i = 0; $i < count($where_clause); $i++) { + $is_numeric = preg_match('@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@', $where_clause[$i]); + if ($is_numeric == true) { + break; + } } } if ($found_unique_key && $is_numeric) { $html_output .= ''; - + } } $html_output .= ''; return $html_output; - + } /** * get Submit button and Reset button for action panel - * + * * @param integer $tabindex tab index * @param integer $tabindex_for_value offset for the values tabindex - * + * * @return string an html snippet */ function PMA_getSumbitAndResetButtonForActionsPanel($tabindex, $tabindex_for_value) @@ -1377,9 +1384,9 @@ function PMA_getSumbitAndResetButtonForActionsPanel($tabindex, $tabindex_for_val /** * Get table head and table foot for insert row table - * + * * @param array $url_params url parameters - * + * * @return string an html snippet */ function PMA_getHeadAndFootOfInsertRowTable($url_params) @@ -1388,14 +1395,14 @@ function PMA_getHeadAndFootOfInsertRowTable($url_params) . '' . '' . '' . __('Column') . ''; - + if ($GLOBALS['cfg']['ShowFieldTypesInDataEditView']) { $html_output .= PMA_showColumnTypesInDataEditView($url_params, true); } if ($GLOBALS['cfg']['ShowFunctionFields']) { $html_output .= PMA_showFunctionFieldsInEditMode($url_params, true); } - + $html_output .= ''. __('Null') . '' . '' . __('Value') . '' . '' @@ -1412,14 +1419,14 @@ function PMA_getHeadAndFootOfInsertRowTable($url_params) /** * Prepares the field value and retrieve special chars, backup field and data array - * + * * @param array $current_row a row of the table * @param array $column description of column in given table * @param array $extracted_columnspec associative array containing type, spec_in_brackets * and possibly enum_set_values (another array) * @param boolean $real_null_value whether column value null or not null - * - * @return array $real_null_value, $data, $special_chars, $backup_field, $special_chars_encoded + * + * @return array $real_null_value, $data, $special_chars, $backup_field, $special_chars_encoded */ function PMA_getSpecialCharsAndBackupFieldForExistingRow($current_row, $column, $extracted_columnspec, $real_null_value, $gis_data_types, $column_name_appendix) @@ -1471,16 +1478,16 @@ function PMA_getSpecialCharsAndBackupFieldForExistingRow($current_row, $column, $backup_field = ''; - + return array($real_null_value, $special_chars_encoded, $special_chars, $data, $backup_field); } /** * display default values - * + * * @param type $column description of column in given table * @param boolean $real_null_value whether column value null or not null - * + * * @return array $real_null_value, $data, $special_chars, $backup_field, $special_chars_encoded */ function PMA_getSpecialCharsAndBackupFieldForInsertingMode($column, $real_null_value) @@ -1513,7 +1520,7 @@ function PMA_getSpecialCharsAndBackupFieldForInsertingMode($column, $real_null_v /** * Prepares the update/insert of a row - * + * * @return array $loop_array, $using_key, $is_insert, $is_insertignore */ function PMA_getParamsForUpdateOrInsert() @@ -1541,7 +1548,7 @@ function PMA_getParamsForUpdateOrInsert() /** * check wether insert row mode and if so include tbl_changen script and set global variables. - * + * * @return void */ function PMA_isInsertRow() @@ -1560,9 +1567,9 @@ function PMA_isInsertRow() /** * set $_SESSION for edit_next - * + * * @param string $one_where_clause one where clause from where clauses array - * + * * @return void */ function PMA_setSessionForEditNext($one_where_clause) @@ -1587,7 +1594,7 @@ function PMA_setSessionForEditNext($one_where_clause) * set $goto_include varible for different cases and retrieve like, * if $GLOBALS['goto'] empty, if $goto_include previously not defined * and new_insert, same_insert, same_insert - * + * * @param string $goto_include store some script for include, otherwise it is boolean false * @return string $goto_include */ @@ -1621,7 +1628,7 @@ function PMA_getGotoInclude($goto_include) /** * Defines the url to return in case of failure of the query - * + * * @param array $url_params url parameters * @return string error url for query failure */ @@ -1636,9 +1643,9 @@ function PMA_getErrorUrl($url_params) /** * Builds the sql query - * + * * @param boolean $is_insertignore $_REQUEST['submit_type'] == 'insertignore' - * @param array $query_fields column names array + * @param array $query_fields column names array * @param array $value_sets array of query values * @return string a query */ @@ -1657,14 +1664,15 @@ function PMA_buildSqlQuery($is_insertignore, $query_fields, $value_sets) /** * Executes the sql query and get the result, then move back to the calling page - * + * * @param array $url_params url paramters array * @param string $query built query from PMA_buildSqlQuery() * @return array $url_params, $total_affected_rows, $last_messages - * $warning_messages, $error_messages + * $warning_messages, $error_messages, $return_to_sql_query */ function PMA_executeSqlQuery($url_params, $query) { + $return_to_sql_query = null; if (! empty($GLOBALS['sql_query'])) { $url_params['sql_query'] = $GLOBALS['sql_query']; $return_to_sql_query = $GLOBALS['sql_query']; @@ -1673,12 +1681,12 @@ function PMA_executeSqlQuery($url_params, $query) // to ensure that the query is displayed in case of // "insert as new row" and then "insert another new row" $GLOBALS['display_query'] = $GLOBALS['sql_query']; - + $total_affected_rows = 0; $last_messages = array(); $warning_messages = array(); $error_messages = array(); - + foreach ($query as $single_query) { if ($_REQUEST['submit_type'] == 'showinsert') { $last_messages[] = PMA_Message::notice(__('Showing SQL query')); @@ -1715,12 +1723,12 @@ function PMA_executeSqlQuery($url_params, $query) $warning_messages = PMA_getWarningMessages(); } unset($result, $single_query, $last_message, $query); - return array($url_params, $total_affected_rows, $last_messages, $warning_messages, $error_messages); + return array($url_params, $total_affected_rows, $last_messages, $warning_messages, $error_messages, $return_to_sql_query); } /** * get the warning messages array - * + * * @return array $warning_essages */ function PMA_getWarningMessages() @@ -1734,4 +1742,225 @@ function PMA_getWarningMessages() } return $warning_essages; } + +/** + * Column to display from the foreign table? + * + * @param string $where_comparison string that contain relation field value + * @param string $relation_field_value relation field value + * @param array $map all Relations to foreign tables for a + * given table or optionally a given column in a table + * @param string $relation_field relation field + * + * @return string $dispval display value from the foriegn table + */ +function PMA_getDisplayValueForForiengTableColumn($where_comparison, $relation_field_value, $map, $relation_field) +{ + $display_field = PMA_getDisplayField($map[$relation_field]['foreign_db'], $map[$relation_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[$relation_field]['foreign_db']) + . '.' . PMA_backquote($map[$relation_field]['foreign_table']) + . ' WHERE ' . PMA_backquote($map[$relation_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); + } + @PMA_DBI_free_result($dispresult); + return $dispval; + } + return ''; +} + +/** + * Display option in the cell according to user choises + * + * @param array $map all Relations to foreign tables for a + * given table or optionally a given column in a table + * @param string $relation_field relation field + * @param string $where_comparison string that contain relation field value + * @param string $dispval display value from the foriegn table + * @param string $relation_field_value relation field value + * + * @return string $output HTML tag + */ +function PMA_getLinkForRelationalDisplayField($map, $relation_field, $where_comparison, + $dispval, $relation_field_value +){ + 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($relation_field_value) . '"'; + } + $_url_params = array( + 'db' => $map[$relation_field]['foreign_db'], + 'table' => $map[$relation_field]['foreign_table'], + 'pos' => '0', + 'sql_query' => 'SELECT * FROM ' + . PMA_backquote($map[$relation_field]['foreign_db']) . '.' . PMA_backquote($map[$relation_field]['foreign_table']) + . ' WHERE ' . PMA_backquote($map[$relation_field]['foreign_field']) . $where_comparison + ); + $output = ''; + + 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($relation_field_value); + } + $output .= ''; + return $output; +} + +/** + * Get transformation function and transformation options + * + * @param string $db db name + * @param string $table table name + * @param array $transformation mimetypes for all columns of a table + * [field_name][field_key] + * @param array $edited_values transform fields list + * @param array $extra_data extra data array + * + * @return array $extra_data + */ +function PMA_getTransformationFunctionAndTransformationOptions($db, $table, + $transformation, $edited_values, $extra_data, $include_file +) { + 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']); + + include_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 + return $extra_data; +} + +/** + * Get current value in multi edit mode + * + * @param array $multi_edit_colummns multiple edit column array + * @param array $multi_edit_columns_name multiple edit columns name array + * @param array $multi_edit_funcs multiple edit functions array + * @param array $gis_from_text_functions array that contains gis from text functions + * @param string $val + * @param array $gis_from_wkb_functions initialy $val is $multi_edit_colummns[$key] + * @param array $func_optional_param array('RAND','UNIX_TIMESTAMP') + * @param array $func_no_param array of set of string + * @param string $key an md5 of the column name + * + * @return array $val, $cur_value + */ +function PMA_getCurrentValueForMultipleEdit($multi_edit_colummns, $multi_edit_columns_name, $multi_edit_funcs, + $gis_from_text_functions, $val, $gis_from_wkb_functions, $func_optional_param, $func_no_param, $key +) { + if (empty($multi_edit_funcs[$key])) { + $cur_value = $val; + } elseif ('UUID' === $multi_edit_funcs[$key]) { + /* This way user will know what UUID new row has */ + $uuid = PMA_DBI_fetch_value('SELECT UUID()'); + $cur_value = "'" . $uuid . "'"; + } elseif ((in_array($multi_edit_funcs[$key], $gis_from_text_functions) + && substr($val, 0, 3) == "'''") + || in_array($multi_edit_funcs[$key], $gis_from_wkb_functions) + ) { + // Remove enclosing apostrophes + $val = substr($val, 1, strlen($val) - 2); + // Remove escaping apostrophes + $val = str_replace("''", "'", $val); + $cur_value = $multi_edit_funcs[$key] . '(' . $val . ')'; + } elseif (! in_array($multi_edit_funcs[$key], $func_no_param) + || ($val != "''" && in_array($multi_edit_funcs[$key], $func_optional_param))) { + $cur_value = $multi_edit_funcs[$key] . '(' . $val . ')'; + } else { + $cur_value = $multi_edit_funcs[$key] . '()'; + } + return array($val, $cur_value); +} + +/** + * Get query values array and query fileds array for insert and update in multi edit + * + * @param array $multi_edit_columns_name multiple edit columns name array + * @param array $multi_edit_columns_null multiple edit columns name array + * @param string $val + * @param array $multi_edit_columns_prev multiple edit previous columns array + * @param array $multi_edit_funcs multiple edit functions array + * @param boolean $is_insert boolean value whether insert or not + * @param array $query_values SET part of the sql query + * @param array $query_fields array of query fileds + * @param string $current_value current value in the column in loop + * @param array $value_sets array of valu sets + * @param string $key an md5 of the column name + * @param array $multi_edit_columns_null_prev array of multiple edit columnd null previous + * + * @return array ($query_values, $query_fields) + */ +function PMA_getQueryValuesForInsertAndUpdateInMultipleEdit($multi_edit_columns_name, + $multi_edit_columns_null, $val, $multi_edit_columns_prev, $multi_edit_funcs,$is_insert, + $query_values, $query_fields, $current_value, $value_sets, $key, $multi_edit_columns_null_prev +) { + // i n s e r t + if ($is_insert) { + // no need to add column into the valuelist + if (strlen($current_value)) { + $query_values[] = $current_value; + // first inserted row so prepare the list of fields + if (empty($value_sets)) { + $query_fields[] = PMA_backquote($multi_edit_columns_name[$key]); + } + } + // u p d a t e + } elseif (!empty($multi_edit_columns_null_prev[$key]) + && ! isset($multi_edit_columns_null[$key])) { + // field had the null checkbox before the update + // field no longer has the null checkbox + $query_values[] = PMA_backquote($multi_edit_columns_name[$key]) . ' = ' . $current_value; + } elseif (empty($multi_edit_funcs[$key]) + && isset($multi_edit_columns_prev[$key]) + && ("'" . PMA_sqlAddSlashes($multi_edit_columns_prev[$key]) . "'" == $val)) { + // No change for this column and no MySQL function is used -> next column + } elseif (! empty($val)) { + // avoid setting a field to NULL when it's already NULL + // (field had the null checkbox before the update + // field still has the null checkbox) + if (empty($multi_edit_columns_null_prev[$key]) + || empty($multi_edit_columns_null[$key]) + ) { + $query_values[] = PMA_backquote($multi_edit_columns_name[$key]) . ' = ' . $current_value; + } + } + return array($query_values, $query_fields); +} + ?> diff --git a/tbl_change.php b/tbl_change.php index 59addef9ad..38f4236d6a 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -156,7 +156,7 @@ if (! isset($where_clause)) { } //Retrieve values for data edit view list($insert_mode, $where_clauses, $result, $rows, $where_clause_array, $found_unique_key) - = PMA_getValuesForEditMode($where_clause, $table, $db); + = PMA_getStuffForEditMode($where_clause, $table, $db); // Copying a row - fetched data will be inserted as a new row, therefore the where clause is needless. if (isset($_REQUEST['default_action']) && $_REQUEST['default_action'] === 'insert') { @@ -201,7 +201,7 @@ $biggest_max_file_size = 0; $url_params['db'] = $db; $url_params['table'] = $table; -$url_params = PMA_urlParamsInEditMode($url_params); +$url_params = PMA_urlParamsInEditMode($url_params, $where_clause_array, $where_clause); //Insert/Edit form $html_output .= '
$where_clause) { // skip fields to be ignored if (! $using_key && isset($_REQUEST['insert_ignore_' . $where_clause])) { @@ -176,65 +177,17 @@ foreach ($loop_array as $rownumber => $where_clause) { // when inserting multiple entries foreach ($multi_edit_columns_name as $key => $colummn_name) { $val = $multi_edit_colummns[$key]; - // Note: $key is an md5 of the fieldname. The actual fieldname is available in $multi_edit_columns_name[$key] include 'libraries/tbl_replace_fields.inc.php'; + list($val, $cur_value) = PMA_getCurrentValueForMultipleEdit($multi_edit_colummns, + $multi_edit_columns_name, $multi_edit_funcs, $gis_from_text_functions, $val, + $gis_from_wkb_functions, $func_optional_param, $func_no_param, $key); - if (empty($multi_edit_funcs[$key])) { - $cur_value = $val; - } elseif ('UUID' === $multi_edit_funcs[$key]) { - /* This way user will know what UUID new row has */ - $uuid = PMA_DBI_fetch_value('SELECT UUID()'); - $cur_value = "'" . $uuid . "'"; - } elseif ((in_array($multi_edit_funcs[$key], $gis_from_text_functions) - && substr($val, 0, 3) == "'''") - || in_array($multi_edit_funcs[$key], $gis_from_wkb_functions) - ) { - // Remove enclosing apostrophes - $val = substr($val, 1, strlen($val) - 2); - // Remove escaping apostrophes - $val = str_replace("''", "'", $val); - $cur_value = $multi_edit_funcs[$key] . '(' . $val . ')'; - } elseif (! in_array($multi_edit_funcs[$key], $func_no_param) - || ($val != "''" && in_array($multi_edit_funcs[$key], $func_optional_param))) { - $cur_value = $multi_edit_funcs[$key] . '(' . $val . ')'; - } else { - $cur_value = $multi_edit_funcs[$key] . '()'; - } - - // i n s e r t - if ($is_insert) { - // no need to add column into the valuelist - if (strlen($cur_value)) { - $query_values[] = $cur_value; - // first inserted row so prepare the list of fields - if (empty($value_sets)) { - $query_fields[] = PMA_backquote($multi_edit_columns_name[$key]); - } - } - - // u p d a t e - } elseif (!empty($multi_edit_columns_null_prev[$key]) - && ! isset($multi_edit_columns_null[$key])) { - // field had the null checkbox before the update - // field no longer has the null checkbox - $query_values[] = PMA_backquote($multi_edit_columns_name[$key]) . ' = ' . $cur_value; - } elseif (empty($multi_edit_funcs[$key]) - && isset($multi_edit_columns_prev[$key]) - && ("'" . PMA_sqlAddSlashes($multi_edit_columns_prev[$key]) . "'" == $val)) { - // No change for this column and no MySQL function is used -> next column - continue; - } elseif (! empty($val)) { - // avoid setting a field to NULL when it's already NULL - // (field had the null checkbox before the update - // field still has the null checkbox) - if (empty($multi_edit_columns_null_prev[$key]) - || empty($multi_edit_columns_null[$key]) - ) { - $query_values[] = PMA_backquote($multi_edit_columns_name[$key]) . ' = ' . $cur_value; - } - } + list($query_values, $query_fields) = PMA_getQueryValuesForInsertAndUpdateInMultipleEdit( + $multi_edit_columns_name,$multi_edit_columns_null, $val, $multi_edit_columns_prev, + $multi_edit_funcs,$is_insert,$query_values, $query_fields, $cur_value, $value_sets, + $key, $multi_edit_columns_null_prev); } // end foreach ($multi_edit_colummns as $key => $val) if (count($query_values) > 0) { @@ -277,7 +230,7 @@ unset($multi_edit_colummns, $is_insertignore); * page */ list ($url_params, $total_affected_rows, $last_messages, $warning_messages, - $error_messages) = PMA_executeSqlQuery($url_params, $query); + $error_messages, $return_to_sql_query) = PMA_executeSqlQuery($url_params, $query); if ($is_insert && count($value_sets) > 0) { $message = PMA_Message::inserted_rows($total_affected_rows); @@ -312,63 +265,18 @@ if ($GLOBALS['is_ajax_request'] == true) { $map = PMA_getForeigners($db, $table, '', 'both'); - $rel_fields = array(); - parse_str($_REQUEST['rel_fields_list'], $rel_fields); + $relation_fields = array(); + parse_str($_REQUEST['rel_fields_list'], $relation_fields); // loop for each relation cell - foreach ( $rel_fields as $cell_index => $curr_cell_rel_field) { + foreach ( $relation_fields as $cell_index => $curr_cell_rel_field) { + foreach ( $curr_cell_rel_field as $relation_field => $relation_field_value) { + $where_comparison = "='" . $relation_field_value . "'"; + $dispval = PMA_displayForiengTableColumn($where_comparison, $relation_field_value, $map, $relation_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 = ''; - - 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 .= ''; - $extra_data['relations'][$cell_index] = $output; + $extra_data['relations'][$cell_index] = PMA_getLinkForRelationalDisplayField( + $map, $relation_field, $where_comparison, $dispval, $relation_field_value + ); } } // end of loop for each relation cell } @@ -388,35 +296,8 @@ if ($GLOBALS['is_ajax_request'] == true) { 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']); - - include_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 + $extra_data = PMA_getTransformationFunctionAndTransformationOptions($db, $table, + $transformation, $edited_values, $include_file, $column_name, $extra_data, $include_file); } // end of loop for each $mime_map } @@ -443,7 +324,7 @@ $active_page = $goto_include; * to the current record */ if (isset($_REQUEST['after_insert']) && 'new_insert' == $_REQUEST['after_insert']) { - unset($_REQUEST['where_clause']); + unset($_REQUEST['where_clause']); } /**