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

MaterializedviewpropertiesController::doSaveEdit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 0
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
/*
4
 * PHPPgAdmin v6.0.0-beta.30
5
 */
6
7
namespace PHPPgAdmin\Controller;
8
9
use \PHPPgAdmin\Decorators\Decorator;
10
11
/**
12
 * Base controller class
13
 */
5 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
14
class MaterializedviewpropertiesController extends BaseController
15
{
16
    public $controller_name = 'MaterializedviewpropertiesController';
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
        $this->printHeader($lang['strviews'] . ' - ' . $_REQUEST['matview']);
30
        $this->printBody();
31
32
        switch ($action) {
33
            case 'save_edit':
34
                if (isset($_POST['cancel'])) {
35
                    $this->doDefinition();
36
                } else {
37
                    $this->doSaveEdit();
38
                }
39
40
                break;
41
            case 'edit':
42
                $this->doEdit();
43
44
                break;
45
            case 'export':
46
                $this->doExport();
47
48
                break;
49
            case 'definition':
50
                $this->doDefinition();
51
52
                break;
53
            case 'properties':
54
                if (isset($_POST['cancel'])) {
55
                    $this->doDefault();
56
                } else {
57
                    $this->doProperties();
58
                }
59
60
                break;
61
            case 'alter':
62
                if (isset($_POST['alter'])) {
63
                    $this->doAlter(false);
64
                } else {
65
                    $this->doDefault();
66
                }
67
68
                break;
69
            case 'confirm_alter':
70
                doAlter(true);
0 ignored issues
show
Bug introduced by
The function doAlter was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

70
                /** @scrutinizer ignore-call */ 
71
                doAlter(true);
Loading history...
71
72
                break;
73
            case 'drop':
74
                if (isset($_POST['drop'])) {
75
                    $this->doDrop(false);
0 ignored issues
show
Bug introduced by
The method doDrop() does not exist on PHPPgAdmin\Controller\Ma...iewpropertiesController. ( Ignorable by Annotation )

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

75
                    $this->/** @scrutinizer ignore-call */ 
76
                           doDrop(false);

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...
76
                } else {
77
                    $this->doDefault();
78
                }
79
80
                break;
81
            case 'confirm_drop':
82
                $this->doDrop(true);
83
84
                break;
85
            default:
86
                $this->doDefault();
87
88
                break;
89
        }
90
91
        $this->printFooter();
92
    }
93
94
    /**
95
     * Show view definition and virtual columns
96
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
97
     */
98
    public function doDefault($msg = '')
99
    {
100
        $conf = $this->conf;
101
102
        $lang = $this->lang;
103
        $data = $this->misc->getDatabaseAccessor();
104
105
        $attPre = function (&$rowdata) use ($data) {
106
            $rowdata->fields['+type'] = $data->formatType($rowdata->fields['type'], $rowdata->fields['atttypmod']);
107
        };
108
109
        $this->printTrail('matview');
110
        $this->printTabs('matview', 'columns');
111
        $this->printMsg($msg);
112
113
        // Get view
114
        $vdata = $data->getView($_REQUEST['matview']);
115
        // Get columns (using same method for getting a view)
116
        $attrs = $data->getTableAttributes($_REQUEST['matview']);
117
118
        // Show comment if any
119
        if (null !== $vdata->fields['relcomment']) {
120
            echo '<p class="comment">', $this->misc->printVal($vdata->fields['relcomment']), "</p>\n";
121
        }
122
123
        $columns = [
124
            'column'  => [
125
                'title' => $lang['strcolumn'],
126
                'field' => Decorator::field('attname'),
127
                'url'   => "colproperties.php?subject=column&amp;{$this->misc->href}&amp;view=" . urlencode($_REQUEST['matview']) . '&amp;',
128
                'vars'  => ['column' => 'attname'],
129
            ],
130
            'type'    => [
131
                'title' => $lang['strtype'],
132
                'field' => Decorator::field('+type'),
133
            ],
134
            'default' => [
135
                'title' => $lang['strdefault'],
136
                'field' => Decorator::field('adsrc'),
137
            ],
138
            'actions' => [
139
                'title' => $lang['stractions'],
140
            ],
141
            'comment' => [
142
                'title' => $lang['strcomment'],
143
                'field' => Decorator::field('comment'),
144
            ],
145
        ];
146
147
        $actions = [
148
            'alter' => [
149
                'content' => $lang['stralter'],
150
                'attr'    => [
151
                    'href' => [
152
                        'url'     => 'materializedviewproperties.php',
153
                        'urlvars' => [
154
                            'action' => 'properties',
155
                            'view'   => $_REQUEST['matview'],
156
                            'column' => Decorator::field('attname'),
157
                        ],
158
                    ],
159
                ],
160
            ],
161
        ];
162
163
        echo $this->printTable($attrs, $columns, $actions, 'materializedviewproperties-materializedviewproperties', null, $attPre);
164
165
        echo "<br />\n";
166
167
        $navlinks = [
168
            'browse' => [
169
                'attr'    => [
170
                    'href' => [
171
                        'url'     => 'display.php',
172
                        'urlvars' => [
173
                            'server'   => $_REQUEST['server'],
174
                            'database' => $_REQUEST['database'],
175
                            'schema'   => $_REQUEST['schema'],
176
                            'matview'  => $_REQUEST['matview'],
177
                            'subject'  => 'matview',
178
                            'return'   => 'matview',
179
                        ],
180
                    ],
181
                ],
182
                'content' => $lang['strbrowse'],
183
            ],
184
            'select' => [
185
                'attr'    => [
186
                    'href' => [
187
                        'url'     => 'materializedviews.php',
188
                        'urlvars' => [
189
                            'action'   => 'confselectrows',
190
                            'server'   => $_REQUEST['server'],
191
                            'database' => $_REQUEST['database'],
192
                            'schema'   => $_REQUEST['schema'],
193
                            'matview'  => $_REQUEST['matview'],
194
                        ],
195
                    ],
196
                ],
197
                'content' => $lang['strselect'],
198
            ],
199
            'drop'   => [
200
                'attr'    => [
201
                    'href' => [
202
                        'url'     => 'materializedviews.php',
203
                        'urlvars' => [
204
                            'action'   => 'confirm_drop',
205
                            'server'   => $_REQUEST['server'],
206
                            'database' => $_REQUEST['database'],
207
                            'schema'   => $_REQUEST['schema'],
208
                            'matview'  => $_REQUEST['matview'],
209
                        ],
210
                    ],
211
                ],
212
                'content' => $lang['strdrop'],
213
            ],
214
            'alter'  => [
215
                'attr'    => [
216
                    'href' => [
217
                        'url'     => 'materializedviewproperties.php',
218
                        'urlvars' => [
219
                            'action'   => 'confirm_alter',
220
                            'server'   => $_REQUEST['server'],
221
                            'database' => $_REQUEST['database'],
222
                            'schema'   => $_REQUEST['schema'],
223
                            'matview'  => $_REQUEST['matview'],
224
                        ],
225
                    ],
226
                ],
227
                'content' => $lang['stralter'],
228
            ],
229
        ];
230
231
        $this->printNavLinks($navlinks, 'materializedviewproperties-materializedviewproperties', get_defined_vars());
232
    }
233
234
    public function doTree()
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
235
    {
236
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
237
238
        $lang = $this->lang;
0 ignored issues
show
Unused Code introduced by
The assignment to $lang is dead and can be removed.
Loading history...
239
        $data = $this->misc->getDatabaseAccessor();
240
241
        $reqvars = $this->misc->getRequestVars('column');
242
        $columns = $data->getTableAttributes($_REQUEST['matview']);
243
244
        $attrs = [
245
            'text'       => Decorator::field('attname'),
246
            'action'     => Decorator::actionurl(
247
                'colproperties.php',
248
                $reqvars,
249
                [
250
                    'view'   => $_REQUEST['matview'],
251
                    'column' => Decorator::field('attname'),
252
                ]
253
            ),
254
            'icon'       => 'Column',
255
            'iconAction' => Decorator::url(
256
                'display.php',
257
                $reqvars,
258
                [
259
                    'view'   => $_REQUEST['matview'],
260
                    'column' => Decorator::field('attname'),
261
                    'query'  => Decorator::replace(
262
                        'SELECT "%column%", count(*) AS "count" FROM %view% GROUP BY "%column%" ORDER BY "%column%"',
263
                        [
264
                            '%column%' => Decorator::field('attname'),
265
                            '%view%'   => $_REQUEST['matview'],
266
                        ]
267
                    ),
268
                ]
269
            ),
270
            'toolTip'    => Decorator::field('comment'),
271
        ];
272
273
        return $this->printTree($columns, $attrs, 'viewcolumns');
274
    }
