示例#1
0
                 $out .= ($style != 'DROP+CREATE' ? "DROP {$routine} IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "") . remove_definer($connection->result("SHOW CREATE {$routine} " . idf_escape($row["Name"]), 2)) . ";;\n\n";
             }
         }
     }
     if ($_POST["events"]) {
         foreach (get_rows("SHOW EVENTS", null, "-- ") as $row) {
             $out .= ($style != 'DROP+CREATE' ? "DROP EVENT IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "") . remove_definer($connection->result("SHOW CREATE EVENT " . idf_escape($row["Name"]), 3)) . ";;\n\n";
         }
     }
     if ($out) {
         echo "DELIMITER ;;\n\n{$out}" . "DELIMITER ;\n\n";
     }
 }
 if ($_POST["table_style"] || $_POST["data_style"]) {
     $views = array();
     foreach (table_status('', true) as $name => $table_status) {
         $table = DB == "" || in_array($name, (array) $_POST["tables"]);
         $data = DB == "" || in_array($name, (array) $_POST["data"]);
         if ($table || $data) {
             if ($ext == "tar") {
                 $tmp_file = new TmpFile();
                 ob_start(array($tmp_file, 'write'), 100000.0);
             }
             $adminer->dumpTable($name, $table ? $_POST["table_style"] : "", is_view($table_status) ? 2 : 0);
             if (is_view($table_status)) {
                 $views[] = $name;
             } elseif ($data) {
                 $fields = fields($name);
                 $adminer->dumpData($name, $_POST["data_style"], "SELECT *" . convert_fields($fields, $fields) . " FROM " . table($name));
             }
             if ($is_sql && $_POST["triggers"] && $table && ($triggers = trigger_sql($name, $_POST["table_style"]))) {
示例#2
0
    /** Prints navigation after Adminer title
     * @param string can be "auth" if there is no database connection, "db" if there is no database selected, "ns" with invalid schema
     * @return null
     */
    function navigation($missing)
    {
        global $VERSION, $jush, $drivers, $connection;
        ?>
<h1>
<?php 
        echo $this->name();
        ?>
 <span class="version"><?php 
        echo $VERSION;
        ?>
</span>
<a href="http://www.adminer.org/#download" target="_blank" id="version"><?php 
        echo version_compare($VERSION, $_COOKIE["adminer_version"]) < 0 ? h($_COOKIE["adminer_version"]) : "";
        ?>
</a>
</h1>
<?php 
        if ($missing == "auth") {
            $first = true;
            foreach ((array) $_SESSION["pwds"] as $vendor => $servers) {
                foreach ($servers as $server => $usernames) {
                    foreach ($usernames as $username => $password) {
                        if ($password !== null) {
                            if ($first) {
                                echo "<p id='logins' onmouseover='menuOver(this, event);' onmouseout='menuOut(this);'>\n";
                                $first = false;
                            }
                            $dbs = $_SESSION["db"][$vendor][$server][$username];
                            foreach ($dbs ? array_keys($dbs) : array("") as $db) {
                                echo "<a href='" . h(auth_url($vendor, $server, $username, $db)) . "'>({$drivers[$vendor]}) " . h($username . ($server != "" ? "@{$server}" : "") . ($db != "" ? " - {$db}" : "")) . "</a><br>\n";
                            }
                        }
                    }
                }
            }
        } else {
            if ($_GET["ns"] !== "" && !$missing && DB != "") {
                $connection->select_db(DB);
                $tables = table_status('', true);
            }
            if (support("sql")) {
                ?>
<script type="text/javascript" src="../externals/jush/modules/jush.js"></script>
<script type="text/javascript" src="../externals/jush/modules/jush-textarea.js"></script>
<script type="text/javascript" src="../externals/jush/modules/jush-txt.js"></script>
<script type="text/javascript" src="../externals/jush/modules/jush-<?php 
                echo $jush;
                ?>
.js"></script>
<script type="text/javascript">
<?php 
                if ($tables) {
                    $links = array();
                    foreach ($tables as $table => $type) {
                        $links[] = preg_quote($table, '/');
                    }
                    echo "var jushLinks = { {$jush}: [ '" . js_escape(ME) . (support("table") ? "table=" : "select=") . "\$&', /\\b(" . implode("|", $links) . ")\\b/g ] };\n";
                    foreach (array("bac", "bra", "sqlite_quo", "mssql_bra") as $val) {
                        echo "jushLinks.{$val} = jushLinks.{$jush};\n";
                    }
                }
                ?>
bodyLoad('<?php 
                echo is_object($connection) ? substr($connection->server_info, 0, 3) : "";
                ?>
');
</script>
<?php 
            }
            $this->databasesPrint($missing);
            if (DB == "" || !$missing) {
                echo "<p class='links'>" . (support("sql") ? "<a href='" . h(ME) . "sql='" . bold(isset($_GET["sql"]) && !isset($_GET["import"])) . ">" . lang('SQL command') . "</a>\n<a href='" . h(ME) . "import='" . bold(isset($_GET["import"])) . ">" . lang('Import') . "</a>\n" : "") . "";
                if (support("dump")) {
                    echo "<a href='" . h(ME) . "dump=" . urlencode(isset($_GET["table"]) ? $_GET["table"] : $_GET["select"]) . "' id='dump'" . bold(isset($_GET["dump"])) . ">" . lang('Export') . "</a>\n";
                }
            }
            if ($_GET["ns"] !== "" && !$missing && DB != "") {
                echo '<a href="' . h(ME) . 'create="' . bold($_GET["create"] === "") . ">" . lang('Create table') . "</a>\n";
                if (!$tables) {
                    echo "<p class='message'>" . lang('No tables.') . "\n";
                } else {
                    $this->tablesPrint($tables);
                }
            }
        }
    }
示例#3
0
<?php

$TABLE = $_GET["select"];
$table_status = table_status($TABLE);
$indexes = indexes($TABLE);
$fields = fields($TABLE);
$foreign_keys = column_foreign_keys($TABLE);
$oid = "";
if ($table_status["Oid"] == "t") {
    $oid = $jush == "sqlite" ? "rowid" : "oid";
    $indexes[] = array("type" => "PRIMARY", "columns" => array($oid));
}
parse_str($_COOKIE["adminer_import"], $adminer_import);
$rights = array();
// privilege => 0
$columns = array();
// selectable columns
$text_length = null;
foreach ($fields as $key => $field) {
    $name = $adminer->fieldName($field);
    if (isset($field["privileges"]["select"]) && $name != "") {
        $columns[$key] = html_entity_decode(strip_tags($name));
        if (ereg('text|lob|geometry|point|linestring|polygon', $field["type"])) {
            $text_length = $adminer->selectLengthProcess();
        }
    }
    $rights += $field["privileges"];
}
list($select, $group) = $adminer->selectColumnsProcess($columns, $indexes);
$is_group = count($group) < count($select);
$where = $adminer->selectSearchProcess($fields, $indexes);
示例#4
0
<?php

header("Content-Type: text/javascript; charset=utf-8");
if ($_GET["script"] == "db") {
    $sums = array("Data_length" => 0, "Index_length" => 0, "Data_free" => 0);
    foreach (table_status() as $name => $table_status) {
        $id = is_adminer_escape($name);
        json_row("Comment-{$id}", nbsp($table_status["Comment"]));
        if (!is_view($table_status)) {
            foreach (array("Engine", "Collation") as $key) {
                json_row("{$key}-{$id}", nbsp($table_status[$key]));
            }
            foreach ($sums + array("Auto_increment" => 0, "Rows" => 0) as $key => $val) {
                if ($table_status[$key] != "") {
                    $val = format_number($table_status[$key]);
                    json_row("{$key}-{$id}", $key == "Rows" && $val && $table_status["Engine"] == ($sql == "pgsql" ? "table" : "InnoDB") ? "~ {$val}" : $val);
                    if (isset($sums[$key])) {
                        // ignore innodb_file_per_table because it is not active for tables created before it was enabled
                        $sums[$key] += $table_status["Engine"] != "InnoDB" || $key != "Data_free" ? $table_status[$key] : 0;
                    }
                } elseif (array_key_exists($key, $table_status)) {
                    json_row("{$key}-{$id}");
                }
            }
        }
    }
    foreach ($sums as $key => $val) {
        json_row("sum-{$key}", format_number($val));
    }
    json_row("");
} elseif ($_GET["script"] == "kill") {
示例#5
0
/** Print results of search in all tables
* @uses $_GET["where"][0]
* @uses $_POST["tables"]
* @return null
*/
function search_tables()
{
    global $adminer, $connection;
    $_GET["where"][0]["op"] = "LIKE %%";
    $_GET["where"][0]["val"] = $_POST["query"];
    $found = false;
    foreach (table_status('', true) 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 || $result->fetch_row()) {
                if (!$found) {
                    echo "<ul>\n";
                    $found = true;
                }
                echo "<li>" . ($result ? "<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" : "{$name}: <span class='error'>" . error() . "</span>\n");
            }
        }
    }
    echo ($found ? "</ul>" : "<p class='message'>" . lang('No tables.')) . "\n";
}
示例#6
0
<?php

$TABLE = $_GET["create"];
$partition_by = array('HASH', 'LINEAR HASH', 'KEY', 'LINEAR KEY', 'RANGE', 'LIST');
$referencable_primary = referencable_primary($TABLE);
$foreign_keys = array();
foreach ($referencable_primary as $table_name => $field) {
    $foreign_keys[str_replace("`", "``", $table_name) . "`" . str_replace("`", "``", $field["field"])] = $table_name;
    // not idf_escape() - used in JS
}
$orig_fields = array();
$orig_status = array();
if ($TABLE != "") {
    $orig_fields = fields($TABLE);
    $orig_status = table_status($TABLE);
}
if ($_POST && !$_POST["fields"]) {
    $_POST["fields"] = array();
}
if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] && !$_POST["down"]) {
    if ($_POST["drop"]) {
        query_redirect("DROP TABLE " . table($TABLE), substr(ME, 0, -1), lang('Table has been dropped.'));
    } else {
        $fields = array();
        $all_fields = array();
        $use_all_fields = false;
        $foreign = array();
        ksort($_POST["fields"]);
        $orig_field = reset($orig_fields);
        $after = " FIRST";
        foreach ($_POST["fields"] as $key => $field) {
示例#7
0
/** Compute size of database
* @param string
* @return string formatted
*/
function db_size($db)
{
    global $connection;
    if (!$connection->select_db($db)) {
        return "?";
    }
    $return = 0;
    foreach (table_status() as $table_status) {
        $return += $table_status["Data_length"] + $table_status["Index_length"];
    }
    return format_number($return);
}
示例#8
0
<?php

$TABLE = $_GET["view"];
$row = $_POST;
if ($_POST && !$error) {
    $name = trim($row["name"]);
    $as = " AS\n{$row['select']}";
    $location = ME . "table=" . urlencode($name);
    $message = lang('View has been altered.');
    if ($_GET["materialized"]) {
        $type = "MATERIALIZED VIEW";
    } else {
        $type = "VIEW";
        if ($jush == "pgsql") {
            $status = table_status($name);
            $type = $status ? strtoupper($status["Engine"]) : $type;
        }
    }
    if (!$_POST["drop"] && $TABLE == $name && $jush != "sqlite" && $type != "MATERIALIZED VIEW") {
        query_redirect(($jush == "mssql" ? "ALTER" : "CREATE OR REPLACE") . " VIEW " . table($name) . $as, $location, $message);
    } else {
        $temp_name = $name . "_adminer_" . uniqid();
        drop_create("DROP {$type} " . table($TABLE), "CREATE {$type} " . table($name) . $as, "DROP {$type} " . table($name), "CREATE {$type} " . table($temp_name) . $as, "DROP {$type} " . table($temp_name), $_POST["drop"] ? substr(ME, 0, -1) : $location, lang('View has been dropped.'), $message, lang('View has been created.'), $TABLE, $name);
    }
}
if (!$_POST && $TABLE != "") {
    $row = view($TABLE);
    $row["name"] = $TABLE;
    if (!$error) {
        $error = error();
    }
示例#9
0
文件: phpadmin.php 项目: rohdoor/ehcp
            ?>
</table>
<p>
<input type="hidden" name="token" value="<?php 
            echo $token;
            ?>
" />
<input type="submit" value="<?php 
            echo lang('Kill');
            ?>
" />
</p>
</form>
<?php 
        } elseif (isset($_GET["select"])) {
            $table_status = table_status($_GET["select"]);
            $indexes = indexes($_GET["select"]);
            $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "REGEXP", "IN", "IS NULL");
            if ($table_status["Engine"] == "MyISAM") {
                $operators[] = "AGAINST";
            }
            $fields = fields($_GET["select"]);
            $rights = array();
            $columns = array();
            unset($text_length);
            foreach ($fields as $key => $field) {
                if (isset($field["privileges"]["select"])) {
                    $columns[] = $key;
                    if (preg_match('~text|blob~', $field["type"])) {
                        $text_length = isset($_GET["text_length"]) ? $_GET["text_length"] : "100";
                    }
?>
<h1  style="<?php 
echo $db_name_style;
?>
"><?php 
echo $db_name_h1 ? $db_name_h1 : $db_name;
?>
</h1>

<?php 
conn_info();
?>

<?php 
$tables = list_tables();
$status = table_status();
$views = list_tables(true);
?>

<p>
	Tables: <b><?php 
echo count($tables);
?>
</b>
	&nbsp;-&nbsp;
	Total size: <b><?php 
echo number_format(ceil($status['total_size'] / 1024), 0, '', ',') . ' KB';
?>
</b>
	&nbsp;-&nbsp;
	Views: <b><?php 
示例#11
0
$SCHEMA = $_GET["schema"] ? $_GET["schema"] : $_COOKIE[$_COOKIE["{$name}-" . DB] ? "{$name}-" . DB : $name];
// $_COOKIE["adminer_schema"] was used before 3.2.0 //! ':' in table name
preg_match_all('~([^:]+):([-0-9.]+)x([-0-9.]+)(_|$)~', $SCHEMA, $matches, PREG_SET_ORDER);
foreach ($matches as $i => $match) {
    $table_pos[$match[1]] = array($match[2], $match[3]);
    $table_pos_js[] = "\n\t'" . js_escape($match[1]) . "': [ {$match['2']}, {$match['3']} ]";
}
$top = 0;
$base_left = -1;
$schema = array();
// table => array("fields" => array(name => field), "pos" => array(top, left), "references" => array(table => array(left => array(source, target))))
$referenced = array();
// target_table => array(table => array(left => target_column))
$lefts = array();
// float => bool
foreach (table_status() as $table_status) {
    if (!isset($table_status["Engine"])) {
        // view
        continue;
    }
    $pos = 0;
    $schema[$table_status["Name"]]["fields"] = array();
    foreach (fields($table_status["Name"]) as $name => $field) {
        $pos += 1.25;
        $field["pos"] = $pos;
        $schema[$table_status["Name"]]["fields"][$name] = $field;
    }
    $schema[$table_status["Name"]]["pos"] = $table_pos[$table_status["Name"]] ? $table_pos[$table_status["Name"]] : array($top, 0);
    foreach ($adminer->foreignKeys($table_status["Name"]) as $val) {
        if (!$val["db"]) {
            $left = $base_left;
示例#12
0
文件: db.inc.php 项目: ly95/adminer
<?php

page_header(lang('Server'), "", false);
if ($adminer->homepage()) {
    echo "<form action='' method='post'>\n";
    echo "<p>" . lang('Search data in tables') . ": <input name='query' value='" . h($_POST["query"]) . "'> <input type='submit' value='" . lang('Search') . "'>\n";
    if ($_POST["query"] != "") {
        search_tables();
    }
    echo "<table cellspacing='0' class='nowrap checkable' onclick='tableClick(event);'>\n";
    echo '<thead><tr class="wrap"><td><input id="check-all" type="checkbox" onclick="formCheck(this, /^tables\\[/);"><th>' . lang('Table') . '<td>' . lang('Rows') . "</thead>\n";
    foreach (table_status() as $table => $row) {
        $name = $adminer->tableName($row);
        if (isset($row["Engine"]) && $name != "") {
            echo '<tr' . odd() . '><td>' . checkbox("tables[]", $table, in_array($table, (array) $_POST["tables"], true), "", "formUncheck('check-all');");
            echo "<th><a href='" . h(ME) . 'select=' . urlencode($table) . "'>{$name}</a>";
            $val = format_number($row["Rows"]);
            echo "<td align='right'><a href='" . h(ME . "edit=") . urlencode($table) . "'>" . ($row["Engine"] == "InnoDB" && $val ? "~ {$val}" : $val) . "</a>";
        }
    }
    echo "</table>\n";
    echo "<script type='text/javascript'>tableCheck();</script>\n";
    echo "</form>\n";
}
示例#13
0
<?php

$TABLE = $_GET["table"];
$fields = fields($TABLE);
if (!$fields) {
    $error = error();
}
$table_status = $fields ? table_status($TABLE) : array();
page_header(($fields && is_view($table_status) ? lang('View') : lang('Table')) . ": " . h($TABLE), $error);
$adminer->selectLinks($table_status);
$comment = $table_status["Comment"];
if ($comment != "") {
    echo "<p>" . lang('Comment') . ": " . h($comment) . "\n";
}
if ($fields) {
    echo "<table cellspacing='0'>\n";
    echo "<thead><tr><th>" . lang('Column') . "<td>" . lang('Type') . (support("comment") ? "<td>" . lang('Comment') : "") . "</thead>\n";
    foreach ($fields as $field) {
        echo "<tr" . odd() . "><th>" . h($field["field"]);
        echo "<td title='" . h($field["collation"]) . "'>" . h($field["full_type"]) . ($field["null"] ? " <i>NULL</i>" : "") . ($field["auto_increment"] ? " <i>" . lang('Auto Increment') . "</i>" : "");
        echo isset($field["default"]) ? " [<b>" . h($field["default"]) . "</b>]" : "";
        echo support("comment") ? "<td>" . nbsp($field["comment"]) : "";
        echo "\n";
    }
    echo "</table>\n";
    if (!is_view($table_status)) {
        echo "<h3>" . lang('Indexes') . "</h3>\n";
        $indexes = indexes($TABLE);
        if ($indexes) {
            echo "<table cellspacing='0'>\n";
            foreach ($indexes as $name => $index) {
示例#14
0
    /** Prints navigation after Adminer title
     * @param string can be "auth" if there is no database connection, "db" if there is no database selected, "ns" with invalid schema
     * @return null
     */
    function navigation($missing)
    {
        global $VERSION, $jush, $drivers, $connection;
        ?>
			<!-- ACERCA DE -->
			<div class='well well-sm well-info' align=center>
				<?php 
        echo $this->name();
        ?>
 <span class="version"><?php 
        echo $VERSION;
        ?>
</span>
				<?php 
        switch_lang();
        ?>
			</div>

<?php 
        if ($missing == "auth") {
            $first = true;
            foreach ((array) $_SESSION["pwds"] as $vendor => $servers) {
                foreach ($servers as $server => $usernames) {
                    foreach ($usernames as $username => $password) {
                        if ($password !== null) {
                            if ($first) {
                                echo "<p id='logins' onmouseover='menuOver(this, event);' onmouseout='menuOut(this);'>\n";
                                $first = false;
                            }
                            $dbs = $_SESSION["db"][$vendor][$server][$username];
                            foreach ($dbs ? array_keys($dbs) : array("") as $db) {
                                echo "<a href='" . h(auth_url($vendor, $server, $username, $db)) . "'>({$drivers[$vendor]}) " . h($username . ($server != "" ? "@{$server}" : "") . ($db != "" ? " - {$db}" : "")) . "</a><br>\n";
                            }
                        }
                    }
                }
            }
        } else {
            if ($_GET["ns"] !== "" && !$missing && DB != "") {
                $connection->select_db(DB);
                $tables = table_status('', true);
            }
            if (support("sql")) {
                ?>
								<script type="text/javascript" src="../externals/jush/modules/jush.js"></script>
								<script type="text/javascript" src="../externals/jush/modules/jush-textarea.js"></script>
								<script type="text/javascript" src="../externals/jush/modules/jush-txt.js"></script>
								<script type="text/javascript" src="../externals/jush/modules/jush-<?php 
                echo $jush;
                ?>
.js"></script>
								<script type="text/javascript">
								<?php 
                if ($tables) {
                    $links = array();
                    foreach ($tables as $table => $type) {
                        $links[] = preg_quote($table, '/');
                    }
                    echo "var jushLinks = { {$jush}: [ '" . js_escape(ME) . (support("table") ? "table=" : "select=") . "\$&', /\\b(" . implode("|", $links) . ")\\b/g ] };\n";
                    foreach (array("bac", "bra", "sqlite_quo", "mssql_bra") as $val) {
                        echo "jushLinks.{$val} = jushLinks.{$jush};\n";
                    }
                }
                ?>
							bodyLoad('<?php 
                echo is_object($connection) ? substr($connection->server_info, 0, 3) : "";
                ?>
');
							</script>
						<?php 
            }
            echo "<div align=center>";
            $this->databasesPrint($missing);
            echo "<br>";
            if (DB == "" || !$missing) {
                echo (support("sql") ? "\n\t\t\t\t\t\t\t<a href='" . h(ME) . "sql='" . bold(isset($_GET["sql"]) && !isset($_GET["import"])) . " class='btn btn-info btn-xs'><i class='fa fa-terminal fa-fw'></i>  " . lang('SQL command') . "</a>\n\n\t\t\t\t\t\t\t<a href='" . h(ME) . "import='" . bold(isset($_GET["import"])) . " class='btn btn-warning btn-xs'><i class='fa fa-download fa-fw'></i> " . lang('Import') . "</a>\n" : "") . "";
                if (support("dump")) {
                    echo "<a href='" . h(ME) . "dump=" . urlencode(isset($_GET["table"]) ? $_GET["table"] : $_GET["select"]) . "' id='dump'" . bold(isset($_GET["dump"])) . " class='btn btn-danger btn-xs'><i class='fa fa-floppy-o fa-fw'></i> " . lang('Export') . "</a>\n";
                }
            }
            if ($_GET["ns"] !== "" && !$missing && DB != "") {
                echo '<a href="' . h(ME) . 'create="' . bold($_GET["create"] === "") . " class='btn btn-success btn-xs'><i class='fa fa-plus fa-fw'></i> " . lang('Create table') . "</a>\n";
                if (!$tables) {
                    //Imprime mensaje indicando que no hay tablas
                    echo "<br><br><div class='alert alert-warning' role='alert'>" . lang('No tables.') . "</div>\n";
                } else {
                    //Imprime la lista de tablas cuando hay al menos una en la BD
                    echo "<div align=left>";
                    $this->tablesPrint($tables);
                    echo "</div>";
                }
            }
            echo "</div>";
        }
    }
示例#15
0
<?php

$TABLE = $_GET["indexes"];
$index_types = array("PRIMARY", "UNIQUE", "INDEX");
$table_status = table_status($TABLE, true);
if (preg_match('~MyISAM|M?aria' . ($connection->server_info >= 5.6 ? '|InnoDB' : '') . '~i', $table_status["Engine"])) {
    $index_types[] = "FULLTEXT";
}
$indexes = indexes($TABLE);
$primary = array();
if ($jush == "mongo") {
    // doesn't support primary key
    $primary = $indexes["_id_"];
    unset($index_types[0]);
    unset($indexes["_id_"]);
}
$row = $_POST;
if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"]) {
    $alter = array();
    foreach ($row["indexes"] as $index) {
        $name = $index["name"];
        if (in_array($index["type"], $index_types)) {
            $columns = array();
            $lengths = array();
            $descs = array();
            $set = array();
            ksort($index["columns"]);
            foreach ($index["columns"] as $key => $column) {
                if ($column != "") {
                    $length = $index["lengths"][$key];
                    $desc = $index["descs"][$key];
示例#16
0
/** Get referencable tables with single column primary key except self
* @param string
* @return array ($table_name => $field)
*/
function referencable_primary($self)
{
    $return = array();
    // table_name => field
    foreach (table_status('', true) as $table_name => $table) {
        if ($table_name != $self && fk_support($table)) {
            foreach (fields($table_name) as $field) {
                if ($field["primary"]) {
                    if ($return[$table_name]) {
                        // multi column primary key
                        unset($return[$table_name]);
                        break;
                    }
                    $return[$table_name] = $field;
                }
            }
        }
    }
    return $return;
}
示例#17
0
            }
        }
        if ($update) {
            if (!$set) {
                redirect($location);
            }
            query_redirect("UPDATE" . limit1(table($TABLE) . " SET" . implode(",", $set), "\nWHERE {$where}"), $location, array(lang('Item has been updated.'), 'success'));
        } else {
            $result = insert_into($TABLE, $set);
            $last_id = $result ? last_id() : 0;
            queries_redirect($location, array(lang('Item%s has been inserted.', $last_id ? " {$last_id}" : ""), 'success'), $result);
            //! link
        }
    }
}
$table_name = $adminer->tableName(table_status($TABLE));
page_header($update ? lang('Edit') : lang('Insert'), $error, array("select" => array($TABLE, $table_name)), $table_name);
$adminer->selectLinks($table_status, '');
// @todo are params OK?
$row = null;
if ($_POST["save"]) {
    $row = (array) $_POST["fields"];
} elseif ($where) {
    $select = array();
    foreach ($fields as $name => $field) {
        if (isset($field["privileges"]["select"])) {
            $as = convert_field($field);
            if ($_POST["clone"] && $field["auto_increment"]) {
                $as = "''";
            }
            if ($jush == "sql" && ereg("enum|set", $field["type"])) {
示例#18
0
        $row["source"][] = "";
    } elseif ($_POST["change"] || $_POST["change-js"]) {
        $row["target"] = array();
    }
} elseif ($name != "") {
    $foreign_keys = foreign_keys($TABLE);
    $row = $foreign_keys[$name];
    $row["source"][] = "";
} else {
    $row["table"] = $TABLE;
    $row["source"] = array("");
}
$source = array_keys(fields($TABLE));
//! no text and blob
$target = $TABLE === $row["table"] ? $source : array_keys(fields($row["table"]));
$referencable = array_keys(array_filter(table_status('', true), 'fk_support'));
?>

<form action="" method="post">
<p>
<?php 
if ($row["db"] == "" && $row["ns"] == "") {
    echo lang('Target table');
    ?>
:
<?php 
    echo html_select("table", $referencable, $row["table"], "this.form['change-js'].value = '1'; this.form.submit();");
    ?>
<input type="hidden" name="change-js" value="">
<noscript><p><input type="submit" name="change" value="<?php 
    echo lang('Change');