xref: /webtrees/app/Module/FrequentlyAskedQuestionsModule.php (revision 4b9ff166b3342695f2a94855b7a33368e6d55c35)
18c2e8227SGreg Roach<?php
28c2e8227SGreg Roachnamespace Fisharebest\Webtrees;
38c2e8227SGreg Roach
48c2e8227SGreg Roach/**
58c2e8227SGreg Roach * webtrees: online genealogy
68c2e8227SGreg Roach * Copyright (C) 2015 webtrees development team
78c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify
88c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by
98c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or
108c2e8227SGreg Roach * (at your option) any later version.
118c2e8227SGreg Roach * This program is distributed in the hope that it will be useful,
128c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
138c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
148c2e8227SGreg Roach * GNU General Public License for more details.
158c2e8227SGreg Roach * You should have received a copy of the GNU General Public License
168c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
178c2e8227SGreg Roach */
188c2e8227SGreg Roach
198c2e8227SGreg Roach/**
208c2e8227SGreg Roach * Class FrequentlyAskedQuestionsModule
218c2e8227SGreg Roach */
228c2e8227SGreg Roachclass FrequentlyAskedQuestionsModule extends Module implements ModuleMenuInterface, ModuleConfigInterface {
238c2e8227SGreg Roach	/** {@inheritdoc} */
248c2e8227SGreg Roach	public function getTitle() {
258c2e8227SGreg Roach		return /* I18N: Name of a module.  Abbreviation for “Frequently Asked Questions” */ I18N::translate('FAQ');
268c2e8227SGreg Roach	}
278c2e8227SGreg Roach
288c2e8227SGreg Roach	/** {@inheritdoc} */
298c2e8227SGreg Roach	public function getDescription() {
308c2e8227SGreg Roach		return /* I18N: Description of the “FAQ” module */ I18N::translate('A list of frequently asked questions and answers.');
318c2e8227SGreg Roach	}
328c2e8227SGreg Roach
338c2e8227SGreg Roach	/** {@inheritdoc} */
348c2e8227SGreg Roach	public function modAction($mod_action) {
358c2e8227SGreg Roach		switch ($mod_action) {
368c2e8227SGreg Roach		case 'admin_config':
378c2e8227SGreg Roach			$this->config();
388c2e8227SGreg Roach			break;
398c2e8227SGreg Roach		case 'admin_delete':
408c2e8227SGreg Roach			$this->delete();
418c2e8227SGreg Roach			$this->config();
428c2e8227SGreg Roach			break;
438c2e8227SGreg Roach		case 'admin_edit':
448c2e8227SGreg Roach			$this->edit();
458c2e8227SGreg Roach			break;
468c2e8227SGreg Roach		case 'admin_movedown':
478c2e8227SGreg Roach			$this->movedown();
488c2e8227SGreg Roach			$this->config();
498c2e8227SGreg Roach			break;
508c2e8227SGreg Roach		case 'admin_moveup':
518c2e8227SGreg Roach			$this->moveup();
528c2e8227SGreg Roach			$this->config();
538c2e8227SGreg Roach			break;
548c2e8227SGreg Roach		case 'show':
558c2e8227SGreg Roach			$this->show();
568c2e8227SGreg Roach			break;
578c2e8227SGreg Roach		default:
588c2e8227SGreg Roach			http_response_code(404);
598c2e8227SGreg Roach		}
608c2e8227SGreg Roach	}
618c2e8227SGreg Roach
628c2e8227SGreg Roach	/** {@inheritdoc} */
638c2e8227SGreg Roach	public function getConfigLink() {
648c2e8227SGreg Roach		return 'module.php?mod=' . $this->getName() . '&amp;mod_action=admin_config';
658c2e8227SGreg Roach	}
668c2e8227SGreg Roach
678c2e8227SGreg Roach	/**
688c2e8227SGreg Roach	 * Action from the configuration page
698c2e8227SGreg Roach	 */
708c2e8227SGreg Roach	private function edit() {
718c2e8227SGreg Roach		if (Filter::postBool('save') && Filter::checkCsrf()) {
728c2e8227SGreg Roach			$block_id = Filter::postInteger('block_id');
738c2e8227SGreg Roach			if ($block_id) {
748c2e8227SGreg Roach				Database::prepare(
758c2e8227SGreg Roach					"UPDATE `##block` SET gedcom_id = NULLIF(:tree_id, '0'), block_order = :block_order WHERE block_id = :block_id"
768c2e8227SGreg Roach				)->execute(array(
778c2e8227SGreg Roach					'tree_id'     => Filter::postInteger('gedcom_id'),
788c2e8227SGreg Roach					'block_order' => Filter::postInteger('block_order'),
798c2e8227SGreg Roach					'block_id'    => $block_id
808c2e8227SGreg Roach				));
818c2e8227SGreg Roach			} else {
828c2e8227SGreg Roach				Database::prepare(
838c2e8227SGreg Roach					"INSERT INTO `##block` (gedcom_id, module_name, block_order) VALUES (NULLIF(:tree_id, '0'), :module_name, :block_order)"
848c2e8227SGreg Roach				)->execute(array(
858c2e8227SGreg Roach					'tree_id'     => Filter::postInteger('gedcom_id'),
868c2e8227SGreg Roach					'module_name' => $this->getName(),
878c2e8227SGreg Roach					'block_order' => Filter::postInteger('block_order'),
888c2e8227SGreg Roach				));
898c2e8227SGreg Roach				$block_id = Database::getInstance()->lastInsertId();
908c2e8227SGreg Roach			}
918c2e8227SGreg Roach			set_block_setting($block_id, 'header', Filter::post('header'));
928c2e8227SGreg Roach			set_block_setting($block_id, 'faqbody', Filter::post('faqbody'));
938c2e8227SGreg Roach
94764a01d9SGreg Roach			$languages = Filter::postArray('lang', null, array_keys(I18N::installedLanguages()));
958c2e8227SGreg Roach			set_block_setting($block_id, 'languages', implode(',', $languages));
968c2e8227SGreg Roach			$this->config();
978c2e8227SGreg Roach		} else {
988c2e8227SGreg Roach			$block_id   = Filter::getInteger('block_id');
998c2e8227SGreg Roach			$controller = new PageController;
1008c2e8227SGreg Roach			if ($block_id) {
1018c2e8227SGreg Roach				$controller->setPageTitle(I18N::translate('Edit FAQ item'));
1028c2e8227SGreg Roach				$header      = get_block_setting($block_id, 'header');
1038c2e8227SGreg Roach				$faqbody     = get_block_setting($block_id, 'faqbody');
1048c2e8227SGreg Roach				$block_order = Database::prepare(
1058c2e8227SGreg Roach					"SELECT block_order FROM `##block` WHERE block_id = :block_id"
1068c2e8227SGreg Roach				)->execute(array('block_id' => $block_id))->fetchOne();
1078c2e8227SGreg Roach				$gedcom_id   = Database::prepare(
1088c2e8227SGreg Roach					"SELECT gedcom_id FROM `##block` WHERE block_id = :block_id"
1098c2e8227SGreg Roach				)->execute(array('block_id' => $block_id))->fetchOne();
1108c2e8227SGreg Roach			} else {
1118c2e8227SGreg Roach				$controller->setPageTitle(I18N::translate('Add an FAQ item'));
1128c2e8227SGreg Roach				$header      = '';
1138c2e8227SGreg Roach				$faqbody     = '';
1148c2e8227SGreg Roach				$block_order = Database::prepare(
1158c2e8227SGreg Roach					"SELECT IFNULL(MAX(block_order)+1, 0) FROM `##block` WHERE module_name = :module_name"
1168c2e8227SGreg Roach				)->execute(array('module_name' => $this->getName()))->fetchOne();
1178c2e8227SGreg Roach				$gedcom_id   = WT_GED_ID;
1188c2e8227SGreg Roach			}
1198c2e8227SGreg Roach			$controller->pageHeader();
1208c2e8227SGreg Roach			if (Module::getModuleByName('ckeditor')) {
1218c2e8227SGreg Roach				CkeditorModule::enableEditor($controller);
1228c2e8227SGreg Roach			}
1238c2e8227SGreg Roach
1248c2e8227SGreg Roach			?>
1258c2e8227SGreg Roach			<ol class="breadcrumb small">
1268c2e8227SGreg Roach				<li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li>
1278c2e8227SGreg Roach				<li><a href="admin_modules.php"><?php echo I18N::translate('Module administration'); ?></a></li>
1288c2e8227SGreg Roach				<li><a href="module.php?mod=<?php echo $this->getName(); ?>&mod_action=admin_config"><?php echo I18N::translate('Frequently asked questions'); ?></a></li>
1298c2e8227SGreg Roach				<li class="active"><?php echo $controller->getPageTitle(); ?></li>
1308c2e8227SGreg Roach			</ol>
1318c2e8227SGreg Roach			<h2><?php echo $controller->getPageTitle(); ?></h2>
1328c2e8227SGreg Roach			<?php
1338c2e8227SGreg Roach
1348c2e8227SGreg Roach			echo '<form name="faq" method="post" action="module.php?mod=', $this->getName(), '&amp;mod_action=admin_edit">';
1358c2e8227SGreg Roach			echo Filter::getCsrf();
1368c2e8227SGreg Roach			echo '<input type="hidden" name="save" value="1">';
1378c2e8227SGreg Roach			echo '<input type="hidden" name="block_id" value="', $block_id, '">';
1388c2e8227SGreg Roach			echo '<table id="faq_module">';
1398c2e8227SGreg Roach			echo '<tr><th>';
1408c2e8227SGreg Roach			echo I18N::translate('Question');
1418c2e8227SGreg Roach			echo '</th></tr><tr><td><input type="text" name="header" size="90" tabindex="1" value="' . Filter::escapeHtml($header) . '"></td></tr>';
1428c2e8227SGreg Roach			echo '<tr><th>';
1438c2e8227SGreg Roach			echo I18N::translate('Answer');
1448c2e8227SGreg Roach			echo '</th></tr><tr><td>';
1458c2e8227SGreg Roach			echo '<textarea name="faqbody" class="html-edit" rows="10" cols="90" tabindex="2">', Filter::escapeHtml($faqbody), '</textarea>';
1468c2e8227SGreg Roach			echo '</td></tr>';
1478c2e8227SGreg Roach			echo '</table><table id="faq_module2">';
1488c2e8227SGreg Roach			echo '<tr>';
1498c2e8227SGreg Roach			echo '<th>', I18N::translate('Show this block for which languages?'), '</th>';
1508c2e8227SGreg Roach			echo '<th>', I18N::translate('FAQ position'), '</th>';
1518c2e8227SGreg Roach			echo '<th>', I18N::translate('FAQ visibility'), '<br><small>', I18N::translate('A FAQ item can be displayed on just one of the family trees, or on all the family trees.'), '</small></th>';
1528c2e8227SGreg Roach			echo '</tr><tr>';
1538c2e8227SGreg Roach			echo '<td>';
1548c2e8227SGreg Roach			$languages = explode(',', get_block_setting($block_id, 'languages'));
1558c2e8227SGreg Roach			echo edit_language_checkboxes('lang', $languages);
1568c2e8227SGreg Roach			echo '</td><td>';
1578c2e8227SGreg Roach			echo '<input type="text" name="block_order" size="3" tabindex="3" value="', $block_order, '"></td>';
1588c2e8227SGreg Roach			echo '</td><td>';
1598c2e8227SGreg Roach			echo select_edit_control('gedcom_id', Tree::getIdList(), I18N::translate('All'), $gedcom_id, 'tabindex="4"');
1608c2e8227SGreg Roach			echo '</td></tr>';
1618c2e8227SGreg Roach			echo '</table>';
1628c2e8227SGreg Roach
1638c2e8227SGreg Roach			echo '<p><input type="submit" value="', I18N::translate('save'), '" tabindex="5">';
1648c2e8227SGreg Roach			echo '</form>';
1658c2e8227SGreg Roach		}
1668c2e8227SGreg Roach	}
1678c2e8227SGreg Roach
1688c2e8227SGreg Roach	/**
1698c2e8227SGreg Roach	 * Respond to a request to delete a FAQ.
1708c2e8227SGreg Roach	 */
1718c2e8227SGreg Roach	private function delete() {
1728c2e8227SGreg Roach		$block_id = Filter::getInteger('block_id');
1738c2e8227SGreg Roach
1748c2e8227SGreg Roach		Database::prepare(
1758c2e8227SGreg Roach			"DELETE FROM `##block_setting` WHERE block_id = :block_id"
1768c2e8227SGreg Roach		)->execute(array('block_id' => $block_id));
1778c2e8227SGreg Roach
1788c2e8227SGreg Roach		Database::prepare(
1798c2e8227SGreg Roach			"DELETE FROM `##block` WHERE block_id = :block_id"
1808c2e8227SGreg Roach		)->execute(array('block_id' => $block_id));
1818c2e8227SGreg Roach	}
1828c2e8227SGreg Roach
1838c2e8227SGreg Roach	/**
1848c2e8227SGreg Roach	 * Respond to a request to move a FAQ up the list.
1858c2e8227SGreg Roach	 */
1868c2e8227SGreg Roach	private function moveup() {
1878c2e8227SGreg Roach		$block_id = Filter::getInteger('block_id');
1888c2e8227SGreg Roach
1898c2e8227SGreg Roach		$block_order = Database::prepare(
1908c2e8227SGreg Roach			"SELECT block_order FROM `##block` WHERE block_id = :block_id"
1918c2e8227SGreg Roach		)->execute(array('block_id' => $block_id))->fetchOne();
1928c2e8227SGreg Roach
1938c2e8227SGreg Roach		$swap_block = Database::prepare(
1948c2e8227SGreg Roach			"SELECT block_order, block_id" .
1958c2e8227SGreg Roach			" FROM `##block`" .
1968c2e8227SGreg Roach			" WHERE block_order = (" .
1978c2e8227SGreg Roach			"  SELECT MAX(block_order) FROM `##block` WHERE block_order < :block_order AND module_name = :module_name_1" .
1988c2e8227SGreg Roach			" ) AND module_name = :module_name_2" .
1998c2e8227SGreg Roach			" LIMIT 1"
2008c2e8227SGreg Roach		)->execute(array(
2018c2e8227SGreg Roach			'block_order'   => $block_order,
2028c2e8227SGreg Roach			'module_name_1' => $this->getName(),
2038c2e8227SGreg Roach			'module_name_2' => $this->getName()
2048c2e8227SGreg Roach		))->fetchOneRow();
2058c2e8227SGreg Roach		if ($swap_block) {
2068c2e8227SGreg Roach			Database::prepare(
2078c2e8227SGreg Roach				"UPDATE `##block` SET block_order = :block_order WHERE block_id = :block_id"
2088c2e8227SGreg Roach			)->execute(array(
2098c2e8227SGreg Roach				'block_order' => $swap_block->block_order,
2108c2e8227SGreg Roach				'block_id'    => $block_id,
2118c2e8227SGreg Roach			));
2128c2e8227SGreg Roach			Database::prepare(
2138c2e8227SGreg Roach				"UPDATE `##block` SET block_order = :block_order WHERE block_id = :block_id"
2148c2e8227SGreg Roach			)->execute(array(
2158c2e8227SGreg Roach				'block_order' => $block_order,
2168c2e8227SGreg Roach				'block_id'    => $swap_block->block_id,
2178c2e8227SGreg Roach			));
2188c2e8227SGreg Roach		}
2198c2e8227SGreg Roach	}
2208c2e8227SGreg Roach
2218c2e8227SGreg Roach	/**
2228c2e8227SGreg Roach	 * Respond to a request to move a FAQ down the list.
2238c2e8227SGreg Roach	 */
2248c2e8227SGreg Roach	private function movedown() {
2258c2e8227SGreg Roach		$block_id = Filter::get('block_id');
2268c2e8227SGreg Roach
2278c2e8227SGreg Roach		$block_order = Database::prepare(
2288c2e8227SGreg Roach			"SELECT block_order FROM `##block` WHERE block_id = :block_id"
2298c2e8227SGreg Roach		)->execute(array(
2308c2e8227SGreg Roach			'block_id' => $block_id,
2318c2e8227SGreg Roach		))->fetchOne();
2328c2e8227SGreg Roach
2338c2e8227SGreg Roach		$swap_block = Database::prepare(
2348c2e8227SGreg Roach			"SELECT block_order, block_id" .
2358c2e8227SGreg Roach			" FROM `##block`" .
2368c2e8227SGreg Roach			" WHERE block_order=(" .
2378c2e8227SGreg Roach			"  SELECT MIN(block_order) FROM `##block` WHERE block_order > :block_order AND module_name = :module_name_1" .
2388c2e8227SGreg Roach			" ) AND module_name = :module_name_2" .
2398c2e8227SGreg Roach			" LIMIT 1"
2408c2e8227SGreg Roach		)->execute(array(
2418c2e8227SGreg Roach			'block_order'   => $block_order,
2428c2e8227SGreg Roach			'module_name_1' => $this->getName(),
2438c2e8227SGreg Roach			'module_name_2' => $this->getName(),
2448c2e8227SGreg Roach			))->fetchOneRow();
2458c2e8227SGreg Roach		if ($swap_block) {
2468c2e8227SGreg Roach			Database::prepare(
2478c2e8227SGreg Roach				"UPDATE `##block` SET block_order = :block_order WHERE block_id = :block_id"
2488c2e8227SGreg Roach			)->execute(array(
2498c2e8227SGreg Roach				'block_order' => $swap_block->block_order,
2508c2e8227SGreg Roach				'block_id'    => $block_id,
2518c2e8227SGreg Roach			));
2528c2e8227SGreg Roach			Database::prepare(
2538c2e8227SGreg Roach				"UPDATE `##block` SET block_order = :block_order WHERE block_id = :block_id"
2548c2e8227SGreg Roach			)->execute(array(
2558c2e8227SGreg Roach				'block_order' => $block_order,
2568c2e8227SGreg Roach				'block_id'    => $swap_block->block_id,
2578c2e8227SGreg Roach			));
2588c2e8227SGreg Roach		}
2598c2e8227SGreg Roach	}
2608c2e8227SGreg Roach
2618c2e8227SGreg Roach	/**
2628c2e8227SGreg Roach	 * Show a list of FAQs
2638c2e8227SGreg Roach	 */
2648c2e8227SGreg Roach	private function show() {
265*4b9ff166SGreg Roach		global $controller, $WT_TREE;
266*4b9ff166SGreg Roach
2678c2e8227SGreg Roach		$controller = new PageController;
2688c2e8227SGreg Roach		$controller
2698c2e8227SGreg Roach			->setPageTitle(I18N::translate('Frequently asked questions'))
2708c2e8227SGreg Roach			->pageHeader();
2718c2e8227SGreg Roach
2728c2e8227SGreg Roach		$faqs = Database::prepare(
2738c2e8227SGreg Roach			"SELECT block_id, bs1.setting_value AS header, bs2.setting_value AS body, bs3.setting_value AS languages" .
2748c2e8227SGreg Roach			" FROM `##block` b" .
2758c2e8227SGreg Roach			" JOIN `##block_setting` bs1 USING (block_id)" .
2768c2e8227SGreg Roach			" JOIN `##block_setting` bs2 USING (block_id)" .
2778c2e8227SGreg Roach			" JOIN `##block_setting` bs3 USING (block_id)" .
2788c2e8227SGreg Roach			" WHERE module_name = :module_name" .
2798c2e8227SGreg Roach			" AND bs1.setting_name = 'header'" .
2808c2e8227SGreg Roach			" AND bs2.setting_name = 'faqbody'" .
2818c2e8227SGreg Roach			" AND bs3.setting_name = 'languages'" .
2828c2e8227SGreg Roach			" AND IFNULL(gedcom_id, :tree_id_1) = :tree_id_2" .
2838c2e8227SGreg Roach			" ORDER BY block_order"
2848c2e8227SGreg Roach		)->execute(array(
2858c2e8227SGreg Roach			'module_name' => $this->getName(),
2868c2e8227SGreg Roach			'tree_id_1'   => WT_GED_ID,
2878c2e8227SGreg Roach			'tree_id_2'   => WT_GED_ID,
2888c2e8227SGreg Roach		))->fetchAll();
2898c2e8227SGreg Roach
2908c2e8227SGreg Roach		// Define your colors for the alternating rows
2918c2e8227SGreg Roach		echo '<h2 class="center">', I18N::translate('Frequently asked questions'), '</h2>';
2928c2e8227SGreg Roach		// Instructions
2938c2e8227SGreg Roach		echo '<div class="faq_italic">', I18N::translate('Click on a title to go straight to it, or scroll down to read them all');
294*4b9ff166SGreg Roach		if (Auth::isManager($WT_TREE)) {
2958c2e8227SGreg Roach			echo '<div class="faq_edit"><a href="module.php?mod=', $this->getName(), '&amp;mod_action=admin_config">', I18N::translate('Click here to add, edit, or delete'), '</a></div>';
2968c2e8227SGreg Roach		}
2978c2e8227SGreg Roach		echo '</div>';
2988c2e8227SGreg Roach		$row_count = 0;
2998c2e8227SGreg Roach		echo '<table class="faq">';
3008c2e8227SGreg Roach		// List of titles
3018c2e8227SGreg Roach		foreach ($faqs as $id => $faq) {
3028c2e8227SGreg Roach			if (!$faq->languages || in_array(WT_LOCALE, explode(',', $faq->languages))) {
3038c2e8227SGreg Roach				$row_color = ($row_count % 2) ? 'odd' : 'even';
3048c2e8227SGreg Roach				// NOTE: Print the header of the current item
3058c2e8227SGreg Roach				echo '<tr class="', $row_color, '"><td style="padding: 5px;">';
3068c2e8227SGreg Roach				echo '<a href="#faq', $id, '">', $faq->header, '</a>';
3078c2e8227SGreg Roach				echo '</td></tr>';
3088c2e8227SGreg Roach				$row_count++;
3098c2e8227SGreg Roach			}
3108c2e8227SGreg Roach		}
3118c2e8227SGreg Roach		echo '</table><hr>';
3128c2e8227SGreg Roach		// Detailed entries
3138c2e8227SGreg Roach		foreach ($faqs as $id => $faq) {
3148c2e8227SGreg Roach			if (!$faq->languages || in_array(WT_LOCALE, explode(',', $faq->languages))) {
3158c2e8227SGreg Roach				echo '<div class="faq_title" id="faq', $id, '">', $faq->header;
3168c2e8227SGreg Roach				echo '<div class="faq_top faq_italic">';
3178c2e8227SGreg Roach				echo '<a href="#content">', I18N::translate('back to top'), '</a>';
3188c2e8227SGreg Roach				echo '</div>';
3198c2e8227SGreg Roach				echo '</div>';
3208c2e8227SGreg Roach				echo '<div class="faq_body">', substr($faq->body, 0, 1) == '<' ? $faq->body : nl2br($faq->body, false), '</div>';
3218c2e8227SGreg Roach				echo '<hr>';
3228c2e8227SGreg Roach			}
3238c2e8227SGreg Roach		}
3248c2e8227SGreg Roach	}
3258c2e8227SGreg Roach
3268c2e8227SGreg Roach	/**
3278c2e8227SGreg Roach	 * Provide a form to manage the FAQs.
3288c2e8227SGreg Roach	 */
3298c2e8227SGreg Roach	private function config() {
3308c2e8227SGreg Roach		$controller = new PageController;
3318c2e8227SGreg Roach		$controller
3328c2e8227SGreg Roach			->setPageTitle(I18N::translate('Frequently asked questions'))
3338c2e8227SGreg Roach			->pageHeader();
3348c2e8227SGreg Roach
3358c2e8227SGreg Roach		$faqs = Database::prepare(
3368c2e8227SGreg Roach			"SELECT block_id, block_order, gedcom_id, bs1.setting_value AS header, bs2.setting_value AS faqbody" .
3378c2e8227SGreg Roach			" FROM `##block` b" .
3388c2e8227SGreg Roach			" JOIN `##block_setting` bs1 USING (block_id)" .
3398c2e8227SGreg Roach			" JOIN `##block_setting` bs2 USING (block_id)" .
3408c2e8227SGreg Roach			" WHERE module_name = :module_name" .
3418c2e8227SGreg Roach			" AND bs1.setting_name = 'header'" .
3428c2e8227SGreg Roach			" AND bs2.setting_name = 'faqbody'" .
3438c2e8227SGreg Roach			" AND IFNULL(gedcom_id, :tree_id_1) = :tree_id_2" .
3448c2e8227SGreg Roach			" ORDER BY block_order"
3458c2e8227SGreg Roach		)->execute(array(
3468c2e8227SGreg Roach			'module_name' => $this->getName(),
3478c2e8227SGreg Roach			'tree_id_1'   => WT_GED_ID,
3488c2e8227SGreg Roach			'tree_id_2'   => WT_GED_ID,
3498c2e8227SGreg Roach			))->fetchAll();
3508c2e8227SGreg Roach
3518c2e8227SGreg Roach		$min_block_order = Database::prepare(
3528c2e8227SGreg Roach			"SELECT MIN(block_order) FROM `##block` WHERE module_name=?"
3538c2e8227SGreg Roach		)->execute(array($this->getName()))->fetchOne();
3548c2e8227SGreg Roach
3558c2e8227SGreg Roach		$max_block_order = Database::prepare(
3568c2e8227SGreg Roach			"SELECT MAX(block_order) FROM `##block` WHERE module_name=?"
3578c2e8227SGreg Roach		)->execute(array($this->getName()))->fetchOne();
3588c2e8227SGreg Roach
3598c2e8227SGreg Roach		?>
3608c2e8227SGreg Roach		<ol class="breadcrumb small">
3618c2e8227SGreg Roach			<li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li>
3628c2e8227SGreg Roach			<li><a href="admin_modules.php"><?php echo I18N::translate('Module administration'); ?></a></li>
3638c2e8227SGreg Roach			<li class="active"><?php echo $controller->getPageTitle(); ?></li>
3648c2e8227SGreg Roach		</ol>
3658c2e8227SGreg Roach		<h2><?php echo $controller->getPageTitle(); ?></h2>
3668c2e8227SGreg Roach		<p>
3678c2e8227SGreg Roach			<?php echo I18N::translate('FAQs are lists of questions and answers, which allow you to explain the site’s rules, policies, and procedures to your visitors.  Questions are typically concerned with privacy, copyright, user-accounts, unsuitable content, requirement for source-citations, etc.'); ?>
3688c2e8227SGreg Roach			<?php echo I18N::translate('You may use HTML to format the answer and to add links to other websites.'); ?>
3698c2e8227SGreg Roach		</p>
3708c2e8227SGreg Roach		<?php
3718c2e8227SGreg Roach
3728c2e8227SGreg Roach		echo
3738c2e8227SGreg Roach			'<p><form>',
3748c2e8227SGreg Roach			I18N::translate('Family tree'), ' ',
3758c2e8227SGreg Roach			'<input type="hidden" name="mod", value="', $this->getName(), '">',
3768c2e8227SGreg Roach			'<input type="hidden" name="mod_action" value="admin_config">',
3778c2e8227SGreg Roach			select_edit_control('ged', Tree::getNameList(), null, WT_GEDCOM),
3788c2e8227SGreg Roach			'<input type="submit" value="', I18N::translate('show'), '">',
3798c2e8227SGreg Roach			'</form></p>';
3808c2e8227SGreg Roach
3818c2e8227SGreg Roach		echo '<a href="module.php?mod=', $this->getName(), '&amp;mod_action=admin_edit">', I18N::translate('Add an FAQ item'), '</a>';
3828c2e8227SGreg Roach
3838c2e8227SGreg Roach		echo '<table id="faq_edit">';
3848c2e8227SGreg Roach		if (empty($faqs)) {
3858c2e8227SGreg Roach			echo '<tr><td class="error center" colspan="5">', I18N::translate('The FAQ list is empty.'), '</td></tr></table>';
3868c2e8227SGreg Roach		} else {
3878c2e8227SGreg Roach			$trees = Tree::getAll();
3888c2e8227SGreg Roach			foreach ($faqs as $faq) {
3898c2e8227SGreg Roach				// NOTE: Print the position of the current item
3908c2e8227SGreg Roach				echo '<tr class="faq_edit_pos"><td>';
3918c2e8227SGreg Roach				echo I18N::translate('Position item'), ': ', ($faq->block_order + 1), ', ';
3928c2e8227SGreg Roach				if ($faq->gedcom_id == null) {
3938c2e8227SGreg Roach					echo I18N::translate('All');
3948c2e8227SGreg Roach				} else {
3958c2e8227SGreg Roach					echo $trees[$faq->gedcom_id]->getTitleHtml();
3968c2e8227SGreg Roach				}
3978c2e8227SGreg Roach				echo '</td>';
3988c2e8227SGreg Roach				// NOTE: Print the edit options of the current item
3998c2e8227SGreg Roach				echo '<td>';
4008c2e8227SGreg Roach				if ($faq->block_order == $min_block_order) {
4018c2e8227SGreg Roach					echo '&nbsp;';
4028c2e8227SGreg Roach				} else {
4038c2e8227SGreg Roach					echo '<a href="module.php?mod=', $this->getName(), '&amp;mod_action=admin_moveup&amp;block_id=', $faq->block_id, '" class="icon-uarrow"></a>';
4048c2e8227SGreg Roach				}
4058c2e8227SGreg Roach				echo '</td><td>';
4068c2e8227SGreg Roach				if ($faq->block_order == $max_block_order) {
4078c2e8227SGreg Roach					echo '&nbsp;';
4088c2e8227SGreg Roach				} else {
4098c2e8227SGreg Roach					echo '<a href="module.php?mod=', $this->getName(), '&amp;mod_action=admin_movedown&amp;block_id=', $faq->block_id, '" class="icon-darrow"></a>';
4108c2e8227SGreg Roach				}
4118c2e8227SGreg Roach				echo '</td><td>';
4128c2e8227SGreg Roach				echo '<a href="module.php?mod=', $this->getName(), '&amp;mod_action=admin_edit&amp;block_id=', $faq->block_id, '">', I18N::translate('Edit'), '</a>';
4138c2e8227SGreg Roach				echo '</td><td>';
4148c2e8227SGreg Roach				echo '<a href="module.php?mod=', $this->getName(), '&amp;mod_action=admin_delete&amp;block_id=', $faq->block_id, '" onclick="return confirm(\'', I18N::translate('Are you sure you want to delete this FAQ entry?'), '\');">', I18N::translate('Delete'), '</a>';
4158c2e8227SGreg Roach				echo '</td></tr>';
4168c2e8227SGreg Roach				// NOTE: Print the title text of the current item
4178c2e8227SGreg Roach				echo '<tr><td colspan="5">';
4188c2e8227SGreg Roach				echo '<div class="faq_edit_item">';
4198c2e8227SGreg Roach				echo '<div class="faq_edit_title">', $faq->header, '</div>';
4208c2e8227SGreg Roach				// NOTE: Print the body text of the current item
4218c2e8227SGreg Roach				echo '<div class="faq_edit_content">', substr($faq->faqbody, 0, 1) == '<' ? $faq->faqbody : nl2br($faq->faqbody, false), '</div></div></td></tr>';
4228c2e8227SGreg Roach			}
4238c2e8227SGreg Roach			echo '</table>';
4248c2e8227SGreg Roach		}
4258c2e8227SGreg Roach	}
4268c2e8227SGreg Roach
4278c2e8227SGreg Roach	/** {@inheritdoc} */
4288c2e8227SGreg Roach	public function defaultMenuOrder() {
4298c2e8227SGreg Roach		return 40;
4308c2e8227SGreg Roach	}
4318c2e8227SGreg Roach
4328c2e8227SGreg Roach	/** {@inheritdoc} */
4338c2e8227SGreg Roach	public function getMenu() {
4348c2e8227SGreg Roach		if (Auth::isSearchEngine()) {
4358c2e8227SGreg Roach			return null;
4368c2e8227SGreg Roach		}
4378c2e8227SGreg Roach
4388c2e8227SGreg Roach		$faqs = Database::prepare(
4398c2e8227SGreg Roach			"SELECT block_id FROM `##block` WHERE module_name = :module_name AND IFNULL(gedcom_id, :tree_id_1) = :tree_id_2"
4408c2e8227SGreg Roach		)->execute(array(
4418c2e8227SGreg Roach			'module_name' => $this->getName(),
4428c2e8227SGreg Roach			'tree_id_1'   => WT_GED_ID,
4438c2e8227SGreg Roach			'tree_id_2'   => WT_GED_ID,
4448c2e8227SGreg Roach		))->fetchAll();
4458c2e8227SGreg Roach
4468c2e8227SGreg Roach		if (!$faqs) {
4478c2e8227SGreg Roach			return null;
4488c2e8227SGreg Roach		}
4498c2e8227SGreg Roach
4508c2e8227SGreg Roach		$menu = new Menu(I18N::translate('FAQ'), 'module.php?mod=faq&amp;mod_action=show', 'menu-help');
4518c2e8227SGreg Roach
4528c2e8227SGreg Roach		return $menu;
4538c2e8227SGreg Roach	}
4548c2e8227SGreg Roach}
455