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

SequencesController::doDefault()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 95
Code Lines 63

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 63
nc 1
nop 1
dl 0
loc 95
rs 8.4117
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 SequencesController extends BaseController
15
{
16
    public $controller_name = 'SequencesController';
17
18
    /**
19
     * Default method to render the controller according to the action parameter.
20
     */
21
    public function render()
22
    {
23
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
24
25
        $lang = $this->lang;
26
27
        $action = $this->action;
28
        if ('tree' == $action) {
29
            return $this->doTree();
30
        }
31
32
        // Print header
33
        $this->printHeader($lang['strsequences']);
34
        $this->printBody();
35
36
        switch ($action) {
37
            case 'create':
38
                $this->doCreateSequence();
39
40
                break;
41
            case 'save_create_sequence':
42
                if (isset($_POST['create'])) {
43
                    $this->doSaveCreateSequence();
44
                } else {
45
                    $this->doDefault();
46
                }
47
48
                break;
49
            case 'properties':
50
                $this->doProperties();
51
52
                break;
53
            case 'drop':
54
                if (isset($_POST['drop'])) {
55
                    $this->doDrop(false);
56
                } else {
57
                    $this->doDefault();
58
                }
59
60
                break;
61
            case 'confirm_drop':
62
                $this->doDrop(true);
63
64
                break;
65
            case 'restart':
66
                $this->doRestart();
67
68
                break;
69
            case 'reset':
70
                $this->doReset();
71
72
                break;
73
            case 'nextval':
74
                $this->doNextval();
75
76
                break;
77
            case 'setval':
78
                if (isset($_POST['setval'])) {
79
                    $this->doSaveSetval();
80
                } else {
81
                    $this->doDefault();
82
                }
83
84
                break;
85
            case 'confirm_setval':
86
                $this->doSetval();
87
88
                break;
89
            case 'alter':
90
                if (isset($_POST['alter'])) {
91
                    $this->doSaveAlter();
92
                } else {
93
                    $this->doDefault();
94
                }
95
96
                break;
97
            case 'confirm_alter':
98
                $this->doAlter();
99
100
                break;
101
            default:
102
                $this->doDefault();
103
104
                break;
105
        }
106
107
        // Print footer
108
        return $this->printFooter();
109
    }
110
111
    /**
112
     * Display list of all sequences in the database/schema.
113
     *
114
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
115
     */
116
    public function doDefault($msg = '')
117
    {
118
        $conf = $this->conf;
119
120
        $lang = $this->lang;
121
        $data = $this->misc->getDatabaseAccessor();
122
123
        $this->printTrail('schema');
124
        $this->printTabs('schema', 'sequences');
125
        $this->printMsg($msg);
126
127
        // Get all sequences
128
        $sequences = $data->getSequences();
129
130
        $columns = [
131
            'sequence' => [
132
                'title' => $lang['strsequence'],
133
                'field' => Decorator::field('seqname'),
134
                'url'   => "sequences.php?action=properties&amp;{$this->misc->href}&amp;",
135
                'vars'  => ['sequence' => 'seqname'],
136
            ],
137
            'owner' => [
138
                'title' => $lang['strowner'],
139
                'field' => Decorator::field('seqowner'),
140
            ],
141
            'actions' => [
142
                'title' => $lang['stractions'],
143
            ],
144
            'comment' => [
145
                'title' => $lang['strcomment'],
146
                'field' => Decorator::field('seqcomment'),
147
            ],
148
        ];
149
150
        $actions = [
151
            'multiactions' => [
152
                'keycols' => ['sequence' => 'seqname'],
153
                'url'     => 'sequences.php',
154
            ],
155
            'alter' => [
156
                'content' => $lang['stralter'],
157
                'attr'    => [
158
                    'href' => [
159
                        'url'     => 'sequences.php',
160
                        'urlvars' => [
161
                            'action'   => 'confirm_alter',
162
                            'subject'  => 'sequence',
163
                            'sequence' => Decorator::field('seqname'),
164
                        ],
165
                    ],
166
                ],
167
            ],
168
            'drop' => [
169
                'content' => $lang['strdrop'],
170
                'attr'    => [
171
                    'href' => [
172
                        'url'     => 'sequences.php',
173
                        'urlvars' => [
174
                            'action'   => 'confirm_drop',
175
                            'sequence' => Decorator::field('seqname'),
176
                        ],
177
                    ],
178
                ],
179
                'multiaction' => 'confirm_drop',
180
            ],
181
            'privileges' => [
182
                'content' => $lang['strprivileges'],
183
                'attr'    => [
184
                    'href' => [
185
                        'url'     => 'privileges.php',
186
                        'urlvars' => [
187
                            'subject'  => 'sequence',
188
                            'sequence' => Decorator::field('seqname'),
189
                        ],
190
                    ],
191
                ],
192
            ],
193
        ];
194
195
        echo $this->printTable($sequences, $columns, $actions, 'sequences-sequences', $lang['strnosequences']);
196
197
        $this->printNavLinks(['create' => [
1 ignored issue
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
198
            'attr' => [
199
                'href' => [
200
                    'url'     => 'sequences.php',
201
                    'urlvars' => [
202
                        'action'   => 'create',
203
                        'server'   => $_REQUEST['server'],
204
                        'database' => $_REQUEST['database'],
205
                        'schema'   => $_REQUEST['schema'],
206
                    ],
207
                ],
208
            ],
209
            'content' => $lang['strcreatesequence'],
210
        ]], 'sequences-sequences', get_defined_vars());
1 ignored issue
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
211
    }
212
213
    /**
214
     * Generate XML for the browser tree.
215
     */
216
    public function doTree()
217
    {
218
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
219
220
        $lang = $this->lang;
0 ignored issues
show
Unused Code introduced by
The assignment to $lang is dead and can be removed.
Loading history...
221
        $data = $this->misc->getDatabaseAccessor();
222
223
        $sequences = $data->getSequences();
224
225
        $reqvars = $this->misc->getRequestVars('sequence');
226
227
        $attrs = [
228
            'text'    => Decorator::field('seqname'),
229
            'icon'    => 'Sequence',
230
            'toolTip' => Decorator::field('seqcomment'),
231
            'action'  => Decorator::actionurl(
232
                'sequences.php',
233
                $reqvars,
234
                [
235
                    'action'   => 'properties',
236
                    'sequence' => Decorator::field('seqname'),
237
                ]
238
            ),
239
        ];
240
241
        return $this->printTree($sequences, $attrs, 'sequences');
242
    }
243
244
    /**
245
     * Display the properties of a sequence.
246
     *
247
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
248
     */
249
    public function doProperties($msg = '')
250
    {
251
        $conf = $this->conf;
252
253
        $lang = $this->lang;
254
        $data = $this->misc->getDatabaseAccessor();
255
        $this->printTrail('sequence');
256
        $this->printTitle($lang['strproperties'], 'pg.sequence');
257
        $this->printMsg($msg);
258
259
        // Fetch the sequence information
260
        $sequence = $data->getSequence($_REQUEST['sequence']);
261
262
        if (is_object($sequence) && $sequence->recordCount() > 0) {
263
            $sequence->fields['is_cycled'] = $data->phpBool($sequence->fields['is_cycled']);
264
            $sequence->fields['is_called'] = $data->phpBool($sequence->fields['is_called']);
265
266
            // Show comment if any
267
            if (null !== $sequence->fields['seqcomment']) {
268
                echo '<p class="comment">', $this->misc->printVal($sequence->fields['seqcomment']), "</p>\n";
269
            }
270
271
            echo '<table border="0">';
272
            echo "<tr><th class=\"data\">{$lang['strname']}</th>";
273
            if ($data->hasAlterSequenceStart()) {
274
                echo "<th class=\"data\">{$lang['strstartvalue']}</th>";
275
            }
276
            echo "<th class=\"data\">{$lang['strlastvalue']}</th>";
277
            echo "<th class=\"data\">{$lang['strincrementby']}</th>";
278
            echo "<th class=\"data\">{$lang['strmaxvalue']}</th>";
279
            echo "<th class=\"data\">{$lang['strminvalue']}</th>";
280
            echo "<th class=\"data\">{$lang['strcachevalue']}</th>";
281
            echo "<th class=\"data\">{$lang['strlogcount']}</th>";
282
            echo "<th class=\"data\">{$lang['strcancycle']}</th>";
283
            echo "<th class=\"data\">{$lang['striscalled']}</th></tr>";
284
            echo '<tr>';
285
            echo '<td class="data1">', $this->misc->printVal($sequence->fields['seqname']), '</td>';
286
            if ($data->hasAlterSequenceStart()) {
287
                echo '<td class="data1">', $this->misc->printVal($sequence->fields['start_value']), '</td>';
288
            }
289
            echo '<td class="data1">', $this->misc->printVal($sequence->fields['last_value']), '</td>';
290
            echo '<td class="data1">', $this->misc->printVal($sequence->fields['increment_by']), '</td>';
291
            echo '<td class="data1">', $this->misc->printVal($sequence->fields['max_value']), '</td>';
292
            echo '<td class="data1">', $this->misc->printVal($sequence->fields['min_value']), '</td>';
293
            echo '<td class="data1">', $this->misc->printVal($sequence->fields['cache_value']), '</td>';
294
            echo '<td class="data1">', $this->misc->printVal($sequence->fields['log_cnt']), '</td>';
295
            echo '<td class="data1">', ($sequence->fields['is_cycled'] ? $lang['stryes'] : $lang['strno']), '</td>';
296
            echo '<td class="data1">', ($sequence->fields['is_called'] ? $lang['stryes'] : $lang['strno']), '</td>';
297
            echo '</tr>';
298
            echo '</table>';
299
300
            $navlinks = [
301
                'alter' => [
302
                    'attr' => [
303
                        'href' => [
304
                            'url'     => 'sequences.php',
305
                            'urlvars' => [
306
                                'action'   => 'confirm_alter',
307
                                'server'   => $_REQUEST['server'],
308
                                'database' => $_REQUEST['database'],
309
                                'schema'   => $_REQUEST['schema'],
310
                                'sequence' => $sequence->fields['seqname'],
311
                            ],
312
                        ],
313
                    ],
314
                    'content' => $lang['stralter'],
315
                ],
316
                'setval' => [
317
                    'attr' => [
318
                        'href' => [
319
                            'url'     => 'sequences.php',
320
                            'urlvars' => [
321
                                'action'   => 'confirm_setval',
322
                                'server'   => $_REQUEST['server'],
323
                                'database' => $_REQUEST['database'],
324
                                'schema'   => $_REQUEST['schema'],
325
                                'sequence' => $sequence->fields['seqname'],
326
                            ],
327
                        ],
328
                    ],
329
                    'content' => $lang['strsetval'],
330
                ],
331
                'nextval' => [
332
                    'attr' => [
333
                        'href' => [
334
                            'url'     => 'sequences.php',
335
                            'urlvars' => [
336
                                'action'   => 'nextval',
337
                                'server'   => $_REQUEST['server'],
338
                                'database' => $_REQUEST['database'],
339
                                'schema'   => $_REQUEST['schema'],
340
                                'sequence' => $sequence->fields['seqname'],
341
                            ],
342
                        ],
343
                    ],
344
                    'content' => $lang['strnextval'],
345
                ],
346
                'restart' => [
347
                    'attr' => [
348
                        'href' => [
349
                            'url'     => 'sequences.php',
350
                            'urlvars' => [
351
                                'action'   => 'restart',
352
                                'server'   => $_REQUEST['server'],
353
                                'database' => $_REQUEST['database'],
354
                                'schema'   => $_REQUEST['schema'],
355
                                'sequence' => $sequence->fields['seqname'],
356
                            ],
357
                        ],
358
                    ],
359
                    'content' => $lang['strrestart'],
360
                ],
361
                'reset' => [
362
                    'attr' => [
363
                        'href' => [
364
                            'url'     => 'sequences.php',
365
                            'urlvars' => [
366
                                'action'   => 'reset',
367
                                'server'   => $_REQUEST['server'],
368
                                'database' => $_REQUEST['database'],
369
                                'schema'   => $_REQUEST['schema'],
370
                                'sequence' => $sequence->fields['seqname'],
371
                            ],
372
                        ],
373
                    ],
374
                    'content' => $lang['strreset'],
375
                ],
376
                'showall' => [
377
                    'attr' => [
378
                        'href' => [
379
                            'url'     => 'sequences.php',
380
                            'urlvars' => [
381
                                'server'   => $_REQUEST['server'],
382
                                'database' => $_REQUEST['database'],
383
                                'schema'   => $_REQUEST['schema'],
384
                            ],
385
                        ],
386
                    ],
387
                    'content' => $lang['strshowallsequences'],
388
                ],
389
            ];
390
391
            if (!$data->hasAlterSequenceStart()) {
392
                unset($navlinks['restart']);
393
            }
394
395
            $this->printNavLinks($navlinks, 'sequences-properties', get_defined_vars());
396
        } else {
397
            echo "<p>{$lang['strnodata']}</p>\n";
398
        }
399
    }
400
401
    /**
402
     * Drop a sequence.
403
     *
404
     * @param mixed $confirm
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
405
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
406
     */
407
    public function doDrop($confirm, $msg = '')
408
    {
409
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
410
411
        $lang = $this->lang;
412
        $data = $this->misc->getDatabaseAccessor();
413
414
        if (empty($_REQUEST['sequence']) && empty($_REQUEST['ma'])) {
415
            return $this->doDefault($lang['strspecifysequencetodrop']);
416
        }
417
418
        if ($confirm) {
419
            $this->printTrail('sequence');
420
            $this->printTitle($lang['strdrop'], 'pg.sequence.drop');
421
            $this->printMsg($msg);
422
423
            echo '<form action="'.\SUBFOLDER."/src/views/sequences.php\" method=\"post\">\n";
424
425
            //If multi drop
426
            if (isset($_REQUEST['ma'])) {
427
                foreach ($_REQUEST['ma'] as $v) {
428
                    $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES));
429
                    echo '<p>', sprintf($lang['strconfdropsequence'], $this->misc->printVal($a['sequence'])), "</p>\n";
430
                    printf('<input type="hidden" name="sequence[]" value="%s" />', htmlspecialchars($a['sequence']));
431
                }
432
            } else {
433
                echo '<p>', sprintf($lang['strconfdropsequence'], $this->misc->printVal($_REQUEST['sequence'])), "</p>\n";
434
                echo '<input type="hidden" name="sequence" value="', htmlspecialchars($_REQUEST['sequence']), "\" />\n";
435
            }
436
437
            echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$lang['strcascade']}</label></p>\n";
