action) { return $this->doTree(); } if ('subtree' == $this->action) { return $this->doSubTree($_REQUEST['what']); } $this->printHeader(); $this->printBody(); if (isset($_POST['cancel'])) { if (isset($_POST['prev_action'])) { $this->action = $_POST['prev_action']; } else { $this->action = ''; } } switch ($this->action) { case 'createconfig': if (isset($_POST['create'])) { $this->doSaveCreateConfig(); } else { $this->doCreateConfig(); } break; case 'alterconfig': if (isset($_POST['alter'])) { $this->doSaveAlterConfig(); } else { $this->doAlterConfig(); } break; case 'dropconfig': if (isset($_POST['drop'])) { $this->doDropConfig(false); } else { $this->doDropConfig(true); } break; case 'viewconfig': $this->doViewConfig($_REQUEST['ftscfg']); break; case 'viewparsers': $this->doViewParsers(); break; case 'viewdicts': $this->doViewDicts(); break; case 'createdict': if (isset($_POST['create'])) { $this->doSaveCreateDict(); } else { $this->doCreateDict(); } break; case 'alterdict': if (isset($_POST['alter'])) { $this->doSaveAlterDict(); } else { $this->doAlterDict(); } break; case 'dropdict': if (isset($_POST['drop'])) { $this->doDropDict(false); } else { $this->doDropDict(true); } break; case 'dropmapping': if (isset($_POST['drop'])) { $this->doDropMapping(false); } else { $this->doDropMapping(true); } break; case 'altermapping': if (isset($_POST['alter'])) { $this->doSaveAlterMapping(); } else { $this->doAlterMapping(); } break; case 'addmapping': if (isset($_POST['add'])) { $this->doSaveAddMapping(); } else { $this->doAddMapping(); } break; default: $this->doDefault(); break; } return $this->printFooter(); } public function doDefault($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->printTrail('schema'); $this->printTabs('schema', 'fulltext'); $this->printTabs('fulltext', 'ftsconfigs'); $this->printMsg($msg); $cfgs = $data->getFtsConfigurations(false); $columns = [ 'configuration' => [ 'title' => $this->lang['strftsconfig'], 'field' => Decorator::field('name'), 'url' => "fulltext?action=viewconfig&{$this->misc->href}&", 'vars' => ['ftscfg' => 'name'], ], 'schema' => [ 'title' => $this->lang['strschema'], 'field' => Decorator::field('schema'), ], 'actions' => [ 'title' => $this->lang['stractions'], ], 'comment' => [ 'title' => $this->lang['strcomment'], 'field' => Decorator::field('comment'), ], ]; $actions = [ 'drop' => [ 'content' => $this->lang['strdrop'], 'attr' => [ 'href' => [ 'url' => 'fulltext', 'urlvars' => [ 'action' => 'dropconfig', 'ftscfg' => Decorator::field('name'), ], ], ], ], 'alter' => [ 'content' => $this->lang['stralter'], 'attr' => [ 'href' => [ 'url' => 'fulltext', 'urlvars' => [ 'action' => 'alterconfig', 'ftscfg' => Decorator::field('name'), ], ], ], ], ]; echo $this->printTable($cfgs, $columns, $actions, 'fulltext-fulltext', $this->lang['strftsnoconfigs']); $navlinks = [ 'createconf' => [ 'attr' => [ 'href' => [ 'url' => 'fulltext', 'urlvars' => [ 'action' => 'createconfig', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], ], ], ], 'content' => $this->lang['strftscreateconfig'], ], ]; $this->printNavLinks($navlinks, 'fulltext-fulltext', get_defined_vars()); } /** * Generate XML for the browser tree. */ public function doTree() { $tabs = $this->misc->getNavTabs('fulltext'); $items = $this->adjustTabsForTree($tabs); $reqvars = $this->misc->getRequestVars('ftscfg'); $attrs = [ 'text' => Decorator::field('title'), 'icon' => Decorator::field('icon'), 'action' => Decorator::actionurl( 'fulltext', $reqvars, Decorator::field('urlvars') ), 'branch' => Decorator::url( 'fulltext', $reqvars, [ 'action' => 'subtree', 'what' => Decorator::field('icon'), // IZ: yeah, it's ugly, but I do not want to change navigation tabs arrays ] ), ]; return $this->printTree($items, $attrs, 'fts'); } public function doSubTree($what) { $data = $this->misc->getDatabaseAccessor(); switch ($what) { case 'FtsCfg': $items = $data->getFtsConfigurations(false); $urlvars = ['action' => 'viewconfig', 'ftscfg' => Decorator::field('name')]; break; case 'FtsDict': $items = $data->getFtsDictionaries(false); $urlvars = ['action' => 'viewdicts']; break; case 'FtsParser': $items = $data->getFtsParsers(false); $urlvars = ['action' => 'viewparsers']; break; default: return; } $reqvars = $this->misc->getRequestVars('ftscfg'); $attrs = [ 'text' => Decorator::field('name'), 'icon' => $what, 'toolTip' => Decorator::field('comment'), 'action' => Decorator::actionurl( 'fulltext', $reqvars, $urlvars ), 'branch' => Decorator::ifempty( Decorator::field('branch'), '', Decorator::url( 'fulltext', $reqvars, [ 'action' => 'subtree', 'ftscfg' => Decorator::field('name'), ] ) ), ]; return $this->printTree($items, $attrs, strtolower($what)); } public function doDropConfig($confirm) { $data = $this->misc->getDatabaseAccessor(); if ($confirm) { $this->printTrail('ftscfg'); $this->printTitle($this->lang['strdrop'], 'pg.ftscfg.drop'); echo '
', sprintf($this->lang['strconfdropftsconfig'], $this->misc->printVal($_REQUEST['ftscfg'])), '
'.PHP_EOL; echo ''.PHP_EOL; } else { $status = $data->dropFtsConfiguration($_POST['ftscfg'], isset($_POST['cascade'])); if (0 == $status) { $this->misc->setReloadBrowser(true); $this->doDefault($this->lang['strftsconfigdropped']); } else { $this->doDefault($this->lang['strftsconfigdroppedbad']); } } } public function doDropDict($confirm) { $data = $this->misc->getDatabaseAccessor(); if ($confirm) { $this->printTrail('ftscfg'); // TODO: change to smth related to dictionary $this->printTitle($this->lang['strdrop'], 'pg.ftsdict.drop'); echo '', sprintf($this->lang['strconfdropftsdict'], $this->misc->printVal($_REQUEST['ftsdict'])), '
'.PHP_EOL; echo ''.PHP_EOL; } else { $status = $data->dropFtsDictionary($_POST['ftsdict'], isset($_POST['cascade'])); if (0 == $status) { $this->misc->setReloadBrowser(true); $this->doViewDicts($this->lang['strftsdictdropped']); } else { $this->doViewDicts($this->lang['strftsdictdroppedbad']); } } } /** * Displays a screen where one can enter a new FTS configuration. * * @param mixed $msg */ public function doCreateConfig($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->coalesceArr($_POST, 'formName', ''); $this->coalesceArr($_POST, 'formParser', ''); $this->coalesceArr($_POST, 'formTemplate', ''); $this->coalesceArr($_POST, 'formWithMap', ''); $this->coalesceArr($_POST, 'formComment', ''); // Fetch all FTS configurations from the database $ftscfgs = $data->getFtsConfigurations(); // Fetch all FTS parsers from the database $ftsparsers = $data->getFtsParsers(); $this->printTrail('schema'); $this->printTitle($this->lang['strftscreateconfig'], 'pg.ftscfg.create'); $this->printMsg($msg); echo ''.PHP_EOL; } /** * Actually creates the new FTS configuration in the database. */ public function doSaveCreateConfig() { $data = $this->misc->getDatabaseAccessor(); $err = ''; // Check that they've given a name if ('' == $_POST['formName']) { $err .= "{$this->lang['strftsconfigneedsname']}{$this->lang['strnodata']}
".PHP_EOL; } } /** * Save the form submission containing changes to a FTS configuration. */ public function doSaveAlterConfig() { $data = $this->misc->getDatabaseAccessor(); $status = $data->updateFtsConfiguration($_POST['ftscfg'], $_POST['formComment'], $_POST['formName']); if (0 == $status) { $this->doDefault($this->lang['strftsconfigaltered']); } else { $this->doAlterConfig($this->lang['strftsconfigalteredbad']); } } /** * View list of FTS parsers. * * @param mixed $msg */ public function doViewParsers($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->printTrail('schema'); $this->printTabs('schema', 'fulltext'); $this->printTabs('fulltext', 'ftsparsers'); $this->printMsg($msg); $parsers = $data->getFtsParsers(false); $columns = [ 'schema' => [ 'title' => $this->lang['strschema'], 'field' => Decorator::field('schema'), ], 'name' => [ 'title' => $this->lang['strname'], 'field' => Decorator::field('name'), ], 'comment' => [ 'title' => $this->lang['strcomment'], 'field' => Decorator::field('comment'), ], ]; $actions = []; echo $this->printTable($parsers, $columns, $actions, 'fulltext-viewparsers', $this->lang['strftsnoparsers']); //TODO: navlink to "create parser" } /** * View list of FTS dictionaries. * * @param mixed $msg */ public function doViewDicts($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->printTrail('schema'); $this->printTabs('schema', 'fulltext'); $this->printTabs('fulltext', 'ftsdicts'); $this->printMsg($msg); $dicts = $data->getFtsDictionaries(false); $columns = [ 'schema' => [ 'title' => $this->lang['strschema'], 'field' => Decorator::field('schema'), ], 'name' => [ 'title' => $this->lang['strname'], 'field' => Decorator::field('name'), ], 'actions' => [ 'title' => $this->lang['stractions'], ], 'comment' => [ 'title' => $this->lang['strcomment'], 'field' => Decorator::field('comment'), ], ]; $actions = [ 'drop' => [ 'content' => $this->lang['strdrop'], 'attr' => [ 'href' => [ 'url' => 'fulltext', 'urlvars' => [ 'action' => 'dropdict', 'ftsdict' => Decorator::field('name'), ], ], ], ], 'alter' => [ 'content' => $this->lang['stralter'], 'attr' => [ 'href' => [ 'url' => 'fulltext', 'urlvars' => [ 'action' => 'alterdict', 'ftsdict' => Decorator::field('name'), ], ], ], ], ]; echo $this->printTable($dicts, $columns, $actions, 'fulltext-viewdicts', $this->lang['strftsnodicts']); $navlinks = [ 'createdict' => [ 'attr' => [ 'href' => [ 'url' => 'fulltext', 'urlvars' => [ 'action' => 'createdict', 'server' => $_REQUEST['server'], 'database' => $_REQUEST['database'], 'schema' => $_REQUEST['schema'], ], ], ], 'content' => $this->lang['strftscreatedict'], ], ]; $this->printNavLinks($navlinks, 'fulltext-viewdicts', get_defined_vars()); } /** * View details of FTS configuration given. * * @param mixed $ftscfg * @param mixed $msg */ public function doViewConfig($ftscfg, $msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->printTrail('ftscfg'); $this->printTabs('schema', 'fulltext'); $this->printTabs('fulltext', 'ftsconfigs'); $this->printMsg($msg); echo "{$this->lang['strnodata']}
".PHP_EOL; } } /** * Save the form submission containing changes to a FTS dictionary. */ public function doSaveAlterDict() { $data = $this->misc->getDatabaseAccessor(); $status = $data->updateFtsDictionary($_POST['ftsdict'], $_POST['formComment'], $_POST['formName']); if (0 == $status) { $this->doViewDicts($this->lang['strftsdictaltered']); } else { $this->doAlterDict($this->lang['strftsdictalteredbad']); } } /** * Show confirmation of drop and perform actual drop of FTS mapping. * * @param mixed $confirm */ public function doDropMapping($confirm) { $data = $this->misc->getDatabaseAccessor(); if (empty($_REQUEST['mapping']) && empty($_REQUEST['ma'])) { $this->doDefault($this->lang['strftsspecifymappingtodrop']); return; } if (empty($_REQUEST['ftscfg'])) { $this->doDefault($this->lang['strftsspecifyconfigtoalter']); return; } if ($confirm) { $this->printTrail('ftscfg'); // TODO: proper breadcrumbs $this->printTitle($this->lang['strdrop'], 'pg.ftscfg.alter'); echo ''.PHP_EOL; } else { // Case of multiaction drop if (is_array($_REQUEST['mapping'])) { $status = $data->changeFtsMapping($_REQUEST['ftscfg'], $_REQUEST['mapping'], 'drop'); if (0 != $status) { $this->doViewConfig($_REQUEST['ftscfg'], $this->lang['strftsmappingdroppedbad']); return; } $this->doViewConfig($_REQUEST['ftscfg'], $this->lang['strftsmappingdropped']); } else { $status = $data->changeFtsMapping($_REQUEST['ftscfg'], [$_REQUEST['mapping']], 'drop'); if (0 == $status) { $this->doViewConfig($_REQUEST['ftscfg'], $this->lang['strftsmappingdropped']); } else { $this->doViewConfig($_REQUEST['ftscfg'], $this->lang['strftsmappingdroppedbad']); } } } } public function doAlterMapping($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->printTrail('ftscfg'); $this->printTitle($this->lang['stralter'], 'pg.ftscfg.alter'); $this->printMsg($msg); $ftsdicts = $data->getFtsDictionaries(); if ($ftsdicts->recordCount() > 0) { $this->coalesceArr($_POST, 'formMapping', @$_REQUEST['mapping']); $this->coalesceArr($_POST, 'formDictionary', ''); $this->coalesceArr($_POST, 'ftscfg', $_REQUEST['ftscfg']); echo ''.PHP_EOL; } else { echo "{$this->lang['strftsnodictionaries']}
".PHP_EOL; } } /** * Save the form submission containing changes to a FTS mapping. */ public function doSaveAlterMapping() { $data = $this->misc->getDatabaseAccessor(); $mappingArray = (is_array($_POST['formMapping']) ? $_POST['formMapping'] : [$_POST['formMapping']]); $status = $data->changeFtsMapping($_POST['ftscfg'], $mappingArray, 'alter', $_POST['formDictionary']); if (0 == $status) { $this->doViewConfig($_POST['ftscfg'], $this->lang['strftsmappingaltered']); } else { $this->doAlterMapping($this->lang['strftsmappingalteredbad']); } } /** * Show the form to enter parameters of a new FTS mapping. * * @param mixed $msg */ public function doAddMapping($msg = '') { $data = $this->misc->getDatabaseAccessor(); $this->printTrail('ftscfg'); $this->printTitle($this->lang['stralter'], 'pg.ftscfg.alter'); $this->printMsg($msg); $ftsdicts = $data->getFtsDictionaries(); if ($ftsdicts->recordCount() > 0) { $this->coalesceArr($_POST, 'formMapping', ''); $this->coalesceArr($_POST, 'formDictionary', ''); $this->coalesceArr($_POST, 'ftscfg', $_REQUEST['ftscfg']); $mappings = $data->getFtsMappings($_POST['ftscfg']); echo ''.PHP_EOL; } else { echo "{$this->lang['strftsnodictionaries']}
".PHP_EOL; } } /** * Save the form submission containing parameters of a new FTS mapping. */ public function doSaveAddMapping() { $data = $this->misc->getDatabaseAccessor(); $mappingArray = (is_array($_POST['formMapping']) ? $_POST['formMapping'] : [$_POST['formMapping']]); $status = $data->changeFtsMapping($_POST['ftscfg'], $mappingArray, 'add', $_POST['formDictionary']); if (0 == $status) { $this->doViewConfig($_POST['ftscfg'], $this->lang['strftsmappingadded']); } else { $this->doAddMapping($this->lang['strftsmappingaddedbad']); } } }