/** Execute query and redirect if successful * @param string * @param string * @param string * @param bool * @param bool * @param bool * @return bool */ function query_adminer_redirect($query, $location, $message, $redirect = true, $execute = true, $failed = false, $time = "") { global $connection, $error, $adminer; if ($execute) { $start = microtime(true); $failed = !$connection->query($query); $time = format_time($start); } $sql = ""; if ($query) { // filter query via plugin fct. $query = AdminerForWP::array_map_recursive('stripslashes', $query); $sql = $adminer->messageQuery($query, $time); } if ($failed) { $error = error() . $sql; return false; } if ($redirect) { adminer_redirect($location, $message . $sql); } return true; }
/** * Deeper array_map() * * @param string $callback Callback function to map * @param array $array Array to map * @source http://www.sitepoint.com/blogs/2005/03/02/magic-quotes-headaches/ * @return array */ static function array_map_recursive($callback, $array) { $r = array(); if (is_array($array)) { foreach ($array as $k => $v) { $r[$k] = is_scalar($v) ? $callback($v) : AdminerForWP::array_map_recursive($callback, $v); } } return $r; }
echo "<p class='error'>" . lang('Error in query') . ": " . implode("", $errors) . "\n"; } //! MS SQL - SET SHOWPLAN_ALL OFF } else { echo "<p class='error'>" . upload_error($query) . "\n"; } } ?> <form action="" method="post" enctype="multipart/form-data" id="form"> <p><?php $_GET = AdminerForWP::array_map_recursive('stripslashes_deep', $_GET); $q = $_GET["sql"]; // overwrite $q from if ($_POST) to save memory if ($_POST) { $_POST = AdminerForWP::array_map_recursive('stripslashes_deep', $_POST); $q = $_POST["query"]; } elseif ($_GET["history"] == "all") { $q = $history; } elseif ($_GET["history"] != "") { $q = $history[$_GET["history"]]; } textarea("query", $q, 20); echo $_POST ? "" : "<script type='text/javascript'>document.getElementsByTagName('textarea')[0].focus();</script>\n"; echo "<p>" . (ini_bool("file_uploads") ? lang('File upload') . ': <input type="file" name="sql_file"' . ($_FILES && $_FILES["sql_file"]["error"] != 4 ? '' : ' onchange="this.form[\'only_errors\'].checked = true;"') . '> (< ' . ini_get("upload_max_filesize") . 'B)' : lang('File uploads are disabled.')); ?> <p> <input type="submit" value="<?php echo lang('Execute'); ?> " title="Ctrl+Enter">
/** Print results of search in all tables * @uses $_GET["where"][0] * @uses $_POST["tables"] * @return null */ function search_tables() { global $adminer, $connection; $_POST = AdminerForWP::array_map_recursive('stripslashes_deep', $_POST); $_GET["where"][0]["op"] = "LIKE %%"; $_GET["where"][0]["val"] = $_POST["query"]; $found = false; foreach (table_status() as $table => $table_status) { $name = $adminer->tableName($table_status); if (isset($table_status["Engine"]) && $name != "" && (!$_POST["tables"] || in_array($table, $_POST["tables"]))) { $result = $connection->query("SELECT" . limit("1 FROM " . table($table), " WHERE " . implode(" AND ", $adminer->selectSearchProcess(fields($table), array())), 1)); if ($result->fetch_row()) { if (!$found) { echo "<ul>\n"; $found = true; } echo "<li><a href='" . h(ME . "select=" . urlencode($table) . "&where[0][op]=" . urlencode($_GET["where"][0]["op"]) . "&where[0][val]=" . urlencode($_GET["where"][0]["val"])) . "'>{$name}</a>\n"; } } } echo ($found ? "</ul>" : "<p class='message'>" . lang('No tables.')) . "\n"; }