438
            echo "<p><input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
439
            echo $this->misc->form;
440
            echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
441
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
442
            echo "</form>\n";
443
        } else {
444
            if (is_array($_POST['sequence'])) {
445
                $msg    = '';
446
                $status = $data->beginTransaction();
447
                if (0 == $status) {
448
                    foreach ($_POST['sequence'] as $s) {
449
                        $status = $data->dropSequence($s, isset($_POST['cascade']));
450
                        if (0 == $status) {
451
                            $msg .= sprintf('%s: %s<br />', htmlentities($s, ENT_QUOTES, 'UTF-8'), $lang['strsequencedropped']);
452
                        } else {
453
                            $data->endTransaction();
454
                            $this->doDefault(sprintf('%s%s: %s<br />', $msg, htmlentities($s, ENT_QUOTES, 'UTF-8'), $lang['strsequencedroppedbad']));
455
456
                            return;
457
                        }
458
                    }
459
                }
460
                if (0 == $data->endTransaction()) {
461
                    // Everything went fine, back to the Default page....
462
                    $this->misc->setReloadBrowser(true);
463
                    $this->doDefault($msg);
464
                } else {
465
                    $this->doDefault($lang['strsequencedroppedbad']);
466
                }
467
            } else {
468
                $status = $data->dropSequence($_POST['sequence'], isset($_POST['cascade']));
469
                if (0 == $status) {
470
                    $this->misc->setReloadBrowser(true);
471
                    $this->doDefault($lang['strsequencedropped']);
472
                } else {
473
                    $this->doDrop(true, $lang['strsequencedroppedbad']);
474
                }
475
            }
476
        }
