Passed
Push — master ( 442876...4ec1bc )
by Felipe
15:55 queued 10:33
created

FulltextController::doDropConfig()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 27
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 22
nc 3
nop 1
dl 0
loc 27
rs 8.8571
c 0
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
/*
4
 * PHPPgAdmin v6.0.0-beta.30
5
 */
6
7
namespace PHPPgAdmin\Controller;
8
9
use PHPPgAdmin\Decorators\Decorator;
10
11
/**
12
 * Base controller class.
13
 */
5 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
14
class 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
226
        $tabs  = $this->misc->getNavTabs('fulltext');
227
        $items = $this->adjustTabsForTree($tabs);
228
229
        $reqvars = $this->misc->getRequestVars('ftscfg');
230
231
        $attrs = [
232
            'text'   => Decorator::field('title'),
233
            'icon'   => Decorator::field('icon'),
234
            'action' => Decorator::actionurl(
235
                'fulltext.php',
236
                $reqvars,
237
                Decorator::field('urlvars')
238
            ),
239
            'branch' => Decorator::url(
240
                'fulltext.php',
241
                $reqvars,
242
                [
243
                    'action' => 'subtree',
244
                    'what'   => Decorator::field('icon'), // IZ: yeah, it's ugly, but I do not want to change navigation tabs arrays
245
                ]
246
            ),
247
        ];
248
249
        return $this->printTree($items, $attrs, 'fts');
250
    }
251
252
    public function doSubTree($what)
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
253
    {
254
        $lang = $this->lang;
0 ignored issues
show
Unused Code introduced by
The assignment to $lang is dead and can be removed.
Loading history...
255
        $data = $this->misc->getDatabaseAccessor();
256
257
        switch ($what) {
258
            case 'FtsCfg':
259
                $items   = $data->getFtsConfigurations(false);
260
                $urlvars = ['action' => 'viewconfig', 'ftscfg' => Decorator::field('name')];
261
262
                break;
263
            case 'FtsDict':
264
                $items   = $data->getFtsDictionaries(false);
265
                $urlvars = ['action' => 'viewdicts'];
266
267
                break;
268
            case 'FtsParser':
269
                $items   = $data->getFtsParsers(false);
270
                $urlvars = ['action' => 'viewparsers'];
271
272
                break;
273
            default:
274
                return;
275
        }
276
277
        $reqvars = $this->misc->getRequestVars('ftscfg');
278
279
        $attrs = [
280
            'text'    => Decorator::field('name'),
281
            'icon'    => $what,
282
            'toolTip' => Decorator::field('comment'),
283
            'action'  => Decorator::actionurl(
284
                'fulltext.php',
285
                $reqvars,
286
                $urlvars
287
            ),
288
            'branch'  => Decorator::ifempty(
289
                Decorator::field('branch'),
290
                '',
291
                Decorator::url(
292
                    'fulltext.php',
293
                    $reqvars,
294
                    [
295
                        'action' => 'subtree',
296
                        'ftscfg' => Decorator::field('name'),
297
                    ]
298
                )
299
            ),
300
        ];
301
302
        return $this->printTree($items, $attrs, strtolower($what));
303
    }
304
305
    public function doDropConfig($confirm)
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
306
    {
307
        $lang = $this->lang;
308
        $data = $this->misc->getDatabaseAccessor();
309
310
        if ($confirm) {
311
            $this->printTrail('ftscfg');
312
            $this->printTitle($lang['strdrop'], 'pg.ftscfg.drop');
313
314
            echo '<p>', sprintf($lang['strconfdropftsconfig'], $this->misc->printVal($_REQUEST['ftscfg'])), "</p>\n";
315
316
            echo '<form action="' . \SUBFOLDER . "/src/views/fulltext.php\" method=\"post\">\n";
317
            echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$lang['strcascade']}</label></p>\n";
318
            echo "<p><input type=\"hidden\" name=\"action\" value=\"dropconfig\" />\n";
319
            echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), "\" />\n";
