Passed
Pull Request — develop (#92)
by Felipe
06:19
created

SequencesController::doSaveCreateSequence()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 18
nc 3
nop 0
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
/*
4
 * PHPPgAdmin v6.0.0-beta.30
5
 */
6
7
namespace PHPPgAdmin\Controller;
8
9
use \PHPPgAdmin\Decorators\Decorator;
10
11
/**
12
 * Base controller class
13
 */
5 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
14
class SequencesController extends BaseController
15
{
16
    public $controller_name = 'SequencesController';
17
18
    public function render()
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
19
    {
20
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
21
22
        $lang = $this->lang;
23
24
        $action = $this->action;
25
        if ('tree' == $action) {
26
            return $this->doTree();
27
        }
28
29
        // Print header
30
        $this->printHeader($lang['strsequences']);
31
        $this->printBody();
32
33
        switch ($action) {
34
            case 'create':
35
                $this->doCreateSequence();
36
37
                break;
38
            case 'save_create_sequence':
39
                if (isset($_POST['create'])) {
40
                    $this->doSaveCreateSequence();
41
                } else {
42
                    $this->doDefault();
43
                }
44
45
                break;
46
            case 'properties':
47
                $this->doProperties();
48
49
                break;
50
            case 'drop':
51
                if (isset($_POST['drop'])) {
52
                    $this->doDrop(false);
53
                } else {
54
                    $this->doDefault();
55
                }
56
57
                break;
58
            case 'confirm_drop':
59
                $this->doDrop(true);
60
61
                break;
62
            case 'restart':
63
                $this->doRestart();
64
65
                break;
66
            case 'reset':
67
                $this->doReset();
68
69
                break;
70
            case 'nextval':
71
                $this->doNextval();
72
73
                break;
74
            case 'setval':
75
                if (isset($_POST['setval'])) {
76
                    $this->doSaveSetval();
77
                } else {
78
                    $this->doDefault();
79
                }
80
81
                break;
82
            case 'confirm_setval':
83
                $this->doSetval();
84
85
                break;
86
            case 'alter':
87
                if (isset($_POST['alter'])) {
88
                    $this->doSaveAlter();
89
                } else {
90
                    $this->doDefault();
91
                }
92
93
                break;
94
            case 'confirm_alter':
95
                $this->doAlter();
96
97
                break;
98
            default:
99
                $this->doDefault();
100
101
                break;
102
        }
103
104
        // Print footer
105
        return $this->printFooter();
106
    }
107
108
    /**
109
     * Display list of all sequences in the database/schema
110
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
111
     */
112
    public function doDefault($msg = '')
113
    {
114
        $conf = $this->conf;
115
116
        $lang = $this->lang;
117
        $data = $this->misc->getDatabaseAccessor();
118
119
        $this->printTrail('schema');
120
        $this->printTabs('schema', 'sequences');
121
        $this->printMsg($msg);
122
123
        // Get all sequences
124
        $sequences = $data->getSequences();
125
126
        $columns = [
127
            'sequence' => [
128
                'title' => $lang['strsequence'],
129
                'field' => Decorator::field('seqname'),
130
                'url'   => "sequences.php?action=properties&amp;{$this->misc->href}&amp;",
131
                'vars'  => ['sequence' => 'seqname'],
132
            ],
133
            'owner'    => [
134
                'title' => $lang['strowner'],
135
                'field' => Decorator::field('seqowner'),
136
            ],
137
            'actions'  => [
138
                'title' => $lang['stractions'],
139
            ],
140
            'comment'  => [
141
                'title' => $lang['strcomment'],
142
                'field' => Decorator::field('seqcomment'),
143
            ],
144
        ];
145
146
        $actions = [
147
            'multiactions' => [
148
                'keycols' => ['sequence' => 'seqname'],
149
                'url'     => 'sequences.php',
150
            ],
151
            'alter'        => [
152
                'content' => $lang['stralter'],
153
                'attr'    => [
154
                    'href' => [
155
                        'url'     => 'sequences.php',
156
                        'urlvars' => [
157
                            'action'   => 'confirm_alter',
158
                            'subject'  => 'sequence',
159
                            'sequence' => Decorator::field('seqname'),
160
                        ],
161
                    ],
162
                ],
163
            ],
164
            'drop'         => [
165
                'content'     => $lang['strdrop'],
166
                'attr'        => [
167
                    'href' => [
168
                        'url'     => 'sequences.php',
169
                        'urlvars' => [
170
                            'action'   => 'confirm_drop',
171
                            'sequence' => Decorator::field('seqname'),
172
                        ],
173
                    ],
174
                ],
175
                'multiaction' => 'confirm_drop',
176
            ],
177
            'privileges'   => [
178
                'content' => $lang['strprivileges'],
179
                'attr'    => [
180
                    'href' => [
181
                        'url'     => 'privileges.php',
182
                        'urlvars' => [
183
                            'subject'  => 'sequence',
184
                            'sequence' => Decorator::field('seqname'),
185
                        ],
186
                    ],
187
                ],
188
            ],
189
        ];
190
191
        echo $this->printTable($sequences, $columns, $actions, 'sequences-sequences', $lang['strnosequences']);
192
193
        $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...
194
            'attr'    => [
195
                'href' => [
196
                    'url'     => 'sequences.php',
197
                    'urlvars' => [
198
                        'action'   => 'create',
199
                        'server'   => $_REQUEST['server'],
200
                        'database' => $_REQUEST['database'],
201
                        'schema'   => $_REQUEST['schema'],
202
                    ],
203
                ],
204
            ],
205
            'content' => $lang['strcreatesequence'],
206
        ]], '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...
207
    }
