':1', ']' => ':2', '[' => ':3');
return strtr($idf, ($back ? array_flip($trans) : $trans));
}
function optionlist($options, $selected = null) {
$return = "";
foreach ($options as $k => $v) {
if (is_array($v)) {
$return .= '';
}
}
return $return;
}
function get_vals($query, $column = 0) {
global $dbh;
$return = array();
$result = $dbh->query($query);
if ($result) {
while ($row = $result->fetch_row()) {
$return[] = $row[$column];
}
$result->free();
}
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])) { // NULL is ambiguous
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($where) {
global $dbh;
$return = array();
foreach ((array) $where["where"] as $key => $val) {
$key = bracket_escape($key, "back");
$return[] = (preg_match('~^[A-Z0-9_]+\\(`(?:[^`]+|``)+`\\)$~', $key) ? $key : idf_escape($key)) . " = BINARY " . $dbh->quote($val); //! enum and set, columns looking like functions
}
foreach ((array) $where["null"] as $key) {
$key = bracket_escape($key, "back");
$return[] = (preg_match('~^[A-Z0-9_]+\\(`(?:[^`]+|``)+`\\)$~', $key) ? $key : idf_escape($key)) . " IS NULL";
}
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));
}
function redirect($location, $message = null) {
if (isset($message)) {
$_SESSION["messages"][] = $message;
}
if (strlen(SID)) {
// append SID if session cookies are disabled
$location .= (strpos($location, "?") === false ? "?" : "&") . SID;
}
header("Location: " . (strlen($location) ? $location : "."));
exit;
}
function query_redirect($query, $location, $message, $redirect = true, $execute = true, $failed = false) {
global $dbh, $error, $SELF;
$id = "sql-" . count($_SESSION["messages"]);
$sql = "";
if ($query) {
$sql = " " . lang('SQL command') . "" . htmlspecialchars($query) . '
' . lang('Edit') . '';
$_SESSION["history"][$_GET["server"]][$_GET["db"]][] = $query;
}
if ($execute) {
$failed = !$dbh->query($query);
}
if ($failed) {
$error = htmlspecialchars($dbh->error) . $sql;
return false;
}
if ($redirect) {
redirect($location, $message . $sql);
}
return true;
}
function queries($query = null) {
global $dbh;
static $queries = array();
if (!isset($query)) {
// return executed queries without parameter
return implode(";\n", $queries);
}
$queries[] = $query;
return $dbh->query($query);
}
function remove_from_uri($param = "") {
$param = "($param|" . session_name() . ")";
return preg_replace("~\\?$param=[^&]*&~", '?', preg_replace("~\\?$param=[^&]*\$|&$param=[^&]*~", '', $_SERVER["REQUEST_URI"]));
}
function print_pagination($page) {
echo " " . ($page == $_GET["page"] ? $page + 1 : '' . ($page + 1) . "");
}
function get_file($key) {
// returns int for error, string otherwise
if (isset($_POST["files"][$key])) {
// get the file from hidden field if the user was logged out
$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 odd($s = ' class="odd"') {
static $i = 0;
if (!$s) { // reset counter
$i = -1;
}
return ($i++ % 2 ? $s : '');
}
function select($result, $dbh2 = null) {
global $SELF;
if (!$result->num_rows) {
echo "
" . htmlspecialchars($field->name) . " | "; } echo "
---|
$val | "; } echo "