<?php
-$where = (isset($_GET["select"]) ? array() : where($_GET));
-$update = ($where && !$_GET["clone"]);
+$where = (isset($_GET["select"]) ? (count($_POST["check"]) == 1 ? where_check($_POST["check"][0]) : array()) : where($_GET));
+$update = ($where && !$_POST["clone"]);
$fields = fields($_GET["edit"]);
foreach ($fields as $name => $field) {
if (isset($_GET["default"]) ? $field["auto_increment"] || preg_match('~text|blob~', $field["type"]) : !isset($field["privileges"][$update ? "update" : "insert"])) {
}
}
}
-page_header((isset($_GET["default"]) ? lang('Default values') : ($_GET["where"] || isset($_GET["select"]) ? lang('Edit') : lang('Insert'))), $error, array((isset($_GET["default"]) ? "table" : "select") => $_GET["edit"]), $_GET["edit"]);
+page_header((isset($_GET["default"]) ? lang('Default values') : ($_GET["where"] || (isset($_GET["select"]) && !$_POST["clone"]) ? lang('Edit') : lang('Insert'))), $error, array((isset($_GET["default"]) ? "table" : "select") => $_GET["edit"]), $_GET["edit"]);
unset($row);
-if ($_POST) {
+if ($_POST["save"]) {
$row = (array) $_POST["fields"];
} elseif ($where) {
$select = array();
foreach ($fields as $name => $field) {
- if (isset($field["privileges"]["select"]) && (!$_GET["clone"] || !$field["auto_increment"])) {
+ if (isset($field["privileges"]["select"]) && (!$_POST["clone"] || !$field["auto_increment"])) {
$select[] = ($field["type"] == "enum" || $field["type"] == "set" ? "1*" . idf_escape($name) . " AS " : "") . idf_escape($name);
}
}
echo "<table cellspacing='0'>\n";
foreach ($fields as $name => $field) {
echo "<tr><th>" . htmlspecialchars($name) . "</th>";
- $value = (!isset($row) ? $field["default"] :
- (strlen($row[$name]) && ($field["type"] == "enum" || $field["type"] == "set") ? intval($row[$name]) :
- ($_POST["clone"] && $field["auto_increment"] ? "" :
- $row[$name]
- )));
+ $value = (!isset($row) ? ($_POST["clone"] && $field["auto_increment"] ? "" : $field["default"])
+ : (strlen($row[$name]) && ($field["type"] == "enum" || $field["type"] == "set") ? intval($row[$name]) : $row[$name])
+ );
input($name, $field, $value);
if (isset($_GET["default"]) && $field["type"] == "timestamp") {
if (!isset($create) && !$_POST) {
?>
<p>
<input type="hidden" name="token" value="<?php echo $token; ?>" />
+<input type="hidden" name="save" value="1" />
<?php
if (isset($_GET["select"])) {
hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
- echo "<input type='hidden' name='save' value='1' />\n";
}
if ($fields) {
echo '<input type="submit" value="' . lang('Save') . '" />';
if (preg_match('~char|date|time~', $field["type"])) {
$options = (preg_match('~char~', $field["type"]) ? array("", "md5", "sha1", "password", "uuid") : array("", "now"));
}
- if (!isset($_GET["clone"]) && !isset($_GET["call"]) && (isset($_GET["select"]) || where($_GET))) {
+ if (!isset($_GET["call"]) && (isset($_GET["select"]) || where($_GET))) {
if (preg_match('~int|float|double|decimal~', $field["type"])) {
$options = array("", "+", "-");
}
return $return;
}
+function where_check($val) {
+ parse_str($val, $check);
+ return where($check);
+}
+
function process_length($length) {
global $enum_length;
return (preg_match("~^\\s*(?:$enum_length)(?:\\s*,\\s*(?:$enum_length))*\\s*\$~", $length) && preg_match_all("~$enum_length~", $length, $matches) ? implode(",", $matches[0]) : preg_replace('~[^0-9,+-]~', '', $length));
if (isset($_GET["function"])) {
$_GET["procedure"] = $_GET["function"];
}
- if (isset($_GET["clone"])) {
- $_GET["edit"] = $_GET["clone"];
- }
if (isset($_GET["sql"])) {
include "./sql.inc.php";
} elseif (isset($_GET["edit"])) {
dump_table($_GET["select"], "");
if (is_array($_POST["check"])) {
foreach ($_POST["check"] as $val) {
- parse_str($val, $check);
- dump_data($_GET["select"], "INSERT", "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where($check)) . " LIMIT 1");
+ dump_data($_GET["select"], "INSERT", "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", where_check($val)) . " LIMIT 1");
}
} else {
dump_data($_GET["select"], "INSERT", ($where ? "FROM " . idf_escape($_GET["select"]) . " WHERE " . implode(" AND ", $where) : ""));
if ($_POST["clone"]) {
$set[] = ($val !== false ? $val : idf_escape($name));
} elseif ($val !== false) {
- $set[] = idf_escape($name) . " = $val";
+ $set[] = "\n" . idf_escape($name) . " = $val";
}
}
- $command .= ($_POST["clone"] ? " SELECT " . implode(", ", $set) . " FROM " . idf_escape($_GET["select"]) : " SET " . implode(", ", $set));
+ $command .= ($_POST["clone"] ? "\nSELECT " . implode(", ", $set) . " FROM " . idf_escape($_GET["select"]) : " SET" . implode(",", $set));
}
if (!$_POST["delete"] && !$set) {
// nothing
echo "</tr></thead>\n";
}
$unique_idf = implode('&', unique_idf($row, $indexes));
- echo '<tr' . odd() . '><td><input type="checkbox" name="check[]" value="' . $unique_idf . '" onclick="this.form[\'all\'].checked = false; form_uncheck(\'all-page\');" />' . (count($select) == count($group) && $_GET["db"] != "information_schema" ? ' <a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '&' . $unique_idf . '">' . lang('edit') . '</a> <a href="' . htmlspecialchars($SELF) . 'clone=' . urlencode($_GET['select']) . '&' . $unique_idf . '">' . lang('clone') . '</a></td>' : '');
+ echo '<tr' . odd() . '><td><input type="checkbox" name="check[]" value="' . $unique_idf . '" onclick="this.form[\'all\'].checked = false; form_uncheck(\'all-page\');" />' . (count($select) == count($group) && $_GET["db"] != "information_schema" ? ' <a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '&' . $unique_idf . '">' . lang('edit') . '</a></td>' : '');
foreach ($row as $key => $val) {
if (!isset($val)) {
$val = "<i>NULL</i>";