208
209
    /**
210
     * Generate XML for the browser tree.
211
     */
212
    public function doTree()
213
    {
214
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
215
216
        $lang = $this->lang;
0 ignored issues
show
Unused Code introduced by
The assignment to $lang is dead and can be removed.
Loading history...
217
        $data = $this->misc->getDatabaseAccessor();
218
219
        $sequences = $data->getSequences();
220
221
        $reqvars = $this->misc->getRequestVars('sequence');
222
223
        $attrs = [
224
            'text'    => Decorator::field('seqname'),
225
            'icon'    => 'Sequence',
226
            'toolTip' => Decorator::field('seqcomment'),
227
            'action'  => Decorator::actionurl(
228
                'sequences.php',
229
                $reqvars,
230
                [
231
                    'action'   => 'properties',
232
                    'sequence' => Decorator::field('seqname'),
233
                ]
234
            ),
235
        ];
236
237
        return $this->printTree($sequences, $attrs, 'sequences');
238
    }
239
240
    /**
241
     * Display the properties of a sequence
242
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
243
     */
244
    public function doProperties($msg = '')
245
    {
246
        $conf = $this->conf;
247
248
        $lang = $this->lang;
249
        $data = $this->misc->getDatabaseAccessor();
250
        $this->printTrail('sequence');
251
        $this->printTitle($lang['strproperties'], 'pg.sequence');
252
        $this->printMsg($msg);
253
254
        // Fetch the sequence information
255
        $sequence = $data->getSequence($_REQUEST['sequence']);
256
257
        if (is_object($sequence) && $sequence->recordCount() > 0) {
258
            $sequence->fields['is_cycled'] = $data->phpBool($sequence->fields['is_cycled']);
259
            $sequence->fields['is_called'] = $data->phpBool($sequence->fields['is_called']);
260
261
            // Show comment if any
262
            if (null !== $sequence->fields['seqcomment']) {
263
                echo '<p class="comment">', $this->misc->printVal($sequence->fields['seqcomment']), "</p>\n";
264
            }
265
266
            echo '<table border="0">';
267
            echo "<tr><th class=\"data\">{$lang['strname']}</th>";
268
            if ($data->hasAlterSequenceStart()) {
269
                echo "<th class=\"data\">{$lang['strstartvalue']}</th>";
270
            }
271
            echo "<th class=\"data\">{$lang['strlastvalue']}</th>";
272
            echo "<th class=\"data\">{$lang['strincrementby']}</th>";
273
            echo "<th class=\"data\">{$lang['strmaxvalue']}</th>";
274
            echo "<th class=\"data\">{$lang['strminvalue']}</th>";
275
            echo "<th class=\"data\">{$lang['strcachevalue']}</th>";
276
            echo "<th class=\"data\">{$lang['strlogcount']}</th>";
277
            echo "<th class=\"data\">{$lang['strcancycle']}</th>";
278
            echo "<th class=\"data\">{$lang['striscalled']}</th></tr>";
279
            echo '<tr>';
280
            echo '<td class="data1">', $this->misc->printVal($sequence->fields['seqname']), '</td>';
281
            if ($data->hasAlterSequenceStart()) {
282
                echo '<td class="data1">', $this->misc->printVal($sequence->fields['start_value']), '</td>';
283
            }
284
            echo '<td class="data1">', $this->misc->printVal($sequence->fields['last_value']), '</td>';
285
            echo '<td class="data1">', $this->misc->printVal($sequence->fields['increment_by']), '</td>';
286
            echo '<td class="data1">', $this->misc->printVal($sequence->fields['max_value']), '</td>';
287
            echo '<td class="data1">', $this->misc->printVal($sequence->fields['min_value']), '</td>';
288
            echo '<td class="data1">', $this->misc->printVal($sequence->fields['cache_value']), '</td>';
289
            echo '<td class="data1">', $this->misc->printVal($sequence->fields['log_cnt']), '</td>';
290
            echo '<td class="data1">', ($sequence->fields['is_cycled'] ? $lang['stryes'] : $lang['strno']), '</td>';
291
            echo '<td class="data1">', ($sequence->fields['is_called'] ? $lang['stryes'] : $lang['strno']), '</td>';
292
            echo '</tr>';
293
            echo '</table>';
294
295
            $navlinks = [
296
                'alter'   => [
297
                    'attr'    => [
298
                        'href' => [
299
                            'url'     => 'sequences.php',
300
                            'urlvars' => [
301
                                'action'   => 'confirm_alter',
302
                                'server'   => $_REQUEST['server'],
303
                                'database' => $_REQUEST['database'],
304
                                'schema'   => $_REQUEST['schema'],
305
                                'sequence' => $sequence->fields['seqname'],
306
                            ],
307
                        ],
308
                    ],
309
                    'content' => $lang['stralter'],
310
                ],
311
                'setval'  => [
312
                    'attr'    => [
313
                        'href' => [
314
                            'url'     => 'sequences.php',
315
                            'urlvars' => [
316
                                'action'   => 'confirm_setval',
317
                                'server'   => $_REQUEST['server'],
318
                                'database' => $_REQUEST['database'],
319
                                'schema'   => $_REQUEST['schema'],
320
                                'sequence' => $sequence->fields['seqname'],
321
                            ],
322
                        ],
323
                    ],
324
                    'content' => $lang['strsetval'],
325
                ],
326
                'nextval' => [
327
                    'attr'    => [
328
                        'href' => [
329
                            'url'     => 'sequences.php',
330
                            'urlvars' => [
331
                                'action'   => 'nextval',
332
                                'server'   => $_REQUEST['server'],
333
                                'database' => $_REQUEST['database'],
334
                                'schema'   => $_REQUEST['schema'],
335
                                'sequence' => $sequence->fields['seqname'],
336
                            ],
337
                        ],
338
                    ],
339
                    'content' => $lang['strnextval'],
340
                ],
341
                'restart' => [
342
                    'attr'    => [
343
                        'href' => [
344
                            'url'     => 'sequences.php',
345
                            'urlvars' => [
346
                                'action'   => 'restart',
347
                                'server'   => $_REQUEST['server'],
348
                                'database' => $_REQUEST['database'],
349
                                'schema'   => $_REQUEST['schema'],
350
                                'sequence' => $sequence->fields['seqname'],
351
                            ],
352
                        ],
353
                    ],
354
                    'content' => $lang['strrestart'],
355
                ],
356
                'reset'   => [
357
                    'attr'    => [
358
                        'href' => [
359
                            'url'     => 'sequences.php',
360
                            'urlvars' => [
361
                                'action'   => 'reset',
362
                                'server'   => $_REQUEST['server'],
363
                                'database' => $_REQUEST['database'],
364
                                'schema'   => $_REQUEST['schema'],
365
                                'sequence' => $sequence->fields['seqname'],
366
                            ],
367
                        ],
368
                    ],
369
                    'content' => $lang['strreset'],
370
                ],
371
                'showall' => [
372
                    'attr'    => [
373
                        'href' => [
374
                            'url'     => 'sequences.php',
375
                            'urlvars' => [
376
                                'server'   => $_REQUEST['server'],
377
                                'database' => $_REQUEST['database'],
378
                                'schema'   => $_REQUEST['schema'],
379
                            ],
380
                        ],
381
                    ],
382
                    'content' => $lang['strshowallsequences'],
383
                ],
384
            ];
385
386
            if (!$data->hasAlterSequenceStart()) {
387
                unset($navlinks['restart']);
388
            }
389
390
            $this->printNavLinks($navlinks, 'sequences-properties', get_defined_vars());
391
        } else {
392
            echo "<p>{$lang['strnodata']}</p>\n";
393
        }
394
    }