275
276
    /**
277
     * Function to save after editing a view
278
     */
279
    public function doSaveEdit()
280
    {
281
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
282
283
        $lang = $this->lang;
284
        $data = $this->misc->getDatabaseAccessor();
285
286
        $status = $data->setView($_POST['view'], $_POST['formDefinition'], $_POST['formComment']);
287
        if (0 == $status) {
288
            $this->doDefinition($lang['strviewupdated']);
289
        } else {
290
            $this->doEdit($lang['strviewupdatedbad']);
291
        }
292
    }
293
294
    /**
295
     * Function to allow editing of a view
296
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
297
     */
298
    public function doEdit($msg = '')
299
    {
300
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
301
302
        $lang = $this->lang;
303
        $data = $this->misc->getDatabaseAccessor();
304
305
        $this->printTrail('view');
306
        $this->printTitle($lang['stredit'], 'pg.matview.alter');
307
        $this->printMsg($msg);
308
309
        $viewdata = $data->getView($_REQUEST['matview']);
310
311
        if ($viewdata->recordCount() > 0) {
312
            if (!isset($_POST['formDefinition'])) {
313
                $_POST['formDefinition'] = $viewdata->fields['vwdefinition'];
314
                $_POST['formComment']    = $viewdata->fields['relcomment'];
315
            }
316
317
            echo '<form action="' . SUBFOLDER . "/src/views/materializedviewproperties.php\" method=\"post\">\n";
318
            echo "<table style=\"width: 100%\">\n";
319
            echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strdefinition']}</th>\n";
320
            echo "\t\t<td class=\"data1\"><textarea style=\"width: 100%;\" rows=\"20\" cols=\"50\" name=\"formDefinition\">",
321
            htmlspecialchars($_POST['formDefinition']), "</textarea></td>\n\t</tr>\n";
322
            echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
323
            echo "\t\t<td class=\"data1\"><textarea rows=\"3\" cols=\"32\" name=\"formComment\">",
324
            htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n";
325
            echo "</table>\n";
326
            echo "<p><input type=\"hidden\" name=\"action\" value=\"save_edit\" />\n";
327
            echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST['matview']), "\" />\n";
328
            echo $this->misc->form;
329
            echo "<input type=\"submit\" value=\"{$lang['stralter']}\" />\n";
330
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
331
            echo "</form>\n";
332
        } else {
333
            echo "<p>{$lang['strnodata']}</p>\n";
334
        }
335
    }
336
337
    /**
338
     * Allow the dumping of the data "in" a view
339
     * NOTE:: PostgreSQL doesn't currently support dumping the data in a view
340
     *        so I have disabled the data related parts for now. In the future
341
     *        we should allow it conditionally if it becomes supported.  This is
342
     *        a SMOP since it is based on pg_dump version not backend version.
343
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
344
     */
345
    public function doExport($msg = '')
