2007-07-04 17:16:44 +00:00
|
|
|
<?php
|
2009-08-29 13:57:50 +00:00
|
|
|
$TABLE = $_GET["indexes"];
|
2010-04-21 12:01:32 +00:00
|
|
|
$index_types = array("PRIMARY", "UNIQUE", "INDEX");
|
2013-04-27 03:04:57 +00:00
|
|
|
$table_status = table_status($TABLE, true);
|
2013-02-20 00:57:04 +00:00
|
|
|
if (eregi("MyISAM|M?aria" . ($connection->server_info >= 5.6 ? "|InnoDB" : ""), $table_status["Engine"])) {
|
2010-04-21 12:01:32 +00:00
|
|
|
$index_types[] = "FULLTEXT";
|
|
|
|
}
|
2009-08-29 13:57:50 +00:00
|
|
|
$indexes = indexes($TABLE);
|
2010-07-14 14:02:50 +00:00
|
|
|
if ($jush == "sqlite") { // doesn't support primary key
|
|
|
|
unset($index_types[0]);
|
|
|
|
unset($indexes[""]);
|
|
|
|
}
|
2013-05-08 15:43:15 +00:00
|
|
|
$row = $_POST;
|
2013-05-02 01:28:04 +00:00
|
|
|
|
2013-07-07 06:35:26 +00:00
|
|
|
if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"]) {
|
2007-07-05 05:09:01 +00:00
|
|
|
$alter = array();
|
2013-05-08 15:43:15 +00:00
|
|
|
foreach ($row["indexes"] as $index) {
|
2011-07-13 13:13:00 +00:00
|
|
|
$name = $index["name"];
|
2007-07-05 05:09:01 +00:00
|
|
|
if (in_array($index["type"], $index_types)) {
|
|
|
|
$columns = array();
|
2007-07-14 07:06:53 +00:00
|
|
|
$lengths = array();
|
2013-06-25 16:42:47 +00:00
|
|
|
$descs = array();
|
2007-07-14 07:06:53 +00:00
|
|
|
$set = array();
|
2007-07-05 05:09:01 +00:00
|
|
|
ksort($index["columns"]);
|
2007-07-14 07:06:53 +00:00
|
|
|
foreach ($index["columns"] as $key => $column) {
|
2010-01-09 23:33:41 +00:00
|
|
|
if ($column != "") {
|
2007-07-14 07:06:53 +00:00
|
|
|
$length = $index["lengths"][$key];
|
2013-06-25 16:42:47 +00:00
|
|
|
$desc = $index["descs"][$key];
|
|
|
|
$set[] = idf_escape($column) . ($length ? "(" . (+$length) . ")" : "") . ($desc ? " DESC" : "");
|
2010-04-21 12:01:32 +00:00
|
|
|
$columns[] = $column;
|
|
|
|
$lengths[] = ($length ? $length : null);
|
2013-06-25 16:42:47 +00:00
|
|
|
$descs[] = $desc;
|
2007-07-05 05:09:01 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-02 01:28:04 +00:00
|
|
|
|
2007-07-05 05:09:01 +00:00
|
|
|
if ($columns) {
|
2011-07-13 13:13:00 +00:00
|
|
|
$existing = $indexes[$name];
|
|
|
|
if ($existing) {
|
2007-07-14 07:13:19 +00:00
|
|
|
ksort($existing["columns"]);
|
|
|
|
ksort($existing["lengths"]);
|
2013-06-25 16:42:47 +00:00
|
|
|
ksort($existing["descs"]);
|
|
|
|
if ($index["type"] == $existing["type"]
|
|
|
|
&& array_values($existing["columns"]) === $columns
|
|
|
|
&& (!$existing["lengths"] || array_values($existing["lengths"]) === $lengths)
|
|
|
|
&& array_values($existing["descs"]) === $descs
|
|
|
|
) {
|
2009-09-11 17:06:45 +00:00
|
|
|
// skip existing index
|
2007-07-05 05:09:01 +00:00
|
|
|
unset($indexes[$name]);
|
2011-07-13 13:13:00 +00:00
|
|
|
continue;
|
2007-07-05 05:09:01 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-13 13:13:00 +00:00
|
|
|
$alter[] = array($index["type"], $name, "(" . implode(", ", $set) . ")");
|
2007-07-05 05:09:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-02 01:28:04 +00:00
|
|
|
|
2009-09-11 17:06:45 +00:00
|
|
|
// drop removed indexes
|
2007-07-05 05:09:01 +00:00
|
|
|
foreach ($indexes as $name => $existing) {
|
2011-07-13 13:13:00 +00:00
|
|
|
$alter[] = array($existing["type"], $name, "DROP");
|
2007-07-05 05:09:01 +00:00
|
|
|
}
|
2008-09-02 08:42:14 +00:00
|
|
|
if (!$alter) {
|
2009-08-29 13:57:50 +00:00
|
|
|
redirect(ME . "table=" . urlencode($TABLE));
|
2007-07-05 05:09:01 +00:00
|
|
|
}
|
2010-04-21 12:01:32 +00:00
|
|
|
queries_redirect(ME . "table=" . urlencode($TABLE), lang('Indexes have been altered.'), alter_indexes($TABLE, $alter));
|
2007-07-04 17:16:44 +00:00
|
|
|
}
|
2009-07-20 12:12:55 +00:00
|
|
|
|
2013-07-05 08:31:53 +00:00
|
|
|
page_header(lang('Indexes'), $error, array("table" => $TABLE), h($TABLE));
|
2007-07-04 17:16:44 +00:00
|
|
|
|
2009-08-29 13:57:50 +00:00
|
|
|
$fields = array_keys(fields($TABLE));
|
2013-05-08 15:43:15 +00:00
|
|
|
if ($_POST["add"]) {
|
|
|
|
foreach ($row["indexes"] as $key => $index) {
|
|
|
|
if ($index["columns"][count($index["columns"])] != "") {
|
|
|
|
$row["indexes"][$key]["columns"][] = "";
|
2007-07-14 07:06:53 +00:00
|
|
|
}
|
2007-07-05 12:01:32 +00:00
|
|
|
}
|
2013-05-08 15:43:15 +00:00
|
|
|
$index = end($row["indexes"]);
|
2013-07-07 06:42:37 +00:00
|
|
|
if ($index["type"] || array_filter($index["columns"], 'strlen')) {
|
2013-05-08 15:43:15 +00:00
|
|
|
$row["indexes"][] = array("columns" => array(1 => ""));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$row) {
|
|
|
|
foreach ($indexes as $key => $index) {
|
|
|
|
$indexes[$key]["name"] = $key;
|
|
|
|
$indexes[$key]["columns"][] = "";
|
2007-07-14 07:06:53 +00:00
|
|
|
}
|
2013-05-08 15:43:15 +00:00
|
|
|
$indexes[] = array("columns" => array(1 => ""));
|
|
|
|
$row["indexes"] = $indexes;
|
2007-07-04 17:16:44 +00:00
|
|
|
}
|
|
|
|
?>
|
2007-07-09 14:47:46 +00:00
|
|
|
|
2007-07-04 17:16:44 +00:00
|
|
|
<form action="" method="post">
|
2010-06-30 15:09:08 +00:00
|
|
|
<table cellspacing="0" class="nowrap">
|
2013-07-10 19:44:03 +00:00
|
|
|
<thead><tr>
|
|
|
|
<th><?php echo lang('Index Type'); ?>
|
|
|
|
<th><input type="submit" style="z-index: -1; position: absolute; height: 0;"><?php echo lang('Column (length)'); ?>
|
|
|
|
<th><?php echo lang('Name'); ?>
|
|
|
|
<th><noscript><input type='image' class='icon' name='add[0]' src='../adminer/static/plus.gif' alt='+' title='<?php echo lang('Add next'); ?>'></noscript>
|
|
|
|
</thead>
|
2007-07-04 17:16:44 +00:00
|
|
|
<?php
|
2010-06-30 15:09:08 +00:00
|
|
|
$j = 1;
|
2007-07-05 04:39:15 +00:00
|
|
|
foreach ($row["indexes"] as $index) {
|
2013-07-07 06:35:26 +00:00
|
|
|
if (!$_POST["drop_col"] || $j != key($_POST["drop_col"])) {
|
|
|
|
echo "<tr><td>" . html_select("indexes[$j][type]", array(-1 => "") + $index_types, $index["type"], ($j == count($row["indexes"]) ? "indexesAddRow(this);" : 1));
|
|
|
|
|
|
|
|
echo "<td>";
|
|
|
|
ksort($index["columns"]);
|
|
|
|
$i = 1;
|
|
|
|
foreach ($index["columns"] as $key => $column) {
|
|
|
|
echo "<span>" . html_select("indexes[$j][columns][$i]", array(-1 => "") + $fields, $column, ($i == count($index["columns"]) ? "indexesAddColumn" : "indexesChangeColumn") . "(this, '" . js_escape($jush == "sql" ? "" : $_GET["indexes"] . "_") . "');");
|
|
|
|
echo ($jush == "sql" || $jush == "mssql" ? "<input type='number' name='indexes[$j][lengths][$i]' class='size' value='" . h($index["lengths"][$key]) . "'>" : "");
|
|
|
|
echo ($jush != "sql" ? checkbox("indexes[$j][descs][$i]", 1, $index["descs"][$key], lang('descending')) : "");
|
|
|
|
echo " </span>";
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "<td><input name='indexes[$j][name]' value='" . h($index["name"]) . "' autocapitalize='off'>\n";
|
|
|
|
echo "<td><input type='image' class='icon' name='drop_col[$j]' src='../adminer/static/cross.gif' alt='x' title='" . lang('Remove') . "' onclick=\"return !editingRemoveRow(this, 'indexes\$1[type]');\">\n";
|
2007-07-04 17:16:44 +00:00
|
|
|
}
|
2007-07-14 07:06:53 +00:00
|
|
|
$j++;
|
2007-07-04 17:16:44 +00:00
|
|
|
}
|
|
|
|
?>
|
|
|
|
</table>
|
2007-07-11 13:56:28 +00:00
|
|
|
<p>
|
2009-07-11 20:30:40 +00:00
|
|
|
<input type="submit" value="<?php echo lang('Save'); ?>">
|
2011-03-08 12:43:05 +00:00
|
|
|
<input type="hidden" name="token" value="<?php echo $token; ?>">
|
2007-07-04 17:16:44 +00:00
|
|
|
</form>
|