2007-07-02 05:51:26 +00:00
|
|
|
<?php
|
2009-07-27 11:25:37 +00:00
|
|
|
function get_dbh() {
|
|
|
|
// can be used in customization, $dbh is minified
|
|
|
|
global $dbh;
|
|
|
|
return $dbh;
|
|
|
|
}
|
|
|
|
|
2007-07-02 05:51:26 +00:00
|
|
|
function idf_escape($idf) {
|
|
|
|
return "`" . str_replace("`", "``", $idf) . "`";
|
|
|
|
}
|
|
|
|
|
|
|
|
function idf_unescape($idf) {
|
|
|
|
return str_replace("``", "`", $idf);
|
|
|
|
}
|
|
|
|
|
|
|
|
function bracket_escape($idf, $back = false) {
|
2009-06-21 23:20:32 +00:00
|
|
|
// escape brackets inside name="x[]"
|
2007-07-09 14:45:11 +00:00
|
|
|
static $trans = array(':' => ':1', ']' => ':2', '[' => ':3');
|
2007-07-02 05:51:26 +00:00
|
|
|
return strtr($idf, ($back ? array_flip($trans) : $trans));
|
|
|
|
}
|
|
|
|
|
2009-07-28 16:20:50 +00:00
|
|
|
function h($string) {
|
|
|
|
return htmlspecialchars($string, ENT_QUOTES);
|
|
|
|
}
|
|
|
|
|
2009-07-23 14:42:38 +00:00
|
|
|
function optionlist($options, $selected = null, $use_keys = false) {
|
2007-07-02 05:51:26 +00:00
|
|
|
$return = "";
|
|
|
|
foreach ($options as $k => $v) {
|
|
|
|
if (is_array($v)) {
|
2009-07-28 16:20:50 +00:00
|
|
|
$return .= '<optgroup label="' . h($k) . '">';
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
2009-07-02 22:37:10 +00:00
|
|
|
foreach ((is_array($v) ? $v : array($k => $v)) as $key => $val) {
|
2009-07-28 16:28:47 +00:00
|
|
|
$return .= '<option' . ($use_keys || is_string($key) ? ' value="' . h($key) . '"' : '') . (($use_keys || is_string($key) ? (string) $key : $val) === $selected ? ' selected' : '') . '>' . h($val);
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
|
|
|
if (is_array($v)) {
|
|
|
|
$return .= '</optgroup>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2009-05-21 11:05:22 +00:00
|
|
|
function get_vals($query, $column = 0) {
|
2009-05-08 05:23:03 +00:00
|
|
|
global $dbh;
|
2007-07-11 22:04:08 +00:00
|
|
|
$return = array();
|
2009-05-08 05:23:03 +00:00
|
|
|
$result = $dbh->query($query);
|
2008-09-30 12:00:18 +00:00
|
|
|
if ($result) {
|
|
|
|
while ($row = $result->fetch_row()) {
|
2009-05-21 11:05:22 +00:00
|
|
|
$return[] = $row[$column];
|
2008-09-30 12:00:18 +00:00
|
|
|
}
|
|
|
|
$result->free();
|
2007-07-11 22:04:08 +00:00
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2007-07-02 05:51:26 +00:00
|
|
|
function unique_idf($row, $indexes) {
|
2007-07-05 04:39:15 +00:00
|
|
|
foreach ($indexes as $index) {
|
|
|
|
if ($index["type"] == "PRIMARY" || $index["type"] == "UNIQUE") {
|
|
|
|
$return = array();
|
|
|
|
foreach ($index["columns"] as $key) {
|
2009-06-21 23:20:32 +00:00
|
|
|
if (!isset($row[$key])) { // NULL is ambiguous
|
2007-07-05 04:39:15 +00:00
|
|
|
continue 2;
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
2007-07-09 06:12:22 +00:00
|
|
|
$return[] = urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($row[$key]);
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
2007-07-05 04:39:15 +00:00
|
|
|
return $return;
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$return = array();
|
|
|
|
foreach ($row as $key => $val) {
|
2009-07-28 12:56:38 +00:00
|
|
|
if (!preg_match('~^(COUNT\\((\\*|(DISTINCT )?`(?:[^`]+|``)+`)\\)|(AVG|GROUP_CONCAT|MAX|MIN|SUM)\\(`(?:[^`]+|``)+`\\))$~', $key)) { //! columns looking like functions
|
|
|
|
$return[] = (isset($val) ? urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($val) : "null%5B%5D=" . urlencode($key));
|
|
|
|
}
|
2007-07-09 06:12:22 +00:00
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
2008-08-08 11:56:37 +00:00
|
|
|
function where($where) {
|
2009-05-08 05:23:03 +00:00
|
|
|
global $dbh;
|
2007-07-09 06:12:22 +00:00
|
|
|
$return = array();
|
2008-01-08 14:02:55 +00:00
|
|
|
foreach ((array) $where["where"] as $key => $val) {
|
2008-08-08 12:26:56 +00:00
|
|
|
$key = bracket_escape($key, "back");
|
2009-06-22 00:53:51 +00:00
|
|
|
$return[] = (preg_match('~^[A-Z0-9_]+\\(`(?:[^`]+|``)+`\\)$~', $key) ? $key : idf_escape($key)) . " = BINARY " . $dbh->quote($val); //! enum and set, columns looking like functions
|
2007-07-09 06:12:22 +00:00
|
|
|
}
|
2008-01-08 14:02:55 +00:00
|
|
|
foreach ((array) $where["null"] as $key) {
|
2008-08-08 12:26:56 +00:00
|
|
|
$key = bracket_escape($key, "back");
|
|
|
|
$return[] = (preg_match('~^[A-Z0-9_]+\\(`(?:[^`]+|``)+`\\)$~', $key) ? $key : idf_escape($key)) . " IS NULL";
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
2009-07-11 19:45:57 +00:00
|
|
|
return implode(" AND ", $return);
|
2007-07-02 05:51:26 +00:00
|
|
|
}
|
|
|
|
|
2009-06-07 23:53:51 +00:00
|
|
|
function where_check($val) {
|
|
|
|
parse_str($val, $check);
|
|
|
|
return where($check);
|
|
|
|
}
|
|
|
|
|
2009-07-15 14:56:27 +00:00
|
|
|
function where_link($i, $column, $value) {
|
|
|
|
return "&where%5B$i%5D%5Bcol%5D=" . urlencode($column) . "&where%5B$i%5D%5Bop%5D=%3D&where%5B$i%5D%5Bval%5D=" . urlencode($value);
|
|
|
|
}
|
|
|
|
|
2007-07-09 06:12:22 +00:00
|
|
|
function redirect($location, $message = null) {
|
|
|
|
if (isset($message)) {
|
2008-04-18 12:01:53 +00:00
|
|
|
$_SESSION["messages"][] = $message;
|
2007-07-09 06:12:22 +00:00
|
|
|
}
|
|
|
|
if (strlen(SID)) {
|
2009-06-21 23:20:32 +00:00
|
|
|
// append SID if session cookies are disabled
|
2007-07-09 06:12:22 +00:00
|
|
|
$location .= (strpos($location, "?") === false ? "?" : "&") . SID;
|
|
|
|
}
|
|
|
|
header("Location: " . (strlen($location) ? $location : "."));
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2008-09-03 13:55:43 +00:00
|
|
|
function query_redirect($query, $location, $message, $redirect = true, $execute = true, $failed = false) {
|
2009-07-30 08:12:54 +00:00
|
|
|
global $dbh, $error, $adminer;
|
2009-06-04 14:00:23 +00:00
|
|
|
$sql = "";
|
|
|
|
if ($query) {
|
2009-07-27 11:25:37 +00:00
|
|
|
$sql = $adminer->messageQuery($query);
|
2009-06-04 14:00:23 +00:00
|
|
|
}
|
2008-09-03 13:55:43 +00:00
|
|
|
if ($execute) {
|
2009-05-08 05:23:03 +00:00
|
|
|
$failed = !$dbh->query($query);
|
2008-09-03 13:55:43 +00:00
|
|
|
}
|
|
|
|
if ($failed) {
|
2009-07-28 16:20:50 +00:00
|
|
|
$error = h($dbh->error) . $sql;
|
2008-09-02 12:39:04 +00:00
|
|
|
return false;
|
2008-09-02 08:42:14 +00:00
|
|
|
}
|
2008-09-02 12:39:04 +00:00
|
|
|
if ($redirect) {
|
|
|
|
redirect($location, $message . $sql);
|
|
|
|
}
|
|
|
|
return true;
|
2008-09-02 08:42:14 +00:00
|
|
|
}
|
|
|
|
|
2008-09-03 13:55:43 +00:00
|
|
|
function queries($query = null) {
|
2009-05-08 05:23:03 +00:00
|
|
|
global $dbh;
|
2008-09-03 13:55:43 +00:00
|
|
|
static $queries = array();
|
|
|
|
if (!isset($query)) {
|
2009-06-21 23:20:32 +00:00
|
|
|
// return executed queries without parameter
|
2008-09-25 14:27:19 +00:00
|
|
|
return implode(";\n", $queries);
|
2008-09-03 13:55:43 +00:00
|
|
|
}
|
|
|
|
$queries[] = $query;
|
2009-05-08 05:23:03 +00:00
|
|
|
return $dbh->query($query);
|
2008-09-03 13:55:43 +00:00
|
|
|
}
|
|
|
|
|
2007-07-27 11:43:44 +00:00
|
|
|
function remove_from_uri($param = "") {
|
2007-07-28 21:14:48 +00:00
|
|
|
$param = "($param|" . session_name() . ")";
|
2007-07-27 11:43:44 +00:00
|
|
|
return preg_replace("~\\?$param=[^&]*&~", '?', preg_replace("~\\?$param=[^&]*\$|&$param=[^&]*~", '', $_SERVER["REQUEST_URI"]));
|
|
|
|
}
|
|
|
|
|
2009-07-15 11:31:17 +00:00
|
|
|
function pagination($page) {
|
2009-07-28 16:20:50 +00:00
|
|
|
return " " . ($page == $_GET["page"] ? $page + 1 : '<a href="' . h(remove_from_uri("page") . ($page ? "&page=$page" : "")) . '">' . ($page + 1) . "</a>");
|
2008-08-07 08:02:54 +00:00
|
|
|
}
|
|
|
|
|
2007-07-09 06:12:22 +00:00
|
|
|
function get_file($key) {
|
2009-06-21 23:20:32 +00:00
|
|
|
// returns int for error, string otherwise
|
2007-07-09 06:12:22 +00:00
|
|
|
if (isset($_POST["files"][$key])) {
|
2009-06-21 23:20:32 +00:00
|
|
|
// get the file from hidden field if the user was logged out
|
2007-07-09 06:12:22 +00:00
|
|
|
$length = strlen($_POST["files"][$key]);
|
2008-03-18 10:29:20 +00:00
|
|
|
return ($length && $length < 4 ? intval($_POST["files"][$key]) : base64_decode($_POST["files"][$key]));
|
2007-07-09 06:12:22 +00:00
|
|
|
}
|
|
|
|
return (!$_FILES[$key] || $_FILES[$key]["error"] ? $_FILES[$key]["error"] : file_get_contents($_FILES[$key]["tmp_name"]));
|
|
|
|
}
|
|
|
|
|
2009-07-16 13:46:49 +00:00
|
|
|
function upload_error($error) {
|
|
|
|
$max_size = ($error == UPLOAD_ERR_INI_SIZE ? ini_get("upload_max_filesize") : null); // post_max_size is checked in index.php
|
|
|
|
return lang('Unable to upload a file.') . ($max_size ? " " . lang('Maximum allowed file size is %sB.', $max_size) : "");
|
|
|
|
}
|
|
|
|
|
2009-04-30 15:21:31 +00:00
|
|
|
function odd($s = ' class="odd"') {
|
|
|
|
static $i = 0;
|
|
|
|
if (!$s) { // reset counter
|
2009-05-18 10:27:49 +00:00
|
|
|
$i = -1;
|
2009-04-30 15:21:31 +00:00
|
|
|
}
|
2009-05-18 10:27:49 +00:00
|
|
|
return ($i++ % 2 ? $s : '');
|
2009-04-30 15:21:31 +00:00
|
|
|
}
|
|
|
|
|
2009-06-03 18:34:57 +00:00
|
|
|
function select($result, $dbh2 = null) {
|
2007-07-10 13:30:42 +00:00
|
|
|
if (!$result->num_rows) {
|
2009-07-11 20:30:40 +00:00
|
|
|
echo "<p class='message'>" . lang('No rows.') . "\n";
|
2007-07-09 06:12:22 +00:00
|
|
|
} else {
|
2009-06-11 14:58:07 +00:00
|
|
|
echo "<table cellspacing='0' class='nowrap'>\n";
|
2009-06-21 23:20:32 +00:00
|
|
|
$links = array(); // colno => orgtable - create links from these columns
|
|
|
|
$indexes = array(); // orgtable => array(column => colno) - primary keys
|
|
|
|
$columns = array(); // orgtable => array(column => ) - not selected columns in primary key
|
|
|
|
$blobs = array(); // colno => bool - display bytes for blobs
|
|
|
|
$types = array(); // colno => type - display char in <code>
|
|
|
|
odd(''); // reset odd for each result
|
2007-07-10 13:30:42 +00:00
|
|
|
for ($i=0; $row = $result->fetch_row(); $i++) {
|
2007-07-09 06:12:22 +00:00
|
|
|
if (!$i) {
|
|
|
|
echo "<thead><tr>";
|
|
|
|
for ($j=0; $j < count($row); $j++) {
|
2007-07-10 13:30:42 +00:00
|
|
|
$field = $result->fetch_field();
|
2007-07-19 14:42:10 +00:00
|
|
|
if (strlen($field->orgtable)) {
|
2007-07-10 13:30:42 +00:00
|
|
|
if (!isset($indexes[$field->orgtable])) {
|
2009-06-21 23:20:32 +00:00
|
|
|
// find primary key in each table
|
2007-07-10 13:30:42 +00:00
|
|
|
$indexes[$field->orgtable] = array();
|
2009-06-03 18:34:57 +00:00
|
|
|
foreach (indexes($field->orgtable, $dbh2) as $index) {
|
2007-07-09 06:12:22 +00:00
|
|
|
if ($index["type"] == "PRIMARY") {
|
2007-07-10 13:30:42 +00:00
|
|
|
$indexes[$field->orgtable] = array_flip($index["columns"]);
|
2007-07-09 06:12:22 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
$columns[$field->orgtable] = $indexes[$field->orgtable];
|
2007-07-09 06:12:22 +00:00
|
|
|
}
|
2007-07-10 20:51:14 +00:00
|
|
|
if (isset($columns[$field->orgtable][$field->orgname])) {
|
|
|
|
unset($columns[$field->orgtable][$field->orgname]);
|
|
|
|
$indexes[$field->orgtable][$field->orgname] = $j;
|
|
|
|
$links[$j] = $field->orgtable;
|
|
|
|
}
|
2007-07-09 06:12:22 +00:00
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
if ($field->charsetnr == 63) {
|
2007-07-09 06:12:22 +00:00
|
|
|
$blobs[$j] = true;
|
|
|
|
}
|
2007-07-15 11:05:42 +00:00
|
|
|
$types[$j] = $field->type;
|
2009-07-28 16:20:50 +00:00
|
|
|
echo "<th>" . h($field->name);
|
2007-07-09 06:12:22 +00:00
|
|
|
}
|
2009-07-11 20:30:40 +00:00
|
|
|
echo "</thead>\n";
|
2007-07-09 06:12:22 +00:00
|
|
|
}
|
2009-04-30 15:21:31 +00:00
|
|
|
echo "<tr" . odd() . ">";
|
2007-07-09 06:12:22 +00:00
|
|
|
foreach ($row as $key => $val) {
|
|
|
|
if (!isset($val)) {
|
|
|
|
$val = "<i>NULL</i>";
|
|
|
|
} else {
|
2009-06-11 05:05:35 +00:00
|
|
|
if ($blobs[$key] && !is_utf8($val)) {
|
2009-06-11 05:18:40 +00:00
|
|
|
$val = "<i>" . lang('%d byte(s)', strlen($val)) . "</i>"; //! link to download
|
2009-06-21 23:41:28 +00:00
|
|
|
} elseif (!strlen(trim($val, " \t"))) {
|
2009-06-21 23:20:32 +00:00
|
|
|
$val = " "; // some content to print a border
|
2007-07-13 14:05:06 +00:00
|
|
|
} else {
|
2009-07-28 16:20:50 +00:00
|
|
|
$val = nl2br(h($val));
|
2007-07-15 11:05:42 +00:00
|
|
|
if ($types[$key] == 254) {
|
|
|
|
$val = "<code>$val</code>";
|
|
|
|
}
|
2007-07-13 14:05:06 +00:00
|
|
|
}
|
2007-07-09 06:12:22 +00:00
|
|
|
if (isset($links[$key]) && !$columns[$links[$key]]) {
|
|
|
|
$link = "edit=" . urlencode($links[$key]);
|
|
|
|
foreach ($indexes[$links[$key]] as $col => $j) {
|
2009-07-30 08:12:54 +00:00
|
|
|
$link .= "&where" . urlencode("[" . bracket_escape($col) . "]") . "=" . urlencode($row[$j]);
|
2007-07-09 06:12:22 +00:00
|
|
|
}
|
2009-07-30 08:12:54 +00:00
|
|
|
$val = "<a href='" . h(ME . $link) . "'>$val</a>";
|
2007-07-09 06:12:22 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-11 20:30:40 +00:00
|
|
|
echo "<td>$val";
|
2007-07-09 06:12:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
echo "</table>\n";
|
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
$result->free();
|
2007-07-09 14:45:11 +00:00
|
|
|
}
|
|
|
|
|
2009-06-11 05:05:35 +00:00
|
|
|
function is_utf8($val) {
|
2009-06-21 23:20:32 +00:00
|
|
|
// don't print control chars except \t\r\n
|
2009-06-11 05:05:35 +00:00
|
|
|
return (preg_match('~~u', $val) && !preg_match('~[\\0-\\x8\\xB\\xC\\xE-\\x1F]~', $val));
|
|
|
|
}
|
|
|
|
|
2009-06-15 09:07:05 +00:00
|
|
|
function shorten_utf8($string, $length = 80, $suffix = "") {
|
2009-07-27 16:59:52 +00:00
|
|
|
preg_match("~^((?:.|\n){0,$length})(.|\n)?~u", $string, $match); // ~s causes trash in $match[2] under some PHP versions
|
2009-07-28 16:20:50 +00:00
|
|
|
return h($match[1]) . $suffix . ($match[2] ? "<em>...</em>" : "");
|
2007-08-24 16:00:10 +00:00
|
|
|
}
|
2008-10-03 12:40:20 +00:00
|
|
|
|
2009-06-11 05:18:40 +00:00
|
|
|
function friendly_url($val) {
|
2009-06-21 23:20:32 +00:00
|
|
|
// used for blobs and export
|
2009-06-11 05:18:40 +00:00
|
|
|
return preg_replace('~[^a-z0-9_]~i', '-', $val);
|
|
|
|
}
|
|
|
|
|
2008-10-09 13:23:54 +00:00
|
|
|
function hidden_fields($process, $ignore = array()) {
|
2008-10-03 13:15:58 +00:00
|
|
|
while (list($key, $val) = each($process)) {
|
|
|
|
if (is_array($val)) {
|
|
|
|
foreach ($val as $k => $v) {
|
|
|
|
$process[$key . "[$k]"] = $v;
|
|
|
|
}
|
|
|
|
} elseif (!in_array($key, $ignore)) {
|
2009-07-28 16:20:50 +00:00
|
|
|
echo '<input type="hidden" name="' . h($key) . '" value="' . h($val) . '">';
|
2008-10-03 13:15:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-07-03 09:16:50 +00:00
|
|
|
|
2009-07-23 14:42:38 +00:00
|
|
|
function column_foreign_keys($table) {
|
|
|
|
$return = array();
|
|
|
|
foreach (foreign_keys($table) as $foreign_key) {
|
|
|
|
foreach ($foreign_key["source"] as $val) {
|
|
|
|
$return[$val][] = $foreign_key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
|
|
|
|
function input($field, $value, $function) {
|
2009-07-27 11:25:37 +00:00
|
|
|
global $types, $adminer;
|
2009-07-28 16:20:50 +00:00
|
|
|
$name = h(bracket_escape($field["field"]));
|
2009-07-03 09:16:50 +00:00
|
|
|
echo "<td class='function'>";
|
|
|
|
if ($field["type"] == "enum") {
|
2009-07-28 16:28:47 +00:00
|
|
|
echo " <td>" . (isset($_GET["select"]) ? " <label><input type='radio' name='fields[$name]' value='-1' checked><em>" . lang('original') . "</em></label>" : "");
|
2009-07-03 09:16:50 +00:00
|
|
|
if ($field["null"] || isset($_GET["default"])) {
|
2009-07-28 16:28:47 +00:00
|
|
|
echo " <label><input type='radio' name='fields[$name]' value=''" . (($field["null"] ? isset($value) : strlen($value)) || isset($_GET["select"]) ? '' : ' checked') . '>' . ($field["null"] ? '<em>NULL</em>' : '') . '</label>';
|
2009-07-03 09:16:50 +00:00
|
|
|
}
|
|
|
|
if (!isset($_GET["default"])) {
|
2009-07-28 16:28:47 +00:00
|
|
|
echo "<input type='radio' name='fields[$name]' value='0'" . ($value === 0 ? ' checked' : '') . '>';
|
2009-07-03 09:16:50 +00:00
|
|
|
}
|
|
|
|
preg_match_all("~'((?:[^']+|'')*)'~", $field["length"], $matches);
|
|
|
|
foreach ($matches[1] as $i => $val) {
|
|
|
|
$val = stripcslashes(str_replace("''", "'", $val));
|
|
|
|
$checked = (is_int($value) ? $value == $i+1 : $value === $val);
|
2009-07-28 16:28:47 +00:00
|
|
|
echo " <label><input type='radio' name='fields[$name]' value='" . (isset($_GET["default"]) ? (strlen($val) ? h($val) : " ") : $i+1) . "'" . ($checked ? ' checked' : '') . '>' . h($val) . '</label>';
|
2009-07-03 09:16:50 +00:00
|
|
|
}
|
|
|
|
} else {
|
2009-07-28 15:52:39 +00:00
|
|
|
$functions = (isset($_GET["select"]) ? array("orig" => lang('original')) : array()) + $adminer->editFunctions($field);
|
|
|
|
$first = array_search("", $functions) + (isset($_GET["select"]) ? 1 : 0);
|
2009-07-28 16:20:50 +00:00
|
|
|
$onchange = ($first ? " onchange=\"var f = this.form['function[" . addcslashes($name, "\r\n'\\") . "]']; if ($first > f.selectedIndex) f.selectedIndex = $first;\"" : "");
|
2009-07-30 08:12:54 +00:00
|
|
|
echo (count($functions) > 1 ? "<select name='function[$name]'>" . optionlist($functions, $function) . "</select>" : (strlen($functions[0]) ? $functions[0] : " ")) . '<td>';
|
2009-07-28 16:20:50 +00:00
|
|
|
$input = $adminer->editInput($_GET["edit"], $field, " name='fields[$name]'$onchange", $value); // usage in call is without a table
|
2009-07-28 10:09:05 +00:00
|
|
|
if (strlen($input)) {
|
|
|
|
echo $input;
|
2009-07-23 14:42:38 +00:00
|
|
|
} elseif ($field["type"] == "set") { //! 64 bits
|
2009-07-03 09:16:50 +00:00
|
|
|
preg_match_all("~'((?:[^']+|'')*)'~", $field["length"], $matches);
|
|
|
|
foreach ($matches[1] as $i => $val) {
|
|
|
|
$val = stripcslashes(str_replace("''", "'", $val));
|
|
|
|
$checked = (is_int($value) ? ($value >> $i) & 1 : in_array($val, explode(",", $value), true));
|
2009-07-28 16:28:47 +00:00
|
|
|
echo " <label><input type='checkbox' name='fields[$name][$i]' value='" . (isset($_GET["default"]) ? h($val) : 1 << $i) . "'" . ($checked ? ' checked' : '') . "$onchange>" . h($val) . '</label>';
|
2009-07-03 09:16:50 +00:00
|
|
|
}
|
|
|
|
} elseif (strpos($field["type"], "text") !== false) {
|
2009-07-28 16:20:50 +00:00
|
|
|
echo "<textarea name='fields[$name]' cols='50' rows='12'$onchange>" . h($value) . '</textarea>';
|
2009-07-13 16:03:51 +00:00
|
|
|
} elseif (ereg('binary|blob', $field["type"])) {
|
2009-07-28 16:20:50 +00:00
|
|
|
echo (ini_get("file_uploads") ? "<input type='file' name='$name'$onchange>" : lang('File uploads are disabled.'));
|
2009-07-03 09:16:50 +00:00
|
|
|
} else {
|
|
|
|
// int(3) is only a display hint
|
|
|
|
$maxlength = (!ereg('int', $field["type"]) && preg_match('~^([0-9]+)(,([0-9]+))?$~', $field["length"], $match) ? ($match[1] + ($match[3] ? 1 : 0) + ($match[2] && !$field["unsigned"] ? 1 : 0)) : ($types[$field["type"]] ? $types[$field["type"]] + ($field["unsigned"] ? 0 : 1) : 0));
|
2009-07-28 16:20:50 +00:00
|
|
|
echo "<input name='fields[$name]' value='" . h($value) . "'" . ($maxlength ? " maxlength='$maxlength'" : "") . "$onchange>";
|
2009-07-03 09:16:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-27 16:32:56 +00:00
|
|
|
function process_input($field) {
|
2009-07-27 11:25:37 +00:00
|
|
|
global $dbh, $adminer;
|
2009-07-27 16:32:56 +00:00
|
|
|
$idf = bracket_escape($field["field"]);
|
2009-07-03 09:16:50 +00:00
|
|
|
$function = $_POST["function"][$idf];
|
|
|
|
$value = $_POST["fields"][$idf];
|
|
|
|
if ($field["type"] == "enum" ? $value == -1 : $function == "orig") {
|
|
|
|
return false;
|
|
|
|
} elseif ($field["type"] == "enum" || $field["auto_increment"] ? !strlen($value) : $function == "NULL") {
|
|
|
|
return "NULL";
|
|
|
|
} elseif ($field["type"] == "enum") {
|
|
|
|
return (isset($_GET["default"]) ? $dbh->quote($value) : intval($value));
|
|
|
|
} elseif ($field["type"] == "set") {
|
2009-07-23 15:57:03 +00:00
|
|
|
return (isset($_GET["default"]) ? $dbh->quote(implode(",", (array) $value)) : array_sum((array) $value));
|
2009-07-13 16:03:51 +00:00
|
|
|
} elseif (ereg('binary|blob', $field["type"])) {
|
2009-07-03 09:16:50 +00:00
|
|
|
$file = get_file($idf);
|
|
|
|
if (!is_string($file)) {
|
|
|
|
return false; //! report errors
|
|
|
|
}
|
2009-07-15 13:34:35 +00:00
|
|
|
return "_binary" . $dbh->quote($file);
|
2009-07-03 09:16:50 +00:00
|
|
|
} else {
|
2009-07-27 16:32:56 +00:00
|
|
|
return $adminer->processInput($field, $value, $function);
|
2009-07-03 09:16:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function dump_csv($row) {
|
|
|
|
foreach ($row as $key => $val) {
|
|
|
|
if (preg_match("~[\"\n,]~", $val) || (isset($val) && !strlen($val))) {
|
|
|
|
$row[$key] = '"' . str_replace('"', '""', $val) . '"';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo implode(",", $row) . "\n";
|
|
|
|
}
|
2009-07-11 19:45:57 +00:00
|
|
|
|
|
|
|
function is_email($email) {
|
|
|
|
$atom = '[-a-z0-9!#$%&\'*+/=?^_`{|}~]'; // characters of local-name
|
|
|
|
$domain = '[a-z0-9]([-a-z0-9]{0,61}[a-z0-9])'; // one domain component
|
|
|
|
return eregi("^$atom+(\\.$atom+)*@($domain?\\.)+$domain\$", $email);
|
|
|
|
}
|
|
|
|
|
|
|
|
function email_header($header) {
|
2009-07-12 18:51:26 +00:00
|
|
|
// iconv_mime_encode requires PHP 5, imap_8bit requires IMAP extension
|
|
|
|
return "=?UTF-8?B?" . base64_encode($header) . "?="; //! split long lines
|
2009-07-11 19:45:57 +00:00
|
|
|
}
|