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
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
|
<?php
/**
* PHPPgAdmin v6.0.0-RC1
*/
namespace PHPPgAdmin\Controller;
use PHPPgAdmin\Decorators\Decorator;
/**
* Base controller class.
*
* @package PHPPgAdmin
*/
class DatabaseController extends BaseController
{
use \PHPPgAdmin\Traits\AdminTrait;
use \PHPPgAdmin\Traits\ExportTrait;
public $table_place = 'database-variables';
public $fields;
public $controller_title = 'strdatabase';
private function _highlight($string, $term)
{
return str_replace($term, "<b>{$term}</b>", $string);
}
/**
* Default method to render the controller according to the action parameter.
*/
public function render()
{
if ('tree' == $this->action) {
return $this->doTree();
}
if ('refresh_locks' == $this->action) {
return $this->currentLocks(true);
}
if ('refresh_processes' == $this->action) {
return $this->currentProcesses(true);
}
$scripts = '';
// normal flow
if ('locks' == $this->action || 'processes' == $this->action) {
$scripts .= '<script src="'.\SUBFOLDER.'/assets/js/database.js" type="text/javascript"></script>';
$refreshTime = $this->conf['ajax_refresh'] * 1500;
$scripts .= '<script type="text/javascript">'.PHP_EOL;
$scripts .= "var Database = {\n";
$scripts .= "ajax_time_refresh: {$refreshTime},\n";
$scripts .= "str_start: {text:'{$this->lang['strstart']}',icon: '".$this->misc->icon('Execute')."'},\n";
$scripts .= "str_stop: {text:'{$this->lang['strstop']}',icon: '".$this->misc->icon('Stop')."'},\n";
$scripts .= "load_icon: '".$this->misc->icon('Loading')."',\n";
$scripts .= "server:'{$_REQUEST['server']}',\n";
$scripts .= "dbname:'{$_REQUEST['database']}',\n";
$scripts .= "action:'refresh_{$this->action}',\n";
$scripts .= "errmsg: '".str_replace("'", "\\'", $this->lang['strconnectionfail'])."'\n";
$scripts .= "};\n";
$scripts .= '</script>'.PHP_EOL;
}
$header_template = 'header.twig';
$footer_template = 'footer.twig';
// @todo convert all these methods to return text instead of print text
ob_start();
switch ($this->action) {
case 'find':
if (isset($_REQUEST['term'])) {
$this->printFindForm(false);
} else {
$this->printFindForm(true);
}
break;
case 'sql':
$this->doSQL();
$header_template = 'header_sqledit.twig';
$footer_template = 'footer_sqledit.twig';
break;
case 'variables':
$this->doVariables();
break;
case 'processes':
$this->doProcesses();
break;
case 'locks':
$this->doLocks();
break;
case 'export':
$this->doExport();
break;
case 'signal':
$this->doSignal();
break;
default:
if (false === $this->adminActions($this->action, 'database')) {
$header_template = 'header_sqledit.twig';
$footer_template = 'footer_sqledit.twig';
$this->doSQL();
}
break;
}
$output = ob_get_clean();
$this->printHeader($this->headerTitle(), $scripts, true, $header_template);
$this->printBody();
echo $output;
$this->printFooter(true, $footer_template);
}
public function doTree($print = true)
{
$reqvars = $this->misc->getRequestVars('database');
$tabs = $this->misc->getNavTabs('database');
$items = $this->adjustTabsForTree($tabs);
$attrs = [
'text' => Decorator::field('title'),
'icon' => Decorator::field('icon'),
'action' => Decorator::actionurl(
Decorator::field('url'),
$reqvars,
Decorator::field('urlvars'),
[
'database' => $this->misc->getDatabase(),
]
),
'branch' => Decorator::branchurl(
Decorator::field('url'),
$reqvars,
Decorator::field('urlvars'),
[
'action' => 'tree',
'database' => $this->misc->getDatabase(),
]
),
];
return $this->printTree($items, $attrs, 'database', $print);
}
/**
* Sends a signal to a process.
*/
public function doSignal()
{
$data = $this->misc->getDatabaseAccessor();
$status = $data->sendSignal($_REQUEST['pid'], $_REQUEST['signal']);
if (0 == $status) {
$this->doProcesses($this->lang['strsignalsent']);
} else {
$this->doProcesses($this->lang['strsignalsentbad']);
}
}
/**
* Searches for a named database object.
*
* @param mixed $confirm
* @param mixed $msg
*/
public function printFindForm($confirm = true, $msg = '')
{
$data = $this->misc->getDatabaseAccessor();
$this->coalesceArr($_REQUEST, 'term', '');
$this->coalesceArr($_REQUEST, 'filter', '');
$this->printTrail('database');
$this->printTabs('database', 'find');
$this->printMsg($msg);
echo '<form action="'.\SUBFOLDER.'/src/views/database" method="post">'.PHP_EOL;
echo '<p><input name="term" value="', htmlspecialchars($_REQUEST['term']),
"\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" />".PHP_EOL;
// Output list of filters. This is complex due to all the 'has' and 'conf' feature possibilities
echo '<select name="filter">'.PHP_EOL;
echo $this->_printTypeOption('');
echo $this->_printTypeOption('COLUMN');
echo $this->_printTypeOption('CONSTRAINT');
echo $this->_printTypeOption('DOMAIN');
echo $this->_printTypeOption('FUNCTION');
echo $this->_printTypeOption('INDEX');
echo $this->_printTypeOption('RULE');
echo $this->_printTypeOption('SCHEMA');
echo $this->_printTypeOption('SEQUENCE');
echo $this->_printTypeOption('TABLE');
echo $this->_printTypeOption('TRIGGER');
echo $this->_printTypeOption('VIEW');
if ($this->conf['show_advanced']) {
echo $this->_printTypeOption('AGGREGATE');
echo $this->_printTypeOption('TYPE');
echo $this->_printTypeOption('OPERATOR');
echo $this->_printTypeOption('OPCLASS');
echo $this->_printTypeOption('CONVERSION');
echo $this->_printTypeOption('LANGUAGE');
}
echo '</select>'.PHP_EOL;
echo "<input type=\"submit\" value=\"{$this->lang['strfind']}\" />".PHP_EOL;
echo $this->misc->form;
echo '<input type="hidden" name="action" value="find" /></p>'.PHP_EOL;
echo '<input type="hidden" name="confirm" value="true" /></p>'.PHP_EOL;
echo '</form>'.PHP_EOL;
// Default focus
$this->setFocus('forms[0].term');
// If a search term has been specified, then perform the search
// and display the results, grouped by object type
if (!$confirm && '' != $_REQUEST['term']) {
return $this->doFind();
}
}
private function _printTypeOption($curr)
{
$filter = $_REQUEST['filter'];
$optionhtml = sprintf('%s<option value="%s" %s>', "\t", $curr, ($curr === $filter) ? ' selected="selected"' : '');
$optionhtml .= $this->_translatedType($curr);
$optionhtml .= '</option>'.PHP_EOL;
return $optionhtml;
}
private function _translatedType($curr)
{
$types = [
'COLUMN' => $this->lang['strcolumns'],
'CONSTRAINT' => $this->lang['strconstraints'],
'COLUMNTABLE' => $this->lang['strcolumns'],
'COLUMNVIEW' => $this->lang['strcolumns'],
'CONSTRAINTDOMAIN' => $this->lang['strconstraints'],
'CONSTRAINTTABLE' => $this->lang['strconstraints'],
'DOMAIN' => $this->lang['strdomains'],
'FUNCTION' => $this->lang['strfunctions'],
'INDEX' => $this->lang['strindexes'],
'RULE' => $this->lang['strrules'],
'RULETABLE' => $this->lang['strrules'],
'RULEVIEW' => $this->lang['strrules'],
'SCHEMA' => $this->lang['strschemas'],
'SEQUENCE' => $this->lang['strsequences'],
'TABLE' => $this->lang['strtables'],
'TRIGGER' => $this->lang['strtriggers'],
'VIEW' => $this->lang['strviews'],
'AGGREGATE' => $this->lang['straggregates'],
'CONVERSION' => $this->lang['strconversions'],
'LANGUAGE' => $this->lang['strlanguages'],
'OPCLASS' => $this->lang['stropclasses'],
'OPERATOR' => $this->lang['stroperators'],
'TYPE' => $this->lang['strtypes'],
];
if (array_key_exists($curr, $types)) {
return $types[$curr];
}
return $this->lang['strallobjects'];
}
private function _printHtmlForType($curr, $rs)
{
switch ($curr) {
case 'SCHEMA':
echo '<li><a href="'.\SUBFOLDER."/redirect/schema?{$this->misc->href}&schema=";
echo $this->misc->printVal($rs->fields['name']), '">';
echo $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']);
echo '</a></li>'.PHP_EOL;
break;
case 'TABLE':
echo '<li>';
echo "<a href=\"tables?subject=schema&{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
echo '<a href="'.\SUBFOLDER."/redirect/table?{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '&table=',
urlencode($rs->fields['name']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), '</a></li>'.PHP_EOL;
break;
case 'VIEW':
echo '<li>';
echo "<a href=\"views?subject=schema&{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
echo '<a href="'.\SUBFOLDER."/redirect/view?{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '&view=',
urlencode($rs->fields['name']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), '</a></li>'.PHP_EOL;
break;
case 'SEQUENCE':
echo '<li>';
echo "<a href=\"sequences?subject=schema&{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
echo "<a href=\"sequences?subject=sequence&action=properties&{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']),
'&sequence=', urlencode($rs->fields['name']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), '</a></li>'.PHP_EOL;
break;
case 'COLUMNTABLE':
echo '<li>';
echo '<a href="'.\SUBFOLDER."/redirect/schema?{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
echo "<a href=\"tblproperties?subject=table&{$this->misc->href}&table=", urlencode($rs->fields['relname']), '&schema=', urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['relname']), '</a>.';
echo "<a href=\"colproperties?{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '&table=',
urlencode($rs->fields['relname']), '&column=', urlencode($rs->fields['name']), '">',
$this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), '</a></li>'.PHP_EOL;
break;
case 'COLUMNVIEW':
echo '<li>';
echo '<a href="'.\SUBFOLDER."/redirect/schema?{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
echo "<a href=\"viewproperties?subject=view&{$this->misc->href}&view=", urlencode($rs->fields['relname']), '&schema=', urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['relname']), '</a>.';
echo "<a href=\"colproperties?{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '&view=',
urlencode($rs->fields['relname']), '&column=', urlencode($rs->fields['name']), '">',
$this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), '</a></li>'.PHP_EOL;
break;
case 'INDEX':
echo '<li>';
echo '<a href="'.\SUBFOLDER."/redirect/schema?{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
echo '<a href="'.\SUBFOLDER."/redirect/table?{$this->misc->href}&table=", urlencode($rs->fields['relname']), '&schema=', urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['relname']), '</a>.';
echo "<a href=\"indexes?{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '&table=', urlencode($rs->fields['relname']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), '</a></li>'.PHP_EOL;
break;
case 'CONSTRAINTTABLE':
echo '<li>';
echo '<a href="'.\SUBFOLDER."/redirect/schema?{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
echo '<a href="'.\SUBFOLDER."/redirect/table?{$this->misc->href}&table=", urlencode($rs->fields['relname']), '&schema=', urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['relname']), '</a>.';
echo "<a href=\"constraints?{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '&table=',
urlencode($rs->fields['relname']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), '</a></li>'.PHP_EOL;
break;
case 'CONSTRAINTDOMAIN':
echo '<li>';
echo "<a href=\"domains?subject=schema&{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
echo "<a href=\"domains?action=properties&{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '&domain=', urlencode($rs->fields['relname']), '">',
$this->misc->printVal($rs->fields['relname']), '.', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), '</a></li>'.PHP_EOL;
break;
case 'TRIGGER':
echo '<li>';
echo '<a href="'.\SUBFOLDER."/redirect/schema?{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
echo '<a href="'.\SUBFOLDER."/redirect/table?{$this->misc->href}&table=", urlencode($rs->fields['relname']), '&schema=', urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['relname']), '</a>.';
echo "<a href=\"triggers?{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '&table=', urlencode($rs->fields['relname']), '">',
$this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), '</a></li>'.PHP_EOL;
break;
case 'RULETABLE':
echo '<li>';
echo '<a href="'.\SUBFOLDER."/redirect/schema?{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
echo '<a href="'.\SUBFOLDER."/redirect/table?{$this->misc->href}&table=", urlencode($rs->fields['relname']), '&schema=', urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['relname']), '</a>.';
echo "<a href=\"rules?subject=table&{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '&reltype=table&table=',
urlencode($rs->fields['relname']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), '</a></li>'.PHP_EOL;
break;
case 'RULEVIEW':
echo '<li>';
echo '<a href="'.\SUBFOLDER."/redirect/schema?{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
echo '<a href="'.\SUBFOLDER."/redirect/view?{$this->misc->href}&view=", urlencode($rs->fields['relname']), '&schema=', urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['relname']), '</a>.';
echo "<a href=\"rules?subject=view&{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '&reltype=view&view=',
urlencode($rs->fields['relname']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), '</a></li>'.PHP_EOL;
break;
case 'FUNCTION':
echo '<li>';
echo "<a href=\"functions?subject=schema&{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
echo "<a href=\"functions?action=properties&{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '&function=',
urlencode($rs->fields['name']), '&function_oid=', urlencode($rs->fields['oid']), '">',
$this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), '</a></li>'.PHP_EOL;
break;
case 'TYPE':
echo '<li>';
echo "<a href=\"types?subject=schema&{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
echo "<a href=\"types?action=properties&{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '&type=',
urlencode($rs->fields['name']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), '</a></li>'.PHP_EOL;
break;
case 'DOMAIN':
echo '<li>';
echo "<a href=\"domains?subject=schema&{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
echo "<a href=\"domains?action=properties&{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '&domain=',
urlencode($rs->fields['name']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), '</a></li>'.PHP_EOL;
break;
case 'OPERATOR':
echo '<li>';
echo "<a href=\"operators?subject=schema&{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
echo "<a href=\"operators?action=properties&{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '&operator=',
urlencode($rs->fields['name']), '&operator_oid=', urlencode($rs->fields['oid']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), '</a></li>'.PHP_EOL;
break;
case 'CONVERSION':
echo '<li>';
echo "<a href=\"conversions?subject=schema&{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
echo "<a href=\"conversions?{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']),
'">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), '</a></li>'.PHP_EOL;
break;
case 'LANGUAGE':
echo "<li><a href=\"languages?{$this->misc->href}\">", $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), '</a></li>'.PHP_EOL;
break;
case 'AGGREGATE':
echo '<li>';
echo "<a href=\"aggregates?subject=schema&{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
echo "<a href=\"aggregates?{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">',
$this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), '</a></li>'.PHP_EOL;
break;
case 'OPCLASS':
echo '<li>';
echo '<a href="'.\SUBFOLDER."/redirect/schema?{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
echo "<a href=\"opclasses?{$this->misc->href}&schema=", urlencode($rs->fields['schemaname']), '">',
$this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), '</a></li>'.PHP_EOL;
break;
}
}
public function doFind()
{
$data = $this->misc->getDatabaseAccessor();
$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 ('RULEVIEW' == $rs->fields['type'] && 'RULETABLE' == $curr) {
$curr = $rs->fields['type'];
} elseif ('COLUMNVIEW' == $rs->fields['type'] && 'COLUMNTABLE' == $curr) {
$curr = $rs->fields['type'];
} elseif ('CONSTRAINTTABLE' == $rs->fields['type'] && 'CONSTRAINTDOMAIN' == $curr) {
$curr = $rs->fields['type'];
} else {
if ('' != $curr) {
echo '</ul>'.PHP_EOL;
}
$curr = $rs->fields['type'];
echo '<h3>';
echo $this->_translatedType($curr);
echo '</h3>';
echo '<ul>'.PHP_EOL;
}
}
$this->_printHtmlForType($curr, $rs);
$rs->moveNext();
}
echo '</ul>'.PHP_EOL;
echo '<p>', $rs->recordCount(), ' ', $this->lang['strobjects'], '</p>'.PHP_EOL;
} else {
echo "<p>{$this->lang['strnoobjects']}</p>".PHP_EOL;
}
}
/**
* Displays options for database download.
*
* @param mixed $msg
*/
public function doExport($msg = '')
{
$this->printTrail('database');
$this->printTabs('database', 'export');
$this->printMsg($msg);
$subject = 'database';
$object = $_REQUEST['database'];
echo $this->formHeader('dbexport');
echo $this->dataOnly(true, true);
echo $this->structureOnly();
echo $this->structureAndData(true);
// $server_info = $this->misc->getServerInfo();
// echo $this->offerNoRoleExport(isset($server_info['pgVersion']) && floatval(substr($server_info['pgVersion'], 0, 3)) >= 10);
echo $this->displayOrDownload(!(strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && isset($_SERVER['HTTPS'])));
echo $this->formFooter($subject, $object);
}
/**
* Show the current status of all database variables.
*/
public function doVariables()
{
$data = $this->misc->getDatabaseAccessor();
// Fetch the variables from the database
$variables = $data->getVariables();
$this->printTrail('database');
$this->printTabs('database', 'variables');
$columns = [
'variable' => [
'title' => $this->lang['strname'],
'field' => Decorator::field('name'),
],
'value' => [
'title' => $this->lang['strsetting'],
'field' => Decorator::field('setting'),
],
];
$actions = [];
echo $this->printTable($variables, $columns, $actions, $this->table_place, $this->lang['strnodata']);
}
/**
* Show all current database connections and any queries they
* are running.
*
* @param mixed $msg
*/
public function doProcesses($msg = '')
{
$this->printTrail('database');
$this->printTabs('database', 'processes');
$this->printMsg($msg);
if (0 === strlen($msg)) {
echo '<br /><a id="control" href=""><img src="'.$this->misc->icon('Refresh')."\" alt=\"{$this->lang['strrefresh']}\" title=\"{$this->lang['strrefresh']}\"/> {$this->lang['strrefresh']}</a>";
}
echo '<div id="data_block">';
$this->currentProcesses();
echo '</div>';
}
public function currentProcesses($isAjax = false)
{
$data = $this->misc->getDatabaseAccessor();
// Display prepared transactions
if ($data->hasPreparedXacts()) {
echo "<h3>{$this->lang['strpreparedxacts']}</h3>".PHP_EOL;
$prep_xacts = $data->getPreparedXacts($_REQUEST['database']);
$columns = [
'transaction' => [
'title' => $this->lang['strxactid'],
'field' => Decorator::field('transaction'),
],
'gid' => [
'title' => $this->lang['strgid'],
'field' => Decorator::field('gid'),
],
'prepared' => [
'title' => $this->lang['strstarttime'],
'field' => Decorator::field('prepared'),
],
'owner' => [
'title' => $this->lang['strowner'],
'field' => Decorator::field('owner'),
],
];
$actions = [];
echo $this->printTable($prep_xacts, $columns, $actions, 'database-processes-preparedxacts', $this->lang['strnodata']);
}
// Fetch the processes from the database
echo "<h3>{$this->lang['strprocesses']}</h3>".PHP_EOL;
$processes = $data->getProcesses($_REQUEST['database']);
$columns = [
'user' => [
'title' => $this->lang['strusername'],
'field' => Decorator::field('usename'),
],
'process' => [
'title' => $this->lang['strprocess'],
'field' => Decorator::field('pid'),
],
'application_name' => [
'title' => 'application',
'field' => Decorator::field('application_name'),
],
'client_addr' => [
'title' => 'address',
'field' => Decorator::field('client_addr'),
],
'blocked' => [
'title' => $this->lang['strblocked'],
'field' => Decorator::field('waiting'),
],
'query' => [
'title' => $this->lang['strsql'],
'field' => Decorator::field('query'),
],
'start_time' => [
'title' => $this->lang['strstarttime'],
'field' => Decorator::field('query_start'),
],
];
// Build possible actions for our process list
$columns['actions'] = ['title' => $this->lang['stractions']];
$actions = [];
if ($data->hasUserSignals() || $data->isSuperUser()) {
$actions = [
'cancel' => [
'content' => $this->lang['strcancel'],
'attr' => [
'href' => [
'url' => 'database',
'urlvars' => [
'action' => 'signal',
'signal' => 'CANCEL',
'pid' => Decorator::field('pid'),
],
],
],
],
'kill' => [
'content' => $this->lang['strkill'],
'attr' => [
'href' => [
'url' => 'database',
'urlvars' => [
'action' => 'signal',
'signal' => 'KILL',
'pid' => Decorator::field('pid'),
],
],
],
],
];
// Remove actions where not supported
if (!$data->hasQueryKill()) {
unset($actions['kill']);
}
if (!$data->hasQueryCancel()) {
unset($actions['cancel']);
}
}
if (0 == count($actions)) {
unset($columns['actions']);
}
echo $this->printTable($processes, $columns, $actions, 'database-processes', $this->lang['strnodata']);
}
public function currentLocks($isAjax = false)
{
$data = $this->misc->getDatabaseAccessor();
// Get the info from the pg_locks view
$variables = $data->getLocks();
$columns = [
'namespace' => [
'title' => $this->lang['strschema'],
'field' => Decorator::field('nspname'),
],
'tablename' => [
'title' => $this->lang['strtablename'],
'field' => Decorator::field('tablename'),
],
'vxid' => [
'title' => $this->lang['strvirtualtransaction'],
'field' => Decorator::field('virtualtransaction'),
],
'transactionid' => [
'title' => $this->lang['strtransaction'],
'field' => Decorator::field('transaction'),
],
'processid' => [
'title' => $this->lang['strprocessid'],
'field' => Decorator::field('pid'),
],
'mode' => [
'title' => $this->lang['strmode'],
'field' => Decorator::field('mode'),
],
'granted' => [
'title' => $this->lang['strislockheld'],
'field' => Decorator::field('granted'),
'type' => 'yesno',
],
];
if (!$data->hasVirtualTransactionId()) {
unset($columns['vxid']);
}
$actions = [];
echo $this->printTable($variables, $columns, $actions, 'database-locks', $this->lang['strnodata']);
}
/**
* Show the existing table locks in the current database.
*/
public function doLocks()
{
$this->printTrail('database');
$this->printTabs('database', 'locks');
echo '<br /><a id="control" href=""><img src="'.$this->misc->icon('Refresh')."\" alt=\"{$this->lang['strrefresh']}\" title=\"{$this->lang['strrefresh']}\"/> {$this->lang['strrefresh']}</a>";
echo '<div id="data_block">';
$this->currentLocks();
echo '</div>';
}
/**
* Allow execution of arbitrary SQL statements on a database.
*/
public function doSQL()
{
if ((!isset($_SESSION['sqlquery'])) || isset($_REQUEST['new'])) {
$_SESSION['sqlquery'] = '';
$_REQUEST['paginate'] = 'on';
}
$this->printTrail('database');
$this->printTabs('database', 'sql');
echo "<p>{$this->lang['strentersql']}</p>".PHP_EOL;
echo '<form action="'.\SUBFOLDER.'/src/views/sql" method="post" enctype="multipart/form-data" id="sqlform">'.PHP_EOL;
echo "<p>{$this->lang['strsql']}<br />".PHP_EOL;
echo '<textarea style="width:95%;" rows="15" cols="50" name="query" id="query">',
htmlspecialchars($_SESSION['sqlquery']), '</textarea></p>'.PHP_EOL;
// 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 = $this->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}\" />".PHP_EOL;
echo "<label for=\"script\">{$this->lang['struploadscript']}</label> <input id=\"script\" name=\"script\" type=\"file\" /></p>".PHP_EOL;
}
}
echo '<p><input type="checkbox" id="paginate" name="paginate"', (isset($_REQUEST['paginate']) ? ' checked="checked"' : ''), " /><label for=\"paginate\">{$this->lang['strpaginate']}</label></p>".PHP_EOL;
echo "<p><input type=\"submit\" name=\"execute\" accesskey=\"r\" value=\"{$this->lang['strexecute']}\" />".PHP_EOL;
echo $this->misc->form;
echo "<input type=\"reset\" accesskey=\"q\" value=\"{$this->lang['strreset']}\" /></p>".PHP_EOL;
echo '</form>'.PHP_EOL;
// Default focus
$this->setFocus('forms[0].query');
}
/**
* This functions does pretty much nothing. It's meant to implement
* an abstract method of AdminTrait.
*
* @param string $msg The message
*
* @return string The message
*/
public function doDefault($msg = '')
{
return $msg;
}
}
|