| Total Complexity | 132 |
| Total Lines | 1303 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
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 |
||
| 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() |
||
| 136 | } |
||
| 137 | |||
| 138 | public function doDefault($msg = '') |
||
| 217 | } |
||
| 218 | |||
| 219 | /** |
||
| 220 | * Generate XML for the browser tree. |
||
| 221 | */ |
||
| 222 | public function doTree() |
||
| 223 | { |
||
| 224 | $lang = $this->lang; |
||
| 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
|
|||
| 253 | { |
||
| 254 | $lang = $this->lang; |
||
| 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
|
|||
| 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
|
|||
| 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
|
|||
| 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
|
|||
| 426 | 'name' => $ftscfgs->fields['name'], |
||
| 427 | 'schema' => $ftscfgs->fields['schema'], |
||
| 428 | ]); |
||
|
1 ignored issue
–
show
|
|||
| 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
|
|||
| 448 | 'parser' => $ftsparsers->fields['name'], |
||
| 449 | 'schema' => $ftsparsers->fields['schema'], |
||
| 450 | ]); |
||
|
1 ignored issue
–
show
|
|||
| 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 !== '') { |
||
| 494 | return doCreateConfig($err); |
||
| 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
|
|||
| 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
|
|||
| 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
|
|||
| 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
|
|||
| 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
|
|||
| 723 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 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
|
|||
| 820 | */ |
||
| 821 | public function doCreateDict($msg = '') |
||
| 822 | { |
||
| 823 | $lang = $this->lang; |
||
| 824 | $data = $this->misc->getDatabaseAccessor(); |
||
| 825 | |||
| 826 | $server_info = $this->misc->getServerInfo(); |
||
| 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']), '" /> ', |
||
| 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
|
|||
| 882 | 'name' => $ftstpls->fields['name'], |
||
| 883 | 'schema' => $ftstpls->fields['schema'], |
||
| 884 | ]); |
||
|
1 ignored issue
–
show
|
|||
| 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; |
||
| 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
|
|||
| 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
|
|||
| 1070 | */ |
||
| 1071 | public function doDropMapping($confirm) |
||
| 1129 | } |
||
| 1130 | } |
||
| 1131 | } |
||
| 1132 | } |
||
| 1133 | |||
| 1134 | public function doAlterMapping($msg = '') |
||
|
1 ignored issue
–
show
|
|||
| 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"; |
||
| 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
|
|||
| 1233 | */ |
||
| 1234 | public function doAddMapping($msg = '') |
||
| 1300 | } |
||
| 1301 | } |
||
| 1302 | |||
| 1303 | /** |
||
| 1304 | * Save the form submission containing parameters of a new FTS mapping. |
||
| 1305 | */ |
||
| 1306 | public function doSaveAddMapping() |
||
| 1317 | } |
||
| 1318 | } |
||
| 1319 | } |
||
| 1320 |