1*8c2e8227SGreg Roach<?php 2*8c2e8227SGreg Roachnamespace Fisharebest\Webtrees; 3*8c2e8227SGreg Roach 4*8c2e8227SGreg Roach/** 5*8c2e8227SGreg Roach * webtrees: online genealogy 6*8c2e8227SGreg Roach * Copyright (C) 2015 webtrees development team 7*8c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify 8*8c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by 9*8c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or 10*8c2e8227SGreg Roach * (at your option) any later version. 11*8c2e8227SGreg Roach * This program is distributed in the hope that it will be useful, 12*8c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 13*8c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*8c2e8227SGreg Roach * GNU General Public License for more details. 15*8c2e8227SGreg Roach * You should have received a copy of the GNU General Public License 16*8c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 17*8c2e8227SGreg Roach */ 18*8c2e8227SGreg Roach 19*8c2e8227SGreg Roach/** 20*8c2e8227SGreg Roach * Class StoriesModule 21*8c2e8227SGreg Roach */ 22*8c2e8227SGreg Roachclass StoriesModule extends Module implements ModuleTabInterface, ModuleConfigInterface, ModuleMenuInterface { 23*8c2e8227SGreg Roach /** {@inheritdoc} */ 24*8c2e8227SGreg Roach public function getTitle() { 25*8c2e8227SGreg Roach return /* I18N: Name of a module */ I18N::translate('Stories'); 26*8c2e8227SGreg Roach } 27*8c2e8227SGreg Roach 28*8c2e8227SGreg Roach /** {@inheritdoc} */ 29*8c2e8227SGreg Roach public function getDescription() { 30*8c2e8227SGreg Roach return /* I18N: Description of the “Stories” module */ I18N::translate('Add narrative stories to individuals in the family tree.'); 31*8c2e8227SGreg Roach } 32*8c2e8227SGreg Roach 33*8c2e8227SGreg Roach /** {@inheritdoc} */ 34*8c2e8227SGreg Roach public function modAction($mod_action) { 35*8c2e8227SGreg Roach switch ($mod_action) { 36*8c2e8227SGreg Roach case 'admin_edit': 37*8c2e8227SGreg Roach $this->edit(); 38*8c2e8227SGreg Roach break; 39*8c2e8227SGreg Roach case 'admin_delete': 40*8c2e8227SGreg Roach $this->delete(); 41*8c2e8227SGreg Roach $this->config(); 42*8c2e8227SGreg Roach break; 43*8c2e8227SGreg Roach case 'admin_config': 44*8c2e8227SGreg Roach $this->config(); 45*8c2e8227SGreg Roach break; 46*8c2e8227SGreg Roach case 'show_list': 47*8c2e8227SGreg Roach $this->showList(); 48*8c2e8227SGreg Roach break; 49*8c2e8227SGreg Roach default: 50*8c2e8227SGreg Roach http_response_code(404); 51*8c2e8227SGreg Roach } 52*8c2e8227SGreg Roach } 53*8c2e8227SGreg Roach 54*8c2e8227SGreg Roach /** {@inheritdoc} */ 55*8c2e8227SGreg Roach public function getConfigLink() { 56*8c2e8227SGreg Roach return 'module.php?mod=' . $this->getName() . '&mod_action=admin_config'; 57*8c2e8227SGreg Roach } 58*8c2e8227SGreg Roach 59*8c2e8227SGreg Roach /** {@inheritdoc} */ 60*8c2e8227SGreg Roach public function defaultTabOrder() { 61*8c2e8227SGreg Roach return 55; 62*8c2e8227SGreg Roach } 63*8c2e8227SGreg Roach 64*8c2e8227SGreg Roach /** {@inheritdoc} */ 65*8c2e8227SGreg Roach public function getTabContent() { 66*8c2e8227SGreg Roach global $controller; 67*8c2e8227SGreg Roach 68*8c2e8227SGreg Roach $block_ids = 69*8c2e8227SGreg Roach Database::prepare( 70*8c2e8227SGreg Roach "SELECT block_id" . 71*8c2e8227SGreg Roach " FROM `##block`" . 72*8c2e8227SGreg Roach " WHERE module_name=?" . 73*8c2e8227SGreg Roach " AND xref=?" . 74*8c2e8227SGreg Roach " AND gedcom_id=?" 75*8c2e8227SGreg Roach )->execute(array( 76*8c2e8227SGreg Roach $this->getName(), 77*8c2e8227SGreg Roach $controller->record->getXref(), 78*8c2e8227SGreg Roach WT_GED_ID 79*8c2e8227SGreg Roach ))->fetchOneColumn(); 80*8c2e8227SGreg Roach 81*8c2e8227SGreg Roach $html = ''; 82*8c2e8227SGreg Roach foreach ($block_ids as $block_id) { 83*8c2e8227SGreg Roach // Only show this block for certain languages 84*8c2e8227SGreg Roach $languages = get_block_setting($block_id, 'languages'); 85*8c2e8227SGreg Roach if (!$languages || in_array(WT_LOCALE, explode(',', $languages))) { 86*8c2e8227SGreg Roach $html .= '<div class="story_title descriptionbox center rela">' . get_block_setting($block_id, 'title') . '</div>'; 87*8c2e8227SGreg Roach $html .= '<div class="story_body optionbox">' . get_block_setting($block_id, 'story_body') . '</div>'; 88*8c2e8227SGreg Roach if (WT_USER_CAN_EDIT) { 89*8c2e8227SGreg Roach $html .= '<div class="story_edit"><a href="module.php?mod=' . $this->getName() . '&mod_action=admin_edit&block_id=' . $block_id . '">'; 90*8c2e8227SGreg Roach $html .= I18N::translate('Edit story') . '</a></div>'; 91*8c2e8227SGreg Roach } 92*8c2e8227SGreg Roach } 93*8c2e8227SGreg Roach } 94*8c2e8227SGreg Roach if (WT_USER_GEDCOM_ADMIN && !$html) { 95*8c2e8227SGreg Roach $html .= '<div class="news_title center">' . $this->getTitle() . '</div>'; 96*8c2e8227SGreg Roach $html .= '<div><a href="module.php?mod=' . $this->getName() . '&mod_action=admin_edit&xref=' . $controller->record->getXref() . '">'; 97*8c2e8227SGreg Roach $html .= I18N::translate('Add a story') . '</a></div><br>'; 98*8c2e8227SGreg Roach } 99*8c2e8227SGreg Roach 100*8c2e8227SGreg Roach return $html; 101*8c2e8227SGreg Roach } 102*8c2e8227SGreg Roach 103*8c2e8227SGreg Roach /** {@inheritdoc} */ 104*8c2e8227SGreg Roach public function hasTabContent() { 105*8c2e8227SGreg Roach return $this->getTabContent() <> ''; 106*8c2e8227SGreg Roach } 107*8c2e8227SGreg Roach 108*8c2e8227SGreg Roach /** {@inheritdoc} */ 109*8c2e8227SGreg Roach public function isGrayedOut() { 110*8c2e8227SGreg Roach global $controller; 111*8c2e8227SGreg Roach 112*8c2e8227SGreg Roach $count_of_stories = 113*8c2e8227SGreg Roach Database::prepare( 114*8c2e8227SGreg Roach "SELECT COUNT(block_id)" . 115*8c2e8227SGreg Roach " FROM `##block`" . 116*8c2e8227SGreg Roach " WHERE module_name=?" . 117*8c2e8227SGreg Roach " AND xref=?" . 118*8c2e8227SGreg Roach " AND gedcom_id=?" 119*8c2e8227SGreg Roach )->execute(array( 120*8c2e8227SGreg Roach $this->getName(), 121*8c2e8227SGreg Roach $controller->record->getXref(), 122*8c2e8227SGreg Roach WT_GED_ID 123*8c2e8227SGreg Roach ))->fetchOne(); 124*8c2e8227SGreg Roach 125*8c2e8227SGreg Roach return $count_of_stories == 0; 126*8c2e8227SGreg Roach } 127*8c2e8227SGreg Roach 128*8c2e8227SGreg Roach /** {@inheritdoc} */ 129*8c2e8227SGreg Roach public function canLoadAjax() { 130*8c2e8227SGreg Roach return false; 131*8c2e8227SGreg Roach } 132*8c2e8227SGreg Roach 133*8c2e8227SGreg Roach /** {@inheritdoc} */ 134*8c2e8227SGreg Roach public function getPreLoadContent() { 135*8c2e8227SGreg Roach return ''; 136*8c2e8227SGreg Roach } 137*8c2e8227SGreg Roach 138*8c2e8227SGreg Roach /** 139*8c2e8227SGreg Roach * Show and process a form to edit a story. 140*8c2e8227SGreg Roach */ 141*8c2e8227SGreg Roach private function edit() { 142*8c2e8227SGreg Roach if (WT_USER_CAN_EDIT) { 143*8c2e8227SGreg Roach if (Filter::postBool('save') && Filter::checkCsrf()) { 144*8c2e8227SGreg Roach $block_id = Filter::postInteger('block_id'); 145*8c2e8227SGreg Roach if ($block_id) { 146*8c2e8227SGreg Roach Database::prepare( 147*8c2e8227SGreg Roach "UPDATE `##block` SET gedcom_id=?, xref=? WHERE block_id=?" 148*8c2e8227SGreg Roach )->execute(array(Filter::postInteger('gedcom_id'), Filter::post('xref', WT_REGEX_XREF), $block_id)); 149*8c2e8227SGreg Roach } else { 150*8c2e8227SGreg Roach Database::prepare( 151*8c2e8227SGreg Roach "INSERT INTO `##block` (gedcom_id, xref, module_name, block_order) VALUES (?, ?, ?, ?)" 152*8c2e8227SGreg Roach )->execute(array( 153*8c2e8227SGreg Roach Filter::postInteger('gedcom_id'), 154*8c2e8227SGreg Roach Filter::post('xref', WT_REGEX_XREF), 155*8c2e8227SGreg Roach $this->getName(), 156*8c2e8227SGreg Roach 0 157*8c2e8227SGreg Roach )); 158*8c2e8227SGreg Roach $block_id = Database::getInstance()->lastInsertId(); 159*8c2e8227SGreg Roach } 160*8c2e8227SGreg Roach set_block_setting($block_id, 'title', Filter::post('title')); 161*8c2e8227SGreg Roach set_block_setting($block_id, 'story_body', Filter::post('story_body')); 162*8c2e8227SGreg Roach $languages = Filter::postArray('lang', null, array_keys(I18N::installed_languages())); 163*8c2e8227SGreg Roach set_block_setting($block_id, 'languages', implode(',', $languages)); 164*8c2e8227SGreg Roach $this->config(); 165*8c2e8227SGreg Roach } else { 166*8c2e8227SGreg Roach $block_id = Filter::getInteger('block_id'); 167*8c2e8227SGreg Roach 168*8c2e8227SGreg Roach $controller = new PageController; 169*8c2e8227SGreg Roach if ($block_id) { 170*8c2e8227SGreg Roach $controller->setPageTitle(I18N::translate('Edit story')); 171*8c2e8227SGreg Roach $title = get_block_setting($block_id, 'title'); 172*8c2e8227SGreg Roach $story_body = get_block_setting($block_id, 'story_body'); 173*8c2e8227SGreg Roach $xref = Database::prepare( 174*8c2e8227SGreg Roach "SELECT xref FROM `##block` WHERE block_id=?" 175*8c2e8227SGreg Roach )->execute(array($block_id))->fetchOne(); 176*8c2e8227SGreg Roach } else { 177*8c2e8227SGreg Roach $controller->setPageTitle(I18N::translate('Add a story')); 178*8c2e8227SGreg Roach $title = ''; 179*8c2e8227SGreg Roach $story_body = ''; 180*8c2e8227SGreg Roach $xref = Filter::get('xref', WT_REGEX_XREF); 181*8c2e8227SGreg Roach } 182*8c2e8227SGreg Roach $controller 183*8c2e8227SGreg Roach ->pageHeader() 184*8c2e8227SGreg Roach ->addExternalJavascript(WT_AUTOCOMPLETE_JS_URL) 185*8c2e8227SGreg Roach ->addInlineJavascript('autocomplete();'); 186*8c2e8227SGreg Roach if (Module::getModuleByName('ckeditor')) { 187*8c2e8227SGreg Roach CkeditorModule::enableEditor($controller); 188*8c2e8227SGreg Roach } 189*8c2e8227SGreg Roach 190*8c2e8227SGreg Roach ?> 191*8c2e8227SGreg Roach <ol class="breadcrumb small"> 192*8c2e8227SGreg Roach <li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li> 193*8c2e8227SGreg Roach <li><a href="admin_modules.php"><?php echo I18N::translate('Module administration'); ?></a></li> 194*8c2e8227SGreg Roach <li><a href="module.php?mod=<?php echo $this->getName(); ?>&mod_action=admin_config"><?php echo $this->getTitle(); ?></a></li> 195*8c2e8227SGreg Roach <li class="active"><?php echo $controller->getPageTitle(); ?></li> 196*8c2e8227SGreg Roach </ol> 197*8c2e8227SGreg Roach 198*8c2e8227SGreg Roach <h1><?php echo $controller->getPageTitle(); ?></h1> 199*8c2e8227SGreg Roach <?php 200*8c2e8227SGreg Roach 201*8c2e8227SGreg Roach echo '<form name="story" method="post" action="module.php?mod=', $this->getName(), '&mod_action=admin_edit">'; 202*8c2e8227SGreg Roach echo Filter::getCsrf(); 203*8c2e8227SGreg Roach echo '<input type="hidden" name="save" value="1">'; 204*8c2e8227SGreg Roach echo '<input type="hidden" name="block_id" value="', $block_id, '">'; 205*8c2e8227SGreg Roach echo '<input type="hidden" name="gedcom_id" value="', WT_GED_ID, '">'; 206*8c2e8227SGreg Roach echo '<table id="story_module">'; 207*8c2e8227SGreg Roach echo '<tr><th>'; 208*8c2e8227SGreg Roach echo I18N::translate('Story title'); 209*8c2e8227SGreg Roach echo '</th></tr><tr><td><textarea name="title" rows="1" cols="90" tabindex="2">', Filter::escapeHtml($title), '</textarea></td></tr>'; 210*8c2e8227SGreg Roach echo '<tr><th>'; 211*8c2e8227SGreg Roach echo I18N::translate('Story'); 212*8c2e8227SGreg Roach echo '</th></tr><tr><td>'; 213*8c2e8227SGreg Roach echo '<textarea name="story_body" class="html-edit" rows="10" cols="90" tabindex="2">', Filter::escapeHtml($story_body), '</textarea>'; 214*8c2e8227SGreg Roach echo '</td></tr>'; 215*8c2e8227SGreg Roach echo '</table><table id="story_module2">'; 216*8c2e8227SGreg Roach echo '<tr>'; 217*8c2e8227SGreg Roach echo '<th>', I18N::translate('Individual'), '</th>'; 218*8c2e8227SGreg Roach echo '<th>', I18N::translate('Show this block for which languages?'), '</th>'; 219*8c2e8227SGreg Roach echo '</tr>'; 220*8c2e8227SGreg Roach echo '<tr>'; 221*8c2e8227SGreg Roach echo '<td class="optionbox">'; 222*8c2e8227SGreg Roach echo '<input data-autocomplete-type="INDI" type="text" name="xref" id="pid" size="4" value="' . $xref . '">'; 223*8c2e8227SGreg Roach echo print_findindi_link('pid'); 224*8c2e8227SGreg Roach if ($xref) { 225*8c2e8227SGreg Roach $person = Individual::getInstance($xref); 226*8c2e8227SGreg Roach if ($person) { 227*8c2e8227SGreg Roach echo ' ', $person->format_list('span'); 228*8c2e8227SGreg Roach } 229*8c2e8227SGreg Roach } 230*8c2e8227SGreg Roach echo '</td>'; 231*8c2e8227SGreg Roach $languages = explode(',', get_block_setting($block_id, 'languages')); 232*8c2e8227SGreg Roach echo '<td class="optionbox">'; 233*8c2e8227SGreg Roach echo edit_language_checkboxes('lang', $languages); 234*8c2e8227SGreg Roach echo '</td></tr></table>'; 235*8c2e8227SGreg Roach echo '<p><input type="submit" value="', I18N::translate('save'), '" tabindex="5">'; 236*8c2e8227SGreg Roach echo '</p>'; 237*8c2e8227SGreg Roach echo '</form>'; 238*8c2e8227SGreg Roach } 239*8c2e8227SGreg Roach } else { 240*8c2e8227SGreg Roach header('Location: ' . WT_BASE_URL); 241*8c2e8227SGreg Roach } 242*8c2e8227SGreg Roach } 243*8c2e8227SGreg Roach 244*8c2e8227SGreg Roach /** 245*8c2e8227SGreg Roach * Respond to a request to delete a story. 246*8c2e8227SGreg Roach */ 247*8c2e8227SGreg Roach private function delete() { 248*8c2e8227SGreg Roach if (WT_USER_CAN_EDIT) { 249*8c2e8227SGreg Roach $block_id = Filter::getInteger('block_id'); 250*8c2e8227SGreg Roach 251*8c2e8227SGreg Roach Database::prepare( 252*8c2e8227SGreg Roach "DELETE FROM `##block_setting` WHERE block_id=?" 253*8c2e8227SGreg Roach )->execute(array($block_id)); 254*8c2e8227SGreg Roach 255*8c2e8227SGreg Roach Database::prepare( 256*8c2e8227SGreg Roach "DELETE FROM `##block` WHERE block_id=?" 257*8c2e8227SGreg Roach )->execute(array($block_id)); 258*8c2e8227SGreg Roach } else { 259*8c2e8227SGreg Roach header('Location: ' . WT_BASE_URL); 260*8c2e8227SGreg Roach exit; 261*8c2e8227SGreg Roach } 262*8c2e8227SGreg Roach } 263*8c2e8227SGreg Roach 264*8c2e8227SGreg Roach /** 265*8c2e8227SGreg Roach * The admin view - list, create, edit, delete stories. 266*8c2e8227SGreg Roach */ 267*8c2e8227SGreg Roach private function config() { 268*8c2e8227SGreg Roach $controller = new PageController; 269*8c2e8227SGreg Roach $controller 270*8c2e8227SGreg Roach ->restrictAccess(WT_USER_GEDCOM_ADMIN) 271*8c2e8227SGreg Roach ->setPageTitle($this->getTitle()) 272*8c2e8227SGreg Roach ->pageHeader() 273*8c2e8227SGreg Roach ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) 274*8c2e8227SGreg Roach ->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL) 275*8c2e8227SGreg Roach ->addInlineJavascript(' 276*8c2e8227SGreg Roach jQuery("#story_table").dataTable({ 277*8c2e8227SGreg Roach ' . I18N::datatablesI18N() . ', 278*8c2e8227SGreg Roach autoWidth: false, 279*8c2e8227SGreg Roach paging: true, 280*8c2e8227SGreg Roach pagingType: "full_numbers", 281*8c2e8227SGreg Roach lengthChange: true, 282*8c2e8227SGreg Roach filter: true, 283*8c2e8227SGreg Roach info: true, 284*8c2e8227SGreg Roach sorting: [[0,"asc"]], 285*8c2e8227SGreg Roach columns: [ 286*8c2e8227SGreg Roach /* 0-name */ null, 287*8c2e8227SGreg Roach /* 1-NAME */ null, 288*8c2e8227SGreg Roach /* 2-NAME */ { sortable:false }, 289*8c2e8227SGreg Roach /* 3-NAME */ { sortable:false } 290*8c2e8227SGreg Roach ] 291*8c2e8227SGreg Roach }); 292*8c2e8227SGreg Roach '); 293*8c2e8227SGreg Roach 294*8c2e8227SGreg Roach $stories = Database::prepare( 295*8c2e8227SGreg Roach "SELECT block_id, xref" . 296*8c2e8227SGreg Roach " FROM `##block` b" . 297*8c2e8227SGreg Roach " WHERE module_name=?" . 298*8c2e8227SGreg Roach " AND gedcom_id=?" . 299*8c2e8227SGreg Roach " ORDER BY xref" 300*8c2e8227SGreg Roach )->execute(array($this->getName(), WT_GED_ID))->fetchAll(); 301*8c2e8227SGreg Roach 302*8c2e8227SGreg Roach ?> 303*8c2e8227SGreg Roach <ol class="breadcrumb small"> 304*8c2e8227SGreg Roach <li><a href="admin.php"><?php echo I18N::translate('Control panel'); ?></a></li> 305*8c2e8227SGreg Roach <li><a href="admin_modules.php"><?php echo I18N::translate('Module administration'); ?></a></li> 306*8c2e8227SGreg Roach <li class="active"><?php echo $controller->getPageTitle(); ?></li> 307*8c2e8227SGreg Roach </ol> 308*8c2e8227SGreg Roach 309*8c2e8227SGreg Roach <h1><?php echo $controller->getPageTitle(); ?></h1> 310*8c2e8227SGreg Roach 311*8c2e8227SGreg Roach <form class="form form-inline"> 312*8c2e8227SGreg Roach <label for="ged" class="sr-only"> 313*8c2e8227SGreg Roach <?php echo I18N::translate('Family tree'); ?> 314*8c2e8227SGreg Roach </label> 315*8c2e8227SGreg Roach <input type="hidden" name="mod" value="<?php echo $this->getName(); ?>"> 316*8c2e8227SGreg Roach <input type="hidden" name="mod_action" value="admin_config"> 317*8c2e8227SGreg Roach <?php echo select_edit_control('ged', Tree::getNameList(), null, WT_GEDCOM, 'class="form-control"'); ?> 318*8c2e8227SGreg Roach <input type="submit" class="btn btn-primary" value="<?php echo I18N::translate('show'); ?>"> 319*8c2e8227SGreg Roach </form> 320*8c2e8227SGreg Roach 321*8c2e8227SGreg Roach <p> 322*8c2e8227SGreg Roach <a href="module.php?mod=<?php echo $this->getName(); ?>&mod_action=admin_edit" class="btn btn-default"> 323*8c2e8227SGreg Roach <i class="fa fa-plus"></i> 324*8c2e8227SGreg Roach <?php echo I18N::translate('Add a story'); ?> 325*8c2e8227SGreg Roach </a> 326*8c2e8227SGreg Roach </p> 327*8c2e8227SGreg Roach 328*8c2e8227SGreg Roach <table class="table table-bordered table-condensed"> 329*8c2e8227SGreg Roach <thead> 330*8c2e8227SGreg Roach <tr> 331*8c2e8227SGreg Roach <th><?php echo I18N::translate('Story title'); ?></th> 332*8c2e8227SGreg Roach <th><?php echo I18N::translate('Individual'); ?></th> 333*8c2e8227SGreg Roach <th><?php echo I18N::translate('Edit'); ?></th> 334*8c2e8227SGreg Roach <th><?php echo I18N::translate('Delete'); ?></th> 335*8c2e8227SGreg Roach </tr> 336*8c2e8227SGreg Roach </thead> 337*8c2e8227SGreg Roach <tbody> 338*8c2e8227SGreg Roach <?php foreach ($stories as $story): ?> 339*8c2e8227SGreg Roach <tr> 340*8c2e8227SGreg Roach <td> 341*8c2e8227SGreg Roach <?php echo Filter::escapeHtml(get_block_setting($story->block_id, 'title')); ?> 342*8c2e8227SGreg Roach </td> 343*8c2e8227SGreg Roach <td> 344*8c2e8227SGreg Roach <?php if ($indi = Individual::getInstance($story->xref)): ?> 345*8c2e8227SGreg Roach <a href="<?php echo $indi->getHtmlUrl(); ?>#stories"> 346*8c2e8227SGreg Roach <?php echo $indi->getFullName(); ?> 347*8c2e8227SGreg Roach </a> 348*8c2e8227SGreg Roach <?php else: ?> 349*8c2e8227SGreg Roach <?php echo $story->xref; ?> 350*8c2e8227SGreg Roach <?php endif; ?> 351*8c2e8227SGreg Roach </td> 352*8c2e8227SGreg Roach <td> 353*8c2e8227SGreg Roach <a href="module.php?mod=<?php echo $this->getName(); ?>&mod_action=admin_edit&block_id=<?php echo $story->block_id; ?>"> 354*8c2e8227SGreg Roach <div class="icon-edit"> </div> 355*8c2e8227SGreg Roach </a> 356*8c2e8227SGreg Roach </td> 357*8c2e8227SGreg Roach <td> 358*8c2e8227SGreg Roach <a 359*8c2e8227SGreg Roach href="module.php?mod=<?php echo $this->getName(); ?>&mod_action=admin_delete&block_id=<?php echo $story->block_id; ?>" 360*8c2e8227SGreg Roach onclick="return confirm('<?php echo I18N::translate('Are you sure you want to delete this story?'); ?>');" 361*8c2e8227SGreg Roach > 362*8c2e8227SGreg Roach <div class="icon-delete"> </div> 363*8c2e8227SGreg Roach </a> 364*8c2e8227SGreg Roach </td> 365*8c2e8227SGreg Roach </tr> 366*8c2e8227SGreg Roach <?php endforeach; ?> 367*8c2e8227SGreg Roach </tbody> 368*8c2e8227SGreg Roach </table> 369*8c2e8227SGreg Roach <?php 370*8c2e8227SGreg Roach } 371*8c2e8227SGreg Roach 372*8c2e8227SGreg Roach /** 373*8c2e8227SGreg Roach * Show the list of stories 374*8c2e8227SGreg Roach */ 375*8c2e8227SGreg Roach private function showList() { 376*8c2e8227SGreg Roach global $controller; 377*8c2e8227SGreg Roach 378*8c2e8227SGreg Roach $controller = new PageController; 379*8c2e8227SGreg Roach $controller 380*8c2e8227SGreg Roach ->setPageTitle($this->getTitle()) 381*8c2e8227SGreg Roach ->pageHeader() 382*8c2e8227SGreg Roach ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) 383*8c2e8227SGreg Roach ->addInlineJavascript(' 384*8c2e8227SGreg Roach jQuery("#story_table").dataTable({ 385*8c2e8227SGreg Roach dom: \'<"H"pf<"dt-clear">irl>t<"F"pl>\', 386*8c2e8227SGreg Roach ' . I18N::datatablesI18N() . ', 387*8c2e8227SGreg Roach autoWidth: false, 388*8c2e8227SGreg Roach paging: true, 389*8c2e8227SGreg Roach pagingType: "full_numbers", 390*8c2e8227SGreg Roach lengthChange: true, 391*8c2e8227SGreg Roach filter: true, 392*8c2e8227SGreg Roach info: true, 393*8c2e8227SGreg Roach jQueryUI: true, 394*8c2e8227SGreg Roach sorting: [[0,"asc"]], 395*8c2e8227SGreg Roach columns: [ 396*8c2e8227SGreg Roach /* 0-name */ null, 397*8c2e8227SGreg Roach /* 1-NAME */ null 398*8c2e8227SGreg Roach ] 399*8c2e8227SGreg Roach }); 400*8c2e8227SGreg Roach '); 401*8c2e8227SGreg Roach 402*8c2e8227SGreg Roach $stories = Database::prepare( 403*8c2e8227SGreg Roach "SELECT block_id, xref" . 404*8c2e8227SGreg Roach " FROM `##block` b" . 405*8c2e8227SGreg Roach " WHERE module_name=?" . 406*8c2e8227SGreg Roach " AND gedcom_id=?" . 407*8c2e8227SGreg Roach " ORDER BY xref" 408*8c2e8227SGreg Roach )->execute(array($this->getName(), WT_GED_ID))->fetchAll(); 409*8c2e8227SGreg Roach 410*8c2e8227SGreg Roach echo '<h2 class="center">', I18N::translate('Stories'), '</h2>'; 411*8c2e8227SGreg Roach if (count($stories) > 0) { 412*8c2e8227SGreg Roach echo '<table id="story_table" class="width100">'; 413*8c2e8227SGreg Roach echo '<thead><tr> 414*8c2e8227SGreg Roach <th>', I18N::translate('Story title'), '</th> 415*8c2e8227SGreg Roach <th>', I18N::translate('Individual'), '</th> 416*8c2e8227SGreg Roach </tr></thead> 417*8c2e8227SGreg Roach <tbody>'; 418*8c2e8227SGreg Roach foreach ($stories as $story) { 419*8c2e8227SGreg Roach $indi = Individual::getInstance($story->xref); 420*8c2e8227SGreg Roach $story_title = get_block_setting($story->block_id, 'title'); 421*8c2e8227SGreg Roach $languages = get_block_setting($story->block_id, 'languages'); 422*8c2e8227SGreg Roach if (!$languages || in_array(WT_LOCALE, explode(',', $languages))) { 423*8c2e8227SGreg Roach if ($indi) { 424*8c2e8227SGreg Roach if ($indi->canShow()) { 425*8c2e8227SGreg Roach echo '<tr><td><a href="' . $indi->getHtmlUrl() . '#stories">' . $story_title . '</a></td><td><a href="' . $indi->getHtmlUrl() . '#stories">' . $indi->getFullName() . '</a></td></tr>'; 426*8c2e8227SGreg Roach } 427*8c2e8227SGreg Roach } else { 428*8c2e8227SGreg Roach echo '<tr><td>', $story_title, '</td><td class="error">', $story->xref, '</td></tr>'; 429*8c2e8227SGreg Roach } 430*8c2e8227SGreg Roach } 431*8c2e8227SGreg Roach } 432*8c2e8227SGreg Roach echo '</tbody></table>'; 433*8c2e8227SGreg Roach } 434*8c2e8227SGreg Roach } 435*8c2e8227SGreg Roach 436*8c2e8227SGreg Roach /** {@inheritdoc} */ 437*8c2e8227SGreg Roach public function defaultMenuOrder() { 438*8c2e8227SGreg Roach return 30; 439*8c2e8227SGreg Roach } 440*8c2e8227SGreg Roach 441*8c2e8227SGreg Roach /** {@inheritdoc} */ 442*8c2e8227SGreg Roach public function defaultAccessLevel() { 443*8c2e8227SGreg Roach return WT_PRIV_HIDE; 444*8c2e8227SGreg Roach } 445*8c2e8227SGreg Roach 446*8c2e8227SGreg Roach /** {@inheritdoc} */ 447*8c2e8227SGreg Roach public function getMenu() { 448*8c2e8227SGreg Roach if (Auth::isSearchEngine()) { 449*8c2e8227SGreg Roach return null; 450*8c2e8227SGreg Roach } 451*8c2e8227SGreg Roach 452*8c2e8227SGreg Roach $menu = new Menu($this->getTitle(), 'module.php?mod=' . $this->getName() . '&mod_action=show_list', 'menu-story'); 453*8c2e8227SGreg Roach 454*8c2e8227SGreg Roach return $menu; 455*8c2e8227SGreg Roach } 456*8c2e8227SGreg Roach} 457