346
    {
347
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
348
349
        $lang = $this->lang;
350
        $data = $this->misc->getDatabaseAccessor();
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
351
352
        $this->printTrail('view');
353
        $this->printTabs('view', 'export');
354
        $this->printMsg($msg);
355
356
        echo '<form action="' . SUBFOLDER . "/src/views/dataexport.php\" method=\"post\">\n";
357
        echo "<table>\n";
358
        echo "<tr><th class=\"data\">{$lang['strformat']}</th><th class=\"data\" colspan=\"2\">{$lang['stroptions']}</th></tr>\n";
359
        // Data only
360
        echo "<!--\n";
361
        echo '<tr><th class="data left">';
362
        echo "<input type=\"radio\" id=\"what1\" name=\"what\" value=\"dataonly\" /><label for=\"what1\">{$lang['strdataonly']}</label></th>\n";
363
        echo "<td>{$lang['strformat']}</td>\n";
364
        echo "<td><select name=\"d_format\" >\n";
365
        echo "<option value=\"copy\">COPY</option>\n";
366
        echo "<option value=\"sql\">SQL</option>\n";
367
        echo "<option value=\"csv\">CSV</option>\n";
368
        echo "<option value=\"tab\">{$lang['strtabbed']}</option>\n";
369
        echo "<option value=\"html\">XHTML</option>\n";
370
        echo "<option value=\"xml\">XML</option>\n";
371
        echo "</select>\n</td>\n</tr>\n";
372
        echo "-->\n";
373
374
        // Structure only
375
        echo "<tr><th class=\"data left\"><input type=\"radio\" id=\"what2\" name=\"what\" value=\"structureonly\" checked=\"checked\" /><label for=\"what2\">{$lang['strstructureonly']}</label></th>\n";
376
        echo "<td><label for=\"s_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"s_clean\" name=\"s_clean\" /></td>\n</tr>\n";
377
        // Structure and data
378
        echo "<!--\n";
379
        echo '<tr><th class="data left" rowspan="2">';
380
        echo "<input type=\"radio\" id=\"what3\" name=\"what\" value=\"structureanddata\" /><label for=\"what3\">{$lang['strstructureanddata']}</label></th>\n";
381
        echo "<td>{$lang['strformat']}</td>\n";
382
        echo "<td><select name=\"sd_format\">\n";
383
        echo "<option value=\"copy\">COPY</option>\n";
384
        echo "<option value=\"sql\">SQL</option>\n";
385
        echo "</select>\n</td>\n</tr>\n";
386
        echo "<td><label for=\"sd_clean\">{$lang['strdrop']}</label></td><td><input type=\"checkbox\" id=\"sd_clean\" name=\"sd_clean\" /></td>\n</tr>\n";
387
        echo "-->\n";
388
        echo "</table>\n";
389
390
        echo "<h3>{$lang['stroptions']}</h3>\n";
391
        echo "<p><input type=\"radio\" id=\"output1\" name=\"output\" value=\"show\" checked=\"checked\" /><label for=\"output1\">{$lang['strshow']}</label>\n";
392
        echo "<br/><input type=\"radio\" id=\"output2\" name=\"output\" value=\"download\" /><label for=\"output2\">{$lang['strdownload']}</label></p>\n";
393
394
        echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n";
395
        echo $this->misc->form;
396
        echo "<input type=\"hidden\" name=\"subject\" value=\"view\" />\n";
397
        echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST['matview']), "\" />\n";
398
        echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n";
399
        echo "</form>\n";
400
    }
401
402
    /**
403
     * Show definition for a view
404
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
405
     */
406
    public function doDefinition($msg = '')
