forked from myfarms/phppgadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMisc.php
2654 lines (2396 loc) · 81.8 KB
/
Misc.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
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
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Class to hold various commonly used functions
*
* $Id: Misc.php,v 1.171 2008/03/17 21:35:48 ioguix Exp $
*/
class Misc {
// Tracking string to include in HREFs
var $href;
// Tracking string to include in forms
var $form;
/**
* Checks if dumps are properly set up
* @param $all (optional) True to check pg_dumpall, false to just check pg_dump
* @return True, dumps are set up, false otherwise
*/
function isDumpEnabled($all = false) {
$info = $this->getServerInfo();
return !empty($info[$all ? 'pg_dumpall_path' : 'pg_dump_path']);
}
/**
* Sets the href tracking variable
*/
function setHREF() {
$this->href = $this->getHREF();
}
/**
* Get a href query string, excluding objects below the given object type (inclusive)
*/
function getHREF($exclude_from = null) {
$href = '';
if (isset($_REQUEST['server']) && $exclude_from != 'server') {
$href .= 'server=' . urlencode($_REQUEST['server']);
if (isset($_REQUEST['database']) && $exclude_from != 'database') {
$href .= '&database=' . urlencode($_REQUEST['database']);
if (isset($_REQUEST['schema']) && $exclude_from != 'schema') {
$href .= '&schema=' . urlencode($_REQUEST['schema']);
}
}
}
return htmlentities($href);
}
function getSubjectParams($subject) {
global $plugin_manager;
$vars = array();
switch($subject) {
case 'root':
$vars = array (
'params' => array(
'subject' => 'root'
)
);
break;
case 'server':
$vars = array ('params' => array(
'server' => $_REQUEST['server'],
'subject' => 'server'
));
break;
case 'role':
$vars = array('params' => array(
'server' => $_REQUEST['server'],
'subject' => 'role',
'action' => 'properties',
'rolename' => $_REQUEST['rolename']
));
break;
case 'database':
$vars = array('params' => array(
'server' => $_REQUEST['server'],
'subject' => 'database',
'database' => $_REQUEST['database'],
));
break;
case 'schema':
$vars = array('params' => array(
'server' => $_REQUEST['server'],
'subject' => 'schema',
'database' => $_REQUEST['database'],
'schema' => $_REQUEST['schema']
));
break;
case 'table':
$vars = array('params' => array(
'server' => $_REQUEST['server'],
'subject' => 'table',
'database' => $_REQUEST['database'],
'schema' => $_REQUEST['schema'],
'table' => $_REQUEST['table']
));
break;
case 'selectrows':
$vars = array(
'url' => 'tables.php',
'params' => array(
'server' => $_REQUEST['server'],
'subject' => 'table',
'database' => $_REQUEST['database'],
'schema' => $_REQUEST['schema'],
'table' => $_REQUEST['table'],
'action' => 'confselectrows'
));
break;
case 'view':
$vars = array('params' => array(
'server' => $_REQUEST['server'],
'subject' => 'view',
'database' => $_REQUEST['database'],
'schema' => $_REQUEST['schema'],
'view' => $_REQUEST['view']
));
break;
case 'fulltext':
case 'ftscfg':
$vars = array('params' => array(
'server' => $_REQUEST['server'],
'subject' => 'fulltext',
'database' => $_REQUEST['database'],
'schema' => $_REQUEST['schema'],
'action' => 'viewconfig',
'ftscfg' => $_REQUEST['ftscfg']
));
break;
case 'function':
$vars = array('params' => array(
'server' => $_REQUEST['server'],
'subject' => 'function',
'database' => $_REQUEST['database'],
'schema' => $_REQUEST['schema'],
'function' => $_REQUEST['function'],
'function_oid' => $_REQUEST['function_oid']
));
break;
case 'aggregate':
$vars = array('params' => array(
'server' => $_REQUEST['server'],
'subject' => 'aggregate',
'action' => 'properties',
'database' => $_REQUEST['database'],
'schema' => $_REQUEST['schema'],
'aggrname' => $_REQUEST['aggrname'],
'aggrtype' => $_REQUEST['aggrtype']
));
break;
case 'column':
if (isset($_REQUEST['table']))
$vars = array('params' => array(
'server' => $_REQUEST['server'],
'subject' => 'column',
'database' => $_REQUEST['database'],
'schema' => $_REQUEST['schema'],
'table' => $_REQUEST['table'],
'column' => $_REQUEST['column']
));
else
$vars = array('params' => array(
'server' => $_REQUEST['server'],
'subject' => 'column',
'database' => $_REQUEST['database'],
'schema' => $_REQUEST['schema'],
'view' => $_REQUEST['view'],
'column' => $_REQUEST['column']
));
break;
case 'plugin':
$vars = array(
'url' => 'plugin.php',
'params' => array(
'server' => $_REQUEST['server'],
'subject' => 'plugin',
'plugin' => $_REQUEST['plugin'],
));
if (!is_null($plugin_manager->getPlugin($_REQUEST['plugin'])))
$vars['params'] = array_merge($vars['params'], $plugin_manager->getPlugin($_REQUEST['plugin'])->get_subject_params());
break;
default:
return false;
}
if (!isset($vars['url']))
$vars['url'] = 'redirect.php';
return $vars;
}
function getHREFSubject($subject) {
$vars = $this->getSubjectParams($subject);
return "{$vars['url']}?". http_build_query($vars['params'], '', '&');
}
/**
* Sets the form tracking variable
*/
function setForm() {
$this->form = '';
if (isset($_REQUEST['server'])) {
$this->form .= "<input type=\"hidden\" name=\"server\" value=\"" . htmlspecialchars($_REQUEST['server']) . "\" />\n";
if (isset($_REQUEST['database'])) {
$this->form .= "<input type=\"hidden\" name=\"database\" value=\"" . htmlspecialchars($_REQUEST['database']) . "\" />\n";
if (isset($_REQUEST['schema'])) {
$this->form .= "<input type=\"hidden\" name=\"schema\" value=\"" . htmlspecialchars($_REQUEST['schema']) . "\" />\n";
}
}
}
}
/**
* Render a value into HTML using formatting rules specified
* by a type name and parameters.
*
* @param $str The string to change
*
* @param $type Field type (optional), this may be an internal PostgreSQL type, or:
* yesno - same as bool, but renders as 'Yes' or 'No'.
* pre - render in a <pre> block.
* nbsp - replace all spaces with 's
* verbatim - render exactly as supplied, no escaping what-so-ever.
* callback - render using a callback function supplied in the 'function' param.
*
* @param $params Type parameters (optional), known parameters:
* null - string to display if $str is null, or set to TRUE to use a default 'NULL' string,
* otherwise nothing is rendered.
* clip - if true, clip the value to a fixed length, and append an ellipsis...
* cliplen - the maximum length when clip is enabled (defaults to $conf['max_chars'])
* ellipsis - the string to append to a clipped value (defaults to $lang['strellipsis'])
* tag - an HTML element name to surround the value.
* class - a class attribute to apply to any surrounding HTML element.
* align - an align attribute ('left','right','center' etc.)
* true - (type='bool') the representation of true.
* false - (type='bool') the representation of false.
* function - (type='callback') a function name, accepts args ($str, $params) and returns a rendering.
* lineno - prefix each line with a line number.
* map - an associative array.
*
* @return The HTML rendered value
*/
function printVal($str, $type = null, $params = array()) {
global $lang, $conf, $data;
// Shortcircuit for a NULL value
if (is_null($str))
return isset($params['null'])
? ($params['null'] === true ? '<i>NULL</i>' : $params['null'])
: '';
if (isset($params['map']) && isset($params['map'][$str])) $str = $params['map'][$str];
// Clip the value if the 'clip' parameter is true.
if (isset($params['clip']) && $params['clip'] === true) {
$maxlen = isset($params['cliplen']) && is_integer($params['cliplen']) ? $params['cliplen'] : $conf['max_chars'];
$ellipsis = isset($params['ellipsis']) ? $params['ellipsis'] : $lang['strellipsis'];
if (strlen($str) > $maxlen) {
$str = substr($str, 0, $maxlen-1) . $ellipsis;
}
}
$out = '';
switch ($type) {
case 'int2':
case 'int4':
case 'int8':
case 'float4':
case 'float8':
case 'money':
case 'numeric':
case 'oid':
case 'xid':
case 'cid':
case 'tid':
$align = 'right';
$out = nl2br(htmlspecialchars($str));
break;
case 'yesno':
if (!isset($params['true'])) $params['true'] = $lang['stryes'];
if (!isset($params['false'])) $params['false'] = $lang['strno'];
// No break - fall through to boolean case.
case 'bool':
case 'boolean':
if (is_bool($str)) $str = $str ? 't' : 'f';
switch ($str) {
case 't':
$out = (isset($params['true']) ? $params['true'] : $lang['strtrue']);
$align = 'center';
break;
case 'f':
$out = (isset($params['false']) ? $params['false'] : $lang['strfalse']);
$align = 'center';
break;
default:
$out = htmlspecialchars($str);
}
break;
case 'bytea':
$tag = 'div';
$class = 'pre';
$out = $data->escapeBytea($str);
break;
case 'errormsg':
$tag = 'pre';
$class = 'error';
$out = htmlspecialchars($str);
break;
case 'pre':
$tag = 'pre';
$out = htmlspecialchars($str);
break;
case 'prenoescape':
$tag = 'pre';
$out = $str;
break;
case 'nbsp':
$out = nl2br(str_replace(' ', ' ', htmlspecialchars($str)));
break;
case 'verbatim':
$out = $str;
break;
case 'callback':
$out = $params['function']($str, $params);
break;
case 'prettysize':
if ($str == -1)
$out = $lang['strnoaccess'];
else
{
$limit = 10 * 1024;
$mult = 1;
if ($str < $limit * $mult)
$out = $str.' '.$lang['strbytes'];
else
{
$mult *= 1024;
if ($str < $limit * $mult)
$out = floor(($str + $mult / 2) / $mult).' '.$lang['strkb'];
else
{
$mult *= 1024;
if ($str < $limit * $mult)
$out = floor(($str + $mult / 2) / $mult).' '.$lang['strmb'];
else
{
$mult *= 1024;
if ($str < $limit * $mult)
$out = floor(($str + $mult / 2) / $mult).' '.$lang['strgb'];
else
{
$mult *= 1024;
if ($str < $limit * $mult)
$out = floor(($str + $mult / 2) / $mult).' '.$lang['strtb'];
}
}
}
}
}
break;
default:
// If the string contains at least one instance of >1 space in a row, a tab
// character, a space at the start of a line, or a space at the start of
// the whole string then render within a pre-formatted element (<pre>).
if (preg_match('/(^ | |\t|\n )/m', $str)) {
$tag = 'pre';
$class = 'data';
$out = htmlspecialchars($str);
} else {
$out = nl2br(htmlspecialchars($str));
}
}
if (isset($params['class'])) $class = $params['class'];
if (isset($params['align'])) $align = $params['align'];
if (!isset($tag) && (isset($class) || isset($align))) $tag = 'div';
if (isset($tag)) {
$alignattr = isset($align) ? " style=\"text-align: {$align}\"" : '';
$classattr = isset($class) ? " class=\"{$class}\"" : '';
$out = "<{$tag}{$alignattr}{$classattr}>{$out}</{$tag}>";
}
// Add line numbers if 'lineno' param is true
if (isset($params['lineno']) && $params['lineno'] === true) {
$lines = explode("\n", $str);
$num = count($lines);
if ($num > 0) {
$temp = "<table>\n<tr><td class=\"{$class}\" style=\"vertical-align: top; padding-right: 10px;\"><pre class=\"{$class}\">";
for ($i = 1; $i <= $num; $i++) {
$temp .= $i . "\n";
}
$temp .= "</pre></td><td class=\"{$class}\" style=\"vertical-align: top;\">{$out}</td></tr></table>\n";
$out = $temp;
}
unset($lines);
}
return $out;
}
/**
* A function to recursively strip slashes. Used to
* enforce magic_quotes_gpc being off.
* @param &var The variable to strip
*/
function stripVar(&$var) {
if (is_array($var)) {
foreach($var as $k => $v) {
$this->stripVar($var[$k]);
/* magic_quotes_gpc escape keys as well ...*/
if (is_string($k)) {
$ek = stripslashes($k);
if ($ek !== $k) {
$var[$ek] = $var[$k];
unset($var[$k]);
}
}
}
}
else
$var = stripslashes($var);
}
/**
* Print out the page heading and help link
* @param $title Title, already escaped
* @param $help (optional) The identifier for the help link
*/
function printTitle($title, $help = null) {
global $data, $lang;
echo "<h2>";
$this->printHelp($title, $help);
echo "</h2>\n";
}
/**
* Print out a message
* @param $msg The message to print
*/
function printMsg($msg) {
if ($msg != '') echo "<p class=\"message\">{$msg}</p>\n";
}
/**
* Creates a database accessor
*/
function getDatabaseAccessor($database, $server_id = null) {
global $lang, $conf, $misc, $_connection;
$server_info = $this->getServerInfo($server_id);
// Perform extra security checks if this config option is set
if ($conf['extra_login_security']) {
// Disallowed logins if extra_login_security is enabled.
// These must be lowercase.
$bad_usernames = array('pgsql', 'postgres', 'root', 'administrator');
$username = strtolower($server_info['username']);
if ($server_info['password'] == '' || in_array($username, $bad_usernames)) {
unset($_SESSION['webdbLogin'][$_REQUEST['server']]);
$msg = $lang['strlogindisallowed'];
include('./login.php');
exit;
}
}
// Create the connection object and make the connection
$_connection = new Connection(
$server_info['host'],
$server_info['port'],
$server_info['sslmode'],
$server_info['username'],
$server_info['password'],
$database
);
// Get the name of the database driver we need to use.
// The description of the server is returned in $platform.
$_type = $_connection->getDriver($platform);
if ($_type === null) {
printf($lang['strpostgresqlversionnotsupported'], $postgresqlMinVer);
exit;
}
$this->setServerInfo('platform', $platform, $server_id);
$this->setServerInfo('pgVersion', $_connection->conn->pgVersion, $server_id);
// Create a database wrapper class for easy manipulation of the
// connection.
include_once('./classes/database/' . $_type . '.php');
$data = new $_type($_connection->conn);
$data->platform = $_connection->platform;
/* we work on UTF-8 only encoding */
$data->execute("SET client_encoding TO 'UTF-8'");
if ($data->hasByteaHexDefault()) {
$data->execute("SET bytea_output TO escape");
}
return $data;
}
/**
* Prints the page header. If global variable $_no_output is
* set then no header is drawn.
* @param $title The title of the page
* @param $script script tag
*/
function printHeader($title = '', $script = null, $frameset = false) {
global $appName, $lang, $_no_output, $conf, $plugin_manager;
if (!isset($_no_output)) {
header("Content-Type: text/html; charset=utf-8");
// Send XHTML headers, or regular XHTML strict headers
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
if ($frameset == true) {
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n";
} else if (isset($conf['use_xhtml_strict']) && $conf['use_xhtml_strict']) {
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-Strict.dtd\">\n";
} else {
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
}
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"{$lang['applocale']}\" lang=\"{$lang['applocale']}\"";
if (strcasecmp($lang['applangdir'], 'ltr') != 0) echo " dir=\"", htmlspecialchars($lang['applangdir']), "\"";
echo ">\n";
echo "<head>\n";
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
// Theme
echo "<link rel=\"stylesheet\" href=\"themes/{$conf['theme']}/global.css\" type=\"text/css\" id=\"csstheme\" />\n";
echo "<link rel=\"shortcut icon\" href=\"images/themes/{$conf['theme']}/Favicon.ico\" type=\"image/vnd.microsoft.icon\" />\n";
echo "<link rel=\"icon\" type=\"image/png\" href=\"images/themes/{$conf['theme']}/Introduction.png\" />\n";
echo "<script type=\"text/javascript\" src=\"libraries/js/jquery.js\"></script>";
echo "<script type=\"text/javascript\">// <!-- \n";
echo "$(document).ready(function() { \n";
echo " if (window.parent.frames.length > 1)\n";
echo " $('#csstheme', window.parent.frames[0].document).attr('href','themes/{$conf['theme']}/global.css');\n";
echo "}); // --></script>\n";
echo "<title>", htmlspecialchars($appName);
if ($title != '') echo htmlspecialchars(" - {$title}");
echo "</title>\n";
if ($script) echo "{$script}\n";
$plugins_head = array();
$_params = array('heads' => &$plugins_head);
$plugin_manager->do_hook('head', $_params);
foreach($plugins_head as $tag) {
echo $tag;
}
echo "</head>\n";
}
}
/**
* Prints the page footer
* @param $doBody True to output body tag, false otherwise
*/
function printFooter($doBody = true) {
global $_reload_browser, $_reload_drop_database;
global $lang, $_no_bottom_link;
if ($doBody) {
if (isset($_reload_browser)) $this->printReload(false);
elseif (isset($_reload_drop_database)) $this->printReload(true);
if (!isset($_no_bottom_link))
echo "<a href=\"#\" class=\"bottom_link\">".$lang['strgotoppage']."</a>";
echo "</body>\n";
}
echo "</html>\n";
}
/**
* Prints the page body.
* @param $doBody True to output body tag, false otherwise
* @param $bodyClass - name of body class
*/
function printBody($bodyClass = '', $doBody = true ) {
global $_no_output;
if (!isset($_no_output)) {
if ($doBody) {
$bodyClass = htmlspecialchars($bodyClass);
echo "<body", ($bodyClass == '' ? '' : " class=\"{$bodyClass}\"");
echo ">\n";
}
}
}
/**
* Outputs JavaScript code that will reload the browser
* @param $database True if dropping a database, false otherwise
*/
function printReload($database) {
echo "<script type=\"text/javascript\">\n";
if ($database)
echo "\tparent.frames.browser.location.href=\"browser.php\";\n";
else
echo "\tparent.frames.browser.location.reload();\n";
echo "</script>\n";
}
/**
* Display a link
* @param $link An associative array of link parameters to print
* link = array(
* 'attr' => array( // list of A tag attribute
* 'attrname' => attribute value
* ...
* ),
* 'content' => The link text
* 'fields' => (optionnal) the data from which content and attr's values are obtained
* );
* the special attribute 'href' might be a string or an array. If href is an array it
* will be generated by getActionUrl. See getActionUrl comment for array format.
*/
function printLink($link) {
if (! isset($link['fields']))
$link['fields'] = $_REQUEST;
$tag = "<a ";
foreach ($link['attr'] as $attr => $value) {
if ($attr == 'href' and is_array($value)) {
$tag.= 'href="'. htmlentities($this->getActionUrl($value, $link['fields'])).'" ';
}
else {
$tag.= htmlentities($attr).'="'. value($value, $link['fields'], 'html') .'" ';
}
}
$tag.= ">". value($link['content'], $link['fields'], 'html') ."</a>\n";
echo $tag;
}
/**
* Display a list of links
* @param $links An associative array of links to print. See printLink function for
* the links array format.
* @param $class An optional class or list of classes seprated by a space
* WARNING: This field is NOT escaped! No user should be able to inject something here, use with care.
*/
function printLinksList($links, $class='') {
echo "<ul class=\"{$class}\">\n";
foreach ($links as $link) {
echo "\t<li>";
$this->printLink($link);
echo "</li>\n";
}
echo "</ul>\n";
}
/**
* Display navigation tabs
* @param $tabs The name of current section (Ex: intro, server, ...), or an array with tabs (Ex: sqledit.php doFind function)
* @param $activetab The name of the tab to be highlighted.
*/
function printTabs($tabs, $activetab) {
global $misc, $conf, $data, $lang;
if (is_string($tabs)) {
$_SESSION['webdbLastTab'][$tabs] = $activetab;
$tabs = $this->getNavTabs($tabs);
}
echo "<table class=\"tabs\"><tr>\n";
#echo "<div class=\"tabs\">\n";
# FIXME: Add if - Augusto 01/12/2016
if (count($tabs) > 0)
$width = (int)(100 / count($tabs)).'%';
else
$width = 1;
foreach ($tabs as $tab_id => $tab) {
$active = ($tab_id == $activetab) ? ' active' : '';
if (!isset($tab['hide']) || $tab['hide'] !== true) {
$tablink = '<a href="' . htmlentities($this->getActionUrl($tab, $_REQUEST)) . '">';
if (isset($tab['icon']) && $icon = $this->icon($tab['icon']))
$tablink .= "<span class=\"icon\"><img src=\"{$icon}\" alt=\"{$tab['title']}\" /></span>";
$tablink .= "<span class=\"label\">{$tab['title']}</span></a>";
echo "<td style=\"width: {$width}\" class=\"tab{$active}\">";
#echo "<span class=\"tab{$active}\" style=\"white-space:nowrap;\">";
if (isset($tab['help']))
$this->printHelp($tablink, $tab['help']);
else
echo $tablink;
echo "</td>\n";
#echo "</span>\n";
}
}
echo "</tr></table>\n";
#echo "</div>\n";
}
/**
* Retrieve the tab info for a specific tab bar.
* @param $section The name of the tab bar.
*/
function getNavTabs($section) {
global $data, $lang, $conf, $plugin_manager;
$hide_advanced = ($conf['show_advanced'] === false);
$tabs = array();
switch ($section) {
case 'root':
$tabs = array (
'intro' => array (
'title' => $lang['strintroduction'],
'url' => "intro.php",
'icon' => 'Introduction',
),
'servers' => array (
'title' => $lang['strservers'],
'url' => "servers.php",
'icon' => 'Servers',
),
);
break;
case 'server':
$hide_users = !$data->isSuperUser();
$tabs = array (
'databases' => array (
'title' => $lang['strdatabases'],
'url' => 'all_db.php',
'urlvars' => array('subject' => 'server'),
'help' => 'pg.database',
'icon' => 'Databases',
)
);
if ($data->hasRoles()) {
$tabs = array_merge($tabs, array(
'roles' => array (
'title' => $lang['strroles'],
'url' => 'roles.php',
'urlvars' => array('subject' => 'server'),
'hide' => $hide_users,
'help' => 'pg.role',
'icon' => 'Roles',
)
));
}
else {
$tabs = array_merge($tabs, array(
'users' => array (
'title' => $lang['strusers'],
'url' => 'users.php',
'urlvars' => array('subject' => 'server'),
'hide' => $hide_users,
'help' => 'pg.user',
'icon' => 'Users',
),
'groups' => array (
'title' => $lang['strgroups'],
'url' => 'groups.php',
'urlvars' => array('subject' => 'server'),
'hide' => $hide_users,
'help' => 'pg.group',
'icon' => 'UserGroups',
)
));
}
$tabs = array_merge($tabs, array(
'account' => array (
'title' => $lang['straccount'],
'url' => $data->hasRoles() ? 'roles.php' : 'users.php',
'urlvars' => array('subject' => 'server', 'action' => 'account'),
'hide' => !$hide_users,
'help' => 'pg.role',
'icon' => 'User',
),
'tablespaces' => array (
'title' => $lang['strtablespaces'],
'url' => 'tablespaces.php',
'urlvars' => array('subject' => 'server'),
'hide' => (!$data->hasTablespaces()),
'help' => 'pg.tablespace',
'icon' => 'Tablespaces',
),
'export' => array (
'title' => $lang['strexport'],
'url' => 'all_db.php',
'urlvars' => array('subject' => 'server', 'action' => 'export'),
'hide' => (!$this->isDumpEnabled()),
'icon' => 'Export',
),
));
break;
case 'database':
$tabs = array (
'schemas' => array (
'title' => $lang['strschemas'],
'url' => 'schemas.php',
'urlvars' => array('subject' => 'database'),
'help' => 'pg.schema',
'icon' => 'Schemas',
),
'sql' => array (
'title' => $lang['strsql'],
'url' => 'database.php',
'urlvars' => array('subject' => 'database', 'action' => 'sql', 'new' => 1),
'help' => 'pg.sql',
'tree' => false,
'icon' => 'SqlEditor'
),
'find' => array (
'title' => $lang['strfind'],
'url' => 'database.php',
'urlvars' => array('subject' => 'database', 'action' => 'find'),
'tree' => false,
'icon' => 'Search'
),
'variables' => array (
'title' => $lang['strvariables'],
'url' => 'database.php',
'urlvars' => array('subject' => 'database', 'action' => 'variables'),
'help' => 'pg.variable',
'tree' => false,
'icon' => 'Variables',
),
'processes' => array (
'title' => $lang['strprocesses'],
'url' => 'database.php',
'urlvars' => array('subject' => 'database', 'action' => 'processes'),
'help' => 'pg.process',
'tree' => false,
'icon' => 'Processes',
),
'locks' => array (
'title' => $lang['strlocks'],
'url' => 'database.php',
'urlvars' => array('subject' => 'database', 'action' => 'locks'),
'help' => 'pg.locks',
'tree' => false,
'icon' => 'Key',
),
'admin' => array (
'title' => $lang['stradmin'],
'url' => 'database.php',
'urlvars' => array('subject' => 'database', 'action' => 'admin'),
'tree' => false,
'icon' => 'Admin',
),
'privileges' => array (
'title' => $lang['strprivileges'],
'url' => 'privileges.php',
'urlvars' => array('subject' => 'database'),
'hide' => (!isset($data->privlist['database'])),
'help' => 'pg.privilege',
'tree' => false,
'icon' => 'Privileges',
),
'languages' => array (
'title' => $lang['strlanguages'],
'url' => 'languages.php',
'urlvars' => array('subject' => 'database'),
'hide' => $hide_advanced,
'help' => 'pg.language',
'icon' => 'Languages',
),
'casts' => array (
'title' => $lang['strcasts'],
'url' => 'casts.php',
'urlvars' => array('subject' => 'database'),
'hide' => ($hide_advanced),
'help' => 'pg.cast',
'icon' => 'Casts',
),
'export' => array (
'title' => $lang['strexport'],
'url' => 'database.php',
'urlvars' => array('subject' => 'database', 'action' => 'export'),
'hide' => (!$this->isDumpEnabled()),
'tree' => false,
'icon' => 'Export',
),
);
break;
case 'schema':
$tabs = array (
'tables' => array (
'title' => $lang['strtables'],
'url' => 'tables.php',
'urlvars' => array('subject' => 'schema'),
'help' => 'pg.table',
'icon' => 'Tables',
),
'views' => array (
'title' => $lang['strviews'],
'url' => 'views.php',
'urlvars' => array('subject' => 'schema'),
'help' => 'pg.view',
'icon' => 'Views',
),
'sequences' => array (
'title' => $lang['strsequences'],
'url' => 'sequences.php',
'urlvars' => array('subject' => 'schema'),
'help' => 'pg.sequence',
'icon' => 'Sequences',
),
'functions' => array (
'title' => $lang['strfunctions'],
'url' => 'functions.php',
'urlvars' => array('subject' => 'schema'),
'help' => 'pg.function',
'icon' => 'Functions',
),
'fulltext' => array (
'title' => $lang['strfulltext'],
'url' => 'fulltext.php',
'urlvars' => array('subject' => 'schema'),
'help' => 'pg.fts',
'tree' => true,
'icon' => 'Fts',
),
'domains' => array (
'title' => $lang['strdomains'],
'url' => 'domains.php',
'urlvars' => array('subject' => 'schema'),
'help' => 'pg.domain',
'icon' => 'Domains',
),
'aggregates' => array (
'title' => $lang['straggregates'],
'url' => 'aggregates.php',
'urlvars' => array('subject' => 'schema'),
'hide' => $hide_advanced,
'help' => 'pg.aggregate',
'icon' => 'Aggregates',
),
'types' => array (
'title' => $lang['strtypes'],
'url' => 'types.php',
'urlvars' => array('subject' => 'schema'),
'hide' => $hide_advanced,
'help' => 'pg.type',
'icon' => 'Types',
),
'operators' => array (
'title' => $lang['stroperators'],
'url' => 'operators.php',
'urlvars' => array('subject' => 'schema'),
'hide' => $hide_advanced,
'help' => 'pg.operator',
'icon' => 'Operators',
),
'opclasses' => array (
'title' => $lang['stropclasses'],
'url' => 'opclasses.php',
'urlvars' => array('subject' => 'schema'),
'hide' => $hide_advanced,
'help' => 'pg.opclass',
'icon' => 'OperatorClasses',
),
'conversions' => array (
'title' => $lang['strconversions'],
'url' => 'conversions.php',
'urlvars' => array('subject' => 'schema'),
'hide' => $hide_advanced,
'help' => 'pg.conversion',
'icon' => 'Conversions',
),
'privileges' => array (
'title' => $lang['strprivileges'],
'url' => 'privileges.php',
'urlvars' => array('subject' => 'schema'),
'help' => 'pg.privilege',
'tree' => false,
'icon' => 'Privileges',
),
'export' => array (
'title' => $lang['strexport'],
'url' => 'schemas.php',
'urlvars' => array('subject' => 'schema', 'action' => 'export'),
'hide' => (!$this->isDumpEnabled()),