diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php
new file mode 100644
index 0000000000..10d2e60e87
--- /dev/null
+++ b/libraries/insert_edit.lib.php
@@ -0,0 +1,1737 @@
+ $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) {
+ $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause);
+ }
+ }
+ if (isset($_REQUEST['clause_is_unique'])) {
+ $_form_params['clause_is_unique'] = $_REQUEST['clause_is_unique'];
+ }
+ return $_form_params;
+}
+
+/**
+ * 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
+ *
+ * @return type containing insert_mode,whereClauses, result array
+ * where_clauses_array and found_unique_key boolean value
+ */
+function PMA_getValuesForEditMode($where_clause, $table, $db)
+{
+ $found_unique_key = false;
+ if (isset($where_clause)) {
+ $where_clause_array = PMA_getWhereClauseArray($where_clause);
+ list($whereClauses, $resultArray, $rowsArray, $found_unique_key)
+ = PMA_analyzeWhereClauses($where_clause_array, $table, $db, $found_unique_key);
+ return array(false, $whereClauses, $resultArray, $rowsArray, $where_clause_array, $found_unique_key);
+ } else {
+ list($results, $row) = PMA_loadFirstRowInEditMode($table, $db);
+ return array(true, null, $results, $row, null, $found_unique_key);
+ }
+}
+
+/**
+ *
+ * @return whereClauseArray array of where clauses
+ */
+function PMA_getWhereClauseArray($where_clause)
+{
+ if(isset ($where_clause)) {
+ if (is_array($where_clause)) {
+ return $where_clause;
+ } else {
+ return array(0 => $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)
+{
+ $rows = array();
+ $result = array();
+ $where_clauses = array();
+ foreach ($where_clause_array as $key_id => $where_clause) {
+ $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
+ . ' WHERE ' . $where_clause . ';';
+ $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
+ $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
+ $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause);
+ $found_unique_key = PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id,
+ $where_clause_array, $local_query, $result, $found_unique_key);
+ }
+ return array($where_clauses, $result, $rows, $found_unique_key);
+}
+
+/**
+ * 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,
+ $where_clause_array, $local_query, $result, $found_unique_key
+) {
+ // No row returned
+ if (! $rows[$key_id]) {
+ unset($rows[$key_id], $where_clause_array[$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)
+ $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);
+ if (! empty($unique_condition)) {
+ $found_unique_key = true;
+ }
+ unset($unique_condition, $tmp_clause_is_unique);
+ }
+ return $found_unique_key;
+}
+
+/**
+ * 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)
+{
+ $result = PMA_DBI_query(
+ 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;',
+ null,
+ PMA_DBI_QUERY_STORE
+ );
+ $rows = array_fill(0, $GLOBALS['cfg']['InsertRows'], false);
+ return array($result, $rows);
+}
+
+/**
+ * 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)
+{
+ if (isset($_REQUEST['where_clause'])) {
+ $url_params['where_clause'] = trim($_REQUEST['where_clause']);
+ }
+ if (! empty($_REQUEST['sql_query'])) {
+ $url_params['sql_query'] = $_REQUEST['sql_query'];
+ }
+ return $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) {
+ $params['ShowFunctionFields'] = 1;
+ } else {
+ $params['ShowFunctionFields'] = 0;
+ }
+ $params['ShowFieldTypesInDataEditView'] = $GLOBALS['cfg']['ShowFieldTypesInDataEditView'];
+ $params['goto'] = 'sql.php';
+ $this_url_params = array_merge($url_params, $params);
+ if(! $showFuncFields) {
+ return ' : ' . __('Function') . ' ' . "\n";
+ }
+ return '
'
+ . '';
+ $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
+ );
+ $html_output .= "\n";
+ if (strlen($special_chars) > 32000) {
+ $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);
+ }
+
+ 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
+ * @param string $unnullify_trigger validation string
+ * @param integer $tabindex tab index
+ * @param integer $tabindex_for_value offset for the values tabindex
+ * @param integer $idindex id index
+ * @param array $data
+ * @param array $paramTableDbArray array containing $db and $table
+ * @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,
+ $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data,
+ $paramTableDbArray, $rownumber_param, $titles
+) {
+ list($db, $table) = $paramTableDbArray;
+ $html_output = '';
+ $html_output .= $backup_field . "\n";
+ $html_output .= ' ';
+ $html_output .= ' '
+ . ''
+ . str_replace("'", "\'", $titles['Browse']) . ' ';
+ return $html_output;
+}
+
+/**
+ * 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
+ * @param integer $tabindex tab index
+ * @param integer $tabindex_for_value offset for the values tabindex
+ * @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,
+ $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data, $foreignData
+) {
+ $html_output = '';
+ $html_output .= $backup_field . "\n";
+ $html_output .= ' '
+ . '';
+
+ 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
+ * @param integer $tabindex tab index
+ * @param integer $tabindex_for_value offset for the values tabindex
+ * @param integer $idindex id index
+ * @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,
+ $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded
+) {
+ $the_class = '';
+ $textAreaRows = $GLOBALS['cfg']['TextareaRows'];
+ $textareaCols = $GLOBALS['cfg']['TextareaCols'];
+
+ if($column['is_char']) {
+ $the_class = 'char';
+ $textAreaRows = $GLOBALS['cfg']['CharTextareaRows'];
+ $textareaCols = $GLOBALS['cfg']['CharTextareaCols'];
+ } elseif(($GLOBALS['cfg']['LongtextDoubleTextarea'] && strstr($column['pma_type'], 'longtext'))) {
+ $textAreaRows = $GLOBALS['cfg']['TextareaRows']*2;
+ $textareaCols = $GLOBALS['cfg']['TextareaCols']*2;
+ }
+ $html_output = $backup_field . "\n"
+ . '';
+
+ 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 = '';
+ if (! isset($column['values'])) {
+ $column['values'] = PMA_getColumnEnumValues($column, $extracted_columnspec);
+ }
+ $column_enum_values = $column['values'];
+ $html_output .= ' ';
+ $html_output .= ' ';
+ $html_output .= "\n" . ' ' . $backup_field . "\n";
+ if (strlen($column['Type']) > 20) {
+ $html_output .= PMA_getDropDownDependingOnLength($column, $column_name_appendix, $unnullify_trigger,
+ $tabindex, $tabindex_for_value, $idindex, $data, $column_enum_values
+ );
+ } else {
+ $html_output .= PMA_getRadioButtonDependingOnLength($column_name_appendix, $unnullify_trigger,
+ $tabindex, $column, $tabindex_for_value, $idindex, $data, $column_enum_values
+ );
+ }
+ return $html_output;
+}
+
+/**
+ * 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)
+{
+ $column['values'] = array();
+ foreach ($extracted_columnspec['enum_set_values'] as $val) {
+ // Removes automatic MySQL escape format
+ $val = str_replace('\'\'', '\'', str_replace('\\\\', '\\', $val));
+ $column['values'][] = array(
+ 'plain' => $val,
+ 'html' => htmlspecialchars($val),
+ );
+ }
+ return $column['values'];
+}
+
+/**
+ * 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
+ * @param integer $tabindex tab index
+ * @param integer $tabindex_for_value offset for the values tabindex
+ * @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,
+ $tabindex, $tabindex_for_value, $idindex, $data, $column_enum_values
+) {
+ $html_output = ''
+ . ' ' . "\n";
+
+ foreach ($column_enum_values as $enum_value) {
+ $html_output .= ' ';
+ $html_output .= '' . "\n";
+ }
+ $html_output .= ' ';
+ return $html_output;
+}
+
+/**
+ * Get HTML radio button for less than 20 string length
+ *
+ * @param string $column_name_appendix the name atttibute
+ * @param string $unnullify_trigger validation string
+ * @param integer $tabindex tab index
+ * @param array $column description of column in given table
+ * @param integer $tabindex_for_value offset for the values tabindex
+ * @param integer $idindex id index
+ * @param array $data
+ * @param array $column_enum_values $column['values']
+ *
+ * @return string an html snippet
+ */
+function PMA_getRadioButtonDependingOnLength($column_name_appendix, $unnullify_trigger,
+ $tabindex, $column, $tabindex_for_value, $idindex, $data, $column_enum_values
+) {
+ $j = 0;
+ $html_output = '';
+ foreach ($column_enum_values as $enum_value) {
+ $html_output .= ' '
+ . ' ';
+ $html_output .= ''
+ . $enum_value['html'] . ' ' . "\n";
+ $j++;
+ }
+ return $html_output;
+}
+
+/**
+ * Get the HTML for 'set' pma type
+ *
+ * @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 string $backup_field hidden input field
+ * @param string $column_name_appendix the name atttibute
+ * @param string $unnullify_trigger validation string
+ * @param integer $tabindex tab index
+ * @param integer $tabindex_for_value offset for the values tabindex
+ * @param integer $idindex id index
+ *
+ * @return string an html snippet
+ */
+function PMA_getPmaTypeSet($column,$extracted_columnspec, $backup_field,
+ $column_name_appendix, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex
+) {
+ list($column_set_values, $select_size) = PMA_getColumnSetValueAndSelectSize($column, $extracted_columnspec);
+ $vset = array_flip(explode(',', $data));
+ $html_output = $backup_field . "\n";
+ $html_output .= ' ';
+ $html_output .= '';
+ foreach ($column_set_values as $column_set_value) {
+ $html_output .= ' ';
+ $html_output .= '' . "\n";
+ }
+ $html_output .= ' ';
+ return $html_output;
+}
+
+/**
+ * Retrieve column 'set' value and select size
+ *
+ * @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'], $column['select_size']
+ */
+function PMA_getColumnSetValueAndSelectSize($column, $extracted_columnspec)
+{
+ if (! isset($column['values'])) {
+ $column['values'] = array();
+ foreach ($extracted_columnspec['enum_set_values'] as $val) {
+ $column['values'][] = array(
+ 'plain' => $val,
+ 'html' => htmlspecialchars($val),
+ );
+ }
+ $column['select_size'] = min(4, count($column['values']));
+ }
+ return array($column['values'], $column['select_size']);
+}
+
+/**
+ * Get HTML for binary and blob column
+ *
+ * @param array $column description of column in given table
+ * @param array $data
+ * @param array $special_chars special characters
+ * @param integer $biggest_max_file_size biggest max file size for uploading
+ * @param string $backup_field hidden input field
+ * @param string $column_name_appendix the name atttibute
+ * @param string $unnullify_trigger validation string
+ * @param integer $tabindex tab index
+ * @param integer $tabindex_for_value offset for the values tabindex
+ * @param integer $idindex id index
+ * @param string $text_dir
+ * @param string $special_chars_encoded replaced char if the string starts
+ * with a \r\n pair (0x0d0a) add an extra \n
+ * @param string $vkey [multi_edit]['row_id']
+ * @param boolean $is_upload is upload or not
+ *
+ * @return string an html snippet
+ */
+function 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
+) {
+ $html_output = '';
+ if (($GLOBALS['cfg']['ProtectBinary'] && $column['is_blob'])
+ || ($GLOBALS['cfg']['ProtectBinary'] == 'all' && $column['is_binary'])
+ || ($GLOBALS['cfg']['ProtectBinary'] == 'noblob' && !$column['is_blob'])
+ ) {
+ $html_output .= __('Binary - do not edit');
+ if (isset($data)) {
+ $data_size = PMA_formatByteDown(strlen(stripslashes($data)), 3, 1);
+ $html_output .= ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
+ unset($data_size);
+ }
+
+ $html_output .= ' '
+ . ' ';
+ } elseif ($column['is_blob']) {
+ $html_output .= "\n"
+ . PMA_getTextarea($column,$backup_field, $column_name_appendix, $unnullify_trigger,
+ $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded);
+ } else {
+ // field size should be at least 4 and max $GLOBALS['cfg']['LimitChars']
+ $fieldsize = min(max($column['len'], 4), $GLOBALS['cfg']['LimitChars']);
+ $html_output .= "\n"
+ . $backup_field . "\n"
+ . PMA_getHTMLinput($column, $column_name_appendix, $special_chars, $fieldsize,
+ $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex);
+ }
+
+ if ($is_upload && $column['is_blob']) {
+ $html_output .= ' '
+ . ' ';
+ list($html_out, $biggest_max_file_size) = PMA_getMaxUploadSize($column,$biggest_max_file_size);
+ $html_output .= $html_out;
+ }
+
+ if (!empty($GLOBALS['cfg']['UploadDir'])) {
+ $html_output .= PMA_getSelectOptionForUpload($vkey, $column);
+ }
+
+ return $html_output;
+}
+
+/**
+ * Get HTML input type
+ *
+ * @param array $column description of column in given table
+ * @param string $column_name_appendix the name atttibute
+ * @param array $special_chars special characters
+ * @param integer $fieldsize html field size
+ * @param string $unnullify_trigger validation string
+ * @param integer $tabindex tab index
+ * @param integer $tabindex_for_value offset for the values tabindex
+ * @param integer $idindex id index
+ *
+ * @return string an html snippet
+ */
+function PMA_getHTMLinput($column, $column_name_appendix, $special_chars,
+ $fieldsize, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex
+) {
+ $the_class = 'textfield';
+ if ($column['pma_type'] == 'date') {
+ $the_class .= ' datefield';
+ } elseif ($column['pma_type'] == 'datetime'
+ || substr($column['pma_type'], 0, 9) == 'timestamp'
+ ) {
+ $the_class .= ' datetimefield';
+ }
+ return ' ';
+}
+
+/**
+ * Get HTML select option for upload
+ *
+ * @param string $vkey [multi_edit]['row_id']
+ * @param array $column description of column in given table
+ *
+ * @return string an html snippet
+ */
+function PMA_getSelectOptionForUpload($vkey, $column)
+{
+ $files = PMA_getFileSelectOptions(PMA_userDir($GLOBALS['cfg']['UploadDir']));
+ if ($files === false) {
+ return ' ' . __('Error') . ' ' . "\n"
+ . ' ' . __('The directory you set for upload work cannot be reached') . "\n";
+ } elseif (!empty($files)) {
+ return " \n"
+ . ' ' . __('Or') . ' ' . ' ' . __('web server upload directory') . ': ' . "\n"
+ . ' ' . "\n"
+ . ' ' . "\n"
+ . $files
+ . ' ' . "\n";
+ }
+}
+
+/**
+ * Retrieve the maximum upload file size
+ *
+ * @param array $column description of column in given table
+ * @param integer $biggest_max_file_size biggest max file size for uploading
+ *
+ * @return array an html snippet and $biggest_max_file_size
+ */
+function PMA_getMaxUploadSize($column, $biggest_max_file_size)
+{
+ // find maximum upload size, based on field type
+ /**
+ * @todo with functions this is not so easy, as you can basically
+ * process any data with function like MD5
+ */
+ global $max_upload_size;
+ $max_field_sizes = array(
+ 'tinyblob' => '256',
+ 'blob' => '65536',
+ 'mediumblob' => '16777216',
+ 'longblob' => '4294967296'); // yeah, really
+
+ $this_field_max_size = $max_upload_size; // from PHP max
+ if ($this_field_max_size > $max_field_sizes[$column['pma_type']]) {
+ $this_field_max_size = $max_field_sizes[$column['pma_type']];
+ }
+ $html_output = PMA_getFormattedMaximumUploadSize($this_field_max_size) . "\n";
+ // do not generate here the MAX_FILE_SIZE, because we should
+ // put only one in the form to accommodate the biggest field
+ if ($this_field_max_size > $biggest_max_file_size) {
+ $biggest_max_file_size = $this_field_max_size;
+ }
+ return array($html_output, $biggest_max_file_size);
+}
+
+/**
+ * Get HTML for pma no support types
+ *
+ * @param array $column description of column in given table
+ * @param string $default_char_editing default char editing mode which is stroe
+ * in the config.inc.php script
+ * @param string $backup_field hidden input field
+ * @param string $column_name_appendix the name atttibute
+ * @param string $unnullify_trigger validation string
+ * @param integer $tabindex tab index
+ * @param array $special_chars apecial characters
+ * @param integer $tabindex_for_value offset for the values tabindex
+ * @param integer $idindex id index
+ * @param string $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_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
+) {
+ $fieldsize = PMA_getColumnSize($column, $extracted_columnspec);
+ $html_output = $backup_field . "\n";
+ if ($column['is_char']
+ && ($GLOBALS['cfg']['CharEditing'] == 'textarea'
+ || strpos($data, "\n") !== false)
+ ) {
+ $html_output .= "\n";
+ $GLOBALS['cfg']['CharEditing'] = $default_char_editing;
+ $html_output .= PMA_getTextarea($column, $backup_field, $column_name_appendix, $unnullify_trigger,
+ $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded);
+ } else {
+ $html_output .= PMA_getHTMLinput($column, $column_name_appendix, $special_chars,
+ $fieldsize, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex);
+
+ if ($column['Extra'] == 'auto_increment') {
+ $html_output .= ' ';
+
+ }
+ if (substr($column['pma_type'], 0, 9) == 'timestamp') {
+ $html_output .= ' ';
+
+ }
+ if (substr($column['pma_type'], 0, 8) == 'datetime') {
+ $html_output .= ' ';
+
+ }
+ if ($column['True_Type'] == 'bit') {
+ $html_output .= ' ';
+
+ }
+ if ($column['pma_type'] == 'date'
+ || $column['pma_type'] == 'datetime'
+ || substr($column['pma_type'], 0, 9) == 'timestamp'
+ ) {
+ // the _3 suffix points to the date field
+ // the _2 suffix points to the corresponding NULL checkbox
+ // in dateFormat, 'yy' means the year with 4 digits
+ }
+ }
+ return $html_output;
+}
+
+/**
+ * Get the field size
+ *
+ * @param array $column description of column in given table
+ *
+ * @return integer field size
+ */
+function PMA_getColumnSize($column, $extracted_columnspec)
+{
+ if ($column['is_char']) {
+ $fieldsize = $extracted_columnspec['spec_in_brackets'];
+ if ($fieldsize > $GLOBALS['cfg']['MaxSizeForInputField']) {
+ /**
+ * This case happens for CHAR or VARCHAR columns which have
+ * a size larger than the maximum size for input field.
+ */
+ $GLOBALS['cfg']['CharEditing'] = 'textarea';
+ }
+ } else {
+ /**
+ * This case happens for example for INT or DATE columns;
+ * in these situations, the value returned in $column['len']
+ * seems appropriate.
+ */
+ $fieldsize = $column['len'];
+ }
+ return min(max($fieldsize, $GLOBALS['cfg']['MinSizeForInputField']), $GLOBALS['cfg']['MaxSizeForInputField']);
+}
+
+/**
+ * Get HTML for gis data types
+ *
+ * @param string $current_row row description
+ * @param array $column description of column in given table
+ *
+ * @return string an html snippet
+ */
+function PMA_getHTMLforGisDataTypes($current_row, $column)
+{
+ $data_val = isset($current_row[$column['Field']]) ? $current_row[$column['Field']] : '';
+ $_url_params = array(
+ 'field' => $column['Field_title'],
+ 'value' => $data_val,
+ );
+ if ($column['pma_type'] != 'geometry') {
+ $_url_params = $_url_params + array('gis_data[gis_type]' => strtoupper($column['pma_type']));
+ }
+ $edit_str = PMA_getIcon('b_edit.png', __('Edit/Insert'));
+ return ''
+ . PMA_linkOrButton('#', $edit_str, array(), false, false, '_blank')
+ . ' ';
+}
+
+/**
+ * get html for continue insertion form
+ *
+ * @param string $table name of the table
+ * @param string $db name of the database
+ * @param array $where_clause_array array of where clauses
+ * @param string $err_url error url
+ *
+ * @return string an html snippet
+ */
+function PMA_getContinueInsertionForm($table, $db, $where_clause_array, $err_url)
+{
+ $html_output = '' . "\n";
+ return $html_output;
+}
+
+/**
+ * Get action panel
+ *
+ * @param integer $tabindex tab index
+ * @param integer $tabindex_for_value offset for the values tabindex
+ * @param boolean $found_unique_key boolean variable for unique key
+ *
+ * @return string an html snippet
+ */
+function PMA_getActionsPanel($where_clause, $after_insert, $tabindex,
+ $tabindex_for_value, $found_unique_key
+) {
+ $html_output = ''
+ . ''
+ . ''
+ . ''
+ . PMA_getSubmitTypeDropDown($where_clause, $tabindex, $tabindex_for_value)
+ . "\n";
+
+ $html_output .= ' '
+ . ''
+ . ' ' . __('and then') . ' '
+ . ' '
+ . ''
+ . PMA_getAfterInsertDropDown($where_clause, $after_insert, $found_unique_key)
+ . ' '
+ . ' ';
+ $html_output .=''
+ . PMA_getSumbitAndResetButtonForActionsPanel($tabindex, $tabindex_for_value)
+ . ' '
+ . '
'
+ . ' ';
+ return $html_output;
+}
+
+/**
+ * Get a HTML drop down for submit types
+ *
+ * @param array $where_clause where clause
+ * @param integer $tabindex tab index
+ * @param integer $tabindex_for_value offset for the values tabindex
+ *
+ * @return string an html snippet
+ */
+function PMA_getSubmitTypeDropDown($where_clause, $tabindex, $tabindex_for_value)
+{
+ $html_output = '';
+ return $html_output;
+}
+
+/**
+ * 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)
+{
+ $html_output = ''
+ . ''
+ . __('Go back to previous page') . ' '
+ . ''
+ . __('Insert another new row') . ' ';
+
+ if (isset($where_clause)) {
+ $html_output .= ''
+ . __('Go back to this page') . ' ';
+
+ // 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 ($found_unique_key && $is_numeric) {
+ $html_output .= ''
+ . __('Edit next row') . ' ';
+
+ }
+ }
+ $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)
+{
+ return ''
+ . PMA_showHint(__('Use TAB key to move from value to value, or CTRL+arrows to move anywhere'))
+ . ' '
+ . ''
+ . ''
+ . ''
+ . ' ';
+}
+
+/**
+ * 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)
+{
+ $html_output = ''
+ . ''
+ . ''
+ . '' . __('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') . ' '
+ . ' '
+ . ' '
+ . ' '
+ . ''
+ . ''
+ . ' '
+ . ' ';
+ return $html_output;
+}
+
+/**
+ * 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
+ */
+function PMA_getSpecialCharsAndBackupFieldForExistingRow($current_row, $column, $extracted_columnspec,
+ $real_null_value, $gis_data_types, $column_name_appendix)
+{
+ $special_chars_encoded = '';
+ // (we are editing)
+ if (is_null($current_row[$column['Field']])) {
+ $real_null_value = true;
+ $current_row[$column['Field']] = '';
+ $special_chars = '';
+ $data = $current_row[$column['Field']];
+ } elseif ($column['True_Type'] == 'bit') {
+ $special_chars = PMA_printable_bit_value(
+ $current_row[$column['Field']], $extracted_columnspec['spec_in_brackets']
+ );
+ } elseif (in_array($column['True_Type'], $gis_data_types)) {
+ // Convert gis data to Well Know Text format
+ $current_row[$column['Field']] = PMA_asWKT($current_row[$column['Field']], true);
+ $special_chars = htmlspecialchars($current_row[$column['Field']]);
+ } else {
+ // special binary "characters"
+ if ($column['is_binary'] || ($column['is_blob'] && ! $GLOBALS['cfg']['ProtectBinary'])) {
+ if ($_SESSION['tmp_user_values']['display_binary_as_hex'] && $GLOBALS['cfg']['ShowFunctionFields']) {
+ $current_row[$column['Field']] = bin2hex($current_row[$column['Field']]);
+ $column['display_binary_as_hex'] = true;
+ } else {
+ $current_row[$column['Field']] = PMA_replaceBinaryContents($current_row[$column['Field']]);
+ }
+ } // end if
+ $special_chars = htmlspecialchars($current_row[$column['Field']]);
+
+ //We need to duplicate the first \n or otherwise we will lose
+ //the first newline entered in a VARCHAR or TEXT column
+ $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
+
+ $data = $current_row[$column['Field']];
+ } // end if... else...
+
+ //when copying row, it is useful to empty auto-increment column to prevent duplicate key error
+ if (isset($_REQUEST['default_action']) && $_REQUEST['default_action'] === 'insert') {
+ if ($column['Key'] === 'PRI' && strpos($column['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
+ // it's better to set a fields_prev in this situation
+ $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)
+{
+ if (! isset($column['Default'])) {
+ $column['Default'] = '';
+ $real_null_value = true;
+ $data = '';
+ } else {
+ $data = $column['Default'];
+ }
+
+ if ($column['True_Type'] == 'bit') {
+ $special_chars = PMA_convert_bit_default_value($column['Default']);
+ } else {
+ $special_chars = htmlspecialchars($column['Default']);
+ }
+ $backup_field = '';
+ $special_chars_encoded = PMA_duplicateFirstNewline($special_chars);
+ // this will select the UNHEX function while inserting
+ if (($column['is_binary'] || ($column['is_blob'] && ! $GLOBALS['cfg']['ProtectBinary']))
+ && (isset($_SESSION['tmp_user_values']['display_binary_as_hex'])
+ && $_SESSION['tmp_user_values']['display_binary_as_hex'])
+ && $GLOBALS['cfg']['ShowFunctionFields']
+ ) {
+ $column['display_binary_as_hex'] = true;
+ }
+ return array($real_null_value, $data, $special_chars, $backup_field, $special_chars_encoded);
+}
+
+/**
+ * Prepares the update/insert of a row
+ *
+ * @return array $loop_array, $using_key, $is_insert, $is_insertignore
+ */
+function PMA_getParamsForUpdateOrInsert()
+{
+ if (isset($_REQUEST['where_clause'])) {
+ // we were editing something => use the WHERE clause
+ $loop_array = (is_array($_REQUEST['where_clause']) ? $_REQUEST['where_clause'] : array($_REQUEST['where_clause']));
+ $using_key = true;
+ $is_insert = $_REQUEST['submit_type'] == 'insert'
+ || $_REQUEST['submit_type'] == 'showinsert'
+ || $_REQUEST['submit_type'] == 'insertignore';
+ $is_insertignore = $_REQUEST['submit_type'] == 'insertignore';
+ } else {
+ // new row => use indexes
+ $loop_array = array();
+ foreach ($_REQUEST['fields']['multi_edit'] as $key => $dummy) {
+ $loop_array[] = $key;
+ }
+ $using_key = false;
+ $is_insert = true;
+ $is_insertignore = false;
+ }
+ return array($loop_array, $using_key, $is_insert, $is_insertignore);
+}
+
+/**
+ * check wether insert row mode and if so include tbl_changen script and set global variables.
+ *
+ * @return void
+ */
+function PMA_isInsertRow()
+{
+ if (isset($_REQUEST['insert_rows'])
+ && is_numeric($_REQUEST['insert_rows'])
+ && $_REQUEST['insert_rows'] != $GLOBALS['cfg']['InsertRows']
+ ) {
+ $GLOBALS['cfg']['InsertRows'] = $_REQUEST['insert_rows'];
+ $GLOBALS['js_include'][] = 'tbl_change.js';
+ include_once 'libraries/header.inc.php';
+ include 'tbl_change.php';
+ exit;
+ }
+}
+
+/**
+ * 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)
+{
+ $local_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($GLOBALS['table'])
+ . ' WHERE ' . str_replace('` =', '` >', $one_where_clause)
+ . ' LIMIT 1;';
+ $res = PMA_DBI_query($local_query);
+ $row = PMA_DBI_fetch_row($res);
+ $meta = PMA_DBI_get_fields_meta($res);
+ // must find a unique condition based on unique key,
+ // not a combination of all fields
+ list($unique_condition, $clause_is_unique)
+ = PMA_getUniqueCondition($res, count($meta), $meta, $row, true);
+ if (! empty($unique_condition)) {
+ $_SESSION['edit_next'] = $unique_condition;
+ }
+ unset($unique_condition, $clause_is_unique);
+}
+
+/**
+ * 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
+ */
+function PMA_getGotoInclude($goto_include)
+{
+ if (isset($_REQUEST['after_insert'])
+ && in_array($_REQUEST['after_insert'], array('new_insert', 'same_insert', 'same_insert'))
+ ) {
+ $goto_include = 'tbl_change.php';
+ } elseif (! empty($GLOBALS['goto'])) {
+ if (! preg_match('@^[a-z_]+\.php$@', $GLOBALS['goto'])) {
+ // this should NOT happen
+ //$GLOBALS['goto'] = false;
+ $goto_include = false;
+ } else {
+ $goto_include = $GLOBALS['goto'];
+ }
+ if ($GLOBALS['goto'] == 'db_sql.php' && strlen($GLOBALS['table'])) {
+ $GLOBALS['table'] = '';
+ }
+ }
+ if (! $goto_include) {
+ if (! strlen($GLOBALS['table'])) {
+ $goto_include = 'db_sql.php';
+ } else {
+ $goto_include = 'tbl_sql.php';
+ }
+ }
+ return $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
+ */
+function PMA_getErrorUrl($url_params)
+{
+ if (isset($_REQUEST['err_url'])) {
+ return $_REQUEST['err_url'];
+ } else {
+ return 'tbl_change.php' . PMA_generate_common_url($url_params);
+ }
+}
+
+/**
+ * Builds the sql query
+ *
+ * @param boolean $is_insertignore $_REQUEST['submit_type'] == 'insertignore'
+ * @param array $query_fields column names array
+ * @param array $value_sets array of query values
+ * @return string a query
+ */
+function PMA_buildSqlQuery($is_insertignore, $query_fields, $value_sets)
+{
+ if ($is_insertignore) {
+ $insert_command = 'INSERT IGNORE ';
+ } else {
+ $insert_command = 'INSERT ';
+ }
+ $query[] = $insert_command . 'INTO ' . PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($GLOBALS['table'])
+ . ' (' . implode(', ', $query_fields) . ') VALUES (' . implode('), (', $value_sets) . ')';
+ unset($insert_command, $query_fields);
+ return $query;
+}
+
+/**
+ * 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
+ */
+function PMA_executeSqlQuery($url_params, $query)
+{
+ if (! empty($GLOBALS['sql_query'])) {
+ $url_params['sql_query'] = $GLOBALS['sql_query'];
+ $return_to_sql_query = $GLOBALS['sql_query'];
+ }
+ $GLOBALS['sql_query'] = implode('; ', $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'));
+ continue;
+ }
+ if ($GLOBALS['cfg']['IgnoreMultiSubmitErrors']) {
+ $result = PMA_DBI_try_query($single_query);
+ } else {
+ $result = PMA_DBI_query($single_query);
+ }
+ if (! $result) {
+ $error_messages[] = PMA_Message::sanitize(PMA_DBI_getError());
+ } else {
+ // The next line contains a real assignment, it's not a typo
+ if ($tmp = @PMA_DBI_affected_rows()) {
+ $total_affected_rows += $tmp;
+ }
+ unset($tmp);
+
+ $insert_id = PMA_DBI_insert_id();
+ if ($insert_id != 0) {
+ // insert_id is id of FIRST record inserted in one insert, so if we
+ // inserted multiple rows, we had to increment this
+
+ if ($total_affected_rows > 0) {
+ $insert_id = $insert_id + $total_affected_rows - 1;
+ }
+ $last_message = PMA_Message::notice(__('Inserted row id: %1$d'));
+ $last_message->addParam($insert_id);
+ $last_messages[] = $last_message;
+ }
+ PMA_DBI_free_result($result);
+ }
+ $warning_messages = PMA_getWarningMessages();
+ }
+ unset($result, $single_query, $last_message, $query);
+ return array($url_params, $total_affected_rows, $last_messages, $warning_messages, $error_messages);
+}
+
+/**
+ * get the warning messages array
+ *
+ * @return array $warning_essages
+ */
+function PMA_getWarningMessages()
+{
+ $warning_essages = array();
+ foreach (PMA_DBI_get_warnings() as $warning) {
+ $warning_essages[]
+ = PMA_Message::sanitize(
+ $warning['Level'] . ': #' . $warning['Code'] . ' ' . $warning['Message']
+ );
+ }
+ return $warning_essages;
+}
+?>
diff --git a/libraries/tbl_replace_fields.inc.php b/libraries/tbl_replace_fields.inc.php
index 5549c33456..e5a33d4654 100644
--- a/libraries/tbl_replace_fields.inc.php
+++ b/libraries/tbl_replace_fields.inc.php
@@ -42,8 +42,8 @@ if (false !== $possibly_uploaded_val) {
// f i e l d v a l u e i n t h e f o r m
- if (isset($me_fields_type[$key])) {
- $type = $me_fields_type[$key];
+ if (isset($multi_edit_columns_type[$key])) {
+ $type = $multi_edit_columns_type[$key];
} else {
$type = '';
}
@@ -51,7 +51,7 @@ if (false !== $possibly_uploaded_val) {
// $key contains the md5() of the fieldname
if ($type != 'protected' && $type != 'set' && 0 === strlen($val)) {
// best way to avoid problems in strict mode (works also in non-strict mode)
- if (isset($me_auto_increment) && isset($me_auto_increment[$key])) {
+ if (isset($multi_edit_auto_increment) && isset($multi_edit_auto_increment[$key])) {
$val = 'NULL';
} else {
$val = "''";
@@ -72,8 +72,8 @@ if (false !== $possibly_uploaded_val) {
// when in UPDATE mode, do not alter field's contents. When in INSERT
// mode, insert empty field because no values were submitted. If protected
// blobs where set, insert original fields content.
- if (! empty($prot_row[$me_fields_name[$key]])) {
- $val = '0x' . bin2hex($prot_row[$me_fields_name[$key]]);
+ if (! empty($prot_row[$multi_edit_columns_name[$key]])) {
+ $val = '0x' . bin2hex($prot_row[$multi_edit_columns_name[$key]]);
} else {
$val = '';
}
@@ -89,14 +89,14 @@ if (false !== $possibly_uploaded_val) {
// Was the Null checkbox checked for this field?
// (if there is a value, we ignore the Null checkbox: this could
// be possible if Javascript is disabled in the browser)
- if (! empty($me_fields_null[$key]) && ($val == "''" || $val == '')) {
+ if (! empty($multi_edit_columns_null[$key]) && ($val == "''" || $val == '')) {
$val = 'NULL';
}
// The Null checkbox was unchecked for this field
if (empty($val)
- && ! empty($me_fields_null_prev[$key])
- && ! isset($me_fields_null[$key])
+ && ! empty($multi_edit_columns_null_prev[$key])
+ && ! isset($multi_edit_columns_null[$key])
) {
$val = "''";
}
diff --git a/tbl_change.php b/tbl_change.php
index 5b42085dea..59addef9ad 100644
--- a/tbl_change.php
+++ b/tbl_change.php
@@ -19,38 +19,34 @@ require_once 'libraries/common.lib.php';
*/
require_once 'libraries/db_table_exists.lib.php';
+/**
+ * functions implementation for this script
+ */
+require_once 'libraries/insert_edit.lib.php';
+
/**
* Sets global variables.
* Here it's better to use a if, instead of the '?' operator
* to avoid setting a variable to '' when it's not present in $_REQUEST
*/
+
if (isset($_REQUEST['where_clause'])) {
$where_clause = $_REQUEST['where_clause'];
}
-if (isset($_REQUEST['clause_is_unique'])) {
- $clause_is_unique = $_REQUEST['clause_is_unique'];
-}
if (isset($_SESSION['edit_next'])) {
$where_clause = $_SESSION['edit_next'];
unset($_SESSION['edit_next']);
$after_insert = 'edit_next';
}
-if (isset($_REQUEST['sql_query'])) {
- $sql_query = $_REQUEST['sql_query'];
-}
if (isset($_REQUEST['ShowFunctionFields'])) {
$cfg['ShowFunctionFields'] = $_REQUEST['ShowFunctionFields'];
}
if (isset($_REQUEST['ShowFieldTypesInDataEditView'])) {
$cfg['ShowFieldTypesInDataEditView'] = $_REQUEST['ShowFieldTypesInDataEditView'];
}
-if (isset($_REQUEST['default_action'])) {
- $default_action = $_REQUEST['default_action'];
-}
if (isset($_REQUEST['after_insert'])) {
$after_insert = $_REQUEST['after_insert'];
}
-
/**
* file listing
*/
@@ -73,8 +69,8 @@ if (empty($GLOBALS['goto'])) {
* @todo check if we could replace by "db_|tbl_" - please clarify!?
*/
$_url_params = array(
- 'db' => $db,
- 'sql_query' => $sql_query
+ 'db' => $db,
+ 'sql_query' => $_REQUEST['sql_query']
);
if (preg_match('@^tbl_@', $GLOBALS['goto'])) {
@@ -133,7 +129,7 @@ if (! empty($disp_message)) {
if (! isset($disp_query)) {
$disp_query = null;
}
- echo PMA_getMessage($disp_message, $disp_query);
+ PMA_showMessage($disp_message, $disp_query);
}
/**
@@ -152,63 +148,27 @@ unset($show_create_table);
*/
PMA_DBI_select_db($db);
$table_fields = array_values(PMA_DBI_get_columns($db, $table));
-$rows = array();
-if (isset($where_clause)) {
- // when in edit mode load all selected rows from table
- $insert_mode = false;
- if (is_array($where_clause)) {
- $where_clause_array = $where_clause;
- } else {
- $where_clause_array = array(0 => $where_clause);
- }
- $result = array();
- $found_unique_key = false;
- $where_clauses = array();
+$paramTableDbArray = array($table, $db);
- foreach ($where_clause_array as $key_id => $where_clause) {
- $local_query = 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table)
- . ' WHERE ' . $where_clause . ';';
- $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
- $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
- $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause);
-
- // No row returned
- if (! $rows[$key_id]) {
- unset($rows[$key_id], $where_clause_array[$key_id]);
- echo PMA_getMessage(__('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)
- $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);
- if (! empty($unique_condition)) {
- $found_unique_key = true;
- }
- unset($unique_condition, $tmp_clause_is_unique);
- }
-
- }
-} else {
- // no primary key given, just load first row - but what happens if table is empty?
- $insert_mode = true;
- $result = PMA_DBI_query(
- 'SELECT * FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table) . ' LIMIT 1;',
- null,
- PMA_DBI_QUERY_STORE
- );
- $rows = array_fill(0, $cfg['InsertRows'], false);
+if (! isset($where_clause)) {
+ $where_clause = null;
}
+//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);
// 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') {
+if (isset($_REQUEST['default_action']) && $_REQUEST['default_action'] === 'insert') {
unset($where_clause, $where_clauses);
}
// retrieve keys into foreign fields, if any
-$foreigners = PMA_getForeigners($db, $table);
+$foreigners = PMA_getForeigners($db, $table);
+// Retrieve form parameters for insert/edit form
+$_form_params = PMA_getFormParametersForInsertForm(
+ $db, $table, $where_clauses, $where_clause_array, $err_url);
/**
* Displays the form
@@ -216,53 +176,21 @@ $foreigners = PMA_getForeigners($db, $table);
// autocomplete feature of IE kills the "onchange" event handler and it
// must be replaced by the "onpropertychange" one in this case
$chg_evt_handler = (PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 && PMA_USR_BROWSER_VER < 7)
- ? 'onpropertychange'
- : 'onchange';
+ ? 'onpropertychange'
+ : 'onchange';
// Had to put the URI because when hosted on an https server,
// some browsers send wrongly this form to the http server.
- ?>
-
-
-
- $db,
- 'table' => $table,
- 'goto' => $GLOBALS['goto'],
- 'err_url' => $err_url,
- 'sql_query' => $sql_query,
-);
-if (isset($where_clauses)) {
- foreach ($where_clause_array as $key_id => $where_clause) {
- $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause);
- }
-}
-if (isset($clause_is_unique)) {
- $_form_params['clause_is_unique'] = $clause_is_unique;
-}
-
-?>
-
-
-
';
} // end foreach on multi-edit
-?>
-
-
-
-
-
-
-
- '
+ . ''
+ . ' ';
if (! isset($after_insert)) {
$after_insert = 'back';
}
-?>
-
-
-
-
-
-
- >
- >
-
- >
-
- >
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 0) {
- echo ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
- } ?>
-
- 0) {
+ $html_output .= ' ' . PMA_generateHiddenMaxFileSize($biggest_max_file_size) . "\n";
+}
+$html_output .= '';
+// end Insert/Edit form
+
if ($insert_mode) {
-?>
-
-
-
-
-
-
- $where_clause) {
- echo ' '. "\n";
- }
- }
- $tmp = '' . "\n";
- $option_values = array(1,2,5,10,15,20,30,40);
- foreach ($option_values as $value) {
- $tmp .= '' . "\n";
- }
- $tmp .= ' ' . "\n";
- echo "\n" . sprintf(__('Continue insertion with %s rows'), $tmp);
- unset($tmp);
- echo ' ' . "\n";
+ //Continue insertion form
+ $html_output .= PMA_getContinueInsertionForm($table, $db, $where_clause_array, $err_url);
}
-
+echo $html_output;
/**
* Displays the footer
*/
require 'libraries/footer.inc.php';
+
?>
diff --git a/tbl_relation.php b/tbl_relation.php
index b990df4d14..06df554797 100644
--- a/tbl_relation.php
+++ b/tbl_relation.php
@@ -130,7 +130,7 @@ if ($cfgRelation['displaywork']) {
}
// will be used in the logic for internal relations and foreign keys:
-$me_fields_name = isset($_REQUEST['fields_name'])
+$multi_edit_columns_name = isset($_REQUEST['fields_name'])
? $_REQUEST['fields_name']
: null;
@@ -141,7 +141,7 @@ if (isset($destination) && $cfgRelation['relwork']) {
$upd_query = false;
// Map the fieldname's md5 back to its real name
- $master_field = $me_fields_name[$master_field_md5];
+ $master_field = $multi_edit_columns_name[$master_field_md5];
if (! empty($foreign_string)) {
$foreign_string = trim($foreign_string, '`');
@@ -189,7 +189,7 @@ if (isset($_REQUEST['destination_foreign'])) {
foreach ($_REQUEST['destination_foreign'] as $master_field_md5 => $foreign_string) {
// Map the fieldname's md5 back to it's real name
- $master_field = $me_fields_name[$master_field_md5];
+ $master_field = $multi_edit_columns_name[$master_field_md5];
if (! empty($foreign_string)) {
list($foreign_db, $foreign_table, $foreign_field) = PMA_backquote_split($foreign_string);
diff --git a/tbl_replace.php b/tbl_replace.php
index e24eeeddcc..87760ee1b9 100644
--- a/tbl_replace.php
+++ b/tbl_replace.php
@@ -16,6 +16,11 @@
*/
require_once 'libraries/common.inc.php';
+/**
+ * functions implementation for this script
+ */
+require_once 'libraries/insert_edit.lib.php';
+
// Check parameters
PMA_checkParameters(array('db', 'table', 'goto'));
@@ -30,96 +35,34 @@ $GLOBALS['js_include'][] = 'makegrid.js';
// Needed for generation of Inline Edit anchors
$GLOBALS['js_include'][] = 'sql.js';
-if (isset($_REQUEST['insert_rows'])
- && is_numeric($_REQUEST['insert_rows'])
- && $_REQUEST['insert_rows'] != $cfg['InsertRows']
-) {
- $cfg['InsertRows'] = $_REQUEST['insert_rows'];
- $GLOBALS['js_include'][] = 'tbl_change.js';
- include_once 'libraries/header.inc.php';
- include 'tbl_change.php';
- exit;
-}
+// check whether insert row moode, if so include tbl_change.php
+PMA_isInsertRow();
if (isset($_REQUEST['after_insert'])
&& in_array($_REQUEST['after_insert'], array('new_insert', 'same_insert', 'edit_next'))
) {
$url_params['after_insert'] = $_REQUEST['after_insert'];
- //$GLOBALS['goto'] = 'tbl_change.php';
- $goto_include = 'tbl_change.php';
-
if (isset($_REQUEST['where_clause'])) {
- if ($_REQUEST['after_insert'] == 'same_insert') {
- foreach ($_REQUEST['where_clause'] as $one_where_clause) {
+ foreach ($_REQUEST['where_clause'] as $one_where_clause) {
+ if ($_REQUEST['after_insert'] == 'same_insert') {
$url_params['where_clause'][] = $one_where_clause;
- }
- } elseif ($_REQUEST['after_insert'] == 'edit_next') {
- foreach ($_REQUEST['where_clause'] as $one_where_clause) {
- $local_query = 'SELECT * FROM ' . PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($GLOBALS['table'])
- . ' WHERE ' . str_replace('` =', '` >', $one_where_clause)
- . ' LIMIT 1;';
- $res = PMA_DBI_query($local_query);
- $row = PMA_DBI_fetch_row($res);
- $meta = PMA_DBI_get_fields_meta($res);
- // must find a unique condition based on unique key,
- // not a combination of all fields
- list($unique_condition, $clause_is_unique) = PMA_getUniqueCondition($res, count($meta), $meta, $row, true);
- if (! empty($unique_condition)) {
- $_SESSION['edit_next'] = $unique_condition;
- }
- unset($unique_condition, $clause_is_unique);
+ } elseif ($_REQUEST['after_insert'] == 'edit_next') {
+ PMA_setSessionForEditNext($one_where_clause);
}
}
}
-} elseif (! empty($GLOBALS['goto'])) {
- if (! preg_match('@^[a-z_]+\.php$@', $GLOBALS['goto'])) {
- // this should NOT happen
- //$GLOBALS['goto'] = false;
- $goto_include = false;
- } else {
- $goto_include = $GLOBALS['goto'];
- }
- if ($GLOBALS['goto'] == 'db_sql.php' && strlen($GLOBALS['table'])) {
- $GLOBALS['table'] = '';
- }
-}
-
-if (! $goto_include) {
- if (! strlen($GLOBALS['table'])) {
- $goto_include = 'db_sql.php';
- } else {
- $goto_include = 'tbl_sql.php';
- }
}
+//get $goto_include for different cases
+$goto_include = PMA_getGotoInclude($goto_include);
// Defines the url to return in case of failure of the query
-if (isset($_REQUEST['err_url'])) {
- $err_url = $_REQUEST['err_url'];
-} else {
- $err_url = 'tbl_change.php' . PMA_generate_common_url($url_params);
-}
+$err_url = PMA_getErrorUrl($url_params);
/**
* Prepares the update/insert of a row
*/
-if (isset($_REQUEST['where_clause'])) {
- // we were editing something => use the WHERE clause
- $loop_array = (is_array($_REQUEST['where_clause']) ? $_REQUEST['where_clause'] : array($_REQUEST['where_clause']));
- $using_key = true;
- $is_insert = $_REQUEST['submit_type'] == 'insert'
- || $_REQUEST['submit_type'] == 'showinsert'
- || $_REQUEST['submit_type'] == 'insertignore';
- $is_insertignore = $_REQUEST['submit_type'] == 'insertignore';
-} else {
- // new row => use indexes
- $loop_array = array();
- foreach ($_REQUEST['fields']['multi_edit'] as $key => $dummy) {
- $loop_array[] = $key;
- }
- $using_key = false;
- $is_insert = true;
- $is_insertignore = false;
-}
+list($loop_array, $using_key, $is_insert, $is_insertignore)
+ = PMA_getParamsForUpdateOrInsert();
$query = array();
$value_sets = array();
@@ -179,35 +122,35 @@ foreach ($loop_array as $rownumber => $where_clause) {
$query_values = array();
// Map multi-edit keys to single-level arrays, dependent on how we got the fields
- $me_fields
+ $multi_edit_colummns
= isset($_REQUEST['fields']['multi_edit'][$rownumber])
? $_REQUEST['fields']['multi_edit'][$rownumber]
: array();
- $me_fields_name
+ $multi_edit_columns_name
= isset($_REQUEST['fields_name']['multi_edit'][$rownumber])
? $_REQUEST['fields_name']['multi_edit'][$rownumber]
: null;
- $me_fields_prev
+ $multi_edit_columns_prev
= isset($_REQUEST['fields_prev']['multi_edit'][$rownumber])
? $_REQUEST['fields_prev']['multi_edit'][$rownumber]
: null;
- $me_funcs
+ $multi_edit_funcs
= isset($_REQUEST['funcs']['multi_edit'][$rownumber])
? $_REQUEST['funcs']['multi_edit'][$rownumber]
: null;
- $me_fields_type
+ $multi_edit_columns_type
= isset($_REQUEST['fields_type']['multi_edit'][$rownumber])
? $_REQUEST['fields_type']['multi_edit'][$rownumber]
: null;
- $me_fields_null
+ $multi_edit_columns_null
= isset($_REQUEST['fields_null']['multi_edit'][$rownumber])
? $_REQUEST['fields_null']['multi_edit'][$rownumber]
: null;
- $me_fields_null_prev
+ $multi_edit_columns_null_prev
= isset($_REQUEST['fields_null_prev']['multi_edit'][$rownumber])
? $_REQUEST['fields_null_prev']['multi_edit'][$rownumber]
: null;
- $me_auto_increment
+ $multi_edit_auto_increment
= isset($_REQUEST['auto_increment']['multi_edit'][$rownumber])
? $_REQUEST['auto_increment']['multi_edit'][$rownumber]
: null;
@@ -215,49 +158,49 @@ foreach ($loop_array as $rownumber => $where_clause) {
// Fetch the current values of a row to use in case we have a protected field
// @todo possibly move to ./libraries/tbl_replace_fields.inc.php
if ($is_insert
- && $using_key && isset($me_fields_type)
- && is_array($me_fields_type) && isset($where_clause)
+ && $using_key && isset($multi_edit_columns_type)
+ && is_array($multi_edit_columns_type) && isset($where_clause)
) {
$prot_row = PMA_DBI_fetch_single_row('SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $where_clause . ';');
}
// When a select field is nullified, it's not present in $_REQUEST
- // so initialize it; this way, the foreach($me_fields) will process it
- foreach ($me_fields_name as $key => $val) {
- if (! isset($me_fields[$key])) {
- $me_fields[$key] = '';
+ // so initialize it; this way, the foreach($multi_edit_colummns) will process it
+ foreach ($multi_edit_columns_name as $key => $val) {
+ if (! isset($multi_edit_colummns[$key])) {
+ $multi_edit_colummns[$key] = '';
}
}
- // Iterate in the order of $me_fields_name, not $me_fields, to avoid problems
+ // Iterate in the order of $multi_edit_columns_name, not $multi_edit_colummns, to avoid problems
// when inserting multiple entries
- foreach ($me_fields_name as $key => $field_name) {
- $val = $me_fields[$key];
+ 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 $me_fields_name[$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';
- if (empty($me_funcs[$key])) {
+ if (empty($multi_edit_funcs[$key])) {
$cur_value = $val;
- } elseif ('UUID' === $me_funcs[$key]) {
+ } 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($me_funcs[$key], $gis_from_text_functions)
+ } elseif ((in_array($multi_edit_funcs[$key], $gis_from_text_functions)
&& substr($val, 0, 3) == "'''")
- || in_array($me_funcs[$key], $gis_from_wkb_functions)
+ || 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 = $me_funcs[$key] . '(' . $val . ')';
- } elseif (! in_array($me_funcs[$key], $func_no_param)
- || ($val != "''" && in_array($me_funcs[$key], $func_optional_param))) {
- $cur_value = $me_funcs[$key] . '(' . $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 = $me_funcs[$key] . '()';
+ $cur_value = $multi_edit_funcs[$key] . '()';
}
// i n s e r t
@@ -267,32 +210,32 @@ foreach ($loop_array as $rownumber => $where_clause) {
$query_values[] = $cur_value;
// first inserted row so prepare the list of fields
if (empty($value_sets)) {
- $query_fields[] = PMA_backquote($me_fields_name[$key]);
+ $query_fields[] = PMA_backquote($multi_edit_columns_name[$key]);
}
}
// u p d a t e
- } elseif (!empty($me_fields_null_prev[$key])
- && ! isset($me_fields_null[$key])) {
+ } 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($me_fields_name[$key]) . ' = ' . $cur_value;
- } elseif (empty($me_funcs[$key])
- && isset($me_fields_prev[$key])
- && ("'" . PMA_sqlAddSlashes($me_fields_prev[$key]) . "'" == $val)) {
+ $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($me_fields_null_prev[$key])
- || empty($me_fields_null[$key])
+ if (empty($multi_edit_columns_null_prev[$key])
+ || empty($multi_edit_columns_null[$key])
) {
- $query_values[] = PMA_backquote($me_fields_name[$key]) . ' = ' . $cur_value;
+ $query_values[] = PMA_backquote($multi_edit_columns_name[$key]) . ' = ' . $cur_value;
}
}
- } // end foreach ($me_fields as $key => $val)
+ } // end foreach ($multi_edit_colummns as $key => $val)
if (count($query_values) > 0) {
if ($is_insert) {
@@ -306,23 +249,15 @@ foreach ($loop_array as $rownumber => $where_clause) {
}
}
} // end foreach ($loop_array as $where_clause)
-unset($me_fields_name, $me_fields_prev, $me_funcs, $me_fields_type, $me_fields_null, $me_fields_null_prev,
- $me_auto_increment, $cur_value, $key, $val, $loop_array, $where_clause, $using_key,
- $func_no_param);
+unset($multi_edit_columns_name, $multi_edit_columns_prev, $multi_edit_funcs,
+ $multi_edit_columns_type, $multi_edit_columns_null, $func_no_param,
+ $multi_edit_auto_increment, $cur_value, $key, $val, $loop_array, $where_clause,
+ $using_key, $multi_edit_columns_null_prev);
// Builds the sql query
if ($is_insert && count($value_sets) > 0) {
- if ($is_insertignore) {
- $insert_command = 'INSERT IGNORE ';
- } else {
- $insert_command = 'INSERT ';
- }
- $query[] = $insert_command . 'INTO ' . PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($GLOBALS['table'])
- . ' (' . implode(', ', $query_fields) . ') VALUES (' . implode('), (', $value_sets) . ')';
- unset($insert_command);
-
- unset($query_fields);
+ $query = PMA_buildSqlQuery($is_insertignore, $query_fields, $value_sets);
} elseif (empty($query)) {
// No change -> move back to the calling script
//
@@ -335,71 +270,14 @@ if ($is_insert && count($value_sets) > 0) {
include '' . PMA_securePath($goto_include);
exit;
}
-unset($me_fields, $is_insertignore);
+unset($multi_edit_colummns, $is_insertignore);
/**
* Executes the sql query and get the result, then move back to the calling
* page
*/
-if (! empty($GLOBALS['sql_query'])) {
- $url_params['sql_query'] = $GLOBALS['sql_query'];
- $return_to_sql_query = $GLOBALS['sql_query'];
-}
-$GLOBALS['sql_query'] = implode('; ', $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'));
- continue;
- }
- if ($GLOBALS['cfg']['IgnoreMultiSubmitErrors']) {
- $result = PMA_DBI_try_query($single_query);
- } else {
- $result = PMA_DBI_query($single_query);
- }
-
- if (! $result) {
- $error_messages[] = PMA_Message::sanitize(PMA_DBI_getError());
- } else {
- // The next line contains a real assignment, it's not a typo
- if ($tmp = @PMA_DBI_affected_rows()) {
- $total_affected_rows += $tmp;
- }
- unset($tmp);
-
- $insert_id = PMA_DBI_insert_id();
- if ($insert_id != 0) {
- // insert_id is id of FIRST record inserted in one insert, so if we
- // inserted multiple rows, we had to increment this
-
- if ($total_affected_rows > 0) {
- $insert_id = $insert_id + $total_affected_rows - 1;
- }
- $last_message = PMA_Message::notice(__('Inserted row id: %1$d'));
- $last_message->addParam($insert_id);
- $last_messages[] = $last_message;
- }
- PMA_DBI_free_result($result);
- } // end if
-
- foreach (PMA_DBI_get_warnings() as $warning) {
- $warning_messages[]
- = PMA_Message::sanitize(
- $warning['Level'] . ': #' . $warning['Code'] . ' ' . $warning['Message']
- );
- }
-
- unset($result);
-}
-unset($single_query, $query);
+list ($url_params, $total_affected_rows, $last_messages, $warning_messages,
+ $error_messages) = PMA_executeSqlQuery($url_params, $query);
if ($is_insert && count($value_sets) > 0) {
$message = PMA_Message::inserted_rows($total_affected_rows);