2007-07-02 05:51:26 +00:00
|
|
|
<?php
|
2009-08-29 13:57:50 +00:00
|
|
|
$TABLE = $_GET["edit"];
|
|
|
|
$fields = fields($TABLE);
|
2018-01-16 15:22:24 +00:00
|
|
|
$where = (isset($_GET["select"]) ? ($_POST["check"] && count($_POST["check"]) == 1 ? where_check($_POST["check"][0], $fields) : "") : where($_GET, $fields));
|
2012-12-12 05:25:56 +00:00
|
|
|
$update = (isset($_GET["select"]) ? $_POST["edit"] : $where);
|
2007-07-25 15:18:59 +00:00
|
|
|
foreach ($fields as $name => $field) {
|
2019-08-16 11:07:19 +00:00
|
|
|
if (!isset($field["privileges"][$update ? "update" : "insert"]) || $adminer->fieldName($field) == "" || $field["generated"]) {
|
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
|
|
|
}
|
2013-05-02 01:28:04 +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"];
|
2023-12-06 22:00:08 +00:00
|
|
|
if (isset($_POST["insert"]) && $_POST["insert"]) { // continue edit or insert
|
2010-04-15 14:59:40 +00:00
|
|
|
$location = ($update ? null : $_SERVER["REQUEST_URI"]);
|
2013-07-24 23:26:41 +00:00
|
|
|
} elseif (!preg_match('~^.+&select=.+$~', $location)) {
|
2009-08-29 13:57:50 +00:00
|
|
|
$location = ME . "select=" . urlencode($TABLE);
|
2009-08-03 13:37:29 +00:00
|
|
|
}
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2013-05-11 20:03:39 +00:00
|
|
|
$indexes = indexes($TABLE);
|
2023-12-06 22:00:08 +00:00
|
|
|
$unique_array = unique_array((isset($_GET["where"]) ? $_GET["where"] : []), $indexes);
|
2013-05-11 20:03:39 +00:00
|
|
|
$query_where = "\nWHERE $where";
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2009-12-14 11:37:59 +00:00
|
|
|
if (isset($_POST["delete"])) {
|
2013-07-05 16:04:06 +00:00
|
|
|
queries_redirect(
|
2013-05-11 20:03:39 +00:00
|
|
|
$location,
|
2013-07-05 16:04:06 +00:00
|
|
|
lang('Item has been deleted.'),
|
|
|
|
$driver->delete($TABLE, $query_where, !$unique_array)
|
2013-05-11 20:03:39 +00:00
|
|
|
);
|
2013-07-24 23:26:41 +00:00
|
|
|
|
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) {
|
2013-07-06 17:31:21 +00:00
|
|
|
$set[idf_escape($name)] = $val;
|
2009-12-14 11:37:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-24 23:26:41 +00:00
|
|
|
|
2009-12-14 11:37:59 +00:00
|
|
|
if ($update) {
|
2010-04-21 12:01:32 +00:00
|
|
|
if (!$set) {
|
|
|
|
redirect($location);
|
|
|
|
}
|
2013-07-05 22:32:15 +00:00
|
|
|
queries_redirect(
|
2013-05-11 20:03:39 +00:00
|
|
|
$location,
|
2013-07-05 22:32:15 +00:00
|
|
|
lang('Item has been updated.'),
|
|
|
|
$driver->update($TABLE, $set, $query_where, !$unique_array)
|
2013-05-11 20:03:39 +00:00
|
|
|
);
|
2013-06-29 19:41:35 +00:00
|
|
|
if (is_ajax()) {
|
|
|
|
page_headers();
|
|
|
|
page_messages($error);
|
|
|
|
exit;
|
|
|
|
}
|
2009-12-14 11:37:59 +00:00
|
|
|
} else {
|
2013-07-05 16:04:06 +00:00
|
|
|
$result = $driver->insert($TABLE, $set);
|
2010-05-12 16:07:46 +00:00
|
|
|
$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
|
|
|
|
2010-04-22 12:19:22 +00:00
|
|
|
$row = null;
|
2023-12-06 22:00:08 +00:00
|
|
|
if (isset($_POST["save"]) &&$_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"])) {
|
2012-09-09 05:56:34 +00:00
|
|
|
$as = convert_field($field);
|
2023-12-06 22:00:08 +00:00
|
|
|
if (isset($_POST["clone"]) && $_POST["clone"] && isset($field["auto_increment"]) && $field["auto_increment"]) {
|
2012-09-09 05:56:34 +00:00
|
|
|
$as = "''";
|
|
|
|
}
|
2013-07-24 23:26:41 +00:00
|
|
|
if ($jush == "sql" && preg_match("~enum|set~", $field["type"])) {
|
2012-09-09 05:56:34 +00:00
|
|
|
$as = "1*" . idf_escape($name);
|
|
|
|
}
|
|
|
|
$select[] = ($as ? "$as AS " : "") . idf_escape($name);
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-09 13:23:54 +00:00
|
|
|
$row = array();
|
2013-07-06 17:31:21 +00:00
|
|
|
if (!support("table")) {
|
|
|
|
$select = array("*");
|
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
if ($select) {
|
2014-01-15 16:23:26 +00:00
|
|
|
$result = $driver->select($TABLE, $select, array($where), $select, array(), (isset($_GET["select"]) ? 2 : 1));
|
2018-01-24 16:31:53 +00:00
|
|
|
if (!$result) {
|
|
|
|
$error = error();
|
|
|
|
} else {
|
|
|
|
$row = $result->fetch_assoc();
|
|
|
|
if (!$row) { // MySQLi returns null
|
|
|
|
$row = false;
|
|
|
|
}
|
2014-01-14 05:24:55 +00:00
|
|
|
}
|
2013-08-08 23:01:29 +00:00
|
|
|
if (isset($_GET["select"]) && (!$row || $result->fetch_assoc())) { // $result->num_rows != 1 isn't available in all drivers
|
|
|
|
$row = null;
|
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
}
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
2011-08-01 19:50:57 +00:00
|
|
|
|
2013-07-06 17:31:21 +00:00
|
|
|
if (!support("table") && !$fields) {
|
|
|
|
if (!$where) { // insert
|
2014-01-15 16:23:26 +00:00
|
|
|
$result = $driver->select($TABLE, array("*"), $where, array("*"));
|
2014-01-12 01:27:04 +00:00
|
|
|
$row = ($result ? $result->fetch_assoc() : false);
|
2014-01-11 23:16:26 +00:00
|
|
|
if (!$row) {
|
2014-01-12 01:27:04 +00:00
|
|
|
$row = array($driver->primary => "");
|
2014-01-11 23:16:26 +00:00
|
|
|
}
|
2013-07-06 17:31:21 +00:00
|
|
|
}
|
|
|
|
if ($row) {
|
|
|
|
foreach ($row as $key => $val) {
|
2013-07-07 05:22:13 +00:00
|
|
|
if (!$where) {
|
2013-07-06 17:31:21 +00:00
|
|
|
$row[$key] = null;
|
|
|
|
}
|
2014-01-12 01:27:04 +00:00
|
|
|
$fields[$key] = array("field" => $key, "null" => ($key != $driver->primary), "auto_increment" => ($key == $driver->primary));
|
2013-07-06 17:31:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-25 07:59:12 +00:00
|
|
|
edit_form($TABLE, $fields, $row, $update);
|