"; //
for easy styling
echo html_select("limit", array("", "30", "100"), $limit);
echo "
\n";
}
function selectLengthPrint($text_length) {
}
function selectActionPrint() {
echo "
\n";
}
function selectEmailPrint($emailFields, $columns) {
if ($emailFields) {
echo '
\n";
}
}
function selectColumnsProcess($columns, $indexes) {
return array(array(), array());
}
function selectSearchProcess($fields, $indexes) {
$return = array();
foreach ((array) $_GET["where"] as $key => $where) {
$col = $where["col"];
$op = $where["op"];
$val = $where["val"];
if (($key < 0 ? "" : $col) . $val != "") {
$conds = array();
foreach (($col != "" ? array($col => $fields[$col]) : $fields) as $name => $field) {
if ($col != "" || is_numeric($val) || !ereg('int|float|double|decimal', $field["type"])) {
if ($col != "" && $field["type"] == "enum") {
$conds[] = (in_array(0, $val) ? idf_escape($name) . " IS NULL OR " : "") . idf_escape($name) . " IN (" . implode(", ", array_map('intval', $val)) . ")";
} else {
$text_type = ereg('char|text|enum|set', $field["type"]);
$value = $this->processInput($field, (!$op && $text_type && ereg('^[^%]+$', $val) ? "%$val%" : $val));
$conds[] = idf_escape($name) . ($value == "NULL" ? " IS" . ($op == ">=" ? " NOT" : "") . " $value"
: (in_array($op, $this->operators) || $op == "=" ? " $op $value"
: ($text_type ? " LIKE $value"
: " IN (" . str_replace(",", "', '", $value) . ")"
))); //! can issue "Illegal mix of collations" for columns in other character sets - solve by CONVERT($name using utf8)
}
}
}
$return[] = ($conds ? "(" . implode(" OR ", $conds) . ")" : "0");
}
}
return $return;
}
function selectOrderProcess($fields, $indexes) {
if ($_GET["order"]) {
return array(idf_escape($_GET["order"][0]) . (isset($_GET["desc"][0]) ? " DESC" : ""));
}
$index_order = $_GET["index_order"];
foreach (($index_order != "" ? array($indexes[$index_order]) : $indexes) as $index) {
if ($index_order != "" || $index["type"] == "INDEX") {
$desc = false;
foreach ($index["columns"] as $val) {
if (ereg('date|timestamp', $fields[$val]["type"])) {
$desc = true;
break;
}
}
$return = array();
foreach ($index["columns"] as $val) {
$return[] = idf_escape($val) . ($desc ? " DESC" : "");
}
return $return;
}
}
return array();
}
function selectLimitProcess() {
return (isset($_GET["limit"]) ? $_GET["limit"] : "30");
}
function selectLengthProcess() {
return "100";
}
function selectEmailProcess($where, $foreignKeys) {
if ($_POST["email_append"]) {
return true;
}
if ($_POST["email"]) {
$sent = 0;
if ($_POST["all"] || $_POST["check"]) {
$field = idf_escape($_POST["email_field"]);
$subject = $_POST["email_subject"];
$message = $_POST["email_message"];
preg_match_all('~\\{\\$([a-z0-9_]+)\\}~i', "$subject.$message", $matches); // allows {$name} in subject or message
$rows = get_rows("SELECT DISTINCT $field" . ($matches[1] ? ", " . implode(", ", array_map('idf_escape', array_unique($matches[1]))) : "") . " FROM " . idf_escape($_GET["select"])
. " WHERE $field IS NOT NULL AND $field != ''"
. ($where ? " AND " . implode(" AND ", $where) : "")
. ($_POST["all"] ? "" : " AND ((" . implode(") OR (", array_map('where_check', (array) $_POST["check"])) . "))")
);
$fields = fields($_GET["select"]);
foreach ($this->rowDescriptions($rows, $foreignKeys) as $row) {
$replace = array('{\\' => '{'); // allow literal {$name}
foreach ($matches[1] as $val) {
$replace['{$' . "$val}"] = $this->editVal($row[$val], $fields[$val]);
}
$email = $row[$_POST["email_field"]];
if (is_mail($email) && send_mail($email, strtr($subject, $replace), strtr($message, $replace), $_POST["email_from"], $_FILES["email_files"])) {
$sent++;
}
}
}
cookie("adminer_email", $_POST["email_from"]);
redirect(remove_from_uri(), lang('%d e-mail(s) have been sent.', $sent));
}
return false;
}
function messageQuery($query) {
return "";
}
function editFunctions($field) {
$return = array();
if ($field["null"] && ereg('blob', $field["type"])) {
$return["NULL"] = lang('empty');
}
$return[""] = ($field["null"] || $field["auto_increment"] || ereg("(tinyint|bit)\\(1\\)", $field["full_type"]) ? "" : "*");
//! respect driver
if (ereg('date|time', $field["type"])) {
$return["now"] = lang('now');
}
if (eregi('_(md5|sha1)$', $field["field"], $match)) {
$return[] = strtolower($match[1]);
}
return $return;
}
function editInput($table, $field, $attrs, $value) {
if ($field["type"] == "enum") {
return (isset($_GET["select"]) ? "
" : "")
. enum_input("radio", $attrs, $field, ($value || isset($_GET["select"]) ? $value : 0), ($field["null"] ? "" : null))
;
}
$options = $this->_foreignKeyOptions($table, $field["field"]);
if ($options) {
return "
";
}
if (ereg("(tinyint|bit)\\(1\\)", $field["full_type"])) { // bool
return '
";
}
if (ereg('date|timestamp', $field["type"])) {
return "
(" . lang('[yyyy]-mm-dd') . ")"; //! maxlength
}
if (eregi('_(md5|sha1)$', $field["field"])) {
return "
";
}
return '';
}
function processInput($field, $value, $function = "") {
if ($function == "now") {
return "$function()";
}
$return = $value;
if (ereg('date|timestamp', $field["type"]) && preg_match('(^' . str_replace('\\$1', '(?P
\\d*)', preg_replace('~(\\\\\\$([2-6]))~', '(?P\\d{1,2})', preg_quote(lang('$1-$3-$5')))) . '(.*))', $value, $match)) {
$return = ($match["p1"] != "" ? $match["p1"] : ($match["p2"] != "" ? ($match["p2"] < 70 ? 20 : 19) . $match["p2"] : gmdate("Y"))) . "-$match[p3]$match[p4]-$match[p5]$match[p6]" . end($match);
}
$return = ($field["type"] == "bit" && ereg('^[0-9]+$', $value) ? $return : q($return));
if (!ereg('char|text', $field["type"]) && !ereg("(tinyint|bit)\\(1\\)", $field["full_type"]) && $value == "") {
$return = "NULL";
} elseif (ereg('^(md5|sha1)$', $function)) {
$return = "$function($return)";
}
if (ereg("binary", $field["type"])) {
$return = "unhex($return)";
}
return $return;
}
function dumpOutput() {
return array();
}
function dumpFormat() {
return array('csv' => 'CSV,', 'csv;' => 'CSV;', 'tsv' => 'TSV');
}
function dumpTable() {
echo "\xef\xbb\xbf"; // UTF-8 byte order mark
}
function dumpData($table, $style, $query) {
global $connection;
$result = $connection->query($query, 1); // 1 - MYSQLI_USE_RESULT
if ($result) {
while ($row = $result->fetch_assoc()) {
dump_csv($row);
}
}
}
function dumpHeaders($identifier) {
$filename = ($identifier != "" ? friendly_url($identifier) : "dump");
$ext = "csv";
header("Content-Type: text/csv; charset=utf-8");
header("Content-Disposition: attachment; filename=$filename.$ext");
session_write_close();
return $ext;
}
function homepage() {
return true;
}
function navigation($missing) {
global $VERSION, $token;
?>
$password) {
if (isset($password)) {
if ($first) {
echo "\n";
$first = false;
}
echo "" . ($username != "" ? h($username) : "" . lang('empty') . "") . "
\n";
}
}
} else {
?>
" . lang('No tables.') . "\n";
} else {
$this->tablesPrint($table_status);
}
}
}
}
function tablesPrint($tables) {
echo "\n";
foreach ($tables as $row) {
$name = $this->tableName($row);
if (isset($row["Engine"]) && $name != "") { // ignore views and tables without name
echo "$name
\n";
}
}
}
function _foreignKeyOptions($table, $column) {
$foreignKeys = column_foreign_keys($table);
foreach ((array) $foreignKeys[$column] as $foreignKey) {
if (count($foreignKey["source"]) == 1) {
$id = idf_escape($foreignKey["target"][0]);
$name = $this->rowDescription($foreignKey["table"]);
if ($name != "") {
$return = &$this->_values[$foreignKey["table"]];
if (!isset($return)) {
$table_status = table_status($foreignKey["table"]);
$return = ($table_status["Rows"] > 1000 ? array() : array("" => "") + get_key_vals("SELECT $id, $name FROM " . idf_escape($foreignKey["table"]) . " ORDER BY 2"));
}
return $return;
}
}
}
}
}
$adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer);