Test Failed
Branch develop (db5506)
by Felipe
03:46
created

TblpropertiesController::doTree()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 23
nc 1
nop 0
dl 0
loc 38
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace PHPPgAdmin\Controller;
4
5
use \PHPPgAdmin\Decorators\Decorator;
6
7
/**
8
 * Base controller class
9
 */
10
class TblpropertiesController extends BaseController
11
{
12
    public $_name = 'TblpropertiesController';
13
14
    public function render()
0 ignored issues
show
Coding Style introduced by
render uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
render uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
15
    {
16
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
17
        $misc = $this->misc;
18
        $lang = $this->lang;
19
20
        $action = $this->action;
21
        if ($action == 'tree') {
22
            return $this->doTree();
23
        }
24
        $data = $misc->getDatabaseAccessor();
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
25
26
        $footer_template = 'footer.twig';
0 ignored issues
show
Unused Code introduced by
The assignment to $footer_template is dead and can be removed.
Loading history...
27
        $header_template = 'header.twig';
28
29
        ob_start();
30
        switch ($action) {
31
            case 'alter':
32
                if (isset($_POST['alter'])) {
33
                    $this->doSaveAlter();
34
                } else {
35
                    $this->doDefault();
36
                }
37
38
                break;
39
            case 'confirm_alter':
40
                $this->doAlter();
41
                break;
42
            case 'import':
43
                $this->doImport();
44
                break;
45
            case 'export':
46
                $this->doExport();
47
                break;
48
            case 'add_column':
49
                if (isset($_POST['cancel'])) {
50
                    $this->doDefault();
51
                } else {
52
                    $header_template = 'header_select2.twig';
53
                    $this->doAddColumn();
54
                }
55
56
                break;
57
            case 'properties':
58
                if (isset($_POST['cancel'])) {
59
                    $this->doDefault();
60
                } else {
61
                    $this->doProperties();
0 ignored issues
show
Bug introduced by
The method doProperties() does not exist on PHPPgAdmin\Controller\TblpropertiesController. ( Ignorable by Annotation )

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

61
                    $this->/** @scrutinizer ignore-call */ doProperties();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
62
                }
63
64
                break;
65
            case 'drop':
66
                if (isset($_POST['drop'])) {
67
                    $this->doDrop(false);
68
                } else {
69
                    $this->doDefault();
70
                }
71
72
                break;
73
            case 'confirm_drop':
74
                $this->doDrop(true);
75
                break;
76
            default:
77
                $this->doDefault();
78
                break;
79
        }
80
81
        $output = ob_get_clean();
82
83
        $this->printHeader($lang['strtables'] . ' - ' . $_REQUEST['table'], null, true, $header_template);
84
        $this->printBody();
85
86
        echo $output;
87
88
        return $this->printFooter();
89
    }
90
91
    /**
92
     * Show default list of columns in the table
93
     */
94
    public function doDefault($msg = '')
0 ignored issues
show
Coding Style introduced by
doDefault uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
95
    {
96
        $conf = $this->conf;
97
        $misc = $this->misc;
98
        $lang = $this->lang;
99
        $data = $misc->getDatabaseAccessor();
100
101
        $attPre = function (&$rowdata, $actions) use ($data) {
102
            $rowdata->fields['+type'] = $data->formatType($rowdata->fields['type'], $rowdata->fields['atttypmod']);
103
            $attname                  = $rowdata->fields['attname'];
104
            $table                    = $_REQUEST['table'];
105
            $data->fieldClean($attname);
106
            $data->fieldClean($table);
107
108
            $actions['browse']['attr']['href']['urlvars']['query'] = "SELECT \"{$attname}\", count(*) AS \"count\"
109
                FROM \"{$table}\" GROUP BY \"{$attname}\" ORDER BY \"{$attname}\"";
110
111
            return $actions;
112
        };
113
114
        $cstrRender = function ($s, $p) use ($misc, $data) {
115
            $str = '';
116
            foreach ($p['keys'] as $k => $c) {
117
                if (is_null($p['keys'][$k]['consrc'])) {
118
                    $atts        = $data->getAttributeNames($_REQUEST['table'], explode(' ', $p['keys'][$k]['indkey']));
119
                    $c['consrc'] = ($c['contype'] == 'u' ? 'UNIQUE (' : 'PRIMARY KEY (') . join(',', $atts) . ')';
120
                }
121
122
                if ($c['p_field'] == $s) {
123
                    switch ($c['contype']) {
124 View Code Duplication
                        case 'p':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
125
                            $str .= '<a href="constraints.php?' . $misc->href . '&amp;table=' . urlencode($c['p_table']) . '&amp;schema=' . urlencode($c['p_schema']) . '"><img src="' .
126
                            $misc->icon('PrimaryKey') . '" alt="[pk]" title="' . htmlentities($c['consrc'], ENT_QUOTES, 'UTF-8') . '" /></a>';
127
                            break;
128 View Code Duplication
                        case 'f':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
129
                            $str .= '<a href="tblproperties.php?' . $misc->href . '&amp;table=' . urlencode($c['f_table']) . '&amp;schema=' . urlencode($c['f_schema']) . '"><img src="' .
130
                            $misc->icon('ForeignKey') . '" alt="[fk]" title="' . htmlentities($c['consrc'], ENT_QUOTES, 'UTF-8') . '" /></a>';
131
                            break;
132 View Code Duplication
                        case 'u':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
133
                            $str .= '<a href="constraints.php?' . $misc->href . '&amp;table=' . urlencode($c['p_table']) . '&amp;schema=' . urlencode($c['p_schema']) . '"><img src="' .
134
                            $misc->icon('UniqueConstraint') . '" alt="[uniq]" title="' . htmlentities($c['consrc'], ENT_QUOTES, 'UTF-8') . '" /></a>';
135
                            break;
136 View Code Duplication
                        case 'c':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
137
                            $str .= '<a href="constraints.php?' . $misc->href . '&amp;table=' . urlencode($c['p_table']) . '&amp;schema=' . urlencode($c['p_schema']) . '"><img src="' .
138
                            $misc->icon('CheckConstraint') . '" alt="[check]" title="' . htmlentities($c['consrc'], ENT_QUOTES, 'UTF-8') . '" /></a>';
139
                    }
140
                }
141
            }
142
143
            return $str;
144
        };
145
146
        $this->printTrail('table');
147
        $this->printTabs('table', 'columns');
148
        $this->printMsg($msg);
149
150
        // Get table
151
        $tdata = $data->getTable($_REQUEST['table']);
152
        // Get columns
153
        $attrs = $data->getTableAttributes($_REQUEST['table']);
154
        // Get constraints keys
155
        $ck = $data->getConstraintsWithFields($_REQUEST['table']);
156
157
        // Show comment if any
158
        if ($tdata->fields['relcomment'] !== null) {
159
            echo '<p class="comment">', $misc->printVal($tdata->fields['relcomment']), "</p>\n";
160
        }
161
162
        $columns = [
163
            'column'  => [
164
                'title' => $lang['strcolumn'],
165
                'field' => Decorator::field('attname'),
166
                'url'   => "colproperties.php?subject=column&amp;{$misc->href}&amp;table=" . urlencode($_REQUEST['table']) . '&amp;',
167
                'vars'  => ['column' => 'attname'],
168
            ],
169
            'type'    => [
170
                'title' => $lang['strtype'],
171
                'field' => Decorator::field('+type'),
172
            ],
173
            'notnull' => [
174
                'title'  => $lang['strnotnull'],
175
                'field'  => Decorator::field('attnotnull'),
176
                'type'   => 'bool',
177
                'params' => ['true' => 'NOT NULL', 'false' => ''],
178
            ],
179
            'default' => [
180
                'title' => $lang['strdefault'],
181
                'field' => Decorator::field('adsrc'),
182
            ],
183
            'keyprop' => [
184
                'title'  => $lang['strconstraints'],
185
                'class'  => 'constraint_cell',
186
                'field'  => Decorator::field('attname'),
187
                'type'   => 'callback',
188
                'params' => [
189
                    'function' => $cstrRender,
190
                    'keys'     => $ck->getArray(),
191
                ],
192
            ],
193
            'actions' => [
194
                'title' => $lang['stractions'],
195
            ],
196
            'comment' => [
197
                'title' => $lang['strcomment'],
198
                'field' => Decorator::field('comment'),
199
            ],
200
        ];
201
202
        $actions = [
0 ignored issues
show
Unused Code introduced by
The assignment to $actions is dead and can be removed.
Loading history...
203
            'browse'     => [
204
                'title' => $lang['strbrowse'],
205
                'url'   => "display.php?{$misc->href}&amp;subject=column&amp;return=table&amp;table=" . urlencode($_REQUEST['table']) . '&amp;',
206
                'vars'  => ['column' => 'attname'],
207
            ],
208
            'alter'      => [
209
                'title' => $lang['stralter'],
210
                'url'   => "colproperties.php?action=properties&amp;{$misc->href}&amp;table=" . urlencode($_REQUEST['table']) . '&amp;',
211
                'vars'  => ['column' => 'attname'],
212
            ],
213
            'privileges' => [
214
                'title' => $lang['strprivileges'],
215
                'url'   => "privileges.php?subject=column&amp;{$misc->href}&amp;table=" . urlencode($_REQUEST['table']) . '&amp;',
216
                'vars'  => ['column' => 'attname'],
217
            ],
218
            'drop'       => [
219
                'title' => $lang['strdrop'],
220
                'url'   => "tblproperties.php?action=confirm_drop&amp;{$misc->href}&amp;table=" . urlencode($_REQUEST['table']) . '&amp;',
221
                'vars'  => ['column' => 'attname'],
222
            ],
223
        ];
224
225
        $actions = [
226
            'browse'     => [
227
                'content' => $lang['strbrowse'],
228
                'attr'    => [
229
                    'href' => [
230
                        'url'     => 'display.php',
231
                        'urlvars' => [
232
                            'table'   => $_REQUEST['table'],
233
                            'subject' => 'column',
234
                            'return'  => 'table',
235
                            'column'  => Decorator::field('attname'),
236
                        ],
237
                    ],
238
                ],
239
            ],
240
            'alter'      => [
241
                'content' => $lang['stralter'],
242
                'attr'    => [
243
                    'href' => [
244
                        'url'     => 'colproperties.php',
245
                        'urlvars' => [
246
                            'subject' => 'column',
247
                            'action'  => 'properties',
248
                            'table'   => $_REQUEST['table'],
249
                            'column'  => Decorator::field('attname'),
250
                        ],
251
                    ],
252
                ],
253
            ],
254
            'privileges' => [
255
                'content' => $lang['strprivileges'],
256
                'attr'    => [
257
                    'href' => [
258
                        'url'     => 'privileges.php',
259
                        'urlvars' => [
260
                            'subject' => 'column',
261
                            'table'   => $_REQUEST['table'],
262
                            'column'  => Decorator::field('attname'),
263
                        ],
264
                    ],
265
                ],
266
            ],
267
            'drop'       => [
268
                'content' => $lang['strdrop'],
269
                'attr'    => [
270
                    'href' => [
271
                        'url'     => 'tblproperties.php',
272
                        'urlvars' => [
273
                            'subject' => 'column',
274
                            'action'  => 'confirm_drop',
275
                            'table'   => $_REQUEST['table'],
276
                            'column'  => Decorator::field('attname'),
277
                        ],
278
                    ],
279
                ],
280
            ],
281
        ];
282
283
        echo $this->printTable($attrs, $columns, $actions, 'tblproperties-tblproperties', null, $attPre);
284
285
        $navlinks = [
286
            'browse'    => [
287
                'attr'    => [
288
                    'href' => [
289
                        'url'     => 'display.php',
290
                        'urlvars' => [
291
                            'server'   => $_REQUEST['server'],
292
                            'database' => $_REQUEST['database'],
293
                            'schema'   => $_REQUEST['schema'],
294
                            'table'    => $_REQUEST['table'],
295
                            'subject'  => 'table',
296
                            'return'   => 'table',
297
                        ],
298
                    ],
299
                ],
300
                'content' => $lang['strbrowse'],
301
            ],
302
            'select'    => [
303
                'attr'    => [
304
                    'href' => [
305
                        'url'     => 'tables.php',
306
                        'urlvars' => [
307
                            'action'   => 'confselectrows',
308
                            'server'   => $_REQUEST['server'],
309
                            'database' => $_REQUEST['database'],
310
                            'schema'   => $_REQUEST['schema'],
311
                            'table'    => $_REQUEST['table'],
312
                        ],
313
                    ],
314
                ],
315
                'content' => $lang['strselect'],
316
            ],
317
            'insert'    => [
318
                'attr'    => [
319
                    'href' => [
320
                        'url'     => 'tables.php',
321
                        'urlvars' => [
322
                            'action'   => 'confinsertrow',
323
                            'server'   => $_REQUEST['server'],
324
                            'database' => $_REQUEST['database'],
325
                            'schema'   => $_REQUEST['schema'],
326
                            'table'    => $_REQUEST['table'],
327
                        ],
328
                    ],
329
                ],
330
                'content' => $lang['strinsert'],
331
            ],
332
            'empty'     => [
333
                'attr'    => [
334
                    'href' => [
335
                        'url'     => 'tables.php',
336
                        'urlvars' => [
337
                            'action'   => 'confirm_empty',
338
                            'server'   => $_REQUEST['server'],
339
                            'database' => $_REQUEST['database'],
340
                            'schema'   => $_REQUEST['schema'],
341
                            'table'    => $_REQUEST['table'],
342
                        ],
343
                    ],
344
                ],
345
                'content' => $lang['strempty'],
346
            ],
347
            'drop'      => [
348
                'attr'    => [
349
                    'href' => [
350
                        'url'     => 'tables.php',
351
                        'urlvars' => [
352
                            'action'   => 'confirm_drop',
353
                            'server'   => $_REQUEST['server'],
354
                            'database' => $_REQUEST['database'],
355
                            'schema'   => $_REQUEST['schema'],
356
                            'table'    => $_REQUEST['table'],
357
                        ],
358
                    ],
359
                ],
360
                'content' => $lang['strdrop'],
361
            ],
362
            'addcolumn' => [
363
                'attr'    => [
364
                    'href' => [
365
                        'url'     => 'tblproperties.php',
366
                        'urlvars' => [
367
                            'action'   => 'add_column',
368
                            'server'   => $_REQUEST['server'],
369
                            'database' => $_REQUEST['database'],
370
                            'schema'   => $_REQUEST['schema'],
371
                            'table'    => $_REQUEST['table'],
372
                        ],
373
                    ],
374
                ],
375
                'content' => $lang['straddcolumn'],
376
            ],
377
            'alter'     => [
378
                'attr'    => [
379
                    'href' => [
380
                        'url'     => 'tblproperties.php',
381
                        'urlvars' => [
382
                            'action'   => 'confirm_alter',
383
                            'server'   => $_REQUEST['server'],
384
                            'database' => $_REQUEST['database'],
385
                            'schema'   => $_REQUEST['schema'],
386
                            'table'    => $_REQUEST['table'],
387
                        ],
388
                    ],
389
                ],
390
                'content' => $lang['stralter'],
391
            ],
392
        ];
393
        $this->printNavLinks($navlinks, 'tblproperties-tblproperties', get_defined_vars());
394
    }
395
396
    public function doTree()
0 ignored issues
show
Coding Style introduced by
doTree uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
397
    {
398
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
399
        $misc = $this->misc;
400
        $lang = $this->lang;
0 ignored issues
show
Unused Code introduced by
The assignment to $lang is dead and can be removed.
Loading history...
401
        $data = $misc->getDatabaseAccessor();
402
403
        $columns = $data->getTableAttributes($_REQUEST['table']);
404
        $reqvars = $misc->getRequestVars('column');
405
406
        $attrs = [
407
            'text'       => Decorator::field('attname'),
408
            'action'     => Decorator::actionurl('colproperties.php',
409
                $reqvars,
410
                [
411
                    'table'  => $_REQUEST['table'],
412
                    'column' => Decorator::field('attname'),
413
                ]
414
            ),
415
            'icon'       => 'Column',
416
            'iconAction' => Decorator::url('display.php',
417
                $reqvars,
418
                [
419
                    'table'  => $_REQUEST['table'],
420
                    'column' => Decorator::field('attname'),
421
                    'query'  => Decorator::replace(
422
                        'SELECT "%column%", count(*) AS "count" FROM "%table%" GROUP BY "%column%" ORDER BY "%column%"',
423
                        [
424
                            '%column%' => Decorator::field('attname'),
425
                            '%table%'  => $_REQUEST['table'],
426
                        ]
427
                    ),
428
                ]
429
            ),
430
            'toolTip'    => Decorator::field('comment'),
431
        ];
432
433
        return $this->printTree($columns, $attrs, 'tblcolumns');
434
    }
435
436
    public function doSaveAlter()
0 ignored issues
show
Coding Style introduced by
doSaveAlter uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
doSaveAlter uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
437
    {
438
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
439
        $misc = $this->misc;
440
        $lang = $this->lang;
441
        $data = $misc->getDatabaseAccessor();
442
443
        // For databases that don't allow owner change
444
        if (!isset($_POST['owner'])) {
445
            $_POST['owner'] = '';
446
        }
447
448
        // Default tablespace to null if it isn't set
449
        if (!isset($_POST['tablespace'])) {
450
            $_POST['tablespace'] = null;
451
        }
452
453
        if (!isset($_POST['newschema'])) {
454
            $_POST['newschema'] = null;
455
        }
456
457
        $status = $data->alterTable($_POST['table'], $_POST['name'], $_POST['owner'], $_POST['newschema'], $_POST['comment'], $_POST['tablespace']);
458
        if ($status == 0) {
459
            // If table has been renamed, need to change to the new name and
460
            // reload the browser frame.
461
            if ($_POST['table'] != $_POST['name']) {
462
                // Jump them to the new table name
463
                $_REQUEST['table'] = $_POST['name'];
464
                // Force a browser reload
465
                $misc->setReloadBrowser(true);
466
            }
467
            // If schema has changed, need to change to the new schema and reload the browser
468
            if (!empty($_POST['newschema']) && ($_POST['newschema'] != $data->_schema)) {
469
                // Jump them to the new sequence schema
470
                $misc->setCurrentSchema($_POST['newschema']);
471
                $misc->setReloadBrowser(true);
472
            }
473
            $this->doDefault($lang['strtablealtered']);
474
        } else {
475
            $this->doAlter($lang['strtablealteredbad']);
476
        }
477
    }
478
479
    /**
480
     * Function to allow altering of a table
481
     */
482
    public function doAlter($msg = '')
0 ignored issues
show
Coding Style introduced by
doAlter uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
doAlter uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
483
    {
484
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
485
        $misc = $this->misc;
486
        $lang = $this->lang;
487
        $data = $misc->getDatabaseAccessor();
488
489
        $this->printTrail('table');
490
        $this->printTitle($lang['stralter'], 'pg.table.alter');
491
        $this->printMsg($msg);
492
493
        // Fetch table info
494
        $table = $data->getTable($_REQUEST['table']);
495
        // Fetch all users
496
        $users = $data->getUsers();
497
        // Fetch all tablespaces from the database
498
        if ($data->hasTablespaces()) {
499
            $tablespaces = $data->getTablespaces(true);
500
        }
501
502
        if ($table->recordCount() > 0) {
503
            if (!isset($_POST['name'])) {
504
                $_POST['name'] = $table->fields['relname'];
505
            }
506
507
            if (!isset($_POST['owner'])) {
508
                $_POST['owner'] = $table->fields['relowner'];
509
            }
510
511
            if (!isset($_POST['newschema'])) {
512
                $_POST['newschema'] = $table->fields['nspname'];
513
            }
514
515
            if (!isset($_POST['comment'])) {
516
                $_POST['comment'] = $table->fields['relcomment'];
517
            }
518
519
            if ($data->hasTablespaces() && !isset($_POST['tablespace'])) {
520
                $_POST['tablespace'] = $table->fields['tablespace'];
521
            }
522
523
            echo '<form action="' . SUBFOLDER . "/src/views/tblproperties.php\" method=\"post\">\n";
524
            echo "<table>\n";
525
            echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n";
526
            echo '<td class="data1">';
527
            echo "<input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
528
            htmlspecialchars($_POST['name'], ENT_QUOTES), "\" /></td></tr>\n";
529
530 View Code Duplication
            if ($data->isSuperUser()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
531
                echo "<tr><th class=\"data left required\">{$lang['strowner']}</th>\n";
532
                echo '<td class="data1"><select name="owner">';
533
                while (!$users->EOF) {
534
                    $uname = $users->fields['usename'];
535
                    echo '<option value="', htmlspecialchars($uname), '"',
536
                    ($uname == $_POST['owner']) ? ' selected="selected"' : '', '>', htmlspecialchars($uname), "</option>\n";
537
                    $users->moveNext();
538
                }
539
                echo "</select></td></tr>\n";
540
            }
541
542
            if ($data->hasAlterTableSchema()) {
543
                $schemas = $data->getSchemas();
544
                echo "<tr><th class=\"data left required\">{$lang['strschema']}</th>\n";
545
                echo '<td class="data1"><select name="newschema">';
546
                while (!$schemas->EOF) {
547
                    $schema = $schemas->fields['nspname'];
548
                    echo '<option value="', htmlspecialchars($schema), '"',
549
                    ($schema == $_POST['newschema']) ? ' selected="selected"' : '', '>', htmlspecialchars($schema), "</option>\n";
550
                    $schemas->moveNext();
551
                }
552
                echo "</select></td></tr>\n";
553
            }
554
555
            // Tablespace (if there are any)
556 View Code Duplication
            if ($data->hasTablespaces() && $tablespaces->recordCount() > 0) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $tablespaces does not seem to be defined for all execution paths leading up to this point.
Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
557
                echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strtablespace']}</th>\n";
558
                echo "\t\t<td class=\"data1\">\n\t\t\t<select name=\"tablespace\">\n";
559
                // Always offer the default (empty) option
560
                echo "\t\t\t\t<option value=\"\"",
561
                ($_POST['tablespace'] == '') ? ' selected="selected"' : '', "></option>\n";
562
                // Display all other tablespaces
563
                while (!$tablespaces->EOF) {
564
                    $spcname = htmlspecialchars($tablespaces->fields['spcname']);
565
                    echo "\t\t\t\t<option value=\"{$spcname}\"",
566
                    ($spcname == $_POST['tablespace']) ? ' selected="selected"' : '', ">{$spcname}</option>\n";
567
                    $tablespaces->moveNext();
568
                }
569
                echo "\t\t\t</select>\n\t\t</td>\n\t</tr>\n";
570
            }
571
572
            echo "<tr><th class=\"data left\">{$lang['strcomment']}</th>\n";
573
            echo '<td class="data1">';
574
            echo '<textarea rows="3" cols="32" name="comment">',
575
            htmlspecialchars($_POST['comment']), "</textarea></td></tr>\n";
576
            echo "</table>\n";
577
            echo "<p><input type=\"hidden\" name=\"action\" value=\"alter\" />\n";
578
            echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), "\" />\n";
579
            echo $misc->form;
580
            echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n";
581
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
582
            echo "</form>\n";
583
        } else {
584
            echo "<p>{$lang['strnodata']}</p>\n";
585
        }
