2007-07-02 15:50:23 +00:00
|
|
|
<?php
|
2009-08-29 13:57:50 +00:00
|
|
|
$TABLE = $_GET["view"];
|
2013-05-08 14:55:08 +00:00
|
|
|
$row = $_POST;
|
2017-02-20 11:13:09 +00:00
|
|
|
$orig_type = "VIEW";
|
|
|
|
if ($jush == "pgsql" && $TABLE != "") {
|
|
|
|
$status = table_status($TABLE);
|
|
|
|
$orig_type = strtoupper($status["Engine"]);
|
|
|
|
}
|
2013-01-31 07:40:26 +00:00
|
|
|
|
2013-05-08 14:55:08 +00:00
|
|
|
if ($_POST && !$error) {
|
|
|
|
$name = trim($row["name"]);
|
|
|
|
$as = " AS\n$row[select]";
|
2013-05-13 18:12:28 +00:00
|
|
|
$location = ME . "table=" . urlencode($name);
|
|
|
|
$message = lang('View has been altered.');
|
2014-05-10 01:57:35 +00:00
|
|
|
|
2017-02-20 11:13:09 +00:00
|
|
|
$type = ($_POST["materialized"] ? "MATERIALIZED VIEW" : "VIEW");
|
2014-05-10 01:57:35 +00:00
|
|
|
|
2017-02-20 11:13:09 +00:00
|
|
|
if (!$_POST["drop"] && $TABLE == $name && $jush != "sqlite" && $type == "VIEW" && $orig_type == "VIEW") {
|
2013-05-13 18:12:28 +00:00
|
|
|
query_redirect(($jush == "mssql" ? "ALTER" : "CREATE OR REPLACE") . " VIEW " . table($name) . $as, $location, $message);
|
|
|
|
} else {
|
|
|
|
$temp_name = $name . "_adminer_" . uniqid();
|
|
|
|
drop_create(
|
2017-02-20 11:13:09 +00:00
|
|
|
"DROP $orig_type " . table($TABLE),
|
2014-05-10 01:57:35 +00:00
|
|
|
"CREATE $type " . table($name) . $as,
|
|
|
|
"DROP $type " . table($name),
|
|
|
|
"CREATE $type " . table($temp_name) . $as,
|
|
|
|
"DROP $type " . table($temp_name),
|
2013-05-13 18:12:28 +00:00
|
|
|
($_POST["drop"] ? substr(ME, 0, -1) : $location),
|
|
|
|
lang('View has been dropped.'),
|
|
|
|
$message,
|
|
|
|
lang('View has been created.'),
|
|
|
|
$TABLE,
|
|
|
|
$name
|
|
|
|
);
|
|
|
|
}
|
2009-07-24 06:05:21 +00:00
|
|
|
}
|
2009-07-20 12:12:55 +00:00
|
|
|
|
2013-05-08 14:55:08 +00:00
|
|
|
if (!$_POST && $TABLE != "") {
|
|
|
|
$row = view($TABLE);
|
|
|
|
$row["name"] = $TABLE;
|
2017-02-20 11:13:09 +00:00
|
|
|
$row["materialized"] = ($orig_type != "VIEW");
|
2013-06-24 16:08:26 +00:00
|
|
|
if (!$error) {
|
2015-01-09 19:32:05 +00:00
|
|
|
$error = error();
|
2013-06-24 16:08:26 +00:00
|
|
|
}
|
2013-05-08 14:55:08 +00:00
|
|
|
}
|
2013-06-24 16:08:26 +00:00
|
|
|
|
2013-07-05 08:31:53 +00:00
|
|
|
page_header(($TABLE != "" ? lang('Alter view') : lang('Create view')), $error, array("table" => $TABLE), h($TABLE));
|
2009-07-24 06:05:21 +00:00
|
|
|
?>
|
|
|
|
|
|
|
|
<form action="" method="post">
|
2013-01-31 05:35:51 +00:00
|
|
|
<p><?php echo lang('Name'); ?>: <input name="name" value="<?php echo h($row["name"]); ?>" maxlength="64" autocapitalize="off">
|
2017-02-20 11:13:09 +00:00
|
|
|
<?php echo (support("materializedview") ? " " . checkbox("materialized", 1, $row["materialized"], lang('Materialized view')) : ""); ?>
|
2010-04-26 16:22:24 +00:00
|
|
|
<p><?php textarea("select", $row["select"]); ?>
|
2009-07-24 06:05:21 +00:00
|
|
|
<p>
|
|
|
|
<input type="submit" value="<?php echo lang('Save'); ?>">
|
2018-01-12 13:43:55 +00:00
|
|
|
<?php if ($_GET["view"] != "") { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>"><?php echo confirm(); ?><?php } ?>
|
2011-03-08 12:43:05 +00:00
|
|
|
<input type="hidden" name="token" value="<?php echo $token; ?>">
|
2009-07-24 06:05:21 +00:00
|
|
|
</form>
|