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

AlldbController   F

Complexity

Total Complexity 73

Size/Duplication

Total Lines 622
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 622
rs 2.3508
c 0
b 0
f 0
wmc 73

8 Methods

Rating   Name   Duplication   Size   Complexity  
C render() 0 62 13
A doTree() 0 22 1
C doDrop() 0 57 10
C doAlter() 0 65 12
B doDefault() 0 135 6
A doExport() 0 47 1
C doSaveCreate() 0 45 7
F doCreate() 0 130 23

How to fix   Complexity   

Complex Class

Complex classes like AlldbController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use AlldbController, and based on these observations, apply Extract Interface, too.

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 AlldbController extends BaseController
15
{
16
    public $controller_name = 'AlldbController';
17
    public $table_place     = 'alldb-databases';
18
19
    /**
20
     * Default method to render the controller according to the action parameter.
21
     */
22
    public function render()
23
    {
24
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
25
26
        $lang   = $this->lang;
27
        $action = $this->action;
28
29
        if ('tree' == $action) {
30
            return $this->doTree();
31
        }
32
33
        $this->printHeader($lang['strdatabases']);
34
        $this->printBody();
35
36
        switch ($action) {
37
            case 'export':
38
                $this->doExport();
39
40
                break;
41
            case 'save_create':
42
                if (isset($_POST['cancel'])) {
43
                    $this->doDefault();
44
                } else {
45
                    $this->doSaveCreate();
46
                }
47
48
                break;
49
            case 'create':
50
                $this->doCreate();
51
52
                break;
53
            case 'drop':
54
                if (isset($_REQUEST['drop'])) {
55
                    $this->doDrop(false);
56
                } else {
57
                    $this->doDefault();
58
                }
59
60
                break;
61
            case 'confirm_drop':
62
                $this->doDrop(true);
63
64
                break;
65
            case 'alter':
66
                if (isset($_POST['oldname'], $_POST['newname']) && !isset($_POST['cancel'])) {
67
                    $this->doAlter(false);
68
                } else {
69
                    $this->doDefault();
70
                }
71
72
                break;
73
            case 'confirm_alter':
74
                $this->doAlter(true);
75
76
                break;
77
            default:
78
                $this->doDefault();
79
80
                break;
81
        }
82
83
        return $this->printFooter();
84
    }
85
86
    /**
87
     * Show default list of databases in the server.
88
     *
89
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
90
     */
91
    public function doDefault($msg = '')
92
    {
93
        $conf = $this->conf;
94
95
        $lang = $this->lang;
96
97
        $this->printTrail('server');
98
        $this->printTabs('server', 'databases');
99
        $this->printMsg($msg);
100
        $data      = $this->misc->getDatabaseAccessor();
101
        $databases = $data->getDatabases();
102
103
        $columns = [
104
            'database' => [
105
                'title' => $lang['strdatabase'],
106
                'field' => Decorator::field('datname'),
107
                'url'   => \SUBFOLDER."/redirect/database?{$this->misc->href}&amp;",
108
                'vars'  => ['database' => 'datname'],
109
            ],
110
            'owner' => [
111
                'title' => $lang['strowner'],
112
                'field' => Decorator::field('datowner'),
113
            ],
114
            'encoding' => [
115
                'title' => $lang['strencoding'],
116
                'field' => Decorator::field('datencoding'),
117
            ],
118
            'lc_collate' => [
119
                'title' => $lang['strcollation'],
120
                'field' => Decorator::field('datcollate'),
121
            ],
122
            'lc_ctype' => [
123
                'title' => $lang['strctype'],
124
                'field' => Decorator::field('datctype'),
125
            ],
126
            'tablespace' => [
127
                'title' => $lang['strtablespace'],
128
                'field' => Decorator::field('tablespace'),
129
            ],
130
            'dbsize' => [
131
                'title' => $lang['strsize'],
132
                'field' => Decorator::field('dbsize'),
133
                'type'  => 'prettysize',
134
            ],
135
            'actions' => [
136
                'title' => $lang['stractions'],
137
            ],
138
            'comment' => [
139
                'title' => $lang['strcomment'],
140
                'field' => Decorator::field('datcomment'),
141
            ],
142
        ];
143
144
        $actions = [
145
            'multiactions' => [
146
                'keycols' => ['database' => 'datname'],
147
                'url'     => 'alldb.php',
148
                'default' => null,
149
            ],
150
            'drop' => [
151
                'content' => $lang['strdrop'],
152
                'attr'    => [
153
                    'href' => [
154
                        'url'     => 'alldb.php',
155
                        'urlvars' => [
156
                            'subject'      => 'database',
157
                            'action'       => 'confirm_drop',
158
                            'dropdatabase' => Decorator::field('datname'),
159
                        ],
160
                    ],
161
                ],
162
                'multiaction' => 'confirm_drop',
163
            ],
164
            'privileges' => [
165
                'content' => $lang['strprivileges'],
166
                'attr'    => [
167
                    'href' => [
168
                        'url'     => 'privileges.php',
169
                        'urlvars' => [
170
                            'subject'  => 'database',
171
                            'database' => Decorator::field('datname'),
172
                        ],
173
                    ],
174
                ],
175
            ],
176
        ];
177
        if ($data->hasAlterDatabase()) {
178
            $actions['alter'] = [
179
                'content' => $lang['stralter'],
180
                'attr'    => [
181
                    'href' => [
182
                        'url'     => 'alldb.php',
183
                        'urlvars' => [
184
                            'subject'       => 'database',
185
                            'action'        => 'confirm_alter',
186
                            'alterdatabase' => Decorator::field('datname'),
187
                        ],
188
                    ],
189
                ],
190
            ];
191
        }
192
193
        if (!$data->hasTablespaces()) {
194
            unset($columns['tablespace']);
195
        }
196
197
        if (!$data->hasServerAdminFuncs()) {
198
            unset($columns['dbsize']);
199
        }
200
201
        if (!$data->hasDatabaseCollation()) {
202
            unset($columns['lc_collate'], $columns['lc_ctype']);
203
        }
204
205
        if (!isset($data->privlist['database'])) {
206
            unset($actions['privileges']);
207
        }
208
209
        echo $this->printTable($databases, $columns, $actions, $this->table_place, $lang['strnodatabases']);
210
211
        $navlinks = [
212
            'create' => [
213
                'attr' => [
214
                    'href' => [
215
                        'url'     => 'alldb.php',
216
                        'urlvars' => [
217
                            'action' => 'create',
218
                            'server' => $_REQUEST['server'],
219
                        ],
220
                    ],
221
                ],
222
                'content' => $lang['strcreatedatabase'],
223
            ],
224
        ];
225
        $this->printNavLinks($navlinks, $this->table_place, get_defined_vars());
226
    }
227
228
    public function doTree()
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
229
    {
230
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
231
232
        $lang = $this->lang;
0 ignored issues
show
Unused Code introduced by
The assignment to $lang is dead and can be removed.
Loading history...
233
        $data = $this->misc->getDatabaseAccessor();
234
235
        $databases = $data->getDatabases();
236
237
        $reqvars = $this->misc->getRequestVars('database');
238
239
        //$this->prtrace($reqvars);
240
241
        $attrs = [
242
            'text'    => Decorator::field('datname'),
243
            'icon'    => 'Database',
244
            'toolTip' => Decorator::field('datcomment'),
245
            'action'  => Decorator::redirecturl('redirect.php', $reqvars, ['database' => Decorator::field('datname')]),
246
            'branch'  => Decorator::url('/src/views/database', $reqvars, ['action' => 'tree', 'database' => Decorator::field('datname')]),
247
        ];
248
249
        return $this->printTree($databases, $attrs, 'databases');
250
    }
251
252
    /**
253
     * Display a form for alter and perform actual alter.
254
     *
255
     * @param mixed $confirm
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
256
     */
257
    public function doAlter($confirm)
258
    {
259
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
260
261
        $lang = $this->lang;
262
        $data = $this->misc->getDatabaseAccessor();
263
264
        if ($confirm) {
265
            $this->printTrail('database');
266
            $this->printTitle($lang['stralter'], 'pg.database.alter');
267
268
            echo '<form action="'.\SUBFOLDER."/src/views/alldb.php\" method=\"post\">\n";
269
            echo "<table>\n";
270
            echo "<tr><th class=\"data left required\">{$lang['strname']}</th>\n";
271
            echo '<td class="data1">';
272
            echo "<input name=\"newname\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
273
            htmlspecialchars($_REQUEST['alterdatabase']), "\" /></td></tr>\n";
274
275
            if ($data->hasAlterDatabaseOwner() && $data->isSuperUser()) {
276
                // Fetch all users
277
278
                $rs    = $data->getDatabaseOwner($_REQUEST['alterdatabase']);
279
                $owner = isset($rs->fields['usename']) ? $rs->fields['usename'] : '';
280
                $users = $data->getUsers();
281
282
                echo "<tr><th class=\"data left required\">{$lang['strowner']}</th>\n";
283
                echo '<td class="data1"><select name="owner">';
284
                while (!$users->EOF) {
285
                    $uname = $users->fields['usename'];
286
                    echo '<option value="', htmlspecialchars($uname), '"',
287
                    ($uname == $owner) ? ' selected="selected"' : '', '>', htmlspecialchars($uname), "</option>\n";
288
                    $users->moveNext();
289
                }
290
                echo "</select></td></tr>\n";
291
            }
292
            if ($data->hasSharedComments()) {
293
                $rs      = $data->getDatabaseComment($_REQUEST['alterdatabase']);
294
                $comment = isset($rs->fields['description']) ? $rs->fields['description'] : '';
295
                echo "<tr><th class=\"data left\">{$lang['strcomment']}</th>\n";
296
                echo '<td class="data1">';
297
                echo '<textarea rows="3" cols="32" name="dbcomment">',
298
                htmlspecialchars($comment), "</textarea></td></tr>\n";
299
            }
300
            echo "</table>\n";
301
            echo "<input type=\"hidden\" name=\"action\" value=\"alter\" />\n";
302
            echo $this->misc->form;
303
            echo '<input type="hidden" name="oldname" value="',
304
            htmlspecialchars($_REQUEST['alterdatabase']), "\" />\n";
305
            echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n";
306
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
307
            echo "</form>\n";
308
        } else {
309
            if (!isset($_POST['owner'])) {
310
                $_POST['owner'] = '';
311
            }
312
313
            if (!isset($_POST['dbcomment'])) {
314
                $_POST['dbcomment'] = '';
315
            }
316
317
            if (0 == $data->alterDatabase($_POST['oldname'], $_POST['newname'], $_POST['owner'], $_POST['dbcomment'])) {
318
                $this->misc->setReloadBrowser(true);
319
                $this->doDefault($lang['strdatabasealtered']);
320
            } else {
321
                $this->doDefault($lang['strdatabasealteredbad']);
322
            }
323
        }
324
    }
325
326
    /**
327
     * Show confirmation of drop and perform actual drop.
328
     *
329
     * @param mixed $confirm
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
330
     */
331
    public function doDrop($confirm)
332
    {
333
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
334
335
        $lang = $this->lang;
336
        $data = $this->misc->getDatabaseAccessor();
337
338
        if (empty($_REQUEST['dropdatabase']) && empty($_REQUEST['ma'])) {
339
            return $this->doDefault($lang['strspecifydatabasetodrop']);
340
        }
341
342
        if ($confirm) {
343
            $this->printTrail('database');
344
            $this->printTitle($lang['strdrop'], 'pg.database.drop');
345
346
            echo '<form action="'.\SUBFOLDER."/src/views/alldb.php\" method=\"post\">\n";
347
            //If multi drop
348
            if (isset($_REQUEST['ma'])) {
349
                foreach ($_REQUEST['ma'] as $v) {
350
                    $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES));
351
                    echo '<p>', sprintf($lang['strconfdropdatabase'], $this->misc->printVal($a['database'])), "</p>\n";
352
                    printf('<input type="hidden" name="dropdatabase[]" value="%s" />', htmlspecialchars($a['database']));
353
                }
354
            } else {
355
                echo '<p>', sprintf($lang['strconfdropdatabase'], $this->misc->printVal($_REQUEST['dropdatabase'])), "</p>\n";
356
                echo '<input type="hidden" name="dropdatabase" value="', htmlspecialchars($_REQUEST['dropdatabase']), "\" />\n";
357
            } // END if multi drop
358
359
            echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n";
360
            echo $this->misc->form;
361
            echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
362
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
363
            echo "</form>\n";
364
        } // END confirm