395
396
    /**
397
     * Drop a sequence
398
     * @param mixed $confirm
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
399
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
400
     */
401
    public function doDrop($confirm, $msg = '')
402
    {
403
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
404
405
        $lang = $this->lang;
406
        $data = $this->misc->getDatabaseAccessor();
407
408
        if (empty($_REQUEST['sequence']) && empty($_REQUEST['ma'])) {
409
            return $this->doDefault($lang['strspecifysequencetodrop']);
410
        }
411
412
        if ($confirm) {
413
            $this->printTrail('sequence');
414
            $this->printTitle($lang['strdrop'], 'pg.sequence.drop');
415
            $this->printMsg($msg);
416
417
            echo '<form action="' . SUBFOLDER . "/src/views/sequences.php\" method=\"post\">\n";
418
419
            //If multi drop
420
            if (isset($_REQUEST['ma'])) {
421
                foreach ($_REQUEST['ma'] as $v) {
422
                    $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES));
423
                    echo '<p>', sprintf($lang['strconfdropsequence'], $this->misc->printVal($a['sequence'])), "</p>\n";
424
                    printf('<input type="hidden" name="sequence[]" value="%s" />', htmlspecialchars($a['sequence']));
425
                }
426
            } else {
427
                echo '<p>', sprintf($lang['strconfdropsequence'], $this->misc->printVal($_REQUEST['sequence'])), "</p>\n";
428
                echo '<input type="hidden" name="sequence" value="', htmlspecialchars($_REQUEST['sequence']), "\" />\n";
429
            }
