2007-07-04 17:16:44 +00:00
|
|
|
<?php
|
2009-08-29 13:57:50 +00:00
|
|
|
$TABLE = $_GET["indexes"];
|
2007-07-04 17:16:44 +00:00
|
|
|
$index_types = array("PRIMARY", "UNIQUE", "INDEX", "FULLTEXT");
|
2009-08-29 13:57:50 +00:00
|
|
|
$indexes = indexes($TABLE);
|
2007-07-09 06:12:22 +00:00
|
|
|
if ($_POST && !$error && !$_POST["add"]) {
|
2007-07-05 05:09:01 +00:00
|
|
|
$alter = array();
|
|
|
|
foreach ($_POST["indexes"] as $index) {
|
|
|
|
if (in_array($index["type"], $index_types)) {
|
|
|
|
$columns = array();
|
2007-07-14 07:06:53 +00:00
|
|
|
$lengths = array();
|
|
|
|
$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) {
|
|
|
|
if (strlen($column)) {
|
|
|
|
$length = $index["lengths"][$key];
|
|
|
|
$set[] = idf_escape($column) . ($length ? "(" . intval($length) . ")" : "");
|
2007-07-05 05:09:01 +00:00
|
|
|
$columns[count($columns) + 1] = $column;
|
2007-07-14 07:06:53 +00:00
|
|
|
$lengths[count($lengths) + 1] = ($length ? $length : null);
|
2007-07-05 05:09:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($columns) {
|
|
|
|
foreach ($indexes as $name => $existing) {
|
2007-07-14 07:13:19 +00:00
|
|
|
ksort($existing["columns"]);
|
|
|
|
ksort($existing["lengths"]);
|
2007-07-14 07:06:53 +00:00
|
|
|
if ($index["type"] == $existing["type"] && $existing["columns"] === $columns && $existing["lengths"] === $lengths) {
|
2009-09-11 17:06:45 +00:00
|
|
|
// skip existing index
|
2007-07-05 05:09:01 +00:00
|
|
|
unset($indexes[$name]);
|
|
|
|
continue 2;
|
|
|
|
}
|
|
|
|
}
|
2009-06-05 08:30:21 +00:00
|
|
|
$alter[] = "\nADD $index[type]" . ($index["type"] == "PRIMARY" ? " KEY" : "") . " (" . implode(", ", $set) . ")";
|
2007-07-05 05:09:01 +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) {
|
2009-06-05 08:30:21 +00:00
|
|
|
$alter[] = "\nDROP INDEX " . idf_escape($name);
|
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
|
|
|
}
|
2009-08-29 13:57:50 +00:00
|
|
|
query_redirect("ALTER TABLE " . idf_escape($TABLE) . implode(",", $alter), ME . "table=" . urlencode($TABLE), lang('Indexes have been altered.'));
|
2007-07-04 17:16:44 +00:00
|
|
|
}
|
2009-07-20 12:12:55 +00:00
|
|
|
|
2009-08-29 13:57:50 +00:00
|
|
|
page_header(lang('Indexes'), $error, array("table" => $TABLE), $TABLE);
|
2007-07-04 17:16:44 +00:00
|
|
|
|
2009-08-29 13:57:50 +00:00
|
|
|
$fields = array_keys(fields($TABLE));
|
2008-07-10 15:39:24 +00:00
|
|
|
$row = array("indexes" => $indexes);
|
2007-07-04 17:16:44 +00:00
|
|
|
if ($_POST) {
|
2007-07-14 07:06:53 +00:00
|
|
|
$row = $_POST;
|
2008-03-18 10:29:20 +00:00
|
|
|
if ($_POST["add"]) {
|
2007-07-14 07:06:53 +00:00
|
|
|
foreach ($row["indexes"] as $key => $index) {
|
|
|
|
if (strlen($index["columns"][count($index["columns"])])) {
|
|
|
|
$row["indexes"][$key]["columns"][] = "";
|
|
|
|
}
|
|
|
|
}
|
2007-08-04 19:37:22 +00:00
|
|
|
$index = end($row["indexes"]);
|
2007-07-14 07:13:19 +00:00
|
|
|
if ($index["type"] || array_filter($index["columns"], 'strlen') || array_filter($index["lengths"], 'strlen')) {
|
2007-07-14 07:06:53 +00:00
|
|
|
$row["indexes"][] = array("columns" => array(1 => ""));
|
|
|
|
}
|
2007-07-05 12:01:32 +00:00
|
|
|
}
|
2007-07-04 17:16:44 +00:00
|
|
|
} else {
|
2007-07-14 07:06:53 +00:00
|
|
|
foreach ($row["indexes"] as $key => $index) {
|
|
|
|
$row["indexes"][$key]["columns"][] = "";
|
|
|
|
}
|
|
|
|
$row["indexes"][] = array("columns" => array(1 => ""));
|
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">
|
2009-05-01 10:41:33 +00:00
|
|
|
<table cellspacing="0">
|
2009-07-11 20:30:40 +00:00
|
|
|
<thead><tr><th><?php echo lang('Index Type'); ?><th><?php echo lang('Column (length)'); ?></thead>
|
2007-07-04 17:16:44 +00:00
|
|
|
<?php
|
|
|
|
$j = 0;
|
2007-07-05 04:39:15 +00:00
|
|
|
foreach ($row["indexes"] as $index) {
|
2009-10-02 13:21:34 +00:00
|
|
|
echo "<tr><td>" . html_select("indexes[$j][type]", array(-1 => "") + $index_types, $index["type"], ($j == count($row["indexes"]) - 1 ? "indexes_add_row(this);" : 1)) . "<td>\n";
|
2007-07-14 07:06:53 +00:00
|
|
|
ksort($index["columns"]);
|
|
|
|
foreach ($index["columns"] as $i => $column) {
|
2009-10-02 13:21:34 +00:00
|
|
|
echo "<span>" . html_select("indexes[$j][columns][$i]", array(-1 => "") + $fields, $column, ($i == count($index["columns"]) ? "indexes_add_column(this);" : 1));
|
2009-07-28 16:20:50 +00:00
|
|
|
echo "<input name='indexes[$j][lengths][$i]' size='2' value='" . h($index["lengths"][$i]) . "'> </span>\n";
|
2007-07-04 17:16:44 +00:00
|
|
|
}
|
2009-07-11 20:30:40 +00:00
|
|
|
echo "\n";
|
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="hidden" name="token" value="<?php echo $token; ?>">
|
|
|
|
<input type="submit" value="<?php echo lang('Save'); ?>">
|
|
|
|
<noscript><p><input type="submit" name="add" value="<?php echo lang('Add next'); ?>"></noscript>
|
2007-07-04 17:16:44 +00:00
|
|
|
</form>
|