diff --git a/create.inc.php b/create.inc.php index e09b371f..4d236fa1 100644 --- a/create.inc.php +++ b/create.inc.php @@ -25,10 +25,7 @@ if ($_POST && !$error && !$_POST["add"]) { //! detect changes 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"] ? "(" . (preg_match("~^\\s*(?:$enum_length)(?:\\s*,\\s*(?:$enum_length))*\\s*\$~", $field["length"]) && preg_match_all("~$enum_length~", $field["length"], $matches) ? implode(",", $matches[0]) : intval($field["length"])) . ")" : "") - . (preg_match('~int|float|double|decimal~', $field["type"]) && in_array($field["unsigned"], $unsigned) ? " $field[unsigned]" : "") - . (preg_match('~char|text|enum|set~', $field["type"]) && $field["collation"] ? " COLLATE '" . $mysql->escape_string($field["collation"]) . "'" : "") + . idf_escape($field["field"]) . process_type($field) . ($field["null"] ? "" : " NOT NULL") . ($key == $_POST["auto_increment"] ? " AUTO_INCREMENT$auto_increment_index" : "") . " COMMENT '" . $mysql->escape_string($field["comment"]) . "'" @@ -58,6 +55,15 @@ if ($_POST && !$error && !$_POST["add"]) { } page_header(strlen($_GET["create"]) ? lang('Alter table') . ': ' . htmlspecialchars($_GET["create"]) : lang('Create table')); +$engines = array(); +$result = $mysql->query("SHOW ENGINES"); +while ($row = $result->fetch_assoc()) { + if ($row["Support"] == "YES" || $row["Support"] == "DEFAULT") { + $engines[] = $row["Engine"]; + } +} +$result->free(); + if ($_POST) { $row = $_POST; ksort($row["fields"]); @@ -86,7 +92,7 @@ $collations = collations();

: " /> - +

diff --git a/createv.inc.php b/createv.inc.php index 9ba75e31..415253ed 100644 --- a/createv.inc.php +++ b/createv.inc.php @@ -16,6 +16,7 @@ if ($_POST) { echo "

" . lang('Unable to operate view') . ": " . htmlspecialchars($error) . "

\n"; } elseif (strlen($_GET["createv"])) { $row = view($_GET["createv"]); + $row["name"] = $_GET["createv"]; } else { $row = array(); } diff --git a/editing.inc.php b/editing.inc.php new file mode 100644 index 00000000..fe8b51c6 --- /dev/null +++ b/editing.inc.php @@ -0,0 +1,163 @@ +'; + } + preg_match_all("~'((?:[^']+|'')*)'~", $field["length"], $matches); + foreach ($matches[1] as $i => $val) { + $val = stripcslashes(str_replace("''", "'", $val)); + $id = "field-$name-" . ($i+1); + $checked = (is_int($value) ? $value == $i+1 : $value === $val); //! '' collide with NULL in $_GET["default"] + echo ' '; + } + if ($field["null"]) { + $id = "field-$name-"; + echo ' '; + } + } elseif ($field["type"] == "set") { //! 64 bits + preg_match_all("~'((?:[^']+|'')*)'~", $field["length"], $matches); + foreach ($matches[1] as $i => $val) { + $val = stripcslashes(str_replace("''", "'", $val)); + $id = "field-$name-" . ($i+1); + $checked = (is_int($value) ? ($value >> $i) & 1 : in_array($val, explode(",", $value), true)); + echo ' '; + } + } elseif (strpos($field["type"], "text") !== false) { + echo ''; + } elseif (preg_match('~binary|blob~', $field["type"])) { + echo (ini_get("file_uploads") ? '' : lang('File uploads are disabled.') . ' '); + } else { + echo ''; + } + if ($field["null"] && preg_match('~char|text|set|binary|blob~', $field["type"])) { + $id = "null-$name"; + echo ''; + } +} + +function process_input($name, $field) { + global $mysql; + $name = bracket_escape($name); + $value = $_POST["fields"][$name]; + if (preg_match('~char|text|set|binary|blob~', $field["type"]) ? $_POST["null"][$name] : !strlen($value)) { + return "NULL"; + } elseif ($field["type"] == "enum") { + return (isset($_GET["default"]) ? "'" . $mysql->escape_string($value) . "'" : intval($value)); + } elseif ($field["type"] == "set") { + return (isset($_GET["default"]) ? "'" . implode(",", array_map(array($mysql, 'escape_string'), (array) $value)) . "'" : array_sum((array) $value)); + } elseif (preg_match('~binary|blob~', $field["type"])) { + $file = get_file($name); + if (!is_string($file) && !$field["null"]) { + return false; //! report errors, also empty $_POST (too big POST data, not only FILES) + } + return "_binary'" . (is_string($file) ? $mysql->escape_string($file) : "") . "'"; + } else { + return "'" . $mysql->escape_string($value) . "'"; + } +} + +function edit_type($key, $field, $collations) { + global $types, $unsigned, $inout; +?> + +" size="3" /> + +escape_string($field["collation"]) . "'" : "") + ; +} + +function edit_fields($fields, $collations, $type = "TABLE") { + global $inout; +?> + + + + + + + + + + + + + + + $field) { + $i++; + ?> + + + + + + + + + + + + +
" />" maxlength="64" /> checked="checked" /> checked="checked" />" maxlength="255" />
+ +result($mysql->query("SHOW CREATE $type " . idf_escape($name)), 2); + preg_match("~\\(($pattern(?:\\s*,$pattern)*)\\)" . ($type == "FUNCTION" ? "\\s*RETURNS\\s+$type_pattern" : "") . "\\s*(.*)~is", $create, $match); + $fields = array(); + preg_match_all("~$pattern~is", $match[1], $matches, PREG_SET_ORDER); + foreach ($matches as $i => $param) { + $fields[$i] = array( + "field" => str_replace("``", "`", $param[2]) . $param[3], + "type" => $param[4], //! type aliases + "length" => preg_replace_callback("~$enum_length~s", 'normalize_enum', $param[5]), + "unsigned" => strtolower(preg_replace('~\\s+~', ' ', trim("$param[7] $param[6]"))), + "null" => true, + "inout" => strtoupper($param[1]), + //! detect character set + ); + } + if ($type != "FUNCTION") { + return array("fields" => $fields, "definition" => $match[16]); + } + $returns = array( + "type" => $match[16], + "length" => preg_replace_callback("~$enum_length~s", 'normalize_enum', $match[17]), + "unsigned" => strtolower(preg_replace('~\\s+~', ' ', trim("$match[19] $match[18]"))), + ); + return array("fields" => $fields, "returns" => $returns, "definition" => $match[20]); +} diff --git a/functions.inc.php b/functions.inc.php index 64fc9c5d..47d6b8b7 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -113,35 +113,13 @@ function foreign_keys($table) { function view($name) { global $mysql; - return array("name" => $name, "select" => preg_replace('~^(?:[^`]+|`[^`]*`)* AS ~U', '', $mysql->result($mysql->query("SHOW CREATE VIEW " . idf_escape($name)), 1))); + return array("select" => preg_replace('~^(?:[^`]+|`[^`]*`)* AS ~U', '', $mysql->result($mysql->query("SHOW CREATE VIEW " . idf_escape($name)), 1))); } function normalize_enum($match) { return "'" . str_replace("'", "''", addcslashes(stripcslashes(str_replace($match[0]{0} . $match[0]{0}, $match[0]{0}, substr($match[0], 1, -1))), '\\')) . "'"; } -function routine($name, $type) { - global $mysql, $enum_length, $inout; - $pattern = "\\s*(" . implode("|", $inout) . ")?\\s*(?:`((?:[^`]+|``)*)`\\s*|\\b(\\S+)\\s+)([a-z]+)(?:\\s*\\(((?:[^'\")]*|$enum_length)+)\\))?\\s*(zerofill\\s+)?(unsigned(?:\\s+zerofill)?)?"; - $create = $mysql->result($mysql->query("SHOW CREATE $type " . idf_escape($name)), 2); - preg_match("~\\($pattern(?:\\s*,$pattern)*~is", $create, $match); - $params = array(); - preg_match_all("~$pattern~is", $match[0], $matches, PREG_SET_ORDER); - foreach ($matches as $i => $match) { - $field = array( - "field" => str_replace("``", "`", $match[2]) . $match[3], - "type" => $match[4], //! type aliases - "length" => preg_replace_callback("~$enum_length~s", 'normalize_enum', $match[5]), - "unsigned" => strtolower(preg_replace('~\\s+~', ' ', trim("$match[7] $match[6]"))), - "null" => true, - "inout" => strtoupper($match[1]), - //! detect character set - ); - $params[$i] = $field; - } - return array("fields" => $params); -} - function unique_idf($row, $indexes) { foreach ($indexes as $index) { if ($index["type"] == "PRIMARY" || $index["type"] == "UNIQUE") { @@ -185,19 +163,6 @@ function collations() { return $return; } -function engines() { - global $mysql; - $return = array(); - $result = $mysql->query("SHOW ENGINES"); - while ($row = $result->fetch_assoc()) { - if ($row["Support"] == "YES" || $row["Support"] == "DEFAULT") { - $return[] = $row["Engine"]; - } - } - $result->free(); - return $return; -} - function token() { return ($GLOBALS["TOKENS"][] = rand(1, 1e6)); } @@ -301,123 +266,6 @@ function select($result) { $result->free(); } -function input($name, $field, $value) { - global $types; - $name = htmlspecialchars(bracket_escape($name)); - if ($field["type"] == "enum") { - if (!isset($_GET["default"])) { - echo ''; - } - preg_match_all("~'((?:[^']+|'')*)'~", $field["length"], $matches); - foreach ($matches[1] as $i => $val) { - $val = stripcslashes(str_replace("''", "'", $val)); - $id = "field-$name-" . ($i+1); - $checked = (is_int($value) ? $value == $i+1 : $value === $val); //! '' collide with NULL in $_GET["default"] - echo ' '; - } - if ($field["null"]) { - $id = "field-$name-"; - echo ' '; - } - } elseif ($field["type"] == "set") { //! 64 bits - preg_match_all("~'((?:[^']+|'')*)'~", $field["length"], $matches); - foreach ($matches[1] as $i => $val) { - $val = stripcslashes(str_replace("''", "'", $val)); - $id = "field-$name-" . ($i+1); - $checked = (is_int($value) ? ($value >> $i) & 1 : in_array($val, explode(",", $value), true)); - echo ' '; - } - } elseif (strpos($field["type"], "text") !== false) { - echo ''; - } elseif (preg_match('~binary|blob~', $field["type"])) { - echo (ini_get("file_uploads") ? '' : lang('File uploads are disabled.') . ' '); - } else { - echo ''; - } - if ($field["null"] && preg_match('~char|text|set|binary|blob~', $field["type"])) { - $id = "null-$name"; - echo ''; - } -} - -function process_input($name, $field) { - global $mysql; - $name = bracket_escape($name); - $value = $_POST["fields"][$name]; - if (preg_match('~char|text|set|binary|blob~', $field["type"]) ? $_POST["null"][$name] : !strlen($value)) { - return "NULL"; - } elseif ($field["type"] == "enum") { - return (isset($_GET["default"]) ? "'" . $mysql->escape_string($value) . "'" : intval($value)); - } elseif ($field["type"] == "set") { - return (isset($_GET["default"]) ? "'" . implode(",", array_map(array($mysql, 'escape_string'), (array) $value)) . "'" : array_sum((array) $value)); - } elseif (preg_match('~binary|blob~', $field["type"])) { - $file = get_file($name); - if (!is_string($file) && !$field["null"]) { - return false; //! report errors, also empty $_POST (too big POST data, not only FILES) - } - return "_binary'" . (is_string($file) ? $mysql->escape_string($file) : "") . "'"; - } else { - return "'" . $mysql->escape_string($value) . "'"; - } -} - -function edit_fields($fields, $collations, $type = "TABLE") { - global $types, $unsigned, $inout; -?> - - - - - - - - - - - - - - - $field) { - $i++; - ?> - - - - - - - - - - - - - - -
" />" maxlength="64" />" size="3" /> checked="checked" /> checked="checked" />" maxlength="255" />
- -"; echo "" . htmlspecialchars($row["ROUTINE_TYPE"]) . ""; echo '' . htmlspecialchars($row["ROUTINE_NAME"]) . ''; - echo '' . lang('Alter') . "\n"; + echo '' . lang('Alter') . "\n"; echo "\n"; } echo "\n"; } $result->free(); - echo '

' . lang('Create procedure') . ' ' . lang('Create function') . "

\n"; - echo '

' . lang('Create view') . "

\n"; + echo '

' . lang('Create procedure') . ' ' . lang('Create function') . "

\n"; + echo '

' . lang('Create view') . "

\n"; } } }