586
    }
587
588
    public function doExport($msg = '')
0 ignored issues
show
Coding Style introduced by
doExport uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
589
    {
590
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
591
        $misc = $this->misc;
592
        $lang = $this->lang;
593
        $data = $misc->getDatabaseAccessor();
594
595
        // Determine whether or not the table has an object ID
596
        $hasID = $data->hasObjectID($_REQUEST['table']);
597
598
        $this->printTrail('table');
599
        $this->printTabs('table', 'export');
600
        $this->printMsg($msg);
601
602
        echo '<form action="' . SUBFOLDER . "/src/views/dataexport.php\" method=\"post\">\n";
603
        echo "<table>\n";
604
        echo "<tr><th class=\"data\">{$lang['strformat']}</th><th class=\"data\" colspan=\"2\">{$lang['stroptions']}</th></tr>\n";
605
        // Data only
606
        echo '<tr><th class="data left" rowspan="', ($hasID) ? 2 : 1, '">';
607
        echo "<input type=\"radio\" id=\"what1\" name=\"what\" value=\"dataonly\" checked=\"checked\" /><label for=\"what1\">{$lang['strdataonly']}</label></th>\n";
608
        echo "<td>{$lang['strformat']}</td>\n";
609
        echo "<td><select name=\"d_format\">\n";
610
        echo "<option value=\"copy\">COPY</option>\n";
611
        echo "<option value=\"sql\">SQL</option>\n";
612
        echo "<option value=\"csv\">CSV</option>\n";
613
        echo "<option value=\"tab\">{$lang['strtabbed']}</option>\n";
614
        echo "<option value=\"html\">XHTML</option>\n";
615
        echo "<option value=\"xml\">XML</option>\n";
616
        echo "</select>\n</td>\n</tr>\n";
617
        if ($hasID) {
618
            echo "<tr><td><label for=\"d_oids\">{$lang['stroids']}</td><td><input type=\"checkbox\" id=\"d_oids\" name=\"d_oids\" /></td>\n</tr>\n";
619
        }
620
        // Structure only
621
        echo "<tr><th class=\"data left\"><input type=\"radio\" id=\"what2\" name=\"what\" value=\"structureonly\" /><label for=\"what2\">{$lang['strstructureonly']}</label></th>\n";
622
        echo "<td><label for=\"s_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"s_clean\" name=\"s_clean\" /></td>\n</tr>\n";
623
        // Structure and data
624
        echo '<tr><th class="data left" rowspan="', ($hasID) ? 3 : 2, '">';
625
        echo "<input type=\"radio\" id=\"what3\" name=\"what\" value=\"structureanddata\" /><label for=\"what3\">{$lang['strstructureanddata']}</label></th>\n";
626
        echo "<td>{$lang['strformat']}</td>\n";
627
        echo "<td><select name=\"sd_format\">\n";
628
        echo "<option value=\"copy\">COPY</option>\n";
629
        echo "<option value=\"sql\">SQL</option>\n";
630
        echo "</select>\n</td>\n</tr>\n";
631
        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";
632
        if ($hasID) {
633
            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";
634
        }
635
        echo "</table>\n";
636
637
        echo "<h3>{$lang['stroptions']}</h3>\n";
638
        echo "<p><input type=\"radio\" id=\"output1\" name=\"output\" value=\"show\" checked=\"checked\" /><label for=\"output1\">{$lang['strshow']}</label>\n";
639
        echo "<br/><input type=\"radio\" id=\"output2\" name=\"output\" value=\"download\" /><label for=\"output2\">{$lang['strdownload']}</label></p>\n";
640
641
        echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n";
642
        echo $misc->form;
643
        echo "<input type=\"hidden\" name=\"subject\" value=\"table\" />\n";
644
        echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), "\" />\n";
