Merge branch 'thilina'

This commit is contained in:
Marc Delisle 2012-05-23 12:43:40 -04:00
commit 91d41355c5
5 changed files with 1948 additions and 1093 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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 = "''";
}

File diff suppressed because it is too large Load Diff

View File

@ -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);

View File

@ -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);