477
    }
478
479
    /**
480
     * Displays a screen where they can enter a new sequence.
481
     *
482
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
483
     */
484
    public function doCreateSequence($msg = '')
485
    {
486
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
487
488
        $lang = $this->lang;
489
        $data = $this->misc->getDatabaseAccessor();
490
491
        if (!isset($_POST['formSequenceName'])) {
492
            $_POST['formSequenceName'] = '';
493
        }
494
495
        if (!isset($_POST['formIncrement'])) {
496
            $_POST['formIncrement'] = '';
497
        }
498
499
        if (!isset($_POST['formMinValue'])) {
500
            $_POST['formMinValue'] = '';
501
        }
502
503
        if (!isset($_POST['formMaxValue'])) {
504
            $_POST['formMaxValue'] = '';
505
        }
506
507
        if (!isset($_POST['formStartValue'])) {
508
            $_POST['formStartValue'] = '';
509
        }
510
511
        if (!isset($_POST['formCacheValue'])) {
512
            $_POST['formCacheValue'] = '';
513
        }
514
515
        $this->printTrail('schema');
516
        $this->printTitle($lang['strcreatesequence'], 'pg.sequence.create');
517
        $this->printMsg($msg);
518
519
        echo '<form action="'.\SUBFOLDER."/src/views/sequences.php\" method=\"post\">\n";
520
        echo "<table>\n";
521
522
        echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n";
523
        echo "<td class=\"data1\"><input name=\"formSequenceName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
524
        htmlspecialchars($_POST['formSequenceName']), "\" /></td></tr>\n";
525
526
        echo "<tr><th class=\"data left\">{$lang['strincrementby']}</th>\n";
527
        echo '<td class="data1"><input name="formIncrement" size="5" value="',
528
        htmlspecialchars($_POST['formIncrement']), "\" /> </td></tr>\n";
529
530
        echo "<tr><th class=\"data left\">{$lang['strminvalue']}</th>\n";
531
        echo '<td class="data1"><input name="formMinValue" size="5" value="',
532
        htmlspecialchars($_POST['formMinValue']), "\" /></td></tr>\n";
533
534
        echo "<tr><th class=\"data left\">{$lang['strmaxvalue']}</th>\n";
535
        echo '<td class="data1"><input name="formMaxValue" size="5" value="',
536
        htmlspecialchars($_POST['formMaxValue']), "\" /></td></tr>\n";
537
538
        echo "<tr><th class=\"data left\">{$lang['strstartvalue']}</th>\n";
539
        echo '<td class="data1"><input name="formStartValue" size="5" value="',
540
        htmlspecialchars($_POST['formStartValue']), "\" /></td></tr>\n";
541
542
        echo "<tr><th class=\"data left\">{$lang['strcachevalue']}</th>\n";
543
        echo '<td class="data1"><input name="formCacheValue" size="5" value="',
544
        htmlspecialchars($_POST['formCacheValue']), "\" /></td></tr>\n";
545
546
        echo "<tr><th class=\"data left\"><label for=\"formCycledValue\">{$lang['strcancycle']}</label></th>\n";
547
        echo '<td class="data1"><input type="checkbox" id="formCycledValue" name="formCycledValue" ',
548
        (isset($_POST['formCycledValue']) ? ' checked="checked"' : ''), " /></td></tr>\n";
549
550
        echo "</table>\n";
551
        echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create_sequence\" />\n";
552
        echo $this->misc->form;
553
        echo "<input type=\"submit\" name=\"create\" value=\"{$lang['strcreate']}\" />\n";
554
        echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
555
        echo "</form>\n";
556
    }
