2007-07-02 05:51:26 +00:00
|
|
|
<?php
|
2009-08-29 13:57:50 +00:00
|
|
|
$TABLE = $_GET["edit"];
|
2009-08-25 10:27:27 +00:00
|
|
|
$where = (isset($_GET["select"]) ? (count($_POST["check"]) == 1 ? where_check($_POST["check"][0]) : "") : where($_GET));
|
|
|
|
$update = (isset($_GET["select"]) ? $_POST["edit"] : $where);
|
2009-08-29 13:57:50 +00:00
|
|
|
$fields = fields($TABLE);
|
2007-07-25 15:18:59 +00:00
|
|
|
foreach ($fields as $name => $field) {
|
2010-01-09 23:33:41 +00:00
|
|
|
if (!isset($field["privileges"][$update ? "update" : "insert"]) || $adminer->fieldName($field) == "") {
|
2007-07-25 15:18:59 +00:00
|
|
|
unset($fields[$name]);
|
2007-07-09 06:12:22 +00:00
|
|
|
}
|
2007-07-05 10:41:53 +00:00
|
|
|
}
|
2008-10-01 11:39:13 +00:00
|
|
|
if ($_POST && !$error && !isset($_GET["select"])) {
|
2010-03-05 16:18:45 +00:00
|
|
|
$location = $_POST["referer"];
|
|
|
|
if ($_POST["insert"]) { // continue edit or insert
|
2010-04-15 14:59:40 +00:00
|
|
|
$location = ($update ? null : $_SERVER["REQUEST_URI"]);
|
2010-03-05 16:18:45 +00:00
|
|
|
} elseif (!ereg('^.+&select=.+$', $location)) {
|
2009-08-29 13:57:50 +00:00
|
|
|
$location = ME . "select=" . urlencode($TABLE);
|
2009-08-03 13:37:29 +00:00
|
|
|
}
|
2009-12-14 11:37:59 +00:00
|
|
|
if (isset($_POST["delete"])) {
|
2010-06-10 21:16:10 +00:00
|
|
|
query_redirect("DELETE" . limit1("FROM " . table($TABLE), " WHERE $where"), $location, lang('Item has been deleted.'));
|
2009-07-23 16:31:28 +00:00
|
|
|
} else {
|
2009-12-14 11:37:59 +00:00
|
|
|
$set = array();
|
|
|
|
foreach ($fields as $name => $field) {
|
|
|
|
$val = process_input($field);
|
2010-04-21 12:01:32 +00:00
|
|
|
if ($val !== false && $val !== null) {
|
|
|
|
$set[idf_escape($name)] = ($update ? "\n" . idf_escape($name) . " = $val" : $val);
|
2009-12-14 11:37:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($update) {
|
2010-04-21 12:01:32 +00:00
|
|
|
if (!$set) {
|
|
|
|
redirect($location);
|
|
|
|
}
|
2010-05-14 13:51:54 +00:00
|
|
|
query_redirect("UPDATE" . limit1(table($TABLE) . " SET" . implode(",", $set), "\nWHERE $where"), $location, lang('Item has been updated.'));
|
2009-12-14 11:37:59 +00:00
|
|
|
} else {
|
2010-05-12 16:07:46 +00:00
|
|
|
$result = insert_into($TABLE, $set);
|
|
|
|
$last_id = ($result ? last_id() : 0);
|
|
|
|
queries_redirect($location, lang('Item%s has been inserted.', ($last_id ? " $last_id" : "")), $result); //! link
|
2009-12-14 11:37:59 +00:00
|
|
|
}
|
2009-07-23 16:31:28 +00:00
|
|
|
}
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
2009-07-11 19:45:57 +00:00
|
|
|
|
2009-08-29 13:57:50 +00:00
|
|
|
$table_name = $adminer->tableName(table_status($TABLE));
|
2009-07-11 19:45:57 +00:00
|
|
|
page_header(
|
2009-08-21 16:54:10 +00:00
|
|
|
($update ? lang('Edit') : lang('Insert')),
|
2009-07-11 19:45:57 +00:00
|
|
|
$error,
|
2009-08-29 13:57:50 +00:00
|
|
|
array("select" => array($TABLE, $table_name)),
|
2009-07-11 19:45:57 +00:00
|
|
|
$table_name
|
|
|
|
);
|
2007-07-02 05:51:26 +00:00
|
|
|
|
2010-04-22 12:19:22 +00:00
|
|
|
$row = null;
|
2009-06-07 23:53:51 +00:00
|
|
|
if ($_POST["save"]) {
|
2007-07-16 14:01:28 +00:00
|
|
|
$row = (array) $_POST["fields"];
|
2007-07-02 05:51:26 +00:00
|
|
|
} elseif ($where) {
|
2007-07-06 13:48:25 +00:00
|
|
|
$select = array();
|
2007-07-02 05:51:26 +00:00
|
|
|
foreach ($fields as $name => $field) {
|
2009-06-13 17:00:48 +00:00
|
|
|
if (isset($field["privileges"]["select"])) {
|
2009-10-07 15:55:47 +00:00
|
|
|
$select[] = ($_POST["clone"] && $field["auto_increment"] ? "'' AS " : (ereg("enum|set", $field["type"]) ? "1*" . idf_escape($name) . " AS " : "")) . idf_escape($name);
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-09 13:23:54 +00:00
|
|
|
$row = array();
|
2007-07-10 13:30:42 +00:00
|
|
|
if ($select) {
|
2010-10-13 15:53:59 +00:00
|
|
|
$rows = get_rows("SELECT" . limit(implode(", ", $select) . " FROM " . table($TABLE), " WHERE $where", (isset($_GET["select"]) ? 2 : 1)));
|
|
|
|
$row = (isset($_GET["select"]) && count($rows) != 1 ? null : reset($rows));
|
2007-07-10 13:30:42 +00:00
|
|
|
}
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
|
|
|
?>
|
2007-07-09 14:45:11 +00:00
|
|
|
|
2010-11-12 16:09:30 +00:00
|
|
|
<form action="" method="post" enctype="multipart/form-data">
|
2007-07-02 05:51:26 +00:00
|
|
|
<?php
|
2007-07-10 20:26:17 +00:00
|
|
|
if ($fields) {
|
2009-05-01 10:41:33 +00:00
|
|
|
echo "<table cellspacing='0'>\n";
|
2007-07-10 20:26:17 +00:00
|
|
|
foreach ($fields as $name => $field) {
|
2009-07-27 11:25:37 +00:00
|
|
|
echo "<tr><th>" . $adminer->fieldName($field);
|
2009-07-30 08:12:54 +00:00
|
|
|
$default = $_GET["set"][bracket_escape($name)];
|
2009-06-30 10:27:12 +00:00
|
|
|
$value = (isset($row)
|
2010-01-09 23:33:41 +00:00
|
|
|
? ($row[$name] != "" && ereg("enum|set", $field["type"]) ? intval($row[$name]) : $row[$name])
|
2010-04-21 12:01:32 +00:00
|
|
|
: (!$update && $field["auto_increment"] ? "" : (isset($_GET["select"]) ? false : (isset($default) ? $default : $field["default"])))
|
2009-06-07 23:53:51 +00:00
|
|
|
);
|
2009-07-27 16:32:56 +00:00
|
|
|
if (!$_POST["save"] && is_string($value)) {
|
|
|
|
$value = $adminer->editVal($value, $field);
|
|
|
|
}
|
2010-01-11 19:58:32 +00:00
|
|
|
$function = ($_POST["save"] ? (string) $_POST["function"][$name] : ($where && $field["on_update"] == "CURRENT_TIMESTAMP" ? "now" : ($value === false ? null : (isset($value) ? '' : 'NULL'))));
|
2009-08-21 17:08:10 +00:00
|
|
|
if ($field["type"] == "timestamp" && $value == "CURRENT_TIMESTAMP") {
|
|
|
|
$value = "";
|
|
|
|
$function = "now";
|
|
|
|
}
|
2009-07-23 14:42:38 +00:00
|
|
|
input($field, $value, $function);
|
2009-07-11 20:30:40 +00:00
|
|
|
echo "\n";
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
2007-07-10 20:26:17 +00:00
|
|
|
echo "</table>\n";
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
|
|
|
?>
|
2007-07-09 06:12:22 +00:00
|
|
|
<p>
|
2009-07-11 20:30:40 +00:00
|
|
|
<input type="hidden" name="token" value="<?php echo $token; ?>">
|
2010-03-05 16:18:45 +00:00
|
|
|
<input type="hidden" name="referer" value="<?php echo h(isset($_POST["referer"]) ? $_POST["referer"] : $_SERVER["HTTP_REFERER"]); ?>">
|
2009-07-11 20:30:40 +00:00
|
|
|
<input type="hidden" name="save" value="1">
|
2008-10-01 11:39:13 +00:00
|
|
|
<?php
|
|
|
|
if (isset($_GET["select"])) {
|
2008-10-09 13:23:54 +00:00
|
|
|
hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
|
2008-10-01 11:39:13 +00:00
|
|
|
}
|
|
|
|
if ($fields) {
|
2010-10-18 05:43:50 +00:00
|
|
|
echo "<input type='submit' value='" . lang('Save') . "'" . (isset($_GET["select"]) ? " onclick='return !ajaxForm(this.form);'" : "") . ">\n";
|
2009-08-21 16:54:10 +00:00
|
|
|
if (!isset($_GET["select"])) {
|
2010-10-17 22:09:29 +00:00
|
|
|
echo '<input type="submit" name="insert" value="' . ($update ? lang('Save and continue edit') : lang('Save and insert next')) . "\" onclick=\"return !ajaxForm(this.form, 'insert=1');\">\n";
|
2009-06-07 23:24:37 +00:00
|
|
|
}
|
|
|
|
}
|
2009-12-14 11:37:59 +00:00
|
|
|
if ($update) {
|
2010-10-18 05:43:50 +00:00
|
|
|
echo "<input type='submit' name='delete' value='" . lang('Delete') . "' onclick=\"return confirm('" . lang('Are you sure?') . "')" . (isset($_GET["select"]) ? " && !ajaxForm(this.form, 'delete=1')" : "") . ";\">\n";
|
2009-12-14 11:37:59 +00:00
|
|
|
}
|
2009-06-07 23:24:37 +00:00
|
|
|
?>
|
2007-07-02 05:51:26 +00:00
|
|
|
</form>
|