430
431
            echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$lang['strcascade']}</label></p>\n";
432
            echo "<p><input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
433
            echo $this->misc->form;
434
            echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
435
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
436
            echo "</form>\n";
437
        } else {
438
            if (is_array($_POST['sequence'])) {
439
                $msg    = '';
440
                $status = $data->beginTransaction();
441
                if (0 == $status) {
442
                    foreach ($_POST['sequence'] as $s) {
443
                        $status = $data->dropSequence($s, isset($_POST['cascade']));
444
                        if (0 == $status) {
445
                            $msg .= sprintf('%s: %s<br />', htmlentities($s, ENT_QUOTES, 'UTF-8'), $lang['strsequencedropped']);
446
                        } else {
447
                            $data->endTransaction();
448
                            $this->doDefault(sprintf('%s%s: %s<br />', $msg, htmlentities($s, ENT_QUOTES, 'UTF-8'), $lang['strsequencedroppedbad']));
449
450
                            return;
451
                        }
452
                    }
453
                }
454
                if (0 == $data->endTransaction()) {
455
                    // Everything went fine, back to the Default page....
456
                    $this->misc->setReloadBrowser(true);
457
                    $this->doDefault($msg);
458
                } else {
459
                    $this->doDefault($lang['strsequencedroppedbad']);
460
                }
461
            } else {
462
                $status = $data->dropSequence($_POST['sequence'], isset($_POST['cascade']));
463
                if (0 == $status) {
464
                    $this->misc->setReloadBrowser(true);
465
                    $this->doDefault($lang['strsequencedropped']);
466
                } else {
467
                    $this->doDrop(true, $lang['strsequencedroppedbad']);
468
                }
469
            }
470
        }
471
    }
472
473
    /**
474
     * Displays a screen where they can enter a new sequence
475
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
476
     */
