mirror of
https://github.com/vrana/adminer.git
synced 2025-08-14 10:34:01 +02:00
Separate editing functions
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@197 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
@@ -25,10 +25,7 @@ if ($_POST && !$error && !$_POST["add"]) {
|
|||||||
//! detect changes
|
//! detect changes
|
||||||
if (strlen($field["field"]) && isset($types[$field["type"]])) {
|
if (strlen($field["field"]) && isset($types[$field["type"]])) {
|
||||||
$fields[] = (!strlen($_GET["create"]) ? "" : (strlen($field["orig"]) ? "CHANGE " . idf_escape($field["orig"]) . " " : "ADD "))
|
$fields[] = (!strlen($_GET["create"]) ? "" : (strlen($field["orig"]) ? "CHANGE " . idf_escape($field["orig"]) . " " : "ADD "))
|
||||||
. idf_escape($field["field"]) . " $field[type]"
|
. idf_escape($field["field"]) . process_type($field)
|
||||||
. ($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"]) . "'" : "")
|
|
||||||
. ($field["null"] ? "" : " NOT NULL")
|
. ($field["null"] ? "" : " NOT NULL")
|
||||||
. ($key == $_POST["auto_increment"] ? " AUTO_INCREMENT$auto_increment_index" : "")
|
. ($key == $_POST["auto_increment"] ? " AUTO_INCREMENT$auto_increment_index" : "")
|
||||||
. " COMMENT '" . $mysql->escape_string($field["comment"]) . "'"
|
. " 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'));
|
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) {
|
if ($_POST) {
|
||||||
$row = $_POST;
|
$row = $_POST;
|
||||||
ksort($row["fields"]);
|
ksort($row["fields"]);
|
||||||
@@ -86,7 +92,7 @@ $collations = collations();
|
|||||||
<form action="" method="post" id="form">
|
<form action="" method="post" id="form">
|
||||||
<p>
|
<p>
|
||||||
<?php echo lang('Table name'); ?>: <input name="name" maxlength="64" value="<?php echo htmlspecialchars($row["name"]); ?>" />
|
<?php echo lang('Table name'); ?>: <input name="name" maxlength="64" value="<?php echo htmlspecialchars($row["name"]); ?>" />
|
||||||
<select name="Engine"><option value="">(<?php echo lang('engine'); ?>)</option><?php echo optionlist(engines(), $row["Engine"]); ?></select>
|
<select name="Engine"><option value="">(<?php echo lang('engine'); ?>)</option><?php echo optionlist($engines, $row["Engine"]); ?></select>
|
||||||
<select name="Collation"><option value="">(<?php echo lang('collation'); ?>)</option><?php echo optionlist($collations, $row["Collation"]); ?></select>
|
<select name="Collation"><option value="">(<?php echo lang('collation'); ?>)</option><?php echo optionlist($collations, $row["Collation"]); ?></select>
|
||||||
<input type="submit" value="<?php echo lang('Save'); ?>" />
|
<input type="submit" value="<?php echo lang('Save'); ?>" />
|
||||||
</p>
|
</p>
|
||||||
|
@@ -16,6 +16,7 @@ if ($_POST) {
|
|||||||
echo "<p class='error'>" . lang('Unable to operate view') . ": " . htmlspecialchars($error) . "</p>\n";
|
echo "<p class='error'>" . lang('Unable to operate view') . ": " . htmlspecialchars($error) . "</p>\n";
|
||||||
} elseif (strlen($_GET["createv"])) {
|
} elseif (strlen($_GET["createv"])) {
|
||||||
$row = view($_GET["createv"]);
|
$row = view($_GET["createv"]);
|
||||||
|
$row["name"] = $_GET["createv"];
|
||||||
} else {
|
} else {
|
||||||
$row = array();
|
$row = array();
|
||||||
}
|
}
|
||||||
|
163
editing.inc.php
Normal file
163
editing.inc.php
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
<?php
|
||||||
|
function input($name, $field, $value) {
|
||||||
|
global $types;
|
||||||
|
$name = htmlspecialchars(bracket_escape($name));
|
||||||
|
if ($field["type"] == "enum") {
|
||||||
|
if (!isset($_GET["default"])) {
|
||||||
|
echo '<input type="radio" name="fields[' . $name . ']" value="0"' . ($value === 0 ? ' checked="checked"' : '') . ' />';
|
||||||
|
}
|
||||||
|
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 ' <label for="' . $id . '"><input type="radio" name="fields[' . $name . ']" id="' . $id . '" value="' . (isset($_GET["default"]) ? htmlspecialchars($val) : $i+1) . '"' . ($checked ? ' checked="checked"' : '') . ' />' . htmlspecialchars($val) . '</label>';
|
||||||
|
}
|
||||||
|
if ($field["null"]) {
|
||||||
|
$id = "field-$name-";
|
||||||
|
echo ' <label for="' . $id . '"><input type="radio" name="fields[' . $name . ']" id="' . $id . '" value=""' . (strlen($value) ? '' : ' checked="checked"') . ' />' . lang('NULL') . '</label>';
|
||||||
|
}
|
||||||
|
} 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 ' <input type="checkbox" name="fields[' . $name . '][' . $i . ']" id="' . $id . '" value="' . (isset($_GET["default"]) ? htmlspecialchars($val) : 1 << $i) . '"' . ($checked ? ' checked="checked"' : '') . ' /><label for="' . $id . '">' . htmlspecialchars($val) . '</label>';
|
||||||
|
}
|
||||||
|
} elseif (strpos($field["type"], "text") !== false) {
|
||||||
|
echo '<textarea name="fields[' . $name . ']" cols="50" rows="12">' . htmlspecialchars($value) . '</textarea>';
|
||||||
|
} elseif (preg_match('~binary|blob~', $field["type"])) {
|
||||||
|
echo (ini_get("file_uploads") ? '<input type="file" name="' . $name . '" />' : lang('File uploads are disabled.') . ' ');
|
||||||
|
} else {
|
||||||
|
echo '<input name="fields[' . $name . ']" value="' . htmlspecialchars($value) . '"' . (strlen($field["length"]) ? " maxlength='$field[length]'" : ($types[$field["type"]] ? " maxlength='" . $types[$field["type"]] . "'" : '')) . ' />';
|
||||||
|
}
|
||||||
|
if ($field["null"] && preg_match('~char|text|set|binary|blob~', $field["type"])) {
|
||||||
|
$id = "null-$name";
|
||||||
|
echo '<label for="' . $id . '"><input type="checkbox" name="null[' . $name . ']" value="1" id="' . $id . '"' . (isset($value) ? '' : ' checked="checked"') . ' />' . lang('NULL') . '</label>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
?>
|
||||||
|
<td><select name="<?php echo $key; ?>[type]" onchange="type_change(this);"><?php echo optionlist(array_keys($types), $field["type"]); ?></select></td>
|
||||||
|
<td><input name="<?php echo $key; ?>[length]" value="<?php echo htmlspecialchars($field["length"]); ?>" size="3" /></td>
|
||||||
|
<td><select name="<?php echo $key; ?>[collation]"><option value="">(<?php echo lang('collation'); ?>)</option><?php echo optionlist($collations, $field["collation"]); ?></select> <select name="<?php echo $key; ?>[unsigned]"><?php echo optionlist($unsigned, $field["unsigned"]); ?></select></td>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
function process_type($field) {
|
||||||
|
global $mysql, $enum_length, $unsigned;
|
||||||
|
return " $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"]) . "'" : "")
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
function edit_fields($fields, $collations, $type = "TABLE") {
|
||||||
|
global $inout;
|
||||||
|
?>
|
||||||
|
<table border="0" cellspacing="0" cellpadding="2">
|
||||||
|
<thead><tr>
|
||||||
|
<?php if ($type == "PROCEDURE") { ?><td><?php echo lang('In-Out'); ?></td><?php } ?>
|
||||||
|
<th><?php echo lang('Column name'); ?></th>
|
||||||
|
<td><?php echo lang('Type'); ?></td>
|
||||||
|
<td><?php echo lang('Length'); ?></td>
|
||||||
|
<td><?php echo lang('Options'); ?></td>
|
||||||
|
<?php if ($type == "TABLE") { ?>
|
||||||
|
<td><?php echo lang('NULL'); ?></td>
|
||||||
|
<td><input type="radio" name="auto_increment" value="" /><?php echo lang('Auto Increment'); ?></td>
|
||||||
|
<td id="comment-0"><?php echo lang('Comment'); ?></td>
|
||||||
|
<?php } ?>
|
||||||
|
<td><input type="submit" name="add[0]" value="<?php echo lang('Add next'); ?>" /></td>
|
||||||
|
</tr></thead>
|
||||||
|
<?php
|
||||||
|
$column_comments = false;
|
||||||
|
foreach ($fields as $i => $field) {
|
||||||
|
$i++;
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<?php if ($type == "PROCEDURE") { ?><td><select name="inout"><?php echo optionlist($inout, $field["inout"]); ?></select></td><?php } ?>
|
||||||
|
<th><input type="hidden" name="fields[<?php echo $i; ?>][orig]" value="<?php echo htmlspecialchars($field[($_POST ? "orig" : "field")]); ?>" /><input name="fields[<?php echo $i; ?>][field]" value="<?php echo htmlspecialchars($field["field"]); ?>" maxlength="64" /></th>
|
||||||
|
<?php edit_type("fields[$i]", $field, $collations); ?>
|
||||||
|
<?php if ($type == "TABLE") { ?>
|
||||||
|
<td><input type="checkbox" name="fields[<?php echo $i; ?>][null]" value="1"<?php if ($field["null"]) { ?> checked="checked"<?php } ?> /></td>
|
||||||
|
<td><input type="radio" name="auto_increment" value="<?php echo $i; ?>"<?php if ($field["auto_increment"]) { ?> checked="checked"<?php } ?> /></td>
|
||||||
|
<td id="comment-<?php echo $i; ?>"><input name="fields[<?php echo $i; ?>][comment]" value="<?php echo htmlspecialchars($field["comment"]); ?>" maxlength="255" /></td>
|
||||||
|
<?php } ?>
|
||||||
|
<td><input type="submit" name="add[<?php echo $i; ?>]" value="<?php echo lang('Add next'); ?>" /></td>
|
||||||
|
</tr>
|
||||||
|
<?php
|
||||||
|
if (strlen($field["comment"])) {
|
||||||
|
$column_comments = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//! JavaScript for next rows
|
||||||
|
?>
|
||||||
|
</table>
|
||||||
|
<script type="text/javascript">
|
||||||
|
function type_change(type) {
|
||||||
|
var name = type.name.substr(0, type.name.length - 6);
|
||||||
|
type.form[name + '[collation]'].style.display = (/char|text|enum|set/.test(type.form[name + '[type]'].value) ? '' : 'none');
|
||||||
|
type.form[name + '[unsigned]'].style.display = (/int|float|double|decimal/.test(type.form[name + '[type]'].value) ? '' : 'none');
|
||||||
|
}
|
||||||
|
for (var i=1; <?php echo count($fields); ?> >= i; i++) {
|
||||||
|
document.getElementById('form')['fields[' + i + '][type]'].onchange();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<?php
|
||||||
|
return $column_comments;
|
||||||
|
}
|
||||||
|
|
||||||
|
function routine($name, $type) {
|
||||||
|
global $mysql, $enum_length, $inout;
|
||||||
|
$type_pattern = "([a-z]+)(?:\\s*\\(((?:[^'\")]*|$enum_length)+)\\))?\\s*(zerofill\\s*)?(unsigned(?:\\s+zerofill)?)?";
|
||||||
|
$pattern = "\\s*(" . ($type == "FUNCTION" ? "" : implode("|", $inout)) . ")?\\s*(?:`((?:[^`]+|``)*)`\\s*|\\b(\\S+)\\s+)$type_pattern";
|
||||||
|
$create = $mysql->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]);
|
||||||
|
}
|
@@ -113,35 +113,13 @@ function foreign_keys($table) {
|
|||||||
|
|
||||||
function view($name) {
|
function view($name) {
|
||||||
global $mysql;
|
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) {
|
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))), '\\')) . "'";
|
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) {
|
function unique_idf($row, $indexes) {
|
||||||
foreach ($indexes as $index) {
|
foreach ($indexes as $index) {
|
||||||
if ($index["type"] == "PRIMARY" || $index["type"] == "UNIQUE") {
|
if ($index["type"] == "PRIMARY" || $index["type"] == "UNIQUE") {
|
||||||
@@ -185,19 +163,6 @@ function collations() {
|
|||||||
return $return;
|
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() {
|
function token() {
|
||||||
return ($GLOBALS["TOKENS"][] = rand(1, 1e6));
|
return ($GLOBALS["TOKENS"][] = rand(1, 1e6));
|
||||||
}
|
}
|
||||||
@@ -301,123 +266,6 @@ function select($result) {
|
|||||||
$result->free();
|
$result->free();
|
||||||
}
|
}
|
||||||
|
|
||||||
function input($name, $field, $value) {
|
|
||||||
global $types;
|
|
||||||
$name = htmlspecialchars(bracket_escape($name));
|
|
||||||
if ($field["type"] == "enum") {
|
|
||||||
if (!isset($_GET["default"])) {
|
|
||||||
echo '<input type="radio" name="fields[' . $name . ']" value="0"' . ($value === 0 ? ' checked="checked"' : '') . ' />';
|
|
||||||
}
|
|
||||||
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 ' <label for="' . $id . '"><input type="radio" name="fields[' . $name . ']" id="' . $id . '" value="' . (isset($_GET["default"]) ? htmlspecialchars($val) : $i+1) . '"' . ($checked ? ' checked="checked"' : '') . ' />' . htmlspecialchars($val) . '</label>';
|
|
||||||
}
|
|
||||||
if ($field["null"]) {
|
|
||||||
$id = "field-$name-";
|
|
||||||
echo ' <label for="' . $id . '"><input type="radio" name="fields[' . $name . ']" id="' . $id . '" value=""' . (strlen($value) ? '' : ' checked="checked"') . ' />' . lang('NULL') . '</label>';
|
|
||||||
}
|
|
||||||
} 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 ' <input type="checkbox" name="fields[' . $name . '][' . $i . ']" id="' . $id . '" value="' . (isset($_GET["default"]) ? htmlspecialchars($val) : 1 << $i) . '"' . ($checked ? ' checked="checked"' : '') . ' /><label for="' . $id . '">' . htmlspecialchars($val) . '</label>';
|
|
||||||
}
|
|
||||||
} elseif (strpos($field["type"], "text") !== false) {
|
|
||||||
echo '<textarea name="fields[' . $name . ']" cols="50" rows="12">' . htmlspecialchars($value) . '</textarea>';
|
|
||||||
} elseif (preg_match('~binary|blob~', $field["type"])) {
|
|
||||||
echo (ini_get("file_uploads") ? '<input type="file" name="' . $name . '" />' : lang('File uploads are disabled.') . ' ');
|
|
||||||
} else {
|
|
||||||
echo '<input name="fields[' . $name . ']" value="' . htmlspecialchars($value) . '"' . (strlen($field["length"]) ? " maxlength='$field[length]'" : ($types[$field["type"]] ? " maxlength='" . $types[$field["type"]] . "'" : '')) . ' />';
|
|
||||||
}
|
|
||||||
if ($field["null"] && preg_match('~char|text|set|binary|blob~', $field["type"])) {
|
|
||||||
$id = "null-$name";
|
|
||||||
echo '<label for="' . $id . '"><input type="checkbox" name="null[' . $name . ']" value="1" id="' . $id . '"' . (isset($value) ? '' : ' checked="checked"') . ' />' . lang('NULL') . '</label>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
?>
|
|
||||||
<table border="0" cellspacing="0" cellpadding="2">
|
|
||||||
<thead><tr>
|
|
||||||
<?php if ($type == "PROCEDURE") { ?><td><?php echo lang('In-Out'); ?></td><?php } ?>
|
|
||||||
<th><?php echo lang('Column name'); ?></th>
|
|
||||||
<td><?php echo lang('Type'); ?></td>
|
|
||||||
<td><?php echo lang('Length'); ?></td>
|
|
||||||
<td><?php echo lang('Options'); ?></td>
|
|
||||||
<?php if ($type == "TABLE") { ?>
|
|
||||||
<td><?php echo lang('NULL'); ?></td>
|
|
||||||
<td><input type="radio" name="auto_increment" value="" /><?php echo lang('Auto Increment'); ?></td>
|
|
||||||
<td id="comment-0"><?php echo lang('Comment'); ?></td>
|
|
||||||
<?php } ?>
|
|
||||||
<td><input type="submit" name="add[0]" value="<?php echo lang('Add next'); ?>" /></td>
|
|
||||||
</tr></thead>
|
|
||||||
<?php
|
|
||||||
$column_comments = false;
|
|
||||||
foreach ($fields as $i => $field) {
|
|
||||||
$i++;
|
|
||||||
?>
|
|
||||||
<tr>
|
|
||||||
<?php if ($type == "PROCEDURE") { ?><td><select name="inout"><?php echo optionlist($inout, $field["inout"]); ?></select></td><?php } ?>
|
|
||||||
<th><input type="hidden" name="fields[<?php echo $i; ?>][orig]" value="<?php echo htmlspecialchars($field[($_POST ? "orig" : "field")]); ?>" /><input name="fields[<?php echo $i; ?>][field]" value="<?php echo htmlspecialchars($field["field"]); ?>" maxlength="64" /></th>
|
|
||||||
<td><select name="fields[<?php echo $i; ?>][type]" onchange="type_change(this);"><?php echo optionlist(array_keys($types), $field["type"]); ?></select></td>
|
|
||||||
<td><input name="fields[<?php echo $i; ?>][length]" value="<?php echo htmlspecialchars($field["length"]); ?>" size="3" /></td>
|
|
||||||
<td><select name="fields[<?php echo $i; ?>][collation]"><option value="">(<?php echo lang('collation'); ?>)</option><?php echo optionlist($collations, $field["collation"]); ?></select> <select name="fields[<?php echo $i; ?>][unsigned]"><?php echo optionlist($unsigned, $field["unsigned"]); ?></select></td>
|
|
||||||
<?php if ($type == "TABLE") { ?>
|
|
||||||
<td><input type="checkbox" name="fields[<?php echo $i; ?>][null]" value="1"<?php if ($field["null"]) { ?> checked="checked"<?php } ?> /></td>
|
|
||||||
<td><input type="radio" name="auto_increment" value="<?php echo $i; ?>"<?php if ($field["auto_increment"]) { ?> checked="checked"<?php } ?> /></td>
|
|
||||||
<td id="comment-<?php echo $i; ?>"><input name="fields[<?php echo $i; ?>][comment]" value="<?php echo htmlspecialchars($field["comment"]); ?>" maxlength="255" /></td>
|
|
||||||
<?php } ?>
|
|
||||||
<td><input type="submit" name="add[<?php echo $i; ?>]" value="<?php echo lang('Add next'); ?>" /></td>
|
|
||||||
</tr>
|
|
||||||
<?php
|
|
||||||
if (strlen($field["comment"])) {
|
|
||||||
$column_comments = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//! JavaScript for next rows
|
|
||||||
?>
|
|
||||||
</table>
|
|
||||||
<script type="text/javascript">
|
|
||||||
function type_change(type) {
|
|
||||||
var name = type.name.substr(0, type.name.length - 6);
|
|
||||||
type.form[name + '[collation]'].style.display = (/char|text|enum|set/.test(type.form[name + '[type]'].value) ? '' : 'none');
|
|
||||||
type.form[name + '[unsigned]'].style.display = (/int|float|double|decimal/.test(type.form[name + '[type]'].value) ? '' : 'none');
|
|
||||||
}
|
|
||||||
for (var i=1; <?php echo count($fields); ?> >= i; i++) {
|
|
||||||
document.getElementById('form')['fields[' + i + '][type]'].onchange();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
<?php
|
|
||||||
return $column_comments;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (get_magic_quotes_gpc()) {
|
if (get_magic_quotes_gpc()) {
|
||||||
$process = array(&$_GET, &$_POST);
|
$process = array(&$_GET, &$_POST);
|
||||||
while (list($key, $val) = each($process)) {
|
while (list($key, $val) = each($process)) {
|
||||||
|
15
index.php
15
index.php
@@ -39,6 +39,7 @@ if (isset($_GET["dump"])) {
|
|||||||
} elseif (isset($_GET["view"])) {
|
} elseif (isset($_GET["view"])) {
|
||||||
include "./view.inc.php";
|
include "./view.inc.php";
|
||||||
} else { // uses CSRF token
|
} else { // uses CSRF token
|
||||||
|
include "./editing.inc.php";
|
||||||
if ($_POST) {
|
if ($_POST) {
|
||||||
$error = (in_array($_POST["token"], (array) $TOKENS) ? "" : lang('Invalid CSRF token. Send the form again.'));
|
$error = (in_array($_POST["token"], (array) $TOKENS) ? "" : lang('Invalid CSRF token. Send the form again.'));
|
||||||
}
|
}
|
||||||
@@ -49,8 +50,8 @@ if (isset($_GET["dump"])) {
|
|||||||
if (isset($_GET["callf"])) {
|
if (isset($_GET["callf"])) {
|
||||||
$_GET["call"] = $_GET["callf"];
|
$_GET["call"] = $_GET["callf"];
|
||||||
}
|
}
|
||||||
if (isset($_GET["createf"])) {
|
if (isset($_GET["function"])) {
|
||||||
$_GET["createp"] = $_GET["createf"];
|
$_GET["procedure"] = $_GET["function"];
|
||||||
}
|
}
|
||||||
if (isset($_GET["sql"])) {
|
if (isset($_GET["sql"])) {
|
||||||
include "./sql.inc.php";
|
include "./sql.inc.php";
|
||||||
@@ -68,8 +69,8 @@ if (isset($_GET["dump"])) {
|
|||||||
include "./foreign.inc.php";
|
include "./foreign.inc.php";
|
||||||
} elseif (isset($_GET["createv"])) {
|
} elseif (isset($_GET["createv"])) {
|
||||||
include "./createv.inc.php";
|
include "./createv.inc.php";
|
||||||
} elseif (isset($_GET["createp"])) {
|
} elseif (isset($_GET["procedure"])) {
|
||||||
include "./createp.inc.php";
|
include "./procedure.inc.php";
|
||||||
} elseif (isset($_GET["processlist"])) {
|
} elseif (isset($_GET["processlist"])) {
|
||||||
include "./processlist.inc.php";
|
include "./processlist.inc.php";
|
||||||
} else {
|
} else {
|
||||||
@@ -85,14 +86,14 @@ if (isset($_GET["dump"])) {
|
|||||||
echo "<tr>";
|
echo "<tr>";
|
||||||
echo "<th>" . htmlspecialchars($row["ROUTINE_TYPE"]) . "</th>";
|
echo "<th>" . htmlspecialchars($row["ROUTINE_TYPE"]) . "</th>";
|
||||||
echo '<td><a href="' . htmlspecialchars($SELF) . ($row["ROUTINE_TYPE"] == "FUNCTION" ? 'callf' : 'call') . '=' . urlencode($row["ROUTINE_NAME"]) . '">' . htmlspecialchars($row["ROUTINE_NAME"]) . '</a></td>';
|
echo '<td><a href="' . htmlspecialchars($SELF) . ($row["ROUTINE_TYPE"] == "FUNCTION" ? 'callf' : 'call') . '=' . urlencode($row["ROUTINE_NAME"]) . '">' . htmlspecialchars($row["ROUTINE_NAME"]) . '</a></td>';
|
||||||
echo '<td><a href="' . htmlspecialchars($SELF) . ($row["ROUTINE_TYPE"] == "FUNCTION" ? 'createf' : 'createp') . '=' . urlencode($row["ROUTINE_NAME"]) . '">' . lang('Alter') . "</a></td>\n";
|
echo '<td><a href="' . htmlspecialchars($SELF) . ($row["ROUTINE_TYPE"] == "FUNCTION" ? 'function' : 'procedure') . '=' . urlencode($row["ROUTINE_NAME"]) . '">' . lang('Alter') . "</a></td>\n";
|
||||||
echo "</tr>\n";
|
echo "</tr>\n";
|
||||||
}
|
}
|
||||||
echo "</table>\n";
|
echo "</table>\n";
|
||||||
}
|
}
|
||||||
$result->free();
|
$result->free();
|
||||||
echo '<p><a href="' . htmlspecialchars($SELF) . 'createp=">' . lang('Create procedure') . '</a> <a href="' . htmlspecialchars($SELF) . 'createf=">' . lang('Create function') . "</a></p>\n";
|
echo '<p><a href="' . htmlspecialchars($SELF) . 'function=">' . lang('Create procedure') . '</a> <a href="' . htmlspecialchars($SELF) . 'createf=">' . lang('Create function') . "</a></p>\n";
|
||||||
echo '<p><a href="' . htmlspecialchars($SELF) . 'createv=">' . lang('Create view') . "</a></p>\n";
|
echo '<p><a href="' . htmlspecialchars($SELF) . 'procedure=">' . lang('Create view') . "</a></p>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user