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

doProperties()   C

Complexity

Conditions 7
Paths 12

Size

Total Lines 89
Code Lines 63

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 63
nc 12
nop 1
dl 0
loc 89
rs 6.5134
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 MaterializedviewpropertiesController extends BaseController
15
{
16
    public $controller_name = 'MaterializedviewpropertiesController';
17
18
    /**
19
     * Default method to render the controller according to the action parameter.
20
     */
21
    public function render()
22
    {
23
        $lang = $this->lang;
24
25
        $action = $this->action;
26
        if ('tree' == $action) {
27
            return $this->doTree();
28
        }
29
30
        $this->printHeader($lang['strviews'] . ' - ' . $_REQUEST['matview']);
31
        $this->printBody();
32
33
        switch ($action) {
34
            case 'save_edit':
35
                if (isset($_POST['cancel'])) {
36
                    $this->doDefinition();
37
                } else {
38
                    $this->doSaveEdit();
39
                }
40
41
                break;
42
            case 'edit':
43
                $this->doEdit();
44
45
                break;
46
            case 'export':
47
                $this->doExport();
48
49
                break;
50
            case 'definition':
51
                $this->doDefinition();
52
53
                break;
54
            case 'properties':
55
                if (isset($_POST['cancel'])) {
56
                    $this->doDefault();
57
                } else {
58
                    $this->doProperties();
59
                }
60
61
                break;
62
            case 'alter':
63
                if (isset($_POST['alter'])) {
64
                    $this->doAlter(false);
65
                } else {
66
                    $this->doDefault();
67
                }
68
69
                break;
70
            case 'confirm_alter':
71
                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

71
                /** @scrutinizer ignore-call */ 
72
                doAlter(true);
Loading history...
72
73
                break;
74
            case 'drop':
75
                if (isset($_POST['drop'])) {
76
                    $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

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