Passed
Push — master ( 442876...4ec1bc )
by Felipe
15:55 queued 10:33
created

DatabaseController::doSignal()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 0
loc 10
rs 9.4285
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
        $lang   = $this->lang;
32
        $action = $this->action;
33
34
        if ('tree' == $action) {
35
            return $this->doTree();
36
        }
37
38
        if ('refresh_locks' == $action) {
39
            return $this->currentLocks(true);
40
        }
41
42
        if ('refresh_processes' == $action) {
43
            return $this->currentProcesses(true);
44
        }
45
        $scripts = '';
46
        // normal flow
47
        if ('locks' == $action || 'processes' == $action) {
48
            $scripts .= '<script src="' . \SUBFOLDER . '/js/database.js" type="text/javascript"></script>';
49
50
            $refreshTime = $this->conf['ajax_refresh'] * 1500;
51
52
            $scripts .= "<script type=\"text/javascript\">\n";
53
            $scripts .= "var Database = {\n";
54
            $scripts .= "ajax_time_refresh: {$refreshTime},\n";
55
            $scripts .= "str_start: {text:'{$lang['strstart']}',icon: '" . $this->misc->icon('Execute') . "'},\n";
56
            $scripts .= "str_stop: {text:'{$lang['strstop']}',icon: '" . $this->misc->icon('Stop') . "'},\n";
57
            $scripts .= "load_icon: '" . $this->misc->icon('Loading') . "',\n";
58
            $scripts .= "server:'{$_REQUEST['server']}',\n";
59
            $scripts .= "dbname:'{$_REQUEST['database']}',\n";
60
            $scripts .= "action:'refresh_{$action}',\n";
61
            $scripts .= "errmsg: '" . str_replace("'", "\\'", $lang['strconnectionfail']) . "'\n";
62
            $scripts .= "};\n";
63
            $scripts .= "</script>\n";
64
        }
65
66
        $header_template = 'header.twig';
67
        $footer_template = 'footer.twig';
68
        // @todo convert all these methods to return text instead of print text
69
        ob_start();
70
        switch ($action) {
71
            case 'find':
72
                if (isset($_REQUEST['term'])) {
73
                    $this->doFind(false);
74
                } else {
75
                    $this->doFind(true);
76
                }
77
78
                break;
79
            case 'sql':
80
                $this->doSQL();
81
                $header_template = 'header_sqledit.twig';
82
                $footer_template = 'footer_sqledit.twig';
83
84
                break;
85
            case 'variables':
86
                $this->doVariables();
87
88
                break;
89
            case 'processes':
90
                $this->doProcesses();
91
92
                break;
93
            case 'locks':
94
                $this->doLocks();
95
96
                break;
97
            case 'export':
98
                $this->doExport();
99
100
                break;
101
            case 'signal':
102
                $this->doSignal();
103
104
                break;
105
            default:
106
                if (false === $this->adminActions($action, 'database')) {
107
                    $header_template = 'header_sqledit.twig';
108
                    $footer_template = 'footer_sqledit.twig';
109
                    $this->doSQL();
110
                }
111
112
                break;
113
        }
114
        $output = ob_get_clean();
115
116
        $this->printHeader($lang['strdatabase'], $scripts, true, $header_template);
117
        $this->printBody();
118
119
        echo $output;
120
121
        $this->printFooter(true, $footer_template);
122
    }
123
124
    public function doTree($print = true)
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
125
    {
126
        $reqvars = $this->misc->getRequestVars('database');
127
        $tabs    = $this->misc->getNavTabs('database');
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
        $lang = $this->lang;
146
        $data = $this->misc->getDatabaseAccessor();
147
148
        $status = $data->sendSignal($_REQUEST['pid'], $_REQUEST['signal']);
149
        if (0 == $status) {
150
            $this->doProcesses($lang['strsignalsent']);
151
        } else {
152
            $this->doProcesses($lang['strsignalsentbad']);
153
        }
154
    }