477
    public function doCreateSequence($msg = '')
478
    {
479
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
480
481
        $lang = $this->lang;
482
        $data = $this->misc->getDatabaseAccessor();
483
484
        if (!isset($_POST['formSequenceName'])) {
485
            $_POST['formSequenceName'] = '';
486
        }
487
488
        if (!isset($_POST['formIncrement'])) {
489
            $_POST['formIncrement'] = '';
490
        }
491
492
        if (!isset($_POST['formMinValue'])) {
493
            $_POST['formMinValue'] = '';
494
        }
495
496
        if (!isset($_POST['formMaxValue'])) {
497
            $_POST['formMaxValue'] = '';
498
        }
499
500
        if (!isset($_POST['formStartValue'])) {
501
            $_POST['formStartValue'] = '';
502
        }
503
504
        if (!isset($_POST['formCacheValue'])) {
505
            $_POST['formCacheValue'] = '';
506
        }
507
508
        $this->printTrail('schema');
509
        $this->printTitle($lang['strcreatesequence'], 'pg.sequence.create');
510
        $this->printMsg($msg);
511
512
        echo '<form action="' . SUBFOLDER . "/src/views/sequences.php\" method=\"post\">\n";
513
        echo "<table>\n";
514
515
        echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n";
516
        echo "<td class=\"data1\"><input name=\"formSequenceName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
517
        htmlspecialchars($_POST['formSequenceName']), "\" /></td></tr>\n";
518
519
        echo "<tr><th class=\"data left\">{$lang['strincrementby']}</th>\n";
520
        echo '<td class="data1"><input name="formIncrement" size="5" value="',
521
        htmlspecialchars($_POST['formIncrement']), "\" /> </td></tr>\n";
522
523
        echo "<tr><th class=\"data left\">{$lang['strminvalue']}</th>\n";
524
        echo '<td class="data1"><input name="formMinValue" size="5" value="',
525
        htmlspecialchars($_POST['formMinValue']), "\" /></td></tr>\n";
526
527
        echo "<tr><th class=\"data left\">{$lang['strmaxvalue']}</th>\n";
528
        echo '<td class="data1"><input name="formMaxValue" size="5" value="',
529
        htmlspecialchars($_POST['formMaxValue']), "\" /></td></tr>\n";
530
531
        echo "<tr><th class=\"data left\">{$lang['strstartvalue']}</th>\n";
532
        echo '<td class="data1"><input name="formStartValue" size="5" value="',
533
        htmlspecialchars($_POST['formStartValue']), "\" /></td></tr>\n";
534
535
        echo "<tr><th class=\"data left\">{$lang['strcachevalue']}</th>\n";
536
        echo '<td class="data1"><input name="formCacheValue" size="5" value="',
537
        htmlspecialchars($_POST['formCacheValue']), "\" /></td></tr>\n";
538
539
        echo "<tr><th class=\"data left\"><label for=\"formCycledValue\">{$lang['strcancycle']}</label></th>\n";
540
        echo '<td class="data1"><input type="checkbox" id="formCycledValue" name="formCycledValue" ',
541
        (isset($_POST['formCycledValue']) ? ' checked="checked"' : ''), " /></td></tr>\n";
542
543
        echo "</table>\n";
544
        echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create_sequence\" />\n";
545
        echo $this->misc->form;
546
        echo "<input type=\"submit\" name=\"create\" value=\"{$lang['strcreate']}\" />\n";
547
        echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
548
        echo "</form>\n";
549
    }
550
551
    /**
552
     * Actually creates the new sequence in the database
553
     */
554
    public function doSaveCreateSequence()
555
    {
556
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
557
558
        $lang = $this->lang;
559
        $data = $this->misc->getDatabaseAccessor();
560
561
        // Check that they've given a name and at least one column
562
        if ('' == $_POST['formSequenceName']) {
563
            $this->doCreateSequence($lang['strsequenceneedsname']);
564
        } else {
565
            $status = $data->createSequence(
566
                $_POST['formSequenceName'],
567
                $_POST['formIncrement'],
568
                $_POST['formMinValue'],
569
                $_POST['formMaxValue'],
570
                $_POST['formStartValue'],
571
                $_POST['formCacheValue'],
572
                isset($_POST['formCycledValue'])
573
            );
574
            if (0 == $status) {
575
                $this->doDefault($lang['strsequencecreated']);
576
            } else {
577
                $this->doCreateSequence($lang['strsequencecreatedbad']);
578
            }
579
        }
580
    }