645
        echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n";
646
        echo "</form>\n";
647
    }
648
649
    public function doImport($msg = '')
0 ignored issues
show
Coding Style introduced by
doImport uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
650
    {
651
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
652
        $misc = $this->misc;
653
        $lang = $this->lang;
654
        $data = $misc->getDatabaseAccessor();
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
655
656
        $this->printTrail('table');
657
        $this->printTabs('table', 'import');
658
        $this->printMsg($msg);
659
660
        // Check that file uploads are enabled
661
        if (ini_get('file_uploads')) {
662
            // Don't show upload option if max size of uploads is zero
663
            $max_size = $misc->inisizeToBytes(ini_get('upload_max_filesize'));
664
            if (is_double($max_size) && $max_size > 0) {
665
                echo '<form action="' . SUBFOLDER . "/src/views/dataimport.php\" method=\"post\" enctype=\"multipart/form-data\">\n";
666
                echo "<table>\n";
667
                echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strformat']}</th>\n";
668
                echo "\t\t<td><select name=\"format\">\n";
669
                echo "\t\t\t<option value=\"auto\">{$lang['strauto']}</option>\n";
670
                echo "\t\t\t<option value=\"csv\">CSV</option>\n";
671
                echo "\t\t\t<option value=\"tab\">{$lang['strtabbed']}</option>\n";
672
                if (function_exists('xml_parser_create')) {
673
                    echo "\t\t\t<option value=\"xml\">XML</option>\n";
674
                }
675
                echo "\t\t</select></td>\n\t</tr>\n";
676
                echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strallowednulls']}</th>\n";
677
                echo "\t\t<td><label><input type=\"checkbox\" name=\"allowednulls[0]\" value=\"\\N\" checked=\"checked\" />{$lang['strbackslashn']}</label><br />\n";
678
                echo "\t\t<label><input type=\"checkbox\" name=\"allowednulls[1]\" value=\"NULL\" />NULL</label><br />\n";
679
                echo "\t\t<label><input type=\"checkbox\" name=\"allowednulls[2]\" value=\"\" />{$lang['stremptystring']}</label></td>\n\t</tr>\n";
680
                echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strfile']}</th>\n";
681
                echo "\t\t<td><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"{$max_size}\" />";
682
                echo "<input type=\"file\" name=\"source\" /></td>\n\t</tr>\n";
683
                echo "</table>\n";
684
                echo "<p><input type=\"hidden\" name=\"action\" value=\"import\" />\n";
685
                echo $misc->form;
686
                echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), "\" />\n";
687
                echo "<input type=\"submit\" value=\"{$lang['strimport']}\" /></p>\n";
688
                echo "</form>\n";
689
            }
690
        } else {
691
            echo "<p>{$lang['strnouploads']}</p>\n";
692
        }
