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

FulltextController   F

Complexity

Total Complexity 132

Size/Duplication

Total Lines 1306
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1306
rs 0.6314
c 0
b 0
f 0
wmc 132

22 Methods

Rating   Name   Duplication   Size   Complexity  
C doDropMapping() 0 58 10
F doCreateConfig() 0 101 10
D render() 0 115 26
B doAlterDict() 0 49 5
C doAddMapping() 0 66 10
B doDefault() 0 79 1
C doSaveCreateDict() 0 46 8
B doDropDict() 0 29 3
A doSaveAddMapping() 0 11 3
F doCreateDict() 0 114 13
A doSaveAlterDict() 0 10 2
B doViewDicts() 0 77 1
B doAlterConfig() 0 55 6
C doSaveCreateConfig() 0 37 8
B doViewParsers() 0 30 1
B doDropConfig() 0 27 3
B doTree() 0 29 1
B doSubTree() 0 51 4
A doSaveAlterConfig() 0 9 2
B doViewConfig() 0 89 1
A doSaveAlterMapping() 0 11 3
C doAlterMapping() 0 75 11

How to fix   Complexity   

Complex Class

Complex classes like FulltextController 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 FulltextController, 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 FulltextController extends BaseController
15
{
16
    public $controller_name = 'FulltextController';
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
        if ('subtree' == $action) {
30
            return $this->doSubTree($_REQUEST['what']);
31
        }
32
33
        $this->printHeader($lang['strschemas']);
34
        $this->printBody();
35
36
        if (isset($_POST['cancel'])) {
37
            if (isset($_POST['prev_action'])) {
38
                $action = $_POST['prev_action'];
39
            } else {
40
                $action = '';
41
            }
42
        }
43
44
        switch ($action) {
45
            case 'createconfig':
46
                if (isset($_POST['create'])) {
47
                    $this->doSaveCreateConfig();
48
                } else {
49
                    $this->doCreateConfig();
50
                }
51
52
                break;
53
            case 'alterconfig':
54
                if (isset($_POST['alter'])) {
55
                    $this->doSaveAlterConfig();
56
                } else {
57
                    $this->doAlterConfig();
58
                }
59
60
                break;
61
            case 'dropconfig':
62
                if (isset($_POST['drop'])) {
63
                    $this->doDropConfig(false);
64
                } else {
65
                    $this->doDropConfig(true);
66
                }
67
68
                break;
69
            case 'viewconfig':
70
                $this->doViewConfig($_REQUEST['ftscfg']);
71
72
                break;
73
            case 'viewparsers':
74
                $this->doViewParsers();
75
76
                break;
77
            case 'viewdicts':
78
                $this->doViewDicts();
79
80
                break;
81
            case 'createdict':
82
                if (isset($_POST['create'])) {
83
                    $this->doSaveCreateDict();
84
                } else {
85
                    doCreateDict();
0 ignored issues
show
Bug introduced by
The function doCreateDict 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

85
                    /** @scrutinizer ignore-call */ 
86
                    doCreateDict();
Loading history...
86
                }
87
88
                break;
89
            case 'alterdict':
90
                if (isset($_POST['alter'])) {
91
                    $this->doSaveAlterDict();
92
                } else {
93
                    $this->doAlterDict();
94
                }
95
96
                break;
97
            case 'dropdict':
98
                if (isset($_POST['drop'])) {
99
                    $this->doDropDict(false);
100
                } else {
101
                    $this->doDropDict(true);
102
                }
103
104
                break;
105
            case 'dropmapping':
106
                if (isset($_POST['drop'])) {
107
                    $this->doDropMapping(false);
108
                } else {
109
                    $this->doDropMapping(true);
110
                }
111
112
                break;
113
            case 'altermapping':
114
                if (isset($_POST['alter'])) {
115
                    $this->doSaveAlterMapping();
116
                } else {
117
                    $this->doAlterMapping();
118
                }
119
120
                break;
121
            case 'addmapping':
122
                if (isset($_POST['add'])) {
123
                    $this->doSaveAddMapping();
124
                } else {
125
                    $this->doAddMapping();
126
                }
127
128
                break;
129
            default:
130
                $this->doDefault();
131
132
                break;
133
        }
134
135
        return $this->printFooter();
136
    }
137
138
    public function doDefault($msg = '')
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
139
    {
140
        $lang = $this->lang;
141
        $data = $this->misc->getDatabaseAccessor();
142
143
        $this->printTrail('schema');
144
        $this->printTabs('schema', 'fulltext');
145
        $this->printTabs('fulltext', 'ftsconfigs');
146
        $this->printMsg($msg);
147
148
        $cfgs = $data->getFtsConfigurations(false);
149
150
        $columns = [
151
            'configuration' => [
152
                'title' => $lang['strftsconfig'],
153
                'field' => Decorator::field('name'),
154
                'url'   => "fulltext.php?action=viewconfig&amp;{$this->misc->href}&amp;",
155
                'vars'  => ['ftscfg' => 'name'],
156
            ],
157
            'schema'        => [
158
                'title' => $lang['strschema'],
159
                'field' => Decorator::field('schema'),
160
            ],
161
            'actions'       => [
162
                'title' => $lang['stractions'],
163
            ],
164
            'comment'       => [
165
                'title' => $lang['strcomment'],
166
                'field' => Decorator::field('comment'),
167
            ],
168
        ];
169
170
        $actions = [
171
            'drop'  => [
172
                'content' => $lang['strdrop'],
173
                'attr'    => [
174
                    'href' => [
175
                        'url'     => 'fulltext.php',
176
                        'urlvars' => [
177
                            'action' => 'dropconfig',
178
                            'ftscfg' => Decorator::field('name'),
179
                        ],
180
                    ],
181
                ],
182
            ],
183
            'alter' => [
184
                'content' => $lang['stralter'],
185
                'attr'    => [
186
                    'href' => [
187
                        'url'     => 'fulltext.php',
188
                        'urlvars' => [
189
                            'action' => 'alterconfig',
190
                            'ftscfg' => Decorator::field('name'),
191
                        ],
192
                    ],
193
                ],
194
            ],
195
        ];
196
197
        echo $this->printTable($cfgs, $columns, $actions, 'fulltext-fulltext', $lang['strftsnoconfigs']);
198
199
        $navlinks = [
200
            'createconf' => [
201
                'attr'    => [
202
                    'href' => [
203
                        'url'     => 'fulltext.php',
204
                        'urlvars' => [
205
                            'action'   => 'createconfig',
206
                            'server'   => $_REQUEST['server'],
207
                            'database' => $_REQUEST['database'],
208
                            'schema'   => $_REQUEST['schema'],
209
                        ],
210
                    ],
211
                ],
212
                'content' => $lang['strftscreateconfig'],
213
            ],
214
        ];
215
216
        $this->printNavLinks($navlinks, 'fulltext-fulltext', get_defined_vars());
217
    }