581
582
    /**
583
     * Restarts a sequence
584
     */
585
    public function doRestart()
586
    {
587
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
588
589
        $lang = $this->lang;
590
        $data = $this->misc->getDatabaseAccessor();
591
592
        $status = $data->restartSequence($_REQUEST['sequence']);
593
        if (0 == $status) {
594
            $this->doProperties($lang['strsequencerestart']);
595
        } else {
596
            $this->doProperties($lang['strsequencerestartbad']);
597
        }
598
    }
599
600
    /**
601
     * Resets a sequence
602
     */
603
    public function doReset()
604
    {
605
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
606
607
        $lang = $this->lang;
608
        $data = $this->misc->getDatabaseAccessor();
609
610
        $status = $data->resetSequence($_REQUEST['sequence']);
611
        if (0 == $status) {
612
            $this->doProperties($lang['strsequencereset']);
613
        } else {
614
            $this->doProperties($lang['strsequenceresetbad']);
615
        }
616
    }
617
618
    /**
619
     * Set Nextval of a sequence
620
     */
621
    public function doNextval()
622
    {
623
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
624
625
        $lang = $this->lang;
626
        $data = $this->misc->getDatabaseAccessor();
627
628
        $status = $data->nextvalSequence($_REQUEST['sequence']);
629
        if (0 == $status) {
630
            $this->doProperties($lang['strsequencenextval']);
631
        } else {
632
            $this->doProperties($lang['strsequencenextvalbad']);
633
        }
634
    }
635
636
    /**
637
     * Function to save after 'setval'ing a sequence
638
     */
639
    public function doSaveSetval()
640
    {
641
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
642
643
        $lang = $this->lang;
644
        $data = $this->misc->getDatabaseAccessor();
645
646
        $status = $data->setvalSequence($_POST['sequence'], $_POST['nextvalue']);
647
        if (0 == $status) {
648
            $this->doProperties($lang['strsequencesetval']);
649
        } else {
650
            $this->doProperties($lang['strsequencesetvalbad']);
651
        }
652
    }
653
654
    /**
655
     * Function to allow 'setval'ing of a sequence
656
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
657
     */
658
    public function doSetval($msg = '')
659
    {
660
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
661
662
        $lang = $this->lang;
663
        $data = $this->misc->getDatabaseAccessor();
664
665
        $this->printTrail('sequence');
666
        $this->printTitle($lang['strsetval'], 'pg.sequence');
667
        $this->printMsg($msg);
668
669
        // Fetch the sequence information
670
        $sequence = $data->getSequence($_REQUEST['sequence']);
671
672
        if (is_object($sequence) && $sequence->recordCount() > 0) {
673
            echo '<form action="' . SUBFOLDER . "/src/views/sequences.php\" method=\"post\">\n";
674
            echo '<table border="0">';
675
            echo "<tr><th class=\"data left required\">{$lang['strlastvalue']}</th>\n";
676
            echo '<td class="data1">';
677
            echo "<input name=\"nextvalue\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
678
            $this->misc->printVal($sequence->fields['last_value']), "\" /></td></tr>\n";
679
            echo "</table>\n";
680
            echo "<p><input type=\"hidden\" name=\"action\" value=\"setval\" />\n";
681
            echo '<input type="hidden" name="sequence" value="', htmlspecialchars($_REQUEST['sequence']), "\" />\n";
682
            echo $this->misc->form;
683
            echo "<input type=\"submit\" name=\"setval\" value=\"{$lang['strsetval']}\" />\n";
684
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
685
            echo "</form>\n";
686
        } else {
687
            echo "<p>{$lang['strnodata']}</p>\n";
688
        }
689
    }
690
691
    /**
692
     * Function to save after altering a sequence
693
     */
694
    public function doSaveAlter()
