2007-07-04 17:16:44 +00:00
|
|
|
<?php
|
|
|
|
$index_types = array("PRIMARY", "UNIQUE", "INDEX", "FULLTEXT");
|
2007-07-05 05:09:01 +00:00
|
|
|
$indexes = indexes($_GET["indexes"]);
|
|
|
|
$fields = array_keys(fields($_GET["indexes"]));
|
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();
|
|
|
|
ksort($index["columns"]);
|
|
|
|
foreach ($index["columns"] as $column) {
|
|
|
|
if (in_array($column, $fields, true)) {
|
|
|
|
$columns[count($columns) + 1] = $column;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($columns) {
|
|
|
|
foreach ($indexes as $name => $existing) {
|
|
|
|
if ($index["type"] == $existing["type"] && $existing["columns"] == $columns) {
|
|
|
|
unset($indexes[$name]);
|
|
|
|
continue 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$alter[] = "ADD $index[type]" . ($index["type"] == "PRIMARY" ? " KEY" : "") . " (" . implode(", ", array_map('idf_escape', $columns)) . ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($indexes as $name => $existing) {
|
|
|
|
$alter[] = "DROP INDEX " . idf_escape($name);
|
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
if (!$alter || $mysql->query("ALTER TABLE " . idf_escape($_GET["indexes"]) . " " . implode(", ", $alter))) {
|
2007-07-05 05:09:01 +00:00
|
|
|
redirect($SELF . "table=" . urlencode($_GET["indexes"]), ($alter ? lang('Indexes has been altered.') : null));
|
|
|
|
}
|
2007-07-10 13:30:42 +00:00
|
|
|
$error = $mysql->error;
|
2007-07-04 17:16:44 +00:00
|
|
|
}
|
|
|
|
page_header(lang('Indexes') . ': ' . htmlspecialchars($_GET["indexes"]));
|
|
|
|
|
|
|
|
if ($_POST) {
|
2007-07-05 12:01:32 +00:00
|
|
|
if (!$_POST["add"]) {
|
|
|
|
echo "<p class='error'>" . lang('Unable to operate indexes') . ": " . htmlspecialchars($error) . "</p>\n";
|
|
|
|
}
|
2007-07-04 17:16:44 +00:00
|
|
|
$row = $_POST;
|
|
|
|
} else {
|
2007-07-05 05:09:01 +00:00
|
|
|
$row = array("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">
|
|
|
|
<table border="0" cellspacing="0" cellpadding="2">
|
|
|
|
<?php
|
|
|
|
$j = 0;
|
2007-07-05 04:39:15 +00:00
|
|
|
foreach ($row["indexes"] as $index) {
|
2007-07-05 12:01:32 +00:00
|
|
|
if ($index["type"] || array_filter($index["columns"], 'strlen')) {
|
|
|
|
echo "<tr><td><select name='indexes[$j][type]'><option></option>" . optionlist($index_types, $index["type"], "not_vals") . "</select></td><td>";
|
|
|
|
ksort($index["columns"]);
|
|
|
|
foreach ($index["columns"] as $i => $column) {
|
|
|
|
if (strlen($column)) {
|
|
|
|
echo "<select name='indexes[$j][columns][$i]'><option></option>" . optionlist($fields, $column, "not_vals") . "</select>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo "<select name='indexes[$j][columns][" . ($i+1) . "]'><option></option>" . optionlist($fields, array(), "not_vals") . "</select>";
|
|
|
|
echo "</td></tr>\n";
|
|
|
|
$j++;
|
2007-07-04 17:16:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//! JavaScript for adding more indexes and columns
|
|
|
|
?>
|
|
|
|
<tr><td><select name="indexes[<?php echo $j; ?>][type]"><option></option><?php echo optionlist($index_types, array(), "not_vals"); ?></select></td><td><select name="indexes[<?php echo $j; ?>][columns][1]"><option></option><?php echo optionlist($fields, array(), "not_vals"); ?></select></td></tr>
|
|
|
|
</table>
|
2007-07-11 13:56:28 +00:00
|
|
|
<p>
|
2007-07-11 21:06:19 +00:00
|
|
|
<input type="hidden" name="token" value="<?php echo $token; ?>" />
|
|
|
|
<input type="submit" value="<?php echo lang('Alter indexes'); ?>" />
|
2007-07-11 13:56:28 +00:00
|
|
|
<input type="submit" name="add" value="<?php echo lang('Add next'); ?>" />
|
|
|
|
</p>
|
2007-07-04 17:16:44 +00:00
|
|
|
</form>
|