Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 101 lines (97 sloc) 3.469 kB
88e1daf Prepare for index edit
jakubvrana authored
1 <?php
79d1902 Substitute table name to $TABLE
jakubvrana authored
2 $TABLE = $_GET["indexes"];
3f5b683 Reintegrate sqlite branch
jakubvrana authored
3 $index_types = array("PRIMARY", "UNIQUE", "INDEX");
4 $table_status = table_status($TABLE);
5 if (ereg("MyISAM|Maria", $table_status["Engine"])) {
6 $index_types[] = "FULLTEXT";
7 }
79d1902 Substitute table name to $TABLE
jakubvrana authored
8 $indexes = indexes($TABLE);
a1bc3cc @vrana SQLite doesn't support primary key modification
authored
9 if ($jush == "sqlite") { // doesn't support primary key
10 unset($index_types[0]);
11 unset($indexes[""]);
12 }
430034c Cottage homework
jakubvrana authored
13 if ($_POST && !$error && !$_POST["add"]) {
0b6ab61 Alter indexes
jakubvrana authored
14 $alter = array();
15 foreach ($_POST["indexes"] as $index) {
16 if (in_array($index["type"], $index_types)) {
17 $columns = array();
e78ec76 Index length
jakubvrana authored
18 $lengths = array();
19 $set = array();
0b6ab61 Alter indexes
jakubvrana authored
20 ksort($index["columns"]);
e78ec76 Index length
jakubvrana authored
21 foreach ($index["columns"] as $key => $column) {
7352c28 Replace strlen() by != ""
jakubvrana authored
22 if ($column != "") {
e78ec76 Index length
jakubvrana authored
23 $length = $index["lengths"][$key];
24 $set[] = idf_escape($column) . ($length ? "(" . intval($length) . ")" : "");
3f5b683 Reintegrate sqlite branch
jakubvrana authored
25 $columns[] = $column;
26 $lengths[] = ($length ? $length : null);
0b6ab61 Alter indexes
jakubvrana authored
27 }
28 }
29 if ($columns) {
30 foreach ($indexes as $name => $existing) {
8983582 Sort existing for ===
jakubvrana authored
31 ksort($existing["columns"]);
32 ksort($existing["lengths"]);
3f5b683 Reintegrate sqlite branch
jakubvrana authored
33 if ($index["type"] == $existing["type"] && array_values($existing["columns"]) === $columns && (!$existing["lengths"] || array_values($existing["lengths"]) === $lengths)) {
f83f204 Comments
jakubvrana authored
34 // skip existing index
0b6ab61 Alter indexes
jakubvrana authored
35 unset($indexes[$name]);
36 continue 2;
37 }
38 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored
39 $alter[] = array($index["type"], "(" . implode(", ", $set) . ")");
0b6ab61 Alter indexes
jakubvrana authored
40 }
41 }
42 }
f83f204 Comments
jakubvrana authored
43 // drop removed indexes
0b6ab61 Alter indexes
jakubvrana authored
44 foreach ($indexes as $name => $existing) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
45 $alter[] = array($existing["type"], idf_escape($name), "DROP");
0b6ab61 Alter indexes
jakubvrana authored
46 }
f91b2c4 Print SQL query by message
jakubvrana authored
47 if (!$alter) {
79d1902 Substitute table name to $TABLE
jakubvrana authored
48 redirect(ME . "table=" . urlencode($TABLE));
0b6ab61 Alter indexes
jakubvrana authored
49 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored
50 queries_redirect(ME . "table=" . urlencode($TABLE), lang('Indexes have been altered.'), alter_indexes($TABLE, $alter));
88e1daf Prepare for index edit
jakubvrana authored
51 }
36d6864 Whitespace
jakubvrana authored
52
79d1902 Substitute table name to $TABLE
jakubvrana authored
53 page_header(lang('Indexes'), $error, array("table" => $TABLE), $TABLE);
88e1daf Prepare for index edit
jakubvrana authored
54
79d1902 Substitute table name to $TABLE
jakubvrana authored
55 $fields = array_keys(fields($TABLE));
d8df520 Initialize variables outside blocks
jakubvrana authored
56 $row = array("indexes" => $indexes);
88e1daf Prepare for index edit
jakubvrana authored
57 if ($_POST) {
e78ec76 Index length
jakubvrana authored
58 $row = $_POST;
4d38c7d Protection against big POST data
jakubvrana authored
59 if ($_POST["add"]) {
e78ec76 Index length
jakubvrana authored
60 foreach ($row["indexes"] as $key => $index) {
7352c28 Replace strlen() by != ""
jakubvrana authored
61 if ($index["columns"][count($index["columns"])] != "") {
e78ec76 Index length
jakubvrana authored
62 $row["indexes"][$key]["columns"][] = "";
63 }
64 }
69673ae Use end() for last item
jakubvrana authored
65 $index = end($row["indexes"]);
8983582 Sort existing for ===
jakubvrana authored
66 if ($index["type"] || array_filter($index["columns"], 'strlen') || array_filter($index["lengths"], 'strlen')) {
e78ec76 Index length
jakubvrana authored
67 $row["indexes"][] = array("columns" => array(1 => ""));
68 }
aaa22e0 Add next
jakubvrana authored
69 }
88e1daf Prepare for index edit
jakubvrana authored
70 } else {
e78ec76 Index length
jakubvrana authored
71 foreach ($row["indexes"] as $key => $index) {
72 $row["indexes"][$key]["columns"][] = "";
73 }
74 $row["indexes"][] = array("columns" => array(1 => ""));
88e1daf Prepare for index edit
jakubvrana authored
75 }
76 ?>
f508fca Empty line
jakubvrana authored
77
88e1daf Prepare for index edit
jakubvrana authored
78 <form action="" method="post">
61fceca @vrana Don't wrap indexes table
authored
79 <table cellspacing="0" class="nowrap">
ace55ed HTML instead of XHTML
jakubvrana authored
80 <thead><tr><th><?php echo lang('Index Type'); ?><th><?php echo lang('Column (length)'); ?></thead>
88e1daf Prepare for index edit
jakubvrana authored
81 <?php
61fceca @vrana Don't wrap indexes table
authored
82 $j = 1;
720f5fc Restructure indexes
jakubvrana authored
83 foreach ($row["indexes"] as $index) {
61fceca @vrana Don't wrap indexes table
authored
84 echo "<tr><td>" . html_select("indexes[$j][type]", array(-1 => "") + $index_types, $index["type"], ($j == count($row["indexes"]) ? "indexesAddRow(this);" : 1)) . "<td>";
e78ec76 Index length
jakubvrana authored
85 ksort($index["columns"]);
61fceca @vrana Don't wrap indexes table
authored
86 $i = 1;
87 foreach ($index["columns"] as $column) {
3c5c0f0 Use camelCase in JavaScript
jakubvrana authored
88 echo "<span>" . html_select("indexes[$j][columns][$i]", array(-1 => "") + $fields, $column, ($i == count($index["columns"]) ? "indexesAddColumn(this);" : 1));
61fceca @vrana Don't wrap indexes table
authored
89 echo "<input name='indexes[$j][lengths][$i]' size='2' value='" . h($index["lengths"][$i]) . "'> </span>"; //! hide for non-MySQL drivers, add ASC|DESC
90 $i++;
88e1daf Prepare for index edit
jakubvrana authored
91 }
e78ec76 Index length
jakubvrana authored
92 $j++;
88e1daf Prepare for index edit
jakubvrana authored
93 }
94 ?>
95 </table>
58178ab Move buttons
jakubvrana authored
96 <p>
ace55ed HTML instead of XHTML
jakubvrana authored
97 <input type="hidden" name="token" value="<?php echo $token; ?>">
98 <input type="submit" value="<?php echo lang('Save'); ?>">
99 <noscript><p><input type="submit" name="add" value="<?php echo lang('Add next'); ?>"></noscript>
88e1daf Prepare for index edit
jakubvrana authored
100 </form>
Something went wrong with that request. Please try again.