function editInput($table, $field, $attrs, $value) { static $foreignTables = array(); static $values = array(); $foreignKeys =& $foreignTables[$table]; if ($foreignKeys === null) { $foreignKeys = column_foreign_keys($table); } foreach ((array) $foreignKeys[$field["field"]] as $foreignKey) { if (count($foreignKey["source"]) == 1) { $target = $foreignKey["table"]; $id = $foreignKey["target"][0]; $options =& $values[$target][$id]; if (!$options) { $options = array("" => "") + get_vals("SELECT " . idf_escape($id) . " FROM " . table($target) . " ORDER BY 1"); } return "<select{$attrs}>" . optionlist($options, $value) . "</select>"; } } }
if (!$row["collation"]) { adminer_redirect(substr(ME, 0, -1)); } query_adminer_redirect("ALTER DATABASE " . idf_escape($name) . (preg_match('~^[a-z0-9_]+$~i', $row["collation"]) ? " COLLATE {$row['collation']}" : ""), substr(ME, 0, -1), lang('Database has been altered.')); } } page_header(DB != "" ? lang('Alter database') : lang('Create database'), $error, array(), h(DB)); $collations = collations(); $name = DB; if ($_POST) { $name = $row["name"]; } elseif (DB != "") { $row["collation"] = db_collation(DB, $collations); } elseif ($jush == "sql") { // propose database name with limited privileges foreach (get_vals("SHOW GRANTS") as $grant) { if (preg_match('~ ON (`(([^\\\\`]|``|\\\\.)*)%`\\.\\*)?~', $grant, $match) && $match[1]) { $name = stripcslashes(idf_unescape("`{$match['2']}`")); break; } } } ?> <form action="" method="post"> <p> <?php echo ($_POST["add_x"] || strpos($name, "\n") ? '<textarea id="name" name="name" rows="10" cols="40">' . h($name) . '</textarea><br>' : '<input name="name" id="name" value="' . h($name) . '" maxlength="64" autocapitalize="off">') . "\n" . ($collations ? html_select("collation", array("" => "(" . lang('collation') . ")") + $collations, $row["collation"]) . doc_link(array('sql' => "charset-charsets.html", 'mssql' => "ms187963.aspx")) : ""); ?> <script type='text/javascript'>focus(document.getElementById('name'));</script> <input type="submit" value="<?php
function page_footer($missing = false) { global $SELF, $mysql; ?> </div> <?php switch_lang(); ?> <div id="menu"> <h1><a href="http://phpminadmin.sourceforge.net"><?php echo lang('phpMinAdmin'); ?> </a></h1> <?php if ($missing != "auth") { ?> <form action="" method="post"> <p> <a href="<?php echo htmlspecialchars($SELF); ?> sql="><?php echo lang('SQL command'); ?> </a> <a href="<?php echo htmlspecialchars($SELF); ?> dump=<?php echo urlencode($_GET["table"]); ?> "><?php echo lang('Dump'); ?> </a> <input type="hidden" name="token" value="<?php echo $_SESSION["tokens"][$_GET["server"]]["?logout"]; ?> " /> <input type="submit" name="logout" value="<?php echo lang('Logout'); ?> " /> </p> </form> <form action=""> <p><?php if (strlen($_GET["server"])) { ?> <input type="hidden" name="server" value="<?php echo htmlspecialchars($_GET["server"]); ?> " /><?php } ?> <select name="db" onchange="this.form.submit();"><option value="">(<?php echo lang('database'); ?> )</option> <?php if (!isset($_SESSION["databases"][$_GET["server"]])) { flush(); $_SESSION["databases"][$_GET["server"]] = get_vals("SHOW DATABASES"); } echo optionlist($_SESSION["databases"][$_GET["server"]], $_GET["db"]); ?> </select> <?php if (isset($_GET["sql"])) { ?> <input type="hidden" name="sql" value="" /><?php } if (isset($_GET["schema"])) { ?> <input type="hidden" name="schema" value="" /><?php } ?> </p> <noscript><p><input type="submit" value="<?php echo lang('Use'); ?> " /></p></noscript> </form> <?php if ($missing != "db" && strlen($_GET["db"])) { $result = $mysql->query("SHOW TABLE STATUS"); if (!$result->num_rows) { echo "<p class='message'>" . lang('No tables.') . "</p>\n"; } else { echo "<p>\n"; while ($row = $result->fetch_assoc()) { echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row["Name"]) . '" title="' . ($row["Engine"] == "MyISAM" ? lang('%d row(s)', $row["Rows"]) : lang('around %d row(s)', $row["Rows"])) . '">' . lang('select') . '</a> '; echo '<a href="' . htmlspecialchars($SELF) . (isset($row["Engine"]) ? 'table' : 'view') . '=' . urlencode($row["Name"]) . '" title="' . (isset($row["Engine"]) ? htmlspecialchars($row["Engine"]) : lang('View')) . '">' . htmlspecialchars($row["Name"]) . "</a><br />\n"; } echo "</p>\n"; } echo '<p><a href="' . htmlspecialchars($SELF) . 'create=">' . lang('Create new table') . "</a></p>\n"; $result->free(); } } ?> </div> </body> </html> <?php }
echo '<thead><tr><th>' . lang('Name') . '<td>' . lang('Type') . '<td>' . lang('Return type') . "<td> </thead>\n"; odd(''); foreach ($routines as $row) { echo '<tr' . odd() . '>'; echo '<th><a href="' . h(ME) . ($row["ROUTINE_TYPE"] != "PROCEDURE" ? 'callf=' : 'call=') . urlencode($row["ROUTINE_NAME"]) . '">' . h($row["ROUTINE_NAME"]) . '</a>'; echo '<td>' . h($row["ROUTINE_TYPE"]); echo '<td>' . h($row["DTD_IDENTIFIER"]); echo '<td><a href="' . h(ME) . ($row["ROUTINE_TYPE"] != "PROCEDURE" ? 'function=' : 'procedure=') . urlencode($row["ROUTINE_NAME"]) . '">' . lang('Alter') . "</a>"; } echo "</table>\n"; } echo '<p class="links">' . (support("procedure") ? '<a href="' . h(ME) . 'procedure=">' . lang('Create procedure') . '</a>' : '') . '<a href="' . h(ME) . 'function=">' . lang('Create function') . "</a>\n"; } if (support("sequence")) { echo "<h3 id='sequences'>" . lang('Sequences') . "</h3>\n"; $sequences = get_vals("SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = current_schema()"); if ($sequences) { echo "<table cellspacing='0'>\n"; echo "<thead><tr><th>" . lang('Name') . "</thead>\n"; odd(''); foreach ($sequences as $val) { echo "<tr" . odd() . "><th><a href='" . h(ME) . "sequence=" . urlencode($val) . "'>" . h($val) . "</a>\n"; } echo "</table>\n"; } echo "<p class='links'><a href='" . h(ME) . "sequence='>" . lang('Create sequence') . "</a>\n"; } if (support("type")) { echo "<h3 id='user-types'>" . lang('User types') . "</h3>\n"; $user_types = types(); if ($user_types) {
/** Count tables in all databases * @param array * @return array array($db => $tables) */ function count_tables($databases) { $return = array(); foreach ($databases as $db) { $return[$db] = count(get_vals("SHOW TABLES IN " . idf_escape($db))); } return $return; }
<?php $PROCEDURE = $_GET["procedure"]; $routine = isset($_GET["function"]) ? "FUNCTION" : "PROCEDURE"; $row = $_POST; $row["fields"] = (array) $row["fields"]; if ($_POST && !process_fields($row["fields"]) && !$error) { $temp_name = "{$row['name']}_adminer_" . uniqid(); drop_create("DROP {$routine} " . idf_escape($PROCEDURE), create_routine($routine, $row), "DROP {$routine} " . idf_escape($row["name"]), create_routine($routine, array("name" => $temp_name) + $row), "DROP {$routine} " . idf_escape($temp_name), substr(ME, 0, -1), lang('Routine has been dropped.'), lang('Routine has been altered.'), lang('Routine has been created.'), $PROCEDURE, $row["name"]); } page_header($PROCEDURE != "" ? (isset($_GET["function"]) ? lang('Alter function') : lang('Alter procedure')) . ": " . h($PROCEDURE) : (isset($_GET["function"]) ? lang('Create function') : lang('Create procedure')), $error); if (!$_POST && $PROCEDURE != "") { $row = routine($PROCEDURE, $routine); $row["name"] = $PROCEDURE; } $collations = get_vals("SHOW CHARACTER SET"); sort($collations); $routine_languages = routine_languages(); ?> <form action="" method="post" id="form"> <p><?php echo lang('Name'); ?> : <input name="name" value="<?php echo h($row["name"]); ?> " maxlength="64" autocapitalize="off"> <?php echo $routine_languages ? lang('Language') . ": " . html_select("language", $routine_languages, $row["language"]) : ""; ?>