-
Notifications
You must be signed in to change notification settings - Fork 383
/
indexes.php
225 lines (188 loc) · 8.15 KB
/
indexes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<?php
/**
* List indexes on a table
*
* $Id: indexes.php,v 1.17 2003/08/12 08:18:53 chriskl Exp $
*/
// Include application functions
include_once('libraries/lib.inc.php');
include_once('classes/class.select.php');
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
$PHP_SELF = $_SERVER['PHP_SELF'];
/**
* Displays a screen where they can enter a new index
*/
function doCreateIndex($msg = '') {
global $data, $localData, $misc;
global $PHP_SELF, $lang;
if (!isset($_POST['formIndexName'])) $_POST['formIndexName'] = '';
if (!isset($_POST['formIndexType'])) $_POST['formIndexType'] = null;
if (!isset($_POST['formCols'])) $_POST['formCols'] = '';
if (!isset($_POST['formWhere'])) $_POST['formWhere'] = '';
echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strindexes']}: {$lang['strcreateindex']} </h2>\n";
$misc->printMsg($msg);
$attrs = &$localData->getTableAttributes($_REQUEST['table']);
$selColumns = new XHTML_select("TableColumnList",true,10);
$selColumns->set_style("width: 10em;");
if ($attrs->recordCount() > 0) {
while (!$attrs->EOF) {
$selColumns->add(new XHTML_Option($attrs->f['attname']));
$attrs->moveNext();
}
}
$selIndex = new XHTML_select("IndexColumnList[]", true, 10);
$selIndex->set_style("width: 10em;");
$selIndex->set_attribute("id", "IndexColumnList");
$buttonAdd = new XHTML_Button("add", ">>");
$buttonAdd->set_attribute("onclick", "buttonPressed(this);");
$buttonAdd->set_attribute("type", "button");
$buttonRemove = new XHTML_Button("remove", "<<");
$buttonRemove->set_attribute("onclick", "buttonPressed(this);");
$buttonRemove->set_attribute("type", "button");
echo "<form onsubmit=\"doSelectAll();\" name=\"formIndex\" action=\"$PHP_SELF\" method=\"post\">\n";
echo "<table>\n";
echo "<tr><th class=\"data\" colspan=\"3\">{$lang['strindexname']}</th></tr>";
echo "<tr>";
echo "<td class=\"data1\" colspan=\"3\"><input type=\"text\" name=\"formIndexName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
htmlspecialchars($_POST['formIndexName']), "\" /></td></tr>";
echo "<tr><th class=\"data\">{$lang['strtablecolumnlist']}</th><th class=\"data\"> </th>";
echo "<th class=\"data\">{$lang['strindexcolumnlist']}</th></tr>\n";
echo "<tr><td class=\"data1\">" . $selColumns->fetch() . "</td>\n";
echo "<td class=\"data1\">" . $buttonRemove->fetch() . $buttonAdd->fetch() . "</td>";
echo "<td class=\"data1\">" . $selIndex->fetch() . "</td></tr>\n";
echo "</table>\n";
echo "<table> \n";
echo "<tr>";
echo "<th class=\"data\">{$lang['strindextype']}</th>";
echo "<td class=\"data1\"><select name=\"formIndexType\">";
foreach ($localData->typIndexes as $v) {
echo "<option value=\"", htmlspecialchars($v), "\"",
($v == $_POST['formIndexType']) ? ' selected="selected"' : '', ">", htmlspecialchars($v), "</option>\n";
}
echo "</select></td></tr>\n";
echo "</tr>";
echo "<tr>";
echo "<th class=\"data\">{$lang['strunique']}</th>";
echo "<td class=\"data1\"><input type=\"checkbox\" name=\"formUnique\"", (isset($_POST['formUnique']) ? 'checked="checked"' : ''), " /></td>";
echo "</tr>";
if ($data->hasPartialIndexes()) {
echo "<tr>";
echo "<th class=\"data\">{$lang['strwhere']}</th>";
echo "<td class=\"data1\">(<input name=\"formWhere\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
htmlspecialchars($_POST['formWhere']), "\" />)</td>";
echo "</tr>";
}
echo "</table>";
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create_index\" />\n";
echo $misc->form;
echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n";
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
echo "</form>\n";
}
/**
* Actually creates the new index in the database
* @@ Note: this function can't handle columns with commas in them
*/
function doSaveCreateIndex() {
global $localData;
global $lang;
// Handle databases that don't have partial indexes
if (!isset($_POST['formWhere'])) $_POST['formWhere'] = '';
// Check that they've given a name and at least one column
if ($_POST['formIndexName'] == '') doCreateIndex($lang['strindexneedsname']);
elseif (!isset($_POST['IndexColumnList']) || $_POST['IndexColumnList'] == '') doCreateIndex($lang['strindexneedscols']);
else {
$status = $localData->createIndex($_POST['formIndexName'], $_POST['table'], $_POST['IndexColumnList'],
$_POST['formIndexType'], isset($_POST['formUnique']), $_POST['formWhere']);
if ($status == 0)
doDefault($lang['strindexcreated']);
else
doCreateIndex($lang['strindexcreatedbad']);
}
}
/**
* Show confirmation of drop index and perform actual drop
*/
function doDropIndex($confirm) {
global $localData, $database, $misc;
global $PHP_SELF, $lang;
if ($confirm) {
echo "<h2>", $misc->printVal($_REQUEST['database']), ": {$lang['strtables']}: ",
$misc->printVal($_REQUEST['table']), ": " , $misc->printVal($_REQUEST['index']), ": {$lang['strdrop']}</h2>\n";
echo "<p>", sprintf($lang['strconfdropindex'], $misc->printVal($_REQUEST['index'])), "</p>\n";
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"action\" value=\"drop_index\" />\n";
echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
echo "<input type=\"hidden\" name=\"index\" value=\"", htmlspecialchars($_REQUEST['index']), "\" />\n";
echo $misc->form;
// Show cascade drop option if supportd
if ($localData->hasDropBehavior()) {
echo "<p><input type=\"checkbox\" name=\"cascade\" /> {$lang['strcascade']}</p>\n";
}
echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
echo "</form>\n";
}
else {
$status = $localData->dropIndex($_POST['index'], isset($_POST['cascade']));
if ($status == 0)
doDefault($lang['strindexdropped']);
else
doDefault($lang['strindexdroppedbad']);
}
}
function doDefault($msg = '') {
global $data, $localData, $misc;
global $PHP_SELF, $lang;
$misc->printTableNav();
echo "<h2>", $misc->printVal($_REQUEST['database']), ": ", $misc->printVal($_REQUEST['table']), ": {$lang['strindexes']}</h2>\n";
$misc->printMsg($msg);
$indexes = &$localData->getIndexes($_REQUEST['table']);
if ($indexes->recordCount() > 0) {
echo "<table>\n";
echo "<tr><th class=\"data\">{$lang['strname']}</th><th class=\"data\">{$lang['strdefinition']}</th>";
echo "<th class=\"data\">{$lang['stractions']}</th>\n";
$i = 0;
while (!$indexes->EOF) {
$id = ( ($i % 2 ) == 0 ? '1' : '2' );
echo "<tr><td class=\"data{$id}\">", $misc->printVal( $indexes->f[$data->ixFields['idxname']]), "</td>";
echo "<td class=\"data{$id}\">", $misc->printVal( $indexes->f[$data->ixFields['idxdef']]), "</td>";
echo "<td class=\"opbutton{$id}\">";
echo "<a href=\"$PHP_SELF?action=confirm_drop_index&{$misc->href}&index=", urlencode( $indexes->f[$data->ixFields['idxname']]),
"&table=", urlencode($_REQUEST['table']), "\">{$lang['strdrop']}</td></tr>\n";
$indexes->movenext();
$i++;
}
echo "</table>\n";
}
else
echo "<p>{$lang['strnoindexes']}</p>\n";
echo "<p><a class=\"navlink\" href=\"$PHP_SELF?action=create_index&{$misc->href}&table=", urlencode($_REQUEST['table']), "\">{$lang['strcreateindex']}</a></p>\n";
}
$misc->printHeader($lang['strindexes'], "<script src=\"indexes.js\" type=\"text/javascript\"></script>");
if ($action == 'create_index' || $action == 'save_create_index')
echo "<body onload=\"init();\">";
else
$misc->printBody();
switch ($action) {
case 'save_create_index':
if (isset($_POST['cancel'])) doDefault();
else doSaveCreateIndex();
break;
case 'create_index':
doCreateIndex();
break;
case 'drop_index':
if (isset($_POST['drop'])) doDropIndex(false);
else doDefault();
break;
case 'confirm_drop_index':
doDropIndex(true);
break;
default:
doDefault();
break;
}
$misc->printFooter();
?>