557
558
    /**
559
     * Actually creates the new sequence in the database.
560
     */
561
    public function doSaveCreateSequence()
562
    {
563
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
564
565
        $lang = $this->lang;
566
        $data = $this->misc->getDatabaseAccessor();
567
568
        // Check that they've given a name and at least one column
569
        if ('' == $_POST['formSequenceName']) {
570
            $this->doCreateSequence($lang['strsequenceneedsname']);
571
        } else {
572
            $status = $data->createSequence(
573
                $_POST['formSequenceName'],
574
                $_POST['formIncrement'],
575
                $_POST['formMinValue'],
576
                $_POST['formMaxValue'],
577
                $_POST['formStartValue'],
578
                $_POST['formCacheValue'],
579
                isset($_POST['formCycledValue'])
580
            );
581
            if (0 == $status) {
582
                $this->doDefault($lang['strsequencecreated']);
583
            } else {
584
                $this->doCreateSequence($lang['strsequencecreatedbad']);
585
            }
586
        }
587
    }
588
589
    /**
590
     * Restarts a sequence.
591
     */
592
    public function doRestart()
593
    {
594
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
595
596
        $lang = $this->lang;
597
        $data = $this->misc->getDatabaseAccessor();
598
599
        $status = $data->restartSequence($_REQUEST['sequence']);
600
        if (0 == $status) {
601
            $this->doProperties($lang['strsequencerestart']);
602
        } else {
603
            $this->doProperties($lang['strsequencerestartbad']);
604
        }
605
    }