218
219
    /**
220
     * Generate XML for the browser tree.
221
     */
222
    public function doTree()
223
    {
224
        $lang = $this->lang;
0 ignored issues
show
Unused Code introduced by
The assignment to $lang is dead and can be removed.
Loading history...
225
        $data = $this->misc->getDatabaseAccessor();
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
226
227
        $tabs  = $this->misc->getNavTabs('fulltext');
228
        $items = $this->adjustTabsForTree($tabs);
229
230
        $reqvars = $this->misc->getRequestVars('ftscfg');
231
232
        $attrs = [
233
            'text'   => Decorator::field('title'),
234
            'icon'   => Decorator::field('icon'),
235
            'action' => Decorator::actionurl(
236
                'fulltext.php',
237
                $reqvars,
238
                Decorator::field('urlvars')
239
            ),
240
            'branch' => Decorator::url(
241
                'fulltext.php',
242
                $reqvars,
243
                [
244
                    'action' => 'subtree',
245
                    'what'   => Decorator::field('icon'), // IZ: yeah, it's ugly, but I do not want to change navigation tabs arrays
246
                ]
247
            ),
248
        ];
249
250
        return $this->printTree($items, $attrs, 'fts');
251
    }
252
253
    public function doSubTree($what)
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
254
    {
255
        $lang = $this->lang;
0 ignored issues
show
Unused Code introduced by
The assignment to $lang is dead and can be removed.
Loading history...
256
        $data = $this->misc->getDatabaseAccessor();
257
258
        switch ($what) {
259
            case 'FtsCfg':
260
                $items   = $data->getFtsConfigurations(false);
261
                $urlvars = ['action' => 'viewconfig', 'ftscfg' => Decorator::field('name')];
262
263
                break;
264
            case 'FtsDict':
265
                $items   = $data->getFtsDictionaries(false);
266
                $urlvars = ['action' => 'viewdicts'];
267
268
                break;
269
            case 'FtsParser':
270
                $items   = $data->getFtsParsers(false);
271
                $urlvars = ['action' => 'viewparsers'];
272
273
                break;
274
            default:
275
                return;
276
        }
277
278
        $reqvars = $this->misc->getRequestVars('ftscfg');
279
280
        $attrs = [
281
            'text'    => Decorator::field('name'),
282
            'icon'    => $what,
283
            'toolTip' => Decorator::field('comment'),
284
            'action'  => Decorator::actionurl(
285
                'fulltext.php',
286
                $reqvars,
287
                $urlvars
288
            ),
289
            'branch'  => Decorator::ifempty(
290
                Decorator::field('branch'),
291
                '',
292
                Decorator::url(
293
                    'fulltext.php',
294
                    $reqvars,
295
                    [
296
                        'action' => 'subtree',
297
                        'ftscfg' => Decorator::field('name'),
298
                    ]
299
                )
300
            ),
301
        ];
302
303
        return $this->printTree($items, $attrs, strtolower($what));
304
    }
305
306
    public function doDropConfig($confirm)
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
307
    {
308
        $lang = $this->lang;
309
        $data = $this->misc->getDatabaseAccessor();
310
311
        if ($confirm) {
312
            $this->printTrail('ftscfg');
313
            $this->printTitle($lang['strdrop'], 'pg.ftscfg.drop');
314
315
            echo '<p>', sprintf($lang['strconfdropftsconfig'], $this->misc->printVal($_REQUEST['ftscfg'])), "</p>\n";
316
317
            echo '<form action="' . \SUBFOLDER . "/src/views/fulltext.php\" method=\"post\">\n";
318
            echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$lang['strcascade']}</label></p>\n";
319
            echo "<p><input type=\"hidden\" name=\"action\" value=\"dropconfig\" />\n";
320
            echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), "\" />\n";
321
            echo '<input type="hidden" name="ftscfg" value="', htmlspecialchars($_REQUEST['ftscfg']), "\" />\n";
322
            echo $this->misc->form;
323
            echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
324
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
325
            echo "</form>\n";
326
        } else {
327
            $status = $data->dropFtsConfiguration($_POST['ftscfg'], isset($_POST['cascade']));
328
            if (0 == $status) {
329
                $this->misc->setReloadBrowser(true);
330
                $this->doDefault($lang['strftsconfigdropped']);
331
            } else {
332
                $this->doDefault($lang['strftsconfigdroppedbad']);
333
            }
334
        }
335
    }
336
337
    public function doDropDict($confirm)
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
338
    {
339
        $lang = $this->lang;
340
        $data = $this->misc->getDatabaseAccessor();
341
342
        if ($confirm) {
343
            $this->printTrail('ftscfg'); // TODO: change to smth related to dictionary
344
            $this->printTitle($lang['strdrop'], 'pg.ftsdict.drop');
345
346
            echo '<p>', sprintf($lang['strconfdropftsdict'], $this->misc->printVal($_REQUEST['ftsdict'])), "</p>\n";
347
348
            echo '<form action="' . \SUBFOLDER . "/src/views/fulltext.php\" method=\"post\">\n";
349
            echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$lang['strcascade']}</label></p>\n";
350
            echo "<p><input type=\"hidden\" name=\"action\" value=\"dropdict\" />\n";
351
            echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), "\" />\n";
352
            echo '<input type="hidden" name="ftsdict" value="', htmlspecialchars($_REQUEST['ftsdict']), "\" />\n";
353
            //echo "<input type=\"hidden\" name=\"ftscfg\" value=\"", htmlspecialchars($_REQUEST['ftscfg']), "\" />\n";
354
            echo "<input type=\"hidden\" name=\"prev_action\" value=\"viewdicts\" /></p>\n";
355
            echo $this->misc->form;
356
            echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
357
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
358
            echo "</form>\n";
359
        } else {
360
            $status = $data->dropFtsDictionary($_POST['ftsdict'], isset($_POST['cascade']));
361
            if (0 == $status) {
362
                $this->misc->setReloadBrowser(true);
363
                $this->doViewDicts($lang['strftsdictdropped']);
364
            } else {
365
                $this->doViewDicts($lang['strftsdictdroppedbad']);
366
            }
367
        }
368
    }
369
370
    /**
371
     * Displays a screen where one can enter a new FTS configuration.
372
     *
373
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
374
     */
375
    public function doCreateConfig($msg = '')