365
        else {
0 ignored issues
show
Coding Style introduced by
Expected "} else \n"; found " // END confirm\n else {\n"
Loading history...
366
            //If multi drop
367
            if (is_array($_REQUEST['dropdatabase'])) {
368
                $msg = '';
369
                foreach ($_REQUEST['dropdatabase'] as $d) {
370
                    $status = $data->dropDatabase($d);
371
                    if (0 == $status) {
372
                        $msg .= sprintf('%s: %s<br />', htmlentities($d, ENT_QUOTES, 'UTF-8'), $lang['strdatabasedropped']);
373
                    } else {
374
                        $this->doDefault(sprintf('%s%s: %s<br />', $msg, htmlentities($d, ENT_QUOTES, 'UTF-8'), $lang['strdatabasedroppedbad']));
375
376
                        return;
377
                    }
378
                } // Everything went fine, back to Default page...
379
                $this->setReloadDropDatabase(true);
380
                $this->doDefault($msg);
381
            } else {
382
                $status = $data->dropDatabase($_POST['dropdatabase']);
383
                if (0 == $status) {
384
                    $this->setReloadDropDatabase(true);
385
                    $this->doDefault($lang['strdatabasedropped']);
386
                } else {
387
                    $this->doDefault($lang['strdatabasedroppedbad']);
388
                }
389
            }
390
        } //END DROP
