$field) { if (isset($_GET["default"]) ? $field["auto_increment"] || preg_match('~text|blob~', $field["type"]) : !isset($field["privileges"][$update ? "update" : "insert"])) { unset($fields[$name]); } } if ($_POST && !$error && !isset($_GET["select"])) { $location = ($_POST["insert"] ? $_SERVER["REQUEST_URI"] : $SELF . (isset($_GET["default"]) ? "table=" : "select=") . urlencode($_GET["edit"])); if (isset($_POST["delete"])) { query_redirect("DELETE FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1", $location, lang('Item has been deleted.')); } else { $set = array(); foreach ($fields as $name => $field) { $val = process_input($name, $field); if (!isset($_GET["default"])) { if ($val !== false || !$update) { $set[] = idf_escape($name) . " = " . ($val !== false ? $val : "''"); } } elseif ($val !== false) { if ($field["type"] == "timestamp") { $set[] = " MODIFY " . idf_escape($name) . " timestamp" . ($field["null"] ? " NULL" : "") . " DEFAULT $val" . ($_POST["on_update"][bracket_escape($name)] ? " ON UPDATE CURRENT_TIMESTAMP" : ""); } else { $set[] = " ALTER " . idf_escape($name) . ($val == ($field["null"] || $field["type"] == "enum" ? "NULL" : "''") ? " DROP DEFAULT" : " SET DEFAULT $val"); } } } if (!$set) { redirect($location); } if (isset($_GET["default"])) { query_redirect("ALTER TABLE " . idf_escape($_GET["edit"]) . implode(",", $set), $location, lang('Default values has been set.')); } elseif ($update) { query_redirect("UPDATE " . idf_escape($_GET["edit"]) . " SET " . implode(", ", $set) . " WHERE " . implode(" AND ", $where) . " LIMIT 1", $location, lang('Item has been updated.')); } else { query_redirect("INSERT INTO " . idf_escape($_GET["edit"]) . " SET " . implode(", ", $set), $location, lang('Item has been inserted.')); } } } 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"]); unset($row); if ($_POST) { $row = (array) $_POST["fields"]; } elseif ($where) { $select = array(); foreach ($fields as $name => $field) { if (isset($field["privileges"]["select"]) && (!$_GET["clone"] || !$field["auto_increment"])) { $select[] = ($field["type"] == "enum" || $field["type"] == "set" ? "1*" . idf_escape($name) . " AS " : "") . idf_escape($name); } } $row = array(); if ($select) { $result = $mysql->query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1"); $row = $result->fetch_assoc(); $result->free(); } } ?>