320
            echo '<input type="hidden" name="ftscfg" value="', htmlspecialchars($_REQUEST['ftscfg']), "\" />\n";
321
            echo $this->misc->form;
322
            echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
323
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
324
            echo "</form>\n";
325
        } else {
326
            $status = $data->dropFtsConfiguration($_POST['ftscfg'], isset($_POST['cascade']));
327
            if (0 == $status) {
328
                $this->misc->setReloadBrowser(true);
329
                $this->doDefault($lang['strftsconfigdropped']);
330
            } else {
331
                $this->doDefault($lang['strftsconfigdroppedbad']);
332
            }
333
        }
334
    }
335
336
    public function doDropDict($confirm)
1 ignored issue
show
Coding Style introduced by
Missing function doc comment
Loading history...
337
    {
338
        $lang = $this->lang;
339
        $data = $this->misc->getDatabaseAccessor();
340
341
        if ($confirm) {
342
            $this->printTrail('ftscfg'); // TODO: change to smth related to dictionary
343
            $this->printTitle($lang['strdrop'], 'pg.ftsdict.drop');
344
345
            echo '<p>', sprintf($lang['strconfdropftsdict'], $this->misc->printVal($_REQUEST['ftsdict'])), "</p>\n";
346
347
            echo '<form action="' . \SUBFOLDER . "/src/views/fulltext.php\" method=\"post\">\n";
348
            echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$lang['strcascade']}</label></p>\n";
349
            echo "<p><input type=\"hidden\" name=\"action\" value=\"dropdict\" />\n";
350
            echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), "\" />\n";
351
            echo '<input type="hidden" name="ftsdict" value="', htmlspecialchars($_REQUEST['ftsdict']), "\" />\n";
352
            //echo "<input type=\"hidden\" name=\"ftscfg\" value=\"", htmlspecialchars($_REQUEST['ftscfg']), "\" />\n";
353
            echo "<input type=\"hidden\" name=\"prev_action\" value=\"viewdicts\" /></p>\n";
354
            echo $this->misc->form;
355
            echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n";
356
            echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n";
357
            echo "</form>\n";
358
        } else {
359
            $status = $data->dropFtsDictionary($_POST['ftsdict'], isset($_POST['cascade']));
360
            if (0 == $status) {
361
                $this->misc->setReloadBrowser(true);
362
                $this->doViewDicts($lang['strftsdictdropped']);
363
            } else {
364
                $this->doViewDicts($lang['strftsdictdroppedbad']);
365
            }
366
        }
367
    }
368
369
    /**
370
     * Displays a screen where one can enter a new FTS configuration.
371
     *
372
     * @param mixed $msg
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
373
     */
374
    public function doCreateConfig($msg = '')
375
    {
376
        $lang = $this->lang;
377
        $data = $this->misc->getDatabaseAccessor();
378
379
        if (!isset($_POST['formName'])) {
380
            $_POST['formName'] = '';
381
        }
382
383
        if (!isset($_POST['formParser'])) {
384
            $_POST['formParser'] = '';
385
        }
386
387
        if (!isset($_POST['formTemplate'])) {
388
            $_POST['formTemplate'] = '';
389
        }
390
391
        if (!isset($_POST['formWithMap'])) {
392
            $_POST['formWithMap'] = '';
393
        }
394
395
        if (!isset($_POST['formComment'])) {
396
            $_POST['formComment'] = '';
397
        }
398
399
        // Fetch all FTS configurations from the database
400
        $ftscfgs = $data->getFtsConfigurations();
401
        // Fetch all FTS parsers from the database
402
        $ftsparsers = $data->getFtsParsers();
403
404
        $this->printTrail('schema');
405
        $this->printTitle($lang['strftscreateconfig'], 'pg.ftscfg.create');
406
        $this->printMsg($msg);
407
408
        echo '<form action="' . \SUBFOLDER . "/src/views/fulltext.php\" method=\"post\">\n";
409
        echo "<table>\n";
410
        // conf name
411
        echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n";
412
        echo "\t\t<td class=\"data1\"><input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"",
413
        htmlspecialchars($_POST['formName']), "\" /></td>\n\t</tr>\n";
414
415
        // Template
416
        echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strftstemplate']}</th>\n";
417
        echo "\t\t<td class=\"data1\">";
418
419
        $tpls   = [];
420
        $tplsel = '';
421
        while (!$ftscfgs->EOF) {
422
            $data->fieldClean($ftscfgs->fields['schema']);
423
            $data->fieldClean($ftscfgs->fields['name']);
424
            $tplname        = $ftscfgs->fields['schema'] . '.' . $ftscfgs->fields['name'];
425
            $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...
426
                'name'   => $ftscfgs->fields['name'],
427
                'schema' => $ftscfgs->fields['schema'],
428
            ]);
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...
429
            if ($_POST['formTemplate'] == $tpls[$tplname]) {
430
                $tplsel = htmlspecialchars($tpls[$tplname]);
431
            }