693
    }
694
695
    /**
696
     * Displays a screen where they can add a column
697
     */
698
    public function doAddColumn($msg = '')
0 ignored issues
show
Coding Style introduced by
doAddColumn uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
doAddColumn uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
699
    {
700
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
701
        $misc = $this->misc;
702
        $lang = $this->lang;
703
        $data = $misc->getDatabaseAccessor();
704
705
        if (!isset($_REQUEST['stage'])) {
706
            $_REQUEST['stage'] = 1;
707
        }
708
709
        switch ($_REQUEST['stage']) {
710
            case 1:
711
                // Set variable defaults
712
                if (!isset($_POST['field'])) {
713
                    $_POST['field'] = '';
714
                }
715
716
                if (!isset($_POST['type'])) {
717
                    $_POST['type'] = '';
718
                }
719
720
                if (!isset($_POST['array'])) {
721
                    $_POST['array'] = '';
722
                }
723
724
                if (!isset($_POST['length'])) {
725
                    $_POST['length'] = '';
726
                }
727
728
                if (!isset($_POST['default'])) {
729
                    $_POST['default'] = '';
730
                }
731
732
                if (!isset($_POST['comment'])) {
733
                    $_POST['comment'] = '';
734
                }
735
736
                // Fetch all available types
737
                $types        = $data->getTypes(true, false, true);
738
                $types_for_js = [];
739
740
                $this->printTrail('table');
741
                $this->printTitle($lang['straddcolumn'], 'pg.column.add');
742
                $this->printMsg($msg);
743
744
                echo '<script src="' . SUBFOLDER . '/js/tables.js" type="text/javascript"></script>';
745
                echo '<form action="' . SUBFOLDER . "/src/views/tblproperties.php\" method=\"post\">\n";
746
747
                // Output table header
748
                echo "<table>\n";
749
                echo "<tr><th class=\"data required\">{$lang['strname']}</th>\n<th colspan=\"2\" class=\"data required\">{$lang['strtype']}</th>\n";
750
                echo "<th class=\"data\">{$lang['strlength']}</th>\n";
751
                if ($data->hasCreateFieldWithConstraints()) {
752
                    echo "<th class=\"data\">{$lang['strnotnull']}</th>\n<th class=\"data\">{$lang['strdefault']}</th>\n";
753
                }
754
755
                echo "<th class=\"data\">{$lang['strcomment']}</th></tr>\n";
756
757
                echo "<tr><td><input name=\"field\" size=\"16\" maxlength=\"{$data->_maxNameLen}\" value=\"",
758
                htmlspecialchars($_POST['field']), "\" /></td>\n";
759
                echo "<td><select  class=\"select2\" name=\"type\" id=\"type\" onchange=\"checkLengths(document.getElementById('type').value,'');\">\n";
760
                // Output any "magic" types.  This came in with the alter column type so we'll check that
761
                if ($data->hasMagicTypes()) {
762
                    foreach ($data->extraTypes as $v) {
763
                        $types_for_js[] = strtolower($v);
764
                        echo "\t<option value=\"", htmlspecialchars($v), '"',
765
                        ($v == $_POST['type']) ? ' selected="selected"' : '', '>',
766
                        $misc->printVal($v), "</option>\n";
767
                    }
768
                }
769
                while (!$types->EOF) {
770
                    $typname        = $types->fields['typname'];
771
                    $types_for_js[] = $typname;
772
                    echo "\t<option value=\"", htmlspecialchars($typname), '"', ($typname == $_POST['type']) ? ' selected="selected"' : '', '>',
773
                    $misc->printVal($typname), "</option>\n";
774
                    $types->moveNext();
775
                }
776
                echo "</select></td>\n";
777
778
                // Output array type selector
779
                echo "<td><select name=\"array\">\n";
780
                echo "\t<option value=\"\"", ($_POST['array'] == '') ? ' selected="selected"' : '', "></option>\n";
781
                echo "\t<option value=\"[]\"", ($_POST['array'] == '[]') ? ' selected="selected"' : '', ">[ ]</option>\n";
782
                echo "</select></td>\n";
783
                $predefined_size_types = array_intersect($data->predefined_size_types, $types_for_js);
784
                $escaped_predef_types  = []; // the JS escaped array elements
785
                foreach ($predefined_size_types as $value) {
786
                    $escaped_predef_types[] = "'{$value}'";
787
                }
788
789
                echo '<td><input name="length" id="lengths" size="8" value="',
790
                htmlspecialchars($_POST['length']), "\" /></td>\n";
791
                // Support for adding column with not null and default
792
                if ($data->hasCreateFieldWithConstraints()) {
793
                    echo '<td><input type="checkbox" name="notnull"',
794
                    (isset($_REQUEST['notnull'])) ? ' checked="checked"' : '', " /></td>\n";
795
                    echo '<td><input name="default" size="20" value="',
796
                    htmlspecialchars($_POST['default']), "\" /></td>\n";
797
                }
798
                echo '<td><input name="comment" size="40" value="',
799
                htmlspecialchars($_POST['comment']), "\" /></td></tr>\n";
800
                echo "</table>\n";
801
                echo "<p><input type=\"hidden\" name=\"action\" value=\"add_column\" />\n";
802
                echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n";
803
                echo $misc->form;
804
                echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), "\" />\n";
805
                if (!$data->hasCreateFieldWithConstraints()) {
806
                    echo "<input type=\"hidden\" name=\"default\" value=\"\" />\n";
807
                }
808
                echo "<input type=\"submit\" value=\"{$lang['stradd']}\" />\n";
809
                echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
810
                echo "</form>\n";
811
                echo '<script type="text/javascript">predefined_lengths = new Array(' . implode(',', $escaped_predef_types) . ");checkLengths(document.getElementById('type').value,'');</script>\n";
812
                break;
813
            case 2:
814
                // Check inputs
815
                if (trim($_POST['field']) == '') {
816
                    $_REQUEST['stage'] = 1;
817
                    $this->doAddColumn($lang['strcolneedsname']);
818
                    return;
819
                }
820
                if (!isset($_POST['length'])) {
821
                    $_POST['length'] = '';
822
                }
823
824
                $status = $data->addColumn($_POST['table'], $_POST['field'],
825
                    $_POST['type'], $_POST['array'] != '', $_POST['length'], isset($_POST['notnull']),
826
                    $_POST['default'], $_POST['comment']);
827
                if ($status == 0) {
828
                    $misc->setReloadBrowser(true);
829
                    $this->doDefault($lang['strcolumnadded']);
830
                } else {
831
                    $_REQUEST['stage'] = 1;
832
                    $this->doAddColumn($lang['strcolumnaddedbad']);
833
                    return;
834
                }
835
                break;
836
            default:
837
                echo "<p>{$lang['strinvalidparam']}</p>\n";
838
        }
