">
\n"; echo checkbox("permanent", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n"; } /** Authorize the user * @param string * @param string * @return bool */ function login($login, $password) { return true; } /** Table caption used in navigation and headings * @param array result of SHOW TABLE STATUS * @return string */ function tableName($tableStatus) { return h($tableStatus["Name"]); } /** Field caption used in select and edit * @param array single field returned from fields() * @param int order of column in select * @return string */ function fieldName($field, $order = 0) { return '' . h($field["field"]) . ''; } /** Print links after select heading * @param array result of SHOW TABLE STATUS * @param string new item options, NULL for no new item * @return null */ function selectLinks($tableStatus, $set = "") { echo '

'; $links = array("select" => lang('Select data'), "table" => lang('Show structure')); if (is_view($tableStatus)) { $links["view"] = lang('Alter view'); } else { $links["create"] = lang('Alter table'); } if (isset($set)) { $links["edit"] = lang('New item'); } foreach ($links as $key => $val) { echo " " . bold($val, isset($_GET[$key])) . ""; } echo "\n"; } /** Find backward keys for table * @param string * @param string * @return array $return[$target_table]["keys"][$key_name][$target_column] = $source_column; $return[$target_table]["name"] = $this->tableName($target_table); */ function backwardKeys($table, $tableName) { return array(); } /** Print backward keys for row * @param array result of $this->backwardKeys() * @param array * @return null */ function backwardKeysPrint($backwardKeys, $row) { } /** Query printed in select before execution * @param string query to be executed * @return string */ function selectQuery($query) { global $jush; return "

>> " . h(str_replace("\n", " ", $query)) . " " . lang('Edit') . "\n"; } /** Description of a row in a table * @param string * @return string SQL expression, empty string for no description */ function rowDescription($table) { return ""; } /** Get descriptions of selected data * @param array all data to print * @param array * @return array */ function rowDescriptions($rows, $foreignKeys) { return $rows; } /** Value printed in select table * @param string HTML-escaped value to print * @param string link to foreign key * @param array single field returned from fields() * @return string */ function selectVal($val, $link, $field) { $return = ($val != "NULL" && ereg("^char|binary", $field["type"]) ? "$val" : $val); if (ereg('blob|bytea|raw|file', $field["type"]) && !is_utf8($val)) { $return = lang('%d byte(s)', strlen(html_entity_decode($val, ENT_QUOTES))); } return ($link ? "$return" : $return); } /** Value conversion used in select and edit * @param string * @param array single field returned from fields() * @return string */ function editVal($val, $field) { return (ereg("binary", $field["type"]) ? reset(unpack("H*", $val)) : $val); } /** Print columns box in select * @param array result of selectColumnsProcess() * @param array selectable columns * @return null */ function selectColumnsPrint($select, $columns) { global $functions, $grouping; print_fieldset("select", lang('Select'), $select); $i = 0; $fun_group = array(lang('Functions') => $functions, lang('Aggregation') => $grouping); foreach ($select as $key => $val) { $val = $_GET["columns"][$key]; echo "

" . html_select("columns[$i][fun]", array(-1 => "") + $fun_group, $val["fun"]); echo "()
\n"; $i++; } echo "
" . html_select("columns[$i][fun]", array(-1 => "") + $fun_group, "", "this.nextSibling.nextSibling.onchange();"); echo "()
\n"; echo "\n"; } /** Print search box in select * @param array result of selectSearchProcess() * @param array selectable columns * @param array * @return null */ function selectSearchPrint($where, $columns, $indexes) { print_fieldset("search", lang('Search'), $where); foreach ($indexes as $i => $index) { if ($index["type"] == "FULLTEXT") { echo "(" . implode(", ", array_map('h', $index["columns"])) . ") AGAINST"; echo " "; echo checkbox("boolean[$i]", 1, isset($_GET["boolean"][$i]), "BOOL"); echo "
\n"; } } $i = 0; foreach ((array) $_GET["where"] as $val) { if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) { echo "
"; echo html_select("where[$i][op]", $this->operators, $val["op"]); echo "
\n"; $i++; } } echo "
"; echo html_select("where[$i][op]", $this->operators); echo "
\n"; echo "\n"; } /** Print order box in select * @param array result of selectOrderProcess() * @param array selectable columns * @param array * @return null */ function selectOrderPrint($order, $columns, $indexes) { print_fieldset("sort", lang('Sort'), $order); $i = 0; foreach ((array) $_GET["order"] as $key => $val) { if (isset($columns[$val])) { echo "
"; echo checkbox("desc[$i]", 1, isset($_GET["desc"][$key]), lang('descending')) . "
\n"; $i++; } } echo "
"; echo checkbox("desc[$i]", 1, 0, lang('descending')) . "
\n"; echo "\n"; } /** Print limit box in select * @param string result of selectLimitProcess() * @return null */ function selectLimitPrint($limit) { echo "
" . lang('Limit') . "
"; //
for easy styling echo ""; echo "
\n"; } /** Print text length box in select * @param string result of selectLengthProcess() * @return null */ function selectLengthPrint($text_length) { if (isset($text_length)) { echo "
" . lang('Text length') . "
"; echo ''; echo "
\n"; } } /** Print action box in select * @return null */ function selectActionPrint() { echo "
" . lang('Action') . "
"; echo ""; echo "
\n"; } /** Print extra text in the end of a select form * @param array fields holding e-mails * @param array selectable columns * @return null */ function selectEmailPrint($emailFields, $columns) { } /** Process columns box in select * @param array selectable columns * @param array * @return array (array(select_expressions), array(group_expressions)) */ function selectColumnsProcess($columns, $indexes) { global $functions, $grouping; $select = array(); // select expressions, empty for * $group = array(); // expressions without aggregation - will be used for GROUP BY if an aggregation function is used foreach ((array) $_GET["columns"] as $key => $val) { if ($val["fun"] == "count" || (isset($columns[$val["col"]]) && (!$val["fun"] || in_array($val["fun"], $functions) || in_array($val["fun"], $grouping)))) { $select[$key] = apply_sql_function($val["fun"], (isset($columns[$val["col"]]) ? idf_escape($val["col"]) : "*")); if (!in_array($val["fun"], $grouping)) { $group[] = $select[$key]; } } } return array($select, $group); } /** Process search box in select * @param array * @param array * @return array expressions to join by AND */ function selectSearchProcess($fields, $indexes) { global $connection, $jush; $return = array(); foreach ($indexes as $i => $index) { if ($index["type"] == "FULLTEXT" && $_GET["fulltext"][$i] != "") { $return[] = "MATCH (" . implode(", ", array_map('idf_escape', $index["columns"])) . ") AGAINST (" . $connection->quote($_GET["fulltext"][$i]) . (isset($_GET["boolean"][$i]) ? " IN BOOLEAN MODE" : "") . ")"; } } foreach ((array) $_GET["where"] as $val) { if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) { $cond = " $val[op]"; if (ereg('IN$', $val["op"])) { $in = process_length($val["val"]); $cond .= " (" . ($in != "" ? $in : "NULL") . ")"; } elseif ($val["op"] == "LIKE %%") { $cond = " LIKE " . $this->processInput($fields[$val["col"]], "%$val[val]%"); } elseif (!ereg('NULL$', $val["op"])) { $cond .= " " . $this->processInput($fields[$val["col"]], $val["val"]); } if ($val["col"] != "") { $return[] = idf_escape($val["col"]) . $cond; } else { // find anywhere $cols = array(); foreach ($fields as $name => $field) { if (is_numeric($val["val"]) || !ereg('int|float|double|decimal', $field["type"])) { $name = idf_escape($name); $cols[] = ($jush == "sql" && ereg('char|text|enum|set', $field["type"]) && !ereg('^utf8', $field["collation"]) ? "CONVERT($name USING utf8)" : $name); } } $return[] = ($cols ? "(" . implode("$cond OR ", $cols) . "$cond)" : "0"); } } } return $return; } /** Process order box in select * @param array * @param array * @return array expressions to join by comma */ function selectOrderProcess($fields, $indexes) { $return = array(); foreach ((array) $_GET["order"] as $key => $val) { if (isset($fields[$val]) || preg_match('~^((COUNT\\(DISTINCT |[A-Z0-9_]+\\()(`(?:[^`]|``)+`|"(?:[^"]|"")+")\\)|COUNT\\(\\*\\))$~', $val)) { //! MS SQL uses [] $return[] = (isset($fields[$val]) ? idf_escape($val) : $val) . (isset($_GET["desc"][$key]) ? " DESC" : ""); } } return $return; } /** Process limit box in select * @return string expression to use in LIMIT, will be escaped */ function selectLimitProcess() { return (isset($_GET["limit"]) ? $_GET["limit"] : "30"); } /** Process length box in select * @return string number of characters to shorten texts, will be escaped */ function selectLengthProcess() { return (isset($_GET["text_length"]) ? $_GET["text_length"] : "100"); } /** Process extras in select form * @param array AND conditions * @param array * @return bool true if processed, false to process other parts of form */ function selectEmailProcess($where, $foreignKeys) { return false; } /** Query printed after execution in the message * @param string executed query * @return string */ function messageQuery($query) { global $jush; restart_session(); $id = "sql-" . count($_SESSION["messages"]); $history = &get_session("history"); $history[$_GET["db"]][] = (strlen($query) > 1e6 // not DB - reset in drop database ? ereg_replace('[\x80-\xFF]+$', '', substr($query, 0, 1e6)) . "\n..." // [\x80-\xFF] - valid UTF-8, \n - can end by one-line comment : $query ); //! respect $_GET["ns"] return " " . lang('SQL command') . "'; } /** Functions displayed in edit form * @param array single field from fields() * @return array */ function editFunctions($field) { global $edit_functions; $return = ($field["null"] ? "NULL/" : ""); foreach ($edit_functions as $key => $functions) { if (!$key || (!isset($_GET["call"]) && (isset($_GET["select"]) || where($_GET)))) { // relative functions foreach ($functions as $pattern => $val) { if (!$pattern || ereg($pattern, $field["type"])) { $return .= "/$val"; } } } } return explode("/", $return); } /** Get options to display edit field * @param string table name * @param array single field from fields() * @param string attributes to use inside the tag * @param string * @return string custom input field or empty string for default */ function editInput($table, $field, $attrs, $value) { if ($field["type"] == "enum") { return ($field["null"] ? " " : "") . "" ; } return ""; } /** Process sent input * @param array single field from fields() * @param string * @param string * @return string expression to use in a query */ function processInput($field, $value, $function = "") { global $connection; $name = $field["field"]; $return = $connection->quote($value); if (ereg('^(now|getdate|uuid)$', $function)) { $return = "$function()"; } elseif (ereg('^current_(date|timestamp)$', $function)) { $return = $function; } elseif (ereg('^([+-]|\\|\\|)$', $function)) { $return = idf_escape($name) . " $function $return"; } elseif (ereg('^[+-] interval$', $function)) { $return = idf_escape($name) . " $function " . (preg_match("~^([0-9]+|'[0-9.: -]') [A-Z_]+$~i", $value) ? $value : $return); } elseif (ereg('^(addtime|subtime|concat)$', $function)) { $return = "$function(" . idf_escape($name) . ", $return)"; } elseif (ereg('^(md5|sha1|password|encrypt|hex)$', $function)) { $return = "$function($return)"; } if (ereg("binary", $field["type"])) { $return = "unhex($return)"; } return $return; } /** Returns export output options * @param bool generate select (otherwise radio) * @param string * @return string */ function dumpOutput($select, $value = "") { $return = array('text' => lang('open'), 'file' => lang('save')); if (function_exists('gzencode')) { $return['gz'] = 'gzip'; } if (function_exists('bzcompress')) { $return['bz2'] = 'bzip2'; } // ZipArchive requires temporary file, ZIP can be created by gzcompress - see PEAR File_Archive return html_select("output", $return, $value, $select); } /** Returns export format options * @param bool generate select (otherwise radio) * @param string * @return string */ function dumpFormat($select, $value = "") { return html_select("format", array('sql' => 'SQL', 'csv' => 'CSV,', 'csv;' => 'CSV;'), $value, $select); } /** Prints navigation after Adminer title * @param string can be "auth" if there is no database connection or "db" if there is no database selected * @return null */ function navigation($missing) { global $VERSION, $connection, $token, $jush, $drivers; ?>

name(); ?>

$servers) { foreach ($servers as $server => $usernames) { foreach ($usernames as $username => $password) { if (isset($password)) { if ($first) { echo "

\n"; $first = false; } echo "($drivers[$driver]) " . h($username . ($server != "" ? "@$server" : "")) . "
\n"; } } } } } else { $databases = get_databases(); ?>

">

"(" . lang('database') . ")") + $databases, DB, "this.form.submit();") : ''); ?> > select_db(DB)) { if (support("scheme")) { echo "
" . html_select("ns", array("" => "(" . lang('schema') . ")") + schemas(), $_GET["ns"], "this.form.submit();"); if ($_GET["ns"] != "") { set_schema($_GET["ns"]); } } if ($_GET["ns"] !== "") { $tables = tables_list(); if (!$tables) { echo "

" . lang('No tables.') . "\n"; } else { $this->tablesPrint($tables); $links = array(); foreach ($tables as $table => $type) { $links[] = preg_quote($table, '/'); } echo "\n"; } echo '

' . bold(lang('Create new table'), $_GET["create"] === "") . "\n"; } } echo (isset($_GET["sql"]) ? '' : (isset($_GET["schema"]) ? '' : (isset($_GET["dump"]) ? '' : ""))); echo "

\n"; } } /** Prints table list in menu * @param array * @return null */ function tablesPrint($tables) { echo "

\n"; foreach ($tables as $table => $type) { echo '' . bold(lang('select'), $_GET["select"] == $table) . ' '; echo '' . bold($this->tableName(array("Name" => $table)), $_GET["table"] == $table) . "
\n"; //! Adminer::tableName may work with full table status } } } $adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer); if (!isset($adminer->operators)) { $adminer->operators = $operators; }