606
607
    /**
608
     * Resets a sequence.
609
     */
610
    public function doReset()
611
    {
612
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
613
614
        $lang = $this->lang;
615
        $data = $this->misc->getDatabaseAccessor();
616
617
        $status = $data->resetSequence($_REQUEST['sequence']);
618
        if (0 == $status) {
619
            $this->doProperties($lang['strsequencereset']);
620
        } else {
621
            $this->doProperties($lang['strsequenceresetbad']);
622
        }
623
    }
624
625
    /**
626
     * Set Nextval of a sequence.
627
     */
628
    public function doNextval()
629
    {
630
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
631
632
        $lang = $this->lang;
633
        $data = $this->misc->getDatabaseAccessor();
634
635
        $status = $data->nextvalSequence($_REQUEST['sequence']);
636
        if (0 == $status) {
637
            $this->doProperties($lang['strsequencenextval']);
638
        } else {
639
            $this->doProperties($lang['strsequencenextvalbad']);
640
        }
641
    }
642
643
    /**
644
     * Function to save after 'setval'ing a sequence.
645
     */
646
    public function doSaveSetval()
647
    {
648
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
649
650
        $lang = $this->lang;
651
        $data = $this->misc->getDatabaseAccessor();
652
653
        $status = $data->setvalSequence($_POST['sequence'], $_POST['nextvalue']);
654
        if (0 == $status) {
655
            $this->doProperties($lang['strsequencesetval']);
656
        } else {
657
            $this->doProperties($lang['strsequencesetvalbad']);
658
        }
659
    }
