Views manipulation

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@186 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2007-07-16 12:17:16 +00:00
parent 91738b900b
commit 1461a77f34
4 changed files with 43 additions and 0 deletions

32
createv.inc.php Normal file
View file

@ -0,0 +1,32 @@
<?php
if ($_POST && !$error) {
if (strlen($_GET["createv"]) && $mysql->query("DROP VIEW " . idf_escape($_GET["createv"])) && $_POST["drop"]) {
redirect(substr($SELF, 0, -1), lang('View has been dropped.'));
}
if (!$_POST["drop"] && $mysql->query("CREATE VIEW " . idf_escape($_POST["name"]) . " AS " . $_POST["select"])) {
redirect($SELF . "view=" . urlencode($_POST["name"]), (strlen($_GET["createv"]) ? lang('View has been altered.') : lang('View has been created.')));
}
$error = $mysql->error;
}
page_header(strlen($_GET["createv"]) ? lang('Alter view') . ": " . htmlspecialchars($_GET["createv"]) : lang('Create view'));
if ($_POST) {
$row = $_POST;
echo "<p class='error'>" . lang('Unable to operate view') . ": " . htmlspecialchars($error) . "</p>\n";
} elseif (strlen($_GET["createv"])) {
$row = array("name" => $_GET["createv"], "select" => preg_replace('~^.* AS ~U', '', $mysql->result($mysql->query("SHOW CREATE VIEW " . idf_escape($_GET["createv"])), 1)));
} else {
$row = array();
}
?>
<form action="" method="post">
<p><textarea name="select" rows="10" cols="80" style="width: 100%;"><?php echo htmlspecialchars($row["select"]); ?></textarea></p>
<p>
<input type="hidden" name="token" value="<?php echo $token; ?>" />
<?php echo lang('Name'); ?>: <input name="name" value="<?php echo htmlspecialchars($row["name"]); ?>" maxlength="64" />
<input type="submit" value="<?php echo lang('Save'); ?>" />
<?php if (strlen($_GET["createv"])) { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>" /><?php } ?>
</p>
</form>

View file

@ -62,6 +62,8 @@ if (isset($_GET["dump"])) {
include "./call.inc.php";
} elseif (isset($_GET["foreign"])) {
include "./foreign.inc.php";
} elseif (isset($_GET["createv"])) {
include "./createv.inc.php";
} else {
$TOKENS = array();
page_header(htmlspecialchars(lang('Database') . ": " . $_GET["db"]));
@ -81,6 +83,7 @@ if (isset($_GET["dump"])) {
echo "</table>\n";
}
$result->free();
echo '<p><a href="' . htmlspecialchars($SELF) . 'createv=">' . lang('Create view') . "</a></p>\n";
}
}
}

View file

@ -122,6 +122,13 @@ function lang($idf = null, $number = null) {
'ON UPDATE' => 'ON UPDATE',
'Index Type' => 'Typ indexu',
'Column (length)' => 'Sloupec (délka)',
'View has been dropped.' => 'Pohled byl odstraněn.',
'View has been altered.' => 'Pohled byl změněn.',
'View has been created.' => 'Pohled byl vytvořen.',
'Alter view' => 'Pozměnit pohled',
'Create view' => 'Vytvořit pohled',
'Unable to operate view' => 'Nepodařilo se zpracovat pohled',
'Name' => 'Název',
),
);
if (!isset($idf)) {

View file

@ -1,3 +1,4 @@
<?php
page_header(lang('View') . ": " . htmlspecialchars($_GET["view"]));
echo "<pre class='jush-sql'>" . htmlspecialchars(preg_replace('~^.* AS ~U', '', $mysql->result($mysql->query("SHOW CREATE VIEW " . idf_escape($_GET["view"])), 1))) . "</pre>\n";
echo '<p><a href="' . htmlspecialchars($SELF) . 'createv=' . urlencode($_GET["view"]) . '">' . lang('Alter view') . "</a></p>\n";