695
    {
696
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
697
698
        $lang = $this->lang;
699
        $data = $this->misc->getDatabaseAccessor();
700
701
        if (!isset($_POST['owner'])) {
702
            $_POST['owner'] = null;
703
        }
704
705
        if (!isset($_POST['newschema'])) {
706
            $_POST['newschema'] = null;
707
        }
708
709
        if (!isset($_POST['formIncrement'])) {
710
            $_POST['formIncrement'] = null;
711
        }
712
713
        if (!isset($_POST['formMinValue'])) {
714
            $_POST['formMinValue'] = null;
715
        }
716
717
        if (!isset($_POST['formMaxValue'])) {
718
            $_POST['formMaxValue'] = null;
719
        }
720
721
        if (!isset($_POST['formStartValue'])) {
722
            $_POST['formStartValue'] = null;
723
        }
724
725
        if (!isset($_POST['formRestartValue'])) {
726
            $_POST['formRestartValue'] = null;
727
        }
728
729
        if (!isset($_POST['formCacheValue'])) {
730
            $_POST['formCacheValue'] = null;
731
        }
732
733
        if (!isset($_POST['formCycledValue'])) {
734
            $_POST['formCycledValue'] = null;
735
        }
736
737
        $status = $data->alterSequence(
738
            $_POST['sequence'],
739
            $_POST['name'],
740
            $_POST['comment'],
741
            $_POST['owner'],
742
            $_POST['newschema'],
743
            $_POST['formIncrement'],
744
            $_POST['formMinValue'],
745
            $_POST['formMaxValue'],
746
            $_POST['formRestartValue'],
747
            $_POST['formCacheValue'],
748
            isset($_POST['formCycledValue']),
749
            $_POST['formStartValue']
750
        );
751
752
        if (0 == $status) {
753
            if ($_POST['sequence'] != $_POST['name']) {
754
                // Jump them to the new view name
755
                $_REQUEST['sequence'] = $_POST['name'];
756
                // Force a browser reload
757
                $this->misc->setReloadBrowser(true);
758
            }
759
            if (!empty($_POST['newschema']) && ($_POST['newschema'] != $data->_schema)) {
760
                // Jump them to the new sequence schema
761
                $this->misc->setCurrentSchema($_POST['newschema']);
762
                $this->misc->setReloadBrowser(true);
763
            }
764
            $this->doProperties($lang['strsequencealtered']);
765
        } else {
766
            $this->doProperties($lang['strsequencealteredbad']);
767
        }
768
    }
769
770
    /**
771
     * Function to allow altering of a sequence
772
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
773
     */
774
    public function doAlter($msg = '')
