xref: /webtrees/app/Module/StoriesModule.php (revision 24ec66ce7e77188cd2495b0f8d4dd0ae6e8c9c52)
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 StoriesModule
218c2e8227SGreg Roach */
228c2e8227SGreg Roachclass StoriesModule extends Module implements ModuleTabInterface, ModuleConfigInterface, ModuleMenuInterface {
238c2e8227SGreg Roach	/** {@inheritdoc} */
248c2e8227SGreg Roach	public function getTitle() {
258c2e8227SGreg Roach		return /* I18N: Name of a module */ I18N::translate('Stories');
268c2e8227SGreg Roach	}
278c2e8227SGreg Roach
288c2e8227SGreg Roach	/** {@inheritdoc} */
298c2e8227SGreg Roach	public function getDescription() {
308c2e8227SGreg Roach		return /* I18N: Description of the “Stories” module */ I18N::translate('Add narrative stories to individuals in the family tree.');
318c2e8227SGreg Roach	}
328c2e8227SGreg Roach
338c2e8227SGreg Roach	/** {@inheritdoc} */
348c2e8227SGreg Roach	public function modAction($mod_action) {
358c2e8227SGreg Roach		switch ($mod_action) {
368c2e8227SGreg Roach		case 'admin_edit':
378c2e8227SGreg Roach			$this->edit();
388c2e8227SGreg Roach			break;
398c2e8227SGreg Roach		case 'admin_delete':
408c2e8227SGreg Roach			$this->delete();
418c2e8227SGreg Roach			$this->config();
428c2e8227SGreg Roach			break;
438c2e8227SGreg Roach		case 'admin_config':
448c2e8227SGreg Roach			$this->config();
458c2e8227SGreg Roach			break;
468c2e8227SGreg Roach		case 'show_list':
478c2e8227SGreg Roach			$this->showList();
488c2e8227SGreg Roach			break;
498c2e8227SGreg Roach		default:
508c2e8227SGreg Roach			http_response_code(404);
518c2e8227SGreg Roach		}
528c2e8227SGreg Roach	}
538c2e8227SGreg Roach
548c2e8227SGreg Roach	/** {@inheritdoc} */
558c2e8227SGreg Roach	public function getConfigLink() {
568c2e8227SGreg Roach		return 'module.php?mod=' . $this->getName() . '&amp;mod_action=admin_config';
578c2e8227SGreg Roach	}
588c2e8227SGreg Roach
598c2e8227SGreg Roach	/** {@inheritdoc} */
608c2e8227SGreg Roach	public function defaultTabOrder() {
618c2e8227SGreg Roach		return 55;
628c2e8227SGreg Roach	}
638c2e8227SGreg Roach
648c2e8227SGreg Roach	/** {@inheritdoc} */
658c2e8227SGreg Roach	public function getTabContent() {
664b9ff166SGreg Roach		global $controller, $WT_TREE;
678c2e8227SGreg Roach
688c2e8227SGreg Roach		$block_ids =
698c2e8227SGreg Roach			Database::prepare(
708c2e8227SGreg Roach				"SELECT block_id" .
718c2e8227SGreg Roach				" FROM `##block`" .
728c2e8227SGreg Roach				" WHERE module_name=?" .
738c2e8227SGreg Roach				" AND xref=?" .
748c2e8227SGreg Roach				" AND gedcom_id=?"
758c2e8227SGreg Roach			)->execute(array(
768c2e8227SGreg Roach				$this->getName(),
778c2e8227SGreg Roach				$controller->record->getXref(),
78*24ec66ceSGreg Roach				$controller->record->getTree()->getTreeId()
798c2e8227SGreg Roach			))->fetchOneColumn();
808c2e8227SGreg Roach
818c2e8227SGreg Roach		$html = '';
828c2e8227SGreg Roach		foreach ($block_ids as $block_id) {
838c2e8227SGreg Roach			// Only show this block for certain languages
848c2e8227SGreg Roach			$languages = get_block_setting($block_id, 'languages');
858c2e8227SGreg Roach			if (!$languages || in_array(WT_LOCALE, explode(',', $languages))) {
868c2e8227SGreg Roach				$html .= '<div class="story_title descriptionbox center rela">' . get_block_setting($block_id, 'title') . '</div>';
878c2e8227SGreg Roach				$html .= '<div class="story_body optionbox">' . get_block_setting($block_id, 'story_body') . '</div>';
884b9ff166SGreg Roach				if (Auth::isEditor($WT_TREE)) {
898c2e8227SGreg Roach					$html .= '<div class="story_edit"><a href="module.php?mod=' . $this->getName() . '&amp;mod_action=admin_edit&amp;block_id=' . $block_id . '">';
908c2e8227SGreg Roach					$html .= I18N::translate('Edit story') . '</a></div>';
918c2e8227SGreg Roach				}
928c2e8227SGreg Roach			}
938c2e8227SGreg Roach		}
944b9ff166SGreg Roach		if (Auth::isManager($WT_TREE) && !$html) {
958c2e8227SGreg Roach			$html .= '<div class="news_title center">' . $this->getTitle() . '</div>';
968c2e8227SGreg Roach			$html .= '<div><a href="module.php?mod=' . $this->getName() . '&amp;mod_action=admin_edit&amp;xref=' . $controller->record->getXref() . '">';
978c2e8227SGreg Roach			$html .= I18N::translate('Add a story') . '</a></div><br>';
988c2e8227SGreg Roach		}
998c2e8227SGreg Roach
1008c2e8227SGreg Roach		return $html;
1018c2e8227SGreg Roach	}
1028c2e8227SGreg Roach
1038c2e8227SGreg Roach	/** {@inheritdoc} */
1048c2e8227SGreg Roach	public function hasTabContent() {
1058c2e8227SGreg Roach		return $this->getTabContent() <> '';
1068c2e8227SGreg Roach	}
1078c2e8227SGreg Roach
1088c2e8227SGreg Roach	/** {@inheritdoc} */
1098c2e8227SGreg Roach	public function isGrayedOut() {
1108c2e8227SGreg Roach		global $controller;
1118c2e8227SGreg Roach
1128c2e8227SGreg Roach		$count_of_stories =
1138c2e8227SGreg Roach			Database::prepare(
1148c2e8227SGreg Roach				"SELECT COUNT(block_id)" .
1158c2e8227SGreg Roach				" FROM `##block`" .
1168c2e8227SGreg Roach				" WHERE module_name=?" .
1178c2e8227SGreg Roach				" AND xref=?" .
1188c2e8227SGreg Roach				" AND gedcom_id=?"
1198c2e8227SGreg Roach			)->execute(array(
1208c2e8227SGreg Roach				$this->getName(),
1218c2e8227SGreg Roach				$controller->record->getXref(),
122*24ec66ceSGreg Roach				$controller->record->getTree()->getTreeId()
1238c2e8227SGreg Roach			))->fetchOne();
1248c2e8227SGreg Roach
1258c2e8227SGreg Roach		return $count_of_stories == 0;
1268c2e8227SGreg Roach	}
1278c2e8227SGreg Roach
1288c2e8227SGreg Roach	/** {@inheritdoc} */
1298c2e8227SGreg Roach	public function canLoadAjax() {
1308c2e8227SGreg Roach		return false;
1318c2e8227SGreg Roach	}
1328c2e8227SGreg Roach
1338c2e8227SGreg Roach	/** {@inheritdoc} */
1348c2e8227SGreg Roach	public function getPreLoadContent() {
1358c2e8227SGreg Roach		return '';
1368c2e8227SGreg Roach	}
1378c2e8227SGreg Roach
1388c2e8227SGreg Roach	/**
1398c2e8227SGreg Roach	 * Show and process a form to edit a story.
1408c2e8227SGreg Roach	 */
1418c2e8227SGreg Roach	private function edit() {
1424b9ff166SGreg Roach		global $WT_TREE;
1434b9ff166SGreg Roach
1444b9ff166SGreg Roach		if (Auth::isEditor($WT_TREE)) {
1458c2e8227SGreg Roach			if (Filter::postBool('save') && Filter::checkCsrf()) {
1468c2e8227SGreg Roach				$block_id = Filter::postInteger('block_id');
1478c2e8227SGreg Roach				if ($block_id) {
1488c2e8227SGreg Roach					Database::prepare(
1498c2e8227SGreg Roach						"UPDATE `##block` SET gedcom_id=?, xref=? WHERE block_id=?"
1508c2e8227SGreg Roach					)->execute(array(Filter::postInteger('gedcom_id'), Filter::post('xref', WT_REGEX_XREF), $block_id));
1518c2e8227SGreg Roach				} else {
1528c2e8227SGreg Roach					Database::prepare(
1538c2e8227SGreg Roach						"INSERT INTO `##block` (gedcom_id, xref, module_name, block_order) VALUES (?, ?, ?, ?)"
1548c2e8227SGreg Roach					)->execute(array(
1558c2e8227SGreg Roach						Filter::postInteger('gedcom_id'),
1568c2e8227SGreg Roach						Filter::post('xref', WT_REGEX_XREF),
1578c2e8227SGreg Roach						$this->getName(),
1588c2e8227SGreg Roach						0
1598c2e8227SGreg Roach					));
1608c2e8227SGreg Roach					$block_id = Database::getInstance()->lastInsertId();
1618c2e8227SGreg Roach				}
1628c2e8227SGreg Roach				set_block_setting($block_id, 'title', Filter::post('title'));
1638c2e8227SGreg Roach				set_block_setting($block_id, 'story_body', Filter::post('story_body'));
164764a01d9SGreg Roach				$languages = Filter::postArray('lang', null, array_keys(I18N::installedLanguages()));
1658c2e8227SGreg Roach				set_block_setting($block_id, 'languages', implode(',', $languages));
1668c2e8227SGreg Roach				$this->config();
1678c2e8227SGreg Roach			} else {
1688c2e8227SGreg Roach				$block_id = Filter::getInteger('block_id');
1698c2e8227SGreg Roach
1708c2e8227SGreg Roach				$controller = new PageController;
1718c2e8227SGreg Roach				if ($block_id) {
1728c2e8227SGreg Roach					$controller->setPageTitle(I18N::translate('Edit story'));
1738c2e8227SGreg Roach					$title      = get_block_setting($block_id, 'title');
1748c2e8227SGreg Roach					$story_body = get_block_setting($block_id, 'story_body');
1758c2e8227SGreg Roach					$xref       = Database::prepare(
1768c2e8227SGreg Roach						"SELECT xref FROM `##block` WHERE block_id=?"
1778c2e8227SGreg Roach					)->execute(array($block_id))->fetchOne();
1788c2e8227SGreg Roach				} else {
1798c2e8227SGreg Roach					$controller->setPageTitle(I18N::translate('Add a story'));
1808c2e8227SGreg Roach					$title      = '';
1818c2e8227SGreg Roach					$story_body = '';
1828c2e8227SGreg Roach					$xref       = Filter::get('xref', WT_REGEX_XREF);
1838c2e8227SGreg Roach				}
1848c2e8227SGreg Roach				$controller
1858c2e8227SGreg Roach					->pageHeader()
1868c2e8227SGreg Roach					->addExternalJavascript(WT_AUTOCOMPLETE_JS_URL)
1878c2e8227SGreg Roach					->addInlineJavascript('autocomplete();');
1888c2e8227SGreg Roach				if (Module::getModuleByName('ckeditor')) {
1898c2e8227SGreg Roach					CkeditorModule::enableEditor($controller);
1908c2e8227SGreg Roach				}
1918c2e8227SGreg Roach
1928c2e8227SGreg Roach				?>
1938c2e8227SGreg Roach				<ol class="breadcrumb small">
1948c2e8227SGreg Roach					<li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li>
1958c2e8227SGreg Roach					<li><a href="admin_modules.php"><?php echo I18N::translate('Module administration'); ?></a></li>
1968c2e8227SGreg Roach					<li><a href="module.php?mod=<?php echo $this->getName(); ?>&mod_action=admin_config"><?php echo $this->getTitle(); ?></a></li>
1978c2e8227SGreg Roach					<li class="active"><?php echo $controller->getPageTitle(); ?></li>
1988c2e8227SGreg Roach				</ol>
1998c2e8227SGreg Roach
2008c2e8227SGreg Roach				<h1><?php echo $controller->getPageTitle(); ?></h1>
2018c2e8227SGreg Roach				<?php
2028c2e8227SGreg Roach
2038c2e8227SGreg Roach				echo '<form name="story" method="post" action="module.php?mod=', $this->getName(), '&amp;mod_action=admin_edit">';
2048c2e8227SGreg Roach				echo Filter::getCsrf();
2058c2e8227SGreg Roach				echo '<input type="hidden" name="save" value="1">';
2068c2e8227SGreg Roach				echo '<input type="hidden" name="block_id" value="', $block_id, '">';
207*24ec66ceSGreg Roach				echo '<input type="hidden" name="gedcom_id" value="', $WT_TREE->getTreeId(), '">';
2088c2e8227SGreg Roach				echo '<table id="story_module">';
2098c2e8227SGreg Roach				echo '<tr><th>';
2108c2e8227SGreg Roach				echo I18N::translate('Story title');
2118c2e8227SGreg Roach				echo '</th></tr><tr><td><textarea name="title" rows="1" cols="90" tabindex="2">', Filter::escapeHtml($title), '</textarea></td></tr>';
2128c2e8227SGreg Roach				echo '<tr><th>';
2138c2e8227SGreg Roach				echo I18N::translate('Story');
2148c2e8227SGreg Roach				echo '</th></tr><tr><td>';
2158c2e8227SGreg Roach				echo '<textarea name="story_body" class="html-edit" rows="10" cols="90" tabindex="2">', Filter::escapeHtml($story_body), '</textarea>';
2168c2e8227SGreg Roach				echo '</td></tr>';
2178c2e8227SGreg Roach				echo '</table><table id="story_module2">';
2188c2e8227SGreg Roach				echo '<tr>';
2198c2e8227SGreg Roach				echo '<th>', I18N::translate('Individual'), '</th>';
2208c2e8227SGreg Roach				echo '<th>', I18N::translate('Show this block for which languages?'), '</th>';
2218c2e8227SGreg Roach				echo '</tr>';
2228c2e8227SGreg Roach				echo '<tr>';
2238c2e8227SGreg Roach				echo '<td class="optionbox">';
2248c2e8227SGreg Roach				echo '<input data-autocomplete-type="INDI" type="text" name="xref" id="pid" size="4" value="' . $xref . '">';
2258c2e8227SGreg Roach				echo print_findindi_link('pid');
2268c2e8227SGreg Roach				if ($xref) {
227*24ec66ceSGreg Roach					$person = Individual::getInstance($xref, $WT_TREE);
2288c2e8227SGreg Roach					if ($person) {
229e9165d70SGreg Roach						echo ' ', $person->formatList('span');
2308c2e8227SGreg Roach					}
2318c2e8227SGreg Roach				}
2328c2e8227SGreg Roach				echo '</td>';
2338c2e8227SGreg Roach				$languages = explode(',', get_block_setting($block_id, 'languages'));
2348c2e8227SGreg Roach				echo '<td class="optionbox">';
2358c2e8227SGreg Roach				echo edit_language_checkboxes('lang', $languages);
2368c2e8227SGreg Roach				echo '</td></tr></table>';
2378c2e8227SGreg Roach				echo '<p><input type="submit" value="', I18N::translate('save'), '" tabindex="5">';
2388c2e8227SGreg Roach				echo '</p>';
2398c2e8227SGreg Roach				echo '</form>';
2408c2e8227SGreg Roach			}
2418c2e8227SGreg Roach		} else {
2428c2e8227SGreg Roach			header('Location: ' . WT_BASE_URL);
2438c2e8227SGreg Roach		}
2448c2e8227SGreg Roach	}
2458c2e8227SGreg Roach
2468c2e8227SGreg Roach	/**
2478c2e8227SGreg Roach	 * Respond to a request to delete a story.
2488c2e8227SGreg Roach	 */
2498c2e8227SGreg Roach	private function delete() {
2504b9ff166SGreg Roach		global $WT_TREE;
2514b9ff166SGreg Roach
2524b9ff166SGreg Roach		if (Auth::isEditor($WT_TREE)) {
2538c2e8227SGreg Roach			$block_id = Filter::getInteger('block_id');
2548c2e8227SGreg Roach
2558c2e8227SGreg Roach			Database::prepare(
2568c2e8227SGreg Roach				"DELETE FROM `##block_setting` WHERE block_id=?"
2578c2e8227SGreg Roach			)->execute(array($block_id));
2588c2e8227SGreg Roach
2598c2e8227SGreg Roach			Database::prepare(
2608c2e8227SGreg Roach				"DELETE FROM `##block` WHERE block_id=?"
2618c2e8227SGreg Roach			)->execute(array($block_id));
2628c2e8227SGreg Roach		} else {
2638c2e8227SGreg Roach			header('Location: ' . WT_BASE_URL);
2648c2e8227SGreg Roach			exit;
2658c2e8227SGreg Roach		}
2668c2e8227SGreg Roach	}
2678c2e8227SGreg Roach
2688c2e8227SGreg Roach	/**
2698c2e8227SGreg Roach	 * The admin view - list, create, edit, delete stories.
2708c2e8227SGreg Roach	 */
2718c2e8227SGreg Roach	private function config() {
272*24ec66ceSGreg Roach		global $WT_TREE;
273*24ec66ceSGreg Roach
2748c2e8227SGreg Roach		$controller = new PageController;
2758c2e8227SGreg Roach		$controller
2764b9ff166SGreg Roach			->restrictAccess(Auth::isAdmin())
2778c2e8227SGreg Roach			->setPageTitle($this->getTitle())
2788c2e8227SGreg Roach			->pageHeader()
2798c2e8227SGreg Roach			->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)
2808c2e8227SGreg Roach			->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL)
2818c2e8227SGreg Roach			->addInlineJavascript('
2828c2e8227SGreg Roach				jQuery("#story_table").dataTable({
2838c2e8227SGreg Roach					' . I18N::datatablesI18N() . ',
2848c2e8227SGreg Roach					autoWidth: false,
2858c2e8227SGreg Roach					paging: true,
2868c2e8227SGreg Roach					pagingType: "full_numbers",
2878c2e8227SGreg Roach					lengthChange: true,
2888c2e8227SGreg Roach					filter: true,
2898c2e8227SGreg Roach					info: true,
2908c2e8227SGreg Roach					sorting: [[0,"asc"]],
2918c2e8227SGreg Roach					columns: [
2928c2e8227SGreg Roach						/* 0-name */ null,
2938c2e8227SGreg Roach						/* 1-NAME */ null,
2948c2e8227SGreg Roach						/* 2-NAME */ { sortable:false },
2958c2e8227SGreg Roach						/* 3-NAME */ { sortable:false }
2968c2e8227SGreg Roach					]
2978c2e8227SGreg Roach				});
2988c2e8227SGreg Roach			');
2998c2e8227SGreg Roach
3008c2e8227SGreg Roach		$stories = Database::prepare(
3018c2e8227SGreg Roach			"SELECT block_id, xref" .
3028c2e8227SGreg Roach			" FROM `##block` b" .
3038c2e8227SGreg Roach			" WHERE module_name=?" .
3048c2e8227SGreg Roach			" AND gedcom_id=?" .
3058c2e8227SGreg Roach			" ORDER BY xref"
306*24ec66ceSGreg Roach		)->execute(array($this->getName(), $WT_TREE->getTreeId()))->fetchAll();
3078c2e8227SGreg Roach
3088c2e8227SGreg Roach		?>
3098c2e8227SGreg Roach		<ol class="breadcrumb small">
3108c2e8227SGreg Roach			<li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li>
3118c2e8227SGreg Roach			<li><a href="admin_modules.php"><?php echo I18N::translate('Module administration'); ?></a></li>
3128c2e8227SGreg Roach			<li class="active"><?php echo $controller->getPageTitle(); ?></li>
3138c2e8227SGreg Roach		</ol>
3148c2e8227SGreg Roach
3158c2e8227SGreg Roach		<h1><?php echo $controller->getPageTitle(); ?></h1>
3168c2e8227SGreg Roach
3178c2e8227SGreg Roach		<form class="form form-inline">
3188c2e8227SGreg Roach			<label for="ged" class="sr-only">
3198c2e8227SGreg Roach				<?php echo I18N::translate('Family tree'); ?>
3208c2e8227SGreg Roach			</label>
3218c2e8227SGreg Roach			<input type="hidden" name="mod" value="<?php echo  $this->getName(); ?>">
3228c2e8227SGreg Roach			<input type="hidden" name="mod_action" value="admin_config">
323*24ec66ceSGreg Roach			<?php echo select_edit_control('ged', Tree::getNameList(), null, $WT_TREE->getName(), 'class="form-control"'); ?>
3248c2e8227SGreg Roach			<input type="submit" class="btn btn-primary" value="<?php echo I18N::translate('show'); ?>">
3258c2e8227SGreg Roach		</form>
3268c2e8227SGreg Roach
3278c2e8227SGreg Roach		<p>
3288c2e8227SGreg Roach			<a href="module.php?mod=<?php echo $this->getName(); ?>&amp;mod_action=admin_edit" class="btn btn-default">
3298c2e8227SGreg Roach				<i class="fa fa-plus"></i>
3308c2e8227SGreg Roach				<?php echo I18N::translate('Add a story'); ?>
3318c2e8227SGreg Roach			</a>
3328c2e8227SGreg Roach		</p>
3338c2e8227SGreg Roach
3348c2e8227SGreg Roach		<table class="table table-bordered table-condensed">
3358c2e8227SGreg Roach			<thead>
3368c2e8227SGreg Roach				<tr>
3378c2e8227SGreg Roach					<th><?php echo I18N::translate('Story title'); ?></th>
3388c2e8227SGreg Roach					<th><?php echo I18N::translate('Individual'); ?></th>
3398c2e8227SGreg Roach					<th><?php echo I18N::translate('Edit'); ?></th>
3408c2e8227SGreg Roach					<th><?php echo I18N::translate('Delete'); ?></th>
3418c2e8227SGreg Roach				</tr>
3428c2e8227SGreg Roach			</thead>
3438c2e8227SGreg Roach			<tbody>
3448c2e8227SGreg Roach				<?php foreach ($stories as $story): ?>
3458c2e8227SGreg Roach				<tr>
3468c2e8227SGreg Roach					<td>
3478c2e8227SGreg Roach						<?php echo Filter::escapeHtml(get_block_setting($story->block_id, 'title')); ?>
3488c2e8227SGreg Roach					</td>
3498c2e8227SGreg Roach					<td>
350*24ec66ceSGreg Roach						<?php if ($indi = Individual::getInstance($story->xref, $WT_TREE)): ?>
3518c2e8227SGreg Roach						<a href="<?php echo $indi->getHtmlUrl(); ?>#stories">
3528c2e8227SGreg Roach							<?php echo $indi->getFullName(); ?>
3538c2e8227SGreg Roach						</a>
3548c2e8227SGreg Roach						<?php else: ?>
3558c2e8227SGreg Roach							<?php echo $story->xref; ?>
3568c2e8227SGreg Roach						<?php endif; ?>
3578c2e8227SGreg Roach						</td>
3588c2e8227SGreg Roach						<td>
3598c2e8227SGreg Roach							<a href="module.php?mod=<?php echo $this->getName(); ?>&amp;mod_action=admin_edit&amp;block_id=<?php echo $story->block_id; ?>">
3608c2e8227SGreg Roach								<div class="icon-edit">&nbsp;</div>
3618c2e8227SGreg Roach							</a>
3628c2e8227SGreg Roach						</td>
3638c2e8227SGreg Roach						<td>
3648c2e8227SGreg Roach							<a
3658c2e8227SGreg Roach								href="module.php?mod=<?php echo $this->getName(); ?>&amp;mod_action=admin_delete&amp;block_id=<?php echo $story->block_id; ?>"
3668c2e8227SGreg Roach								onclick="return confirm('<?php echo I18N::translate('Are you sure you want to delete this story?'); ?>');"
3678c2e8227SGreg Roach							>
3688c2e8227SGreg Roach								<div class="icon-delete">&nbsp;</div>
3698c2e8227SGreg Roach							</a>
3708c2e8227SGreg Roach					</td>
3718c2e8227SGreg Roach				</tr>
3728c2e8227SGreg Roach				<?php endforeach; ?>
3738c2e8227SGreg Roach			</tbody>
3748c2e8227SGreg Roach		</table>
3758c2e8227SGreg Roach		<?php
3768c2e8227SGreg Roach	}
3778c2e8227SGreg Roach
3788c2e8227SGreg Roach	/**
3798c2e8227SGreg Roach	 * Show the list of stories
3808c2e8227SGreg Roach	 */
3818c2e8227SGreg Roach	private function showList() {
382*24ec66ceSGreg Roach		global $controller, $WT_TREE;
3838c2e8227SGreg Roach
3848c2e8227SGreg Roach		$controller = new PageController;
3858c2e8227SGreg Roach		$controller
3868c2e8227SGreg Roach			->setPageTitle($this->getTitle())
3878c2e8227SGreg Roach			->pageHeader()
3888c2e8227SGreg Roach			->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)
3898c2e8227SGreg Roach			->addInlineJavascript('
3908c2e8227SGreg Roach				jQuery("#story_table").dataTable({
3918c2e8227SGreg Roach					dom: \'<"H"pf<"dt-clear">irl>t<"F"pl>\',
3928c2e8227SGreg Roach					' . I18N::datatablesI18N() . ',
3938c2e8227SGreg Roach					autoWidth: false,
3948c2e8227SGreg Roach					paging: true,
3958c2e8227SGreg Roach					pagingType: "full_numbers",
3968c2e8227SGreg Roach					lengthChange: true,
3978c2e8227SGreg Roach					filter: true,
3988c2e8227SGreg Roach					info: true,
3998c2e8227SGreg Roach					jQueryUI: true,
4008c2e8227SGreg Roach					sorting: [[0,"asc"]],
4018c2e8227SGreg Roach					columns: [
4028c2e8227SGreg Roach						/* 0-name */ null,
4038c2e8227SGreg Roach						/* 1-NAME */ null
4048c2e8227SGreg Roach					]
4058c2e8227SGreg Roach				});
4068c2e8227SGreg Roach			');
4078c2e8227SGreg Roach
4088c2e8227SGreg Roach		$stories = Database::prepare(
4098c2e8227SGreg Roach			"SELECT block_id, xref" .
4108c2e8227SGreg Roach			" FROM `##block` b" .
4118c2e8227SGreg Roach			" WHERE module_name=?" .
4128c2e8227SGreg Roach			" AND gedcom_id=?" .
4138c2e8227SGreg Roach			" ORDER BY xref"
414*24ec66ceSGreg Roach		)->execute(array($this->getName(), $WT_TREE->getTreeId()))->fetchAll();
4158c2e8227SGreg Roach
4168c2e8227SGreg Roach		echo '<h2 class="center">', I18N::translate('Stories'), '</h2>';
4178c2e8227SGreg Roach		if (count($stories) > 0) {
4188c2e8227SGreg Roach			echo '<table id="story_table" class="width100">';
4198c2e8227SGreg Roach			echo '<thead><tr>
4208c2e8227SGreg Roach				<th>', I18N::translate('Story title'), '</th>
4218c2e8227SGreg Roach				<th>', I18N::translate('Individual'), '</th>
4228c2e8227SGreg Roach				</tr></thead>
4238c2e8227SGreg Roach				<tbody>';
4248c2e8227SGreg Roach			foreach ($stories as $story) {
425*24ec66ceSGreg Roach				$indi        = Individual::getInstance($story->xref, $WT_TREE);
4268c2e8227SGreg Roach				$story_title = get_block_setting($story->block_id, 'title');
4278c2e8227SGreg Roach				$languages   = get_block_setting($story->block_id, 'languages');
4288c2e8227SGreg Roach				if (!$languages || in_array(WT_LOCALE, explode(',', $languages))) {
4298c2e8227SGreg Roach					if ($indi) {
4308c2e8227SGreg Roach						if ($indi->canShow()) {
4318c2e8227SGreg Roach							echo '<tr><td><a href="' . $indi->getHtmlUrl() . '#stories">' . $story_title . '</a></td><td><a href="' . $indi->getHtmlUrl() . '#stories">' . $indi->getFullName() . '</a></td></tr>';
4328c2e8227SGreg Roach						}
4338c2e8227SGreg Roach					} else {
4348c2e8227SGreg Roach						echo '<tr><td>', $story_title, '</td><td class="error">', $story->xref, '</td></tr>';
4358c2e8227SGreg Roach					}
4368c2e8227SGreg Roach				}
4378c2e8227SGreg Roach			}
4388c2e8227SGreg Roach			echo '</tbody></table>';
4398c2e8227SGreg Roach		}
4408c2e8227SGreg Roach	}
4418c2e8227SGreg Roach
4428c2e8227SGreg Roach	/** {@inheritdoc} */
4438c2e8227SGreg Roach	public function defaultMenuOrder() {
4448c2e8227SGreg Roach		return 30;
4458c2e8227SGreg Roach	}
4468c2e8227SGreg Roach
4478c2e8227SGreg Roach	/** {@inheritdoc} */
4488c2e8227SGreg Roach	public function defaultAccessLevel() {
4494b9ff166SGreg Roach		return Auth::PRIV_HIDE;
4508c2e8227SGreg Roach	}
4518c2e8227SGreg Roach
4528c2e8227SGreg Roach	/** {@inheritdoc} */
4538c2e8227SGreg Roach	public function getMenu() {
4548c2e8227SGreg Roach		if (Auth::isSearchEngine()) {
4558c2e8227SGreg Roach			return null;
4568c2e8227SGreg Roach		}
4578c2e8227SGreg Roach
4588c2e8227SGreg Roach		$menu = new Menu($this->getTitle(), 'module.php?mod=' . $this->getName() . '&amp;mod_action=show_list', 'menu-story');
4598c2e8227SGreg Roach
4608c2e8227SGreg Roach		return $menu;
4618c2e8227SGreg Roach	}
4628c2e8227SGreg Roach}
463