839
    }
840
841
    /**
842
     * Show confirmation of drop column and perform actual drop
843
     */
844 View Code Duplication
    public function doDrop($confirm)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
doDrop uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
doDrop uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
845
    {
846
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
847
        $misc = $this->misc;
848
        $lang = $this->lang;
849
        $data = $misc->getDatabaseAccessor();
850
851
        if ($confirm) {
852
            $this->printTrail('column');
853
            $this->printTitle($lang['strdrop'], 'pg.column.drop');
854
855
            echo '<p>', sprintf($lang['strconfdropcolumn'], $misc->printVal($_REQUEST['column']),
856
                $misc->printVal($_REQUEST['table'])), "</p>\n";
857
858
            echo '<form action="' . SUBFOLDER . "/src/views/tblproperties.php\" method=\"post\">\n";
859
            echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
860
            echo '<input type="hidden" name="table" value="', htmlspecialchars($_REQUEST['table']), "\" />\n";
861
            echo '<input type="hidden" name="column" value="', htmlspecialchars($_REQUEST['column']), "\" />\n";
862
            echo $misc->form;
863
            echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\"> <label for=\"cascade\">{$lang['strcascade']}</label></p>\n";
864
            echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
865
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
866
            echo "</form>\n";
867
        } else {
868
            $status = $data->dropColumn($_POST['table'], $_POST['column'], isset($_POST['cascade']));
869
            if ($status == 0) {
870
                $misc->setReloadBrowser(true);
871
                $this->doDefault($lang['strcolumndropped']);
872
            } else {
873
                $this->doDefault($lang['strcolumndroppedbad']);
874
            }
875
        }
876
    }
877
}
878