forked from myfarms/phppgadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
domains.php
587 lines (521 loc) · 18.5 KB
/
domains.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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
<?php
/**
* Manage domains in a database
*
* $Id: domains.php,v 1.34 2007/09/13 13:41:01 ioguix Exp $
*/
// Include application functions
include_once('./libraries/lib.inc.php');
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
if (!isset($msg)) $msg = '';
/**
* Function to save after altering a domain
*/
function doSaveAlter() {
global $data, $lang;
$status = $data->alterDomain($_POST['domain'], $_POST['domdefault'],
isset($_POST['domnotnull']), $_POST['domowner']);
if ($status == 0)
doProperties($lang['strdomainaltered']);
else
doAlter($lang['strdomainalteredbad']);
}
/**
* Allow altering a domain
*/
function doAlter($msg = '') {
global $data, $misc;
global $lang;
$misc->printTrail('domain');
$misc->printTitle($lang['stralter'],'pg.domain.alter');
$misc->printMsg($msg);
// Fetch domain info
$domaindata = $data->getDomain($_REQUEST['domain']);
// Fetch all users
$users = $data->getUsers();
if ($domaindata->recordCount() > 0) {
if (!isset($_POST['domname'])) {
$_POST['domtype'] = $domaindata->fields['domtype'];
$_POST['domdefault'] = $domaindata->fields['domdef'];
$domaindata->fields['domnotnull'] = $data->phpBool($domaindata->fields['domnotnull']);
if ($domaindata->fields['domnotnull']) $_POST['domnotnull'] = 'on';
$_POST['domowner'] = $domaindata->fields['domowner'];
}
// Display domain info
echo "<form action=\"domains.php\" method=\"post\">\n";
echo "<table>\n";
echo "<tr><th class=\"data left required\" style=\"width: 70px\">{$lang['strname']}</th>\n";
echo "<td class=\"data1\">", $misc->printVal($domaindata->fields['domname']), "</td></tr>\n";
echo "<tr><th class=\"data left required\">{$lang['strtype']}</th>\n";
echo "<td class=\"data1\">", $misc->printVal($domaindata->fields['domtype']), "</td></tr>\n";
echo "<tr><th class=\"data left\"><label for=\"domnotnull\">{$lang['strnotnull']}</label></th>\n";
echo "<td class=\"data1\"><input type=\"checkbox\" id=\"domnotnull\" name=\"domnotnull\"", (isset($_POST['domnotnull']) ? ' checked="checked"' : ''), " /></td></tr>\n";
echo "<tr><th class=\"data left\">{$lang['strdefault']}</th>\n";
echo "<td class=\"data1\"><input name=\"domdefault\" size=\"32\" value=\"",
htmlspecialchars($_POST['domdefault']), "\" /></td></tr>\n";
echo "<tr><th class=\"data left required\">{$lang['strowner']}</th>\n";
echo "<td class=\"data1\"><select name=\"domowner\">";
while (!$users->EOF) {
$uname = $users->fields['usename'];
echo "<option value=\"", htmlspecialchars($uname), "\"",
($uname == $_POST['domowner']) ? ' selected="selected"' : '', ">", htmlspecialchars($uname), "</option>\n";
$users->moveNext();
}
echo "</select></td></tr>\n";
echo "</table>\n";
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_alter\" />\n";
echo "<input type=\"hidden\" name=\"domain\" value=\"", htmlspecialchars($_REQUEST['domain']), "\" />\n";
echo $misc->form;
echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n";
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
echo "</form>\n";
}
else echo "<p>{$lang['strnodata']}</p>\n";
}
/**
* Confirm and then actually add a CHECK constraint
*/
function addCheck($confirm, $msg = '') {
global $data, $misc;
global $lang;
if (!isset($_POST['name'])) $_POST['name'] = '';
if (!isset($_POST['definition'])) $_POST['definition'] = '';
if ($confirm) {
$misc->printTrail('domain');
$misc->printTitle($lang['straddcheck'],'pg.constraint.check');
$misc->printMsg($msg);
echo "<form action=\"domains.php\" method=\"post\">\n";
echo "<table>\n";
echo "<tr><th class=\"data\">{$lang['strname']}</th>\n";
echo "<th class=\"data required\">{$lang['strdefinition']}</th></tr>\n";
echo "<tr><td class=\"data1\"><input name=\"name\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"",
htmlspecialchars($_POST['name']), "\" /></td>\n";
echo "<td class=\"data1\">(<input name=\"definition\" size=\"32\" value=\"",
htmlspecialchars($_POST['definition']), "\" />)</td></tr>\n";
echo "</table>\n";
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_add_check\" />\n";
echo "<input type=\"hidden\" name=\"domain\" value=\"", htmlspecialchars($_REQUEST['domain']), "\" />\n";
echo $misc->form;
echo "<input type=\"submit\" name=\"add\" value=\"{$lang['stradd']}\" />\n";
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
echo "</form>\n";
}
else {
if (trim($_POST['definition']) == '')
addCheck(true, $lang['strcheckneedsdefinition']);
else {
$status = $data->addDomainCheckConstraint($_POST['domain'],
$_POST['definition'], $_POST['name']);
if ($status == 0)
doProperties($lang['strcheckadded']);
else
addCheck(true, $lang['strcheckaddedbad']);
}
}
}
/**
* Show confirmation of drop constraint and perform actual drop
*/
function doDropConstraint($confirm, $msg = '') {
global $data, $misc;
global $lang;
if ($confirm) {
$misc->printTrail('domain');
$misc->printTitle($lang['strdrop'],'pg.constraint.drop');
$misc->printMsg($msg);
echo "<p>", sprintf($lang['strconfdropconstraint'], $misc->printVal($_REQUEST['constraint']),
$misc->printVal($_REQUEST['domain'])), "</p>\n";
echo "<form action=\"domains.php\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"action\" value=\"drop_con\" />\n";
echo "<input type=\"hidden\" name=\"domain\" value=\"", htmlspecialchars($_REQUEST['domain']), "\" />\n";
echo "<input type=\"hidden\" name=\"constraint\" value=\"", htmlspecialchars($_REQUEST['constraint']), "\" />\n";
echo $misc->form;
echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$lang['strcascade']}</label></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 = $data->dropDomainConstraint($_POST['domain'], $_POST['constraint'], isset($_POST['cascade']));
if ($status == 0)
doProperties($lang['strconstraintdropped']);
else
doDropConstraint(true, $lang['strconstraintdroppedbad']);
}
}
/**
* Show properties for a domain. Allow manipulating constraints as well.
*/
function doProperties($msg = '') {
global $data, $misc;
global $lang;
$misc->printTrail('domain');
$misc->printTitle($lang['strproperties'],'pg.domain');
$misc->printMsg($msg);
$domaindata = $data->getDomain($_REQUEST['domain']);
if ($domaindata->recordCount() > 0) {
// Show comment if any
if ($domaindata->fields['domcomment'] !== null)
echo "<p class=\"comment\">", $misc->printVal($domaindata->fields['domcomment']), "</p>\n";
// Display domain info
$domaindata->fields['domnotnull'] = $data->phpBool($domaindata->fields['domnotnull']);
echo "<table>\n";
echo "<tr><th class=\"data left\" style=\"width: 70px\">{$lang['strname']}</th>\n";
echo "<td class=\"data1\">", $misc->printVal($domaindata->fields['domname']), "</td></tr>\n";
echo "<tr><th class=\"data left\">{$lang['strtype']}</th>\n";
echo "<td class=\"data1\">", $misc->printVal($domaindata->fields['domtype']), "</td></tr>\n";
echo "<tr><th class=\"data left\">{$lang['strnotnull']}</th>\n";
echo "<td class=\"data1\">", ($domaindata->fields['domnotnull'] ? 'NOT NULL' : ''), "</td></tr>\n";
echo "<tr><th class=\"data left\">{$lang['strdefault']}</th>\n";
echo "<td class=\"data1\">", $misc->printVal($domaindata->fields['domdef']), "</td></tr>\n";
echo "<tr><th class=\"data left\">{$lang['strowner']}</th>\n";
echo "<td class=\"data1\">", $misc->printVal($domaindata->fields['domowner']), "</td></tr>\n";
echo "</table>\n";
// Display domain constraints
echo "<h3>{$lang['strconstraints']}</h3>\n";
if ($data->hasDomainConstraints()) {
$domaincons = $data->getDomainConstraints($_REQUEST['domain']);
$columns = array (
'name' => array (
'title' => $lang['strname'],
'field' => field('conname')
),
'definition' => array (
'title' => $lang['strdefinition'],
'field' => field('consrc'),
),
'actions' => array (
'title' => $lang['stractions'],
)
);
$actions = array (
'drop' => array (
'content' => $lang['strdrop'],
'attr'=> array (
'href' => array (
'url' => 'domains.php',
'urlvars' => array (
'action' => 'confirm_drop_con',
'domain' => $_REQUEST['domain'],
'constraint' => field('conname'),
'type' => field('contype'),
)
)
)
)
);
$misc->printTable($domaincons, $columns, $actions, 'domains-properties', $lang['strnodata']);
}
}
else echo "<p>{$lang['strnodata']}</p>\n";
$navlinks = array (
'drop' => array (
'attr'=> array (
'href' => array (
'url' => 'domains.php',
'urlvars' => array (
'action' => 'confirm_drop',
'server' => $_REQUEST['server'],
'database' => $_REQUEST['database'],
'schema' => $_REQUEST['schema'],
'domain' => $_REQUEST['domain']
)
)
),
'content' => $lang['strdrop']
)
);
if ($data->hasAlterDomains()) {
$navlinks['addcheck'] = array (
'attr'=> array (
'href' => array (
'url' => 'domains.php',
'urlvars' => array (
'action' => 'add_check',
'server' => $_REQUEST['server'],
'database' => $_REQUEST['database'],
'schema' => $_REQUEST['schema'],
'domain' => $_REQUEST['domain']
)
)
),
'content' => $lang['straddcheck']
);
$navlinks['alter'] = array (
'attr'=> array (
'href' => array (
'url' => 'domains.php',
'urlvars' => array (
'action' => 'alter',
'server' => $_REQUEST['server'],
'database' => $_REQUEST['database'],
'schema' => $_REQUEST['schema'],
'domain' => $_REQUEST['domain']
)
)
),
'content' => $lang['stralter']
);
}
$misc->printNavLinks($navlinks, 'domains-properties', get_defined_vars());
}
/**
* Show confirmation of drop and perform actual drop
*/
function doDrop($confirm) {
global $data, $misc;
global $lang;
if ($confirm) {
$misc->printTrail('domain');
$misc->printTitle($lang['strdrop'],'pg.domain.drop');
echo "<p>", sprintf($lang['strconfdropdomain'], $misc->printVal($_REQUEST['domain'])), "</p>\n";
echo "<form action=\"domains.php\" method=\"post\">\n";
echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /><label for=\"cascade\">{$lang['strcascade']}</label></p>\n";
echo "<p><input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
echo "<input type=\"hidden\" name=\"domain\" value=\"", htmlspecialchars($_REQUEST['domain']), "\" />\n";
echo $misc->form;
echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
echo "</form>\n";
}
else {
$status = $data->dropDomain($_POST['domain'], isset($_POST['cascade']));
if ($status == 0)
doDefault($lang['strdomaindropped']);
else
doDefault($lang['strdomaindroppedbad']);
}
}
/**
* Displays a screen where they can enter a new domain
*/
function doCreate($msg = '') {
global $data, $misc;
global $lang;
if (!isset($_POST['domname'])) $_POST['domname'] = '';
if (!isset($_POST['domtype'])) $_POST['domtype'] = '';
if (!isset($_POST['domlength'])) $_POST['domlength'] = '';
if (!isset($_POST['domarray'])) $_POST['domarray'] = '';
if (!isset($_POST['domdefault'])) $_POST['domdefault'] = '';
if (!isset($_POST['domcheck'])) $_POST['domcheck'] = '';
$types = $data->getTypes(true);
$misc->printTrail('schema');
$misc->printTitle($lang['strcreatedomain'],'pg.domain.create');
$misc->printMsg($msg);
echo "<form action=\"domains.php\" method=\"post\">\n";
echo "<table>\n";
echo "<tr><th class=\"data left required\" style=\"width: 70px\">{$lang['strname']}</th>\n";
echo "<td class=\"data1\"><input name=\"domname\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
htmlspecialchars($_POST['domname']), "\" /></td></tr>\n";
echo "<tr><th class=\"data left required\">{$lang['strtype']}</th>\n";
echo "<td class=\"data1\">\n";
// Output return type list
echo "<select name=\"domtype\">\n";
while (!$types->EOF) {
echo "<option value=\"", htmlspecialchars($types->fields['typname']), "\"",
($types->fields['typname'] == $_POST['domtype']) ? ' selected="selected"' : '', ">",
$misc->printVal($types->fields['typname']), "</option>\n";
$types->moveNext();
}
echo "</select>\n";
// Type length
echo "<input type=\"text\" size=\"4\" name=\"domlength\" value=\"", htmlspecialchars($_POST['domlength']), "\" />";
// Output array type selector
echo "<select name=\"domarray\">\n";
echo "<option value=\"\"", ($_POST['domarray'] == '') ? ' selected="selected"' : '', "></option>\n";
echo "<option value=\"[]\"", ($_POST['domarray'] == '[]') ? ' selected="selected"' : '', ">[ ]</option>\n";
echo "</select></td></tr>\n";
echo "<tr><th class=\"data left\"><label for=\"domnotnull\">{$lang['strnotnull']}</label></th>\n";
echo "<td class=\"data1\"><input type=\"checkbox\" id=\"domnotnull\" name=\"domnotnull\"",
(isset($_POST['domnotnull']) ? ' checked="checked"' : ''), " /></td></tr>\n";
echo "<tr><th class=\"data left\">{$lang['strdefault']}</th>\n";
echo "<td class=\"data1\"><input name=\"domdefault\" size=\"32\" value=\"",
htmlspecialchars($_POST['domdefault']), "\" /></td></tr>\n";
if ($data->hasDomainConstraints()) {
echo "<tr><th class=\"data left\">{$lang['strconstraints']}</th>\n";
echo "<td class=\"data1\">CHECK (<input name=\"domcheck\" size=\"32\" value=\"",
htmlspecialchars($_POST['domcheck']), "\" />)</td></tr>\n";
}
echo "</table>\n";
echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create\" />\n";
echo $misc->form;
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 domain in the database
*/
function doSaveCreate() {
global $data, $lang;
if (!isset($_POST['domcheck'])) $_POST['domcheck'] = '';
// Check that they've given a name and a definition
if ($_POST['domname'] == '') doCreate($lang['strdomainneedsname']);
else {
$status = $data->createDomain($_POST['domname'], $_POST['domtype'], $_POST['domlength'], $_POST['domarray'] != '',
isset($_POST['domnotnull']), $_POST['domdefault'], $_POST['domcheck']);
if ($status == 0)
doDefault($lang['strdomaincreated']);
else
doCreate($lang['strdomaincreatedbad']);
}
}
/**
* Show default list of domains in the database
*/
function doDefault($msg = '') {
global $data, $conf, $misc;
global $lang;
$misc->printTrail('schema');
$misc->printTabs('schema','domains');
$misc->printMsg($msg);
$domains = $data->getDomains();
$columns = array(
'domain' => array(
'title' => $lang['strdomain'],
'field' => field('domname'),
'url' => "domains.php?action=properties&{$misc->href}&",
'vars' => array('domain' => 'domname'),
),
'type' => array(
'title' => $lang['strtype'],
'field' => field('domtype'),
),
'notnull' => array(
'title' => $lang['strnotnull'],
'field' => field('domnotnull'),
'type' => 'bool',
'params'=> array('true' => 'NOT NULL', 'false' => ''),
),
'default' => array(
'title' => $lang['strdefault'],
'field' => field('domdef'),
),
'owner' => array(
'title' => $lang['strowner'],
'field' => field('domowner'),
),
'actions' => array(
'title' => $lang['stractions'],
),
'comment' => array(
'title' => $lang['strcomment'],
'field' => field('domcomment'),
),
);
$actions = array(
'alter' => array(
'content' => $lang['stralter'],
'attr'=> array (
'href' => array (
'url' => 'domains.php',
'urlvars' => array (
'action' => 'alter',
'domain' => field('domname')
)
)
)
),
'drop' => array(
'content' => $lang['strdrop'],
'attr'=> array (
'href' => array (
'url' => 'domains.php',
'urlvars' => array (
'action' => 'confirm_drop',
'domain' => field('domname')
)
)
)
),
);
if (!$data->hasAlterDomains()) unset($actions['alter']);
$misc->printTable($domains, $columns, $actions, 'domains-domains', $lang['strnodomains']);
$navlinks = array (
'create' => array (
'attr'=> array (
'href' => array (
'url' => 'domains.php',
'urlvars' => array (
'action' => 'create',
'server' => $_REQUEST['server'],
'database' => $_REQUEST['database'],
'schema' => $_REQUEST['schema'],
)
)
),
'content' => $lang['strcreatedomain']
)
);
$misc->printNavLinks($navlinks, 'domains-domains', get_defined_vars());
}
/**
* Generate XML for the browser tree.
*/
function doTree() {
global $misc, $data;
$domains = $data->getDomains();
$reqvars = $misc->getRequestVars('domain');
$attrs = array(
'text' => field('domname'),
'icon' => 'Domain',
'toolTip'=> field('domcomment'),
'action' => url('domains.php',
$reqvars,
array(
'action' => 'properties',
'domain' => field('domname')
)
)
);
$misc->printTree($domains, $attrs, 'domains');
exit;
}
if ($action == 'tree') doTree();
$misc->printHeader($lang['strdomains']);
$misc->printBody();
switch ($action) {
case 'add_check':
addCheck(true);
break;
case 'save_add_check':
if (isset($_POST['cancel'])) doProperties();
else addCheck(false);
break;
case 'drop_con':
if (isset($_POST['drop'])) doDropConstraint(false);
else doProperties();
break;
case 'confirm_drop_con':
doDropConstraint(true);
break;
case 'save_create':
if (isset($_POST['cancel'])) doDefault();
else doSaveCreate();
break;
case 'create':
doCreate();
break;
case 'drop':
if (isset($_POST['drop'])) doDrop(false);
else doDefault();
break;
case 'confirm_drop':
doDrop(true);
break;
case 'save_alter':
if (isset($_POST['alter'])) doSaveAlter();
else doProperties();
break;
case 'alter':
doAlter();
break;
case 'properties':
doProperties();
break;
default:
doDefault();
break;
}
$misc->printFooter();
?>