376
    {
377
        $lang = $this->lang;
378
        $data = $this->misc->getDatabaseAccessor();
379
380
        $server_info = $this->misc->getServerInfo();
0 ignored issues
show
Unused Code introduced by
The assignment to $server_info is dead and can be removed.
Loading history...
381
382
        if (!isset($_POST['formName'])) {
383
            $_POST['formName'] = '';
384
        }
385
386
        if (!isset($_POST['formParser'])) {
387
            $_POST['formParser'] = '';
388
        }
389
390
        if (!isset($_POST['formTemplate'])) {
391
            $_POST['formTemplate'] = '';
392
        }
393
394
        if (!isset($_POST['formWithMap'])) {
395
            $_POST['formWithMap'] = '';
396
        }
397
398
        if (!isset($_POST['formComment'])) {
399
            $_POST['formComment'] = '';
400
        }
401
402
        // Fetch all FTS configurations from the database
403
        $ftscfgs = $data->getFtsConfigurations();
404
        // Fetch all FTS parsers from the database
405
        $ftsparsers = $data->getFtsParsers();
406
407
        $this->printTrail('schema');
408
        $this->printTitle($lang['strftscreateconfig'], 'pg.ftscfg.create');
409
        $this->printMsg($msg);
410
411
        echo '<form action="' . \SUBFOLDER . "/src/views/fulltext.php\" method=\"post\">\n";
412
        echo "<table>\n";
413
        // conf name
414
        echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n";
415
        echo "\t\t<td class=\"data1\"><input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
416
        htmlspecialchars($_POST['formName']), "\" /></td>\n\t</tr>\n";
417
418
        // Template
419
        echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strftstemplate']}</th>\n";
420
        echo "\t\t<td class=\"data1\">";
421
422
        $tpls   = [];
423
        $tplsel = '';
424
        while (!$ftscfgs->EOF) {
425
            $data->fieldClean($ftscfgs->fields['schema']);
426
            $data->fieldClean($ftscfgs->fields['name']);
427
            $tplname        = $ftscfgs->fields['schema'] . '.' . $ftscfgs->fields['name'];
428
            $tpls[$tplname] = serialize([
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...
429
                'name'   => $ftscfgs->fields['name'],
430
                'schema' => $ftscfgs->fields['schema'],
431
            ]);
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...
432
            if ($_POST['formTemplate'] == $tpls[$tplname]) {
433
                $tplsel = htmlspecialchars($tpls[$tplname]);
434
            }
435
            $ftscfgs->moveNext();
436
        }
437
        echo \PHPPgAdmin\XHtml\HTMLController::printCombo($tpls, 'formTemplate', true, $tplsel, false);
438
        echo "\n\t\t</td>\n\t</tr>\n";
439
440
        // Parser
441
        echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strftsparser']}</th>\n";
442
        echo "\t\t<td class=\"data1\">\n";
443
        $ftsparsers_ = [];
444
        $ftsparsel   = '';
445
        while (!$ftsparsers->EOF) {
446
            $data->fieldClean($ftsparsers->fields['schema']);
447
            $data->fieldClean($ftsparsers->fields['name']);
448
            $parsername = $ftsparsers->fields['schema'] . '.' . $ftsparsers->fields['name'];
449
450
            $ftsparsers_[$parsername] = serialize([
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...
451
                'parser' => $ftsparsers->fields['name'],
452
                'schema' => $ftsparsers->fields['schema'],
453
            ]);
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...
454
            if ($_POST['formParser'] == $ftsparsers_[$parsername]) {
455
                $ftsparsel = htmlspecialchars($ftsparsers_[$parsername]);
456
            }
457
            $ftsparsers->moveNext();
458
        }
459
        echo \PHPPgAdmin\XHtml\HTMLController::printCombo($ftsparsers_, 'formParser', true, $ftsparsel, false);
460
        echo "\n\t\t</td>\n\t</tr>\n";
461
462
        // Comment
463
        echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
464
        echo "\t\t<td class=\"data1\"><textarea name=\"formComment\" rows=\"3\" cols=\"32\">",
465
        htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n";
466
467
        echo "</table>\n";
468
        echo "<p>\n";
469
        echo "<input type=\"hidden\" name=\"action\" value=\"createconfig\" />\n";
470
        echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), "\" />\n";
471
        echo $this->misc->form;
472
        echo "<input type=\"submit\" name=\"create\" value=\"{$lang['strcreate']}\" />\n";
473
        echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
474
        echo "</p>\n";
475
        echo "</form>\n";
476
    }
477
478
    /**
479
     * Actually creates the new FTS configuration in the database.
480
     */
481
    public function doSaveCreateConfig()
482
    {
483
        $lang = $this->lang;
484
        $data = $this->misc->getDatabaseAccessor();
485
486
        $err = '';
487
        // Check that they've given a name
488
        if ('' == $_POST['formName']) {
489
            $err .= "{$lang['strftsconfigneedsname']}<br />";
490
        }
491
492
        if (('' != $_POST['formParser']) && ('' != $_POST['formTemplate'])) {
493
            $err .= "{$lang['strftscantparsercopy']}<br />";
494
        }
495
496
        if ('' != $err) {
0 ignored issues
show
introduced by
The condition '' != $err can never be true.
Loading history...
497
            return doCreateConfig($err);
0 ignored issues
show
Bug introduced by
The function doCreateConfig 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

497
            return /** @scrutinizer ignore-call */ doCreateConfig($err);
Loading history...
498
        }
499
500
        if ('' != $_POST['formParser']) {
501
            $formParser = unserialize($_POST['formParser']);
502
        } else {
503
            $formParser = '';
504
        }
505
506
        if ('' != $_POST['formTemplate']) {
507
            $formTemplate = unserialize($_POST['formTemplate']);
508
        } else {
509
            $formTemplate = '';
510
        }
511
512
        $status = $data->createFtsConfiguration($_POST['formName'], $formParser, $formTemplate, $_POST['formComment']);
513
        if (0 == $status) {
514
            $this->misc->setReloadBrowser(true);
515
            $this->doDefault($lang['strftsconfigcreated']);
516
        } else {
517
            $this->doCreateConfig($lang['strftsconfigcreatedbad']);
518
        }
519
    }
520
521
    /**
522
     * Display a form to permit editing FTS configuration properies.
523
     *
524
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
525
     */
526
    public function doAlterConfig($msg = '')