432
            $ftscfgs->moveNext();
433
        }
434
        echo \PHPPgAdmin\XHtml\HTMLController::printCombo($tpls, 'formTemplate', true, $tplsel, false);
435
        echo "\n\t\t</td>\n\t</tr>\n";
436
437
        // Parser
438
        echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strftsparser']}</th>\n";
439
        echo "\t\t<td class=\"data1\">\n";
440
        $ftsparsers_ = [];
441
        $ftsparsel   = '';
442
        while (!$ftsparsers->EOF) {
443
            $data->fieldClean($ftsparsers->fields['schema']);
444
            $data->fieldClean($ftsparsers->fields['name']);
445
            $parsername = $ftsparsers->fields['schema'] . '.' . $ftsparsers->fields['name'];
446
447
            $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...
448
                'parser' => $ftsparsers->fields['name'],
449
                'schema' => $ftsparsers->fields['schema'],
450
            ]);
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...
451
            if ($_POST['formParser'] == $ftsparsers_[$parsername]) {
452
                $ftsparsel = htmlspecialchars($ftsparsers_[$parsername]);
453
            }
454
            $ftsparsers->moveNext();
455
        }
456
        echo \PHPPgAdmin\XHtml\HTMLController::printCombo($ftsparsers_, 'formParser', true, $ftsparsel, false);
457
        echo "\n\t\t</td>\n\t</tr>\n";
458
459
        // Comment
460
        echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n";
461
        echo "\t\t<td class=\"data1\"><textarea name=\"formComment\" rows=\"3\" cols=\"32\">",
462
        htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n";
463
464
        echo "</table>\n";
465
        echo "<p>\n";
466
        echo "<input type=\"hidden\" name=\"action\" value=\"createconfig\" />\n";
467
        echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), "\" />\n";
468
        echo $this->misc->form;
469
        echo "<input type=\"submit\" name=\"create\" value=\"{$lang['strcreate']}\" />\n";
470
        echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n";
471
        echo "</p>\n";
472
        echo "</form>\n";
473
    }
474
475
    /**
476
     * Actually creates the new FTS configuration in the database.
477
     */
478
    public function doSaveCreateConfig()
479
    {
480
        $lang = $this->lang;
481
        $data = $this->misc->getDatabaseAccessor();
482
483
        $err = '';
484
        // Check that they've given a name
485
        if ('' == $_POST['formName']) {
486
            $err .= "{$lang['strftsconfigneedsname']}<br />";
487
        }
488
489
        if (('' != $_POST['formParser']) && ('' != $_POST['formTemplate'])) {
490
            $err .= "{$lang['strftscantparsercopy']}<br />";
491
        }
492
493
        if ($err !== '') {
0 ignored issues
show
introduced by
The condition $err !== '' is always false.
Loading history...
494
            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

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