Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 100 lines (97 sloc) 3.469 kb
88e1dafd » jakubvrana
2007-07-04 Prepare for index edit
1 <?php
79d19028 » jakubvrana
2009-08-29 Substitute table name to $TABLE
2 $TABLE = $_GET["indexes"];
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
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 }
79d19028 » jakubvrana
2009-08-29 Substitute table name to $TABLE
8 $indexes = indexes($TABLE);
a1bc3cc9 »
2010-07-14 SQLite doesn't support primary key modification
9 if ($jush == "sqlite") { // doesn't support primary key
10 unset($index_types[0]);
11 unset($indexes[""]);
12 }
430034c3 » jakubvrana
2007-07-09 Cottage homework
13 if ($_POST && !$error && !$_POST["add"]) {
0b6ab614 » jakubvrana
2007-07-05 Alter indexes
14 $alter = array();
15 foreach ($_POST["indexes"] as $index) {
16 if (in_array($index["type"], $index_types)) {
17 $columns = array();
e78ec761 » jakubvrana
2007-07-14 Index length
18 $lengths = array();
19 $set = array();
0b6ab614 » jakubvrana
2007-07-05 Alter indexes
20 ksort($index["columns"]);
e78ec761 » jakubvrana
2007-07-14 Index length
21 foreach ($index["columns"] as $key => $column) {
7352c281 » jakubvrana
2010-01-09 Replace strlen() by != ""
22 if ($column != "") {
e78ec761 » jakubvrana
2007-07-14 Index length
23 $length = $index["lengths"][$key];
24 $set[] = idf_escape($column) . ($length ? "(" . intval($length) . ")" : "");
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
25 $columns[] = $column;
26 $lengths[] = ($length ? $length : null);
0b6ab614 » jakubvrana
2007-07-05 Alter indexes
27 }
28 }
29 if ($columns) {
30 foreach ($indexes as $name => $existing) {
89835826 » jakubvrana
2007-07-14 Sort existing for ===
31 ksort($existing["columns"]);
32 ksort($existing["lengths"]);
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
33 if ($index["type"] == $existing["type"] && array_values($existing["columns"]) === $columns && (!$existing["lengths"] || array_values($existing["lengths"]) === $lengths)) {
f83f2043 » jakubvrana
2009-09-11 Comments
34 // skip existing index
0b6ab614 » jakubvrana
2007-07-05 Alter indexes
35 unset($indexes[$name]);
36 continue 2;
37 }
38 }
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
39 $alter[] = array($index["type"], "(" . implode(", ", $set) . ")");
0b6ab614 » jakubvrana
2007-07-05 Alter indexes
40 }
41 }
42 }
f83f2043 » jakubvrana
2009-09-11 Comments
43 // drop removed indexes
0b6ab614 » jakubvrana
2007-07-05 Alter indexes
44 foreach ($indexes as $name => $existing) {
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
45 $alter[] = array($existing["type"], idf_escape($name), "DROP");
0b6ab614 » jakubvrana
2007-07-05 Alter indexes
46 }
f91b2c4b » jakubvrana
2008-09-02 Print SQL query by message
47 if (!$alter) {
79d19028 » jakubvrana
2009-08-29 Substitute table name to $TABLE
48 redirect(ME . "table=" . urlencode($TABLE));
0b6ab614 » jakubvrana
2007-07-05 Alter indexes
49 }
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
50 queries_redirect(ME . "table=" . urlencode($TABLE), lang('Indexes have been altered.'), alter_indexes($TABLE, $alter));
88e1dafd » jakubvrana
2007-07-04 Prepare for index edit
51 }
36d6864a » jakubvrana
2009-07-20 Whitespace
52
79d19028 » jakubvrana
2009-08-29 Substitute table name to $TABLE
53 page_header(lang('Indexes'), $error, array("table" => $TABLE), $TABLE);
88e1dafd » jakubvrana
2007-07-04 Prepare for index edit
54
79d19028 » jakubvrana
2009-08-29 Substitute table name to $TABLE
55 $fields = array_keys(fields($TABLE));
d8df5206 » jakubvrana
2008-07-10 Initialize variables outside blocks
56 $row = array("indexes" => $indexes);
88e1dafd » jakubvrana
2007-07-04 Prepare for index edit
57 if ($_POST) {
e78ec761 » jakubvrana
2007-07-14 Index length
58 $row = $_POST;
4d38c7d9 » jakubvrana
2008-03-18 Protection against big POST data
59 if ($_POST["add"]) {
e78ec761 » jakubvrana
2007-07-14 Index length
60 foreach ($row["indexes"] as $key => $index) {
7352c281 » jakubvrana
2010-01-09 Replace strlen() by != ""
61 if ($index["columns"][count($index["columns"])] != "") {
e78ec761 » jakubvrana
2007-07-14 Index length
62 $row["indexes"][$key]["columns"][] = "";
63 }
64 }
69673aed » jakubvrana
2007-08-04 Use end() for last item
65 $index = end($row["indexes"]);
89835826 » jakubvrana
2007-07-14 Sort existing for ===
66 if ($index["type"] || array_filter($index["columns"], 'strlen') || array_filter($index["lengths"], 'strlen')) {
e78ec761 » jakubvrana
2007-07-14 Index length
67 $row["indexes"][] = array("columns" => array(1 => ""));
68 }
aaa22e0a » jakubvrana
2007-07-05 Add next
69 }
88e1dafd » jakubvrana
2007-07-04 Prepare for index edit
70 } else {
e78ec761 » jakubvrana
2007-07-14 Index length
71 foreach ($row["indexes"] as $key => $index) {
72 $row["indexes"][$key]["columns"][] = "";
73 }
74 $row["indexes"][] = array("columns" => array(1 => ""));
88e1dafd » jakubvrana
2007-07-04 Prepare for index edit
75 }
76 ?>
f508fca3 » jakubvrana
2007-07-09 Empty line
77
88e1dafd » jakubvrana
2007-07-04 Prepare for index edit
78 <form action="" method="post">
61fcecaa »
2010-06-30 Don't wrap indexes table
79 <table cellspacing="0" class="nowrap">
ace55ed1 » jakubvrana
2009-07-11 HTML instead of XHTML
80 <thead><tr><th><?php echo lang('Index Type'); ?><th><?php echo lang('Column (length)'); ?></thead>
88e1dafd » jakubvrana
2007-07-04 Prepare for index edit
81 <?php
61fcecaa »
2010-06-30 Don't wrap indexes table
82 $j = 1;
720f5fc8 » jakubvrana
2007-07-05 Restructure indexes
83 foreach ($row["indexes"] as $index) {
61fcecaa »
2010-06-30 Don't wrap indexes table
84 echo "<tr><td>" . html_select("indexes[$j][type]", array(-1 => "") + $index_types, $index["type"], ($j == count($row["indexes"]) ? "indexesAddRow(this);" : 1)) . "<td>";
e78ec761 » jakubvrana
2007-07-14 Index length
85 ksort($index["columns"]);
61fcecaa »
2010-06-30 Don't wrap indexes table
86 $i = 1;
87 foreach ($index["columns"] as $column) {
3c5c0f01 » jakubvrana
2009-12-17 Use camelCase in JavaScript
88 echo "<span>" . html_select("indexes[$j][columns][$i]", array(-1 => "") + $fields, $column, ($i == count($index["columns"]) ? "indexesAddColumn(this);" : 1));
61fcecaa »
2010-06-30 Don't wrap indexes table
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++;
88e1dafd » jakubvrana
2007-07-04 Prepare for index edit
91 }
e78ec761 » jakubvrana
2007-07-14 Index length
92 $j++;
88e1dafd » jakubvrana
2007-07-04 Prepare for index edit
93 }
94 ?>
95 </table>
58178ab2 » jakubvrana
2007-07-11 Move buttons
96 <p>
ace55ed1 » jakubvrana
2009-07-11 HTML instead of XHTML
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>
88e1dafd » jakubvrana
2007-07-04 Prepare for index edit
100 </form>
Something went wrong with that request. Please try again.