155
156
    /**
157
     * Searches for a named database object.
158
     *
159
     * @param mixed $confirm
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
160
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
161
     */
162
    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

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

580
    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...
581
    {
582
        $lang = $this->lang;
583
        $data = $this->misc->getDatabaseAccessor();
584
585
        // Display prepared transactions
586
        if ($data->hasPreparedXacts()) {
587
            echo "<h3>{$lang['strpreparedxacts']}</h3>\n";
588
            $prep_xacts = $data->getPreparedXacts($_REQUEST['database']);
589
590
            $columns = [
591
                'transaction' => [
592
                    'title' => $lang['strxactid'],
593
                    'field' => Decorator::field('transaction'),
594
                ],
595
                'gid'         => [
596
                    'title' => $lang['strgid'],
597
                    'field' => Decorator::field('gid'),
598
                ],
599
                'prepared'    => [
600
                    'title' => $lang['strstarttime'],
601
                    'field' => Decorator::field('prepared'),
602
                ],
603
                'owner'       => [
604
                    'title' => $lang['strowner'],
605
                    'field' => Decorator::field('owner'),
606
                ],
607
            ];
608
609
            $actions = [];
610
611
            echo $this->printTable($prep_xacts, $columns, $actions, 'database-processes-preparedxacts', $lang['strnodata']);
612
        }
613
614
        // Fetch the processes from the database
615
        echo "<h3>{$lang['strprocesses']}</h3>\n";
616
        $processes = $data->getProcesses($_REQUEST['database']);
617
618
        $columns = [
619
            'user'             => [
620
                'title' => $lang['strusername'],
621
                'field' => Decorator::field('usename'),
622
            ],
623
            'process'          => [
624
                'title' => $lang['strprocess'],
625
                'field' => Decorator::field('pid'),
626
            ],
627
            'application_name' => [
628
                'title' => 'application',
629
                'field' => Decorator::field('application_name'),
630
            ],
631
            'client_addr'      => [
632
                'title' => 'address',
633
                'field' => Decorator::field('client_addr'),
634
            ],
635
            'blocked'          => [
636
                'title' => $lang['strblocked'],
637
                'field' => Decorator::field('waiting'),
638
            ],
639
            'query'            => [
640
                'title' => $lang['strsql'],
641
                'field' => Decorator::field('query'),
642
            ],
643
            'start_time'       => [
644
                'title' => $lang['strstarttime'],
645
                'field' => Decorator::field('query_start'),
646
            ],
647
        ];
648
649
        // Build possible actions for our process list
650
        $columns['actions'] = ['title' => $lang['stractions']];
651
652
        $actions = [];
653
        if ($data->hasUserSignals() || $data->isSuperUser()) {
654
            $actions = [
655
                'cancel' => [
656
                    'content' => $lang['strcancel'],
657
                    'attr'    => [
658
                        'href' => [
659
                            'url'     => 'database.php',
660
                            'urlvars' => [
661
                                'action' => 'signal',
662
                                'signal' => 'CANCEL',
663
                                'pid'    => Decorator::field('pid'),
664
                            ],
665
                        ],
666
                    ],
667
                ],
668
                'kill'   => [
669
                    'content' => $lang['strkill'],
670
                    'attr'    => [
671
                        'href' => [
672
                            'url'     => 'database.php',
673
                            'urlvars' => [
674
                                'action' => 'signal',
675
                                'signal' => 'KILL',
676
                                'pid'    => Decorator::field('pid'),
677
                            ],
678
                        ],
679
                    ],
680
                ],
681
            ];
682
683
            // Remove actions where not supported
684
            if (!$data->hasQueryKill()) {
685
                unset($actions['kill']);
686
            }
687
688
            if (!$data->hasQueryCancel()) {
689
                unset($actions['cancel']);
690
            }
691
        }
692
693
        if (0 == count($actions)) {
694
            unset($columns['actions']);
695
        }
696
697
        echo $this->printTable($processes, $columns, $actions, 'database-processes', $lang['strnodata']);
698
    }
699
700
    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

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