summaryrefslogtreecommitdiff
path: root/modules_v3/faq
diff options
context:
space:
mode:
authorfisharebest <fisharebest@gmail.com>2011-08-04 19:03:17 +0000
committerfisharebest <fisharebest@gmail.com>2011-08-04 19:03:17 +0000
commit3a66749533ae4ec372c95f7b0a6363efa4f5d294 (patch)
tree48931d265ee51c08f56820a767237975b00ebc3a /modules_v3/faq
parentd83d060a1ac10dc72134c3d4804e89b04cc68ad6 (diff)
downloadwebtrees-3a66749533ae4ec372c95f7b0a6363efa4f5d294.tar.gz
webtrees-3a66749533ae4ec372c95f7b0a6363efa4f5d294.tar.bz2
webtrees-3a66749533ae4ec372c95f7b0a6363efa4f5d294.zip
#821050 - Error calling page after update to 1.2.2
Diffstat (limited to 'modules_v3/faq')
-rw-r--r--modules_v3/faq/help_text.php72
-rw-r--r--modules_v3/faq/module.php418
2 files changed, 490 insertions, 0 deletions
diff --git a/modules_v3/faq/help_text.php b/modules_v3/faq/help_text.php
new file mode 100644
index 0000000000..7340f9c8d6
--- /dev/null
+++ b/modules_v3/faq/help_text.php
@@ -0,0 +1,72 @@
+<?php
+/**
+ * Module help text.
+ *
+ * This file is included from the application help_text.php script.
+ * It simply needs to set $title and $text for the help topic $help_topic
+ *
+ * webtrees: Web based Family History software
+ * Copyright (C) 2010 webtrees development team.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * @version $Id$
+ */
+
+if (!defined('WT_WEBTREES') || !defined('WT_SCRIPT_NAME') || WT_SCRIPT_NAME!='help_text.php') {
+ header('HTTP/1.0 403 Forbidden');
+ exit;
+}
+
+switch ($help) {
+case 'add_faq_item':
+ $title=WT_I18N::translate('Frequently asked questions');
+ $text=
+ WT_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.').
+ '<br/><br/>'.
+ WT_I18N::translate('You may use HTML to format the answer and to add links to other websites.');
+ break;
+
+case 'add_faq_order':
+ $title=WT_I18N::translate('FAQ position');
+ $text=WT_I18N::translate('This field controls the order in which the FAQ items are displayed.<br /><br />You do not have to enter the numbers sequentially. If you leave holes in the numbering scheme, you can insert other items later. For example, if you use the numbers 1, 6, 11, 16, you can later insert items with the missing sequence numbers. Negative numbers and zero are allowed, and can be used to insert items in front of the first one.<br /><br />When more than one FAQ item has the same position number, only one of these items will be visible.');
+ break;
+
+case 'add_faq_visibility':
+ $title=WT_I18N::translate('FAQ visibility');
+ $text=WT_I18N::translate('You can determine whether this FAQ will be visible regardless of GEDCOM, or whether it will be visible only to the current GEDCOM.<br /><ul><li><b>ALL</b>&nbsp;&nbsp;&nbsp;The FAQ will appear in all FAQ lists, regardless of GEDCOM.</li><li><b>%s</b>&nbsp;&nbsp;&nbsp;The FAQ will appear only in the currently active GEDCOM\'s FAQ list.</li></ul>', WT_GEDCOM);
+ break;
+
+case 'delete_faq_item':
+ $title=WT_I18N::translate('Delete FAQ item');
+ $text=WT_I18N::translate('This option will let you delete an item from the FAQ page');
+ break;
+
+case 'edit_faq_item':
+ $title=WT_I18N::translate('Edit FAQ item');
+ $text=WT_I18N::translate('This option will let you edit an item on the FAQ page.');
+ break;
+
+case 'movedown_faq_item':
+ $title=WT_I18N::translate('Move FAQ item down');
+ $text=WT_I18N::translate('This option will let you move an item downwards on the FAQ page.<br /><br />Each time you use this option, the FAQ Position number of this item is increased by one. You can achieve the same effect by editing the item in question and changing the FAQ Position field. When more than one FAQ item has the same position number, only one of these items will be visible.');
+ break;
+
+case 'moveup_faq_item':
+ $title=WT_I18N::translate('Move FAQ item up');
+ $text=WT_I18N::translate('This option will let you move an item upwards on the FAQ page.<br /><br />Each time you use this option, the FAQ Position number of this item is reduced by one. You can achieve the same effect by editing the item in question and changing the FAQ Position field. When more than one FAQ item has the same position number, only one of these items will be visible.');
+ break;
+
+}
diff --git a/modules_v3/faq/module.php b/modules_v3/faq/module.php
new file mode 100644
index 0000000000..49a83410f2
--- /dev/null
+++ b/modules_v3/faq/module.php
@@ -0,0 +1,418 @@
+<?php
+// Classes and libraries for module system
+//
+// webtrees: Web based Family History software
+// Copyright (C) 2011 webtrees development team.
+//
+// Derived from PhpGedView
+// Copyright (C) 2010 John Finlay
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// $Id$
+
+if (!defined('WT_WEBTREES')) {
+ header('HTTP/1.0 403 Forbidden');
+ exit;
+}
+
+class faq_WT_Module extends WT_Module implements WT_Module_Block, WT_Module_Config {
+ // Extend class WT_Module
+ public function getTitle() {
+ return /* I18N: Name of a module. Abbreviation for "Frequently Asked Questions" */ WT_I18N::translate('FAQ');
+ }
+
+ // Extend class WT_Module
+ public function getDescription() {
+ return /* I18N: Description of the "FAQ" module */ WT_I18N::translate('A list of frequently asked questions and answers.');
+ }
+
+ // Extend WT_Module
+ 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:
+ header('HTTP/1.0 404 Not Found');
+ }
+ }
+
+ // Implement WT_Module_Config
+ public function getConfigLink() {
+ return 'module.php?mod='.$this->getName().'&amp;mod_action=admin_config';
+ }
+
+ // Implement class WT_Module_Block
+ public function getBlock($block_id, $template=true, $cfg=null) {
+ }
+
+ // Implement class WT_Module_Block
+ public function loadAjax() {
+ return false;
+ }
+
+ // Implement class WT_Module_Block
+ public function isUserBlock() {
+ return false;
+ }
+
+ // Implement class WT_Module_Block
+ public function isGedcomBlock() {
+ return false;
+ }
+
+ // Implement class WT_Module_Block
+ public function configureBlock($block_id) {
+ }
+
+ // Action from the configuration page
+ private function edit() {
+ global $TEXT_DIRECTION;
+
+ require_once WT_ROOT.'includes/functions/functions_edit.php';
+
+ if (safe_POST_bool('save')) {
+ $block_id=safe_POST('block_id');
+ if ($block_id) {
+ WT_DB::prepare(
+ "UPDATE `##block` SET gedcom_id=?, block_order=? WHERE block_id=?"
+ )->execute(array(
+ safe_POST('gedcom_id'),
+ (int)safe_POST('block_order'),
+ $block_id
+ ));
+ } else {
+ WT_DB::prepare(
+ "INSERT INTO `##block` (gedcom_id, module_name, block_order) VALUES (?, ?, ?)"
+ )->execute(array(
+ safe_POST('gedcom_id', array_keys(get_all_gedcoms())),
+ $this->getName(),
+ (int)safe_POST('block_order')
+ ));
+ $block_id=WT_DB::getInstance()->lastInsertId();
+ }
+ set_block_setting($block_id, 'header', safe_POST('header', WT_REGEX_UNSAFE));
+ set_block_setting($block_id, 'faqbody', safe_POST('faqbody', WT_REGEX_UNSAFE)); // allow html
+ $languages=array();
+ foreach (WT_I18N::installed_languages() as $code=>$name) {
+ if (safe_POST_bool('lang_'.$code)) {
+ $languages[]=$code;
+ }
+ }
+ set_block_setting($block_id, 'languages', implode(',', $languages));
+ $this->config();
+ } else {
+ $block_id=safe_GET('block_id');
+ if ($block_id) {
+ print_header(WT_I18N::translate('Edit FAQ item'));
+ $header=get_block_setting($block_id, 'header');
+ $faqbody=get_block_setting($block_id, 'faqbody');
+ $block_order=WT_DB::prepare(
+ "SELECT block_order FROM `##block` WHERE block_id=?"
+ )->execute(array($block_id))->fetchOne();
+ $gedcom_id=WT_DB::prepare(
+ "SELECT gedcom_id FROM `##block` WHERE block_id=?"
+ )->execute(array($block_id))->fetchOne();
+ } else {
+ print_header(WT_I18N::translate('Add FAQ item'));
+ $header='';
+ $faqbody='';
+ $block_order=WT_DB::prepare(
+ "SELECT IFNULL(MAX(block_order)+1, 0) FROM `##block` WHERE module_name=?"
+ )->execute(array($this->getName()))->fetchOne();
+ $gedcom_id=WT_GED_ID;
+ }
+
+ // "Help for this page" link
+ echo '<div id="page_help">', help_link('add_faq_item', $this->getName()), '</div>';
+ echo '<form name="faq" method="post" action="#">';
+ echo '<input type="hidden" name="save" value="1" />';
+ echo '<input type="hidden" name="block_id" value="', $block_id, '" />';
+ echo '<table id="faq_module">';
+ echo '<tr><th>';
+ echo WT_I18N::translate('Question');
+ echo '</th></tr><tr><td><input type="text" name="header" size="90" tabindex="1" value="'.htmlspecialchars($header).'"/></td></tr>';
+ echo '<tr><th>';
+ echo WT_I18N::translate('Answer');
+ echo '</th></tr><tr><td>';
+ if (array_key_exists('ckeditor', WT_Module::getActiveModules())) {
+ // use CKeditor module
+ require_once WT_ROOT.WT_MODULES_DIR.'ckeditor/ckeditor.php';
+ $oCKeditor = new CKEditor();
+ $oCKeditor->basePath = WT_MODULES_DIR.'ckeditor/';
+ $oCKeditor->config['width'] = 900;
+ $oCKeditor->config['height'] = 400;
+ $oCKeditor->config['AutoDetectLanguage'] = false ;
+ $oCKeditor->config['DefaultLanguage'] = 'en';
+ $oCKeditor->editor('faqbody', $faqbody);
+ } else {
+ //use standard textarea
+ echo '<textarea name="faqbody" rows="10" cols="90" tabindex="2">', htmlspecialchars($faqbody), '</textarea>';
+ }
+ echo '</td></tr>';
+ echo '</table><table id="faq_module2">';
+ echo '<tr>';
+ echo '<th>', WT_I18N::translate('Show this block for which languages?'), '</th>';
+ echo '<th>', WT_I18N::translate('FAQ position'), help_link('add_faq_order', $this->getName()), '</th>';
+ echo '<th>', WT_I18N::translate('FAQ visibility'), help_link('add_faq_visibility', $this->getName()), '</th>';
+ echo '</tr><tr>';
+ echo '<td>';
+ $languages=get_block_setting($block_id, 'languages');
+ echo edit_language_checkboxes('lang_', $languages);
+ echo '</td><td>';
+ echo '<input type="text" name="block_order" size="3" tabindex="3" value="', $block_order, '" /></td>';
+ echo '</td><td>';
+ echo '<select name="gedcom_id" tabindex="4" />';
+ echo '<option value="">', WT_I18N::translate('All'), '</option>';
+ echo '<option value="', WT_GED_ID, '" selected="selected">', WT_I18N::translate('%s', get_gedcom_setting(WT_GED_ID, 'title')), '</option';
+ echo '</select>';
+ echo '</td></tr>';
+ echo '</table>';
+
+ echo '<p><input type="submit" value="', WT_I18N::translate('Save'), '" tabindex="5"/>';
+ echo '&nbsp;<input type="button" value="', WT_I18N::translate('Cancel'), '" onclick="window.location=\''.$this->getConfigLink().'\';" tabindex="6" /></p>';
+ echo '</form>';
+
+ print_footer();
+ exit;
+ }
+ }
+
+ private function delete() {
+ $block_id=safe_GET('block_id');
+
+ $block_order=WT_DB::prepare(
+ "SELECT block_order FROM `##block` WHERE block_id=?"
+ )->execute(array($block_id))->fetchOne();
+
+ WT_DB::prepare(
+ "DELETE FROM `##block_setting` WHERE block_id=?"
+ )->execute(array($block_id));
+
+ WT_DB::prepare(
+ "DELETE FROM `##block` WHERE block_id=?"
+ )->execute(array($block_id));
+ }
+
+ private function moveup() {
+ $block_id=safe_GET('block_id');
+
+ $block_order=WT_DB::prepare(
+ "SELECT block_order FROM `##block` WHERE block_id=?"
+ )->execute(array($block_id))->fetchOne();
+
+ $swap_block=WT_DB::prepare(
+ "SELECT block_order, block_id".
+ " FROM `##block`".
+ " WHERE block_order=(".
+ " SELECT MAX(block_order) FROM `##block` WHERE block_order < ? AND module_name=?".
+ " )".
+ " LIMIT 1"
+ )->execute(array($block_order, $this->getName()))->fetchOneRow();
+ if ($swap_block) {
+ WT_DB::prepare(
+ "UPDATE `##block` SET block_order=? WHERE block_id=?"
+ )->execute(array($swap_block->block_order, $block_id));
+ WT_DB::prepare(
+ "UPDATE `##block` SET block_order=? WHERE block_id=?"
+ )->execute(array($block_order, $swap_block->block_id));
+ }
+ }
+
+ private function movedown() {
+ $block_id=safe_GET('block_id');
+
+ $block_order=WT_DB::prepare(
+ "SELECT block_order FROM `##block` WHERE block_id=?"
+ )->execute(array($block_id))->fetchOne();
+
+ $swap_block=WT_DB::prepare(
+ "SELECT block_order, block_id".
+ " FROM `##block`".
+ " WHERE block_order=(".
+ " SELECT MIN(block_order) FROM `##block` WHERE block_order>? AND module_name=?".
+ " )".
+ " LIMIT 1"
+ )->execute(array($block_order, $this->getName()))->fetchOneRow();
+ if ($swap_block) {
+ WT_DB::prepare(
+ "UPDATE `##block` SET block_order=? WHERE block_id=?"
+ )->execute(array($swap_block->block_order, $block_id));
+ WT_DB::prepare(
+ "UPDATE `##block` SET block_order=? WHERE block_id=?"
+ )->execute(array($block_order, $swap_block->block_id));
+ }
+ }
+
+ private function show() {
+ print_header($this->getTitle());
+
+ $faqs=WT_DB::prepare(
+ "SELECT block_id, bs1.setting_value AS header, bs2.setting_value AS body".
+ " FROM `##block` b".
+ " JOIN `##block_setting` bs1 USING (block_id)".
+ " JOIN `##block_setting` bs2 USING (block_id)".
+ " WHERE module_name=?".
+ " AND bs1.setting_name='header'".
+ " AND bs2.setting_name='faqbody'".
+ " AND (gedcom_id IS NULL OR gedcom_id=?)".
+ " ORDER BY block_order"
+ )->execute(array($this->getName(), WT_GED_ID))->fetchAll();
+
+ // Define your colors for the alternating rows
+ echo '<h2 class="center">', WT_I18N::translate('Frequently asked questions'), '</h2>';
+ // Instructions
+ echo '<div class="faq_italic">', WT_I18N::translate('Click on a title to go straight to it, or scroll down to read them all');
+ if (WT_USER_GEDCOM_ADMIN) {
+ echo '<div class="faq_edit">',
+ '<a href="module.php?mod=faq&mod_action=admin_config">', WT_I18N::translate('Click here to Add, Edit, or Delete'), '</a>',
+ '</div>';
+ }
+ echo '</div>';
+ //Start the table to contain the list of headers
+ $row_count = 0;
+ echo '<table class="faq">';
+ // List of titles
+ foreach ($faqs as $id => $faq) {
+ $header =get_block_setting($faq->block_id, 'header');
+ $faqbody =get_block_setting($faq->block_id, 'faqbody');
+ $languages=get_block_setting($faq->block_id, 'languages');
+ if (!$languages || in_array(WT_LOCALE, explode(',', $languages))) {
+ $row_color = ($row_count % 2) ? 'odd' : 'even';
+ // NOTE: Print the header of the current item
+ echo '<tr class="', $row_color, '"><td style="padding: 5px;">';
+ echo '<a href="#faq', $id, '">', $id+1, ' ', $faq->header, '</a>';
+ echo '</td></tr>';
+ $row_count++;
+ }
+ }
+ echo '</table><hr>';
+ // Detailed entries
+ echo '<table>';
+ foreach ($faqs as $id => $faq) {
+ $header =get_block_setting($faq->block_id, 'header');
+ $faqbody =get_block_setting($faq->block_id, 'faqbody');
+ $languages=get_block_setting($faq->block_id, 'languages');
+ if (!$languages || in_array(WT_LOCALE, explode(',', $languages))) {
+ // NOTE: Print the body text of the current item, with its header
+ echo '<div class="faq_title" id="faq', $id, '">', $faq->header;
+ echo '<div class="faq_top faq_italic">';
+ echo '<a href="#body">', WT_I18N::translate('back to top'), '</a>';
+ echo '</div>';
+ echo '</div>';
+ echo '<div class="faq_body">', substr($faqbody, 0, 1)=='<' ? $faqbody : nl2br($faqbody), '</div>';
+ echo '<hr />';
+ }
+ }
+ echo '</table>';
+
+ print_footer();
+ }
+
+ private function config() {
+ global $WT_IMAGES;
+
+ print_header($this->getTitle());
+
+ $faqs=WT_DB::prepare(
+ "SELECT block_id, block_order, gedcom_id, bs1.setting_value AS header, bs2.setting_value AS faqbody".
+ " FROM `##block` b".
+ " JOIN `##block_setting` bs1 USING (block_id)".
+ " JOIN `##block_setting` bs2 USING (block_id)".
+ " WHERE module_name=?".
+ " AND bs1.setting_name='header'".
+ " AND bs2.setting_name='faqbody'".
+ " AND (gedcom_id IS NULL OR gedcom_id=?)".
+ " ORDER BY block_order"
+ )->execute(array($this->getName(), WT_GED_ID))->fetchAll();
+
+ $min_block_order=WT_DB::prepare(
+ "SELECT MIN(block_order) FROM `##block` WHERE module_name=?"
+ )->execute(array($this->getName()))->fetchOne();
+
+ $max_block_order=WT_DB::prepare(
+ "SELECT MAX(block_order) FROM `##block` WHERE module_name=?"
+ )->execute(array($this->getName()))->fetchOne();
+
+ echo '<table class="list_table width100">';
+ echo '<tr><td class="width20 list_label" colspan="5">';
+ echo '<a href="module.php?mod=', $this->getName(), '&amp;mod_action=admin_edit">', WT_I18N::translate('Add FAQ item'), '</a>';
+ echo help_link('add_faq_item', $this->getName());
+ echo '</td></tr>';
+ if (empty($faqs)) {
+ echo '<tr><td class="error center">', WT_I18N::translate('The FAQ list is empty.'), '</td></tr></table>';
+ } else {
+ foreach ($faqs as $faq) {
+ echo '<tr>';
+ // NOTE: Print the position of the current item
+ echo '<td class="descriptionbox width20 $TEXT_DIRECTION">';
+ echo WT_I18N::translate('Position item'), ': ', $faq->block_order, ', ';
+ if ($faq->gedcom_id==null) {
+ echo WT_I18N::translate('All');
+ } else {
+ echo get_gedcom_from_id($faq->gedcom_id);
+ }
+ echo '</td>';
+ echo '<td class="descriptionbox">', $faq->header, '</td>';
+ echo '<tr>';
+ // NOTE: Print the edit options of the current item
+ echo '<td class="optionbox center">';
+ if ($faq->block_order==$min_block_order) {
+ echo '&nbsp;';
+ } else {
+ echo '<a href="module.php?mod=', $this->getName(), '&amp;mod_action=admin_moveup&amp;block_id=', $faq->block_id, '"><img src="', $WT_IMAGES["uarrow"], '" border="0" alt="" /></a>';
+ echo help_link('moveup_faq_item', $this->getName());
+ }
+ echo '</td><td class="optionbox center">';
+ if ($faq->block_order==$max_block_order) {
+ echo '&nbsp;';
+ } else {
+ echo '<a href="module.php?mod=', $this->getName(), '&amp;mod_action=admin_movedown&amp;block_id=', $faq->block_id, '"><img src="', $WT_IMAGES["darrow"], '" border="0" alt="" /></a>';
+ echo help_link('movedown_faq_item', $this->getName());
+ }
+ echo '</td><td class="optionbox center">';
+ echo '<a href="module.php?mod=', $this->getName(), '&amp;mod_action=admin_edit&amp;block_id=', $faq->block_id, '">', WT_I18N::translate('Edit'), '</a>';
+ echo help_link('edit_faq_item', $this->getName());
+ echo '</td><td class="optionbox center">';
+ echo '<a href="module.php?mod=', $this->getName(), '&amp;mod_action=admin_delete&amp;block_id=', $faq->block_id, '" onclick="return confirm(\'', WT_I18N::translate('Are you sure you want to delete this FAQ entry?'), '\');">', WT_I18N::translate('Delete'), '</a>';
+ echo help_link('delete_faq_item', $this->getName());
+ echo '</td>';
+ // NOTE: Print the body text of the current item
+ echo '<td class="list_value_wrap">', substr($faq->faqbody, 0, 1)=='<' ? $faq->faqbody : nl2br($faq->faqbody), '</td></tr>';
+ }
+ echo '</table>';
+ }
+ print_footer();
+ }
+}