1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* List constraints on a table
|
5
|
*
|
6
|
* $Id: constraints.php,v 1.42 2005/10/18 03:45:15 chriskl Exp $
|
7
|
*/
|
8
|
|
9
|
// Include application functions
|
10
|
include_once('./libraries/lib.inc.php');
|
11
|
include_once('./classes/class.select.php');
|
12
|
|
13
|
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
|
14
|
$PHP_SELF = $_SERVER['PHP_SELF'];
|
15
|
|
16
|
/**
|
17
|
* Confirm and then actually add a FOREIGN KEY constraint
|
18
|
*/
|
19
|
function addForeignKey($stage, $msg = '') {
|
20
|
global $PHP_SELF, $data, $data, $misc;
|
21
|
global $lang;
|
22
|
|
23
|
if (!isset($_POST['name'])) $_POST['name'] = '';
|
24
|
if (!isset($_POST['target'])) $_POST['target'] = '';
|
25
|
|
26
|
switch ($stage) {
|
27
|
case 2:
|
28
|
// Check that they've given at least one source column
|
29
|
if (!isset($_REQUEST['SourceColumnList']) && (!isset($_POST['IndexColumnList']) || !is_array($_POST['IndexColumnList']) || sizeof($_POST['IndexColumnList']) == 0))
|
30
|
addForeignKey(1, $lang['strfkneedscols']);
|
31
|
else {
|
32
|
// Copy the IndexColumnList variable from stage 1
|
33
|
if (isset($_REQUEST['IndexColumnList']) && !isset($_REQUEST['SourceColumnList']))
|
34
|
$_REQUEST['SourceColumnList'] = serialize($_REQUEST['IndexColumnList']);
|
35
|
|
36
|
// Initialise variables
|
37
|
if (!isset($_POST['upd_action'])) $_POST['upd_action'] = null;
|
38
|
if (!isset($_POST['del_action'])) $_POST['del_action'] = null;
|
39
|
if (!isset($_POST['match'])) $_POST['match'] = null;
|
40
|
if (!isset($_POST['deferrable'])) $_POST['deferrable'] = null;
|
41
|
if (!isset($_POST['initially'])) $_POST['initially'] = null;
|
42
|
$_REQUEST['target'] = unserialize($_REQUEST['target']);
|
43
|
|
44
|
$misc->printTrail('table');
|
45
|
$misc->printTitle($lang['straddfk'],'pg.constraint.foreign_key');
|
46
|
$misc->printMsg($msg);
|
47
|
|
48
|
// Unserialize target and fetch appropriate table. This is a bit messy
|
49
|
// because the table could be in another schema.
|
50
|
if ($data->hasSchemas())
|
51
|
$data->setSchema($_REQUEST['target']['schemaname']);
|
52
|
$attrs = $data->getTableAttributes($_REQUEST['target']['tablename']);
|
53
|
if ($data->hasSchemas())
|
54
|
$data->setSchema($_REQUEST['schema']);
|
55
|
|
56
|
$selColumns = new XHTML_select('TableColumnList', true, 10);
|
57
|
$selColumns->set_style('width: 10em;');
|
58
|
|
59
|
if ($attrs->recordCount() > 0) {
|
60
|
while (!$attrs->EOF) {
|
61
|
$selColumns->add(new XHTML_Option($attrs->f['attname']));
|
62
|
$attrs->moveNext();
|
63
|
}
|
64
|
}
|
65
|
|
66
|
$selIndex = new XHTML_select('IndexColumnList[]', true, 10);
|
67
|
$selIndex->set_style('width: 10em;');
|
68
|
$selIndex->set_attribute('id', 'IndexColumnList');
|
69
|
$buttonAdd = new XHTML_Button('add', '>>');
|
70
|
$buttonAdd->set_attribute('onclick', 'buttonPressed(this);');
|
71
|
$buttonAdd->set_attribute('type', 'button');
|
72
|
|
73
|
$buttonRemove = new XHTML_Button('remove', '<<');
|
74
|
$buttonRemove->set_attribute('onclick', 'buttonPressed(this);');
|
75
|
$buttonRemove->set_attribute('type', 'button');
|
76
|
|
77
|
echo "<form onsubmit=\"doSelectAll();\" name=\"formIndex\" action=\"$PHP_SELF\" method=\"post\">\n";
|
78
|
|
79
|
echo "<table>\n";
|
80
|
echo "<tr><th class=\"data\" colspan=\"3\">{$lang['strfktarget']}</th></tr>";
|
81
|
echo "<tr><th class=\"data\">{$lang['strtablecolumnlist']}</th><th class=\"data\"> </th><th class=data>{$lang['strfkcolumnlist']}</th></tr>\n";
|
82
|
echo "<tr><td class=\"data1\">" . $selColumns->fetch() . "</td>\n";
|
83
|
echo "<td class=\"data1\" align=\"center\">" . $buttonRemove->fetch() . $buttonAdd->fetch() . "</td>";
|
84
|
echo "<td class=\"data1\">" . $selIndex->fetch() . "</td></tr>\n";
|
85
|
echo "<tr><th class=\"data\" colspan=\"3\">{$lang['stractions']}</th></tr>";
|
86
|
echo "<tr>";
|
87
|
echo "<td class=\"data1\" colspan=\"3\">\n";
|
88
|
// ON SELECT actions
|
89
|
echo "{$lang['stronupdate']} <select name=\"upd_action\">";
|
90
|
foreach ($data->fkactions as $v)
|
91
|
echo "<option value=\"{$v}\"", ($_POST['upd_action'] == $v) ? ' selected="selected"' : '', ">{$v}</option>\n";
|
92
|
echo "</select><br />\n";
|
93
|
|
94
|
// ON DELETE actions
|
95
|
echo "{$lang['strondelete']} <select name=\"del_action\">";
|
96
|
foreach ($data->fkactions as $v)
|
97
|
echo "<option value=\"{$v}\"", ($_POST['del_action'] == $v) ? ' selected="selected"' : '', ">{$v}</option>\n";
|
98
|
echo "</select><br />\n";
|
99
|
|
100
|
// MATCH options
|
101
|
echo "<select name=\"match\">";
|
102
|
foreach ($data->fkmatches as $v)
|
103
|
echo "<option value=\"{$v}\"", ($_POST['match'] == $v) ? ' selected="selected"' : '', ">{$v}</option>\n";
|
104
|
echo "</select><br />\n";
|
105
|
|
106
|
// DEFERRABLE options
|
107
|
echo "<select name=\"deferrable\">";
|
108
|
foreach ($data->fkdeferrable as $v)
|
109
|
echo "<option value=\"{$v}\"", ($_POST['deferrable'] == $v) ? ' selected="selected"' : '', ">{$v}</option>\n";
|
110
|
echo "</select><br />\n";
|
111
|
|
112
|
// INITIALLY options
|
113
|
echo "<select name=\"initially\">";
|
114
|
foreach ($data->fkinitial as $v)
|
115
|
echo "<option value=\"{$v}\"", ($_POST['initially'] == $v) ? ' selected="selected"' : '', ">{$v}</option>\n";
|
116
|
echo "</select>\n";
|
117
|
echo "</td></tr>\n";
|
118
|
echo "</table>\n";
|
119
|
|
120
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_add_foreign_key\" />\n";
|
121
|
echo $misc->form;
|
122
|
echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
|
123
|
echo "<input type=\"hidden\" name=\"name\" value=\"", htmlspecialchars($_REQUEST['name']), "\" />\n";
|
124
|
echo "<input type=\"hidden\" name=\"target\" value=\"", htmlspecialchars(serialize($_REQUEST['target'])), "\" />\n";
|
125
|
echo "<input type=\"hidden\" name=\"SourceColumnList\" value=\"", htmlspecialchars($_REQUEST['SourceColumnList']), "\" />\n";
|
126
|
echo "<input type=\"hidden\" name=\"stage\" value=\"3\" />\n";
|
127
|
echo "<input type=\"submit\" value=\"{$lang['stradd']}\" />\n";
|
128
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
|
129
|
echo "</form>\n";
|
130
|
}
|
131
|
break;
|
132
|
case 3:
|
133
|
// Unserialize target
|
134
|
$_POST['target'] = unserialize($_POST['target']);
|
135
|
|
136
|
// Check that they've given at least one column
|
137
|
if (isset($_POST['SourceColumnList'])) $temp = unserialize($_POST['SourceColumnList']);
|
138
|
if (!isset($_POST['IndexColumnList']) || !is_array($_POST['IndexColumnList'])
|
139
|
|| sizeof($_POST['IndexColumnList']) == 0 || !isset($temp)
|
140
|
|| !is_array($temp) || sizeof($temp) == 0) addForeignKey(2, $lang['strfkneedscols']);
|
141
|
else {
|
142
|
$status = $data->addForeignKey($_POST['table'], $_POST['target']['schemaname'], $_POST['target']['tablename'],
|
143
|
unserialize($_POST['SourceColumnList']), $_POST['IndexColumnList'], $_POST['upd_action'], $_POST['del_action'],
|
144
|
$_POST['match'], $_POST['deferrable'], $_POST['initially'], $_POST['name']);
|
145
|
if ($status == 0)
|
146
|
doDefault($lang['strfkadded']);
|
147
|
else
|
148
|
addForeignKey(2, $lang['strfkaddedbad']);
|
149
|
}
|
150
|
break;
|
151
|
default:
|
152
|
$misc->printTrail('table');
|
153
|
$misc->printTitle($lang['straddfk'],'pg.constraint.foreign_key');
|
154
|
$misc->printMsg($msg);
|
155
|
|
156
|
$attrs = $data->getTableAttributes($_REQUEST['table']);
|
157
|
$tables = $data->getTables(true);
|
158
|
|
159
|
$selColumns = new XHTML_select('TableColumnList', true, 10);
|
160
|
$selColumns->set_style('width: 10em;');
|
161
|
|
162
|
if ($attrs->recordCount() > 0) {
|
163
|
while (!$attrs->EOF) {
|
164
|
$selColumns->add(new XHTML_Option($attrs->f['attname']));
|
165
|
$attrs->moveNext();
|
166
|
}
|
167
|
}
|
168
|
|
169
|
$selIndex = new XHTML_select('IndexColumnList[]', true, 10);
|
170
|
$selIndex->set_style('width: 10em;');
|
171
|
$selIndex->set_attribute('id', 'IndexColumnList');
|
172
|
$buttonAdd = new XHTML_Button('add', '>>');
|
173
|
$buttonAdd->set_attribute('onclick', 'buttonPressed(this);');
|
174
|
$buttonAdd->set_attribute('type', 'button');
|
175
|
|
176
|
$buttonRemove = new XHTML_Button('remove', '<<');
|
177
|
$buttonRemove->set_attribute('onclick', 'buttonPressed(this);');
|
178
|
$buttonRemove->set_attribute('type', 'button');
|
179
|
|
180
|
echo "<form onsubmit=\"doSelectAll();\" name=\"formIndex\" action=\"$PHP_SELF\" method=\"post\">\n";
|
181
|
|
182
|
echo "<table>\n";
|
183
|
echo "<tr><th class=\"data\" colspan=\"3\">{$lang['strname']}</th></tr>\n";
|
184
|
echo "<tr><td class=\"data1\" colspan=\"3\"><input type=\"text\" name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" /></td></tr>\n";
|
185
|
echo "<tr><th class=\"data\">{$lang['strtablecolumnlist']}</th><th class=\"data\"> </th><th class=\"data required\">{$lang['strfkcolumnlist']}</th></tr>\n";
|
186
|
echo "<tr><td class=\"data1\">" . $selColumns->fetch() . "</td>\n";
|
187
|
echo "<td class=\"data1\" align=\"center\">" . $buttonRemove->fetch() . $buttonAdd->fetch() . "</td>\n";
|
188
|
echo "<td class=data1>" . $selIndex->fetch() . "</td></tr>\n";
|
189
|
echo "<tr><th class=\"data\" colspan=\"3\">{$lang['strfktarget']}</th></tr>";
|
190
|
echo "<tr>";
|
191
|
echo "<td class=\"data1\" colspan=\"3\"><select name=\"target\">";
|
192
|
while (!$tables->EOF) {
|
193
|
$key = array('schemaname' => $tables->f['nspname'], 'tablename' => $tables->f['relname']);
|
194
|
$key = serialize($key);
|
195
|
echo "<option value=\"", htmlspecialchars($key), "\">";
|
196
|
if ($data->hasSchemas() && $tables->f['nspname'] != $_REQUEST['schema']) {
|
197
|
echo htmlspecialchars($tables->f['nspname']), '.';
|
198
|
}
|
199
|
echo htmlspecialchars($tables->f['relname']), "</option>\n";
|
200
|
$tables->moveNext();
|
201
|
}
|
202
|
echo "</select>\n";
|
203
|
echo "</td></tr>";
|
204
|
echo "</table>\n";
|
205
|
|
206
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_add_foreign_key\" />\n";
|
207
|
echo $misc->form;
|
208
|
echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
|
209
|
echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n";
|
210
|
echo "<input type=\"submit\" value=\"{$lang['stradd']}\" />\n";
|
211
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
|
212
|
echo "</form>\n";
|
213
|
break;
|
214
|
}
|
215
|
|
216
|
}
|
217
|
|
218
|
/**
|
219
|
* Confirm and then actually add a PRIMARY KEY or UNIQUE constraint
|
220
|
*/
|
221
|
function addPrimaryOrUniqueKey($type, $confirm, $msg = '') {
|
222
|
global $PHP_SELF, $data, $data, $misc;
|
223
|
global $lang;
|
224
|
|
225
|
if (!isset($_POST['name'])) $_POST['name'] = '';
|
226
|
|
227
|
if ($confirm) {
|
228
|
if (!isset($_POST['name'])) $_POST['name'] = '';
|
229
|
if (!isset($_POST['tablespace'])) $_POST['tablespace'] = '';
|
230
|
|
231
|
$misc->printTrail('table');
|
232
|
|
233
|
switch ($type) {
|
234
|
case 'primary':
|
235
|
$misc->printTitle($lang['straddpk'],'pg.constraint.primary_key');
|
236
|
break;
|
237
|
case 'unique':
|
238
|
$misc->printTitle($lang['stradduniq'],'pg.constraint.unique_key');
|
239
|
break;
|
240
|
default:
|
241
|
doDefault($lang['strinvalidparam']);
|
242
|
return;
|
243
|
}
|
244
|
|
245
|
$misc->printMsg($msg);
|
246
|
|
247
|
$attrs = $data->getTableAttributes($_REQUEST['table']);
|
248
|
// Fetch all tablespaces from the database
|
249
|
if ($data->hasTablespaces()) $tablespaces = $data->getTablespaces();
|
250
|
|
251
|
|
252
|
$selColumns = new XHTML_select('TableColumnList', true, 10);
|
253
|
$selColumns->set_style('width: 10em;');
|
254
|
|
255
|
if ($attrs->recordCount() > 0) {
|
256
|
while (!$attrs->EOF) {
|
257
|
$selColumns->add(new XHTML_Option($attrs->f['attname']));
|
258
|
$attrs->moveNext();
|
259
|
}
|
260
|
}
|
261
|
|
262
|
$selIndex = new XHTML_select('IndexColumnList[]', true, 10);
|
263
|
$selIndex->set_style('width: 10em;');
|
264
|
$selIndex->set_attribute('id', 'IndexColumnList');
|
265
|
$buttonAdd = new XHTML_Button('add', '>>');
|
266
|
$buttonAdd->set_attribute('onclick', 'buttonPressed(this);');
|
267
|
$buttonAdd->set_attribute('type', 'button');
|
268
|
|
269
|
$buttonRemove = new XHTML_Button('remove', '<<');
|
270
|
$buttonRemove->set_attribute('onclick', 'buttonPressed(this);');
|
271
|
$buttonRemove->set_attribute('type', 'button');
|
272
|
|
273
|
echo "<form onsubmit=\"doSelectAll();\" name=\"formIndex\" action=\"$PHP_SELF\" method=\"post\">\n";
|
274
|
|
275
|
echo "<table>\n";
|
276
|
echo "<tr><th class=\"data\" colspan=\"3\">{$lang['strname']}</th></tr>";
|
277
|
echo "<tr>";
|
278
|
echo "<td class=\"data1\" colspan=\"3\"><input type=\"text\" name=\"name\" value=\"", htmlspecialchars($_POST['name']),
|
279
|
"\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" /></td></tr>";
|
280
|
echo "<tr><th class=\"data\">{$lang['strtablecolumnlist']}</th><th class=\"data\"> </th><th class=\"data required\">{$lang['strindexcolumnlist']}</th></tr>\n";
|
281
|
echo "<tr><td class=\"data1\">" . $selColumns->fetch() . "</td>\n";
|
282
|
echo "<td class=\"data1\" align=\"center\">" . $buttonRemove->fetch() . $buttonAdd->fetch() . "</td>";
|
283
|
echo "<td class=data1>" . $selIndex->fetch() . "</td></tr>\n";
|
284
|
|
285
|
// Tablespace (if there are any)
|
286
|
if ($data->hasTablespaces() && $tablespaces->recordCount() > 0) {
|
287
|
echo "<tr><th class=\"data\" colspan=\"3\">{$lang['strtablespace']}</th></tr>";
|
288
|
echo "<tr><td class=\"data1\" colspan=\"3\"><select name=\"tablespace\">\n";
|
289
|
// Always offer the default (empty) option
|
290
|
echo "\t\t\t\t<option value=\"\"",
|
291
|
($_POST['tablespace'] == '') ? ' selected="selected"' : '', "></option>\n";
|
292
|
// Display all other tablespaces
|
293
|
while (!$tablespaces->EOF) {
|
294
|
$spcname = htmlspecialchars($tablespaces->f['spcname']);
|
295
|
echo "\t\t\t\t<option value=\"{$spcname}\"",
|
296
|
($spcname == $_POST['tablespace']) ? ' selected="selected"' : '', ">{$spcname}</option>\n";
|
297
|
$tablespaces->moveNext();
|
298
|
}
|
299
|
echo "</select></td></tr>\n";
|
300
|
}
|
301
|
|
302
|
echo "</table>\n";
|
303
|
|
304
|
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_add_primary_key\" />\n";
|
305
|
echo $misc->form;
|
306
|
echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
|
307
|
echo "<input type=\"hidden\" name=\"type\" value=\"", htmlspecialchars($type), "\" />\n";
|
308
|
echo "<input type=\"submit\" value=\"{$lang['stradd']}\" />\n";
|
309
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
|
310
|
echo "</form>\n";
|
311
|
}
|
312
|
else {
|
313
|
// Default tablespace to empty if it isn't set
|
314
|
if (!isset($_POST['tablespace'])) $_POST['tablespace'] = '';
|
315
|
|
316
|
if ($_POST['type'] == 'primary') {
|
317
|
// Check that they've given at least one column
|
318
|
if (!isset($_POST['IndexColumnList']) || !is_array($_POST['IndexColumnList'])
|
319
|
|| sizeof($_POST['IndexColumnList']) == 0) addPrimaryOrUniqueKey($_POST['type'], true, $lang['strpkneedscols']);
|
320
|
else {
|
321
|
$status = $data->addPrimaryKey($_POST['table'], $_POST['IndexColumnList'], $_POST['name'], $_POST['tablespace']);
|
322
|
if ($status == 0)
|
323
|
doDefault($lang['strpkadded']);
|
324
|
else
|
325
|
addPrimaryOrUniqueKey($_POST['type'], true, $lang['strpkaddedbad']);
|
326
|
}
|
327
|
}
|
328
|
elseif ($_POST['type'] == 'unique') {
|
329
|
// Check that they've given at least one column
|
330
|
if (!isset($_POST['IndexColumnList']) || !is_array($_POST['IndexColumnList'])
|
331
|
|| sizeof($_POST['IndexColumnList']) == 0) addPrimaryOrUniqueKey($_POST['type'], true, $lang['struniqneedscols']);
|
332
|
else {
|
333
|
$status = $data->addUniqueKey($_POST['table'], $_POST['IndexColumnList'], $_POST['name'], $_POST['tablespace']);
|
334
|
if ($status == 0)
|
335
|
doDefault($lang['struniqadded']);
|
336
|
else
|
337
|
addPrimaryOrUniqueKey($_POST['type'], true, $lang['struniqaddedbad']);
|
338
|
}
|
339
|
}
|
340
|
else doDefault($lang['strinvalidparam']);
|
341
|
}
|
342
|
}
|
343
|
|
344
|
/**
|
345
|
* Confirm and then actually add a CHECK constraint
|
346
|
*/
|
347
|
function addCheck($confirm, $msg = '') {
|
348
|
global $PHP_SELF, $data, $data, $misc;
|
349
|
global $lang;
|
350
|
|
351
|
if (!isset($_POST['name'])) $_POST['name'] = '';
|
352
|
if (!isset($_POST['definition'])) $_POST['definition'] = '';
|
353
|
|
354
|
if ($confirm) {
|
355
|
$misc->printTrail('table');
|
356
|
$misc->printTitle($lang['straddcheck'],'pg.constraint.check');
|
357
|
$misc->printMsg($msg);
|
358
|
|
359
|
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
|
360
|
echo "<table>\n";
|
361
|
echo "<tr><th class=\"data\">{$lang['strname']}</th>\n";
|
362
|
echo "<th class=\"data required\">{$lang['strdefinition']}</th></tr>\n";
|
363
|
|
364
|
echo "<tr><td class=\"data1\"><input name=\"name\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"",
|
365
|
htmlspecialchars($_POST['name']), "\" /></td>\n";
|
366
|
|
367
|
echo "<td class=\"data1\">(<input name=\"definition\" size=\"32\" value=\"",
|
368
|
htmlspecialchars($_POST['definition']), "\" />)</td></tr>\n";
|
369
|
echo "</table>\n";
|
370
|
|
371
|
echo "<input type=\"hidden\" name=\"action\" value=\"save_add_check\" />\n";
|
372
|
echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
|
373
|
echo $misc->form;
|
374
|
echo "<p><input type=\"submit\" name=\"ok\" value=\"{$lang['stradd']}\" />\n";
|
375
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
|
376
|
echo "</form>\n";
|
377
|
|
378
|
}
|
379
|
else {
|
380
|
if (trim($_POST['definition']) == '')
|
381
|
addCheck(true, $lang['strcheckneedsdefinition']);
|
382
|
else {
|
383
|
$status = $data->addCheckConstraint($_POST['table'],
|
384
|
$_POST['definition'], $_POST['name']);
|
385
|
if ($status == 0)
|
386
|
doDefault($lang['strcheckadded']);
|
387
|
else
|
388
|
addCheck(true, $lang['strcheckaddedbad']);
|
389
|
}
|
390
|
}
|
391
|
}
|
392
|
|
393
|
/**
|
394
|
* Show confirmation of drop and perform actual drop
|
395
|
*/
|
396
|
function doDrop($confirm) {
|
397
|
global $data, $misc;
|
398
|
global $PHP_SELF, $lang;
|
399
|
|
400
|
if ($confirm) {
|
401
|
$misc->printTrail('constraint');
|
402
|
$misc->printTitle($lang['strdrop'],'pg.constraint.drop');
|
403
|
|
404
|
echo "<p>", sprintf($lang['strconfdropconstraint'], $misc->printVal($_REQUEST['constraint']),
|
405
|
$misc->printVal($_REQUEST['table'])), "</p>\n";
|
406
|
|
407
|
echo "<form action=\"$PHP_SELF\" method=\"post\">\n";
|
408
|
echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
|
409
|
echo "<input type=\"hidden\" name=\"table\" value=\"", htmlspecialchars($_REQUEST['table']), "\" />\n";
|
410
|
echo "<input type=\"hidden\" name=\"constraint\" value=\"", htmlspecialchars($_REQUEST['constraint']), "\" />\n";
|
411
|
echo "<input type=\"hidden\" name=\"type\" value=\"", htmlspecialchars($_REQUEST['type']), "\" />\n";
|
412
|
echo $misc->form;
|
413
|
// Show cascade drop option if supportd
|
414
|
if ($data->hasDropBehavior()) {
|
415
|
echo "<p><input type=\"checkbox\" name=\"cascade\" /> {$lang['strcascade']}</p>\n";
|
416
|
}
|
417
|
echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
|
418
|
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
|
419
|
echo "</form>\n";
|
420
|
}
|
421
|
else {
|
422
|
$status = $data->dropConstraint($_POST['constraint'], $_POST['table'], $_POST['type'], isset($_POST['cascade']));
|
423
|
if ($status == 0)
|
424
|
doDefault($lang['strconstraintdropped']);
|
425
|
else
|
426
|
doDefault($lang['strconstraintdroppedbad']);
|
427
|
}
|
428
|
}
|
429
|
|
430
|
/**
|
431
|
* List all the constraints on the table
|
432
|
*/
|
433
|
function doDefault($msg = '') {
|
434
|
global $data, $misc;
|
435
|
global $PHP_SELF;
|
436
|
global $lang;
|
437
|
|
438
|
function cnPre(&$rowdata) {
|
439
|
global $data, $lang;
|
440
|
if (is_null($rowdata->f['consrc'])) {
|
441
|
$atts = $data->getAttributeNames($_REQUEST['table'], explode(' ', $rowdata->f['indkey']));
|
442
|
$rowdata->f['+definition'] = ($rowdata->f['contype'] == 'u' ? "UNIQUE (" : "PRIMARY KEY (") . join(',', $atts) . ')';
|
443
|
} else {
|
444
|
$rowdata->f['+definition'] = $rowdata->f['consrc'];
|
445
|
}
|
446
|
}
|
447
|
|
448
|
$misc->printTrail('table');
|
449
|
$misc->printTabs('table','constraints');
|
450
|
$misc->printMsg($msg);
|
451
|
|
452
|
$constraints = $data->getConstraints($_REQUEST['table']);
|
453
|
|
454
|
$columns = array(
|
455
|
'constraint' => array(
|
456
|
'title' => $lang['strname'],
|
457
|
'field' => 'conname',
|
458
|
),
|
459
|
'definition' => array(
|
460
|
'title' => $lang['strdefinition'],
|
461
|
'field' => '+definition',
|
462
|
'type' => 'pre',
|
463
|
),
|
464
|
'actions' => array(
|
465
|
'title' => $lang['stractions'],
|
466
|
),
|
467
|
);
|
468
|
|
469
|
$actions = array(
|
470
|
'drop' => array(
|
471
|
'title' => $lang['strdrop'],
|
472
|
'url' => "{$PHP_SELF}?action=confirm_drop&{$misc->href}&table=".urlencode($_REQUEST['table'])."&",
|
473
|
'vars' => array('constraint' => 'conname', 'type' => 'contype'),
|
474
|
),
|
475
|
);
|
476
|
|
477
|
if (!$data->hasIsClustered()) unset($columns['clustered']);
|
478
|
|
479
|
$misc->printTable($constraints, $columns, $actions, $lang['strnoconstraints'], 'cnPre');
|
480
|
|
481
|
echo "<p><a class=\"navlink\" href=\"{$PHP_SELF}?action=add_check&{$misc->href}&table=", urlencode($_REQUEST['table']),
|
482
|
"\">{$lang['straddcheck']}</a> |\n";
|
483
|
echo "<a class=\"navlink\" href=\"{$PHP_SELF}?action=add_unique_key&{$misc->href}&table=", urlencode($_REQUEST['table']),
|
484
|
"\">{$lang['stradduniq']}</a> |\n";
|
485
|
echo "<a class=\"navlink\" href=\"{$PHP_SELF}?action=add_primary_key&{$misc->href}&table=", urlencode($_REQUEST['table']),
|
486
|
"\">{$lang['straddpk']}</a> |\n";
|
487
|
echo "<a class=\"navlink\" href=\"{$PHP_SELF}?action=add_foreign_key&{$misc->href}&table=", urlencode($_REQUEST['table']),
|
488
|
"\">{$lang['straddfk']}</a></p>\n";
|
489
|
}
|
490
|
|
491
|
$misc->printHeader($lang['strtables'] . ' - ' . $_REQUEST['table'] . ' - ' . $lang['strconstraints'],
|
492
|
"<script src=\"indexes.js\" type=\"text/javascript\"></script>");
|
493
|
|
494
|
if ($action == 'add_unique_key' || $action == 'save_add_unique_key'
|
495
|
|| $action == 'add_primary_key' || $action == 'save_add_primary_key'
|
496
|
|| $action == 'add_foreign_key' || $action == 'save_add_foreign_key')
|
497
|
echo "<body onload=\"init();\">";
|
498
|
else
|
499
|
$misc->printBody();
|
500
|
|
501
|
switch ($action) {
|
502
|
case 'add_foreign_key':
|
503
|
addForeignKey(1);
|
504
|
break;
|
505
|
case 'save_add_foreign_key':
|
506
|
if (isset($_POST['cancel'])) doDefault();
|
507
|
else addForeignKey($_REQUEST['stage']);
|
508
|
break;
|
509
|
case 'add_unique_key':
|
510
|
addPrimaryOrUniqueKey('unique', true);
|
511
|
break;
|
512
|
case 'save_add_unique_key':
|
513
|
if (isset($_POST['cancel'])) doDefault();
|
514
|
else addPrimaryOrUniqueKey('unique', false);
|
515
|
break;
|
516
|
case 'add_primary_key':
|
517
|
addPrimaryOrUniqueKey('primary', true);
|
518
|
break;
|
519
|
case 'save_add_primary_key':
|
520
|
if (isset($_POST['cancel'])) doDefault();
|
521
|
else addPrimaryOrUniqueKey('primary', false);
|
522
|
break;
|
523
|
case 'add_check':
|
524
|
addCheck(true);
|
525
|
break;
|
526
|
case 'save_add_check':
|
527
|
if (isset($_POST['cancel'])) doDefault();
|
528
|
else addCheck(false);
|
529
|
break;
|
530
|
case 'save_create':
|
531
|
doSaveCreate();
|
532
|
break;
|
533
|
case 'create':
|
534
|
doCreate();
|
535
|
break;
|
536
|
case 'drop':
|
537
|
if (isset($_POST['drop'])) doDrop(false);
|
538
|
else doDefault();
|
539
|
break;
|
540
|
case 'confirm_drop':
|
541
|
doDrop(true);
|
542
|
break;
|
543
|
default:
|
544
|
doDefault();
|
545
|
break;
|
546
|
}
|
547
|
|
548
|
$misc->printFooter();
|
549
|
|
550
|
?>
|