391
    }
392
393
    // END FUNCTION
394
395
    /**
396
     * Displays a screen where they can enter a new database.
397
     *
398
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
399
     */
400
    public function doCreate($msg = '')
401
    {
402
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
403
404
        $lang = $this->lang;
405
        $data = $this->misc->getDatabaseAccessor();
406
407
        $this->printTrail('server');
408
        $this->printTitle($lang['strcreatedatabase'], 'pg.database.create');
409
        $this->printMsg($msg);
410
411
        if (!isset($_POST['formName'])) {
412
            $_POST['formName'] = '';
413
        }
414
415
        // Default encoding is that in language file
416
        if (!isset($_POST['formEncoding'])) {
417
            $_POST['formEncoding'] = '';
418
        }
419
        if (!isset($_POST['formTemplate'])) {
420
            $_POST['formTemplate'] = 'template1';
421
        }
422
423
        if (!isset($_POST['formSpc'])) {
424
            $_POST['formSpc'] = '';
425
        }
426
427
        if (!isset($_POST['formComment'])) {
428
            $_POST['formComment'] = '';
429
        }
430
431
        // Fetch a list of databases in the cluster
432
        $templatedbs = $data->getDatabases(false);
433
434
        // Fetch all tablespaces from the database
435
        if ($data->hasTablespaces()) {
436
            $tablespaces = $data->getTablespaces();
437
        }
438
439
        echo '<form action="'.\SUBFOLDER."/src/views/alldb.php\" method=\"post\">\n";
440
        echo "<table>\n";
441
        echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n";
442
        echo "\t\t<td class=\"data1\"><input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
443
        htmlspecialchars($_POST['formName']), "\" /></td>\n\t</tr>\n";
444
445
        echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strtemplatedb']}</th>\n";
446
        echo "\t\t<td class=\"data1\">\n";
447
        echo "\t\t\t<select name=\"formTemplate\">\n";
448
        // Always offer template0 and template1
449
        echo "\t\t\t\t<option value=\"template0\"",
450
        ('template0' == $_POST['formTemplate']) ? ' selected="selected"' : '', ">template0</option>\n";
451
        echo "\t\t\t\t<option value=\"template1\"",
452
        ('template1' == $_POST['formTemplate']) ? ' selected="selected"' : '', ">template1</option>\n";
453
        while (!$templatedbs->EOF) {
454
            $dbname = htmlspecialchars($templatedbs->fields['datname']);
455
            if ('template1' != $dbname) {
456
                // filter out for $conf[show_system] users so we dont get duplicates
457
                echo "\t\t\t\t<option value=\"{$dbname}\"",
458
                ($dbname == $_POST['formTemplate']) ? ' selected="selected"' : '', ">{$dbname}</option>\n";
459
            }
460
            $templatedbs->moveNext();
461
        }
462
        echo "\t\t\t</select>\n";
463
        echo "\t\t</td>\n\t</tr>\n";
464
465
        // ENCODING
466
        echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strencoding']}</th>\n";
467
        echo "\t\t<td class=\"data1\">\n";
468
        echo "\t\t\t<select name=\"formEncoding\">\n";
469
        echo "\t\t\t\t<option value=\"\"></option>\n";
470
        while (list($key) = each($data->codemap)) {
0 ignored issues
show
Deprecated Code introduced by
The function each() has been deprecated: 7.2 ( Ignorable by Annotation )

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

470
        while (list($key) = /** @scrutinizer ignore-deprecated */ each($data->codemap)) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
471
            echo "\t\t\t\t<option value=\"", htmlspecialchars($key), '"',
472
            ($key == $_POST['formEncoding']) ? ' selected="selected"' : '', '>',
473
            $this->misc->printVal($key), "</option>\n";
474
        }
475
        echo "\t\t\t</select>\n";
476
        echo "\t\t</td>\n\t</tr>\n";
477
478
        if ($data->hasDatabaseCollation()) {
479
            if (!isset($_POST['formCollate'])) {
480
                $_POST['formCollate'] = '';
481
            }
482
483
            if (!isset($_POST['formCType'])) {
484
                $_POST['formCType'] = '';
485
            }
486
487
            // LC_COLLATE
488
            echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcollation']}</th>\n";
489
            echo "\t\t<td class=\"data1\">\n";
490
            echo "\t\t\t<input name=\"formCollate\" value=\"", htmlspecialchars($_POST['formCollate']), "\" />\n";
491
            echo "\t\t</td>\n\t</tr>\n";
492
493
            // LC_CTYPE
494
            echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strctype']}</th>\n";
495
            echo "\t\t<td class=\"data1\">\n";
496
            echo "\t\t\t<input name=\"formCType\" value=\"", htmlspecialchars($_POST['formCType']), "\" />\n";
497
            echo "\t\t</td>\n\t</tr>\n";
498
        }
499
500
        // Tablespace (if there are any)
501
        if ($data->hasTablespaces() && $tablespaces->recordCount() > 0) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $tablespaces does not seem to be defined for all execution paths leading up to this point.
Loading history...
502
            echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strtablespace']}</th>\n";
503
            echo "\t\t<td class=\"data1\">\n\t\t\t<select name=\"formSpc\">\n";
504
            // Always offer the default (empty) option
505
            echo "\t\t\t\t<option value=\"\"",
506
            ('' == $_POST['formSpc']) ? ' selected="selected"' : '', "></option>\n";
507
            // Display all other tablespaces
508
            while (!$tablespaces->EOF) {
509
                $spcname = htmlspecialchars($tablespaces->fields['spcname']);
510
                echo "\t\t\t\t<option value=\"{$spcname}\"",
511
                ($spcname == $_POST['formSpc']) ? ' selected="selected"' : '', ">{$spcname}</option>\n";
512
                $tablespaces->moveNext();
513
            }
514
            echo "\t\t\t</select>\n\t\t</td>\n\t</tr>\n";
515
        }
