18c2e8227SGreg Roach<?php 28c2e8227SGreg Roach/** 38c2e8227SGreg Roach * webtrees: online genealogy 46bdf7674SGreg Roach * Copyright (C) 2017 webtrees development team 58c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify 68c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by 78c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or 88c2e8227SGreg Roach * (at your option) any later version. 98c2e8227SGreg Roach * This program is distributed in the hope that it will be useful, 108c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 118c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 128c2e8227SGreg Roach * GNU General Public License for more details. 138c2e8227SGreg Roach * You should have received a copy of the GNU General Public License 148c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 158c2e8227SGreg Roach */ 1676692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module; 1776692c8bSGreg Roach 180e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth; 1915d603e7SGreg Roachuse Fisharebest\Webtrees\Bootstrap4; 200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Controller\PageController; 210e62c4b8SGreg Roachuse Fisharebest\Webtrees\Database; 220e62c4b8SGreg Roachuse Fisharebest\Webtrees\Filter; 233d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsEdit; 24cc5ab399SGreg Roachuse Fisharebest\Webtrees\Html; 250e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 260e62c4b8SGreg Roachuse Fisharebest\Webtrees\Individual; 270e62c4b8SGreg Roachuse Fisharebest\Webtrees\Menu; 280e62c4b8SGreg Roachuse Fisharebest\Webtrees\Module; 290e62c4b8SGreg Roachuse Fisharebest\Webtrees\Tree; 308c2e8227SGreg Roach 318c2e8227SGreg Roach/** 328c2e8227SGreg Roach * Class StoriesModule 338c2e8227SGreg Roach */ 34e2a378d3SGreg Roachclass StoriesModule extends AbstractModule implements ModuleTabInterface, ModuleConfigInterface, ModuleMenuInterface { 358c2e8227SGreg Roach /** {@inheritdoc} */ 368c2e8227SGreg Roach public function getTitle() { 378c2e8227SGreg Roach return /* I18N: Name of a module */ I18N::translate('Stories'); 388c2e8227SGreg Roach } 398c2e8227SGreg Roach 408c2e8227SGreg Roach /** {@inheritdoc} */ 418c2e8227SGreg Roach public function getDescription() { 428c2e8227SGreg Roach return /* I18N: Description of the “Stories” module */ I18N::translate('Add narrative stories to individuals in the family tree.'); 438c2e8227SGreg Roach } 448c2e8227SGreg Roach 4576692c8bSGreg Roach /** 4676692c8bSGreg Roach * This is a general purpose hook, allowing modules to respond to routes 4776692c8bSGreg Roach * of the form module.php?mod=FOO&mod_action=BAR 4876692c8bSGreg Roach * 4976692c8bSGreg Roach * @param string $mod_action 5076692c8bSGreg Roach */ 518c2e8227SGreg Roach public function modAction($mod_action) { 528c2e8227SGreg Roach switch ($mod_action) { 538c2e8227SGreg Roach case 'admin_edit': 548c2e8227SGreg Roach $this->edit(); 558c2e8227SGreg Roach break; 568c2e8227SGreg Roach case 'admin_delete': 578c2e8227SGreg Roach $this->delete(); 588c2e8227SGreg Roach $this->config(); 598c2e8227SGreg Roach break; 608c2e8227SGreg Roach case 'admin_config': 618c2e8227SGreg Roach $this->config(); 628c2e8227SGreg Roach break; 638c2e8227SGreg Roach case 'show_list': 648c2e8227SGreg Roach $this->showList(); 658c2e8227SGreg Roach break; 668c2e8227SGreg Roach default: 678c2e8227SGreg Roach http_response_code(404); 688c2e8227SGreg Roach } 698c2e8227SGreg Roach } 708c2e8227SGreg Roach 718c2e8227SGreg Roach /** {@inheritdoc} */ 728c2e8227SGreg Roach public function getConfigLink() { 738c2e8227SGreg Roach return 'module.php?mod=' . $this->getName() . '&mod_action=admin_config'; 748c2e8227SGreg Roach } 758c2e8227SGreg Roach 768c2e8227SGreg Roach /** {@inheritdoc} */ 778c2e8227SGreg Roach public function defaultTabOrder() { 788c2e8227SGreg Roach return 55; 798c2e8227SGreg Roach } 808c2e8227SGreg Roach 818c2e8227SGreg Roach /** {@inheritdoc} */ 828c2e8227SGreg Roach public function getTabContent() { 834b9ff166SGreg Roach global $controller, $WT_TREE; 848c2e8227SGreg Roach 858c2e8227SGreg Roach $block_ids = 868c2e8227SGreg Roach Database::prepare( 878c2e8227SGreg Roach "SELECT block_id" . 888c2e8227SGreg Roach " FROM `##block`" . 898c2e8227SGreg Roach " WHERE module_name=?" . 908c2e8227SGreg Roach " AND xref=?" . 918c2e8227SGreg Roach " AND gedcom_id=?" 9213abd6f3SGreg Roach )->execute([ 938c2e8227SGreg Roach $this->getName(), 948c2e8227SGreg Roach $controller->record->getXref(), 95cbc1590aSGreg Roach $controller->record->getTree()->getTreeId(), 9613abd6f3SGreg Roach ])->fetchOneColumn(); 978c2e8227SGreg Roach 988c2e8227SGreg Roach $html = ''; 998c2e8227SGreg Roach foreach ($block_ids as $block_id) { 1008c2e8227SGreg Roach // Only show this block for certain languages 101e2a378d3SGreg Roach $languages = $this->getBlockSetting($block_id, 'languages'); 1028c2e8227SGreg Roach if (!$languages || in_array(WT_LOCALE, explode(',', $languages))) { 103e2a378d3SGreg Roach $html .= '<div class="story_title descriptionbox center rela">' . $this->getBlockSetting($block_id, 'title') . '</div>'; 104e2a378d3SGreg Roach $html .= '<div class="story_body optionbox">' . $this->getBlockSetting($block_id, 'story_body') . '</div>'; 1054b9ff166SGreg Roach if (Auth::isEditor($WT_TREE)) { 1068c2e8227SGreg Roach $html .= '<div class="story_edit"><a href="module.php?mod=' . $this->getName() . '&mod_action=admin_edit&block_id=' . $block_id . '">'; 107cdc90107SGreg Roach $html .= I18N::translate('Edit the story') . '</a></div>'; 1088c2e8227SGreg Roach } 1098c2e8227SGreg Roach } 1108c2e8227SGreg Roach } 1114b9ff166SGreg Roach if (Auth::isManager($WT_TREE) && !$html) { 1128c2e8227SGreg Roach $html .= '<div class="news_title center">' . $this->getTitle() . '</div>'; 1138c2e8227SGreg Roach $html .= '<div><a href="module.php?mod=' . $this->getName() . '&mod_action=admin_edit&xref=' . $controller->record->getXref() . '">'; 1148c2e8227SGreg Roach $html .= I18N::translate('Add a story') . '</a></div><br>'; 1158c2e8227SGreg Roach } 1168c2e8227SGreg Roach 1178c2e8227SGreg Roach return $html; 1188c2e8227SGreg Roach } 1198c2e8227SGreg Roach 1208c2e8227SGreg Roach /** {@inheritdoc} */ 1218c2e8227SGreg Roach public function hasTabContent() { 122cbc1590aSGreg Roach return $this->getTabContent() != ''; 1238c2e8227SGreg Roach } 1248c2e8227SGreg Roach 1258c2e8227SGreg Roach /** {@inheritdoc} */ 1268c2e8227SGreg Roach public function isGrayedOut() { 1278c2e8227SGreg Roach global $controller; 1288c2e8227SGreg Roach 1298c2e8227SGreg Roach $count_of_stories = 1308c2e8227SGreg Roach Database::prepare( 1318c2e8227SGreg Roach "SELECT COUNT(block_id)" . 1328c2e8227SGreg Roach " FROM `##block`" . 1338c2e8227SGreg Roach " WHERE module_name=?" . 1348c2e8227SGreg Roach " AND xref=?" . 1358c2e8227SGreg Roach " AND gedcom_id=?" 13613abd6f3SGreg Roach )->execute([ 1378c2e8227SGreg Roach $this->getName(), 1388c2e8227SGreg Roach $controller->record->getXref(), 139cbc1590aSGreg Roach $controller->record->getTree()->getTreeId(), 14013abd6f3SGreg Roach ])->fetchOne(); 1418c2e8227SGreg Roach 1428c2e8227SGreg Roach return $count_of_stories == 0; 1438c2e8227SGreg Roach } 1448c2e8227SGreg Roach 1458c2e8227SGreg Roach /** {@inheritdoc} */ 1468c2e8227SGreg Roach public function canLoadAjax() { 1478c2e8227SGreg Roach return false; 1488c2e8227SGreg Roach } 1498c2e8227SGreg Roach 1508c2e8227SGreg Roach /** {@inheritdoc} */ 1518c2e8227SGreg Roach public function getPreLoadContent() { 1528c2e8227SGreg Roach return ''; 1538c2e8227SGreg Roach } 1548c2e8227SGreg Roach 1558c2e8227SGreg Roach /** 1568c2e8227SGreg Roach * Show and process a form to edit a story. 1578c2e8227SGreg Roach */ 1588c2e8227SGreg Roach private function edit() { 1594b9ff166SGreg Roach global $WT_TREE; 1604b9ff166SGreg Roach 1614b9ff166SGreg Roach if (Auth::isEditor($WT_TREE)) { 1628c2e8227SGreg Roach if (Filter::postBool('save') && Filter::checkCsrf()) { 1638c2e8227SGreg Roach $block_id = Filter::postInteger('block_id'); 1648c2e8227SGreg Roach if ($block_id) { 1658c2e8227SGreg Roach Database::prepare( 1668c2e8227SGreg Roach "UPDATE `##block` SET gedcom_id=?, xref=? WHERE block_id=?" 16713abd6f3SGreg Roach )->execute([Filter::postInteger('gedcom_id'), Filter::post('xref', WT_REGEX_XREF), $block_id]); 1688c2e8227SGreg Roach } else { 1698c2e8227SGreg Roach Database::prepare( 1708c2e8227SGreg Roach "INSERT INTO `##block` (gedcom_id, xref, module_name, block_order) VALUES (?, ?, ?, ?)" 17113abd6f3SGreg Roach )->execute([ 1728c2e8227SGreg Roach Filter::postInteger('gedcom_id'), 1738c2e8227SGreg Roach Filter::post('xref', WT_REGEX_XREF), 1748c2e8227SGreg Roach $this->getName(), 175cbc1590aSGreg Roach 0, 17613abd6f3SGreg Roach ]); 1778c2e8227SGreg Roach $block_id = Database::getInstance()->lastInsertId(); 1788c2e8227SGreg Roach } 179e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'title', Filter::post('title')); 180e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'story_body', Filter::post('story_body')); 181c999a340SGreg Roach $languages = Filter::postArray('lang'); 182e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'languages', implode(',', $languages)); 1838c2e8227SGreg Roach $this->config(); 1848c2e8227SGreg Roach } else { 1858c2e8227SGreg Roach $block_id = Filter::getInteger('block_id'); 1868c2e8227SGreg Roach 1878c2e8227SGreg Roach $controller = new PageController; 1888c2e8227SGreg Roach if ($block_id) { 189cdc90107SGreg Roach $controller->setPageTitle(I18N::translate('Edit the story')); 190e2a378d3SGreg Roach $title = $this->getBlockSetting($block_id, 'title'); 191e2a378d3SGreg Roach $story_body = $this->getBlockSetting($block_id, 'story_body'); 1928c2e8227SGreg Roach $xref = Database::prepare( 1938c2e8227SGreg Roach "SELECT xref FROM `##block` WHERE block_id=?" 19413abd6f3SGreg Roach )->execute([$block_id])->fetchOne(); 1958c2e8227SGreg Roach } else { 1968c2e8227SGreg Roach $controller->setPageTitle(I18N::translate('Add a story')); 1978c2e8227SGreg Roach $title = ''; 1988c2e8227SGreg Roach $story_body = ''; 1998c2e8227SGreg Roach $xref = Filter::get('xref', WT_REGEX_XREF); 2008c2e8227SGreg Roach } 20115d603e7SGreg Roach $controller->pageHeader(); 2028c2e8227SGreg Roach if (Module::getModuleByName('ckeditor')) { 2038c2e8227SGreg Roach CkeditorModule::enableEditor($controller); 2048c2e8227SGreg Roach } 2058c2e8227SGreg Roach 206691beab6SGreg Roach $individual = Individual::getInstance($xref, $WT_TREE); 207691beab6SGreg Roach 20815d603e7SGreg Roach echo Bootstrap4::breadcrumbs([ 20915d603e7SGreg Roach 'admin.php' => I18N::translate('Control panel'), 21015d603e7SGreg Roach 'admin_modules.php' => I18N::translate('Module administration'), 21115d603e7SGreg Roach 'module.php?mod=' . $this->getName() . '&mod_action=admin_config' => $this->getTitle(), 21215d603e7SGreg Roach ], $controller->getPageTitle()); 2138c2e8227SGreg Roach ?> 2148c2e8227SGreg Roach 21515d603e7SGreg Roach <h1><?= $controller->getPageTitle() ?></h1> 2168c2e8227SGreg Roach 21715d603e7SGreg Roach <form class="form-horizontal" method="post" action="module.php?mod=<?= $this->getName() ?>&mod_action=admin_edit"> 21815d603e7SGreg Roach <?= Filter::getCsrf() ?> 219691beab6SGreg Roach <input type="hidden" name="save" value="1"> 22015d603e7SGreg Roach <input type="hidden" name="block_id" value="<?= $block_id ?>"> 22115d603e7SGreg Roach <input type="hidden" name="gedcom_id" value="<?= $WT_TREE->getTreeId() ?>"> 222691beab6SGreg Roach 22315d603e7SGreg Roach <div class="row form-group"> 22415d603e7SGreg Roach <label for="title" class="col-sm-3 col-form-label"> 22515d603e7SGreg Roach <?= I18N::translate('Story title') ?> 226691beab6SGreg Roach </label> 227691beab6SGreg Roach <div class="col-sm-9"> 228cc5ab399SGreg Roach <input type="text" class="form-control" name="title" id="title" value="<?= Html::escape($title) ?>"> 229691beab6SGreg Roach </div> 230691beab6SGreg Roach </div> 231691beab6SGreg Roach 23215d603e7SGreg Roach <div class="row form-group"> 23315d603e7SGreg Roach <label for="story_body" class="col-sm-3 col-form-label"> 23415d603e7SGreg Roach <?= I18N::translate('Story') ?> 235691beab6SGreg Roach </label> 236691beab6SGreg Roach <div class="col-sm-9"> 237cc5ab399SGreg Roach <textarea name="story_body" id="story_body" class="html-edit form-control" rows="10"><?= Html::escape($story_body) ?></textarea> 238691beab6SGreg Roach </div> 239691beab6SGreg Roach </div> 240691beab6SGreg Roach 24115d603e7SGreg Roach <div class="row form-group"> 24215d603e7SGreg Roach <label for="xref" class="col-sm-3 col-form-label"> 24315d603e7SGreg Roach <?= I18N::translate('Individual') ?> 244691beab6SGreg Roach </label> 245691beab6SGreg Roach <div class="col-sm-9"> 24615d603e7SGreg Roach <input data-autocomplete-type="INDI" type="text" name="xref" id="xref" size="4" value="<?= $xref ?>"> 247691beab6SGreg Roach <?php if ($individual): ?> 24815d603e7SGreg Roach <?= $individual->formatList('span') ?> 24915d603e7SGreg Roach <?php endif ?> 250691beab6SGreg Roach </div> 251691beab6SGreg Roach </div> 252691beab6SGreg Roach 25315d603e7SGreg Roach <div class="row form-group"> 25415d603e7SGreg Roach <label for="xref" class="col-sm-3 col-form-label"> 25515d603e7SGreg Roach <?= I18N::translate('Show this block for which languages') ?> 256691beab6SGreg Roach </label> 257691beab6SGreg Roach <div class="col-sm-9"> 25815d603e7SGreg Roach <?= FunctionsEdit::editLanguageCheckboxes('lang', explode(',', $this->getBlockSetting($block_id, 'languages'))) ?> 259691beab6SGreg Roach </div> 260691beab6SGreg Roach </div> 261691beab6SGreg Roach 26215d603e7SGreg Roach <div class="row form-group"> 26315d603e7SGreg Roach <div class="offset-sm-3 col-sm-9"> 264691beab6SGreg Roach <button type="submit" class="btn btn-primary"> 265691beab6SGreg Roach <i class="fa fa-check"></i> 26615d603e7SGreg Roach <?= I18N::translate('save') ?> 267691beab6SGreg Roach </button> 268691beab6SGreg Roach </div> 269691beab6SGreg Roach </div> 270691beab6SGreg Roach 271691beab6SGreg Roach </form> 272691beab6SGreg Roach <?php 2738c2e8227SGreg Roach } 2748c2e8227SGreg Roach } else { 275bff8dc60SGreg Roach header('Location: index.php'); 2768c2e8227SGreg Roach } 2778c2e8227SGreg Roach } 2788c2e8227SGreg Roach 2798c2e8227SGreg Roach /** 2808c2e8227SGreg Roach * Respond to a request to delete a story. 2818c2e8227SGreg Roach */ 2828c2e8227SGreg Roach private function delete() { 2834b9ff166SGreg Roach global $WT_TREE; 2844b9ff166SGreg Roach 2854b9ff166SGreg Roach if (Auth::isEditor($WT_TREE)) { 2868c2e8227SGreg Roach $block_id = Filter::getInteger('block_id'); 2878c2e8227SGreg Roach 2888c2e8227SGreg Roach Database::prepare( 2898c2e8227SGreg Roach "DELETE FROM `##block_setting` WHERE block_id=?" 29013abd6f3SGreg Roach )->execute([$block_id]); 2918c2e8227SGreg Roach 2928c2e8227SGreg Roach Database::prepare( 2938c2e8227SGreg Roach "DELETE FROM `##block` WHERE block_id=?" 29413abd6f3SGreg Roach )->execute([$block_id]); 2958c2e8227SGreg Roach } else { 296bff8dc60SGreg Roach header('Location: index.php'); 2978c2e8227SGreg Roach exit; 2988c2e8227SGreg Roach } 2998c2e8227SGreg Roach } 3008c2e8227SGreg Roach 3018c2e8227SGreg Roach /** 3028c2e8227SGreg Roach * The admin view - list, create, edit, delete stories. 3038c2e8227SGreg Roach */ 3048c2e8227SGreg Roach private function config() { 30524ec66ceSGreg Roach global $WT_TREE; 30624ec66ceSGreg Roach 3078c2e8227SGreg Roach $controller = new PageController; 3088c2e8227SGreg Roach $controller 3094b9ff166SGreg Roach ->restrictAccess(Auth::isAdmin()) 3108c2e8227SGreg Roach ->setPageTitle($this->getTitle()) 3118c2e8227SGreg Roach ->pageHeader() 3128c2e8227SGreg Roach ->addInlineJavascript(' 31315d603e7SGreg Roach $("#story_table").dataTable({ 3148c2e8227SGreg Roach ' . I18N::datatablesI18N() . ', 3158c2e8227SGreg Roach autoWidth: false, 3168c2e8227SGreg Roach paging: true, 3178c2e8227SGreg Roach pagingType: "full_numbers", 3188c2e8227SGreg Roach lengthChange: true, 3198c2e8227SGreg Roach filter: true, 3208c2e8227SGreg Roach info: true, 3218c2e8227SGreg Roach sorting: [[0,"asc"]], 3228c2e8227SGreg Roach columns: [ 3238c2e8227SGreg Roach /* 0-name */ null, 3248c2e8227SGreg Roach /* 1-NAME */ null, 3258c2e8227SGreg Roach /* 2-NAME */ { sortable:false }, 3268c2e8227SGreg Roach /* 3-NAME */ { sortable:false } 3278c2e8227SGreg Roach ] 3288c2e8227SGreg Roach }); 3298c2e8227SGreg Roach '); 3308c2e8227SGreg Roach 3318c2e8227SGreg Roach $stories = Database::prepare( 3328c2e8227SGreg Roach "SELECT block_id, xref" . 3338c2e8227SGreg Roach " FROM `##block` b" . 3348c2e8227SGreg Roach " WHERE module_name=?" . 3358c2e8227SGreg Roach " AND gedcom_id=?" . 3368c2e8227SGreg Roach " ORDER BY xref" 33713abd6f3SGreg Roach )->execute([$this->getName(), $WT_TREE->getTreeId()])->fetchAll(); 3388c2e8227SGreg Roach 33915d603e7SGreg Roach echo Bootstrap4::breadcrumbs([ 34015d603e7SGreg Roach 'admin.php' => I18N::translate('Control panel'), 34115d603e7SGreg Roach 'admin_modules.php' => I18N::translate('Module administration'), 34215d603e7SGreg Roach ], $controller->getPageTitle()); 3438c2e8227SGreg Roach ?> 3448c2e8227SGreg Roach 34515d603e7SGreg Roach <h1><?= $controller->getPageTitle() ?></h1> 3468c2e8227SGreg Roach 3478c2e8227SGreg Roach <form class="form form-inline"> 3488c2e8227SGreg Roach <label for="ged" class="sr-only"> 34915d603e7SGreg Roach <?= I18N::translate('Family tree') ?> 3508c2e8227SGreg Roach </label> 35115d603e7SGreg Roach <input type="hidden" name="mod" value="<?= $this->getName() ?>"> 3528c2e8227SGreg Roach <input type="hidden" name="mod_action" value="admin_config"> 35315d603e7SGreg Roach <?= Bootstrap4::select(Tree::getNameList(), $WT_TREE->getName(), ['id' => 'ged', 'name' => 'ged']) ?> 35415d603e7SGreg Roach <input type="submit" class="btn btn-primary" value="<?= I18N::translate('show') ?>"> 3558c2e8227SGreg Roach </form> 3568c2e8227SGreg Roach 3578c2e8227SGreg Roach <p> 35815d603e7SGreg Roach <a href="module.php?mod=<?= $this->getName() ?>&mod_action=admin_edit" class="btn btn-default"> 3598c2e8227SGreg Roach <i class="fa fa-plus"></i> 36015d603e7SGreg Roach <?= I18N::translate('Add a story') ?> 3618c2e8227SGreg Roach </a> 3628c2e8227SGreg Roach </p> 3638c2e8227SGreg Roach 364*27134781SGreg Roach <table class="table table-bordered table-sm"> 3658c2e8227SGreg Roach <thead> 3668c2e8227SGreg Roach <tr> 36715d603e7SGreg Roach <th><?= I18N::translate('Story title') ?></th> 36815d603e7SGreg Roach <th><?= I18N::translate('Individual') ?></th> 36915d603e7SGreg Roach <th><?= I18N::translate('Edit') ?></th> 37015d603e7SGreg Roach <th><?= I18N::translate('Delete') ?></th> 3718c2e8227SGreg Roach </tr> 3728c2e8227SGreg Roach </thead> 3738c2e8227SGreg Roach <tbody> 3748c2e8227SGreg Roach <?php foreach ($stories as $story): ?> 3758c2e8227SGreg Roach <tr> 3768c2e8227SGreg Roach <td> 377cc5ab399SGreg Roach <?= Html::escape($this->getBlockSetting($story->block_id, 'title')) ?> 3788c2e8227SGreg Roach </td> 3798c2e8227SGreg Roach <td> 38015d603e7SGreg Roach <?php $individual = Individual::getInstance($story->xref, $WT_TREE) ?> 381691beab6SGreg Roach <?php if ($individual): ?> 38215d603e7SGreg Roach <a href="<?= $individual->getHtmlUrl() ?>#tab-stories"> 38315d603e7SGreg Roach <?= $individual->getFullName() ?> 3848c2e8227SGreg Roach </a> 3858c2e8227SGreg Roach <?php else: ?> 38615d603e7SGreg Roach <?= $story->xref ?> 38715d603e7SGreg Roach <?php endif ?> 3888c2e8227SGreg Roach </td> 3898c2e8227SGreg Roach <td> 39015d603e7SGreg Roach <a href="module.php?mod=<?= $this->getName() ?>&mod_action=admin_edit&block_id=<?= $story->block_id ?>"> 39115d603e7SGreg Roach <i class="fa fa-pencil"></i> <?= I18N::translate('Edit') ?> 3928c2e8227SGreg Roach </a> 3938c2e8227SGreg Roach </td> 3948c2e8227SGreg Roach <td> 3958c2e8227SGreg Roach <a 39615d603e7SGreg Roach href="module.php?mod=<?= $this->getName() ?>&mod_action=admin_delete&block_id=<?= $story->block_id ?>" 397cc5ab399SGreg Roach onclick="return confirm('<?= I18N::translate('Are you sure you want to delete “%s”?', Html::escape($this->getBlockSetting($story->block_id, 'title'))) ?>');" 3988c2e8227SGreg Roach > 39915d603e7SGreg Roach <i class="fa fa-trash"></i> <?= I18N::translate('Delete') ?> 4008c2e8227SGreg Roach </a> 4018c2e8227SGreg Roach </td> 4028c2e8227SGreg Roach </tr> 40315d603e7SGreg Roach <?php endforeach ?> 4048c2e8227SGreg Roach </tbody> 4058c2e8227SGreg Roach </table> 4068c2e8227SGreg Roach <?php 4078c2e8227SGreg Roach } 4088c2e8227SGreg Roach 4098c2e8227SGreg Roach /** 4108c2e8227SGreg Roach * Show the list of stories 4118c2e8227SGreg Roach */ 4128c2e8227SGreg Roach private function showList() { 41324ec66ceSGreg Roach global $controller, $WT_TREE; 4148c2e8227SGreg Roach 4158c2e8227SGreg Roach $controller = new PageController; 4168c2e8227SGreg Roach $controller 4178c2e8227SGreg Roach ->setPageTitle($this->getTitle()) 4188c2e8227SGreg Roach ->pageHeader() 4198c2e8227SGreg Roach ->addInlineJavascript(' 42015d603e7SGreg Roach $("#story_table").dataTable({ 4218c2e8227SGreg Roach dom: \'<"H"pf<"dt-clear">irl>t<"F"pl>\', 4228c2e8227SGreg Roach ' . I18N::datatablesI18N() . ', 4238c2e8227SGreg Roach autoWidth: false, 4248c2e8227SGreg Roach paging: true, 4258c2e8227SGreg Roach pagingType: "full_numbers", 4268c2e8227SGreg Roach lengthChange: true, 4278c2e8227SGreg Roach filter: true, 4288c2e8227SGreg Roach info: true, 4298c2e8227SGreg Roach sorting: [[0,"asc"]], 4308c2e8227SGreg Roach columns: [ 4318c2e8227SGreg Roach /* 0-name */ null, 4328c2e8227SGreg Roach /* 1-NAME */ null 4338c2e8227SGreg Roach ] 4348c2e8227SGreg Roach }); 4358c2e8227SGreg Roach '); 4368c2e8227SGreg Roach 4378c2e8227SGreg Roach $stories = Database::prepare( 4388c2e8227SGreg Roach "SELECT block_id, xref" . 4398c2e8227SGreg Roach " FROM `##block` b" . 4408c2e8227SGreg Roach " WHERE module_name=?" . 4418c2e8227SGreg Roach " AND gedcom_id=?" . 4428c2e8227SGreg Roach " ORDER BY xref" 44313abd6f3SGreg Roach )->execute([$this->getName(), $WT_TREE->getTreeId()])->fetchAll(); 4448c2e8227SGreg Roach 44515d603e7SGreg Roach echo '<h2 class="wt-page-title">', I18N::translate('Stories'), '</h2>'; 4468c2e8227SGreg Roach if (count($stories) > 0) { 4478c2e8227SGreg Roach echo '<table id="story_table" class="width100">'; 4488c2e8227SGreg Roach echo '<thead><tr> 4498c2e8227SGreg Roach <th>', I18N::translate('Story title'), '</th> 4508c2e8227SGreg Roach <th>', I18N::translate('Individual'), '</th> 4518c2e8227SGreg Roach </tr></thead> 4528c2e8227SGreg Roach <tbody>'; 4538c2e8227SGreg Roach foreach ($stories as $story) { 45424ec66ceSGreg Roach $indi = Individual::getInstance($story->xref, $WT_TREE); 455e2a378d3SGreg Roach $story_title = $this->getBlockSetting($story->block_id, 'title'); 456e2a378d3SGreg Roach $languages = $this->getBlockSetting($story->block_id, 'languages'); 4578c2e8227SGreg Roach if (!$languages || in_array(WT_LOCALE, explode(',', $languages))) { 4588c2e8227SGreg Roach if ($indi) { 4598c2e8227SGreg Roach if ($indi->canShow()) { 46015d603e7SGreg Roach echo '<tr><td><a href="' . $indi->getHtmlUrl() . '#tab-stories">' . $story_title . '</a></td><td><a href="' . $indi->getHtmlUrl() . '#tab-stories">' . $indi->getFullName() . '</a></td></tr>'; 4618c2e8227SGreg Roach } 4628c2e8227SGreg Roach } else { 4638c2e8227SGreg Roach echo '<tr><td>', $story_title, '</td><td class="error">', $story->xref, '</td></tr>'; 4648c2e8227SGreg Roach } 4658c2e8227SGreg Roach } 4668c2e8227SGreg Roach } 4678c2e8227SGreg Roach echo '</tbody></table>'; 4688c2e8227SGreg Roach } 4698c2e8227SGreg Roach } 4708c2e8227SGreg Roach 4710ee13198SGreg Roach /** 4720ee13198SGreg Roach * The user can re-order menus. Until they do, they are shown in this order. 4730ee13198SGreg Roach * 4740ee13198SGreg Roach * @return int 4750ee13198SGreg Roach */ 4768c2e8227SGreg Roach public function defaultMenuOrder() { 4778c2e8227SGreg Roach return 30; 4788c2e8227SGreg Roach } 4798c2e8227SGreg Roach 4800ee13198SGreg Roach /** 4810ee13198SGreg Roach * What is the default access level for this module? 4820ee13198SGreg Roach * 4830ee13198SGreg Roach * Some modules are aimed at admins or managers, and are not generally shown to users. 4840ee13198SGreg Roach * 4850ee13198SGreg Roach * @return int 4860ee13198SGreg Roach */ 4878c2e8227SGreg Roach public function defaultAccessLevel() { 4884b9ff166SGreg Roach return Auth::PRIV_HIDE; 4898c2e8227SGreg Roach } 4908c2e8227SGreg Roach 4910ee13198SGreg Roach /** 4920ee13198SGreg Roach * A menu, to be added to the main application menu. 4930ee13198SGreg Roach * 4940ee13198SGreg Roach * @return Menu|null 4950ee13198SGreg Roach */ 4968c2e8227SGreg Roach public function getMenu() { 4978c2e8227SGreg Roach $menu = new Menu($this->getTitle(), 'module.php?mod=' . $this->getName() . '&mod_action=show_list', 'menu-story'); 4988c2e8227SGreg Roach 4998c2e8227SGreg Roach return $menu; 5008c2e8227SGreg Roach } 5018c2e8227SGreg Roach} 502