Rights
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@66 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
ffcea8b587
commit
1faeb90e02
44
edit.inc.php
44
edit.inc.php
|
@ -1,15 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
$fields = fields($_GET["edit"]);
|
$fields = fields($_GET["edit"]);
|
||||||
$where = array();
|
$where = array();
|
||||||
if (is_array($_GET["where"])) {
|
foreach ((array) $_GET["where"] as $key => $val) {
|
||||||
foreach ($_GET["where"] as $key => $val) {
|
$where[] = idf_escape($key) . " = BINARY '" . mysql_real_escape_string($val) . "'"; //! enum and set
|
||||||
$where[] = idf_escape($key) . " = BINARY '" . mysql_real_escape_string($val) . "'";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (is_array($_GET["null"])) {
|
foreach ((array) $_GET["null"] as $key) {
|
||||||
foreach ($_GET["null"] as $key) {
|
|
||||||
$where[] = idf_escape($key) . " IS NULL";
|
$where[] = idf_escape($key) . " IS NULL";
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ($_POST) {
|
if ($_POST) {
|
||||||
if (isset($_POST["delete"])) {
|
if (isset($_POST["delete"])) {
|
||||||
|
@ -17,17 +13,19 @@ if ($_POST) {
|
||||||
$message = lang('Item has been deleted.');
|
$message = lang('Item has been deleted.');
|
||||||
} else {
|
} else {
|
||||||
$set = array();
|
$set = array();
|
||||||
foreach ($fields as $key => $field) {
|
foreach ($_POST["fields"] as $key => $val) {
|
||||||
if (preg_match('~char|text|set~', $field["type"]) ? $_POST["null"][$key] : !strlen($_POST["fields"][$key])) {
|
$name = bracket_escape($key, "back");
|
||||||
$value = "NULL";
|
$field = $fields[$name];
|
||||||
|
if (preg_match('~char|text|set~', $field["type"]) ? $_POST["null"][$key] : !strlen($val)) {
|
||||||
|
$val = "NULL";
|
||||||
} elseif ($field["type"] == "enum") {
|
} elseif ($field["type"] == "enum") {
|
||||||
$value = intval($_POST["fields"][$key]);
|
$val = intval($val);
|
||||||
} elseif ($field["type"] == "set") {
|
} elseif ($field["type"] == "set") {
|
||||||
$value = array_sum((array) $_POST["fields"][$key]);
|
$val = array_sum((array) $val);
|
||||||
} else {
|
} else {
|
||||||
$value = "'" . mysql_real_escape_string($_POST["fields"][$key]) . "'";
|
$val = "'" . mysql_real_escape_string($val) . "'";
|
||||||
}
|
}
|
||||||
$set[] = idf_escape(bracket_escape($key, "back")) . " = $value";
|
$set[] = idf_escape($name) . " = $val";
|
||||||
}
|
}
|
||||||
if ($where) {
|
if ($where) {
|
||||||
$query = "UPDATE " . idf_escape($_GET["edit"]) . " SET " . implode(", ", $set) . " WHERE " . implode(" AND ", $where) . " LIMIT 1";
|
$query = "UPDATE " . idf_escape($_GET["edit"]) . " SET " . implode(", ", $set) . " WHERE " . implode(" AND ", $where) . " LIMIT 1";
|
||||||
|
@ -47,26 +45,27 @@ page_header(($_GET["where"] ? lang('Edit') : lang('Insert')) . ": " . htmlspecia
|
||||||
if ($_POST) {
|
if ($_POST) {
|
||||||
echo "<p class='error'>" . lang('Error during saving') . ": " . htmlspecialchars($error) . "</p>\n";
|
echo "<p class='error'>" . lang('Error during saving') . ": " . htmlspecialchars($error) . "</p>\n";
|
||||||
$data = $_POST["fields"];
|
$data = $_POST["fields"];
|
||||||
foreach ($_POST["fields"] as $key => $val) {
|
foreach ($_POST["null"] as $key => $val) {
|
||||||
$data[$key] = null;
|
$data[$key] = null;
|
||||||
}
|
}
|
||||||
} elseif ($where) {
|
} elseif ($where) {
|
||||||
$select = array("*");
|
$select = array();
|
||||||
foreach ($fields as $name => $field) {
|
foreach ($fields as $name => $field) {
|
||||||
if ($field["type"] == "enum" || $field["type"] == "set") {
|
if (in_array("select", $field["privileges"]) && in_array(($where ? "update" : "insert"), $field["privileges"])) {
|
||||||
$select[] = "1*" . idf_escape($name) . " AS " . idf_escape($name);
|
$select[] = ($field["type"] == "enum" || $field["type"] == "set" ? "1*" . idf_escape($name) . " AS " : "") . idf_escape($name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$data = mysql_fetch_assoc(mysql_query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1"));
|
$data = ($select ? mysql_fetch_assoc(mysql_query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1")) : array());
|
||||||
} else {
|
} else {
|
||||||
$data = array();
|
$data = array();
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
<table border='1' cellspacing='0' cellpadding='2'>
|
<table border="0" cellspacing="0" cellpadding="2">
|
||||||
<?php
|
<?php
|
||||||
$types = types();
|
$types = types();
|
||||||
foreach ($fields as $name => $field) {
|
foreach ($fields as $name => $field) {
|
||||||
|
if (in_array(($where ? "update" : "insert"), $field["privileges"])) {
|
||||||
echo "<tr><th>" . htmlspecialchars($name) . "</th><td>";
|
echo "<tr><th>" . htmlspecialchars($name) . "</th><td>";
|
||||||
$value = ($data ? $data[$name] : $field["default"]);
|
$value = ($data ? $data[$name] : $field["default"]);
|
||||||
$name = htmlspecialchars(bracket_escape($name));
|
$name = htmlspecialchars(bracket_escape($name));
|
||||||
|
@ -89,15 +88,16 @@ foreach ($fields as $name => $field) {
|
||||||
}
|
}
|
||||||
} elseif (strpos($field["type"], "text") !== false) {
|
} elseif (strpos($field["type"], "text") !== false) {
|
||||||
echo '<textarea name="fields[' . $name . ']" cols="50" rows="12">' . htmlspecialchars($value) . '</textarea>';
|
echo '<textarea name="fields[' . $name . ']" cols="50" rows="12">' . htmlspecialchars($value) . '</textarea>';
|
||||||
} else { //! numbers, date, binary
|
} else { //! binary
|
||||||
echo '<input name="fields[' . $name . ']" value="' . htmlspecialchars($value) . '"' . (strlen($field["length"]) ? " maxlength='$field[length]'" : ($types[$field["type"]] ? " maxlength='" . $types[$field["type"]] . "'" : '')) . ' />';
|
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~', $field["type"])) {
|
if ($field["null"] && preg_match('~char|text|set~', $field["type"])) {
|
||||||
echo '<input type="checkbox" name="null[' . $name . ']" value="1" id="null-' . $name . '"' . (isset($value) ? '' : ' checked="checked"') . ' /><label for="null-' . $name . '">' . lang('NULL') . '</label>';
|
echo '<input type="checkbox" name="null[' . $name . ']" value="1" id="null-' . $name . '"' . (isset($value) ? '' : ' checked="checked"') . ' /><label for="null-' . $name . '">' . lang('NULL') . '</label>';
|
||||||
}
|
}
|
||||||
echo "</td></tr>\n";
|
echo "</td></tr>\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
echo "<tr><th><input type='hidden' name='sent' value='1' /></th><td><input type='submit' value='" . lang('Save') . "' /> <input type='submit' name='insert' value='" . lang('Save and insert') . "' />" . ($where ? " <input type='submit' name='delete' value='" . lang('Delete') . "' />" : "") . "</td></tr>\n";
|
|
||||||
?>
|
?>
|
||||||
</table>
|
</table>
|
||||||
|
<p><input type="hidden" name="sent" value="1" /></th><td><input type="submit" value="<?php echo lang('Save'); ?>" /> <input type="submit" name="insert" value="<?php echo lang('Save and insert'); ?>" /><?php if ($where) { ?> <input type="submit" name="delete" value="<?php echo lang('Delete'); ?>" /><?php } ?></p>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in a new issue