Passed
Push — master ( d71956...442876 )
by Felipe
07:09 queued 03:12
created

DatabaseController::doProcesses()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

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

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

546
    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...
547
    {
548
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
549
        $misc = $this->misc;
550
        $lang = $this->lang;
551
        $data = $misc->getDatabaseAccessor();
552
553
        // Display prepared transactions
554
        if ($data->hasPreparedXacts()) {
555
            echo "<h3>{$lang['strpreparedxacts']}</h3>\n";
556
            $prep_xacts = $data->getPreparedXacts($_REQUEST['database']);
557
558
            $columns = [
559
                'transaction' => [
560
                    'title' => $lang['strxactid'],
561
                    'field' => Decorator::field('transaction'),
562
                ],
563
                'gid'         => [
564
                    'title' => $lang['strgid'],
565
                    'field' => Decorator::field('gid'),
566
                ],
567
                'prepared'    => [
568
                    'title' => $lang['strstarttime'],
569
                    'field' => Decorator::field('prepared'),
570
                ],
571
                'owner'       => [
572
                    'title' => $lang['strowner'],
573
                    'field' => Decorator::field('owner'),
574
                ],
575
            ];
576
577
            $actions = [];
578
579
            echo $this->printTable($prep_xacts, $columns, $actions, 'database-processes-preparedxacts', $lang['strnodata']);
580
        }
581
582
        // Fetch the processes from the database
583
        echo "<h3>{$lang['strprocesses']}</h3>\n";
584
        $processes = $data->getProcesses($_REQUEST['database']);
585
586
        $columns = [
587
            'user'             => [
588
                'title' => $lang['strusername'],
589
                'field' => Decorator::field('usename'),
590
            ],
591
            'process'          => [
592
                'title' => $lang['strprocess'],
593
                'field' => Decorator::field('pid'),
594
            ],
595
            'application_name' => [
596
                'title' => 'application',
597
                'field' => Decorator::field('application_name'),
598
            ],
599
            'client_addr'      => [
600
                'title' => 'address',
601
                'field' => Decorator::field('client_addr'),
602
            ],
603
            'blocked'          => [
604
                'title' => $lang['strblocked'],
605
                'field' => Decorator::field('waiting'),
606
            ],
607
            'query'            => [
608
                'title' => $lang['strsql'],
609
                'field' => Decorator::field('query'),
610
            ],
611
            'start_time'       => [
612
                'title' => $lang['strstarttime'],
613
                'field' => Decorator::field('query_start'),
614
            ],
615
        ];
616
617
        // Build possible actions for our process list
618
        $columns['actions'] = ['title' => $lang['stractions']];
619
620
        $actions = [];
621
        if ($data->hasUserSignals() || $data->isSuperUser()) {
622
            $actions = [
623
                'cancel' => [
624
                    'content' => $lang['strcancel'],
625
                    'attr'    => [
626
                        'href' => [
627
                            'url'     => 'database.php',
628
                            'urlvars' => [
629
                                'action' => 'signal',
630
                                'signal' => 'CANCEL',
631
                                'pid'    => Decorator::field('pid'),
632
                            ],
633
                        ],
634
                    ],
635
                ],
636
                'kill'   => [
637
                    'content' => $lang['strkill'],
638
                    'attr'    => [
639
                        'href' => [
640
                            'url'     => 'database.php',
641
                            'urlvars' => [
642
                                'action' => 'signal',
643
                                'signal' => 'KILL',
644
                                'pid'    => Decorator::field('pid'),
645
                            ],
646
                        ],
647
                    ],
648
                ],
649
            ];
650
651
            // Remove actions where not supported
652
            if (!$data->hasQueryKill()) {
653
                unset($actions['kill']);
654
            }
655
656
            if (!$data->hasQueryCancel()) {
657
                unset($actions['cancel']);
658
            }
659
        }
660
661
        if (count($actions) == 0) {
662
            unset($columns['actions']);
663
        }
664
665
        echo $this->printTable($processes, $columns, $actions, 'database-processes', $lang['strnodata']);
666
667
        return;
668
    }
669
670
    public function currentLocks($isAjax = false)
2 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
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

670
    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...
