Passed
Pull Request — develop (#92)
by Felipe
04:47
created

DatabaseController::currentLocks()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 48
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 31
nc 2
nop 1
dl 0
loc 48
rs 9.125
c 0
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
/*
4
 * PHPPgAdmin v6.0.0-beta.30
5
 */
6
7
namespace PHPPgAdmin\Controller;
8
9
use PHPPgAdmin\Decorators\Decorator;
10
11
/**
12
 * Base controller class.
13
 */
5 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
14
class DatabaseController extends BaseController
15
{
16
    use AdminTrait;
17
    public $script          = 'database.php';
18
    public $controller_name = 'DatabaseController';
19
    public $table_place     = 'database-variables';
20
21
    public function _highlight($string, $term)
2 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
Coding Style introduced by
Public method name "DatabaseController::_highlight" must not be prefixed with an underscore
Loading history...
22
    {
23
        return str_replace($term, "<b>{$term}</b>", $string);
24
    }
25
26
    /**
27
     * Default method to render the controller according to the action parameter.
28
     */
29
    public function render()
30
    {
31
        $conf = $this->conf;
32
33
        $lang   = $this->lang;
34
        $action = $this->action;
35
        $data   = $this->misc->getDatabaseAccessor();
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
36
37
        if ('tree' == $action) {
38
            return $this->doTree();
39
        }
40
41
        if ('refresh_locks' == $action) {
42
            return $this->currentLocks(true);
43
        }
44
45
        if ('refresh_processes' == $action) {
46
            return $this->currentProcesses(true);
47
        }
48
        $scripts = '';
49
        // normal flow
50
        if ('locks' == $action || 'processes' == $action) {
51
            $scripts .= '<script src="'.\SUBFOLDER.'/js/database.js" type="text/javascript"></script>';
52
53
            $refreshTime = $conf['ajax_refresh'] * 1500;
54
55
            $scripts .= "<script type=\"text/javascript\">\n";
56
            $scripts .= "var Database = {\n";
57
            $scripts .= "ajax_time_refresh: {$refreshTime},\n";
58
            $scripts .= "str_start: {text:'{$lang['strstart']}',icon: '".$this->misc->icon('Execute')."'},\n";
59
            $scripts .= "str_stop: {text:'{$lang['strstop']}',icon: '".$this->misc->icon('Stop')."'},\n";
60
            $scripts .= "load_icon: '".$this->misc->icon('Loading')."',\n";
61
            $scripts .= "server:'{$_REQUEST['server']}',\n";
62
            $scripts .= "dbname:'{$_REQUEST['database']}',\n";
63
            $scripts .= "action:'refresh_{$action}',\n";
64
            $scripts .= "errmsg: '".str_replace("'", "\\'", $lang['strconnectionfail'])."'\n";
65
            $scripts .= "};\n";
66
            $scripts .= "</script>\n";
67
        }
68
69
        $header_template = 'header.twig';
70
        $footer_template = 'footer.twig';
71
        // @todo convert all these methods to return text instead of print text
72
        ob_start();
73
        switch ($action) {
74
            case 'find':
75
                if (isset($_REQUEST['term'])) {
76
                    $this->doFind(false);
77
                } else {
78
                    $this->doFind(true);
79
                }
80
81
                break;
82
            case 'sql':
83
                $this->doSQL();
84
                $header_template = 'header_sqledit.twig';
85
                $footer_template = 'footer_sqledit.twig';
86
87
                break;
88
            case 'variables':
89
                $this->doVariables();
90
91
                break;
92
            case 'processes':
93
                $this->doProcesses();
94
95
                break;
96
            case 'locks':
97
                $this->doLocks();
98
99
                break;
100
            case 'export':
101
                $this->doExport();
102
103
                break;
104
            case 'signal':
105
                $this->doSignal();
106
107
                break;
108
            default:
109
                if (false === $this->adminActions($action, 'database')) {
110
                    $header_template = 'header_sqledit.twig';
111
                    $footer_template = 'footer_sqledit.twig';
112
                    $this->doSQL();
113
                }
114
115
                break;
116
        }
117
        $output = ob_get_clean();
118
119
        $this->printHeader($lang['strdatabase'], $scripts, true, $header_template);
120
        $this->printBody();
121
122
        echo $output;
123
124
        $this->printFooter(true, $footer_template);
125
    }
126
127
    public function doTree($print = true)
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
128
    {
129
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
130
131
        $lang = $this->lang;
0 ignored issues
show
Unused Code introduced by
The assignment to $lang is dead and can be removed.
Loading history...
132
133
        $data = $this->misc->getDatabaseAccessor();
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
134
135
        $reqvars = $this->misc->getRequestVars('database');
136
137
        $tabs = $this->misc->getNavTabs('database');
138
139
        $items = $this->adjustTabsForTree($tabs);
140
141
        $attrs = [
142
            'text'   => Decorator::field('title'),
143
            'icon'   => Decorator::field('icon'),
144
            'action' => Decorator::actionurl(Decorator::field('url'), $reqvars, Decorator::field('urlvars', [])),
145
            'branch' => Decorator::url(Decorator::field('url'), $reqvars, Decorator::field('urlvars'), ['action' => 'tree']),
146
        ];
147
148
        return $this->printTree($items, $attrs, 'database', $print);
149
    }
150
151
    /**
152
     * Sends a signal to a process.
153
     */
154
    public function doSignal()
155
    {
156
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
157
158
        $lang = $this->lang;
159
        $data = $this->misc->getDatabaseAccessor();
160
161
        $status = $data->sendSignal($_REQUEST['pid'], $_REQUEST['signal']);
162
        if (0 == $status) {
163
            $this->doProcesses($lang['strsignalsent']);
164
        } else {
165
            $this->doProcesses($lang['strsignalsentbad']);
166
        }
167
    }
168
169
    /**
170
     * Searches for a named database object.
171
     *
172
     * @param mixed $confirm
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
173
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
174
     */
175
    public function doFind($confirm = true, $msg = '')
0 ignored issues
show
Unused Code introduced by
The parameter $confirm is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

175
    public function doFind(/** @scrutinizer ignore-unused */ $confirm = true, $msg = '')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
176
    {
177
        $conf = $this->conf;
178
179
        $lang = $this->lang;
180
        $data = $this->misc->getDatabaseAccessor();
181
182
        if (!isset($_REQUEST['term'])) {
183
            $_REQUEST['term'] = '';
184
        }
185
186
        if (!isset($_REQUEST['filter'])) {
187
            $_REQUEST['filter'] = '';
188
        }
189
190
        $this->printTrail('database');
191
        $this->printTabs('database', 'find');
192
        $this->printMsg($msg);
193
194
        echo '<form action="'.\SUBFOLDER."/src/views/database.php\" method=\"post\">\n";
195
        echo '<p><input name="term" value="', htmlspecialchars($_REQUEST['term']),
196
            "\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" />\n";
197
        // Output list of filters.  This is complex due to all the 'has' and 'conf' feature possibilities
198
        echo "<select name=\"filter\">\n";
199
        echo "\t<option value=\"\"", ('' == $_REQUEST['filter']) ? ' selected="selected"' : '', ">{$lang['strallobjects']}</option>\n";
200
        echo "\t<option value=\"SCHEMA\"", ('SCHEMA' == $_REQUEST['filter']) ? ' selected="selected"' : '', ">{$lang['strschemas']}</option>\n";
201
        echo "\t<option value=\"TABLE\"", ('TABLE' == $_REQUEST['filter']) ? ' selected="selected"' : '', ">{$lang['strtables']}</option>\n";
202
        echo "\t<option value=\"VIEW\"", ('VIEW' == $_REQUEST['filter']) ? ' selected="selected"' : '', ">{$lang['strviews']}</option>\n";
203
        echo "\t<option value=\"SEQUENCE\"", ('SEQUENCE' == $_REQUEST['filter']) ? ' selected="selected"' : '', ">{$lang['strsequences']}</option>\n";
204
        echo "\t<option value=\"COLUMN\"", ('COLUMN' == $_REQUEST['filter']) ? ' selected="selected"' : '', ">{$lang['strcolumns']}</option>\n";
205
        echo "\t<option value=\"RULE\"", ('RULE' == $_REQUEST['filter']) ? ' selected="selected"' : '', ">{$lang['strrules']}</option>\n";
206
        echo "\t<option value=\"INDEX\"", ('INDEX' == $_REQUEST['filter']) ? ' selected="selected"' : '', ">{$lang['strindexes']}</option>\n";
207
        echo "\t<option value=\"TRIGGER\"", ('TRIGGER' == $_REQUEST['filter']) ? ' selected="selected"' : '', ">{$lang['strtriggers']}</option>\n";
208
        echo "\t<option value=\"CONSTRAINT\"", ('CONSTRAINT' == $_REQUEST['filter']) ? ' selected="selected"' : '', ">{$lang['strconstraints']}</option>\n";
209
        echo "\t<option value=\"FUNCTION\"", ('FUNCTION' == $_REQUEST['filter']) ? ' selected="selected"' : '', ">{$lang['strfunctions']}</option>\n";
210
        echo "\t<option value=\"DOMAIN\"", ('DOMAIN' == $_REQUEST['filter']) ? ' selected="selected"' : '', ">{$lang['strdomains']}</option>\n";
211
        if ($conf['show_advanced']) {
212
            echo "\t<option value=\"AGGREGATE\"", ('AGGREGATE' == $_REQUEST['filter']) ? ' selected="selected"' : '', ">{$lang['straggregates']}</option>\n";
213
            echo "\t<option value=\"TYPE\"", ('TYPE' == $_REQUEST['filter']) ? ' selected="selected"' : '', ">{$lang['strtypes']}</option>\n";
214
            echo "\t<option value=\"OPERATOR\"", ('OPERATOR' == $_REQUEST['filter']) ? ' selected="selected"' : '', ">{$lang['stroperators']}</option>\n";
215
            echo "\t<option value=\"OPCLASS\"", ('OPCLASS' == $_REQUEST['filter']) ? ' selected="selected"' : '', ">{$lang['stropclasses']}</option>\n";
216
            echo "\t<option value=\"CONVERSION\"", ('CONVERSION' == $_REQUEST['filter']) ? ' selected="selected"' : '', ">{$lang['strconversions']}</option>\n";
217
            echo "\t<option value=\"LANGUAGE\"", ('LANGUAGE' == $_REQUEST['filter']) ? ' selected="selected"' : '', ">{$lang['strlanguages']}</option>\n";
218
        }
219
        echo "</select>\n";
220
        echo "<input type=\"submit\" value=\"{$lang['strfind']}\" />\n";
221
        echo $this->misc->form;
222
        echo "<input type=\"hidden\" name=\"action\" value=\"find\" /></p>\n";
223
        echo "</form>\n";
224
225
        // Default focus
226
        $this->setFocus('forms[0].term');
227
228
        // If a search term has been specified, then perform the search
229
        // and display the results, grouped by object type
230
        if ('' != $_REQUEST['term']) {
231
            $rs = $data->findObject($_REQUEST['term'], $_REQUEST['filter']);
232
            if ($rs->recordCount() > 0) {
233
                $curr = '';
234
                while (!$rs->EOF) {
235
                    // Output a new header if the current type has changed, but not if it's just changed the rule type
236
                    if ($rs->fields['type'] != $curr) {
237
                        // Short-circuit in the case of changing from table rules to view rules; table cols to view cols;
238
                        // table constraints to domain constraints
239
                        if ('RULEVIEW' == $rs->fields['type'] && 'RULETABLE' == $curr) {
240
                            $curr = $rs->fields['type'];
241
                        } elseif ('COLUMNVIEW' == $rs->fields['type'] && 'COLUMNTABLE' == $curr) {
242
                            $curr = $rs->fields['type'];
243
                        } elseif ('CONSTRAINTTABLE' == $rs->fields['type'] && 'CONSTRAINTDOMAIN' == $curr) {
244
                            $curr = $rs->fields['type'];
245
                        } else {
246
                            if ('' != $curr) {
247
                                echo "</ul>\n";
248
                            }
249
250
                            $curr = $rs->fields['type'];
251
                            echo '<h3>';
252
                            switch ($curr) {
253
                                case 'SCHEMA':
254
                                    echo $lang['strschemas'];
255
256
                                    break;
257
                                case 'TABLE':
258
                                    echo $lang['strtables'];
259
260
                                    break;
261
                                case 'VIEW':
262
                                    echo $lang['strviews'];
263
264
                                    break;
265
                                case 'SEQUENCE':
266
                                    echo $lang['strsequences'];
267
268
                                    break;
269
                                case 'COLUMNTABLE':
270
                                case 'COLUMNVIEW':
271
                                    echo $lang['strcolumns'];
272
273
                                    break;
274
                                case 'INDEX':
275
                                    echo $lang['strindexes'];
276
277
                                    break;
278
                                case 'CONSTRAINTTABLE':
279
                                case 'CONSTRAINTDOMAIN':
280
                                    echo $lang['strconstraints'];
281
282
                                    break;
283
                                case 'TRIGGER':
284
                                    echo $lang['strtriggers'];
285
286
                                    break;
287
                                case 'RULETABLE':
288
                                case 'RULEVIEW':
289
                                    echo $lang['strrules'];
290
291
                                    break;
292
                                case 'FUNCTION':
293
                                    echo $lang['strfunctions'];
294
295
                                    break;
296
                                case 'TYPE':
297
                                    echo $lang['strtypes'];
298
299
                                    break;
300
                                case 'DOMAIN':
301
                                    echo $lang['strdomains'];
302
303
                                    break;
304
                                case 'OPERATOR':
305
                                    echo $lang['stroperators'];
306
307
                                    break;
308
                                case 'CONVERSION':
309
                                    echo $lang['strconversions'];
310
311
                                    break;
312
                                case 'LANGUAGE':
313
                                    echo $lang['strlanguages'];
314
315
                                    break;
316
                                case 'AGGREGATE':
317
                                    echo $lang['straggregates'];
318
319
                                    break;
320
                                case 'OPCLASS':
321
                                    echo $lang['stropclasses'];
322
323
                                    break;
324
                            }
325
                            echo '</h3>';
326
                            echo "<ul>\n";
327
                        }
328
                    }
329
330
                    switch ($curr) {
331
                        case 'SCHEMA':
332
                            echo '<li><a href="'.\SUBFOLDER."/redirect/schema?{$this->misc->href}&amp;schema=", $this->misc->printVal($rs->fields['name']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
333
334
                            break;
335
                        case 'TABLE':
336
                            echo '<li>';
337
                            echo "<a href=\"tables.php?subject=schema&amp;{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
338
                            echo '<a href="'.\SUBFOLDER."/redirect/table?{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '&amp;table=',
339
                            urlencode($rs->fields['name']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
340
341
                            break;
342
                        case 'VIEW':
343
                            echo '<li>';
344
                            echo "<a href=\"views.php?subject=schema&amp;{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
345
                            echo '<a href="'.\SUBFOLDER."/redirect/view?{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '&amp;view=',
346
                            urlencode($rs->fields['name']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
347
348
                            break;
349
                        case 'SEQUENCE':
350
                            echo '<li>';
351
                            echo "<a href=\"sequences.php?subject=schema&amp;{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
352
                            echo "<a href=\"sequences.php?subject=sequence&amp;action=properties&amp;{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']),
353
                            '&amp;sequence=', urlencode($rs->fields['name']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
354
355
                            break;
356
                        case 'COLUMNTABLE':
357
                            echo '<li>';
358
                            echo '<a href="'.\SUBFOLDER."/redirect/schema?{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
359
                            echo "<a href=\"tblproperties.php?subject=table&amp;{$this->misc->href}&amp;table=", urlencode($rs->fields['relname']), '&amp;schema=', urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['relname']), '</a>.';
360
                            echo "<a href=\"colproperties.php?{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '&amp;table=',
361
                            urlencode($rs->fields['relname']), '&amp;column=', urlencode($rs->fields['name']), '">',
362
                            $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
363
364
                            break;
365
                        case 'COLUMNVIEW':
366
                            echo '<li>';
367
                            echo '<a href="'.\SUBFOLDER."/redirect/schema?{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
368
                            echo "<a href=\"viewproperties.php?subject=view&amp;{$this->misc->href}&amp;view=", urlencode($rs->fields['relname']), '&amp;schema=', urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['relname']), '</a>.';
369
                            echo "<a href=\"colproperties.php?{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '&amp;view=',
370
                            urlencode($rs->fields['relname']), '&amp;column=', urlencode($rs->fields['name']), '">',
371
                            $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
372
373
                            break;
374
                        case 'INDEX':
375
                            echo '<li>';
376
                            echo '<a href="'.\SUBFOLDER."/redirect/schema?{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
377
                            echo '<a href="'.\SUBFOLDER."/redirect/table?{$this->misc->href}&amp;table=", urlencode($rs->fields['relname']), '&amp;schema=', urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['relname']), '</a>.';
378
                            echo "<a href=\"indexes.php?{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '&amp;table=', urlencode($rs->fields['relname']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
379
380
                            break;
381
                        case 'CONSTRAINTTABLE':
382
                            echo '<li>';
383
                            echo '<a href="'.\SUBFOLDER."/redirect/schema?{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
384
                            echo '<a href="'.\SUBFOLDER."/redirect/table?{$this->misc->href}&amp;table=", urlencode($rs->fields['relname']), '&amp;schema=', urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['relname']), '</a>.';
385
                            echo "<a href=\"constraints.php?{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '&amp;table=',
386
                            urlencode($rs->fields['relname']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
387
388
                            break;
389
                        case 'CONSTRAINTDOMAIN':
390
                            echo '<li>';
391
                            echo "<a href=\"domains.php?subject=schema&amp;{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
392
                            echo "<a href=\"domains.php?action=properties&amp;{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '&amp;domain=', urlencode($rs->fields['relname']), '">',
393
                            $this->misc->printVal($rs->fields['relname']), '.', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
394
395
                            break;
396
                        case 'TRIGGER':
397
                            echo '<li>';
398
                            echo '<a href="'.\SUBFOLDER."/redirect/schema?{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
399
                            echo '<a href="'.\SUBFOLDER."/redirect/table?{$this->misc->href}&amp;table=", urlencode($rs->fields['relname']), '&amp;schema=', urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['relname']), '</a>.';
400
                            echo "<a href=\"triggers.php?{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '&amp;table=', urlencode($rs->fields['relname']), '">',
401
                            $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
402
403
                            break;
404
                        case 'RULETABLE':
405
                            echo '<li>';
406
                            echo '<a href="'.\SUBFOLDER."/redirect/schema?{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
407
                            echo '<a href="'.\SUBFOLDER."/redirect/table?{$this->misc->href}&amp;table=", urlencode($rs->fields['relname']), '&amp;schema=', urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['relname']), '</a>.';
408
                            echo "<a href=\"rules.php?subject=table&amp;{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '&amp;reltype=table&amp;table=',
409
                            urlencode($rs->fields['relname']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
410
411
                            break;
412
                        case 'RULEVIEW':
413
                            echo '<li>';
414
                            echo '<a href="'.\SUBFOLDER."/redirect/schema?{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
415
                            echo '<a href="'.\SUBFOLDER."/redirect/view?{$this->misc->href}&amp;view=", urlencode($rs->fields['relname']), '&amp;schema=', urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['relname']), '</a>.';
416
                            echo "<a href=\"rules.php?subject=view&amp;{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '&amp;reltype=view&amp;view=',
417
                            urlencode($rs->fields['relname']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
418
419
                            break;
420
                        case 'FUNCTION':
421
                            echo '<li>';
422
                            echo "<a href=\"functions.php?subject=schema&amp;{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
423
                            echo "<a href=\"functions.php?action=properties&amp;{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '&amp;function=',
424
                            urlencode($rs->fields['name']), '&amp;function_oid=', urlencode($rs->fields['oid']), '">',
425
                            $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
426
427
                            break;
428
                        case 'TYPE':
429
                            echo '<li>';
430
                            echo "<a href=\"types.php?subject=schema&amp;{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
431
                            echo "<a href=\"types.php?action=properties&amp;{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '&amp;type=',
432
                            urlencode($rs->fields['name']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
433
434
                            break;
435
                        case 'DOMAIN':
436
                            echo '<li>';
437
                            echo "<a href=\"domains.php?subject=schema&amp;{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
438
                            echo "<a href=\"domains.php?action=properties&amp;{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '&amp;domain=',
439
                            urlencode($rs->fields['name']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
440
441
                            break;
442
                        case 'OPERATOR':
443
                            echo '<li>';
444
                            echo "<a href=\"operators.php?subject=schema&amp;{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
445
                            echo "<a href=\"operators.php?action=properties&amp;{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '&amp;operator=',
446
                            urlencode($rs->fields['name']), '&amp;operator_oid=', urlencode($rs->fields['oid']), '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
447
448
                            break;
449
                        case 'CONVERSION':
450
                            echo '<li>';
451
                            echo "<a href=\"conversions.php?subject=schema&amp;{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
452
                            echo "<a href=\"conversions.php?{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']),
453
                            '">', $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
454
455
                            break;
456
                        case 'LANGUAGE':
457
                            echo "<li><a href=\"languages.php?{$this->misc->href}\">", $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
458
459
                            break;
460
                        case 'AGGREGATE':
461
                            echo '<li>';
462
                            echo "<a href=\"aggregates.php?subject=schema&amp;{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
463
                            echo "<a href=\"aggregates.php?{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">',
464
                            $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
465
466
                            break;
467
                        case 'OPCLASS':
468
                            echo '<li>';
469
                            echo '<a href="'.\SUBFOLDER."/redirect/schema?{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">', $this->misc->printVal($rs->fields['schemaname']), '</a>.';
470
                            echo "<a href=\"opclasses.php?{$this->misc->href}&amp;schema=", urlencode($rs->fields['schemaname']), '">',
471
                            $this->_highlight($this->misc->printVal($rs->fields['name']), $_REQUEST['term']), "</a></li>\n";
472
473
                            break;
474
                    }
475
                    $rs->moveNext();
476
                }
477
                echo "</ul>\n";
478
479
                echo '<p>', $rs->recordCount(), ' ', $lang['strobjects'], "</p>\n";
480
            } else {
481
                echo "<p>{$lang['strnoobjects']}</p>\n";
482
            }
483
        }
484
    }
485
486
    /**
487
     * Displays options for database download.
488
     *
489
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
490
     */
491
    public function doExport($msg = '')
492
    {
493
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
494
495
        $lang = $this->lang;
496
        $data = $this->misc->getDatabaseAccessor();
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
497
498
        $this->printTrail('database');
499
        $this->printTabs('database', 'export');
500
        $this->printMsg($msg);
501
502
        echo '<form action="'.\SUBFOLDER."/src/views/dbexport.php\" method=\"post\">\n";
503
        echo "<table>\n";
504
        echo "<tr><th class=\"data\">{$lang['strformat']}</th><th class=\"data\" colspan=\"2\">{$lang['stroptions']}</th></tr>\n";
505
        // Data only
506
        echo '<tr><th class="data left" rowspan="2">';
507
        echo "<input type=\"radio\" id=\"what1\" name=\"what\" value=\"dataonly\" checked=\"checked\" /><label for=\"what1\">{$lang['strdataonly']}</label></th>\n";
508
        echo "<td>{$lang['strformat']}</td>\n";
509
        echo "<td><select name=\"d_format\">\n";
510
        echo "<option value=\"copy\">COPY</option>\n";
511
        echo "<option value=\"sql\">SQL</option>\n";
512
        echo "</select>\n</td>\n</tr>\n";
513
        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";
514
        // Structure only
515
        echo "<tr><th class=\"data left\"><input type=\"radio\" id=\"what2\" name=\"what\" value=\"structureonly\" /><label for=\"what2\">{$lang['strstructureonly']}</label></th>\n";
516
        echo "<td><label for=\"s_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"s_clean\" name=\"s_clean\" /></td>\n</tr>\n";
517
        // Structure and data
518
        echo '<tr><th class="data left" rowspan="3">';
519
        echo "<input type=\"radio\" id=\"what3\" name=\"what\" value=\"structureanddata\" /><label for=\"what3\">{$lang['strstructureanddata']}</label></th>\n";
520
        echo "<td>{$lang['strformat']}</td>\n";
521
        echo "<td><select name=\"sd_format\">\n";
522
        echo "<option value=\"copy\">COPY</option>\n";
523
        echo "<option value=\"sql\">SQL</option>\n";
524
        echo "</select>\n</td>\n</tr>\n";
525
        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";
526
        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";
527
        echo "</table>\n";
528
529
        echo "<h3>{$lang['stroptions']}</h3>\n";
530
        echo "<p><input type=\"radio\" id=\"output1\" name=\"output\" value=\"show\" checked=\"checked\" /><label for=\"output1\">{$lang['strshow']}</label>\n";
531
        echo "<br/><input type=\"radio\" id=\"output2\" name=\"output\" value=\"download\" /><label for=\"output2\">{$lang['strdownload']}</label>\n";
532
        // MSIE cannot download gzip in SSL mode - it's just broken
533
        if (!(strstr($_SERVER['HTTP_USER_AGENT'], 'MSIE') && isset($_SERVER['HTTPS']))) {
534
            echo "<br /><input type=\"radio\" id=\"output3\" name=\"output\" value=\"gzipped\" /><label for=\"output3\">{$lang['strdownloadgzipped']}</label>\n";
535
        }
536
        echo "</p>\n";
537
        echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n";
538
        echo "<input type=\"hidden\" name=\"subject\" value=\"database\" />\n";
539
        echo $this->misc->form;
540
        echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n";
541
        echo "</form>\n";
542
    }
543
544
    /**
545
     * Show the current status of all database variables.
546
     */
547
    public function doVariables()
548
    {
549
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
550
551
        $lang = $this->lang;
552
        $data = $this->misc->getDatabaseAccessor();
553
554
        // Fetch the variables from the database
555
        $variables = $data->getVariables();
556
        $this->printTrail('database');
557
        $this->printTabs('database', 'variables');
558
559
        $columns = [
560
            'variable' => [
561
                'title' => $lang['strname'],
562
                'field' => Decorator::field('name'),
563
            ],
564
            'value' => [
565
                'title' => $lang['strsetting'],
566
                'field' => Decorator::field('setting'),
567
            ],
568
        ];
569
570
        $actions = [];
571
572
        echo $this->printTable($variables, $columns, $actions, $this->table_place, $lang['strnodata']);
573
    }
574
575
    /**
576
     * Show all current database connections and any queries they
577
     * are running.
578
     *
579
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
580
     */
581
    public function doProcesses($msg = '')
582
    {
583
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
584
585
        $lang = $this->lang;
586
        $data = $this->misc->getDatabaseAccessor();
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
587
588
        $this->printTrail('database');
589
        $this->printTabs('database', 'processes');
590
        $this->printMsg($msg);
591
592
        if (0 === strlen($msg)) {
593
            echo '<br /><a id="control" href=""><img src="'.$this->misc->icon('Refresh')."\" alt=\"{$lang['strrefresh']}\" title=\"{$lang['strrefresh']}\"/>&nbsp;{$lang['strrefresh']}</a>";
594
        }
595
596
        echo '<div id="data_block">';
597
        $this->currentProcesses();
598
        echo '</div>';
599
    }
600
601
    public function currentProcesses($isAjax = false)
2 ignored issues
show
Unused Code introduced by
The parameter $isAjax is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

601
    public function currentProcesses(/** @scrutinizer ignore-unused */ $isAjax = false)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
602
    {
603
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
604
605
        $lang = $this->lang;
606
        $data = $this->misc->getDatabaseAccessor();
607
608
        // Display prepared transactions
609
        if ($data->hasPreparedXacts()) {
610
            echo "<h3>{$lang['strpreparedxacts']}</h3>\n";
611
            $prep_xacts = $data->getPreparedXacts($_REQUEST['database']);
612
613
            $columns = [
614
                'transaction' => [
615
                    'title' => $lang['strxactid'],
616
                    'field' => Decorator::field('transaction'),
617
                ],
618
                'gid' => [
619
                    'title' => $lang['strgid'],
620
                    'field' => Decorator::field('gid'),
621
                ],
622
                'prepared' => [
623
                    'title' => $lang['strstarttime'],
624
                    'field' => Decorator::field('prepared'),
625
                ],
626
                'owner' => [
627
                    'title' => $lang['strowner'],
628
                    'field' => Decorator::field('owner'),
629
                ],
630
            ];
631
632
            $actions = [];
633
634
            echo $this->printTable($prep_xacts, $columns, $actions, 'database-processes-preparedxacts', $lang['strnodata']);
635
        }
636
637
        // Fetch the processes from the database
638
        echo "<h3>{$lang['strprocesses']}</h3>\n";
639
        $processes = $data->getProcesses($_REQUEST['database']);
640
641
        $columns = [
642
            'user' => [
643
                'title' => $lang['strusername'],
644
                'field' => Decorator::field('usename'),
645
            ],
646
            'process' => [
647
                'title' => $lang['strprocess'],
648
                'field' => Decorator::field('pid'),
649
            ],
650
            'application_name' => [
651
                'title' => 'application',
652
                'field' => Decorator::field('application_name'),
653
            ],
654
            'client_addr' => [
655
                'title' => 'address',
656
                'field' => Decorator::field('client_addr'),
657
            ],
658
            'blocked' => [
659
                'title' => $lang['strblocked'],
660
                'field' => Decorator::field('waiting'),
661
            ],
662
            'query' => [
663
                'title' => $lang['strsql'],
664
                'field' => Decorator::field('query'),
665
            ],
666
            'start_time' => [
667
                'title' => $lang['strstarttime'],
668
                'field' => Decorator::field('query_start'),
669
            ],
670
        ];
671
672
        // Build possible actions for our process list
673
        $columns['actions'] = ['title' => $lang['stractions']];
674
675
        $actions = [];
676
        if ($data->hasUserSignals() || $data->isSuperUser()) {
677
            $actions = [
678
                'cancel' => [
679
                    'content' => $lang['strcancel'],
680
                    'attr'    => [
681
                        'href' => [
682
                            'url'     => 'database.php',
683
                            'urlvars' => [
684
                                'action' => 'signal',
685
                                'signal' => 'CANCEL',
686
                                'pid'    => Decorator::field('pid'),
687
                            ],
688
                        ],
689
                    ],
690
                ],
691
                'kill' => [
692
                    'content' => $lang['strkill'],
693
                    'attr'    => [
694
                        'href' => [
695
                            'url'     => 'database.php',
696
                            'urlvars' => [
697
                                'action' => 'signal',
698
                                'signal' => 'KILL',
699
                                'pid'    => Decorator::field('pid'),
700
                            ],
701
                        ],
702
                    ],
703
                ],
704
            ];
705
706
            // Remove actions where not supported
707
            if (!$data->hasQueryKill()) {
708
                unset($actions['kill']);
709
            }
710
711
            if (!$data->hasQueryCancel()) {
712
                unset($actions['cancel']);
713
            }
714
        }
715
716
        if (0 == count($actions)) {
717
            unset($columns['actions']);
718
        }
719
720
        echo $this->printTable($processes, $columns, $actions, 'database-processes', $lang['strnodata']);
721
    }
722
723
    public function currentLocks($isAjax = false)
2 ignored issues
show
Unused Code introduced by
The parameter $isAjax is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

723
    public function currentLocks(/** @scrutinizer ignore-unused */ $isAjax = false)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
Missing function doc comment
Loading history...
724
    {
725
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
726
727
        $lang = $this->lang;
728
        $data = $this->misc->getDatabaseAccessor();
729
730
        // Get the info from the pg_locks view
731
        $variables = $data->getLocks();
732
733
        $columns = [
734
            'namespace' => [
735
                'title' => $lang['strschema'],
736
                'field' => Decorator::field('nspname'),
737
            ],
738
            'tablename' => [
739
                'title' => $lang['strtablename'],
740
                'field' => Decorator::field('tablename'),
741
            ],
742
            'vxid' => [
743
                'title' => $lang['strvirtualtransaction'],
744
                'field' => Decorator::field('virtualtransaction'),
745
            ],
746
            'transactionid' => [
747
                'title' => $lang['strtransaction'],
748
                'field' => Decorator::field('transaction'),
749
            ],
750
            'processid' => [
751
                'title' => $lang['strprocessid'],
752
                'field' => Decorator::field('pid'),
753
            ],
754
            'mode' => [
755
                'title' => $lang['strmode'],
756
                'field' => Decorator::field('mode'),
757
            ],
758
            'granted' => [
759
                'title' => $lang['strislockheld'],
760
                'field' => Decorator::field('granted'),
761
                'type'  => 'yesno',
762
            ],
763
        ];
764
765
        if (!$data->hasVirtualTransactionId()) {
766
            unset($columns['vxid']);
767
        }
768
769
        $actions = [];
770
        echo $this->printTable($variables, $columns, $actions, 'database-locks', $lang['strnodata']);
771
    }
772
773
    /**
774
     * Show the existing table locks in the current database.
775
     */
776
    public function doLocks()
777
    {
778
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
779
780
        $lang = $this->lang;
781
        $data = $this->misc->getDatabaseAccessor();
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
782
783
        $this->printTrail('database');
784
        $this->printTabs('database', 'locks');
785
786
        echo '<br /><a id="control" href=""><img src="'.$this->misc->icon('Refresh')."\" alt=\"{$lang['strrefresh']}\" title=\"{$lang['strrefresh']}\"/>&nbsp;{$lang['strrefresh']}</a>";
787
788
        echo '<div id="data_block">';
789
        $this->currentLocks();
790
        echo '</div>';
791
    }
792
793
    /**
794
     * Allow execution of arbitrary SQL statements on a database.
795
     */
796
    public function doSQL()
797
    {
798
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
799
800
        $lang = $this->lang;
801
        $data = $this->misc->getDatabaseAccessor();
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
802
803
        if ((!isset($_SESSION['sqlquery'])) || isset($_REQUEST['new'])) {
804
            $_SESSION['sqlquery'] = '';
805
            $_REQUEST['paginate'] = 'on';
806
        }
807
808
        $this->printTrail('database');
809
        $this->printTabs('database', 'sql');
810
        echo "<p>{$lang['strentersql']}</p>\n";
811
        echo '<form action="'.\SUBFOLDER.'/src/views/sql.php" method="post" enctype="multipart/form-data" id="sqlform">'."\n";
812
        echo "<p>{$lang['strsql']}<br />\n";
813
        echo '<textarea style="width:95%;" rows="15" cols="50" name="query" id="query">',
814
        htmlspecialchars($_SESSION['sqlquery']), "</textarea></p>\n";
815
816
        // Check that file uploads are enabled
817
        if (ini_get('file_uploads')) {
818
            // Don't show upload option if max size of uploads is zero
819
            $max_size = $this->misc->inisizeToBytes(ini_get('upload_max_filesize'));
820
            if (is_double($max_size) && $max_size > 0) {
821
                echo "<p><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"{$max_size}\" />\n";
822
                echo "<label for=\"script\">{$lang['struploadscript']}</label> <input id=\"script\" name=\"script\" type=\"file\" /></p>\n";
823
            }
824
        }
825
826
        echo '<p><input type="checkbox" id="paginate" name="paginate"', (isset($_REQUEST['paginate']) ? ' checked="checked"' : ''), " /><label for=\"paginate\">{$lang['strpaginate']}</label></p>\n";
827
        echo "<p><input type=\"submit\" name=\"execute\" accesskey=\"r\" value=\"{$lang['strexecute']}\" />\n";
828
        echo $this->misc->form;
829
        echo "<input type=\"reset\" accesskey=\"q\" value=\"{$lang['strreset']}\" /></p>\n";
830
        echo "</form>\n";
831
832
        // Default focus
833
        $this->setFocus('forms[0].query');
834
    }
835
836
    /**
837
     * This functions does pretty much nothing. It's meant to implement
838
     * an abstract method of AdminTrait.
839
     *
840
     * @param string $msg The message
841
     *
842
     * @return string The message
843
     */
844
    public function doDefault($msg = '')
845
    {
846
        return $msg;
847
    }
848
}
849