/wp-content/plugins/adminer/inc/adminer/indexes.inc.php

https://gitlab.com/Blueprint-Marketing/interoccupy.net · PHP · 104 lines · 99 code · 3 blank · 2 comment · 27 complexity · e9d6851a7b3e58ef8b410046d44b0775 MD5 · raw file

  1. <?php
  2. $TABLE = $_GET["indexes"];
  3. $index_types = array("PRIMARY", "UNIQUE", "INDEX");
  4. $table_status = table_status($TABLE);
  5. if (eregi("MyISAM|M?aria", $table_status["Engine"])) {
  6. $index_types[] = "FULLTEXT";
  7. }
  8. $indexes = indexes($TABLE);
  9. if ($jush == "sqlite") { // doesn't support primary key
  10. unset($index_types[0]);
  11. unset($indexes[""]);
  12. }
  13. if ($_POST && !$error && !$_POST["add"]) {
  14. $alter = array();
  15. foreach ($_POST["indexes"] as $index) {
  16. $name = $index["name"];
  17. if (in_array($index["type"], $index_types)) {
  18. $columns = array();
  19. $lengths = array();
  20. $set = array();
  21. ksort($index["columns"]);
  22. foreach ($index["columns"] as $key => $column) {
  23. if ($column != "") {
  24. $length = $index["lengths"][$key];
  25. $set[] = idf_escape($column) . ($length ? "(" . (+$length) . ")" : "");
  26. $columns[] = $column;
  27. $lengths[] = ($length ? $length : null);
  28. }
  29. }
  30. if ($columns) {
  31. $existing = $indexes[$name];
  32. if ($existing) {
  33. ksort($existing["columns"]);
  34. ksort($existing["lengths"]);
  35. if ($index["type"] == $existing["type"] && array_values($existing["columns"]) === $columns && (!$existing["lengths"] || array_values($existing["lengths"]) === $lengths)) {
  36. // skip existing index
  37. unset($indexes[$name]);
  38. continue;
  39. }
  40. }
  41. $alter[] = array($index["type"], $name, "(" . implode(", ", $set) . ")");
  42. }
  43. }
  44. }
  45. // drop removed indexes
  46. foreach ($indexes as $name => $existing) {
  47. $alter[] = array($existing["type"], $name, "DROP");
  48. }
  49. if (!$alter) {
  50. redirect(ME . "table=" . urlencode($TABLE));
  51. }
  52. queries_redirect(ME . "table=" . urlencode($TABLE), lang('Indexes have been altered.'), alter_indexes($TABLE, $alter));
  53. }
  54. page_header(lang('Indexes'), $error, array("table" => $TABLE), $TABLE);
  55. $fields = array_keys(fields($TABLE));
  56. $row = array("indexes" => $indexes);
  57. if ($_POST) {
  58. $row = $_POST;
  59. if ($_POST["add"]) {
  60. foreach ($row["indexes"] as $key => $index) {
  61. if ($index["columns"][count($index["columns"])] != "") {
  62. $row["indexes"][$key]["columns"][] = "";
  63. }
  64. }
  65. $index = end($row["indexes"]);
  66. if ($index["type"] || array_filter($index["columns"], 'strlen') || array_filter($index["lengths"], 'strlen')) {
  67. $row["indexes"][] = array("columns" => array(1 => ""));
  68. }
  69. }
  70. } else {
  71. foreach ($row["indexes"] as $key => $index) {
  72. $row["indexes"][$key]["name"] = $key;
  73. $row["indexes"][$key]["columns"][] = "";
  74. }
  75. $row["indexes"][] = array("columns" => array(1 => ""));
  76. }
  77. ?>
  78. <form action="" method="post">
  79. <table cellspacing="0" class="nowrap">
  80. <thead><tr><th><?php echo lang('Index Type'); ?><th><?php echo lang('Column (length)'); ?><th><?php echo lang('Name'); ?></thead>
  81. <?php
  82. $j = 1;
  83. foreach ($row["indexes"] as $index) {
  84. echo "<tr><td>" . html_select("indexes[$j][type]", array(-1 => "") + $index_types, $index["type"], ($j == count($row["indexes"]) ? "indexesAddRow(this);" : 1)) . "<td>";
  85. ksort($index["columns"]);
  86. $i = 1;
  87. foreach ($index["columns"] as $key => $column) {
  88. echo "<span>" . html_select("indexes[$j][columns][$i]", array(-1 => "") + $fields, $column, ($i == count($index["columns"]) ? "indexesAddColumn" : "indexesChangeColumn") . "(this, '" . js_adminer_escape($jush == "sql" ? "" : $_GET["indexes"] . "_") . "');");
  89. echo "<input name='indexes[$j][lengths][$i]' size='2' value='" . h($index["lengths"][$key]) . "'> </span>"; //! hide for non-MySQL drivers, add ASC|DESC
  90. $i++;
  91. }
  92. echo "<td><input name='indexes[$j][name]' value='" . h($index["name"]) . "'>\n";
  93. $j++;
  94. }
  95. ?>
  96. </table>
  97. <p>
  98. <input type="submit" value="<?php echo lang('Save'); ?>">
  99. <noscript><p><input type="submit" name="add" value="<?php echo lang('Add next'); ?>"></noscript>
  100. <input type="hidden" name="token" value="<?php echo $token; ?>">
  101. </form>