516
517
        // Comments (if available)
518
        if ($data->hasSharedComments()) {
519
            echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
520
            echo "\t\t<td><textarea name=\"formComment\" rows=\"3\" cols=\"32\">",
521
            htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n";
522
        }
523
524
        echo "</table>\n";
525
        echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create\" />\n";
526
        echo $this->misc->form;
527
        echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n";
528
        echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
529
        echo "</form>\n";
530
    }
531
532
    /**
533
     * Actually creates the new view in the database.
534
     */
535
    public function doSaveCreate()
536
    {
537
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
538
539
        $lang = $this->lang;
540
        $data = $this->misc->getDatabaseAccessor();
541
542
        // Default tablespace to null if it isn't set
543
        if (!isset($_POST['formSpc'])) {
544
            $_POST['formSpc'] = null;
545
        }
546
547
        // Default comment to blank if it isn't set
548
        if (!isset($_POST['formComment'])) {
549
            $_POST['formComment'] = null;
550
        }
551
552
        // Default collate to blank if it isn't set
553
        if (!isset($_POST['formCollate'])) {
554
            $_POST['formCollate'] = null;
555
        }
556
557
        // Default ctype to blank if it isn't set
558
        if (!isset($_POST['formCType'])) {
559
            $_POST['formCType'] = null;
560
        }
561
562
        // Check that they've given a name and a definition
563
        if ('' == $_POST['formName']) {
564
            $this->doCreate($lang['strdatabaseneedsname']);
565
        } else {
566
            $status = $data->createDatabase(
567
                $_POST['formName'],
568
                $_POST['formEncoding'],
569
                $_POST['formSpc'],
570
                $_POST['formComment'],
571
                $_POST['formTemplate'],
572
                $_POST['formCollate'],
573
                $_POST['formCType']
574
            );
575
            if (0 == $status) {
576
                $this->misc->setReloadBrowser(true);
577
                $this->doDefault($lang['strdatabasecreated']);
578
            } else {
579
                $this->doCreate($lang['strdatabasecreatedbad']);
580
            }
581
        }
582
    }
