PageRenderTime 48ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/system/application/third_party/adminer/adminer/indexes.inc.php

https://gitlab.com/sylver.gocloud/gocloudasia-college-system-framework
PHP | 140 lines | 130 code | 8 blank | 2 comment | 34 complexity | 8680fac1d9c2846c1e22ccbaba706563 MD5 | raw file
  1. <?php
  2. $TABLE = $_GET["indexes"];
  3. $index_types = array("PRIMARY", "UNIQUE", "INDEX");
  4. $table_status = table_status($TABLE, true);
  5. if (preg_match('~MyISAM|M?aria' . ($connection->server_info >= 5.6 ? '|InnoDB' : '') . '~i', $table_status["Engine"])) {
  6. $index_types[] = "FULLTEXT";
  7. }
  8. $indexes = indexes($TABLE);
  9. $primary = array();
  10. if ($jush == "mongo") { // doesn't support primary key
  11. $primary = $indexes["_id_"];
  12. unset($index_types[0]);
  13. unset($indexes["_id_"]);
  14. }
  15. $row = $_POST;
  16. if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"]) {
  17. $alter = array();
  18. foreach ($row["indexes"] as $index) {
  19. $name = $index["name"];
  20. if (in_array($index["type"], $index_types)) {
  21. $columns = array();
  22. $lengths = array();
  23. $descs = array();
  24. $set = array();
  25. ksort($index["columns"]);
  26. foreach ($index["columns"] as $key => $column) {
  27. if ($column != "") {
  28. $length = $index["lengths"][$key];
  29. $desc = $index["descs"][$key];
  30. $set[] = idf_escape($column) . ($length ? "(" . (+$length) . ")" : "") . ($desc ? " DESC" : "");
  31. $columns[] = $column;
  32. $lengths[] = ($length ? $length : null);
  33. $descs[] = $desc;
  34. }
  35. }
  36. if ($columns) {
  37. $existing = $indexes[$name];
  38. if ($existing) {
  39. ksort($existing["columns"]);
  40. ksort($existing["lengths"]);
  41. ksort($existing["descs"]);
  42. if ($index["type"] == $existing["type"]
  43. && array_values($existing["columns"]) === $columns
  44. && (!$existing["lengths"] || array_values($existing["lengths"]) === $lengths)
  45. && array_values($existing["descs"]) === $descs
  46. ) {
  47. // skip existing index
  48. unset($indexes[$name]);
  49. continue;
  50. }
  51. }
  52. $alter[] = array($index["type"], $name, $set);
  53. }
  54. }
  55. }
  56. // drop removed indexes
  57. foreach ($indexes as $name => $existing) {
  58. $alter[] = array($existing["type"], $name, "DROP");
  59. }
  60. if (!$alter) {
  61. redirectx(ME . "table=" . urlencode($TABLE));
  62. }
  63. queries_redirect(ME . "table=" . urlencode($TABLE), lang('Indexes have been altered.'), alter_indexes($TABLE, $alter));
  64. }
  65. page_header(lang('Indexes'), $error, array("table" => $TABLE), h($TABLE));
  66. $fields = array_keys(fields($TABLE));
  67. if ($_POST["add"]) {
  68. foreach ($row["indexes"] as $key => $index) {
  69. if ($index["columns"][count($index["columns"])] != "") {
  70. $row["indexes"][$key]["columns"][] = "";
  71. }
  72. }
  73. $index = end($row["indexes"]);
  74. if ($index["type"] || array_filter($index["columns"], 'strlen')) {
  75. $row["indexes"][] = array("columns" => array(1 => ""));
  76. }
  77. }
  78. if (!$row) {
  79. foreach ($indexes as $key => $index) {
  80. $indexes[$key]["name"] = $key;
  81. $indexes[$key]["columns"][] = "";
  82. }
  83. $indexes[] = array("columns" => array(1 => ""));
  84. $row["indexes"] = $indexes;
  85. }
  86. ?>
  87. <form action="" method="post">
  88. <table cellspacing="0" class="nowrap">
  89. <thead><tr>
  90. <th><?php echo lang('Index Type'); ?>
  91. <th><input type="submit" style="left: -1000px; position: absolute;"><?php echo lang('Column (length)'); ?>
  92. <th><?php echo lang('Name'); ?>
  93. <th><noscript><input type='image' class='icon' name='add[0]' src='../adminer/static/plus.gif' alt='+' title='<?php echo lang('Add next'); ?>'></noscript>&nbsp;
  94. </thead>
  95. <?php
  96. if ($primary) {
  97. echo "<tr><td>PRIMARY<td>";
  98. foreach ($primary["columns"] as $key => $column) {
  99. echo select_input(" disabled", $fields, $column);
  100. echo "<label><input disabled type='checkbox'>" . lang('descending') . "</label> ";
  101. }
  102. echo "<td><td>\n";
  103. }
  104. $j = 1;
  105. foreach ($row["indexes"] as $index) {
  106. if (!$_POST["drop_col"] || $j != key($_POST["drop_col"])) {
  107. echo "<tr><td>" . html_select("indexes[$j][type]", array(-1 => "") + $index_types, $index["type"], ($j == count($row["indexes"]) ? "indexesAddRow(this);" : 1));
  108. echo "<td>";
  109. ksort($index["columns"]);
  110. $i = 1;
  111. foreach ($index["columns"] as $key => $column) {
  112. echo "<span>" . select_input(
  113. " name='indexes[$j][columns][$i]' onchange=\"" . ($i == count($index["columns"]) ? "indexesAddColumn" : "indexesChangeColumn") . "(this, '" . js_escape($jush == "sql" ? "" : $_GET["indexes"] . "_") . "');\"",
  114. ($fields ? array_combine($fields, $fields) : $fields),
  115. $column
  116. );
  117. echo ($jush == "sql" || $jush == "mssql" ? "<input type='number' name='indexes[$j][lengths][$i]' class='size' value='" . h($index["lengths"][$key]) . "'>" : "");
  118. echo ($jush != "sql" ? checkbox("indexes[$j][descs][$i]", 1, $index["descs"][$key], lang('descending')) : "");
  119. echo " </span>";
  120. $i++;
  121. }
  122. echo "<td><input name='indexes[$j][name]' value='" . h($index["name"]) . "' autocapitalize='off'>\n";
  123. 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";
  124. }
  125. $j++;
  126. }
  127. ?>
  128. </table>
  129. <p>
  130. <input type="submit" value="<?php echo lang('Save'); ?>">
  131. <input type="hidden" name="token" value="<?php echo $token; ?>">
  132. </form>