diff --git a/create.inc.php b/create.inc.php index 86b7c773..e11204b8 100644 --- a/create.inc.php +++ b/create.inc.php @@ -1,54 +1,53 @@ $field) { - if (strlen($field["name"]) && in_array($field["type"], $types)) { - $length = ($field["length"] ? "(" . intval($field["length"]) . ")" : ""); //! decimal, enum and set lengths - $fields[] = idf_escape($field["name"]) . " " . $field["type"] . $length . ($field["not_null"] ? " NOT NULL" : "") . ($field["auto_increment"] ? " AUTO_INCREMENT" : ""); +if ($_POST) { + if ($_POST["drop"]) { + $query = "DROP TABLE " . idf_escape($_GET["create"]); + $message = lang('Table has been dropped.'); + } else { + $fields = array(); + ksort($_POST["fields"]); + foreach ($_POST["fields"] as $key => $field) { + if (strlen($field["name"]) && in_array($field["type"], $types)) { + $length = ($field["length"] ? "(" . intval($field["length"]) . ")" : ""); //! decimal, enum and set lengths + $fields[] = idf_escape($field["name"]) . " " . $field["type"] . $length . ($field["not_null"] ? " NOT NULL" : "") . ($field["auto_increment"] ? " AUTO_INCREMENT" : ""); + } + } + $status = ($_POST["Engine"] ? " ENGINE='" . mysql_real_escape_string($_POST["Engine"]) . "'" : "") . ($_POST["Collation"] ? " COLLATE '" . mysql_real_escape_string($_POST["Collation"]) . "'" : ""); + if (strlen($_GET["create"])) { + $query = "ALTER TABLE " . idf_escape($_GET["create"]) . " RENAME TO " . idf_escape($_POST["name"]) . ", $status"; + $message = lang('Table has been altered.'); + } else { + $query = "CREATE TABLE " . idf_escape($_POST["name"]) . " (" . implode(", ", $fields) . ")$status"; + $message = lang('Table has been created.'); } } - $status = ($_POST["engine"] ? " ENGINE='" . mysql_real_escape_string($_POST["engine"]) . "'" : "") . ($_POST["collate"] ? " COLLATE '" . mysql_real_escape_string($_POST["collate"]) . "'" : ""); - if (strlen($_GET["create"])) { - if (mysql_query("ALTER TABLE " . idf_escape($_GET["create"]) . " RENAME TO " . idf_escape($_POST["name"]) . ", $status")) { - $_SESSION["message"] = lang('Table has been altered.'); - header("Location: $SELF" . "table=" . urlencode($_POST["name"]) . (SID ? "&" . SID : "")); - exit; - } - } elseif ($fields && mysql_query("CREATE TABLE " . idf_escape($_POST["name"]) . " (" . implode(", ", $fields) . ")$status")) { - $_SESSION["message"] = lang('Table has been created.'); - header("Location: $SELF" . "table=" . urlencode($_POST["name"]) . (SID ? "&" . SID : "")); + if (mysql_query($query)) { + $_SESSION["message"] = $message; + header("Location: " . ($_POST["drop"] ? substr($SELF, 0, -1) : $SELF . "table=" . urlencode($_POST["name"])) . (SID ? "&" . SID : "")); exit; } + $error = mysql_error(); } page_header(strlen($_GET["create"]) ? lang('Alter table') . ': ' . htmlspecialchars($_GET["create"]) : lang('Create table')); echo "
" . lang('Unable to operate table') . ": " . htmlspecialchars(mysql_error()) . "
\n"; - $collate = $_POST["collate"]; - $engine = $_POST["engine"]; + echo "" . lang('Unable to operate table') . ": " . htmlspecialchars($error) . "
\n"; + $row = $_POST; //! prefill fields } elseif (strlen($_GET["create"])) { $row = mysql_fetch_assoc(mysql_query("SHOW TABLE STATUS LIKE '" . mysql_real_escape_string($_GET["create"]) . "'")); - $collate = $row["Collation"]; - $engine = $row["Engine"]; + $row["name"] = $_GET["create"]; //! prefill fields } //! collate columns, references, indexes, unsigned ?>