583
584
    /**
585
     * Displays options for cluster download.
586
     *
587
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
588
     */
589
    public function doExport($msg = '')
590
    {
591
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
592
593
        $lang = $this->lang;
594
        $data = $this->misc->getDatabaseAccessor();
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
595
596
        $this->printTrail('server');
597
        $this->printTabs('server', 'export');
598
        $this->printMsg($msg);
599
600
        echo '<form action="'.\SUBFOLDER."/src/views/dbexport.php\" method=\"post\">\n";
601
        echo "<table>\n";
602
        echo "<tr><th class=\"data\">{$lang['strformat']}</th><th class=\"data\">{$lang['stroptions']}</th></tr>\n";
603
        // Data only
604
        echo '<tr><th class="data left" rowspan="2">';
605
        echo "<input type=\"radio\" id=\"what1\" name=\"what\" value=\"dataonly\" checked=\"checked\" /><label for=\"what1\">{$lang['strdataonly']}</label></th>\n";
606
        echo "<td>{$lang['strformat']}\n";
607
        echo "<select name=\"d_format\">\n";
608
        echo "<option value=\"copy\">COPY</option>\n";
609
        echo "<option value=\"sql\">SQL</option>\n";
610
        echo "</select>\n</td>\n</tr>\n";
611
        echo "<tr><td><input type=\"checkbox\" id=\"d_oids\" name=\"d_oids\" /><label for=\"d_oids\">{$lang['stroids']}</label></td>\n</tr>\n";
612
        // Structure only
613
        echo "<tr><th class=\"data left\"><input type=\"radio\" id=\"what2\" name=\"what\" value=\"structureonly\" /><label for=\"what2\">{$lang['strstructureonly']}</label></th>\n";
614
        echo "<td><input type=\"checkbox\" id=\"s_clean\" name=\"s_clean\" /><label for=\"s_clean\">{$lang['strdrop']}</label></td>\n</tr>\n";
615
        // Structure and data
616
        echo '<tr><th class="data left" rowspan="3">';
617
        echo "<input type=\"radio\" id=\"what3\" name=\"what\" value=\"structureanddata\" /><label for=\"what3\">{$lang['strstructureanddata']}</label></th>\n";
618
        echo "<td>{$lang['strformat']}\n";
619
        echo "<select name=\"sd_format\">\n";
620
        echo "<option value=\"copy\">COPY</option>\n";
621
        echo "<option value=\"sql\">SQL</option>\n";
622
        echo "</select>\n</td>\n</tr>\n";
623
        echo "<tr><td><input type=\"checkbox\" id=\"sd_clean\" name=\"sd_clean\" /><label for=\"sd_clean\">{$lang['strdrop']}</label></td>\n</tr>\n";
624
        echo "<tr><td><input type=\"checkbox\" id=\"sd_oids\" name=\"sd_oids\" /><label for=\"sd_oids\">{$lang['stroids']}</label></td>\n</tr>\n";
625
        echo "</table>\n";
626
627
        echo "<h3>{$lang['stroptions']}</h3>\n";
628
        echo "<p><input type=\"radio\" id=\"output1\" name=\"output\" value=\"show\" checked=\"checked\" /><label for=\"output1\">{$lang['strshow']}</label>\n";
629
        echo "<br/><input type=\"radio\" id=\"output2\" name=\"output\" value=\"download\" /><label for=\"output2\">{$lang['strdownload']}</label></p>\n";
630
631
        echo "<p><input type=\"hidden\" name=\"action\" value=\"export\" />\n";
632
        echo "<input type=\"hidden\" name=\"subject\" value=\"server\" />\n";
633
        echo $this->misc->form;
634
        echo "<input type=\"submit\" value=\"{$lang['strexport']}\" /></p>\n";
635
        echo "</form>\n";
636
    }
637
}
638