527
    {
528
        $lang = $this->lang;
529
        $data = $this->misc->getDatabaseAccessor();
530
531
        $this->printTrail('ftscfg');
532
        $this->printTitle($lang['stralter'], 'pg.ftscfg.alter');
533
        $this->printMsg($msg);
534
535
        $ftscfg = $data->getFtsConfigurationByName($_REQUEST['ftscfg']);
536
        if ($ftscfg->recordCount() > 0) {
537
            if (!isset($_POST['formComment'])) {
538
                $_POST['formComment'] = $ftscfg->fields['comment'];
539
            }
540
541
            if (!isset($_POST['ftscfg'])) {
542
                $_POST['ftscfg'] = $_REQUEST['ftscfg'];
543
            }
544
545
            if (!isset($_POST['formName'])) {
546
                $_POST['formName'] = $_REQUEST['ftscfg'];
547
            }
548
549
            if (!isset($_POST['formParser'])) {
550
                $_POST['formParser'] = '';
551
            }
552
553
            // Fetch all FTS parsers from the database
554
            $ftsparsers = $data->getFtsParsers();
1 ignored issue
show
Unused Code introduced by
The assignment to $ftsparsers is dead and can be removed.
Loading history...
555
556
            echo '<form action="' . \SUBFOLDER . "/src/views/fulltext.php\" method=\"post\">\n";
557
            echo "<table>\n";
558
559
            echo "\t<tr>\n";
560
            echo "\t\t<th class=\"data left required\">{$lang['strname']}</th>\n";
561
            echo "\t\t<td class=\"data1\">";
562
            echo "\t\t\t<input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
563
            htmlspecialchars($_POST['formName']), "\" />\n";
564
            echo "\t\t</td>\n";
565
            echo "\t</tr>\n";
566
567
            // Comment
568
            echo "\t<tr>\n";
569
            echo "\t\t<th class=\"data\">{$lang['strcomment']}</th>\n";
570
            echo "\t\t<td class=\"data1\"><textarea cols=\"32\" rows=\"3\"name=\"formComment\">", htmlspecialchars($_POST['formComment']), "</textarea></td>\n";
571
            echo "\t</tr>\n";
572
            echo "</table>\n";
573
            echo "<p><input type=\"hidden\" name=\"action\" value=\"alterconfig\" />\n";
574
            echo '<input type="hidden" name="ftscfg" value="', htmlspecialchars($_POST['ftscfg']), "\" />\n";
575
            echo $this->misc->form;
576
            echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n";
577
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
578
            echo "</form>\n";
579
        } else {
580
            echo "<p>{$lang['strnodata']}</p>\n";
581
        }
582
    }
583
584
    /**
585
     * Save the form submission containing changes to a FTS configuration.
586
     */
587
    public function doSaveAlterConfig()
588
    {
589
        $lang   = $this->lang;
590
        $data   = $this->misc->getDatabaseAccessor();
591
        $status = $data->updateFtsConfiguration($_POST['ftscfg'], $_POST['formComment'], $_POST['formName']);
592
        if (0 == $status) {
593
            $this->doDefault($lang['strftsconfigaltered']);
594
        } else {
595
            $this->doAlterConfig($lang['strftsconfigalteredbad']);
596
        }
597
    }
598
599
    /**
600
     * View list of FTS parsers.
601
     *
602
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
603
     */
604
    public function doViewParsers($msg = '')
605
    {
606
        $lang = $this->lang;
607
        $data = $this->misc->getDatabaseAccessor();
608
609
        $this->printTrail('schema');
610
        $this->printTabs('schema', 'fulltext');
611
        $this->printTabs('fulltext', 'ftsparsers');
612
        $this->printMsg($msg);
613
614
        $parsers = $data->getFtsParsers(false);
615
616
        $columns = [
617
            'schema'  => [
618
                'title' => $lang['strschema'],
619
                'field' => Decorator::field('schema'),
620
            ],
621
            'name'    => [
622
                'title' => $lang['strname'],
623
                'field' => Decorator::field('name'),
624
            ],
625
            'comment' => [
626
                'title' => $lang['strcomment'],
627
                'field' => Decorator::field('comment'),
628
            ],
629
        ];
630
631
        $actions = [];
632
633
        echo $this->printTable($parsers, $columns, $actions, 'fulltext-viewparsers', $lang['strftsnoparsers']);
634
635
        //TODO: navlink to "create parser"
636
    }
637
638
    /**
639
     * View list of FTS dictionaries.
640
     *
641
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
642
     */
643
    public function doViewDicts($msg = '')
644
    {
645
        $lang = $this->lang;
646
        $data = $this->misc->getDatabaseAccessor();
647
648
        $this->printTrail('schema');
649
        $this->printTabs('schema', 'fulltext');
650
        $this->printTabs('fulltext', 'ftsdicts');
651
        $this->printMsg($msg);
652
653
        $dicts = $data->getFtsDictionaries(false);
654
655
        $columns = [
656
            'schema'  => [
657
                'title' => $lang['strschema'],
658
                'field' => Decorator::field('schema'),
659
            ],
660
            'name'    => [
661
                'title' => $lang['strname'],
662
                'field' => Decorator::field('name'),
663
            ],
664
            'actions' => [
665
                'title' => $lang['stractions'],
666
            ],
667
            'comment' => [
668
                'title' => $lang['strcomment'],
669
                'field' => Decorator::field('comment'),
670
            ],
671
        ];
672
673
        $actions = [
674
            'drop'  => [
675
                'content' => $lang['strdrop'],
676
                'attr'    => [
677
                    'href' => [
678
                        'url'     => 'fulltext.php',
679
                        'urlvars' => [
680
                            'action'  => 'dropdict',
681
                            'ftsdict' => Decorator::field('name'),
682
                        ],
683
                    ],
684
                ],
685
            ],
686
            'alter' => [
687
                'content' => $lang['stralter'],
688
                'attr'    => [
689
                    'href' => [
690
                        'url'     => 'fulltext.php',
691
                        'urlvars' => [
692
                            'action'  => 'alterdict',
693
                            'ftsdict' => Decorator::field('name'),
694
                        ],
695
                    ],
696
                ],
697
            ],
698
        ];
699
700
        echo $this->printTable($dicts, $columns, $actions, 'fulltext-viewdicts', $lang['strftsnodicts']);
701
702
        $navlinks = [
703
            'createdict' => [
704
                'attr'    => [
705
                    'href' => [
706
                        'url'     => 'fulltext.php',
707
                        'urlvars' => [
708
                            'action'   => 'createdict',
709
                            'server'   => $_REQUEST['server'],
710
                            'database' => $_REQUEST['database'],
711
                            'schema'   => $_REQUEST['schema'],
712
                        ],
713
                    ],
714
                ],
715
                'content' => $lang['strftscreatedict'],
716
            ],
717
        ];
718
719
        $this->printNavLinks($navlinks, 'fulltext-viewdicts', get_defined_vars());
720
    }
721
722
    /**
723
     * View details of FTS configuration given.
724
     *
725
     * @param mixed $ftscfg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
726
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
727
     */
728
    public function doViewConfig($ftscfg, $msg = '')