407
    {
408
        $conf = $this->conf;
409
410
        $lang = $this->lang;
411
        $data = $this->misc->getDatabaseAccessor();
412
413
        // Get view
414
        $vdata = $data->getView($_REQUEST['matview']);
415
416
        $this->printTrail('view');
417
        $this->printTabs('view', 'definition');
418
        $this->printMsg($msg);
419
420
        if ($vdata->recordCount() > 0) {
421
            // Show comment if any
422
            if (null !== $vdata->fields['relcomment']) {
423
                echo '<p class="comment">', $this->misc->printVal($vdata->fields['relcomment']), "</p>\n";
424
            }
425
426
            echo "<table style=\"width: 100%\">\n";
427
            echo "<tr><th class=\"data\">{$lang['strdefinition']}</th></tr>\n";
428
            echo '<tr><td class="data1">', $this->misc->printVal($vdata->fields['vwdefinition']), "</td></tr>\n";
429
            echo "</table>\n";
430
        } else {
431
            echo "<p>{$lang['strnodata']}</p>\n";
432
        }
433
434
        $this->printNavLinks(['alter' => [
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...
435
            'attr'    => [
436
                'href' => [
437
                    'url'     => 'materializedviewproperties.php',
438
                    'urlvars' => [
439
                        'action'   => 'edit',
440
                        'server'   => $_REQUEST['server'],
441
                        'database' => $_REQUEST['database'],
442
                        'schema'   => $_REQUEST['schema'],
443
                        'view'     => $_REQUEST['matview'],
444
                    ],
445
                ],
446
            ],
447
            'content' => $lang['stralter'],
448
        ]], 'materializedviewproperties-definition', 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...
449
    }
450
451
    /**
452
     * Displays a screen where they can alter a column in a view
453
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
454
     */
455
    public function doProperties($msg = '')
456
    {
457
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
458
459
        $lang = $this->lang;
460
        $data = $this->misc->getDatabaseAccessor();
461
462
        if (!isset($_REQUEST['stage'])) {
463
            $_REQUEST['stage'] = 1;
464
        }
465
466
        switch ($_REQUEST['stage']) {
467
            case 1:
468
469
                $this->printTrail('column');
470
                $this->printTitle($lang['stralter'], 'pg.column.alter');
471
                $this->printMsg($msg);
472
473
                echo '<form action="' . SUBFOLDER . "/src/views/materializedviewproperties.php\" method=\"post\">\n";
474
475
                // Output view header
476
                echo "<table>\n";
477
                echo "<tr><th class=\"data required\">{$lang['strname']}</th><th class=\"data required\">{$lang['strtype']}</th>";
478
                echo "<th class=\"data\">{$lang['strdefault']}</th><th class=\"data\">{$lang['strcomment']}</th></tr>";
479
480
                $column = $data->getTableAttributes($_REQUEST['matview'], $_REQUEST['column']);
481
482
                if (!isset($_REQUEST['default'])) {
483
                    $_REQUEST['field']   = $column->fields['attname'];
484
                    $_REQUEST['default'] = $_REQUEST['olddefault'] = $column->fields['adsrc'];
485
                    $_REQUEST['comment'] = $column->fields['comment'];
486
                }
487
488
                echo '<tr><td><input name="field" size="32" value="',
489
                htmlspecialchars($_REQUEST['field']), '" /></td>';
490
491
                echo '<td>', $this->misc->printVal($data->formatType($column->fields['type'], $column->fields['atttypmod'])), '</td>';
492
                echo '<td><input name="default" size="20" value="',
493
                htmlspecialchars($_REQUEST['default']), '" /></td>';
494
                echo '<td><input name="comment" size="32" value="',
495
                htmlspecialchars($_REQUEST['comment']), '" /></td>';
496
497
                echo "</table>\n";
498
                echo "<p><input type=\"hidden\" name=\"action\" value=\"properties\" />\n";
499
                echo "<input type=\"hidden\" name=\"stage\" value=\"2\" />\n";
500
                echo $this->misc->form;
501
                echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST['matview']), "\" />\n";
502
                echo '<input type="hidden" name="column" value="', htmlspecialchars($_REQUEST['column']), "\" />\n";
503
                echo '<input type="hidden" name="olddefault" value="', htmlspecialchars($_REQUEST['olddefault']), "\" />\n";
504
                echo "<input type=\"submit\" value=\"{$lang['stralter']}\" />\n";
505
                echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
506
                echo "</form>\n";
507
508
                break;
509
            case 2:
510
511
                // Check inputs
512
                if ('' == trim($_REQUEST['field'])) {
513
                    $_REQUEST['stage'] = 1;
514
                    $this->doProperties($lang['strcolneedsname']);
515
516
                    return;
517
                }
518
519
                // Alter the view column
520
                list($status, $sql) = $data->alterColumn(
521
                    $_REQUEST['matview'],
522
                    $_REQUEST['column'],
523
                    $_REQUEST['field'],
524
                    false,
525
                    false,
526
                    $_REQUEST['default'],
527
                    $_REQUEST['olddefault'],
528
                    '',
529
                    '',
530
                    '',
531
                    '',
532
                    $_REQUEST['comment']
533
                );
534
                if (0 == $status) {
535
                    $this->doDefault($lang['strcolumnaltered']);
536
                } else {
537
                    $_REQUEST['stage'] = 1;
538
                    $this->doProperties($lang['strcolumnalteredbad']);
539
540
                    return;
541
                }
542
543
                break;
544
            default:
545
                echo "<p>{$lang['strinvalidparam']}</p>\n";
546
        }
547
    }