775
    {
776
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
777
778
        $lang = $this->lang;
779
        $data = $this->misc->getDatabaseAccessor();
780
781
        $this->printTrail('sequence');
782
        $this->printTitle($lang['stralter'], 'pg.sequence.alter');
783
        $this->printMsg($msg);
784
785
        // Fetch the sequence information
786
        $sequence = $data->getSequence($_REQUEST['sequence']);
787
788
        if (is_object($sequence) && $sequence->recordCount() > 0) {
789
            if (!isset($_POST['name'])) {
790
                $_POST['name'] = $_REQUEST['sequence'];
791
            }
792
793
            if (!isset($_POST['comment'])) {
794
                $_POST['comment'] = $sequence->fields['seqcomment'];
795
            }
796
797
            if (!isset($_POST['owner'])) {
798
                $_POST['owner'] = $sequence->fields['seqowner'];
799
            }
800
801
            if (!isset($_POST['newschema'])) {
802
                $_POST['newschema'] = $sequence->fields['nspname'];
803
            }
804
805
            // Handle Checkbox Value
806
            $sequence->fields['is_cycled'] = $data->phpBool($sequence->fields['is_cycled']);
807
            if ($sequence->fields['is_cycled']) {
808
                $_POST['formCycledValue'] = 'on';
809
            }
810
811
            echo '<form action="' . SUBFOLDER . "/src/views/sequences.php\" method=\"post\">\n";
812
            echo "<table>\n";
813
814
            echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n";
815
            echo '<td class="data1">';
816
            echo "<input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
817
            htmlspecialchars($_POST['name']), "\" /></td></tr>\n";
818
819
            if ($data->isSuperUser()) {
820
                // Fetch all users
821
                $users = $data->getUsers();
822
823
                echo "<tr><th class=\"data left required\">{$lang['strowner']}</th>\n";
824
                echo '<td class="data1"><select name="owner">';
825
                while (!$users->EOF) {
826
                    $uname = $users->fields['usename'];
827
                    echo '<option value="', htmlspecialchars($uname), '"',
828
                    ($uname == $_POST['owner']) ? ' selected="selected"' : '', '>', htmlspecialchars($uname), "</option>\n";
829
                    $users->moveNext();
830
                }
831
                echo "</select></td></tr>\n";
832
            }
833
834
            if ($data->hasAlterSequenceSchema()) {
835
                $schemas = $data->getSchemas();
836
                echo "<tr><th class=\"data left required\">{$lang['strschema']}</th>\n";
837
                echo '<td class="data1"><select name="newschema">';
838
                while (!$schemas->EOF) {
839
                    $schema = $schemas->fields['nspname'];
840
                    echo '<option value="', htmlspecialchars($schema), '"',
841
                    ($schema == $_POST['newschema']) ? ' selected="selected"' : '', '>', htmlspecialchars($schema), "</option>\n";
842
                    $schemas->moveNext();
843
                }
844
                echo "</select></td></tr>\n";
845
            }
846
847
            echo "<tr><th class=\"data left\">{$lang['strcomment']}</th>\n";
848
            echo '<td class="data1">';
849
            echo '<textarea rows="3" cols="32" name="comment">',
850
            htmlspecialchars($_POST['comment']), "</textarea></td></tr>\n";
851
852
            if ($data->hasAlterSequenceStart()) {
853
                echo "<tr><th class=\"data left\">{$lang['strstartvalue']}</th>\n";
854
                echo '<td class="data1"><input name="formStartValue" size="5" value="',
855
                htmlspecialchars($sequence->fields['start_value']), "\" /></td></tr>\n";
856
            }
857
858
            echo "<tr><th class=\"data left\">{$lang['strrestartvalue']}</th>\n";
859
            echo '<td class="data1"><input name="formRestartValue" size="5" value="',
860
            htmlspecialchars($sequence->fields['last_value']), "\" /></td></tr>\n";
861
862
            echo "<tr><th class=\"data left\">{$lang['strincrementby']}</th>\n";
863
            echo '<td class="data1"><input name="formIncrement" size="5" value="',
864
            htmlspecialchars($sequence->fields['increment_by']), "\" /> </td></tr>\n";
865
866
            echo "<tr><th class=\"data left\">{$lang['strmaxvalue']}</th>\n";
867
            echo '<td class="data1"><input name="formMaxValue" size="5" value="',
868
            htmlspecialchars($sequence->fields['max_value']), "\" /></td></tr>\n";
869
870
            echo "<tr><th class=\"data left\">{$lang['strminvalue']}</th>\n";
871
            echo '<td class="data1"><input name="formMinValue" size="5" value="',
872
            htmlspecialchars($sequence->fields['min_value']), "\" /></td></tr>\n";
873
874
            echo "<tr><th class=\"data left\">{$lang['strcachevalue']}</th>\n";
875
            echo '<td class="data1"><input name="formCacheValue" size="5" value="',
876
            htmlspecialchars($sequence->fields['cache_value']), "\" /></td></tr>\n";
877
878
            echo "<tr><th class=\"data left\"><label for=\"formCycledValue\">{$lang['strcancycle']}</label></th>\n";
879
            echo '<td class="data1"><input type="checkbox" id="formCycledValue" name="formCycledValue" ',
880
            (isset($_POST['formCycledValue']) ? ' checked="checked"' : ''), " /></td></tr>\n";
881
882
            echo "</table>\n";
883
            echo "<p><input type=\"hidden\" name=\"action\" value=\"alter\" />\n";
884
            echo $this->misc->form;
885
            echo '<input type="hidden" name="sequence" value="', htmlspecialchars($_REQUEST['sequence']), "\" />\n";
886
            echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n";
887
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
888
            echo "</form>\n";
889
        } else {
890
            echo "<p>{$lang['strnodata']}</p>\n";
891
        }
892
    }
893
}
894