HuasoFoundries /
phpPgAdmin6
| 1 | <?php |
||
| 2 | |||
|
0 ignored issues
–
show
Coding Style
introduced
by
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 | */ |
||
| 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 | $conf = $this->conf; |
||
| 24 | |||
| 25 | $lang = $this->lang; |
||
| 26 | |||
| 27 | $action = $this->action; |
||
| 28 | if ('tree' == $action) { |
||
| 29 | return $this->doTree(); |
||
| 30 | } |
||
| 31 | if ('subtree' == $action) { |
||
| 32 | return $this->doSubTree($_REQUEST['what']); |
||
| 33 | } |
||
| 34 | |||
| 35 | $this->printHeader($lang['strschemas']); |
||
| 36 | $this->printBody(); |
||
| 37 | |||
| 38 | if (isset($_POST['cancel'])) { |
||
| 39 | if (isset($_POST['prev_action'])) { |
||
| 40 | $action = $_POST['prev_action']; |
||
| 41 | } else { |
||
| 42 | $action = ''; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | |||
| 46 | switch ($action) { |
||
| 47 | case 'createconfig': |
||
| 48 | if (isset($_POST['create'])) { |
||
| 49 | $this->doSaveCreateConfig(); |
||
| 50 | } else { |
||
| 51 | $this->doCreateConfig(); |
||
| 52 | } |
||
| 53 | |||
| 54 | break; |
||
| 55 | case 'alterconfig': |
||
| 56 | if (isset($_POST['alter'])) { |
||
| 57 | $this->doSaveAlterConfig(); |
||
| 58 | } else { |
||
| 59 | $this->doAlterConfig(); |
||
| 60 | } |
||
| 61 | |||
| 62 | break; |
||
| 63 | case 'dropconfig': |
||
| 64 | if (isset($_POST['drop'])) { |
||
| 65 | $this->doDropConfig(false); |
||
| 66 | } else { |
||
| 67 | $this->doDropConfig(true); |
||
| 68 | } |
||
| 69 | |||
| 70 | break; |
||
| 71 | case 'viewconfig': |
||
| 72 | $this->doViewConfig($_REQUEST['ftscfg']); |
||
| 73 | |||
| 74 | break; |
||
| 75 | case 'viewparsers': |
||
| 76 | $this->doViewParsers(); |
||
| 77 | |||
| 78 | break; |
||
| 79 | case 'viewdicts': |
||
| 80 | $this->doViewDicts(); |
||
| 81 | |||
| 82 | break; |
||
| 83 | case 'createdict': |
||
| 84 | if (isset($_POST['create'])) { |
||
| 85 | $this->doSaveCreateDict(); |
||
| 86 | } else { |
||
| 87 | doCreateDict(); |
||
| 88 | } |
||
| 89 | |||
| 90 | break; |
||
| 91 | case 'alterdict': |
||
| 92 | if (isset($_POST['alter'])) { |
||
| 93 | $this->doSaveAlterDict(); |
||
| 94 | } else { |
||
| 95 | $this->doAlterDict(); |
||
| 96 | } |
||
| 97 | |||
| 98 | break; |
||
| 99 | case 'dropdict': |
||
| 100 | if (isset($_POST['drop'])) { |
||
| 101 | $this->doDropDict(false); |
||
| 102 | } else { |
||
| 103 | $this->doDropDict(true); |
||
| 104 | } |
||
| 105 | |||
| 106 | break; |
||
| 107 | case 'dropmapping': |
||
| 108 | if (isset($_POST['drop'])) { |
||
| 109 | $this->doDropMapping(false); |
||
| 110 | } else { |
||
| 111 | $this->doDropMapping(true); |
||
| 112 | } |
||
| 113 | |||
| 114 | break; |
||
| 115 | case 'altermapping': |
||
| 116 | if (isset($_POST['alter'])) { |
||
| 117 | $this->doSaveAlterMapping(); |
||
| 118 | } else { |
||
| 119 | $this->doAlterMapping(); |
||
| 120 | } |
||
| 121 | |||
| 122 | break; |
||
| 123 | case 'addmapping': |
||
| 124 | if (isset($_POST['add'])) { |
||
| 125 | $this->doSaveAddMapping(); |
||
| 126 | } else { |
||
| 127 | $this->doAddMapping(); |
||
| 128 | } |
||
| 129 | |||
| 130 | break; |
||
| 131 | default: |
||
| 132 | $this->doDefault(); |
||
| 133 | |||
| 134 | break; |
||
| 135 | } |
||
| 136 | |||
| 137 | return $this->printFooter(); |
||
| 138 | } |
||
| 139 | |||
| 140 | public function doDefault($msg = '') |
||
| 141 | { |
||
| 142 | $conf = $this->conf; |
||
| 143 | |||
| 144 | $lang = $this->lang; |
||
| 145 | $data = $this->misc->getDatabaseAccessor(); |
||
| 146 | |||
| 147 | $this->printTrail('schema'); |
||
| 148 | $this->printTabs('schema', 'fulltext'); |
||
| 149 | $this->printTabs('fulltext', 'ftsconfigs'); |
||
| 150 | $this->printMsg($msg); |
||
| 151 | |||
| 152 | $cfgs = $data->getFtsConfigurations(false); |
||
| 153 | |||
| 154 | $columns = [ |
||
| 155 | 'configuration' => [ |
||
| 156 | 'title' => $lang['strftsconfig'], |
||
| 157 | 'field' => Decorator::field('name'), |
||
| 158 | 'url' => "fulltext.php?action=viewconfig&{$this->misc->href}&", |
||
| 159 | 'vars' => ['ftscfg' => 'name'], |
||
| 160 | ], |
||
| 161 | 'schema' => [ |
||
| 162 | 'title' => $lang['strschema'], |
||
| 163 | 'field' => Decorator::field('schema'), |
||
| 164 | ], |
||
| 165 | 'actions' => [ |
||
| 166 | 'title' => $lang['stractions'], |
||
| 167 | ], |
||
| 168 | 'comment' => [ |
||
| 169 | 'title' => $lang['strcomment'], |
||
| 170 | 'field' => Decorator::field('comment'), |
||
| 171 | ], |
||
| 172 | ]; |
||
| 173 | |||
| 174 | $actions = [ |
||
| 175 | 'drop' => [ |
||
| 176 | 'content' => $lang['strdrop'], |
||
| 177 | 'attr' => [ |
||
| 178 | 'href' => [ |
||
| 179 | 'url' => 'fulltext.php', |
||
| 180 | 'urlvars' => [ |
||
| 181 | 'action' => 'dropconfig', |
||
| 182 | 'ftscfg' => Decorator::field('name'), |
||
| 183 | ], |
||
| 184 | ], |
||
| 185 | ], |
||
| 186 | ], |
||
| 187 | 'alter' => [ |
||
| 188 | 'content' => $lang['stralter'], |
||
| 189 | 'attr' => [ |
||
| 190 | 'href' => [ |
||
| 191 | 'url' => 'fulltext.php', |
||
| 192 | 'urlvars' => [ |
||
| 193 | 'action' => 'alterconfig', |
||
| 194 | 'ftscfg' => Decorator::field('name'), |
||
| 195 | ], |
||
| 196 | ], |
||
| 197 | ], |
||
| 198 | ], |
||
| 199 | ]; |
||
| 200 | |||
| 201 | echo $this->printTable($cfgs, $columns, $actions, 'fulltext-fulltext', $lang['strftsnoconfigs']); |
||
| 202 | |||
| 203 | $navlinks = [ |
||
| 204 | 'createconf' => [ |
||
| 205 | 'attr' => [ |
||
| 206 | 'href' => [ |
||
| 207 | 'url' => 'fulltext.php', |
||
| 208 | 'urlvars' => [ |
||
| 209 | 'action' => 'createconfig', |
||
| 210 | 'server' => $_REQUEST['server'], |
||
| 211 | 'database' => $_REQUEST['database'], |
||
| 212 | 'schema' => $_REQUEST['schema'], |
||
| 213 | ], |
||
| 214 | ], |
||
| 215 | ], |
||
| 216 | 'content' => $lang['strftscreateconfig'], |
||
| 217 | ], |
||
| 218 | ]; |
||
| 219 | |||
| 220 | $this->printNavLinks($navlinks, 'fulltext-fulltext', get_defined_vars()); |
||
| 221 | } |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Generate XML for the browser tree. |
||
| 225 | */ |
||
| 226 | public function doTree() |
||
| 227 | { |
||
| 228 | $conf = $this->conf; |
||
| 229 | |||
| 230 | $lang = $this->lang; |
||
| 231 | $data = $this->misc->getDatabaseAccessor(); |
||
| 232 | |||
| 233 | $tabs = $this->misc->getNavTabs('fulltext'); |
||
| 234 | $items = $this->adjustTabsForTree($tabs); |
||
| 235 | |||
| 236 | $reqvars = $this->misc->getRequestVars('ftscfg'); |
||
| 237 | |||
| 238 | $attrs = [ |
||
| 239 | 'text' => Decorator::field('title'), |
||
| 240 | 'icon' => Decorator::field('icon'), |
||
| 241 | 'action' => Decorator::actionurl( |
||
| 242 | 'fulltext.php', |
||
| 243 | $reqvars, |
||
| 244 | Decorator::field('urlvars') |
||
| 245 | ), |
||
| 246 | 'branch' => Decorator::url( |
||
| 247 | 'fulltext.php', |
||
| 248 | $reqvars, |
||
| 249 | [ |
||
| 250 | 'action' => 'subtree', |
||
| 251 | 'what' => Decorator::field('icon'), // IZ: yeah, it's ugly, but I do not want to change navigation tabs arrays |
||
| 252 | ] |
||
| 253 | ), |
||
| 254 | ]; |
||
| 255 | |||
| 256 | return $this->printTree($items, $attrs, 'fts'); |
||
| 257 | } |
||
| 258 | |||
| 259 | public function doSubTree($what) |
||
| 260 | { |
||
| 261 | $conf = $this->conf; |
||
| 262 | |||
| 263 | $lang = $this->lang; |
||
| 264 | $data = $this->misc->getDatabaseAccessor(); |
||
| 265 | |||
| 266 | switch ($what) { |
||
| 267 | case 'FtsCfg': |
||
| 268 | $items = $data->getFtsConfigurations(false); |
||
| 269 | $urlvars = ['action' => 'viewconfig', 'ftscfg' => Decorator::field('name')]; |
||
| 270 | |||
| 271 | break; |
||
| 272 | case 'FtsDict': |
||
| 273 | $items = $data->getFtsDictionaries(false); |
||
| 274 | $urlvars = ['action' => 'viewdicts']; |
||
| 275 | |||
| 276 | break; |
||
| 277 | case 'FtsParser': |
||
| 278 | $items = $data->getFtsParsers(false); |
||
| 279 | $urlvars = ['action' => 'viewparsers']; |
||
| 280 | |||
| 281 | break; |
||
| 282 | default: |
||
| 283 | return; |
||
| 284 | } |
||
| 285 | |||
| 286 | $reqvars = $this->misc->getRequestVars('ftscfg'); |
||
| 287 | |||
| 288 | $attrs = [ |
||
| 289 | 'text' => Decorator::field('name'), |
||
| 290 | 'icon' => $what, |
||
| 291 | 'toolTip' => Decorator::field('comment'), |
||
| 292 | 'action' => Decorator::actionurl( |
||
| 293 | 'fulltext.php', |
||
| 294 | $reqvars, |
||
| 295 | $urlvars |
||
| 296 | ), |
||
| 297 | 'branch' => Decorator::ifempty( |
||
| 298 | Decorator::field('branch'), |
||
| 299 | '', |
||
| 300 | Decorator::url( |
||
| 301 | 'fulltext.php', |
||
| 302 | $reqvars, |
||
| 303 | [ |
||
| 304 | 'action' => 'subtree', |
||
| 305 | 'ftscfg' => Decorator::field('name'), |
||
| 306 | ] |
||
| 307 | ) |
||
| 308 | ), |
||
| 309 | ]; |
||
| 310 | |||
| 311 | return $this->printTree($items, $attrs, strtolower($what)); |
||
| 312 | } |
||
| 313 | |||
| 314 | public function doDropConfig($confirm) |
||
| 315 | { |
||
| 316 | $conf = $this->conf; |
||
| 317 | |||
| 318 | $lang = $this->lang; |
||
| 319 | $data = $this->misc->getDatabaseAccessor(); |
||
| 320 | |||
| 321 | if ($confirm) { |
||
| 322 | $this->printTrail('ftscfg'); |
||
| 323 | $this->printTitle($lang['strdrop'], 'pg.ftscfg.drop'); |
||
| 324 | |||
| 325 | echo '<p>', sprintf($lang['strconfdropftsconfig'], $this->misc->printVal($_REQUEST['ftscfg'])), "</p>\n"; |
||
| 326 | |||
| 327 | echo '<form action="'.\SUBFOLDER."/src/views/fulltext.php\" method=\"post\">\n"; |
||
| 328 | echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$lang['strcascade']}</label></p>\n"; |
||
| 329 | echo "<p><input type=\"hidden\" name=\"action\" value=\"dropconfig\" />\n"; |
||
| 330 | echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), "\" />\n"; |
||
| 331 | echo '<input type="hidden" name="ftscfg" value="', htmlspecialchars($_REQUEST['ftscfg']), "\" />\n"; |
||
| 332 | echo $this->misc->form; |
||
| 333 | echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n"; |
||
| 334 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 335 | echo "</form>\n"; |
||
| 336 | } else { |
||
| 337 | $status = $data->dropFtsConfiguration($_POST['ftscfg'], isset($_POST['cascade'])); |
||
| 338 | if (0 == $status) { |
||
| 339 | $this->misc->setReloadBrowser(true); |
||
| 340 | $this->doDefault($lang['strftsconfigdropped']); |
||
| 341 | } else { |
||
| 342 | $this->doDefault($lang['strftsconfigdroppedbad']); |
||
| 343 | } |
||
| 344 | } |
||
| 345 | } |
||
| 346 | |||
| 347 | public function doDropDict($confirm) |
||
| 348 | { |
||
| 349 | $conf = $this->conf; |
||
| 350 | |||
| 351 | $lang = $this->lang; |
||
| 352 | $data = $this->misc->getDatabaseAccessor(); |
||
| 353 | |||
| 354 | if ($confirm) { |
||
| 355 | $this->printTrail('ftscfg'); // TODO: change to smth related to dictionary |
||
| 356 | $this->printTitle($lang['strdrop'], 'pg.ftsdict.drop'); |
||
| 357 | |||
| 358 | echo '<p>', sprintf($lang['strconfdropftsdict'], $this->misc->printVal($_REQUEST['ftsdict'])), "</p>\n"; |
||
| 359 | |||
| 360 | echo '<form action="'.\SUBFOLDER."/src/views/fulltext.php\" method=\"post\">\n"; |
||
| 361 | echo "<p><input type=\"checkbox\" id=\"cascade\" name=\"cascade\" /> <label for=\"cascade\">{$lang['strcascade']}</label></p>\n"; |
||
| 362 | echo "<p><input type=\"hidden\" name=\"action\" value=\"dropdict\" />\n"; |
||
| 363 | echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), "\" />\n"; |
||
| 364 | echo '<input type="hidden" name="ftsdict" value="', htmlspecialchars($_REQUEST['ftsdict']), "\" />\n"; |
||
| 365 | //echo "<input type=\"hidden\" name=\"ftscfg\" value=\"", htmlspecialchars($_REQUEST['ftscfg']), "\" />\n"; |
||
| 366 | echo "<input type=\"hidden\" name=\"prev_action\" value=\"viewdicts\" /></p>\n"; |
||
| 367 | echo $this->misc->form; |
||
| 368 | echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n"; |
||
| 369 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 370 | echo "</form>\n"; |
||
| 371 | } else { |
||
| 372 | $status = $data->dropFtsDictionary($_POST['ftsdict'], isset($_POST['cascade'])); |
||
| 373 | if (0 == $status) { |
||
| 374 | $this->misc->setReloadBrowser(true); |
||
| 375 | $this->doViewDicts($lang['strftsdictdropped']); |
||
| 376 | } else { |
||
| 377 | $this->doViewDicts($lang['strftsdictdroppedbad']); |
||
| 378 | } |
||
| 379 | } |
||
| 380 | } |
||
| 381 | |||
| 382 | /** |
||
| 383 | * Displays a screen where one can enter a new FTS configuration. |
||
| 384 | * |
||
| 385 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 386 | */ |
||
| 387 | public function doCreateConfig($msg = '') |
||
| 388 | { |
||
| 389 | $conf = $this->conf; |
||
| 390 | |||
| 391 | $lang = $this->lang; |
||
| 392 | $data = $this->misc->getDatabaseAccessor(); |
||
| 393 | |||
| 394 | $server_info = $this->misc->getServerInfo(); |
||
| 395 | |||
| 396 | if (!isset($_POST['formName'])) { |
||
| 397 | $_POST['formName'] = ''; |
||
| 398 | } |
||
| 399 | |||
| 400 | if (!isset($_POST['formParser'])) { |
||
| 401 | $_POST['formParser'] = ''; |
||
| 402 | } |
||
| 403 | |||
| 404 | if (!isset($_POST['formTemplate'])) { |
||
| 405 | $_POST['formTemplate'] = ''; |
||
| 406 | } |
||
| 407 | |||
| 408 | if (!isset($_POST['formWithMap'])) { |
||
| 409 | $_POST['formWithMap'] = ''; |
||
| 410 | } |
||
| 411 | |||
| 412 | if (!isset($_POST['formComment'])) { |
||
| 413 | $_POST['formComment'] = ''; |
||
| 414 | } |
||
| 415 | |||
| 416 | // Fetch all FTS configurations from the database |
||
| 417 | $ftscfgs = $data->getFtsConfigurations(); |
||
| 418 | // Fetch all FTS parsers from the database |
||
| 419 | $ftsparsers = $data->getFtsParsers(); |
||
| 420 | |||
| 421 | $this->printTrail('schema'); |
||
| 422 | $this->printTitle($lang['strftscreateconfig'], 'pg.ftscfg.create'); |
||
| 423 | $this->printMsg($msg); |
||
| 424 | |||
| 425 | echo '<form action="'.\SUBFOLDER."/src/views/fulltext.php\" method=\"post\">\n"; |
||
| 426 | echo "<table>\n"; |
||
| 427 | // conf name |
||
| 428 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n"; |
||
| 429 | echo "\t\t<td class=\"data1\"><input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 430 | htmlspecialchars($_POST['formName']), "\" /></td>\n\t</tr>\n"; |
||
| 431 | |||
| 432 | // Template |
||
| 433 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strftstemplate']}</th>\n"; |
||
| 434 | echo "\t\t<td class=\"data1\">"; |
||
| 435 | |||
| 436 | $tpls = []; |
||
| 437 | $tplsel = ''; |
||
| 438 | while (!$ftscfgs->EOF) { |
||
| 439 | $data->fieldClean($ftscfgs->fields['schema']); |
||
| 440 | $data->fieldClean($ftscfgs->fields['name']); |
||
| 441 | $tplname = $ftscfgs->fields['schema'].'.'.$ftscfgs->fields['name']; |
||
| 442 | $tpls[$tplname] = serialize([ |
||
| 443 | 'name' => $ftscfgs->fields['name'], |
||
| 444 | 'schema' => $ftscfgs->fields['schema'], |
||
| 445 | ]); |
||
| 446 | if ($_POST['formTemplate'] == $tpls[$tplname]) { |
||
| 447 | $tplsel = htmlspecialchars($tpls[$tplname]); |
||
| 448 | } |
||
| 449 | $ftscfgs->moveNext(); |
||
| 450 | } |
||
| 451 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($tpls, 'formTemplate', true, $tplsel, false); |
||
| 452 | echo "\n\t\t</td>\n\t</tr>\n"; |
||
| 453 | |||
| 454 | // Parser |
||
| 455 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strftsparser']}</th>\n"; |
||
| 456 | echo "\t\t<td class=\"data1\">\n"; |
||
| 457 | $ftsparsers_ = []; |
||
| 458 | $ftsparsel = ''; |
||
| 459 | while (!$ftsparsers->EOF) { |
||
| 460 | $data->fieldClean($ftsparsers->fields['schema']); |
||
| 461 | $data->fieldClean($ftsparsers->fields['name']); |
||
| 462 | $parsername = $ftsparsers->fields['schema'].'.'.$ftsparsers->fields['name']; |
||
| 463 | |||
| 464 | $ftsparsers_[$parsername] = serialize([ |
||
| 465 | 'parser' => $ftsparsers->fields['name'], |
||
| 466 | 'schema' => $ftsparsers->fields['schema'], |
||
| 467 | ]); |
||
| 468 | if ($_POST['formParser'] == $ftsparsers_[$parsername]) { |
||
| 469 | $ftsparsel = htmlspecialchars($ftsparsers_[$parsername]); |
||
| 470 | } |
||
| 471 | $ftsparsers->moveNext(); |
||
| 472 | } |
||
| 473 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($ftsparsers_, 'formParser', true, $ftsparsel, false); |
||
| 474 | echo "\n\t\t</td>\n\t</tr>\n"; |
||
| 475 | |||
| 476 | // Comment |
||
| 477 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n"; |
||
| 478 | echo "\t\t<td class=\"data1\"><textarea name=\"formComment\" rows=\"3\" cols=\"32\">", |
||
| 479 | htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n"; |
||
| 480 | |||
| 481 | echo "</table>\n"; |
||
| 482 | echo "<p>\n"; |
||
| 483 | echo "<input type=\"hidden\" name=\"action\" value=\"createconfig\" />\n"; |
||
| 484 | echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), "\" />\n"; |
||
| 485 | echo $this->misc->form; |
||
| 486 | echo "<input type=\"submit\" name=\"create\" value=\"{$lang['strcreate']}\" />\n"; |
||
| 487 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n"; |
||
| 488 | echo "</p>\n"; |
||
| 489 | echo "</form>\n"; |
||
| 490 | } |
||
| 491 | |||
| 492 | /** |
||
| 493 | * Actually creates the new FTS configuration in the database. |
||
| 494 | */ |
||
| 495 | public function doSaveCreateConfig() |
||
| 496 | { |
||
| 497 | $conf = $this->conf; |
||
| 498 | |||
| 499 | $lang = $this->lang; |
||
| 500 | $data = $this->misc->getDatabaseAccessor(); |
||
| 501 | |||
| 502 | $err = ''; |
||
| 503 | // Check that they've given a name |
||
| 504 | if ('' == $_POST['formName']) { |
||
| 505 | $err .= "{$lang['strftsconfigneedsname']}<br />"; |
||
| 506 | } |
||
| 507 | |||
| 508 | if (('' != $_POST['formParser']) && ('' != $_POST['formTemplate'])) { |
||
| 509 | $err .= "{$lang['strftscantparsercopy']}<br />"; |
||
| 510 | } |
||
| 511 | |||
| 512 | if ('' != $err) { |
||
|
0 ignored issues
–
show
|
|||
| 513 | return doCreateConfig($err); |
||
| 514 | } |
||
| 515 | |||
| 516 | if ('' != $_POST['formParser']) { |
||
| 517 | $formParser = unserialize($_POST['formParser']); |
||
| 518 | } else { |
||
| 519 | $formParser = ''; |
||
| 520 | } |
||
| 521 | |||
| 522 | if ('' != $_POST['formTemplate']) { |
||
| 523 | $formTemplate = unserialize($_POST['formTemplate']); |
||
| 524 | } else { |
||
| 525 | $formTemplate = ''; |
||
| 526 | } |
||
| 527 | |||
| 528 | $status = $data->createFtsConfiguration($_POST['formName'], $formParser, $formTemplate, $_POST['formComment']); |
||
| 529 | if (0 == $status) { |
||
| 530 | $this->misc->setReloadBrowser(true); |
||
| 531 | $this->doDefault($lang['strftsconfigcreated']); |
||
| 532 | } else { |
||
| 533 | $this->doCreateConfig($lang['strftsconfigcreatedbad']); |
||
| 534 | } |
||
| 535 | } |
||
| 536 | |||
| 537 | /** |
||
| 538 | * Display a form to permit editing FTS configuration properies. |
||
| 539 | * |
||
| 540 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 541 | */ |
||
| 542 | public function doAlterConfig($msg = '') |
||
| 543 | { |
||
| 544 | $conf = $this->conf; |
||
|
0 ignored issues
–
show
|
|||
| 545 | |||
| 546 | $lang = $this->lang; |
||
| 547 | $data = $this->misc->getDatabaseAccessor(); |
||
| 548 | |||
| 549 | $this->printTrail('ftscfg'); |
||
| 550 | $this->printTitle($lang['stralter'], 'pg.ftscfg.alter'); |
||
| 551 | $this->printMsg($msg); |
||
| 552 | |||
| 553 | $ftscfg = $data->getFtsConfigurationByName($_REQUEST['ftscfg']); |
||
| 554 | if ($ftscfg->recordCount() > 0) { |
||
| 555 | if (!isset($_POST['formComment'])) { |
||
| 556 | $_POST['formComment'] = $ftscfg->fields['comment']; |
||
| 557 | } |
||
| 558 | |||
| 559 | if (!isset($_POST['ftscfg'])) { |
||
| 560 | $_POST['ftscfg'] = $_REQUEST['ftscfg']; |
||
| 561 | } |
||
| 562 | |||
| 563 | if (!isset($_POST['formName'])) { |
||
| 564 | $_POST['formName'] = $_REQUEST['ftscfg']; |
||
| 565 | } |
||
| 566 | |||
| 567 | if (!isset($_POST['formParser'])) { |
||
| 568 | $_POST['formParser'] = ''; |
||
| 569 | } |
||
| 570 | |||
| 571 | // Fetch all FTS parsers from the database |
||
| 572 | $ftsparsers = $data->getFtsParsers(); |
||
| 573 | |||
| 574 | echo '<form action="'.\SUBFOLDER."/src/views/fulltext.php\" method=\"post\">\n"; |
||
| 575 | echo "<table>\n"; |
||
| 576 | |||
| 577 | echo "\t<tr>\n"; |
||
| 578 | echo "\t\t<th class=\"data left required\">{$lang['strname']}</th>\n"; |
||
| 579 | echo "\t\t<td class=\"data1\">"; |
||
| 580 | echo "\t\t\t<input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 581 | htmlspecialchars($_POST['formName']), "\" />\n"; |
||
| 582 | echo "\t\t</td>\n"; |
||
| 583 | echo "\t</tr>\n"; |
||
| 584 | |||
| 585 | // Comment |
||
| 586 | echo "\t<tr>\n"; |
||
| 587 | echo "\t\t<th class=\"data\">{$lang['strcomment']}</th>\n"; |
||
| 588 | echo "\t\t<td class=\"data1\"><textarea cols=\"32\" rows=\"3\"name=\"formComment\">", htmlspecialchars($_POST['formComment']), "</textarea></td>\n"; |
||
| 589 | echo "\t</tr>\n"; |
||
| 590 | echo "</table>\n"; |
||
| 591 | echo "<p><input type=\"hidden\" name=\"action\" value=\"alterconfig\" />\n"; |
||
| 592 | echo '<input type="hidden" name="ftscfg" value="', htmlspecialchars($_POST['ftscfg']), "\" />\n"; |
||
| 593 | echo $this->misc->form; |
||
| 594 | echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n"; |
||
| 595 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 596 | echo "</form>\n"; |
||
| 597 | } else { |
||
| 598 | echo "<p>{$lang['strnodata']}</p>\n"; |
||
| 599 | } |
||
| 600 | } |
||
| 601 | |||
| 602 | /** |
||
| 603 | * Save the form submission containing changes to a FTS configuration. |
||
| 604 | */ |
||
| 605 | public function doSaveAlterConfig() |
||
| 606 | { |
||
| 607 | $conf = $this->conf; |
||
| 608 | |||
| 609 | $lang = $this->lang; |
||
| 610 | $data = $this->misc->getDatabaseAccessor(); |
||
| 611 | $status = $data->updateFtsConfiguration($_POST['ftscfg'], $_POST['formComment'], $_POST['formName']); |
||
| 612 | if (0 == $status) { |
||
| 613 | $this->doDefault($lang['strftsconfigaltered']); |
||
| 614 | } else { |
||
| 615 | $this->doAlterConfig($lang['strftsconfigalteredbad']); |
||
| 616 | } |
||
| 617 | } |
||
| 618 | |||
| 619 | /** |
||
| 620 | * View list of FTS parsers. |
||
| 621 | * |
||
| 622 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 623 | */ |
||
| 624 | public function doViewParsers($msg = '') |
||
| 625 | { |
||
| 626 | $conf = $this->conf; |
||
| 627 | |||
| 628 | $lang = $this->lang; |
||
| 629 | $data = $this->misc->getDatabaseAccessor(); |
||
| 630 | |||
| 631 | $this->printTrail('schema'); |
||
| 632 | $this->printTabs('schema', 'fulltext'); |
||
| 633 | $this->printTabs('fulltext', 'ftsparsers'); |
||
| 634 | $this->printMsg($msg); |
||
| 635 | |||
| 636 | $parsers = $data->getFtsParsers(false); |
||
| 637 | |||
| 638 | $columns = [ |
||
| 639 | 'schema' => [ |
||
| 640 | 'title' => $lang['strschema'], |
||
| 641 | 'field' => Decorator::field('schema'), |
||
| 642 | ], |
||
| 643 | 'name' => [ |
||
| 644 | 'title' => $lang['strname'], |
||
| 645 | 'field' => Decorator::field('name'), |
||
| 646 | ], |
||
| 647 | 'comment' => [ |
||
| 648 | 'title' => $lang['strcomment'], |
||
| 649 | 'field' => Decorator::field('comment'), |
||
| 650 | ], |
||
| 651 | ]; |
||
| 652 | |||
| 653 | $actions = []; |
||
| 654 | |||
| 655 | echo $this->printTable($parsers, $columns, $actions, 'fulltext-viewparsers', $lang['strftsnoparsers']); |
||
| 656 | |||
| 657 | //TODO: navlink to "create parser" |
||
| 658 | } |
||
| 659 | |||
| 660 | /** |
||
| 661 | * View list of FTS dictionaries. |
||
| 662 | * |
||
| 663 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 664 | */ |
||
| 665 | public function doViewDicts($msg = '') |
||
| 666 | { |
||
| 667 | $conf = $this->conf; |
||
| 668 | |||
| 669 | $lang = $this->lang; |
||
| 670 | $data = $this->misc->getDatabaseAccessor(); |
||
| 671 | |||
| 672 | $this->printTrail('schema'); |
||
| 673 | $this->printTabs('schema', 'fulltext'); |
||
| 674 | $this->printTabs('fulltext', 'ftsdicts'); |
||
| 675 | $this->printMsg($msg); |
||
| 676 | |||
| 677 | $dicts = $data->getFtsDictionaries(false); |
||
| 678 | |||
| 679 | $columns = [ |
||
| 680 | 'schema' => [ |
||
| 681 | 'title' => $lang['strschema'], |
||
| 682 | 'field' => Decorator::field('schema'), |
||
| 683 | ], |
||
| 684 | 'name' => [ |
||
| 685 | 'title' => $lang['strname'], |
||
| 686 | 'field' => Decorator::field('name'), |
||
| 687 | ], |
||
| 688 | 'actions' => [ |
||
| 689 | 'title' => $lang['stractions'], |
||
| 690 | ], |
||
| 691 | 'comment' => [ |
||
| 692 | 'title' => $lang['strcomment'], |
||
| 693 | 'field' => Decorator::field('comment'), |
||
| 694 | ], |
||
| 695 | ]; |
||
| 696 | |||
| 697 | $actions = [ |
||
| 698 | 'drop' => [ |
||
| 699 | 'content' => $lang['strdrop'], |
||
| 700 | 'attr' => [ |
||
| 701 | 'href' => [ |
||
| 702 | 'url' => 'fulltext.php', |
||
| 703 | 'urlvars' => [ |
||
| 704 | 'action' => 'dropdict', |
||
| 705 | 'ftsdict' => Decorator::field('name'), |
||
| 706 | ], |
||
| 707 | ], |
||
| 708 | ], |
||
| 709 | ], |
||
| 710 | 'alter' => [ |
||
| 711 | 'content' => $lang['stralter'], |
||
| 712 | 'attr' => [ |
||
| 713 | 'href' => [ |
||
| 714 | 'url' => 'fulltext.php', |
||
| 715 | 'urlvars' => [ |
||
| 716 | 'action' => 'alterdict', |
||
| 717 | 'ftsdict' => Decorator::field('name'), |
||
| 718 | ], |
||
| 719 | ], |
||
| 720 | ], |
||
| 721 | ], |
||
| 722 | ]; |
||
| 723 | |||
| 724 | echo $this->printTable($dicts, $columns, $actions, 'fulltext-viewdicts', $lang['strftsnodicts']); |
||
| 725 | |||
| 726 | $navlinks = [ |
||
| 727 | 'createdict' => [ |
||
| 728 | 'attr' => [ |
||
| 729 | 'href' => [ |
||
| 730 | 'url' => 'fulltext.php', |
||
| 731 | 'urlvars' => [ |
||
| 732 | 'action' => 'createdict', |
||
| 733 | 'server' => $_REQUEST['server'], |
||
| 734 | 'database' => $_REQUEST['database'], |
||
| 735 | 'schema' => $_REQUEST['schema'], |
||
| 736 | ], |
||
| 737 | ], |
||
| 738 | ], |
||
| 739 | 'content' => $lang['strftscreatedict'], |
||
| 740 | ], |
||
| 741 | ]; |
||
| 742 | |||
| 743 | $this->printNavLinks($navlinks, 'fulltext-viewdicts', get_defined_vars()); |
||
| 744 | } |
||
| 745 | |||
| 746 | /** |
||
| 747 | * View details of FTS configuration given. |
||
| 748 | * |
||
| 749 | * @param mixed $ftscfg |
||
|
1 ignored issue
–
show
|
|||
| 750 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 751 | */ |
||
| 752 | public function doViewConfig($ftscfg, $msg = '') |
||
| 753 | { |
||
| 754 | $conf = $this->conf; |
||
| 755 | |||
| 756 | $lang = $this->lang; |
||
| 757 | $data = $this->misc->getDatabaseAccessor(); |
||
| 758 | |||
| 759 | $this->printTrail('ftscfg'); |
||
| 760 | $this->printTabs('schema', 'fulltext'); |
||
| 761 | $this->printTabs('fulltext', 'ftsconfigs'); |
||
| 762 | $this->printMsg($msg); |
||
| 763 | |||
| 764 | echo "<h3>{$lang['strftsconfigmap']}</h3>\n"; |
||
| 765 | |||
| 766 | $map = $data->getFtsConfigurationMap($ftscfg); |
||
| 767 | |||
| 768 | $columns = [ |
||
| 769 | 'name' => [ |
||
| 770 | 'title' => $lang['strftsmapping'], |
||
| 771 | 'field' => Decorator::field('name'), |
||
| 772 | ], |
||
| 773 | 'dictionaries' => [ |
||
| 774 | 'title' => $lang['strftsdicts'], |
||
| 775 | 'field' => Decorator::field('dictionaries'), |
||
| 776 | ], |
||
| 777 | 'actions' => [ |
||
| 778 | 'title' => $lang['stractions'], |
||
| 779 | ], |
||
| 780 | 'comment' => [ |
||
| 781 | 'title' => $lang['strcomment'], |
||
| 782 | 'field' => Decorator::field('description'), |
||
| 783 | ], |
||
| 784 | ]; |
||
| 785 | |||
| 786 | $actions = [ |
||
| 787 | 'drop' => [ |
||
| 788 | 'multiaction' => 'dropmapping', |
||
| 789 | 'content' => $lang['strdrop'], |
||
| 790 | 'attr' => [ |
||
| 791 | 'href' => [ |
||
| 792 | 'url' => 'fulltext.php', |
||
| 793 | 'urlvars' => [ |
||
| 794 | 'action' => 'dropmapping', |
||
| 795 | 'mapping' => Decorator::field('name'), |
||
| 796 | 'ftscfg' => Decorator::field('cfgname'), |
||
| 797 | ], |
||
| 798 | ], |
||
| 799 | ], |
||
| 800 | ], |
||
| 801 | 'alter' => [ |
||
| 802 | 'content' => $lang['stralter'], |
||
| 803 | 'attr' => [ |
||
| 804 | 'href' => [ |
||
| 805 | 'url' => 'fulltext.php', |
||
| 806 | 'urlvars' => [ |
||
| 807 | 'action' => 'altermapping', |
||
| 808 | 'mapping' => Decorator::field('name'), |
||
| 809 | 'ftscfg' => Decorator::field('cfgname'), |
||
| 810 | ], |
||
| 811 | ], |
||
| 812 | ], |
||
| 813 | ], |
||
| 814 | 'multiactions' => [ |
||
| 815 | 'keycols' => ['mapping' => 'name'], |
||
| 816 | 'url' => 'fulltext.php', |
||
| 817 | 'default' => null, |
||
| 818 | 'vars' => ['ftscfg' => $ftscfg], |
||
| 819 | ], |
||
| 820 | ]; |
||
| 821 | |||
| 822 | echo $this->printTable($map, $columns, $actions, 'fulltext-viewconfig', $lang['strftsemptymap']); |
||
| 823 | |||
| 824 | $navlinks = [ |
||
| 825 | 'addmapping' => [ |
||
| 826 | 'attr' => [ |
||
| 827 | 'href' => [ |
||
| 828 | 'url' => 'fulltext.php', |
||
| 829 | 'urlvars' => [ |
||
| 830 | 'action' => 'addmapping', |
||
| 831 | 'server' => $_REQUEST['server'], |
||
| 832 | 'database' => $_REQUEST['database'], |
||
| 833 | 'schema' => $_REQUEST['schema'], |
||
| 834 | 'ftscfg' => $ftscfg, |
||
| 835 | ], |
||
| 836 | ], |
||
| 837 | ], |
||
| 838 | 'content' => $lang['strftsaddmapping'], |
||
| 839 | ], |
||
| 840 | ]; |
||
| 841 | |||
| 842 | $this->printNavLinks($navlinks, 'fulltext-viewconfig', get_defined_vars()); |
||
| 843 | } |
||
| 844 | |||
| 845 | /** |
||
| 846 | * Displays a screen where one can enter a details of a new FTS dictionary. |
||
| 847 | * |
||
| 848 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 849 | */ |
||
| 850 | public function doCreateDict($msg = '') |
||
| 851 | { |
||
| 852 | $conf = $this->conf; |
||
| 853 | |||
| 854 | $lang = $this->lang; |
||
| 855 | $data = $this->misc->getDatabaseAccessor(); |
||
| 856 | |||
| 857 | $server_info = $this->misc->getServerInfo(); |
||
| 858 | |||
| 859 | if (!isset($_POST['formName'])) { |
||
| 860 | $_POST['formName'] = ''; |
||
| 861 | } |
||
| 862 | |||
| 863 | if (!isset($_POST['formIsTemplate'])) { |
||
| 864 | $_POST['formIsTemplate'] = false; |
||
| 865 | } |
||
| 866 | |||
| 867 | if (!isset($_POST['formTemplate'])) { |
||
| 868 | $_POST['formTemplate'] = ''; |
||
| 869 | } |
||
| 870 | |||
| 871 | if (!isset($_POST['formLexize'])) { |
||
| 872 | $_POST['formLexize'] = ''; |
||
| 873 | } |
||
| 874 | |||
| 875 | if (!isset($_POST['formInit'])) { |
||
| 876 | $_POST['formInit'] = ''; |
||
| 877 | } |
||
| 878 | |||
| 879 | if (!isset($_POST['formOption'])) { |
||
| 880 | $_POST['formOption'] = ''; |
||
| 881 | } |
||
| 882 | |||
| 883 | if (!isset($_POST['formComment'])) { |
||
| 884 | $_POST['formComment'] = ''; |
||
| 885 | } |
||
| 886 | |||
| 887 | // Fetch all FTS dictionaries from the database |
||
| 888 | $ftstpls = $data->getFtsDictionaryTemplates(); |
||
| 889 | |||
| 890 | $this->printTrail('schema'); |
||
| 891 | // TODO: create doc links |
||
| 892 | $this->printTitle($lang['strftscreatedict'], 'pg.ftsdict.create'); |
||
| 893 | $this->printMsg($msg); |
||
| 894 | |||
| 895 | echo '<form action="'.\SUBFOLDER."/src/views/fulltext.php\" method=\"post\">\n"; |
||
| 896 | echo "<table>\n"; |
||
| 897 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n"; |
||
| 898 | echo "\t\t<td class=\"data1\"><input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 899 | htmlspecialchars($_POST['formName']), '" /> ', |
||
| 900 | '<input type="checkbox" name="formIsTemplate" id="formIsTemplate"', $_POST['formIsTemplate'] ? ' checked="checked" ' : '', " />\n", |
||
| 901 | "<label for=\"formIsTemplate\">{$lang['strftscreatedicttemplate']}</label></td>\n\t</tr>\n"; |
||
| 902 | |||
| 903 | // Template |
||
| 904 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strftstemplate']}</th>\n"; |
||
| 905 | echo "\t\t<td class=\"data1\">"; |
||
| 906 | $tpls = []; |
||
| 907 | $tplsel = ''; |
||
| 908 | while (!$ftstpls->EOF) { |
||
| 909 | $data->fieldClean($ftstpls->fields['schema']); |
||
| 910 | $data->fieldClean($ftstpls->fields['name']); |
||
| 911 | $tplname = $ftstpls->fields['schema'].'.'.$ftstpls->fields['name']; |
||
| 912 | $tpls[$tplname] = serialize([ |
||
| 913 | 'name' => $ftstpls->fields['name'], |
||
| 914 | 'schema' => $ftstpls->fields['schema'], |
||
| 915 | ]); |
||
| 916 | if ($_POST['formTemplate'] == $tpls[$tplname]) { |
||
| 917 | $tplsel = htmlspecialchars($tpls[$tplname]); |
||
| 918 | } |
||
| 919 | $ftstpls->moveNext(); |
||
| 920 | } |
||
| 921 | echo \PHPPgAdmin\XHtml\HTMLController::printCombo($tpls, 'formTemplate', true, $tplsel, false); |
||
| 922 | echo "\n\t\t</td>\n\t</tr>\n"; |
||
| 923 | |||
| 924 | // TODO: what about maxlengths? |
||
| 925 | // Lexize |
||
| 926 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strftslexize']}</th>\n"; |
||
| 927 | echo "\t\t<td class=\"data1\"><input name=\"formLexize\" size=\"32\" maxlength=\"1000\" value=\"", |
||
| 928 | htmlspecialchars($_POST['formLexize']), '" ', isset($_POST['formIsTemplate']) ? '' : ' disabled="disabled" ', |
||
| 929 | "/></td>\n\t</tr>\n"; |
||
| 930 | |||
| 931 | // Init |
||
| 932 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strftsinit']}</th>\n"; |
||
| 933 | echo "\t\t<td class=\"data1\"><input name=\"formInit\" size=\"32\" maxlength=\"1000\" value=\"", |
||
| 934 | htmlspecialchars($_POST['formInit']), '"', @$_POST['formIsTemplate'] ? '' : ' disabled="disabled" ', |
||
| 935 | "/></td>\n\t</tr>\n"; |
||
| 936 | |||
| 937 | // Option |
||
| 938 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strftsoptionsvalues']}</th>\n"; |
||
| 939 | echo "\t\t<td class=\"data1\"><input name=\"formOption\" size=\"32\" maxlength=\"1000\" value=\"", |
||
| 940 | htmlspecialchars($_POST['formOption']), "\" /></td>\n\t</tr>\n"; |
||
| 941 | |||
| 942 | // Comment |
||
| 943 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n"; |
||
| 944 | echo "\t\t<td class=\"data1\"><textarea name=\"formComment\" rows=\"3\" cols=\"32\">", |
||
| 945 | htmlspecialchars($_POST['formComment']), "</textarea></td>\n\t</tr>\n"; |
||
| 946 | |||
| 947 | echo "</table>\n"; |
||
| 948 | echo "<p>\n"; |
||
| 949 | echo "<input type=\"hidden\" name=\"action\" value=\"createdict\" />\n"; |
||
| 950 | echo '<input type="hidden" name="database" value="', htmlspecialchars($_REQUEST['database']), "\" />\n"; |
||
| 951 | echo $this->misc->form; |
||
| 952 | echo "<input type=\"submit\" name=\"create\" value=\"{$lang['strcreate']}\" />\n"; |
||
| 953 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n"; |
||
| 954 | echo "</p>\n"; |
||
| 955 | echo "</form>\n", |
||
| 956 | "<script type=\"text/javascript\"> |
||
| 957 | function templateOpts() { |
||
| 958 | isTpl = document.getElementsByName('formIsTemplate')[0].checked; |
||
| 959 | {$this->document}.getElementsByName('formTemplate')[0].disabled = isTpl; |
||
| 960 | {$this->document}.getElementsByName('formOption')[0].disabled = isTpl; |
||
| 961 | {$this->document}.getElementsByName('formLexize')[0].disabled = !isTpl; |
||
| 962 | {$this->document}.getElementsByName('formInit')[0].disabled = !isTpl; |
||
| 963 | } |
||
| 964 | |||
| 965 | {$this->document}.getElementsByName('formIsTemplate')[0].onchange = templateOpts; |
||
| 966 | |||
| 967 | templateOpts(); |
||
| 968 | </script>\n"; |
||
| 969 | } |
||
| 970 | |||
| 971 | /** |
||
| 972 | * Actually creates the new FTS dictionary in the database. |
||
| 973 | */ |
||
| 974 | public function doSaveCreateDict() |
||
| 975 | { |
||
| 976 | $conf = $this->conf; |
||
| 977 | |||
| 978 | $lang = $this->lang; |
||
| 979 | $data = $this->misc->getDatabaseAccessor(); |
||
| 980 | |||
| 981 | // Check that they've given a name |
||
| 982 | if ('' == $_POST['formName']) { |
||
| 983 | $this->doCreateDict($lang['strftsdictneedsname']); |
||
| 984 | } else { |
||
| 985 | if (!isset($_POST['formIsTemplate'])) { |
||
| 986 | $_POST['formIsTemplate'] = false; |
||
| 987 | } |
||
| 988 | |||
| 989 | if (isset($_POST['formTemplate'])) { |
||
| 990 | $formTemplate = unserialize($_POST['formTemplate']); |
||
| 991 | } else { |
||
| 992 | $formTemplate = ''; |
||
| 993 | } |
||
| 994 | |||
| 995 | if (!isset($_POST['formLexize'])) { |
||
| 996 | $_POST['formLexize'] = ''; |
||
| 997 | } |
||
| 998 | |||
| 999 | if (!isset($_POST['formInit'])) { |
||
| 1000 | $_POST['formInit'] = ''; |
||
| 1001 | } |
||
| 1002 | |||
| 1003 | if (!isset($_POST['formOption'])) { |
||
| 1004 | $_POST['formOption'] = ''; |
||
| 1005 | } |
||
| 1006 | |||
| 1007 | $status = $data->createFtsDictionary( |
||
| 1008 | $_POST['formName'], |
||
| 1009 | $_POST['formIsTemplate'], |
||
| 1010 | $formTemplate, |
||
| 1011 | $_POST['formLexize'], |
||
| 1012 | $_POST['formInit'], |
||
| 1013 | $_POST['formOption'], |
||
| 1014 | $_POST['formComment'] |
||
| 1015 | ); |
||
| 1016 | |||
| 1017 | if (0 == $status) { |
||
| 1018 | $this->misc->setReloadBrowser(true); |
||
| 1019 | $this->doViewDicts($lang['strftsdictcreated']); |
||
| 1020 | } else { |
||
| 1021 | $this->doCreateDict($lang['strftsdictcreatedbad']); |
||
| 1022 | } |
||
| 1023 | } |
||
| 1024 | } |
||
| 1025 | |||
| 1026 | /** |
||
| 1027 | * Display a form to permit editing FTS dictionary properies. |
||
| 1028 | * |
||
| 1029 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 1030 | */ |
||
| 1031 | public function doAlterDict($msg = '') |
||
| 1032 | { |
||
| 1033 | $conf = $this->conf; |
||
| 1034 | |||
| 1035 | $lang = $this->lang; |
||
| 1036 | $data = $this->misc->getDatabaseAccessor(); |
||
| 1037 | |||
| 1038 | $this->printTrail('ftscfg'); // TODO: change to smth related to dictionary |
||
| 1039 | $this->printTitle($lang['stralter'], 'pg.ftsdict.alter'); |
||
| 1040 | $this->printMsg($msg); |
||
| 1041 | |||
| 1042 | $ftsdict = $data->getFtsDictionaryByName($_REQUEST['ftsdict']); |
||
| 1043 | if ($ftsdict->recordCount() > 0) { |
||
| 1044 | if (!isset($_POST['formComment'])) { |
||
| 1045 | $_POST['formComment'] = $ftsdict->fields['comment']; |
||
| 1046 | } |
||
| 1047 | |||
| 1048 | if (!isset($_POST['ftsdict'])) { |
||
| 1049 | $_POST['ftsdict'] = $_REQUEST['ftsdict']; |
||
| 1050 | } |
||
| 1051 | |||
| 1052 | if (!isset($_POST['formName'])) { |
||
| 1053 | $_POST['formName'] = $_REQUEST['ftsdict']; |
||
| 1054 | } |
||
| 1055 | |||
| 1056 | echo '<form action="'.\SUBFOLDER."/src/views/fulltext.php\" method=\"post\">\n"; |
||
| 1057 | echo "<table>\n"; |
||
| 1058 | |||
| 1059 | echo "\t<tr>\n"; |
||
| 1060 | echo "\t\t<th class=\"data left required\">{$lang['strname']}</th>\n"; |
||
| 1061 | echo "\t\t<td class=\"data1\">"; |
||
| 1062 | echo "\t\t\t<input name=\"formName\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
| 1063 | htmlspecialchars($_POST['formName']), "\" />\n"; |
||
| 1064 | echo "\t\t</td>\n"; |
||
| 1065 | echo "\t</tr>\n"; |
||
| 1066 | |||
| 1067 | // Comment |
||
| 1068 | echo "\t<tr>\n"; |
||
| 1069 | echo "\t\t<th class=\"data\">{$lang['strcomment']}</th>\n"; |
||
| 1070 | echo "\t\t<td class=\"data1\"><textarea cols=\"32\" rows=\"3\"name=\"formComment\">", htmlspecialchars($_POST['formComment']), "</textarea></td>\n"; |
||
| 1071 | echo "\t</tr>\n"; |
||
| 1072 | echo "</table>\n"; |
||
| 1073 | echo "<p><input type=\"hidden\" name=\"action\" value=\"alterdict\" />\n"; |
||
| 1074 | echo '<input type="hidden" name="ftsdict" value="', htmlspecialchars($_POST['ftsdict']), "\" />\n"; |
||
| 1075 | echo "<input type=\"hidden\" name=\"prev_action\" value=\"viewdicts\" /></p>\n"; |
||
| 1076 | echo $this->misc->form; |
||
| 1077 | echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n"; |
||
| 1078 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 1079 | echo "</form>\n"; |
||
| 1080 | } else { |
||
| 1081 | echo "<p>{$lang['strnodata']}</p>\n"; |
||
| 1082 | } |
||
| 1083 | } |
||
| 1084 | |||
| 1085 | /** |
||
| 1086 | * Save the form submission containing changes to a FTS dictionary. |
||
| 1087 | */ |
||
| 1088 | public function doSaveAlterDict() |
||
| 1089 | { |
||
| 1090 | $conf = $this->conf; |
||
| 1091 | |||
| 1092 | $lang = $this->lang; |
||
| 1093 | $data = $this->misc->getDatabaseAccessor(); |
||
| 1094 | |||
| 1095 | $status = $data->updateFtsDictionary($_POST['ftsdict'], $_POST['formComment'], $_POST['formName']); |
||
| 1096 | if (0 == $status) { |
||
| 1097 | $this->doViewDicts($lang['strftsdictaltered']); |
||
| 1098 | } else { |
||
| 1099 | $this->doAlterDict($lang['strftsdictalteredbad']); |
||
| 1100 | } |
||
| 1101 | } |
||
| 1102 | |||
| 1103 | /** |
||
| 1104 | * Show confirmation of drop and perform actual drop of FTS mapping. |
||
| 1105 | * |
||
| 1106 | * @param mixed $confirm |
||
|
1 ignored issue
–
show
|
|||
| 1107 | */ |
||
| 1108 | public function doDropMapping($confirm) |
||
| 1109 | { |
||
| 1110 | $conf = $this->conf; |
||
| 1111 | |||
| 1112 | $lang = $this->lang; |
||
| 1113 | $data = $this->misc->getDatabaseAccessor(); |
||
| 1114 | |||
| 1115 | if (empty($_REQUEST['mapping']) && empty($_REQUEST['ma'])) { |
||
| 1116 | $this->doDefault($lang['strftsspecifymappingtodrop']); |
||
| 1117 | |||
| 1118 | return; |
||
| 1119 | } |
||
| 1120 | |||
| 1121 | if (empty($_REQUEST['ftscfg'])) { |
||
| 1122 | $this->doDefault($lang['strftsspecifyconfigtoalter']); |
||
| 1123 | |||
| 1124 | return; |
||
| 1125 | } |
||
| 1126 | |||
| 1127 | if ($confirm) { |
||
| 1128 | $this->printTrail('ftscfg'); // TODO: proper breadcrumbs |
||
| 1129 | $this->printTitle($lang['strdrop'], 'pg.ftscfg.alter'); |
||
| 1130 | |||
| 1131 | echo '<form action="'.\SUBFOLDER."/src/views/fulltext.php\" method=\"post\">\n"; |
||
| 1132 | |||
| 1133 | // Case of multiaction drop |
||
| 1134 | if (isset($_REQUEST['ma'])) { |
||
| 1135 | foreach ($_REQUEST['ma'] as $v) { |
||
| 1136 | $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
||
| 1137 | echo '<p>', sprintf($lang['strconfdropftsmapping'], $this->misc->printVal($a['mapping']), $this->misc->printVal($_REQUEST['ftscfg'])), "</p>\n"; |
||
| 1138 | printf('<input type="hidden" name="mapping[]" value="%s" />', htmlspecialchars($a['mapping'])); |
||
| 1139 | } |
||
| 1140 | } else { |
||
| 1141 | echo '<p>', sprintf($lang['strconfdropftsmapping'], $this->misc->printVal($_REQUEST['mapping']), $this->misc->printVal($_REQUEST['ftscfg'])), "</p>\n"; |
||
| 1142 | echo '<input type="hidden" name="mapping" value="', htmlspecialchars($_REQUEST['mapping']), "\" />\n"; |
||
| 1143 | } |
||
| 1144 | |||
| 1145 | echo "<input type=\"hidden\" name=\"ftscfg\" value=\"{$_REQUEST['ftscfg']}\" />\n"; |
||
| 1146 | echo "<input type=\"hidden\" name=\"action\" value=\"dropmapping\" />\n"; |
||
| 1147 | echo "<input type=\"hidden\" name=\"prev_action\" value=\"viewconfig\" /></p>\n"; |
||
| 1148 | echo $this->misc->form; |
||
| 1149 | echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n"; |
||
| 1150 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n"; |
||
| 1151 | echo "</form>\n"; |
||
| 1152 | } else { |
||
| 1153 | // Case of multiaction drop |
||
| 1154 | if (is_array($_REQUEST['mapping'])) { |
||
| 1155 | $status = $data->changeFtsMapping($_REQUEST['ftscfg'], $_REQUEST['mapping'], 'drop'); |
||
| 1156 | if (0 != $status) { |
||
| 1157 | $this->doViewConfig($_REQUEST['ftscfg'], $lang['strftsmappingdroppedbad']); |
||
| 1158 | |||
| 1159 | return; |
||
| 1160 | } |
||
| 1161 | $this->doViewConfig($_REQUEST['ftscfg'], $lang['strftsmappingdropped']); |
||
| 1162 | } else { |
||
| 1163 | $status = $data->changeFtsMapping($_REQUEST['ftscfg'], [$_REQUEST['mapping']], 'drop'); |
||
| 1164 | if (0 == $status) { |
||
| 1165 | $this->doViewConfig($_REQUEST['ftscfg'], $lang['strftsmappingdropped']); |
||
| 1166 | } else { |
||
| 1167 | $this->doViewConfig($_REQUEST['ftscfg'], $lang['strftsmappingdroppedbad']); |
||
| 1168 | } |
||
| 1169 | } |
||
| 1170 | } |
||
| 1171 | } |
||
| 1172 | |||
| 1173 | public function doAlterMapping($msg = '') |
||
| 1174 | { |
||
| 1175 | $conf = $this->conf; |
||
| 1176 | |||
| 1177 | $lang = $this->lang; |
||
| 1178 | $data = $this->misc->getDatabaseAccessor(); |
||
| 1179 | $this->printTrail('ftscfg'); |
||
| 1180 | $this->printTitle($lang['stralter'], 'pg.ftscfg.alter'); |
||
| 1181 | $this->printMsg($msg); |
||
| 1182 | |||
| 1183 | $ftsdicts = $data->getFtsDictionaries(); |
||
| 1184 | if ($ftsdicts->recordCount() > 0) { |
||
| 1185 | if (!isset($_POST['formMapping'])) { |
||
| 1186 | $_POST['formMapping'] = @$_REQUEST['mapping']; |
||
| 1187 | } |
||
| 1188 | |||
| 1189 | if (!isset($_POST['formDictionary'])) { |
||
| 1190 | $_POST['formDictionary'] = ''; |
||
| 1191 | } |
||
| 1192 | |||
| 1193 | if (!isset($_POST['ftscfg'])) { |
||
| 1194 | $_POST['ftscfg'] = $_REQUEST['ftscfg']; |
||
| 1195 | } |
||
| 1196 | |||
| 1197 | echo '<form action="'.\SUBFOLDER."/src/views/fulltext.php\" method=\"post\">\n"; |
||
| 1198 | |||
| 1199 | echo "<table>\n"; |
||
| 1200 | echo "\t<tr>\n"; |
||
| 1201 | echo "\t\t<th class=\"data left required\">{$lang['strftsmapping']}</th>\n"; |
||
| 1202 | echo "\t\t<td class=\"data1\">"; |
||
| 1203 | |||
| 1204 | // Case of multiaction drop |
||
| 1205 | if (isset($_REQUEST['ma'])) { |
||
| 1206 | $ma_mappings = []; |
||
| 1207 | $ma_mappings_names = []; |
||
| 1208 | foreach ($_REQUEST['ma'] as $v) { |
||
| 1209 | $a = unserialize(htmlspecialchars_decode($v, ENT_QUOTES)); |
||
| 1210 | printf('<input type="hidden" name="formMapping[]" value="%s" />', htmlspecialchars($a['mapping'])); |
||
| 1211 | $ma_mappings[] = $data->getFtsMappingByName($_POST['ftscfg'], $a['mapping']); |
||
| 1212 | $ma_mappings_names[] = $a['mapping']; |
||
| 1213 | } |
||
| 1214 | echo implode(', ', $ma_mappings_names); |
||
| 1215 | } else { |
||
| 1216 | $mapping = $data->getFtsMappingByName($_POST['ftscfg'], $_POST['formMapping']); |
||
| 1217 | echo $mapping->fields['name']; |
||
| 1218 | echo '<input type="hidden" name="formMapping" value="', htmlspecialchars($_POST['formMapping']), "\" />\n"; |
||
| 1219 | } |
||
| 1220 | |||
| 1221 | echo "\t\t</td>\n"; |
||
| 1222 | echo "\t</tr>\n"; |
||
| 1223 | |||
| 1224 | // Dictionary |
||
| 1225 | echo "\t<tr>\n"; |
||
| 1226 | echo "\t\t<th class=\"data left required\">{$lang['strftsdict']}</th>\n"; |
||
| 1227 | echo "\t\t<td class=\"data1\">"; |
||
| 1228 | echo "\t\t\t<select name=\"formDictionary\">\n"; |
||
| 1229 | while (!$ftsdicts->EOF) { |
||
| 1230 | $ftsdict = htmlspecialchars($ftsdicts->fields['name']); |
||
| 1231 | echo "\t\t\t\t<option value=\"{$ftsdict}\"", |
||
| 1232 | ($ftsdict == $_POST['formDictionary'] || $ftsdict == @$mapping->fields['dictionaries'] || $ftsdict == @$ma_mappings[0]->fields['dictionaries']) ? ' selected="selected"' : '', ">{$ftsdict}</option>\n"; |
||
| 1233 | $ftsdicts->moveNext(); |
||
| 1234 | } |
||
| 1235 | |||
| 1236 | echo "\t\t</td>\n"; |
||
| 1237 | echo "\t</tr>\n"; |
||
| 1238 | |||
| 1239 | echo "</table>\n"; |
||
| 1240 | echo "<p><input type=\"hidden\" name=\"action\" value=\"altermapping\" />\n"; |
||
| 1241 | echo '<input type="hidden" name="ftscfg" value="', htmlspecialchars($_POST['ftscfg']), "\" />\n"; |
||
| 1242 | echo "<input type=\"hidden\" name=\"prev_action\" value=\"viewconfig\" /></p>\n"; |
||
| 1243 | |||
| 1244 | echo $this->misc->form; |
||
| 1245 | echo "<input type=\"submit\" name=\"alter\" value=\"{$lang['stralter']}\" />\n"; |
||
| 1246 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 1247 | echo "</form>\n"; |
||
| 1248 | } else { |
||
| 1249 | echo "<p>{$lang['strftsnodictionaries']}</p>\n"; |
||
| 1250 | } |
||
| 1251 | } |
||
| 1252 | |||
| 1253 | /** |
||
| 1254 | * Save the form submission containing changes to a FTS mapping. |
||
| 1255 | */ |
||
| 1256 | public function doSaveAlterMapping() |
||
| 1257 | { |
||
| 1258 | $conf = $this->conf; |
||
| 1259 | |||
| 1260 | $lang = $this->lang; |
||
| 1261 | $data = $this->misc->getDatabaseAccessor(); |
||
| 1262 | |||
| 1263 | $mappingArray = (is_array($_POST['formMapping']) ? $_POST['formMapping'] : [$_POST['formMapping']]); |
||
| 1264 | $status = $data->changeFtsMapping($_POST['ftscfg'], $mappingArray, 'alter', $_POST['formDictionary']); |
||
| 1265 | if (0 == $status) { |
||
| 1266 | $this->doViewConfig($_POST['ftscfg'], $lang['strftsmappingaltered']); |
||
| 1267 | } else { |
||
| 1268 | $this->doAlterMapping($lang['strftsmappingalteredbad']); |
||
| 1269 | } |
||
| 1270 | } |
||
| 1271 | |||
| 1272 | /** |
||
| 1273 | * Show the form to enter parameters of a new FTS mapping. |
||
| 1274 | * |
||
| 1275 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 1276 | */ |
||
| 1277 | public function doAddMapping($msg = '') |
||
| 1278 | { |
||
| 1279 | $conf = $this->conf; |
||
| 1280 | |||
| 1281 | $lang = $this->lang; |
||
| 1282 | $data = $this->misc->getDatabaseAccessor(); |
||
| 1283 | |||
| 1284 | $this->printTrail('ftscfg'); |
||
| 1285 | $this->printTitle($lang['stralter'], 'pg.ftscfg.alter'); |
||
| 1286 | $this->printMsg($msg); |
||
| 1287 | |||
| 1288 | $ftsdicts = $data->getFtsDictionaries(); |
||
| 1289 | if ($ftsdicts->recordCount() > 0) { |
||
| 1290 | if (!isset($_POST['formMapping'])) { |
||
| 1291 | $_POST['formMapping'] = ''; |
||
| 1292 | } |
||
| 1293 | |||
| 1294 | if (!isset($_POST['formDictionary'])) { |
||
| 1295 | $_POST['formDictionary'] = ''; |
||
| 1296 | } |
||
| 1297 | |||
| 1298 | if (!isset($_POST['ftscfg'])) { |
||
| 1299 | $_POST['ftscfg'] = $_REQUEST['ftscfg']; |
||
| 1300 | } |
||
| 1301 | |||
| 1302 | $mappings = $data->getFtsMappings($_POST['ftscfg']); |
||
| 1303 | |||
| 1304 | echo '<form action="'.\SUBFOLDER."/src/views/fulltext.php\" method=\"post\">\n"; |
||
| 1305 | echo "<table>\n"; |
||
| 1306 | echo "\t<tr>\n"; |
||
| 1307 | echo "\t\t<th class=\"data left required\">{$lang['strftsmapping']}</th>\n"; |
||
| 1308 | echo "\t\t<td class=\"data1\">"; |
||
| 1309 | echo "\t\t\t<select name=\"formMapping\">\n"; |
||
| 1310 | while (!$mappings->EOF) { |
||
| 1311 | $mapping = htmlspecialchars($mappings->fields['name']); |
||
| 1312 | $mapping_desc = htmlspecialchars($mappings->fields['description']); |
||
| 1313 | echo "\t\t\t\t<option value=\"{$mapping}\"", |
||
| 1314 | $mapping == $_POST['formMapping'] ? ' selected="selected"' : '', ">{$mapping}", $mapping_desc ? " - {$mapping_desc}" : '', "</option>\n"; |
||
| 1315 | $mappings->moveNext(); |
||
| 1316 | } |
||
| 1317 | echo "\t\t</td>\n"; |
||
| 1318 | echo "\t</tr>\n"; |
||
| 1319 | |||
| 1320 | // Dictionary |
||
| 1321 | echo "\t<tr>\n"; |
||
| 1322 | echo "\t\t<th class=\"data left required\">{$lang['strftsdict']}</th>\n"; |
||
| 1323 | echo "\t\t<td class=\"data1\">"; |
||
| 1324 | echo "\t\t\t<select name=\"formDictionary\">\n"; |
||
| 1325 | while (!$ftsdicts->EOF) { |
||
| 1326 | $ftsdict = htmlspecialchars($ftsdicts->fields['name']); |
||
| 1327 | echo "\t\t\t\t<option value=\"{$ftsdict}\"", |
||
| 1328 | $ftsdict == $_POST['formDictionary'] ? ' selected="selected"' : '', ">{$ftsdict}</option>\n"; |
||
| 1329 | $ftsdicts->moveNext(); |
||
| 1330 | } |
||
| 1331 | |||
| 1332 | echo "\t\t</td>\n"; |
||
| 1333 | echo "\t</tr>\n"; |
||
| 1334 | |||
| 1335 | echo "</table>\n"; |
||
| 1336 | echo "<p><input type=\"hidden\" name=\"action\" value=\"addmapping\" />\n"; |
||
| 1337 | echo '<input type="hidden" name="ftscfg" value="', htmlspecialchars($_POST['ftscfg']), "\" />\n"; |
||
| 1338 | echo "<input type=\"hidden\" name=\"prev_action\" value=\"viewconfig\" /></p>\n"; |
||
| 1339 | echo $this->misc->form; |
||
| 1340 | echo "<input type=\"submit\" name=\"add\" value=\"{$lang['stradd']}\" />\n"; |
||
| 1341 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
| 1342 | echo "</form>\n"; |
||
| 1343 | } else { |
||
| 1344 | echo "<p>{$lang['strftsnodictionaries']}</p>\n"; |
||
| 1345 | } |
||
| 1346 | } |
||
| 1347 | |||
| 1348 | /** |
||
| 1349 | * Save the form submission containing parameters of a new FTS mapping. |
||
| 1350 | */ |
||
| 1351 | public function doSaveAddMapping() |
||
| 1352 | { |
||
| 1353 | $conf = $this->conf; |
||
|
0 ignored issues
–
show
|
|||
| 1354 | |||
| 1355 | $lang = $this->lang; |
||
| 1356 | $data = $this->misc->getDatabaseAccessor(); |
||
| 1357 | |||
| 1358 | $mappingArray = (is_array($_POST['formMapping']) ? $_POST['formMapping'] : [$_POST['formMapping']]); |
||
| 1359 | $status = $data->changeFtsMapping($_POST['ftscfg'], $mappingArray, 'add', $_POST['formDictionary']); |
||
| 1360 | if (0 == $status) { |
||
| 1361 | $this->doViewConfig($_POST['ftscfg'], $lang['strftsmappingadded']); |
||
| 1362 | } else { |
||
| 1363 | $this->doAddMapping($lang['strftsmappingaddedbad']); |
||
| 1364 | } |
||
| 1365 | } |
||
| 1366 | } |
||
| 1367 |