660
661
    /**
662
     * Function to allow 'setval'ing of a sequence.
663
     *
664
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
665
     */
666
    public function doSetval($msg = '')
667
    {
668
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
669
670
        $lang = $this->lang;
671
        $data = $this->misc->getDatabaseAccessor();
672
673
        $this->printTrail('sequence');
674
        $this->printTitle($lang['strsetval'], 'pg.sequence');
675
        $this->printMsg($msg);
676
677
        // Fetch the sequence information
678
        $sequence = $data->getSequence($_REQUEST['sequence']);
679
680
        if (is_object($sequence) && $sequence->recordCount() > 0) {
681
            echo '<form action="'.\SUBFOLDER."/src/views/sequences.php\" method=\"post\">\n";
682
            echo '<table border="0">';
683
            echo "<tr><th class=\"data left required\">{$lang['strlastvalue']}</th>\n";
684
            echo '<td class="data1">';
685
            echo "<input name=\"nextvalue\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
686
            $this->misc->printVal($sequence->fields['last_value']), "\" /></td></tr>\n";
687
            echo "</table>\n";
688
            echo "<p><input type=\"hidden\" name=\"action\" value=\"setval\" />\n";
689
            echo '<input type="hidden" name="sequence" value="', htmlspecialchars($_REQUEST['sequence']), "\" />\n";
690
            echo $this->misc->form;
691
            echo "<input type=\"submit\" name=\"setval\" value=\"{$lang['strsetval']}\" />\n";
692
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
693
            echo "</form>\n";
694
        } else {
695
            echo "<p>{$lang['strnodata']}</p>\n";
696
        }
697
    }
698
699
    /**
700
     * Function to save after altering a sequence.
701
     */
702
    public function doSaveAlter()