729
    {
730
        $lang = $this->lang;
731
        $data = $this->misc->getDatabaseAccessor();
732
733
        $this->printTrail('ftscfg');
734
        $this->printTabs('schema', 'fulltext');
735
        $this->printTabs('fulltext', 'ftsconfigs');
736
        $this->printMsg($msg);
737
738
        echo "<h3>{$lang['strftsconfigmap']}</h3>\n";
739
740
        $map = $data->getFtsConfigurationMap($ftscfg);
741
742
        $columns = [
743
            'name'         => [
744
                'title' => $lang['strftsmapping'],
745
                'field' => Decorator::field('name'),
746
            ],
747
            'dictionaries' => [
748
                'title' => $lang['strftsdicts'],
749
                'field' => Decorator::field('dictionaries'),
750
            ],
751
            'actions'      => [
752
                'title' => $lang['stractions'],
753
            ],
754
            'comment'      => [
755
                'title' => $lang['strcomment'],
756
                'field' => Decorator::field('description'),
757
            ],
758
        ];
759
760
        $actions = [
761
            'drop'         => [
762
                'multiaction' => 'dropmapping',
763
                'content'     => $lang['strdrop'],
764
                'attr'        => [
765
                    'href' => [
766
                        'url'     => 'fulltext.php',
767
                        'urlvars' => [
768
                            'action'  => 'dropmapping',
769
                            'mapping' => Decorator::field('name'),
770
                            'ftscfg'  => Decorator::field('cfgname'),
771
                        ],
772
                    ],
773
                ],
774
            ],
775
            'alter'        => [
776
                'content' => $lang['stralter'],
777
                'attr'    => [
778
                    'href' => [
779
                        'url'     => 'fulltext.php',
780
                        'urlvars' => [
781
                            'action'  => 'altermapping',
782
                            'mapping' => Decorator::field('name'),
783
                            'ftscfg'  => Decorator::field('cfgname'),
784
                        ],
785
                    ],
786
                ],
787
            ],
788
            'multiactions' => [
789
                'keycols' => ['mapping' => 'name'],
790
                'url'     => 'fulltext.php',
791
                'default' => null,
792
                'vars'    => ['ftscfg' => $ftscfg],
793
            ],
794
        ];
795
796
        echo $this->printTable($map, $columns, $actions, 'fulltext-viewconfig', $lang['strftsemptymap']);
797
798
        $navlinks = [
799
            'addmapping' => [
800
                'attr'    => [
801
                    'href' => [
802
                        'url'     => 'fulltext.php',
803
                        'urlvars' => [
804
                            'action'   => 'addmapping',
805
                            'server'   => $_REQUEST['server'],
806
                            'database' => $_REQUEST['database'],
807
                            'schema'   => $_REQUEST['schema'],
808
                            'ftscfg'   => $ftscfg,
809
                        ],
810
                    ],
811
                ],
812
                'content' => $lang['strftsaddmapping'],
813
            ],
814
        ];
815
816
        $this->printNavLinks($navlinks, 'fulltext-viewconfig', get_defined_vars());
817
    }
818
819
    /**
820
     * Displays a screen where one can enter a details of a new FTS dictionary.
821
     *
822
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
823
     */
824
    public function doCreateDict($msg = '')
825
    {
826
        $lang = $this->lang;
827
        $data = $this->misc->getDatabaseAccessor();
828
829
        $server_info = $this->misc->getServerInfo();
0 ignored issues
show
Unused Code introduced by
The assignment to $server_info is dead and can be removed.
Loading history...
830
831
        if (!isset($_POST['formName'])) {
832
            $_POST['formName'] = '';
833
        }
834
835
        if (!isset($_POST['formIsTemplate'])) {
836
            $_POST['formIsTemplate'] = false;
837
        }
838
839
        if (!isset($_POST['formTemplate'])) {
840
            $_POST['formTemplate'] = '';
841
        }
842
843
        if (!isset($_POST['formLexize'])) {
844
            $_POST['formLexize'] = '';
845
        }
846
847
        if (!isset($_POST['formInit'])) {
848
            $_POST['formInit'] = '';
849
        }
850
851
        if (!isset($_POST['formOption'])) {
852
            $_POST['formOption'] = '';
853
        }
854
855
        if (!isset($_POST['formComment'])) {
856
            $_POST['formComment'] = '';
857
        }
858
859
        // Fetch all FTS dictionaries from the database
860
        $ftstpls = $data->getFtsDictionaryTemplates();
861
862
        $this->printTrail('schema');
863
        // TODO: create doc links
864
        $this->printTitle($lang['strftscreatedict'], 'pg.ftsdict.create');
865
        $this->printMsg($msg);
866
867
        echo '<form action="' . \SUBFOLDER . "/src/views/fulltext.php\" method=\"post\">\n";
868
        echo "<table>\n";
869
        echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n";
870
        echo "\t\t<td class=\"data1\"><input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
871
        htmlspecialchars($_POST['formName']), '" />&nbsp;',
872
        '<input type="checkbox" name="formIsTemplate" id="formIsTemplate"', $_POST['formIsTemplate'] ? ' checked="checked" ' : '', " />\n",
873
            "<label for=\"formIsTemplate\">{$lang['strftscreatedicttemplate']}</label></td>\n\t</tr>\n";
874
875
        // Template
876
        echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strftstemplate']}</th>\n";
877
        echo "\t\t<td class=\"data1\">";
878
        $tpls   = [];
879
        $tplsel = '';
880
        while (!$ftstpls->EOF) {
881
            $data->fieldClean($ftstpls->fields['schema']);
882
            $data->fieldClean($ftstpls->fields['name']);
883
            $tplname        = $ftstpls->fields['schema'] . '.' . $ftstpls->fields['name'];
884
            $tpls[$tplname] = serialize([
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...
885
                'name'   => $ftstpls->fields['name'],
886
                'schema' => $ftstpls->fields['schema'],
887
            ]);
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...
888
            if ($_POST['formTemplate'] == $tpls[$tplname]) {
889
                $tplsel = htmlspecialchars($tpls[$tplname]);
890
            }
891
            $ftstpls->moveNext();
892
        }
893
        echo \PHPPgAdmin\XHtml\HTMLController::printCombo($tpls, 'formTemplate', true, $tplsel, false);
894
        echo "\n\t\t</td>\n\t</tr>\n";
895
896
        // TODO: what about maxlengths?
897
        // Lexize
898
        echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strftslexize']}</th>\n";
899
        echo "\t\t<td class=\"data1\"><input name=\"formLexize\" size=\"32\" maxlength=\"1000\" value=\"",
900
        htmlspecialchars($_POST['formLexize']), '" ', isset($_POST['formIsTemplate']) ? '' : ' disabled="disabled" ',
901
            "/></td>\n\t</tr>\n";
902
903
        // Init
904
        echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strftsinit']}</th>\n";
905
        echo "\t\t<td class=\"data1\"><input name=\"formInit\" size=\"32\" maxlength=\"1000\" value=\"",
906
        htmlspecialchars($_POST['formInit']), '"', @$_POST['formIsTemplate'] ? '' : ' disabled="disabled" ',
907
            "/></td>\n\t</tr>\n";
908
909
        // Option
910
        echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strftsoptionsvalues']}</th>\n";
911
        echo "\t\t<td class=\"data1\"><input name=\"formOption\" size=\"32\" maxlength=\"1000\" value=\"",
912
        htmlspecialchars($_POST['formOption']), "\" /></td>\n\t</tr>\n";
913
914
        // Comment
915
        echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
916
        echo "\t\t<td class=\"data1\"><textarea name=\"formComment\" rows=\"3\" cols=\"32\">",
917
        htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n";
918
919
        echo "</table>\n";
920
        echo "<p>\n";
921
        echo "<input type=\"hidden\" name=\"action\" value=\"createdict\" />\n";
922
        echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), "\" />\n";
