mirror of
https://github.com/vrana/adminer.git
synced 2025-08-10 08:34:20 +02:00
Simplify process_fields()
This commit is contained in:
@@ -17,8 +17,11 @@ if ($TABLE != "") {
|
||||
|
||||
$row = $_POST;
|
||||
$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"]) {
|
||||
query_redirect("DROP TABLE " . table($TABLE), substr(ME, 0, -1), lang('Table has been dropped.'));
|
||||
} 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);
|
||||
|
||||
if ($_POST) {
|
||||
if ($row["auto_increment_col"]) {
|
||||
$row["fields"][$row["auto_increment_col"]]["auto_increment"] = true;
|
||||
}
|
||||
process_fields($row["fields"]);
|
||||
if (!$_POST) {
|
||||
$row = array(
|
||||
"Engine" => $_COOKIE["adminer_engine"],
|
||||
"fields" => array(array("field" => "", "type" => (isset($types["int"]) ? "int" : (isset($types["integer"]) ? "integer" : "")))),
|
||||
"partition_names" => array(""),
|
||||
);
|
||||
|
||||
} elseif ($TABLE != "") {
|
||||
if ($TABLE != "") {
|
||||
$row = $orig_status;
|
||||
$row["name"] = $TABLE;
|
||||
$row["fields"] = array();
|
||||
@@ -134,13 +138,7 @@ if ($_POST) {
|
||||
}
|
||||
$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();
|
||||
|
@@ -260,7 +260,7 @@ function edit_fields($fields, $collations, $type = "TABLE", $foreign_keys = arra
|
||||
|
||||
/** Move fields up and down or add field
|
||||
* @param array
|
||||
* @return null
|
||||
* @return bool
|
||||
*/
|
||||
function process_fields(&$fields) {
|
||||
ksort($fields);
|
||||
@@ -278,8 +278,7 @@ function process_fields(&$fields) {
|
||||
}
|
||||
$offset++;
|
||||
}
|
||||
}
|
||||
if ($_POST["down"]) {
|
||||
} elseif ($_POST["down"]) {
|
||||
$found = false;
|
||||
foreach ($fields as $key => $field) {
|
||||
if (isset($field["field"]) && $found) {
|
||||
@@ -292,11 +291,13 @@ function process_fields(&$fields) {
|
||||
}
|
||||
$offset++;
|
||||
}
|
||||
}
|
||||
} elseif ($_POST["add"]) {
|
||||
$fields = array_values($fields);
|
||||
if ($_POST["add"]) {
|
||||
array_splice($fields, key($_POST["add"]), 0, array(array()));
|
||||
} elseif (!$_POST["drop_col"]) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Callback used in routine()
|
||||
|
@@ -4,8 +4,7 @@ $routine = (isset($_GET["function"]) ? "FUNCTION" : "PROCEDURE");
|
||||
$row = $_POST;
|
||||
$row["fields"] = (array) $row["fields"];
|
||||
|
||||
if ($_POST) {
|
||||
if (!$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] && !$_POST["down"]) {
|
||||
if ($_POST && !process_fields($row["fields"]) && !$error) {
|
||||
$temp_name = "$row[name]_adminer_" . uniqid();
|
||||
drop_create(
|
||||
"DROP $routine " . idf_escape($PROCEDURE),
|
||||
@@ -19,8 +18,6 @@ if ($_POST) {
|
||||
$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);
|
||||
|
||||
|
Reference in New Issue
Block a user