671
    {
672
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
673
        $misc = $this->misc;
674
        $lang = $this->lang;
675
        $data = $misc->getDatabaseAccessor();
676
677
        // Get the info from the pg_locks view
678
        $variables = $data->getLocks();
679
680
        $columns = [
681
            'namespace'     => [
682
                'title' => $lang['strschema'],
683
                'field' => Decorator::field('nspname'),
684
            ],
685
            'tablename'     => [
686
                'title' => $lang['strtablename'],
687
                'field' => Decorator::field('tablename'),
688
            ],
689
            'vxid'          => [
690
                'title' => $lang['strvirtualtransaction'],
691
                'field' => Decorator::field('virtualtransaction'),
692
            ],
693
            'transactionid' => [
694
                'title' => $lang['strtransaction'],
695
                'field' => Decorator::field('transaction'),
696
            ],
697
            'processid'     => [
698
                'title' => $lang['strprocessid'],
699
                'field' => Decorator::field('pid'),
700
            ],
701
            'mode'          => [
702
                'title' => $lang['strmode'],
703
                'field' => Decorator::field('mode'),
704
            ],
705
            'granted'       => [
706
                'title' => $lang['strislockheld'],
707
                'field' => Decorator::field('granted'),
708
                'type'  => 'yesno',
709
            ],
710
        ];
711
712
        if (!$data->hasVirtualTransactionId()) {
713
            unset($columns['vxid']);
714
        }
715
716
        $actions = [];
717
        echo $this->printTable($variables, $columns, $actions, 'database-locks', $lang['strnodata']);
718
719
        return;
720
    }
721
722
    /**
723
     * Show the existing table locks in the current database
724
     */
725
    public function doLocks()
726
    {
727
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
728
        $misc = $this->misc;
729
        $lang = $this->lang;
730
        $data = $misc->getDatabaseAccessor();
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
731
732
        $this->printTrail('database');
733
        $this->printTabs('database', 'locks');
734
735
        echo '<br /><a id="control" href=""><img src="' . $misc->icon('Refresh') . "\" alt=\"{$lang['strrefresh']}\" title=\"{$lang['strrefresh']}\"/>&nbsp;{$lang['strrefresh']}</a>";
736
737
        echo '<div id="data_block">';
738
        $this->currentLocks();
739
        echo '</div>';
740
    }
741
742
    /**
743
     * Allow execution of arbitrary SQL statements on a database
744
     */
745
    public function doSQL()
746
    {
747
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
748
        $misc = $this->misc;
749
        $lang = $this->lang;
750
        $data = $misc->getDatabaseAccessor();
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
751
752
        if ((!isset($_SESSION['sqlquery'])) || isset($_REQUEST['new'])) {
753
            $_SESSION['sqlquery'] = '';
754
            $_REQUEST['paginate'] = 'on';
755
        }
756
757
        $this->printTrail('database');
758
        $this->printTabs('database', 'sql');
759
        echo "<p>{$lang['strentersql']}</p>\n";
760
        echo '<form action="' . SUBFOLDER . '/src/views/sql.php" method="post" enctype="multipart/form-data" id="sqlform">' . "\n";
761
        echo "<p>{$lang['strsql']}<br />\n";
762
        echo '<textarea style="width:95%;" rows="15" cols="50" name="query" id="query">',
763
        htmlspecialchars($_SESSION['sqlquery']), "</textarea></p>\n";
764
765
        // Check that file uploads are enabled
766
        if (ini_get('file_uploads')) {
767
            // Don't show upload option if max size of uploads is zero
768
            $max_size = $misc->inisizeToBytes(ini_get('upload_max_filesize'));
769
            if (is_double($max_size) && $max_size > 0) {
770
                echo "<p><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"{$max_size}\" />\n";
771
                echo "<label for=\"script\">{$lang['struploadscript']}</label> <input id=\"script\" name=\"script\" type=\"file\" /></p>\n";
772
            }
773
        }
774
775
        echo '<p><input type="checkbox" id="paginate" name="paginate"', (isset($_REQUEST['paginate']) ? ' checked="checked"' : ''), " /><label for=\"paginate\">{$lang['strpaginate']}</label></p>\n";
776
        echo "<p><input type=\"submit\" name=\"execute\" accesskey=\"r\" value=\"{$lang['strexecute']}\" />\n";
777
        echo $misc->form;
778
        echo "<input type=\"reset\" accesskey=\"q\" value=\"{$lang['strreset']}\" /></p>\n";
779
        echo "</form>\n";
780
781
        // Default focus
782
        $this->setFocus('forms[0].query');
783
    }
784
785
    /**
786
     * This functions does pretty much nothing. It's meant to implement
787
     * an abstract method of AdminTrait
788
     *
789
     * @param string  $msg  The message
790
     *
791
     * @return string  The message
792
     */
793
    public function doDefault($msg = '')
794
    {
795
        return $msg;
796
    }
797
}
798