xref: /webtrees/app/Module/StoriesModule.php (revision 3d7a8a4ca809135634f38216b734b15acff479f7)
18c2e8227SGreg Roach<?php
20e62c4b8SGreg Roachnamespace Fisharebest\Webtrees\Module;
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 */
180e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth;
190e62c4b8SGreg Roachuse Fisharebest\Webtrees\Controller\PageController;
200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Database;
210e62c4b8SGreg Roachuse Fisharebest\Webtrees\Filter;
22*3d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsEdit;
23*3d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsPrint;
240e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
250e62c4b8SGreg Roachuse Fisharebest\Webtrees\Individual;
260e62c4b8SGreg Roachuse Fisharebest\Webtrees\Menu;
270e62c4b8SGreg Roachuse Fisharebest\Webtrees\Module;
280e62c4b8SGreg Roachuse Fisharebest\Webtrees\Tree;
298c2e8227SGreg Roach
308c2e8227SGreg Roach/**
318c2e8227SGreg Roach * Class StoriesModule
328c2e8227SGreg Roach */
33e2a378d3SGreg Roachclass StoriesModule extends AbstractModule implements ModuleTabInterface, ModuleConfigInterface, ModuleMenuInterface {
348c2e8227SGreg Roach	/** {@inheritdoc} */
358c2e8227SGreg Roach	public function getTitle() {
368c2e8227SGreg Roach		return /* I18N: Name of a module */ I18N::translate('Stories');
378c2e8227SGreg Roach	}
388c2e8227SGreg Roach
398c2e8227SGreg Roach	/** {@inheritdoc} */
408c2e8227SGreg Roach	public function getDescription() {
418c2e8227SGreg Roach		return /* I18N: Description of the “Stories” module */ I18N::translate('Add narrative stories to individuals in the family tree.');
428c2e8227SGreg Roach	}
438c2e8227SGreg Roach
448c2e8227SGreg Roach	/** {@inheritdoc} */
458c2e8227SGreg Roach	public function modAction($mod_action) {
468c2e8227SGreg Roach		switch ($mod_action) {
478c2e8227SGreg Roach		case 'admin_edit':
488c2e8227SGreg Roach			$this->edit();
498c2e8227SGreg Roach			break;
508c2e8227SGreg Roach		case 'admin_delete':
518c2e8227SGreg Roach			$this->delete();
528c2e8227SGreg Roach			$this->config();
538c2e8227SGreg Roach			break;
548c2e8227SGreg Roach		case 'admin_config':
558c2e8227SGreg Roach			$this->config();
568c2e8227SGreg Roach			break;
578c2e8227SGreg Roach		case 'show_list':
588c2e8227SGreg Roach			$this->showList();
598c2e8227SGreg Roach			break;
608c2e8227SGreg Roach		default:
618c2e8227SGreg Roach			http_response_code(404);
628c2e8227SGreg Roach		}
638c2e8227SGreg Roach	}
648c2e8227SGreg Roach
658c2e8227SGreg Roach	/** {@inheritdoc} */
668c2e8227SGreg Roach	public function getConfigLink() {
678c2e8227SGreg Roach		return 'module.php?mod=' . $this->getName() . '&amp;mod_action=admin_config';
688c2e8227SGreg Roach	}
698c2e8227SGreg Roach
708c2e8227SGreg Roach	/** {@inheritdoc} */
718c2e8227SGreg Roach	public function defaultTabOrder() {
728c2e8227SGreg Roach		return 55;
738c2e8227SGreg Roach	}
748c2e8227SGreg Roach
758c2e8227SGreg Roach	/** {@inheritdoc} */
768c2e8227SGreg Roach	public function getTabContent() {
774b9ff166SGreg Roach		global $controller, $WT_TREE;
788c2e8227SGreg Roach
798c2e8227SGreg Roach		$block_ids =
808c2e8227SGreg Roach			Database::prepare(
818c2e8227SGreg Roach				"SELECT block_id" .
828c2e8227SGreg Roach				" FROM `##block`" .
838c2e8227SGreg Roach				" WHERE module_name=?" .
848c2e8227SGreg Roach				" AND xref=?" .
858c2e8227SGreg Roach				" AND gedcom_id=?"
868c2e8227SGreg Roach			)->execute(array(
878c2e8227SGreg Roach				$this->getName(),
888c2e8227SGreg Roach				$controller->record->getXref(),
89cbc1590aSGreg Roach				$controller->record->getTree()->getTreeId(),
908c2e8227SGreg Roach			))->fetchOneColumn();
918c2e8227SGreg Roach
928c2e8227SGreg Roach		$html = '';
938c2e8227SGreg Roach		foreach ($block_ids as $block_id) {
948c2e8227SGreg Roach			// Only show this block for certain languages
95e2a378d3SGreg Roach			$languages = $this->getBlockSetting($block_id, 'languages');
968c2e8227SGreg Roach			if (!$languages || in_array(WT_LOCALE, explode(',', $languages))) {
97e2a378d3SGreg Roach				$html .= '<div class="story_title descriptionbox center rela">' . $this->getBlockSetting($block_id, 'title') . '</div>';
98e2a378d3SGreg Roach				$html .= '<div class="story_body optionbox">' . $this->getBlockSetting($block_id, 'story_body') . '</div>';
994b9ff166SGreg Roach				if (Auth::isEditor($WT_TREE)) {
1008c2e8227SGreg Roach					$html .= '<div class="story_edit"><a href="module.php?mod=' . $this->getName() . '&amp;mod_action=admin_edit&amp;block_id=' . $block_id . '">';
1018c2e8227SGreg Roach					$html .= I18N::translate('Edit story') . '</a></div>';
1028c2e8227SGreg Roach				}
1038c2e8227SGreg Roach			}
1048c2e8227SGreg Roach		}
1054b9ff166SGreg Roach		if (Auth::isManager($WT_TREE) && !$html) {
1068c2e8227SGreg Roach			$html .= '<div class="news_title center">' . $this->getTitle() . '</div>';
1078c2e8227SGreg Roach			$html .= '<div><a href="module.php?mod=' . $this->getName() . '&amp;mod_action=admin_edit&amp;xref=' . $controller->record->getXref() . '">';
1088c2e8227SGreg Roach			$html .= I18N::translate('Add a story') . '</a></div><br>';
1098c2e8227SGreg Roach		}
1108c2e8227SGreg Roach
1118c2e8227SGreg Roach		return $html;
1128c2e8227SGreg Roach	}
1138c2e8227SGreg Roach
1148c2e8227SGreg Roach	/** {@inheritdoc} */
1158c2e8227SGreg Roach	public function hasTabContent() {
116cbc1590aSGreg Roach		return $this->getTabContent() != '';
1178c2e8227SGreg Roach	}
1188c2e8227SGreg Roach
1198c2e8227SGreg Roach	/** {@inheritdoc} */
1208c2e8227SGreg Roach	public function isGrayedOut() {
1218c2e8227SGreg Roach		global $controller;
1228c2e8227SGreg Roach
1238c2e8227SGreg Roach		$count_of_stories =
1248c2e8227SGreg Roach			Database::prepare(
1258c2e8227SGreg Roach				"SELECT COUNT(block_id)" .
1268c2e8227SGreg Roach				" FROM `##block`" .
1278c2e8227SGreg Roach				" WHERE module_name=?" .
1288c2e8227SGreg Roach				" AND xref=?" .
1298c2e8227SGreg Roach				" AND gedcom_id=?"
1308c2e8227SGreg Roach			)->execute(array(
1318c2e8227SGreg Roach				$this->getName(),
1328c2e8227SGreg Roach				$controller->record->getXref(),
133cbc1590aSGreg Roach				$controller->record->getTree()->getTreeId(),
1348c2e8227SGreg Roach			))->fetchOne();
1358c2e8227SGreg Roach
1368c2e8227SGreg Roach		return $count_of_stories == 0;
1378c2e8227SGreg Roach	}
1388c2e8227SGreg Roach
1398c2e8227SGreg Roach	/** {@inheritdoc} */
1408c2e8227SGreg Roach	public function canLoadAjax() {
1418c2e8227SGreg Roach		return false;
1428c2e8227SGreg Roach	}
1438c2e8227SGreg Roach
1448c2e8227SGreg Roach	/** {@inheritdoc} */
1458c2e8227SGreg Roach	public function getPreLoadContent() {
1468c2e8227SGreg Roach		return '';
1478c2e8227SGreg Roach	}
1488c2e8227SGreg Roach
1498c2e8227SGreg Roach	/**
1508c2e8227SGreg Roach	 * Show and process a form to edit a story.
1518c2e8227SGreg Roach	 */
1528c2e8227SGreg Roach	private function edit() {
1534b9ff166SGreg Roach		global $WT_TREE;
1544b9ff166SGreg Roach
1554b9ff166SGreg Roach		if (Auth::isEditor($WT_TREE)) {
1568c2e8227SGreg Roach			if (Filter::postBool('save') && Filter::checkCsrf()) {
1578c2e8227SGreg Roach				$block_id = Filter::postInteger('block_id');
1588c2e8227SGreg Roach				if ($block_id) {
1598c2e8227SGreg Roach					Database::prepare(
1608c2e8227SGreg Roach						"UPDATE `##block` SET gedcom_id=?, xref=? WHERE block_id=?"
1618c2e8227SGreg Roach					)->execute(array(Filter::postInteger('gedcom_id'), Filter::post('xref', WT_REGEX_XREF), $block_id));
1628c2e8227SGreg Roach				} else {
1638c2e8227SGreg Roach					Database::prepare(
1648c2e8227SGreg Roach						"INSERT INTO `##block` (gedcom_id, xref, module_name, block_order) VALUES (?, ?, ?, ?)"
1658c2e8227SGreg Roach					)->execute(array(
1668c2e8227SGreg Roach						Filter::postInteger('gedcom_id'),
1678c2e8227SGreg Roach						Filter::post('xref', WT_REGEX_XREF),
1688c2e8227SGreg Roach						$this->getName(),
169cbc1590aSGreg Roach						0,
1708c2e8227SGreg Roach					));
1718c2e8227SGreg Roach					$block_id = Database::getInstance()->lastInsertId();
1728c2e8227SGreg Roach				}
173e2a378d3SGreg Roach				$this->setBlockSetting($block_id, 'title', Filter::post('title'));
174e2a378d3SGreg Roach				$this->setBlockSetting($block_id, 'story_body', Filter::post('story_body'));
175c999a340SGreg Roach				$languages = Filter::postArray('lang');
176e2a378d3SGreg Roach				$this->setBlockSetting($block_id, 'languages', implode(',', $languages));
1778c2e8227SGreg Roach				$this->config();
1788c2e8227SGreg Roach			} else {
1798c2e8227SGreg Roach				$block_id = Filter::getInteger('block_id');
1808c2e8227SGreg Roach
1818c2e8227SGreg Roach				$controller = new PageController;
1828c2e8227SGreg Roach				if ($block_id) {
1838c2e8227SGreg Roach					$controller->setPageTitle(I18N::translate('Edit story'));
184e2a378d3SGreg Roach					$title      = $this->getBlockSetting($block_id, 'title');
185e2a378d3SGreg Roach					$story_body = $this->getBlockSetting($block_id, 'story_body');
1868c2e8227SGreg Roach					$xref       = Database::prepare(
1878c2e8227SGreg Roach						"SELECT xref FROM `##block` WHERE block_id=?"
1888c2e8227SGreg Roach					)->execute(array($block_id))->fetchOne();
1898c2e8227SGreg Roach				} else {
1908c2e8227SGreg Roach					$controller->setPageTitle(I18N::translate('Add a story'));
1918c2e8227SGreg Roach					$title      = '';
1928c2e8227SGreg Roach					$story_body = '';
1938c2e8227SGreg Roach					$xref       = Filter::get('xref', WT_REGEX_XREF);
1948c2e8227SGreg Roach				}
1958c2e8227SGreg Roach				$controller
1968c2e8227SGreg Roach					->pageHeader()
1978c2e8227SGreg Roach					->addExternalJavascript(WT_AUTOCOMPLETE_JS_URL)
1988c2e8227SGreg Roach					->addInlineJavascript('autocomplete();');
1998c2e8227SGreg Roach				if (Module::getModuleByName('ckeditor')) {
2008c2e8227SGreg Roach					CkeditorModule::enableEditor($controller);
2018c2e8227SGreg Roach				}
2028c2e8227SGreg Roach
203691beab6SGreg Roach				$individual = Individual::getInstance($xref, $WT_TREE);
204691beab6SGreg Roach
2058c2e8227SGreg Roach				?>
2068c2e8227SGreg Roach				<ol class="breadcrumb small">
2078c2e8227SGreg Roach					<li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li>
2088c2e8227SGreg Roach					<li><a href="admin_modules.php"><?php echo I18N::translate('Module administration'); ?></a></li>
2098c2e8227SGreg Roach					<li><a href="module.php?mod=<?php echo $this->getName(); ?>&mod_action=admin_config"><?php echo $this->getTitle(); ?></a></li>
2108c2e8227SGreg Roach					<li class="active"><?php echo $controller->getPageTitle(); ?></li>
2118c2e8227SGreg Roach				</ol>
2128c2e8227SGreg Roach
2138c2e8227SGreg Roach				<h1><?php echo $controller->getPageTitle(); ?></h1>
2148c2e8227SGreg Roach
215691beab6SGreg Roach				<form class="form-horizontal" method="post" action="module.php?mod=<?php echo $this->getName(); ?>&amp;mod_action=admin_edit">
216691beab6SGreg Roach					<?php echo Filter::getCsrf(); ?>
217691beab6SGreg Roach					<input type="hidden" name="save" value="1">
218691beab6SGreg Roach					<input type="hidden" name="block_id" value="<?php echo $block_id; ?>">
219691beab6SGreg Roach					<input type="hidden" name="gedcom_id" value="<?php echo $WT_TREE->getTreeId(); ?>">
220691beab6SGreg Roach
221691beab6SGreg Roach					<div class="form-group">
222691beab6SGreg Roach						<label for="title" class="col-sm-3 control-label">
223691beab6SGreg Roach							<?php echo I18N::translate('Story title'); ?>
224691beab6SGreg Roach						</label>
225691beab6SGreg Roach						<div class="col-sm-9">
226691beab6SGreg Roach							<input type="text" class="form-control" name="title" id="title" value="<?php echo Filter::escapeHtml($title); ?>">
227691beab6SGreg Roach						</div>
228691beab6SGreg Roach					</div>
229691beab6SGreg Roach
230691beab6SGreg Roach					<div class="form-group">
231691beab6SGreg Roach						<label for="story_body" class="col-sm-3 control-label">
232691beab6SGreg Roach							<?php echo I18N::translate('Story'); ?>
233691beab6SGreg Roach						</label>
234691beab6SGreg Roach						<div class="col-sm-9">
235691beab6SGreg Roach							<textarea name="story_body" id="story_body" class="html-edit form-control" rows="10"><?php echo Filter::escapeHtml($story_body); ?></textarea>
236691beab6SGreg Roach						</div>
237691beab6SGreg Roach					</div>
238691beab6SGreg Roach
239691beab6SGreg Roach					<div class="form-group">
240691beab6SGreg Roach						<label for="xref" class="col-sm-3 control-label">
241691beab6SGreg Roach							<?php echo I18N::translate('Individual'); ?>
242691beab6SGreg Roach						</label>
243691beab6SGreg Roach						<div class="col-sm-9">
244691beab6SGreg Roach							<input data-autocomplete-type="INDI" type="text" name="xref" id="xref" size="4" value="<?php echo $xref; ?>">
245*3d7a8a4cSGreg Roach							<?php echo FunctionsPrint::printFindIndividualLink('xref'); ?>
246691beab6SGreg Roach							<?php if ($individual): ?>
247691beab6SGreg Roach								<?php echo $individual->formatList('span'); ?>
248691beab6SGreg Roach							<?php endif; ?>
249691beab6SGreg Roach						</div>
250691beab6SGreg Roach					</div>
251691beab6SGreg Roach
252691beab6SGreg Roach					<div class="form-group">
253691beab6SGreg Roach						<label for="xref" class="col-sm-3 control-label">
254691beab6SGreg Roach							<?php echo I18N::translate('Show this block for which languages?'); ?>
255691beab6SGreg Roach						</label>
256691beab6SGreg Roach						<div class="col-sm-9">
257*3d7a8a4cSGreg Roach							<?php echo FunctionsEdit::editLanguageCheckboxes('lang', explode(',', $this->getBlockSetting($block_id, 'languages'))); ?>
258691beab6SGreg Roach						</div>
259691beab6SGreg Roach					</div>
260691beab6SGreg Roach
261691beab6SGreg Roach					<div class="form-group">
262691beab6SGreg Roach						<div class="col-sm-offset-3 col-sm-9">
263691beab6SGreg Roach							<button type="submit" class="btn btn-primary">
264691beab6SGreg Roach								<i class="fa fa-check"></i>
265691beab6SGreg Roach								<?php echo I18N::translate('save'); ?>
266691beab6SGreg Roach							</button>
267691beab6SGreg Roach						</div>
268691beab6SGreg Roach					</div>
269691beab6SGreg Roach
270691beab6SGreg Roach				</form>
271691beab6SGreg Roach				<?php
2728c2e8227SGreg Roach			}
2738c2e8227SGreg Roach		} else {
2748c2e8227SGreg Roach			header('Location: ' . WT_BASE_URL);
2758c2e8227SGreg Roach		}
2768c2e8227SGreg Roach	}
2778c2e8227SGreg Roach
2788c2e8227SGreg Roach	/**
2798c2e8227SGreg Roach	 * Respond to a request to delete a story.
2808c2e8227SGreg Roach	 */
2818c2e8227SGreg Roach	private function delete() {
2824b9ff166SGreg Roach		global $WT_TREE;
2834b9ff166SGreg Roach
2844b9ff166SGreg Roach		if (Auth::isEditor($WT_TREE)) {
2858c2e8227SGreg Roach			$block_id = Filter::getInteger('block_id');
2868c2e8227SGreg Roach
2878c2e8227SGreg Roach			Database::prepare(
2888c2e8227SGreg Roach				"DELETE FROM `##block_setting` WHERE block_id=?"
2898c2e8227SGreg Roach			)->execute(array($block_id));
2908c2e8227SGreg Roach
2918c2e8227SGreg Roach			Database::prepare(
2928c2e8227SGreg Roach				"DELETE FROM `##block` WHERE block_id=?"
2938c2e8227SGreg Roach			)->execute(array($block_id));
2948c2e8227SGreg Roach		} else {
2958c2e8227SGreg Roach			header('Location: ' . WT_BASE_URL);
2968c2e8227SGreg Roach			exit;
2978c2e8227SGreg Roach		}
2988c2e8227SGreg Roach	}
2998c2e8227SGreg Roach
3008c2e8227SGreg Roach	/**
3018c2e8227SGreg Roach	 * The admin view - list, create, edit, delete stories.
3028c2e8227SGreg Roach	 */
3038c2e8227SGreg Roach	private function config() {
30424ec66ceSGreg Roach		global $WT_TREE;
30524ec66ceSGreg Roach
3068c2e8227SGreg Roach		$controller = new PageController;
3078c2e8227SGreg Roach		$controller
3084b9ff166SGreg Roach			->restrictAccess(Auth::isAdmin())
3098c2e8227SGreg Roach			->setPageTitle($this->getTitle())
3108c2e8227SGreg Roach			->pageHeader()
3118c2e8227SGreg Roach			->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)
3128c2e8227SGreg Roach			->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL)
3138c2e8227SGreg Roach			->addInlineJavascript('
3148c2e8227SGreg Roach				jQuery("#story_table").dataTable({
3158c2e8227SGreg Roach					' . I18N::datatablesI18N() . ',
3168c2e8227SGreg Roach					autoWidth: false,
3178c2e8227SGreg Roach					paging: true,
3188c2e8227SGreg Roach					pagingType: "full_numbers",
3198c2e8227SGreg Roach					lengthChange: true,
3208c2e8227SGreg Roach					filter: true,
3218c2e8227SGreg Roach					info: true,
3228c2e8227SGreg Roach					sorting: [[0,"asc"]],
3238c2e8227SGreg Roach					columns: [
3248c2e8227SGreg Roach						/* 0-name */ null,
3258c2e8227SGreg Roach						/* 1-NAME */ null,
3268c2e8227SGreg Roach						/* 2-NAME */ { sortable:false },
3278c2e8227SGreg Roach						/* 3-NAME */ { sortable:false }
3288c2e8227SGreg Roach					]
3298c2e8227SGreg Roach				});
3308c2e8227SGreg Roach			');
3318c2e8227SGreg Roach
3328c2e8227SGreg Roach		$stories = Database::prepare(
3338c2e8227SGreg Roach			"SELECT block_id, xref" .
3348c2e8227SGreg Roach			" FROM `##block` b" .
3358c2e8227SGreg Roach			" WHERE module_name=?" .
3368c2e8227SGreg Roach			" AND gedcom_id=?" .
3378c2e8227SGreg Roach			" ORDER BY xref"
33824ec66ceSGreg Roach		)->execute(array($this->getName(), $WT_TREE->getTreeId()))->fetchAll();
3398c2e8227SGreg Roach
3408c2e8227SGreg Roach		?>
3418c2e8227SGreg Roach		<ol class="breadcrumb small">
3428c2e8227SGreg Roach			<li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li>
3438c2e8227SGreg Roach			<li><a href="admin_modules.php"><?php echo I18N::translate('Module administration'); ?></a></li>
3448c2e8227SGreg Roach			<li class="active"><?php echo $controller->getPageTitle(); ?></li>
3458c2e8227SGreg Roach		</ol>
3468c2e8227SGreg Roach
3478c2e8227SGreg Roach		<h1><?php echo $controller->getPageTitle(); ?></h1>
3488c2e8227SGreg Roach
3498c2e8227SGreg Roach		<form class="form form-inline">
3508c2e8227SGreg Roach			<label for="ged" class="sr-only">
3518c2e8227SGreg Roach				<?php echo I18N::translate('Family tree'); ?>
3528c2e8227SGreg Roach			</label>
3538c2e8227SGreg Roach			<input type="hidden" name="mod" value="<?php echo  $this->getName(); ?>">
3548c2e8227SGreg Roach			<input type="hidden" name="mod_action" value="admin_config">
355*3d7a8a4cSGreg Roach			<?php echo FunctionsEdit::selectEditControl('ged', Tree::getNameList(), null, $WT_TREE->getName(), 'class="form-control"'); ?>
3568c2e8227SGreg Roach			<input type="submit" class="btn btn-primary" value="<?php echo I18N::translate('show'); ?>">
3578c2e8227SGreg Roach		</form>
3588c2e8227SGreg Roach
3598c2e8227SGreg Roach		<p>
3608c2e8227SGreg Roach			<a href="module.php?mod=<?php echo $this->getName(); ?>&amp;mod_action=admin_edit" class="btn btn-default">
3618c2e8227SGreg Roach				<i class="fa fa-plus"></i>
3628c2e8227SGreg Roach				<?php echo I18N::translate('Add a story'); ?>
3638c2e8227SGreg Roach			</a>
3648c2e8227SGreg Roach		</p>
3658c2e8227SGreg Roach
3668c2e8227SGreg Roach		<table class="table table-bordered table-condensed">
3678c2e8227SGreg Roach			<thead>
3688c2e8227SGreg Roach				<tr>
3698c2e8227SGreg Roach					<th><?php echo I18N::translate('Story title'); ?></th>
3708c2e8227SGreg Roach					<th><?php echo I18N::translate('Individual'); ?></th>
3718c2e8227SGreg Roach					<th><?php echo I18N::translate('Edit'); ?></th>
3728c2e8227SGreg Roach					<th><?php echo I18N::translate('Delete'); ?></th>
3738c2e8227SGreg Roach				</tr>
3748c2e8227SGreg Roach			</thead>
3758c2e8227SGreg Roach			<tbody>
3768c2e8227SGreg Roach				<?php foreach ($stories as $story): ?>
3778c2e8227SGreg Roach				<tr>
3788c2e8227SGreg Roach					<td>
379e2a378d3SGreg Roach						<?php echo Filter::escapeHtml($this->getBlockSetting($story->block_id, 'title')); ?>
3808c2e8227SGreg Roach					</td>
3818c2e8227SGreg Roach					<td>
382691beab6SGreg Roach						<?php $individual = Individual::getInstance($story->xref, $WT_TREE); ?>
383691beab6SGreg Roach						<?php if ($individual): ?>
384691beab6SGreg Roach						<a href="<?php echo $individual->getHtmlUrl(); ?>#stories">
385691beab6SGreg Roach							<?php echo $individual->getFullName(); ?>
3868c2e8227SGreg Roach						</a>
3878c2e8227SGreg Roach						<?php else: ?>
3888c2e8227SGreg Roach							<?php echo $story->xref; ?>
3898c2e8227SGreg Roach						<?php endif; ?>
3908c2e8227SGreg Roach						</td>
3918c2e8227SGreg Roach						<td>
3928c2e8227SGreg Roach							<a href="module.php?mod=<?php echo $this->getName(); ?>&amp;mod_action=admin_edit&amp;block_id=<?php echo $story->block_id; ?>">
3938c2e8227SGreg Roach								<div class="icon-edit">&nbsp;</div>
3948c2e8227SGreg Roach							</a>
3958c2e8227SGreg Roach						</td>
3968c2e8227SGreg Roach						<td>
3978c2e8227SGreg Roach							<a
3988c2e8227SGreg Roach								href="module.php?mod=<?php echo $this->getName(); ?>&amp;mod_action=admin_delete&amp;block_id=<?php echo $story->block_id; ?>"
3998c2e8227SGreg Roach								onclick="return confirm('<?php echo I18N::translate('Are you sure you want to delete this story?'); ?>');"
4008c2e8227SGreg Roach							>
4018c2e8227SGreg Roach								<div class="icon-delete">&nbsp;</div>
4028c2e8227SGreg Roach							</a>
4038c2e8227SGreg Roach					</td>
4048c2e8227SGreg Roach				</tr>
4058c2e8227SGreg Roach				<?php endforeach; ?>
4068c2e8227SGreg Roach			</tbody>
4078c2e8227SGreg Roach		</table>
4088c2e8227SGreg Roach		<?php
4098c2e8227SGreg Roach	}
4108c2e8227SGreg Roach
4118c2e8227SGreg Roach	/**
4128c2e8227SGreg Roach	 * Show the list of stories
4138c2e8227SGreg Roach	 */
4148c2e8227SGreg Roach	private function showList() {
41524ec66ceSGreg Roach		global $controller, $WT_TREE;
4168c2e8227SGreg Roach
4178c2e8227SGreg Roach		$controller = new PageController;
4188c2e8227SGreg Roach		$controller
4198c2e8227SGreg Roach			->setPageTitle($this->getTitle())
4208c2e8227SGreg Roach			->pageHeader()
4218c2e8227SGreg Roach			->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)
4228c2e8227SGreg Roach			->addInlineJavascript('
4238c2e8227SGreg Roach				jQuery("#story_table").dataTable({
4248c2e8227SGreg Roach					dom: \'<"H"pf<"dt-clear">irl>t<"F"pl>\',
4258c2e8227SGreg Roach					' . I18N::datatablesI18N() . ',
4268c2e8227SGreg Roach					autoWidth: false,
4278c2e8227SGreg Roach					paging: true,
4288c2e8227SGreg Roach					pagingType: "full_numbers",
4298c2e8227SGreg Roach					lengthChange: true,
4308c2e8227SGreg Roach					filter: true,
4318c2e8227SGreg Roach					info: true,
4328c2e8227SGreg Roach					jQueryUI: true,
4338c2e8227SGreg Roach					sorting: [[0,"asc"]],
4348c2e8227SGreg Roach					columns: [
4358c2e8227SGreg Roach						/* 0-name */ null,
4368c2e8227SGreg Roach						/* 1-NAME */ null
4378c2e8227SGreg Roach					]
4388c2e8227SGreg Roach				});
4398c2e8227SGreg Roach			');
4408c2e8227SGreg Roach
4418c2e8227SGreg Roach		$stories = Database::prepare(
4428c2e8227SGreg Roach			"SELECT block_id, xref" .
4438c2e8227SGreg Roach			" FROM `##block` b" .
4448c2e8227SGreg Roach			" WHERE module_name=?" .
4458c2e8227SGreg Roach			" AND gedcom_id=?" .
4468c2e8227SGreg Roach			" ORDER BY xref"
44724ec66ceSGreg Roach		)->execute(array($this->getName(), $WT_TREE->getTreeId()))->fetchAll();
4488c2e8227SGreg Roach
4498c2e8227SGreg Roach		echo '<h2 class="center">', I18N::translate('Stories'), '</h2>';
4508c2e8227SGreg Roach		if (count($stories) > 0) {
4518c2e8227SGreg Roach			echo '<table id="story_table" class="width100">';
4528c2e8227SGreg Roach			echo '<thead><tr>
4538c2e8227SGreg Roach				<th>', I18N::translate('Story title'), '</th>
4548c2e8227SGreg Roach				<th>', I18N::translate('Individual'), '</th>
4558c2e8227SGreg Roach				</tr></thead>
4568c2e8227SGreg Roach				<tbody>';
4578c2e8227SGreg Roach			foreach ($stories as $story) {
45824ec66ceSGreg Roach				$indi        = Individual::getInstance($story->xref, $WT_TREE);
459e2a378d3SGreg Roach				$story_title = $this->getBlockSetting($story->block_id, 'title');
460e2a378d3SGreg Roach				$languages   = $this->getBlockSetting($story->block_id, 'languages');
4618c2e8227SGreg Roach				if (!$languages || in_array(WT_LOCALE, explode(',', $languages))) {
4628c2e8227SGreg Roach					if ($indi) {
4638c2e8227SGreg Roach						if ($indi->canShow()) {
4648c2e8227SGreg Roach							echo '<tr><td><a href="' . $indi->getHtmlUrl() . '#stories">' . $story_title . '</a></td><td><a href="' . $indi->getHtmlUrl() . '#stories">' . $indi->getFullName() . '</a></td></tr>';
4658c2e8227SGreg Roach						}
4668c2e8227SGreg Roach					} else {
4678c2e8227SGreg Roach						echo '<tr><td>', $story_title, '</td><td class="error">', $story->xref, '</td></tr>';
4688c2e8227SGreg Roach					}
4698c2e8227SGreg Roach				}
4708c2e8227SGreg Roach			}
4718c2e8227SGreg Roach			echo '</tbody></table>';
4728c2e8227SGreg Roach		}
4738c2e8227SGreg Roach	}
4748c2e8227SGreg Roach
4758c2e8227SGreg Roach	/** {@inheritdoc} */
4768c2e8227SGreg Roach	public function defaultMenuOrder() {
4778c2e8227SGreg Roach		return 30;
4788c2e8227SGreg Roach	}
4798c2e8227SGreg Roach
4808c2e8227SGreg Roach	/** {@inheritdoc} */
4818c2e8227SGreg Roach	public function defaultAccessLevel() {
4824b9ff166SGreg Roach		return Auth::PRIV_HIDE;
4838c2e8227SGreg Roach	}
4848c2e8227SGreg Roach
4858c2e8227SGreg Roach	/** {@inheritdoc} */
4868c2e8227SGreg Roach	public function getMenu() {
4878c2e8227SGreg Roach		if (Auth::isSearchEngine()) {
4888c2e8227SGreg Roach			return null;
4898c2e8227SGreg Roach		}
4908c2e8227SGreg Roach
4918c2e8227SGreg Roach		$menu = new Menu($this->getTitle(), 'module.php?mod=' . $this->getName() . '&amp;mod_action=show_list', 'menu-story');
4928c2e8227SGreg Roach
4938c2e8227SGreg Roach		return $menu;
4948c2e8227SGreg Roach	}
4958c2e8227SGreg Roach}
496