2007-07-02 20:21:30 +00:00
|
|
|
<?php
|
2007-07-09 06:12:22 +00:00
|
|
|
if ($_POST && !$error) {
|
2007-07-02 20:21:30 +00:00
|
|
|
if ($_POST["drop"]) {
|
|
|
|
if (mysql_query("DROP DATABASE " . idf_escape($_GET["db"]))) {
|
2007-07-03 06:48:18 +00:00
|
|
|
redirect(substr(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF), 0, -1), lang('Database has been dropped.'));
|
2007-07-02 20:21:30 +00:00
|
|
|
}
|
|
|
|
} elseif ($_GET["db"] !== $_POST["name"]) {
|
|
|
|
if (mysql_query("CREATE DATABASE " . idf_escape($_POST["name"]) . ($_POST["collation"] ? " COLLATE '" . mysql_real_escape_string($_POST["collation"]) . "'" : ""))) {
|
|
|
|
if (!strlen($_GET["db"])) {
|
2007-07-03 06:48:18 +00:00
|
|
|
redirect(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF) . "db=" . urlencode($_POST["name"]), lang('Database has been created.'));
|
2007-07-02 20:21:30 +00:00
|
|
|
}
|
|
|
|
$result = mysql_query("SHOW TABLES");
|
|
|
|
while ($row = mysql_fetch_row($result)) {
|
|
|
|
if (!mysql_query("RENAME TABLE " . idf_escape($row[0]) . " TO " . idf_escape($_POST["name"]) . "." . idf_escape($row[0]))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mysql_free_result($result);
|
|
|
|
if (!$row) {
|
|
|
|
mysql_query("DROP DATABASE " . idf_escape($_GET["db"]));
|
2007-07-03 06:48:18 +00:00
|
|
|
redirect(preg_replace('~(\\?)db=[^&]*&|&db=[^&]*~', '\\1', $SELF) . "db=" . urlencode($_POST["name"]), lang('Database has been renamed.'));
|
2007-07-02 20:21:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif (!$_POST["collation"] || mysql_query("ALTER DATABASE " . idf_escape($_POST["name"]) . " COLLATE '" . mysql_real_escape_string($_POST["collation"]) . "'")) {
|
2007-07-03 06:48:18 +00:00
|
|
|
redirect(substr($SELF, 0, -1), ($_POST["collation"] ? lang('Database has been altered.') : null));
|
2007-07-02 20:21:30 +00:00
|
|
|
}
|
2007-07-06 13:00:58 +00:00
|
|
|
$error = mysql_error();
|
2007-07-02 20:21:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
page_header(strlen($_GET["db"]) ? lang('Alter database') . ": " . htmlspecialchars($_GET["db"]) : lang('Create database'));
|
|
|
|
|
|
|
|
if ($_POST) {
|
|
|
|
echo "<p class='error'>" . lang('Unable to operate database') . ": " . htmlspecialchars($error) . "</p>\n";
|
|
|
|
$name = $_POST["name"];
|
2007-07-06 13:00:58 +00:00
|
|
|
$collate = $_POST["collation"];
|
2007-07-02 20:21:30 +00:00
|
|
|
} else {
|
|
|
|
$name = $_GET["db"];
|
2007-07-06 13:00:58 +00:00
|
|
|
$collate = array();
|
|
|
|
if (strlen($_GET["db"]) && ($result = mysql_query("SHOW CREATE DATABASE " . idf_escape($_GET["db"])))) {
|
|
|
|
if (preg_match('~ COLLATE ([^ ]+)~', mysql_result($result, 0, 1), $match)) {
|
|
|
|
$collate = $match[1];
|
|
|
|
}
|
|
|
|
mysql_free_result($result);
|
|
|
|
}
|
2007-07-02 20:21:30 +00:00
|
|
|
}
|
|
|
|
?>
|
2007-07-09 14:47:46 +00:00
|
|
|
|
2007-07-02 20:21:30 +00:00
|
|
|
<form action="" method="post"><div>
|
|
|
|
<input name="name" value="<?php echo htmlspecialchars($name); ?>" maxlength="64" />
|
|
|
|
<select name="collation"><option value="">(<?php echo lang('collation'); ?>)</option><?php echo optionlist(collations(), $collate, "not_vals"); ?></select>
|
2007-07-09 06:12:22 +00:00
|
|
|
<input type="hidden" name="token" value="<?php echo $token; ?>" />
|
2007-07-02 20:21:30 +00:00
|
|
|
<input type="submit" value="<?php echo lang('Save'); ?>" />
|
|
|
|
<?php if (strlen($_GET["db"])) { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>" /><?php } ?>
|
|
|
|
</div></form>
|