This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
forked from phppgadmin/phppgadmin
-
Notifications
You must be signed in to change notification settings - Fork 3
/
database.php
702 lines (631 loc) · 30 KB
/
database.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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
<?php
/**
* Manage schemas within a database
*
* $Id: database.php,v 1.104 2007/11/30 06:04:43 xzilla Exp $
*/
// Include application functions
include_once('./libraries/lib.inc.php');
$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
if (!isset($msg)) $msg = '';
$scripts = '';
function _highlight($string, $term) {
return str_replace($term, "<b>{$term}</b>", $string);
}
/**
* Sends a signal to a process
*/
function doSignal() {
global $data, $lang;
$status = $data->sendSignal($_REQUEST['pid'], $_REQUEST['signal']);
if ($status == 0)
doProcesses($lang['strsignalsent']);
else
doProcesses($lang['strsignalsentbad']);
}
/**
* Searches for a named database object
*/
function doFind($confirm = true, $msg = '') {
global $data, $misc;
global $lang, $conf;
if (!isset($_REQUEST['term'])) $_REQUEST['term'] = '';
if (!isset($_REQUEST['filter'])) $_REQUEST['filter'] = '';
$misc->printTrail('database');
$misc->printTabs('database','find');
$misc->printMsg($msg);
echo "<form action=\"database.php\" method=\"post\">\n";
echo "<p><input name=\"term\" value=\"", htmlspecialchars($_REQUEST['term']),
"\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" />\n";
// Output list of filters. This is complex due to all the 'has' and 'conf' feature possibilities
echo "<select name=\"filter\">\n";
echo "\t<option value=\"\"", ($_REQUEST['filter'] == '') ? ' selected="selected"' : '', ">{$lang['strallobjects']}</option>\n";
echo "\t<option value=\"SCHEMA\"", ($_REQUEST['filter'] == 'SCHEMA') ? ' selected="selected"' : '', ">{$lang['strschemas']}</option>\n";
echo "\t<option value=\"TABLE\"", ($_REQUEST['filter'] == 'TABLE') ? ' selected="selected"' : '', ">{$lang['strtables']}</option>\n";
echo "\t<option value=\"VIEW\"", ($_REQUEST['filter'] == 'VIEW') ? ' selected="selected"' : '', ">{$lang['strviews']}</option>\n";
echo "\t<option value=\"SEQUENCE\"", ($_REQUEST['filter'] == 'SEQUENCE') ? ' selected="selected"' : '', ">{$lang['strsequences']}</option>\n";
echo "\t<option value=\"COLUMN\"", ($_REQUEST['filter'] == 'COLUMN') ? ' selected="selected"' : '', ">{$lang['strcolumns']}</option>\n";
echo "\t<option value=\"RULE\"", ($_REQUEST['filter'] == 'RULE') ? ' selected="selected"' : '', ">{$lang['strrules']}</option>\n";
echo "\t<option value=\"INDEX\"", ($_REQUEST['filter'] == 'INDEX') ? ' selected="selected"' : '', ">{$lang['strindexes']}</option>\n";
echo "\t<option value=\"TRIGGER\"", ($_REQUEST['filter'] == 'TRIGGER') ? ' selected="selected"' : '', ">{$lang['strtriggers']}</option>\n";
echo "\t<option value=\"CONSTRAINT\"", ($_REQUEST['filter'] == 'CONSTRAINT') ? ' selected="selected"' : '', ">{$lang['strconstraints']}</option>\n";
echo "\t<option value=\"FUNCTION\"", ($_REQUEST['filter'] == 'FUNCTION') ? ' selected="selected"' : '', ">{$lang['strfunctions']}</option>\n";
echo "\t<option value=\"DOMAIN\"", ($_REQUEST['filter'] == 'DOMAIN') ? ' selected="selected"' : '', ">{$lang['strdomains']}</option>\n";
if ($conf['show_advanced']) {
echo "\t<option value=\"AGGREGATE\"", ($_REQUEST['filter'] == 'AGGREGATE') ? ' selected="selected"' : '', ">{$lang['straggregates']}</option>\n";
echo "\t<option value=\"TYPE\"", ($_REQUEST['filter'] == 'TYPE') ? ' selected="selected"' : '', ">{$lang['strtypes']}</option>\n";
echo "\t<option value=\"OPERATOR\"", ($_REQUEST['filter'] == 'OPERATOR') ? ' selected="selected"' : '', ">{$lang['stroperators']}</option>\n";
echo "\t<option value=\"OPCLASS\"", ($_REQUEST['filter'] == 'OPCLASS') ? ' selected="selected"' : '', ">{$lang['stropclasses']}</option>\n";
echo "\t<option value=\"CONVERSION\"", ($_REQUEST['filter'] == 'CONVERSION') ? ' selected="selected"' : '', ">{$lang['strconversions']}</option>\n";
echo "\t<option value=\"LANGUAGE\"", ($_REQUEST['filter'] == 'LANGUAGE') ? ' selected="selected"' : '', ">{$lang['strlanguages']}</option>\n";
}
echo "</select>\n";
echo "<input type=\"submit\" value=\"{$lang['strfind']}\" />\n";
echo $misc->form;
echo "<input type=\"hidden\" name=\"action\" value=\"find\" /></p>\n";
echo "</form>\n";
// Default focus
$misc->setFocus('forms[0].term');
// If a search term has been specified, then perform the search
// and display the results, grouped by object type
if ($_REQUEST['term'] != '') {
$rs = $data->findObject($_REQUEST['term'], $_REQUEST['filter']);
if ($rs->recordCount() > 0) {
$curr = '';
while (!$rs->EOF) {
// Output a new header if the current type has changed, but not if it's just changed the rule type
if ($rs->fields['type'] != $curr) {
// Short-circuit in the case of changing from table rules to view rules; table cols to view cols;
// table constraints to domain constraints
if ($rs->fields['type'] == 'RULEVIEW' && $curr == 'RULETABLE') {
$curr = $rs->fields['type'];
}
elseif ($rs->fields['type'] == 'COLUMNVIEW' && $curr == 'COLUMNTABLE') {
$curr = $rs->fields['type'];
}
elseif ($rs->fields['type'] == 'CONSTRAINTTABLE' && $curr == 'CONSTRAINTDOMAIN') {
$curr = $rs->fields['type'];
}
else {
if ($curr != '') echo "</ul>\n";
$curr = $rs->fields['type'];
echo "<h3>";
switch ($curr) {
case 'SCHEMA':
echo $lang['strschemas'];
break;
case 'TABLE':
echo $lang['strtables'];
break;
case 'VIEW':
echo $lang['strviews'];
break;
case 'SEQUENCE':
echo $lang['strsequences'];
break;
case 'COLUMNTABLE':
case 'COLUMNVIEW':
echo $lang['strcolumns'];
break;
case 'INDEX':
echo $lang['strindexes'];
break;
case 'CONSTRAINTTABLE':
case 'CONSTRAINTDOMAIN':
echo $lang['strconstraints'];
break;
case 'TRIGGER':
echo $lang['strtriggers'];
break;
case 'RULETABLE':
case 'RULEVIEW':
echo $lang['strrules'];
break;
case 'FUNCTION':
echo $lang['strfunctions'];
break;
case 'TYPE':
echo $lang['strtypes'];
break;
case 'DOMAIN':
echo $lang['strdomains'];
break;
case 'OPERATOR':
echo $lang['stroperators'];
break;
case 'CONVERSION':
echo $lang['strconversions'];
break;
case 'LANGUAGE':
echo $lang['strlanguages'];
break;
case 'AGGREGATE':
echo $lang['straggregates'];
break;
case 'OPCLASS':
echo $lang['stropclasses'];
break;
}
echo "</h3>";
echo "<ul>\n";
}
}
switch ($curr) {
case 'SCHEMA':
echo "<li><a href=\"redirect.php?subject=schema&{$misc->href}&schema=", $misc->printVal($rs->fields['name']), "\">", _highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
case 'TABLE':
echo "<li>";
echo "<a href=\"tables.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['schemaname']), "</a>.";
echo "<a href=\"redirect.php?subject=table&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "&table=",
urlencode($rs->fields['name']), "\">", _highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
case 'VIEW':
echo "<li>";
echo "<a href=\"views.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['schemaname']), "</a>.";
echo "<a href=\"redirect.php?subject=view&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "&view=",
urlencode($rs->fields['name']), "\">", _highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
case 'SEQUENCE':
echo "<li>";
echo "<a href=\"sequences.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['schemaname']), "</a>.";
echo "<a href=\"sequences.php?subject=sequence&action=properties&{$misc->href}&schema=", urlencode($rs->fields['schemaname']),
"&sequence=", urlencode($rs->fields['name']), "\">", _highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
case 'COLUMNTABLE':
echo "<li>";
echo "<a href=\"redirect.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['schemaname']), "</a>.";
echo "<a href=\"tblproperties.php?subject=table&{$misc->href}&table=", urlencode($rs->fields['relname']), "&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['relname']), "</a>.";
echo "<a href=\"colproperties.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "&table=",
urlencode($rs->fields['relname']), "&column=", urlencode($rs->fields['name']), "\">",
_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
case 'COLUMNVIEW':
echo "<li>";
echo "<a href=\"redirect.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['schemaname']), "</a>.";
echo "<a href=\"viewproperties.php?subject=view&{$misc->href}&view=", urlencode($rs->fields['relname']), "&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['relname']), "</a>.";
echo "<a href=\"colproperties.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "&view=",
urlencode($rs->fields['relname']), "&column=", urlencode($rs->fields['name']), "\">",
_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
case 'INDEX':
echo "<li>";
echo "<a href=\"redirect.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['schemaname']), "</a>.";
echo "<a href=\"redirect.php?subject=table&{$misc->href}&table=", urlencode($rs->fields['relname']), "&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['relname']), "</a>.";
echo "<a href=\"indexes.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "&table=", urlencode($rs->fields['relname']), "\">", _highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
case 'CONSTRAINTTABLE':
echo "<li>";
echo "<a href=\"redirect.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['schemaname']), "</a>.";
echo "<a href=\"redirect.php?subject=table&{$misc->href}&table=", urlencode($rs->fields['relname']), "&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['relname']), "</a>.";
echo "<a href=\"constraints.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "&table=",
urlencode($rs->fields['relname']), "\">", _highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
case 'CONSTRAINTDOMAIN':
echo "<li>";
echo "<a href=\"domains.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['schemaname']), "</a>.";
echo "<a href=\"domains.php?action=properties&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "&domain=", urlencode($rs->fields['relname']), "\">",
$misc->printVal($rs->fields['relname']), '.', _highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
case 'TRIGGER':
echo "<li>";
echo "<a href=\"redirect.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['schemaname']), "</a>.";
echo "<a href=\"redirect.php?subject=table&{$misc->href}&table=", urlencode($rs->fields['relname']), "&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['relname']), "</a>.";
echo "<a href=\"triggers.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "&table=", urlencode($rs->fields['relname']), "\">",
_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
case 'RULETABLE':
echo "<li>";
echo "<a href=\"redirect.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['schemaname']), "</a>.";
echo "<a href=\"redirect.php?subject=table&{$misc->href}&table=", urlencode($rs->fields['relname']), "&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['relname']), "</a>.";
echo "<a href=\"rules.php?subject=table&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "&reltype=table&table=",
urlencode($rs->fields['relname']), "\">", _highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
case 'RULEVIEW':
echo "<li>";
echo "<a href=\"redirect.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['schemaname']), "</a>.";
echo "<a href=\"redirect.php?subject=view&{$misc->href}&view=", urlencode($rs->fields['relname']), "&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['relname']), "</a>.";
echo "<a href=\"rules.php?subject=view&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "&reltype=view&view=",
urlencode($rs->fields['relname']), "\">", _highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
case 'FUNCTION':
echo "<li>";
echo "<a href=\"functions.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['schemaname']), "</a>.";
echo "<a href=\"functions.php?action=properties&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "&function=",
urlencode($rs->fields['name']), "&function_oid=", urlencode($rs->fields['oid']), "\">",
_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
case 'TYPE':
echo "<li>";
echo "<a href=\"types.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['schemaname']), "</a>.";
echo "<a href=\"types.php?action=properties&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "&type=",
urlencode($rs->fields['name']), "\">", _highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
case 'DOMAIN':
echo "<li>";
echo "<a href=\"domains.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['schemaname']), "</a>.";
echo "<a href=\"domains.php?action=properties&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "&domain=",
urlencode($rs->fields['name']), "\">", _highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
case 'OPERATOR':
echo "<li>";
echo "<a href=\"operators.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['schemaname']), "</a>.";
echo "<a href=\"operators.php?action=properties&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "&operator=",
urlencode($rs->fields['name']), "&operator_oid=", urlencode($rs->fields['oid']) ,"\">", _highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
case 'CONVERSION':
echo "<li>";
echo "<a href=\"conversions.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['schemaname']), "</a>.";
echo "<a href=\"conversions.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']),
"\">", _highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
case 'LANGUAGE':
echo "<li><a href=\"languages.php?{$misc->href}\">", _highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
case 'AGGREGATE':
echo "<li>";
echo "<a href=\"aggregates.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['schemaname']), "</a>.";
echo "<a href=\"aggregates.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">",
_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
case 'OPCLASS':
echo "<li>";
echo "<a href=\"redirect.php?subject=schema&{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">", $misc->printVal($rs->fields['schemaname']), "</a>.";
echo "<a href=\"opclasses.php?{$misc->href}&schema=", urlencode($rs->fields['schemaname']), "\">",
_highlight($misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
break;
}
$rs->moveNext();
}
echo "</ul>\n";
echo "<p>", $rs->recordCount(), " ", $lang['strobjects'], "</p>\n";
}
else echo "<p>{$lang['strnoobjects']}</p>\n";
}
}
/**
* Displays options for database download
*/
function doExport($msg = '') {
global $data, $misc;
global $lang;
$misc->printTrail('database');
$misc->printTabs('database','export');
$misc->printMsg($msg);
echo "<form action=\"dbexport.php\" method=\"post\">\n";
echo "<table>\n";
echo "<tr><th class=\"data\">{$lang['strformat']}</th><th class=\"data\" colspan=\"2\">{$lang['stroptions']}</th></tr>\n";
// Data only
echo "<tr><th class=\"data left\" rowspan=\"". ($data->hasServerOids() ? 2 : 1) ."\">";
echo "<input type=\"radio\" id=\"what1\" name=\"what\" value=\"dataonly\" checked=\"checked\" /><label for=\"what1\">{$lang['strdataonly']}</label></th>\n";
echo "<td>{$lang['strformat']}</td>\n";
echo "<td><select name=\"d_format\">\n";
echo "<option value=\"copy\">COPY</option>\n";
echo "<option value=\"sql\">SQL</option>\n";
echo "</select>\n</td>\n</tr>\n";
if ($data->hasServerOids()) {
echo "<tr><td><label for=\"d_oids\">{$lang['stroids']}</label></td><td><input type=\"checkbox\" id=\"d_oids\" name=\"d_oids\" /></td>\n</tr>\n";
}
// Structure only
echo "<tr><th class=\"data left\"><input type=\"radio\" id=\"what2\" name=\"what\" value=\"structureonly\" /><label for=\"what2\">{$lang['strstructureonly']}</label></th>\n";
echo "<td><label for=\"s_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"s_clean\" name=\"s_clean\" /></td>\n</tr>\n";
// Structure and data
echo "<tr><th class=\"data left\" rowspan=\"". ($data->hasServerOids() ? 3 : 2) ."\">";
echo "<input type=\"radio\" id=\"what3\" name=\"what\" value=\"structureanddata\" /><label for=\"what3\">{$lang['strstructureanddata']}</label></th>\n";
echo "<td>{$lang['strformat']}</td>\n";
echo "<td><select name=\"sd_format\">\n";
echo "<option value=\"copy\">COPY</option>\n";
echo "<option value=\"sql\">SQL</option>\n";
echo "</select>\n</td>\n</tr>\n";
echo "<tr><td><label for=\"sd_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"sd_clean\" name=\"sd_clean\" /></td>\n</tr>\n";
if ($data->hasServerOids()) {
echo "<tr><td><label for=\"sd_oids\">{$lang['stroids']}</label></td><td><input type=\"checkbox\" id=\"sd_oids\" name=\"sd_oids\" /></td>\n</tr>\n";
}
echo "</table>\n";
echo "<h3>{$lang['stroptions']}</h3>\n";
echo "<p><input type=\"radio\" id=\"output1\" name=\"output\" value=\"show\" checked=\"checked\" /><label for=\"output1\">{$lang['strshow']}</label>\n";
echo "<br/><input type=\"radio\" id=\"output2\" name=\"output\" value=\"download\" /><label for=\"output2\">{$lang['strdownload']}</label>\n";
// MSIE cannot download gzip in SSL mode - it's just broken
if (!(strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && isset($_SERVER['HTTPS']))) {
echo "<br /><input type=\"radio\" id=\"output3\" name=\"output\" value=\"gzipped\" /><label for=\"output3\">{$lang['strdownloadgzipped']}</label>\n";
}
echo "</p>\n";
echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n";
echo "<input type=\"hidden\" name=\"subject\" value=\"database\" />\n";
echo $misc->form;
echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n";
echo "</form>\n";
}
/**
* Show the current status of all database variables
*/
function doVariables() {
global $data, $misc;
global $lang;
// Fetch the variables from the database
$variables = $data->getVariables();
$misc->printTrail('database');
$misc->printTabs('database','variables');
$columns = array(
'variable' => array(
'title' => $lang['strname'],
'field' => field('name'),
),
'value' => array(
'title' => $lang['strsetting'],
'field' => field('setting'),
),
);
$actions = array();
$misc->printTable($variables, $columns, $actions, 'database-variables', $lang['strnodata']);
}
/**
* Show all current database connections and any queries they
* are running.
*/
function doProcesses($msg = '') {
global $data, $misc;
global $lang;
$misc->printTrail('database');
$misc->printTabs('database','processes');
$misc->printMsg($msg);
if (strlen($msg) === 0) {
echo "<br /><a id=\"control\" href=\"\"><img src=\"".$misc->icon('Refresh')."\" alt=\"{$lang['strrefresh']}\" title=\"{$lang['strrefresh']}\"/> {$lang['strrefresh']}</a>";
}
echo "<div id=\"data_block\">";
currentProcesses();
echo "</div>";
}
function currentProcesses($isAjax = false) {
global $data, $misc, $lang;
// Display prepared transactions
if($data->hasPreparedXacts()) {
echo "<h3>{$lang['strpreparedxacts']}</h3>\n";
$prep_xacts = $data->getPreparedXacts($_REQUEST['database']);
$columns = array(
'transaction' => array(
'title' => $lang['strxactid'],
'field' => field('transaction'),
),
'gid' => array(
'title' => $lang['strgid'],
'field' => field('gid'),
),
'prepared' => array(
'title' => $lang['strstarttime'],
'field' => field('prepared'),
),
'owner' => array(
'title' => $lang['strowner'],
'field' => field('owner'),
),
);
$actions = array();
$misc->printTable($prep_xacts, $columns, $actions, 'database-processes-preparedxacts', $lang['strnodata']);
}
// Fetch the processes from the database
echo "<h3>{$lang['strprocesses']}</h3>\n";
$processes = $data->getProcesses($_REQUEST['database']);
$columns = array(
'user' => array(
'title' => $lang['strusername'],
'field' => field('usename'),
),
'process' => array(
'title' => $lang['strprocess'],
'field' => field('pid'),
),
'blocked' => array(
'title' => $lang['strblocked'],
'field' => field('waiting'),
),
'query' => array(
'title' => $lang['strsql'],
'field' => field('query'),
),
'start_time' => array(
'title' => $lang['strstarttime'],
'field' => field('query_start'),
),
);
// Build possible actions for our process list
$columns['actions'] = array('title' => $lang['stractions']);
$actions = array();
if ($data->hasUserSignals() || $data->isSuperUser()) {
$actions = array(
'cancel' => array(
'content' => $lang['strcancel'],
'attr'=> array (
'href' => array (
'url' => 'database.php',
'urlvars' => array (
'action' => 'signal',
'signal' => 'CANCEL',
'pid' => field('pid')
)
)
)
),
'kill' => array(
'content' => $lang['strkill'],
'attr'=> array (
'href' => array (
'url' => 'database.php',
'urlvars' => array (
'action' => 'signal',
'signal' => 'KILL',
'pid' => field('pid')
)
)
)
)
);
// Remove actions where not supported
if (!$data->hasQueryKill()) unset($actions['kill']);
if (!$data->hasQueryCancel()) unset($actions['cancel']);
}
if (count($actions) == 0) unset($columns['actions']);
$misc->printTable($processes, $columns, $actions, 'database-processes', $lang['strnodata']);
if ($isAjax) exit;
}
function currentLocks($isAjax = false) {
global $data, $misc, $lang;
// Get the info from the pg_locks view
$variables = $data->getLocks();
$columns = array(
'namespace' => array(
'title' => $lang['strschema'],
'field' => field('nspname'),
),
'tablename' => array(
'title' => $lang['strtablename'],
'field' => field('tablename'),
),
'vxid' => array(
'title' => $lang['strvirtualtransaction'],
'field' => field('virtualtransaction'),
),
'transactionid' => array(
'title' => $lang['strtransaction'],
'field' => field('transaction'),
),
'processid' => array(
'title' => $lang['strprocessid'],
'field' => field('pid'),
),
'mode' => array(
'title' => $lang['strmode'],
'field' => field('mode'),
),
'granted' => array(
'title' => $lang['strislockheld'],
'field' => field('granted'),
'type' => 'yesno',
),
);
if (!$data->hasVirtualTransactionId()) unset($columns['vxid']);
$actions = array();
$misc->printTable($variables, $columns, $actions, 'database-locks', $lang['strnodata']);
if ($isAjax) exit;
}
/**
* Show the existing table locks in the current database
*/
function doLocks() {
global $data, $misc;
global $lang;
$misc->printTrail('database');
$misc->printTabs('database','locks');
echo "<br /><a id=\"control\" href=\"\"><img src=\"".$misc->icon('Refresh')."\" alt=\"{$lang['strrefresh']}\" title=\"{$lang['strrefresh']}\"/> {$lang['strrefresh']}</a>";
echo "<div id=\"data_block\">";
currentLocks();
echo "</div>";
}
/**
* Allow execution of arbitrary SQL statements on a database
*/
function doSQL() {
global $data, $misc;
global $lang;
if ((!isset($_SESSION['sqlquery'])) || isset($_REQUEST['new'])) {
$_SESSION['sqlquery'] = '';
$_REQUEST['paginate'] = 'on';
}
$misc->printTrail('database');
$misc->printTabs('database','sql');
echo "<p>{$lang['strentersql']}</p>\n";
echo "<form action=\"sql.php\" method=\"post\" enctype=\"multipart/form-data\">\n";
echo "<p>{$lang['strsql']}<br />\n";
echo "<textarea style=\"width:100%;\" rows=\"20\" cols=\"50\" name=\"query\">",
htmlspecialchars($_SESSION['sqlquery']), "</textarea></p>\n";
// Check that file uploads are enabled
if (ini_get('file_uploads')) {
// Don't show upload option if max size of uploads is zero
$max_size = $misc->inisizeToBytes(ini_get('upload_max_filesize'));
if (is_double($max_size) && $max_size > 0) {
echo "<p><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"{$max_size}\" />\n";
echo "<label for=\"script\">{$lang['struploadscript']}</label> <input id=\"script\" name=\"script\" type=\"file\" /></p>\n";
}
}
echo "<p><input type=\"checkbox\" id=\"paginate\" name=\"paginate\"", (isset($_REQUEST['paginate']) ? ' checked="checked"' : ''), " /><label for=\"paginate\">{$lang['strpaginate']}</label></p>\n";
echo "<p><input type=\"submit\" name=\"execute\" accesskey=\"r\" value=\"{$lang['strexecute']}\" />\n";
echo $misc->form;
echo "<input type=\"reset\" accesskey=\"q\" value=\"{$lang['strreset']}\" /></p>\n";
echo "</form>\n";
// Default focus
$misc->setFocus('forms[0].query');
}
function doTree() {
global $misc, $data, $lang;
$reqvars = $misc->getRequestVars('database');
$tabs = $misc->getNavTabs('database');
$items = $misc->adjustTabsForTree($tabs);
$attrs = array(
'text' => field('title'),
'icon' => field('icon'),
'action' => url(field('url'),
$reqvars,
field('urlvars', array())
),
'branch' => url(field('url'),
$reqvars,
field('urlvars'),
array('action' => 'tree')
),
);
$misc->printTree($items, $attrs, 'database');
exit;
}
require('./admin.php');
/* shortcuts: these functions exit the script */
if ($action == 'tree') doTree();
if ($action == 'refresh_locks') currentLocks(true);
if ($action == 'refresh_processes') currentProcesses(true);
/* normal flow */
if ($action == 'locks' or $action == 'processes') {
$scripts .= "<script src=\"js/database.js\" type=\"text/javascript\"></script>";
$refreshTime = $conf['ajax_refresh'] * 1000;
$scripts .= "<script type=\"text/javascript\">\n";
$scripts .= "var Database = {\n";
$scripts .= "ajax_time_refresh: {$refreshTime},\n";
$scripts .= "str_start: {text:'{$lang['strstart']}',icon: '". $misc->icon('Execute') ."'},\n";
$scripts .= "str_stop: {text:'{$lang['strstop']}',icon: '". $misc->icon('Stop') ."'},\n";
$scripts .= "load_icon: '". $misc->icon('Loading') ."',\n";
$scripts .= "server:'{$_REQUEST['server']}',\n";
$scripts .= "dbname:'{$_REQUEST['database']}',\n";
$scripts .= "action:'refresh_{$action}',\n";
$scripts .= "errmsg: '". str_replace("'", "\'", $lang['strconnectionfail']) ."'\n";
$scripts .= "};\n";
$scripts .= "</script>\n";
}
$misc->printHeader($lang['strdatabase'], $scripts);
$misc->printBody();
switch ($action) {
case 'find':
if (isset($_REQUEST['term'])) doFind(false);
else doFind(true);
break;
case 'sql':
doSQL();
break;
case 'variables':
doVariables();
break;
case 'processes':
doProcesses();
break;
case 'locks':
doLocks();
break;
case 'export':
doExport();
break;
case 'signal':
doSignal();
break;
default:
if (adminActions($action, 'database') === false) doSQL();
break;
}
$misc->printFooter();
?>