$column) { if (strlen($column)) { $length = $index["lengths"][$key]; $set[] = idf_escape($column) . ($length ? "(" . intval($length) . ")" : ""); $columns[count($columns) + 1] = $column; $lengths[count($lengths) + 1] = ($length ? $length : null); } } if ($columns) { foreach ($indexes as $name => $existing) { ksort($existing["columns"]); ksort($existing["lengths"]); if ($index["type"] == $existing["type"] && $existing["columns"] === $columns && $existing["lengths"] === $lengths) { // skip existing index unset($indexes[$name]); continue 2; } } $alter[] = "\nADD $index[type]" . ($index["type"] == "PRIMARY" ? " KEY" : "") . " (" . implode(", ", $set) . ")"; } } } // drop removed indexes foreach ($indexes as $name => $existing) { $alter[] = "\nDROP INDEX " . idf_escape($name); } if (!$alter) { redirect(ME . "table=" . urlencode($TABLE)); } query_redirect("ALTER TABLE " . idf_escape($TABLE) . implode(",", $alter), ME . "table=" . urlencode($TABLE), lang('Indexes have been altered.')); } page_header(lang('Indexes'), $error, array("table" => $TABLE), $TABLE); $fields = array_keys(fields($TABLE)); $row = array("indexes" => $indexes); if ($_POST) { $row = $_POST; if ($_POST["add"]) { foreach ($row["indexes"] as $key => $index) { if (strlen($index["columns"][count($index["columns"])])) { $row["indexes"][$key]["columns"][] = ""; } } $index = end($row["indexes"]); if ($index["type"] || array_filter($index["columns"], 'strlen') || array_filter($index["lengths"], 'strlen')) { $row["indexes"][] = array("columns" => array(1 => "")); } } } else { foreach ($row["indexes"] as $key => $index) { $row["indexes"][$key]["columns"][] = ""; } $row["indexes"][] = array("columns" => array(1 => "")); } ?>
" . html_select("indexes[$j][type]", array(-1 => "") + $index_types, $index["type"], ($j == count($row["indexes"]) - 1 ? "indexesAddRow(this);" : 1)) . "\n"; ksort($index["columns"]); foreach ($index["columns"] as $i => $column) { echo "" . html_select("indexes[$j][columns][$i]", array(-1 => "") + $fields, $column, ($i == count($index["columns"]) ? "indexesAddColumn(this);" : 1)); echo " \n"; } echo "\n"; $j++; } ?>