$field) { if (strlen($field["field"]) && isset($types[$field["type"]])) { $fields[] = (!strlen($_GET["create"]) ? "" : (strlen($field["orig"]) ? "CHANGE " . idf_escape($field["orig"]) . " " : "ADD ")) . idf_escape($field["field"]) . " $field[type]" . ($field["length"] ? "($field[length])" : "") . (preg_match('~int|float|double|decimal~', $field["type"]) && in_array($field["unsigned"], $unsigned) ? " $field[unsigned]" : "") . (preg_match('~char|text~', $field["type"]) && $field["collation"] ? " COLLATE '" . mysql_real_escape_string($field["collation"]) . "'" : "") . ($field["null"] ? "" : " NOT NULL") . ($key == $_POST["auto_increment"] ? " AUTO_INCREMENT PRIMARY KEY" : "") //! drop old primary key, can be part of any index ; } elseif (strlen($field["orig"])) { $fields[] = "DROP " . idf_escape($field["orig"]); } } $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"]) . " " . implode(", ", $fields) . ", 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.'); } } if (mysql_query($query)) { redirect(($_POST["drop"] ? substr($SELF, 0, -1) : $SELF . "table=" . urlencode($_POST["name"])), $message); } $error = mysql_error(); } page_header(strlen($_GET["create"]) ? lang('Alter table') . ': ' . htmlspecialchars($_GET["create"]) : lang('Create table')); if ($_POST) { if (!$_POST["add"]) { echo "
" . lang('Unable to operate table') . ": " . htmlspecialchars($error) . "
\n"; } $row = $_POST; } elseif (strlen($_GET["create"])) { $row = mysql_fetch_assoc(mysql_query("SHOW TABLE STATUS LIKE '" . mysql_real_escape_string($_GET["create"]) . "'")); $row["name"] = $_GET["create"]; $row["fields"] = fields($_GET["create"]); } else { $row = array("fields" => array()); } //! default, comments $collations = collations(); ?>