':1', ']' => ':2', '[' => ':3'); return strtr($idf, ($back ? array_flip($trans) : $trans)); } function optionlist($options, $selected = array(), $not_vals = false) { $return = ""; foreach ($options as $k => $v) { if (is_array($v)) { $return .= ''; } } return $return; } function fields($table) { global $mysql; $return = array(); $result = $mysql->query("SHOW FULL COLUMNS FROM " . idf_escape($table)); if ($result) { while ($row = $result->fetch_assoc()) { preg_match('~^([^(]+)(?:\\((.+)\\))?( unsigned)?( zerofill)?$~', $row["Type"], $match); $return[$row["Field"]] = array( "field" => $row["Field"], "type" => $match[1], "length" => $match[2], "unsigned" => ltrim($match[3] . $match[4]), "default" => $row["Default"], "null" => ($row["Null"] == "YES"), "auto_increment" => ($row["Extra"] == "auto_increment"), "collation" => $row["Collation"], "privileges" => array_flip(explode(",", $row["Privileges"])), "comment" => $row["Comment"], ); } $result->free(); } return $return; } function indexes($table) { global $mysql; $return = array(); $result = $mysql->query("SHOW INDEX FROM " . idf_escape($table)); while ($row = $result->fetch_assoc()) { $return[$row["Key_name"]]["type"] = ($row["Key_name"] == "PRIMARY" ? "PRIMARY" : ($row["Index_type"] == "FULLTEXT" ? "FULLTEXT" : ($row["Non_unique"] ? "INDEX" : "UNIQUE"))); $return[$row["Key_name"]]["columns"][$row["Seq_in_index"]] = $row["Column_name"]; } $result->free(); return $return; } function foreign_keys($table) { global $mysql; static $pattern = '~`((?:[^`]*|``)+)`~'; $return = array(); $result = $mysql->query("SHOW CREATE TABLE " . idf_escape($table)); if ($result) { $create_table = $mysql->result($result, 0, 1); $result->free(); preg_match_all('~FOREIGN KEY \\((.+)\\) REFERENCES (?:`(.+)`\\.)?`(.+)` \\((.+)\\)~', $create_table, $matches, PREG_SET_ORDER); foreach ($matches as $match) { preg_match_all($pattern, $match[1], $source); preg_match_all($pattern, $match[4], $target); $return[] = array(idf_unescape($match[2]), idf_unescape($match[3]), array_map('idf_unescape', $source[1]), array_map('idf_unescape', $target[1])); } } return $return; } function unique_idf($row, $indexes) { foreach ($indexes as $index) { if ($index["type"] == "PRIMARY" || $index["type"] == "UNIQUE") { $return = array(); foreach ($index["columns"] as $key) { if (!isset($row[$key])) { continue 2; } $return[] = urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($row[$key]); } return $return; } } $return = array(); foreach ($row as $key => $val) { $return[] = (isset($val) ? urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($val) : "null%5B%5D=" . urlencode($key)); } return $return; } function where() { global $mysql; $return = array(); foreach ((array) $_GET["where"] as $key => $val) { $return[] = idf_escape(bracket_escape($key, "back")) . " = BINARY '" . $mysql->real_escape_string($val) . "'"; //! enum and set } foreach ((array) $_GET["null"] as $key) { $return[] = idf_escape(bracket_escape($key, "back")) . " IS NULL"; } return $return; } function collations() { global $mysql; $return = array(); $result = $mysql->query("SHOW COLLATION"); while ($row = $result->fetch_assoc()) { $return[$row["Charset"]][] = $row["Collation"]; } $result->free(); return $return; } function engines() { global $mysql; $return = array(); $result = $mysql->query("SHOW ENGINES"); while ($row = $result->fetch_assoc()) { if ($row["Support"] == "YES" || $row["Support"] == "DEFAULT") { $return[] = $row["Engine"]; } } $result->free(); return $return; } function types() { return array( "tinyint" => 3, "smallint" => 5, "mediumint" => 8, "int" => 10, "bigint" => 20, "float" => 12, "double" => 21, "decimal" => 66, "date" => 10, "datetime" => 19, "timestamp" => 19, "time" => 10, "year" => 4, "char" => 255, "varchar" => 65535, "binary" => 255, "varbinary" => 65535, "tinytext" => 255, "text" => 65535, "mediumtext" => 16777215, "longtext" => 4294967295, "tinyblob" => 255, "blob" => 65535, "mediumblob" => 16777215, "longblob" => 4294967295, "enum" => 65535, "set" => 64, ); } function token() { return ($GLOBALS["TOKENS"][] = rand(1, 1e6)); } function token_delete() { if ($_POST["token"] && ($pos = array_search($_POST["token"], (array) $GLOBALS["TOKENS"])) !== false) { unset($GLOBALS["TOKENS"][$pos]); return true; } return false; } function redirect($location, $message = null) { if (isset($message)) { $_SESSION["message"] = $message; } token_delete(); if (strlen(SID)) { $location .= (strpos($location, "?") === false ? "?" : "&") . SID; } header("Location: " . (strlen($location) ? $location : ".")); exit; } function get_file($key) { if (isset($_POST["files"][$key])) { $length = strlen($_POST["files"][$key]); return ($length & $length < 4 ? intval($_POST["files"][$key]) : base64_decode($_POST["files"][$key])); } return (!$_FILES[$key] || $_FILES[$key]["error"] ? $_FILES[$key]["error"] : file_get_contents($_FILES[$key]["tmp_name"])); } function select($result) { if (!$result->num_rows) { echo "
\n"; } else { echo "" . htmlspecialchars($field->name) . " | "; } echo "
---|
$val | "; } echo "