703
    {
704
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
705
706
        $lang = $this->lang;
707
        $data = $this->misc->getDatabaseAccessor();
708
709
        if (!isset($_POST['owner'])) {
710
            $_POST['owner'] = null;
711
        }
712
713
        if (!isset($_POST['newschema'])) {
714
            $_POST['newschema'] = null;
715
        }
716
717
        if (!isset($_POST['formIncrement'])) {
718
            $_POST['formIncrement'] = null;
719
        }
720
721
        if (!isset($_POST['formMinValue'])) {
722
            $_POST['formMinValue'] = null;
723
        }
724
725
        if (!isset($_POST['formMaxValue'])) {
726
            $_POST['formMaxValue'] = null;
727
        }
728
729
        if (!isset($_POST['formStartValue'])) {
730
            $_POST['formStartValue'] = null;
731
        }
732
733
        if (!isset($_POST['formRestartValue'])) {
734
            $_POST['formRestartValue'] = null;
735
        }
736
737
        if (!isset($_POST['formCacheValue'])) {
738
            $_POST['formCacheValue'] = null;
739
        }
740
741
        if (!isset($_POST['formCycledValue'])) {
742
            $_POST['formCycledValue'] = null;
743
        }
744
745
        $status = $data->alterSequence(
746
            $_POST['sequence'],
747
            $_POST['name'],
748
            $_POST['comment'],
749
            $_POST['owner'],
750
            $_POST['newschema'],
751
            $_POST['formIncrement'],
752
            $_POST['formMinValue'],
753
            $_POST['formMaxValue'],
754
            $_POST['formRestartValue'],
755
            $_POST['formCacheValue'],
756
            isset($_POST['formCycledValue']),
757
            $_POST['formStartValue']
758
        );
759
760
        if (0 == $status) {
761
            if ($_POST['sequence'] != $_POST['name']) {
762
                // Jump them to the new view name
763
                $_REQUEST['sequence'] = $_POST['name'];
764
                // Force a browser reload
765
                $this->misc->setReloadBrowser(true);
766
            }
767
            if (!empty($_POST['newschema']) && ($_POST['newschema'] != $data->_schema)) {
768
                // Jump them to the new sequence schema
769
                $this->misc->setCurrentSchema($_POST['newschema']);
770
                $this->misc->setReloadBrowser(true);
771
            }
772
            $this->doProperties($lang['strsequencealtered']);
773
        } else {
774
            $this->doProperties($lang['strsequencealteredbad']);
775
        }
776
    }
777
778
    /**
779
     * Function to allow altering of a sequence.
780
     *
781
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
782
     */
783
    public function doAlter($msg = '')
