. */ /** * Class FrequentlyAskedQuestionsModule */ class FrequentlyAskedQuestionsModule extends Module implements ModuleMenuInterface, ModuleConfigInterface { /** {@inheritdoc} */ public function getTitle() { return /* I18N: Name of a module. Abbreviation for “Frequently Asked Questions” */ I18N::translate('FAQ'); } /** {@inheritdoc} */ public function getDescription() { return /* I18N: Description of the “FAQ” module */ I18N::translate('A list of frequently asked questions and answers.'); } /** {@inheritdoc} */ public function modAction($mod_action) { switch ($mod_action) { case 'admin_config': $this->config(); break; case 'admin_delete': $this->delete(); $this->config(); break; case 'admin_edit': $this->edit(); break; case 'admin_movedown': $this->movedown(); $this->config(); break; case 'admin_moveup': $this->moveup(); $this->config(); break; case 'show': $this->show(); break; default: http_response_code(404); } } /** {@inheritdoc} */ public function getConfigLink() { return 'module.php?mod=' . $this->getName() . '&mod_action=admin_config'; } /** * Action from the configuration page */ private function edit() { if (Filter::postBool('save') && Filter::checkCsrf()) { $block_id = Filter::postInteger('block_id'); if ($block_id) { Database::prepare( "UPDATE `##block` SET gedcom_id = NULLIF(:tree_id, '0'), block_order = :block_order WHERE block_id = :block_id" )->execute(array( 'tree_id' => Filter::postInteger('gedcom_id'), 'block_order' => Filter::postInteger('block_order'), 'block_id' => $block_id )); } else { Database::prepare( "INSERT INTO `##block` (gedcom_id, module_name, block_order) VALUES (NULLIF(:tree_id, '0'), :module_name, :block_order)" )->execute(array( 'tree_id' => Filter::postInteger('gedcom_id'), 'module_name' => $this->getName(), 'block_order' => Filter::postInteger('block_order'), )); $block_id = Database::getInstance()->lastInsertId(); } set_block_setting($block_id, 'header', Filter::post('header')); set_block_setting($block_id, 'faqbody', Filter::post('faqbody')); $languages = Filter::postArray('lang', null, array_keys(I18N::installedLanguages())); set_block_setting($block_id, 'languages', implode(',', $languages)); $this->config(); } else { $block_id = Filter::getInteger('block_id'); $controller = new PageController; if ($block_id) { $controller->setPageTitle(I18N::translate('Edit FAQ item')); $header = get_block_setting($block_id, 'header'); $faqbody = get_block_setting($block_id, 'faqbody'); $block_order = Database::prepare( "SELECT block_order FROM `##block` WHERE block_id = :block_id" )->execute(array('block_id' => $block_id))->fetchOne(); $gedcom_id = Database::prepare( "SELECT gedcom_id FROM `##block` WHERE block_id = :block_id" )->execute(array('block_id' => $block_id))->fetchOne(); } else { $controller->setPageTitle(I18N::translate('Add an FAQ item')); $header = ''; $faqbody = ''; $block_order = Database::prepare( "SELECT IFNULL(MAX(block_order)+1, 0) FROM `##block` WHERE module_name = :module_name" )->execute(array('module_name' => $this->getName()))->fetchOne(); $gedcom_id = WT_GED_ID; } $controller->pageHeader(); if (Module::getModuleByName('ckeditor')) { CkeditorModule::enableEditor($controller); } ?>
'; echo I18N::translate('Question'); echo ' |
---|
'; echo I18N::translate('Answer'); echo ' |
'; echo ''; echo ' |
', I18N::translate('Show this block for which languages?'), ' | '; echo '', I18N::translate('FAQ position'), ' | '; echo '', I18N::translate('FAQ visibility'), ' ', I18N::translate('A FAQ item can be displayed on just one of the family trees, or on all the family trees.'), ' | ';
echo '
---|---|---|
'; $languages = explode(',', get_block_setting($block_id, 'languages')); echo edit_language_checkboxes('lang', $languages); echo ' | '; echo ' | '; echo ''; echo select_edit_control('gedcom_id', Tree::getIdList(), I18N::translate('All'), $gedcom_id, 'tabindex="4"'); echo ' |
'; echo ''; } } /** * Respond to a request to delete a FAQ. */ private function delete() { $block_id = Filter::getInteger('block_id'); Database::prepare( "DELETE FROM `##block_setting` WHERE block_id = :block_id" )->execute(array('block_id' => $block_id)); Database::prepare( "DELETE FROM `##block` WHERE block_id = :block_id" )->execute(array('block_id' => $block_id)); } /** * Respond to a request to move a FAQ up the list. */ private function moveup() { $block_id = Filter::getInteger('block_id'); $block_order = Database::prepare( "SELECT block_order FROM `##block` WHERE block_id = :block_id" )->execute(array('block_id' => $block_id))->fetchOne(); $swap_block = Database::prepare( "SELECT block_order, block_id" . " FROM `##block`" . " WHERE block_order = (" . " SELECT MAX(block_order) FROM `##block` WHERE block_order < :block_order AND module_name = :module_name_1" . " ) AND module_name = :module_name_2" . " LIMIT 1" )->execute(array( 'block_order' => $block_order, 'module_name_1' => $this->getName(), 'module_name_2' => $this->getName() ))->fetchOneRow(); if ($swap_block) { Database::prepare( "UPDATE `##block` SET block_order = :block_order WHERE block_id = :block_id" )->execute(array( 'block_order' => $swap_block->block_order, 'block_id' => $block_id, )); Database::prepare( "UPDATE `##block` SET block_order = :block_order WHERE block_id = :block_id" )->execute(array( 'block_order' => $block_order, 'block_id' => $swap_block->block_id, )); } } /** * Respond to a request to move a FAQ down the list. */ private function movedown() { $block_id = Filter::get('block_id'); $block_order = Database::prepare( "SELECT block_order FROM `##block` WHERE block_id = :block_id" )->execute(array( 'block_id' => $block_id, ))->fetchOne(); $swap_block = Database::prepare( "SELECT block_order, block_id" . " FROM `##block`" . " WHERE block_order=(" . " SELECT MIN(block_order) FROM `##block` WHERE block_order > :block_order AND module_name = :module_name_1" . " ) AND module_name = :module_name_2" . " LIMIT 1" )->execute(array( 'block_order' => $block_order, 'module_name_1' => $this->getName(), 'module_name_2' => $this->getName(), ))->fetchOneRow(); if ($swap_block) { Database::prepare( "UPDATE `##block` SET block_order = :block_order WHERE block_id = :block_id" )->execute(array( 'block_order' => $swap_block->block_order, 'block_id' => $block_id, )); Database::prepare( "UPDATE `##block` SET block_order = :block_order WHERE block_id = :block_id" )->execute(array( 'block_order' => $block_order, 'block_id' => $swap_block->block_id, )); } } /** * Show a list of FAQs */ private function show() { global $controller, $WT_TREE; $controller = new PageController; $controller ->setPageTitle(I18N::translate('Frequently asked questions')) ->pageHeader(); $faqs = Database::prepare( "SELECT block_id, bs1.setting_value AS header, bs2.setting_value AS body, bs3.setting_value AS languages" . " FROM `##block` b" . " JOIN `##block_setting` bs1 USING (block_id)" . " JOIN `##block_setting` bs2 USING (block_id)" . " JOIN `##block_setting` bs3 USING (block_id)" . " WHERE module_name = :module_name" . " AND bs1.setting_name = 'header'" . " AND bs2.setting_name = 'faqbody'" . " AND bs3.setting_name = 'languages'" . " AND IFNULL(gedcom_id, :tree_id_1) = :tree_id_2" . " ORDER BY block_order" )->execute(array( 'module_name' => $this->getName(), 'tree_id_1' => WT_GED_ID, 'tree_id_2' => WT_GED_ID, ))->fetchAll(); // Define your colors for the alternating rows echo '
'; echo '', $faq->header, ''; echo ' |
'; echo '', I18N::translate('Add an FAQ item'), ''; echo '
', I18N::translate('The FAQ list is empty.'), ' |