923
        echo $this->misc->form;
924
        echo "<input type=\"submit\" name=\"create\" value=\"{$lang['strcreate']}\" />\n";
925
        echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
926
        echo "</p>\n";
927
        echo "</form>\n",
928
            "<script type=\"text/javascript\">
929
				function templateOpts() {
930
					isTpl = document.getElementsByName('formIsTemplate')[0].checked;
931
					{$this->document}.getElementsByName('formTemplate')[0].disabled = isTpl;
0 ignored issues
show
Bug Best Practice introduced by
The property document does not exist on PHPPgAdmin\Controller\FulltextController. Did you maybe forget to declare it?
Loading history...
932
					{$this->document}.getElementsByName('formOption')[0].disabled = isTpl;
933
					{$this->document}.getElementsByName('formLexize')[0].disabled = !isTpl;
934
					{$this->document}.getElementsByName('formInit')[0].disabled = !isTpl;
935
				}
936
937
				{$this->document}.getElementsByName('formIsTemplate')[0].onchange = templateOpts;
938
939
				templateOpts();
940
			</script>\n";
941
    }
942
943
    /**
944
     * Actually creates the new FTS dictionary in the database.
945
     */
946
    public function doSaveCreateDict()
947
    {
948
        $lang = $this->lang;
949
        $data = $this->misc->getDatabaseAccessor();
950
951
        // Check that they've given a name
952
        if ('' == $_POST['formName']) {
953
            $this->doCreateDict($lang['strftsdictneedsname']);
954
        } else {
955
            if (!isset($_POST['formIsTemplate'])) {
956
                $_POST['formIsTemplate'] = false;
957
            }
958
959
            if (isset($_POST['formTemplate'])) {
960
                $formTemplate = unserialize($_POST['formTemplate']);
961
            } else {
962
                $formTemplate = '';
963
            }
964
965
            if (!isset($_POST['formLexize'])) {
966
                $_POST['formLexize'] = '';
967
            }
968
969
            if (!isset($_POST['formInit'])) {
970
                $_POST['formInit'] = '';
971
            }
972
973
            if (!isset($_POST['formOption'])) {
974
                $_POST['formOption'] = '';
975
            }
976
977
            $status = $data->createFtsDictionary(
978
                $_POST['formName'],
979
                $_POST['formIsTemplate'],
980
                $formTemplate,
981
                $_POST['formLexize'],
982
                $_POST['formInit'],
983
                $_POST['formOption'],
984
                $_POST['formComment']
985
            );
986
987
            if (0 == $status) {
988
                $this->misc->setReloadBrowser(true);
989
                $this->doViewDicts($lang['strftsdictcreated']);
990
            } else {
991
                $this->doCreateDict($lang['strftsdictcreatedbad']);
992
            }
993
        }
994
    }
995
996
    /**
997
     * Display a form to permit editing FTS dictionary properies.
998
     *
999
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
1000
     */
1001
    public function doAlterDict($msg = '')
1002
    {
1003
        $lang = $this->lang;
1004
        $data = $this->misc->getDatabaseAccessor();
1005
1006
        $this->printTrail('ftscfg'); // TODO: change to smth related to dictionary
1007
        $this->printTitle($lang['stralter'], 'pg.ftsdict.alter');
1008
        $this->printMsg($msg);
1009
1010
        $ftsdict = $data->getFtsDictionaryByName($_REQUEST['ftsdict']);
1011
        if ($ftsdict->recordCount() > 0) {
1012
            if (!isset($_POST['formComment'])) {
1013
                $_POST['formComment'] = $ftsdict->fields['comment'];
1014
            }
1015
1016
            if (!isset($_POST['ftsdict'])) {
1017
                $_POST['ftsdict'] = $_REQUEST['ftsdict'];
1018
            }
1019
1020
            if (!isset($_POST['formName'])) {
1021
                $_POST['formName'] = $_REQUEST['ftsdict'];
1022
            }
1023
1024
            echo '<form action="' . \SUBFOLDER . "/src/views/fulltext.php\" method=\"post\">\n";
1025
            echo "<table>\n";
1026
1027
            echo "\t<tr>\n";
1028
            echo "\t\t<th class=\"data left required\">{$lang['strname']}</th>\n";
1029
            echo "\t\t<td class=\"data1\">";
1030
            echo "\t\t\t<input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
1031
            htmlspecialchars($_POST['formName']), "\" />\n";
1032
            echo "\t\t</td>\n";
1033
            echo "\t</tr>\n";
1034
1035
            // Comment
1036
            echo "\t<tr>\n";
1037
            echo "\t\t<th class=\"data\">{$lang['strcomment']}</th>\n";
1038
            echo "\t\t<td class=\"data1\"><textarea cols=\"32\" rows=\"3\"name=\"formComment\">", htmlspecialchars($_POST['formComment']), "</textarea></td>\n";
1039
            echo "\t</tr>\n";
1040
            echo "</table>\n";
1041
            echo "<p><input type=\"hidden\" name=\"action\" value=\"alterdict\" />\n";
1042
            echo '<input type="hidden" name="ftsdict" value="', htmlspecialchars($_POST['ftsdict']), "\" />\n";
1043
            echo "<input type=\"hidden\" name=\"prev_action\" value=\"viewdicts\" /></p>\n";
1044
            echo $this->misc->form;
1045
            echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n";
1046
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
1047
            echo "</form>\n";
1048
        } else {
1049
            echo "<p>{$lang['strnodata']}</p>\n";
1050
        }
1051
    }
1052
1053
    /**
1054
     * Save the form submission containing changes to a FTS dictionary.
1055
     */
1056
    public function doSaveAlterDict()