784
    {
785
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
786
787
        $lang = $this->lang;
788
        $data = $this->misc->getDatabaseAccessor();
789
790
        $this->printTrail('sequence');
791
        $this->printTitle($lang['stralter'], 'pg.sequence.alter');
792
        $this->printMsg($msg);
793
794
        // Fetch the sequence information
795
        $sequence = $data->getSequence($_REQUEST['sequence']);
796
797
        if (is_object($sequence) && $sequence->recordCount() > 0) {
798
            if (!isset($_POST['name'])) {
799
                $_POST['name'] = $_REQUEST['sequence'];
800
            }
801
802
            if (!isset($_POST['comment'])) {
803
                $_POST['comment'] = $sequence->fields['seqcomment'];
804
            }
805
806
            if (!isset($_POST['owner'])) {
807
                $_POST['owner'] = $sequence->fields['seqowner'];
808
            }
809
810
            if (!isset($_POST['newschema'])) {
811
                $_POST['newschema'] = $sequence->fields['nspname'];
812
            }
813
814
            // Handle Checkbox Value
815
            $sequence->fields['is_cycled'] = $data->phpBool($sequence->fields['is_cycled']);
816
            if ($sequence->fields['is_cycled']) {
817
                $_POST['formCycledValue'] = 'on';
818
            }
819
820
            echo '<form action="'.\SUBFOLDER."/src/views/sequences.php\" method=\"post\">\n";
821
            echo "<table>\n";
822
823
            echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n";
824
            echo '<td class="data1">';
825
            echo "<input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
826
            htmlspecialchars($_POST['name']), "\" /></td></tr>\n";
827
828
            if ($data->isSuperUser()) {
829
                // Fetch all users
830
                $users = $data->getUsers();
831
832
                echo "<tr><th class=\"data left required\">{$lang['strowner']}</th>\n";
833
                echo '<td class="data1"><select name="owner">';
834
                while (!$users->EOF) {
835
                    $uname = $users->fields['usename'];
836
                    echo '<option value="', htmlspecialchars($uname), '"',
837
                    ($uname == $_POST['owner']) ? ' selected="selected"' : '', '>', htmlspecialchars($uname), "</option>\n";
838
                    $users->moveNext();
839
                }
840
                echo "</select></td></tr>\n";
841
            }
842
843
            if ($data->hasAlterSequenceSchema()) {
844
                $schemas = $data->getSchemas();
845
                echo "<tr><th class=\"data left required\">{$lang['strschema']}</th>\n";
846
                echo '<td class="data1"><select name="newschema">';
847
                while (!$schemas->EOF) {
848
                    $schema = $schemas->fields['nspname'];
849
                    echo '<option value="', htmlspecialchars($schema), '"',
850
                    ($schema == $_POST['newschema']) ? ' selected="selected"' : '', '>', htmlspecialchars($schema), "</option>\n";
851
                    $schemas->moveNext();
852
                }
853
                echo "</select></td></tr>\n";
854
            }
855
856
            echo "<tr><th class=\"data left\">{$lang['strcomment']}</th>\n";
857
            echo '<td class="data1">';
858
            echo '<textarea rows="3" cols="32" name="comment">',
859
            htmlspecialchars($_POST['comment']), "</textarea></td></tr>\n";
860
861
            if ($data->hasAlterSequenceStart()) {
862
                echo "<tr><th class=\"data left\">{$lang['strstartvalue']}</th>\n";
863
                echo '<td class="data1"><input name="formStartValue" size="5" value="',
864
                htmlspecialchars($sequence->fields['start_value']), "\" /></td></tr>\n";
865
            }
866
867
            echo "<tr><th class=\"data left\">{$lang['strrestartvalue']}</th>\n";
868
            echo '<td class="data1"><input name="formRestartValue" size="5" value="',
869
            htmlspecialchars($sequence->fields['last_value']), "\" /></td></tr>\n";
870
871
            echo "<tr><th class=\"data left\">{$lang['strincrementby']}</th>\n";
872
            echo '<td class="data1"><input name="formIncrement" size="5" value="',
873
            htmlspecialchars($sequence->fields['increment_by']), "\" /> </td></tr>\n";
874
875
            echo "<tr><th class=\"data left\">{$lang['strmaxvalue']}</th>\n";
876
            echo '<td class="data1"><input name="formMaxValue" size="5" value="',
877
            htmlspecialchars($sequence->fields['max_value']), "\" /></td></tr>\n";
878
879
            echo "<tr><th class=\"data left\">{$lang['strminvalue']}</th>\n";
880
            echo '<td class="data1"><input name="formMinValue" size="5" value="',
881
            htmlspecialchars($sequence->fields['min_value']), "\" /></td></tr>\n";
882
883
            echo "<tr><th class=\"data left\">{$lang['strcachevalue']}</th>\n";
884
            echo '<td class="data1"><input name="formCacheValue" size="5" value="',
885
            htmlspecialchars($sequence->fields['cache_value']), "\" /></td></tr>\n";
886
887
            echo "<tr><th class=\"data left\"><label for=\"formCycledValue\">{$lang['strcancycle']}</label></th>\n";
888
            echo '<td class="data1"><input type="checkbox" id="formCycledValue" name="formCycledValue" ',
889
            (isset($_POST['formCycledValue']) ? ' checked="checked"' : ''), " /></td></tr>\n";
890
891
            echo "</table>\n";
892
            echo "<p><input type=\"hidden\" name=\"action\" value=\"alter\" />\n";
893
            echo $this->misc->form;
894
            echo '<input type="hidden" name="sequence" value="', htmlspecialchars($_REQUEST['sequence']), "\" />\n";
895
            echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n";
896
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
897
            echo "</form>\n";
898
        } else {
899
            echo "<p>{$lang['strnodata']}</p>\n";
900
        }
901
    }
902
}
903