548
549
    public function doAlter($confirm = false, $msg = '')
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
550
    {
551
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
552
553
        $lang = $this->lang;
554
        $data = $this->misc->getDatabaseAccessor();
555
556
        if ($confirm) {
557
            $this->printTrail('view');
558
            $this->printTitle($lang['stralter'], 'pg.matview.alter');
559
            $this->printMsg($msg);
560
561
            // Fetch view info
562
            $view = $data->getView($_REQUEST['matview']);
563
564
            if ($view->recordCount() > 0) {
565
                if (!isset($_POST['name'])) {
566
                    $_POST['name'] = $view->fields['relname'];
567
                }
568
569
                if (!isset($_POST['owner'])) {
570
                    $_POST['owner'] = $view->fields['relowner'];
571
                }
572
573
                if (!isset($_POST['newschema'])) {
574
                    $_POST['newschema'] = $view->fields['nspname'];
575
                }
576
577
                if (!isset($_POST['comment'])) {
578
                    $_POST['comment'] = $view->fields['relcomment'];
579
                }
580
581
                echo '<form action="' . SUBFOLDER . "/src/views/materializedviewproperties.php\" method=\"post\">\n";
582
                echo "<table>\n";
583
                echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n";
584
                echo '<td class="data1">';
585
                echo "<input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
586
                htmlspecialchars($_POST['name']), "\" /></td></tr>\n";
587
588
                if ($data->isSuperUser()) {
589
                    // Fetch all users
590
                    $users = $data->getUsers();
591
592
                    echo "<tr><th class=\"data left required\">{$lang['strowner']}</th>\n";
593
                    echo '<td class="data1"><select name="owner">';
594
                    while (!$users->EOF) {
595
                        $uname = $users->fields['usename'];
596
                        echo '<option value="', htmlspecialchars($uname), '"',
597
                        ($uname == $_POST['owner']) ? ' selected="selected"' : '', '>', htmlspecialchars($uname), "</option>\n";
598
                        $users->moveNext();
599
                    }
600
                    echo "</select></td></tr>\n";
601
                }
602
603
                if ($data->hasAlterTableSchema()) {
604
                    $schemas = $data->getSchemas();
605
                    echo "<tr><th class=\"data left required\">{$lang['strschema']}</th>\n";
606
                    echo '<td class="data1"><select name="newschema">';
607
                    while (!$schemas->EOF) {
608
                        $schema = $schemas->fields['nspname'];
609
                        echo '<option value="', htmlspecialchars($schema), '"',
610
                        ($schema == $_POST['newschema']) ? ' selected="selected"' : '', '>', htmlspecialchars($schema), "</option>\n";
611
                        $schemas->moveNext();
612
                    }
613
                    echo "</select></td></tr>\n";
614
                }
615
616
                echo "<tr><th class=\"data left\">{$lang['strcomment']}</th>\n";
617
                echo '<td class="data1">';
618
                echo '<textarea rows="3" cols="32" name="comment">',
619
                htmlspecialchars($_POST['comment']), "</textarea></td></tr>\n";
620
                echo "</table>\n";
621
                echo "<input type=\"hidden\" name=\"action\" value=\"alter\" />\n";
622
                echo '<input type="hidden" name="view" value="', htmlspecialchars($_REQUEST['matview']), "\" />\n";
623
                echo $this->misc->form;
624
                echo "<p><input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n";
625
                echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
626
                echo "</form>\n";
627
            } else {
628
                echo "<p>{$lang['strnodata']}</p>\n";
629
            }
630
        } else {
631
            // For databases that don't allow owner change
632
            if (!isset($_POST['owner'])) {
633
                $_POST['owner'] = '';
634
            }
635
636
            if (!isset($_POST['newschema'])) {
637
                $_POST['newschema'] = null;
638
            }
639
640
            $status = $data->alterView($_POST['view'], $_POST['name'], $_POST['owner'], $_POST['newschema'], $_POST['comment']);
641
            if (0 == $status) {
642
                // If view has been renamed, need to change to the new name and
643
                // reload the browser frame.
644
                if ($_POST['view'] != $_POST['name']) {
645
                    // Jump them to the new view name
646
                    $_REQUEST['matview'] = $_POST['name'];
647
                    // Force a browser reload
648
                    $this->misc->setReloadBrowser(true);
649
                }
650
                // If schema has changed, need to change to the new schema and reload the browser
651
                if (!empty($_POST['newschema']) && ($_POST['newschema'] != $data->_schema)) {
652
                    // Jump them to the new sequence schema
653
                    $this->misc->setCurrentSchema($_POST['newschema']);
654
                    $this->misc->setReloadBrowser(true);
655
                }
656
                $this->doDefault($lang['strviewaltered']);
657
            } else {
658
                $this->doAlter(true, $lang['strviewalteredbad']);
659
            }
660
        }
661
    }
662
}
663