1057
    {
1058
        $lang = $this->lang;
1059
        $data = $this->misc->getDatabaseAccessor();
1060
1061
        $status = $data->updateFtsDictionary($_POST['ftsdict'], $_POST['formComment'], $_POST['formName']);
1062
        if (0 == $status) {
1063
            $this->doViewDicts($lang['strftsdictaltered']);
1064
        } else {
1065
            $this->doAlterDict($lang['strftsdictalteredbad']);
1066
        }
1067
    }
1068
1069
    /**
1070
     * Show confirmation of drop and perform actual drop of FTS mapping.
1071
     *
1072
     * @param mixed $confirm
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
1073
     */
1074
    public function doDropMapping($confirm)
1075
    {
1076
        $lang = $this->lang;
1077
        $data = $this->misc->getDatabaseAccessor();
1078
1079
        if (empty($_REQUEST['mapping']) && empty($_REQUEST['ma'])) {
1080
            $this->doDefault($lang['strftsspecifymappingtodrop']);
1081
1082
            return;
1083
        }
1084
1085
        if (empty($_REQUEST['ftscfg'])) {
1086
            $this->doDefault($lang['strftsspecifyconfigtoalter']);
1087
1088
            return;
1089
        }
1090
1091
        if ($confirm) {
1092
            $this->printTrail('ftscfg'); // TODO: proper breadcrumbs
1093
            $this->printTitle($lang['strdrop'], 'pg.ftscfg.alter');
1094
1095
            echo '<form action="' . \SUBFOLDER . "/src/views/fulltext.php\" method=\"post\">\n";
1096
1097
            // Case of multiaction drop
1098
            if (isset($_REQUEST['ma'])) {
1099
                foreach ($_REQUEST['ma'] as $v) {
1100
                    $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES));
1101
                    echo '<p>', sprintf($lang['strconfdropftsmapping'], $this->misc->printVal($a['mapping']), $this->misc->printVal($_REQUEST['ftscfg'])), "</p>\n";
1102
                    printf('<input type="hidden" name="mapping[]" value="%s" />', htmlspecialchars($a['mapping']));
1103
                }
1104
            } else {
1105
                echo '<p>', sprintf($lang['strconfdropftsmapping'], $this->misc->printVal($_REQUEST['mapping']), $this->misc->printVal($_REQUEST['ftscfg'])), "</p>\n";
1106
                echo '<input type="hidden" name="mapping" value="', htmlspecialchars($_REQUEST['mapping']), "\" />\n";
1107
            }
1108
1109
            echo "<input type=\"hidden\" name=\"ftscfg\" value=\"{$_REQUEST['ftscfg']}\" />\n";
1110
            echo "<input type=\"hidden\" name=\"action\" value=\"dropmapping\" />\n";
1111
            echo "<input type=\"hidden\" name=\"prev_action\" value=\"viewconfig\" /></p>\n";
1112
            echo $this->misc->form;
1113
            echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
1114
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
1115
            echo "</form>\n";
1116
        } else {
1117
            // Case of multiaction drop
1118
            if (is_array($_REQUEST['mapping'])) {
1119
                $status = $data->changeFtsMapping($_REQUEST['ftscfg'], $_REQUEST['mapping'], 'drop');
1120
                if (0 != $status) {
1121
                    $this->doViewConfig($_REQUEST['ftscfg'], $lang['strftsmappingdroppedbad']);
1122
1123
                    return;
1124
                }
1125
                $this->doViewConfig($_REQUEST['ftscfg'], $lang['strftsmappingdropped']);
1126
            } else {
1127
                $status = $data->changeFtsMapping($_REQUEST['ftscfg'], [$_REQUEST['mapping']], 'drop');
1128
                if (0 == $status) {
1129
                    $this->doViewConfig($_REQUEST['ftscfg'], $lang['strftsmappingdropped']);
1130
                } else {
1131
                    $this->doViewConfig($_REQUEST['ftscfg'], $lang['strftsmappingdroppedbad']);
1132
                }
1133
            }
1134
        }
1135
    }
1136
1137
    public function doAlterMapping($msg = '')
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
1138
    {
1139
        $lang = $this->lang;
1140
        $data = $this->misc->getDatabaseAccessor();
1141
        $this->printTrail('ftscfg');
1142
        $this->printTitle($lang['stralter'], 'pg.ftscfg.alter');
1143
        $this->printMsg($msg);
1144
1145
        $ftsdicts = $data->getFtsDictionaries();
1146
        if ($ftsdicts->recordCount() > 0) {
1147
            if (!isset($_POST['formMapping'])) {
1148
                $_POST['formMapping'] = @$_REQUEST['mapping'];
1149
            }
1150
1151
            if (!isset($_POST['formDictionary'])) {
1152
                $_POST['formDictionary'] = '';
1153
            }
1154
1155
            if (!isset($_POST['ftscfg'])) {
1156
                $_POST['ftscfg'] = $_REQUEST['ftscfg'];
1157
            }
1158
1159
            echo '<form action="' . \SUBFOLDER . "/src/views/fulltext.php\" method=\"post\">\n";
1160
1161
            echo "<table>\n";
1162
            echo "\t<tr>\n";
1163
            echo "\t\t<th class=\"data left required\">{$lang['strftsmapping']}</th>\n";
1164
            echo "\t\t<td class=\"data1\">";
1165
1166
            // Case of multiaction drop
1167
            if (isset($_REQUEST['ma'])) {
1168
                $ma_mappings       = [];
1169
                $ma_mappings_names = [];
1170
                foreach ($_REQUEST['ma'] as $v) {
1171
                    $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES));
1172
                    printf('<input type="hidden" name="formMapping[]" value="%s" />', htmlspecialchars($a['mapping']));
1173
                    $ma_mappings[]       = $data->getFtsMappingByName($_POST['ftscfg'], $a['mapping']);
1174
                    $ma_mappings_names[] = $a['mapping'];
1175
                }
1176
                echo implode(', ', $ma_mappings_names);
1177
            } else {
1178
                $mapping = $data->getFtsMappingByName($_POST['ftscfg'], $_POST['formMapping']);
1179
                echo $mapping->fields['name'];
1180
                echo '<input type="hidden" name="formMapping" value="', htmlspecialchars($_POST['formMapping']), "\" />\n";
1181
            }
1182
1183
            echo "\t\t</td>\n";
1184
            echo "\t</tr>\n";
1185
1186
            // Dictionary
1187
            echo "\t<tr>\n";
1188
            echo "\t\t<th class=\"data left required\">{$lang['strftsdict']}</th>\n";
1189
            echo "\t\t<td class=\"data1\">";
1190
            echo "\t\t\t<select name=\"formDictionary\">\n";
