Simplify process_fields()
This commit is contained in:
parent
046da00eb6
commit
c38655418b
|
@ -17,8 +17,11 @@ if ($TABLE != "") {
|
||||||
|
|
||||||
$row = $_POST;
|
$row = $_POST;
|
||||||
$row["fields"] = (array) $row["fields"];
|
$row["fields"] = (array) $row["fields"];
|
||||||
|
if ($row["auto_increment_col"]) {
|
||||||
|
$row["fields"][$row["auto_increment_col"]]["auto_increment"] = true;
|
||||||
|
}
|
||||||
|
|
||||||
if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] && !$_POST["down"]) {
|
if ($_POST && !process_fields($row["fields"]) && !$error) {
|
||||||
if ($_POST["drop"]) {
|
if ($_POST["drop"]) {
|
||||||
query_redirect("DROP TABLE " . table($TABLE), substr(ME, 0, -1), lang('Table has been dropped.'));
|
query_redirect("DROP TABLE " . table($TABLE), substr(ME, 0, -1), lang('Table has been dropped.'));
|
||||||
} else {
|
} else {
|
||||||
|
@ -104,13 +107,14 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"]
|
||||||
|
|
||||||
page_header(($TABLE != "" ? lang('Alter table') : lang('Create table')), $error, array("table" => $TABLE), $TABLE);
|
page_header(($TABLE != "" ? lang('Alter table') : lang('Create table')), $error, array("table" => $TABLE), $TABLE);
|
||||||
|
|
||||||
if ($_POST) {
|
if (!$_POST) {
|
||||||
if ($row["auto_increment_col"]) {
|
$row = array(
|
||||||
$row["fields"][$row["auto_increment_col"]]["auto_increment"] = true;
|
"Engine" => $_COOKIE["adminer_engine"],
|
||||||
}
|
"fields" => array(array("field" => "", "type" => (isset($types["int"]) ? "int" : (isset($types["integer"]) ? "integer" : "")))),
|
||||||
process_fields($row["fields"]);
|
"partition_names" => array(""),
|
||||||
|
);
|
||||||
|
|
||||||
} elseif ($TABLE != "") {
|
if ($TABLE != "") {
|
||||||
$row = $orig_status;
|
$row = $orig_status;
|
||||||
$row["name"] = $TABLE;
|
$row["name"] = $TABLE;
|
||||||
$row["fields"] = array();
|
$row["fields"] = array();
|
||||||
|
@ -134,13 +138,7 @@ if ($_POST) {
|
||||||
}
|
}
|
||||||
$row["partition_names"][] = "";
|
$row["partition_names"][] = "";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
|
||||||
$row = array(
|
|
||||||
"Engine" => $_COOKIE["adminer_engine"],
|
|
||||||
"fields" => array(array("field" => "", "type" => (isset($types["int"]) ? "int" : (isset($types["integer"]) ? "integer" : "")))),
|
|
||||||
"partition_names" => array(""),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$collations = collations();
|
$collations = collations();
|
||||||
|
|
|
@ -260,7 +260,7 @@ function edit_fields($fields, $collations, $type = "TABLE", $foreign_keys = arra
|
||||||
|
|
||||||
/** Move fields up and down or add field
|
/** Move fields up and down or add field
|
||||||
* @param array
|
* @param array
|
||||||
* @return null
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function process_fields(&$fields) {
|
function process_fields(&$fields) {
|
||||||
ksort($fields);
|
ksort($fields);
|
||||||
|
@ -278,8 +278,7 @@ function process_fields(&$fields) {
|
||||||
}
|
}
|
||||||
$offset++;
|
$offset++;
|
||||||
}
|
}
|
||||||
}
|
} elseif ($_POST["down"]) {
|
||||||
if ($_POST["down"]) {
|
|
||||||
$found = false;
|
$found = false;
|
||||||
foreach ($fields as $key => $field) {
|
foreach ($fields as $key => $field) {
|
||||||
if (isset($field["field"]) && $found) {
|
if (isset($field["field"]) && $found) {
|
||||||
|
@ -292,11 +291,13 @@ function process_fields(&$fields) {
|
||||||
}
|
}
|
||||||
$offset++;
|
$offset++;
|
||||||
}
|
}
|
||||||
}
|
} elseif ($_POST["add"]) {
|
||||||
$fields = array_values($fields);
|
$fields = array_values($fields);
|
||||||
if ($_POST["add"]) {
|
|
||||||
array_splice($fields, key($_POST["add"]), 0, array(array()));
|
array_splice($fields, key($_POST["add"]), 0, array(array()));
|
||||||
|
} elseif (!$_POST["drop_col"]) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Callback used in routine()
|
/** Callback used in routine()
|
||||||
|
|
|
@ -4,8 +4,7 @@ $routine = (isset($_GET["function"]) ? "FUNCTION" : "PROCEDURE");
|
||||||
$row = $_POST;
|
$row = $_POST;
|
||||||
$row["fields"] = (array) $row["fields"];
|
$row["fields"] = (array) $row["fields"];
|
||||||
|
|
||||||
if ($_POST) {
|
if ($_POST && !process_fields($row["fields"]) && !$error) {
|
||||||
if (!$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] && !$_POST["down"]) {
|
|
||||||
$temp_name = "$row[name]_adminer_" . uniqid();
|
$temp_name = "$row[name]_adminer_" . uniqid();
|
||||||
drop_create(
|
drop_create(
|
||||||
"DROP $routine " . idf_escape($PROCEDURE),
|
"DROP $routine " . idf_escape($PROCEDURE),
|
||||||
|
@ -18,8 +17,6 @@ if ($_POST) {
|
||||||
lang('Routine has been created.'),
|
lang('Routine has been created.'),
|
||||||
$PROCEDURE
|
$PROCEDURE
|
||||||
);
|
);
|
||||||
}
|
|
||||||
process_fields($row["fields"]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
page_header(($PROCEDURE != "" ? (isset($_GET["function"]) ? lang('Alter function') : lang('Alter procedure')) . ": " . h($PROCEDURE) : (isset($_GET["function"]) ? lang('Create function') : lang('Create procedure'))), $error);
|
page_header(($PROCEDURE != "" ? (isset($_GET["function"]) ? lang('Alter function') : lang('Alter procedure')) . ": " . h($PROCEDURE) : (isset($_GET["function"]) ? lang('Create function') : lang('Create procedure'))), $error);
|
||||||
|
|
Loading…
Reference in a new issue