1191
            while (!$ftsdicts->EOF) {
1192
                $ftsdict = htmlspecialchars($ftsdicts->fields['name']);
1193
                echo "\t\t\t\t<option value=\"{$ftsdict}\"",
1194
                ($ftsdict == $_POST['formDictionary'] || $ftsdict == @$mapping->fields['dictionaries'] || $ftsdict == @$ma_mappings[0]->fields['dictionaries']) ? ' selected="selected"' : '', ">{$ftsdict}</option>\n";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ma_mappings does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $mapping does not seem to be defined for all execution paths leading up to this point.
Loading history...
1195
                $ftsdicts->moveNext();
1196
            }
1197
1198
            echo "\t\t</td>\n";
1199
            echo "\t</tr>\n";
1200
1201
            echo "</table>\n";
1202
            echo "<p><input type=\"hidden\" name=\"action\" value=\"altermapping\" />\n";
1203
            echo '<input type="hidden" name="ftscfg" value="', htmlspecialchars($_POST['ftscfg']), "\" />\n";
1204
            echo "<input type=\"hidden\" name=\"prev_action\" value=\"viewconfig\" /></p>\n";
1205
1206
            echo $this->misc->form;
1207
            echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n";
1208
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
1209
            echo "</form>\n";
1210
        } else {
1211
            echo "<p>{$lang['strftsnodictionaries']}</p>\n";
1212
        }
1213
    }
1214
1215
    /**
1216
     * Save the form submission containing changes to a FTS mapping.
1217
     */
1218
    public function doSaveAlterMapping()
1219
    {
1220
        $lang = $this->lang;
1221
        $data = $this->misc->getDatabaseAccessor();
1222
1223
        $mappingArray = (is_array($_POST['formMapping']) ? $_POST['formMapping'] : [$_POST['formMapping']]);
1224
        $status       = $data->changeFtsMapping($_POST['ftscfg'], $mappingArray, 'alter', $_POST['formDictionary']);
1225
        if (0 == $status) {
1226
            $this->doViewConfig($_POST['ftscfg'], $lang['strftsmappingaltered']);
1227
        } else {
1228
            $this->doAlterMapping($lang['strftsmappingalteredbad']);
1229
        }
1230
    }
1231
1232
    /**
1233
     * Show the form to enter parameters of a new FTS mapping.
1234
     *
1235
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
1236
     */
1237
    public function doAddMapping($msg = '')
1238
    {
1239
        $lang = $this->lang;
1240
        $data = $this->misc->getDatabaseAccessor();
1241
1242
        $this->printTrail('ftscfg');
1243
        $this->printTitle($lang['stralter'], 'pg.ftscfg.alter');
1244
        $this->printMsg($msg);
1245
1246
        $ftsdicts = $data->getFtsDictionaries();
1247
        if ($ftsdicts->recordCount() > 0) {
1248
            if (!isset($_POST['formMapping'])) {
1249
                $_POST['formMapping'] = '';
1250
            }
1251
1252
            if (!isset($_POST['formDictionary'])) {
1253
                $_POST['formDictionary'] = '';
1254
            }
1255
1256
            if (!isset($_POST['ftscfg'])) {
1257
                $_POST['ftscfg'] = $_REQUEST['ftscfg'];
1258
            }
1259
1260
            $mappings = $data->getFtsMappings($_POST['ftscfg']);
1261
1262
            echo '<form action="' . \SUBFOLDER . "/src/views/fulltext.php\" method=\"post\">\n";
1263
            echo "<table>\n";
1264
            echo "\t<tr>\n";
1265
            echo "\t\t<th class=\"data left required\">{$lang['strftsmapping']}</th>\n";
1266
            echo "\t\t<td class=\"data1\">";
1267
            echo "\t\t\t<select name=\"formMapping\">\n";
1268
            while (!$mappings->EOF) {
1269
                $mapping      = htmlspecialchars($mappings->fields['name']);
1270
                $mapping_desc = htmlspecialchars($mappings->fields['description']);
1271
                echo "\t\t\t\t<option value=\"{$mapping}\"",
1272
                $mapping == $_POST['formMapping'] ? ' selected="selected"' : '', ">{$mapping}", $mapping_desc ? " - {$mapping_desc}" : '', "</option>\n";
1273
                $mappings->moveNext();
1274
            }
1275
            echo "\t\t</td>\n";
1276
            echo "\t</tr>\n";
1277
1278
            // Dictionary
1279
            echo "\t<tr>\n";
1280
            echo "\t\t<th class=\"data left required\">{$lang['strftsdict']}</th>\n";
1281
            echo "\t\t<td class=\"data1\">";
1282
            echo "\t\t\t<select name=\"formDictionary\">\n";
1283
            while (!$ftsdicts->EOF) {
1284
                $ftsdict = htmlspecialchars($ftsdicts->fields['name']);
1285
                echo "\t\t\t\t<option value=\"{$ftsdict}\"",
1286
                $ftsdict == $_POST['formDictionary'] ? ' selected="selected"' : '', ">{$ftsdict}</option>\n";
1287
                $ftsdicts->moveNext();
1288
            }
1289
1290
            echo "\t\t</td>\n";
1291
            echo "\t</tr>\n";
1292
1293
            echo "</table>\n";
1294
            echo "<p><input type=\"hidden\" name=\"action\" value=\"addmapping\" />\n";
1295
            echo '<input type="hidden" name="ftscfg" value="', htmlspecialchars($_POST['ftscfg']), "\" />\n";
1296
            echo "<input type=\"hidden\" name=\"prev_action\" value=\"viewconfig\" /></p>\n";
1297
            echo $this->misc->form;
1298
            echo "<input type=\"submit\" name=\"add\" value=\"{$lang['stradd']}\" />\n";
1299
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
1300
            echo "</form>\n";
1301
        } else {
1302
            echo "<p>{$lang['strftsnodictionaries']}</p>\n";
1303
        }
1304
    }
1305
1306
    /**
1307
     * Save the form submission containing parameters of a new FTS mapping.
1308
     */
1309
    public function doSaveAddMapping()
1310
    {
1311
        $lang = $this->lang;
1312
        $data = $this->misc->getDatabaseAccessor();
1313
1314
        $mappingArray = (is_array($_POST['formMapping']) ? $_POST['formMapping'] : [$_POST['formMapping']]);
1315
        $status       = $data->changeFtsMapping($_POST['ftscfg'], $mappingArray, 'add', $_POST['formDictionary']);
1316
        if (0 == $status) {
1317
            $this->doViewConfig($_POST['ftscfg'], $lang['strftsmappingadded']);
1318
        } else {
1319
            $this->doAddMapping($lang['strftsmappingaddedbad']);
1320
        }
1321
    }
1322
}
1323